(path: Path)
| 882 | |
| 883 | @functools.lru_cache(maxsize=None) |
| 884 | def lazy_load_file(path: Path) -> ModelPlus: |
| 885 | fp = open(path, 'rb') |
| 886 | first8 = fp.read(8) |
| 887 | fp.seek(0) |
| 888 | if first8[:2] == b'PK': |
| 889 | # A zip file, i.e. PyTorch format |
| 890 | return lazy_load_torch_file(fp, path) |
| 891 | elif struct.unpack('<Q', first8)[0] < 16 * 1024 * 1024: |
| 892 | # Probably safetensors |
| 893 | return lazy_load_safetensors_file(fp, path) |
| 894 | else: |
| 895 | raise ValueError(f"unknown format: {path}") |
| 896 | |
| 897 | |
| 898 | In = TypeVar('In') |
no test coverage detected