MCPcopy Index your code
hub / github.com/microsoft/BitNet / nth_multifile_path

Function nth_multifile_path

utils/convert.py:1363–1381  ·  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

1361
1362
1363def nth_multifile_path(path: Path, n: int) -> Path | None:
1364 '''Given any path belonging to a multi-file model (e.g. foo.bin.1), return
1365 the nth path in the model.
1366 '''
1367 # Support the following patterns:
1368 patterns = [
1369 # - x.00.pth, x.01.pth, etc.
1370 (r'\.[0-9]{2}\.pth$', f'.{n:02}.pth'),
1371 # - x-00001-of-00002.bin, x-00002-of-00002.bin, etc.
1372 (r'-[0-9]{5}-of-(.*)$', fr'-{n:05}-of-\1'),
1373 # x.bin, x.bin.1, etc.
1374 (r'(\.[0-9]+)?$', r'\1' if n == 0 else fr'\1.{n}')
1375 ]
1376 for regex, replacement in patterns:
1377 if re.search(regex, path.name):
1378 new_path = path.with_name(re.sub(regex, replacement, path.name))
1379 if new_path.exists():
1380 return new_path
1381 return None
1382
1383
1384def find_multifile_paths(path: Path) -> list[Path]:

Callers 1

find_multifile_pathsFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected