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

Function load_some_model

tokenizer/convert/convert.py:1260–1284  ·  view source on GitHub ↗

Load a model of any supported format.

(path: Path)

Source from the content-addressed store, hash-verified

1258
1259
1260def load_some_model(path: Path) -> ModelPlus:
1261 '''Load a model of any supported format.'''
1262 # Be extra-friendly and accept either a file or a directory:
1263 if path.is_dir():
1264 # Check if it's a set of safetensors files first
1265 globs = ["model-00001-of-*.safetensors", "model.safetensors"]
1266 files = [file for glob in globs for file in path.glob(glob)]
1267 if not files:
1268 # Try the PyTorch patterns too, with lower priority
1269 globs = ["consolidated.00.pth", "pytorch_model-00001-of-*.bin", "*.pt", "pytorch_model.bin"]
1270 files = [file for glob in globs for file in path.glob(glob)]
1271 if not files:
1272 raise Exception(f"Can't find model in directory {path}")
1273 if len(files) > 1:
1274 raise Exception(f"Found multiple models in {path}, not sure which to pick: {files}")
1275 path = files[0]
1276
1277 paths = find_multifile_paths(path)
1278 models_plus: list[ModelPlus] = []
1279 for path in paths:
1280 print(f"Loading model file {path}")
1281 models_plus.append(lazy_load_file(path))
1282
1283 model_plus = merge_multifile_models(models_plus)
1284 return model_plus
1285
1286
1287class VocabFactory:

Callers 1

mainFunction · 0.85

Calls 3

find_multifile_pathsFunction · 0.85
lazy_load_fileFunction · 0.85
merge_multifile_modelsFunction · 0.85

Tested by

no test coverage detected