MCPcopy Create free account
hub / github.com/Pints-AI/1.5-Pints / nth_multifile_path

Function nth_multifile_path

tokenizer/convert/convert.py:1221–1239  ·  view source on GitHub ↗

Given any path belonging to a multi-file model (e.g. foo.bin.1), return the nth path in the model.

(path: Path, n: int)

Source from the content-addressed store, hash-verified

1219
1220
1221def nth_multifile_path(path: Path, n: int) -> Path | None:
1222 '''Given any path belonging to a multi-file model (e.g. foo.bin.1), return
1223 the nth path in the model.
1224 '''
1225 # Support the following patterns:
1226 patterns: list[tuple[str, str]] = [
1227 # - x.00.pth, x.01.pth, etc.
1228 (r'\.[0-9]{2}\.pth$', f'.{n:02}.pth'),
1229 # - x-00001-of-00002.bin, x-00002-of-00002.bin, etc.
1230 (r'-[0-9]{5}-of-(.*)$', fr'-{n:05}-of-\1'),
1231 # x.bin, x.bin.1, etc.
1232 (r'(\.[0-9]+)?$', r'\1' if n == 0 else fr'\1.{n}')
1233 ]
1234 for regex, replacement in patterns:
1235 if re.search(regex, path.name):
1236 new_path = path.with_name(re.sub(regex, replacement, path.name))
1237 if new_path.exists():
1238 return new_path
1239 return None
1240
1241
1242def find_multifile_paths(path: Path) -> list[Path]:

Callers 1

find_multifile_pathsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected