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

Function lazy_load_torch_file

tokenizer/convert/convert.py:838–849  ·  view source on GitHub ↗
(outer_fp: IO[bytes], path: Path)

Source from the content-addressed store, hash-verified

836
837
838def lazy_load_torch_file(outer_fp: IO[bytes], path: Path) -> ModelPlus:
839 zf = zipfile.ZipFile(outer_fp)
840 pickle_paths = [name for name in zf.namelist() if name.endswith('.pkl')]
841 assert len(pickle_paths) == 1, pickle_paths
842 pickle_fp = zf.open(pickle_paths[0], 'r')
843 unpickler = LazyUnpickler(pickle_fp,
844 data_base_path=pickle_paths[0][:-4],
845 zip_file=zf)
846 model = unpickler.load()
847 if 'model' in model: model = model['model']
848 as_dict = dict(model.items())
849 return ModelPlus(model=as_dict, paths=[path], format='torch', vocab=None)
850
851
852def lazy_load_safetensors_file(fp: IO[bytes], path: Path) -> ModelPlus:

Callers 1

lazy_load_fileFunction · 0.85

Calls 3

loadMethod · 0.95
LazyUnpicklerClass · 0.85
ModelPlusClass · 0.85

Tested by

no test coverage detected