MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / nth_multifile_path

Function nth_multifile_path

convert-dense.py:1005–1023  ·  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

1003 return out
1004
1005def nth_multifile_path(path: Path, n: int) -> Path | None:
1006 '''Given any path belonging to a multi-file model (e.g. foo.bin.1), return
1007 the nth path in the model.
1008 '''
1009 # Support the following patterns:
1010 patterns: list[tuple[str, str]] = [
1011 # - x.00.pth, x.01.pth, etc.
1012 (r'\.[0-9]{2}\.pth$', f'.{n:02}.pth'),
1013 # - x-00001-of-00002.bin, x-00002-of-00002.bin, etc.
1014 (r'-[0-9]{5}-of-(.*)$', fr'-{n:05}-of-\1'),
1015 # x.bin, x.bin.1, etc.
1016 (r'(\.[0-9]+)?$', r'\1' if n == 0 else fr'\1.{n}')
1017 ]
1018 for regex, replacement in patterns:
1019 if re.search(regex, path.name):
1020 new_path = path.with_name(re.sub(regex, replacement, path.name))
1021 if new_path.exists():
1022 return new_path
1023 return None
1024
1025
1026def find_multifile_paths(path: Path) -> list[Path]:

Callers 1

find_multifile_pathsFunction · 0.70

Calls 2

subMethod · 0.80
searchMethod · 0.45

Tested by

no test coverage detected