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

Function load_some_model

convert-dense.py:1044–1068  ·  view source on GitHub ↗

Load a model of any supported format.

(path: Path)

Source from the content-addressed store, hash-verified

1042
1043
1044def load_some_model(path: Path) -> ModelPlus:
1045 '''Load a model of any supported format.'''
1046 # Be extra-friendly and accept either a file or a directory:
1047 if path.is_dir():
1048 # Check if it's a set of safetensors files first
1049 globs = ["model-00001-of-*.safetensors", "model.safetensors"]
1050 files = [file for glob in globs for file in path.glob(glob)]
1051 if not files:
1052 # Try the PyTorch patterns too, with lower priority
1053 globs = ["consolidated.00.pth", "pytorch_model-00001-of-*.bin", "*.pt", "pytorch_model.bin"]
1054 files = [file for glob in globs for file in path.glob(glob)]
1055 if not files:
1056 raise Exception(f"Can't find model in directory {path}")
1057 if len(files) > 1:
1058 raise Exception(f"Found multiple models in {path}, not sure which to pick: {files}")
1059 path = files[0]
1060
1061 paths = find_multifile_paths(path)
1062 models_plus: list[ModelPlus] = []
1063 for path in paths:
1064 print(f"Loading model file {path}")
1065 models_plus.append(lazy_load_file(path))
1066
1067 model_plus = merge_multifile_models(models_plus)
1068 return model_plus
1069
1070
1071def load_vocab(path: Path, vocabtype: str | None) -> Vocab:

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