Load a model of any supported format.
(path: Path)
| 1400 | |
| 1401 | |
| 1402 | def 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 | |
| 1425 | class VocabFactory: |
no test coverage detected