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

Function load_predictor_model

convert.py:1117–1134  ·  view source on GitHub ↗

Load MLP models for sparse FFN inference from directory.

(path: Path)

Source from the content-addressed store, hash-verified

1115 return model_plus
1116
1117def load_predictor_model(path: Path) -> ModelPlus:
1118 '''Load MLP models for sparse FFN inference from directory.'''
1119 assert path.is_dir(), f"MLP model path {path} is not a directory"
1120
1121 first_model_path = path / "model_0.pt"
1122 assert first_model_path.resolve(), f"MLP model path {path} does not contain model_0.pt"
1123
1124 model_paths = find_multifile_paths(first_model_path)
1125 models_plus: list[ModelPlus] = []
1126 for model_path in model_paths:
1127 # find number in model_path
1128 model_layer = int(re.search(r'model_(\d+).pt', str(model_path)).group(1))
1129 print(f"Loading MLP model file {model_path}")
1130 mlp_model = lazy_load_file(model_path)
1131 mlp_model.model = {f"model.layers.{model_layer}.{name}": tensor for name, tensor in mlp_model.model.items()}
1132 models_plus.append(mlp_model)
1133
1134 return merge_multifile_models(models_plus)
1135
1136
1137def load_vocab(path: Path, vocabtype: str | None) -> Vocab:

Callers 1

mainFunction · 0.85

Calls 8

strFunction · 0.85
find_multifile_pathsFunction · 0.70
lazy_load_fileFunction · 0.70
merge_multifile_modelsFunction · 0.70
printFunction · 0.50
groupMethod · 0.45
searchMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected