MCPcopy Index your code
hub / github.com/microsoft/BitNet / load_some_model

Function load_some_model

utils/convert.py:1402–1422  ·  view source on GitHub ↗

Load a model of any supported format.

(path: Path)

Source from the content-addressed store, hash-verified

1400
1401
1402def load_some_model(path: Path) -> ModelPlus:
1403 '''Load a model of any supported format.'''
1404 # Be extra-friendly and accept either a file or a directory:
1405 if path.is_dir():
1406 # Check if it's a set of safetensors files
1407 globs = ["model-00001-of-*.safetensors", "model.safetensors", "consolidated.safetensors"]
1408 files = [file for glob in globs for file in path.glob(glob)]
1409 if not files:
1410 raise FileNotFoundError(f"Can't find safetensors model in directory {path}")
1411 if len(files) > 1:
1412 raise ValueError(f"Found multiple models in {path}, not sure which to pick: {files}")
1413 path = files[0]
1414
1415 paths = find_multifile_paths(path)
1416 models_plus: list[ModelPlus] = []
1417 for path in paths:
1418 logger.info(f"Loading model file {path}")
1419 models_plus.append(lazy_load_file(path))
1420
1421 model_plus = merge_multifile_models(models_plus)
1422 return model_plus
1423
1424
1425class VocabFactory:

Callers 1

mainFunction · 0.70

Calls 3

find_multifile_pathsFunction · 0.70
lazy_load_fileFunction · 0.70
merge_multifile_modelsFunction · 0.70

Tested by

no test coverage detected