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

Function lazy_load_file

convert.py:769–780  ·  view source on GitHub ↗
(path: Path)

Source from the content-addressed store, hash-verified

767
768@functools.lru_cache(maxsize=None)
769def lazy_load_file(path: Path) -> ModelPlus:
770 fp = open(path, 'rb')
771 first8 = fp.read(8)
772 fp.seek(0)
773 if first8[:2] == b'PK':
774 # A zip file, i.e. PyTorch format
775 return lazy_load_torch_file(fp, path)
776 elif struct.unpack('<Q', first8)[0] < 16 * 1024 * 1024:
777 # Probably safetensors
778 return lazy_load_safetensors_file(fp, path)
779 else:
780 raise ValueError(f"unknown format: {path}")
781
782
783In = TypeVar('In')

Callers 3

load_some_modelFunction · 0.70
load_predictor_modelFunction · 0.70
mainFunction · 0.70

Calls 4

lazy_load_torch_fileFunction · 0.70
readMethod · 0.45
seekMethod · 0.45

Tested by

no test coverage detected