Load MLP models for sparse FFN inference from directory.
(path: Path)
| 1115 | return model_plus |
| 1116 | |
| 1117 | def 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 | |
| 1137 | def load_vocab(path: Path, vocabtype: str | None) -> Vocab: |
no test coverage detected