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

Function load_some_model

convert.py:1091–1115  ·  view source on GitHub ↗

Load a model of any supported format.

(path: Path)

Source from the content-addressed store, hash-verified

1089
1090
1091def load_some_model(path: Path) -> ModelPlus:
1092 '''Load a model of any supported format.'''
1093 # Be extra-friendly and accept either a file or a directory:
1094 if path.is_dir():
1095 # Check if it's a set of safetensors files first
1096 globs = ["model-00001-of-*.safetensors", "model.safetensors"]
1097 files = [file for glob in globs for file in path.glob(glob)]
1098 if not files:
1099 # Try the PyTorch patterns too, with lower priority
1100 globs = ["consolidated.00.pth", "pytorch_model-00001-of-*.bin", "*.pt", "pytorch_model.bin"]
1101 files = [file for glob in globs for file in path.glob(glob)]
1102 if not files:
1103 raise Exception(f"Can't find model in directory {path}")
1104 if len(files) > 1:
1105 raise Exception(f"Found multiple models in {path}, not sure which to pick: {files}")
1106 path = files[0]
1107
1108 paths = find_multifile_paths(path)
1109 models_plus: list[ModelPlus] = []
1110 for path in paths:
1111 print(f"Loading model file {path}")
1112 models_plus.append(lazy_load_file(path))
1113
1114 model_plus = merge_multifile_models(models_plus)
1115 return model_plus
1116
1117def load_predictor_model(path: Path) -> ModelPlus:
1118 '''Load MLP models for sparse FFN inference from directory.'''

Callers 1

mainFunction · 0.70

Calls 5

find_multifile_pathsFunction · 0.70
lazy_load_fileFunction · 0.70
merge_multifile_modelsFunction · 0.70
printFunction · 0.50
appendMethod · 0.45

Tested by

no test coverage detected