(path: Path)
| 767 | |
| 768 | @functools.lru_cache(maxsize=None) |
| 769 | def lazy_load_file(path: Path) -> ModelPlus: |
| 770 | fp = open(path, 'rb') |
| 771 | first8 = fp.read(8) |
| 772 | fp.seek(0) |
| 773 | if first8[:2] == b'PK': |
| 774 | # A zip file, i.e. PyTorch format |
| 775 | return lazy_load_torch_file(fp, path) |
| 776 | elif struct.unpack('<Q', first8)[0] < 16 * 1024 * 1024: |
| 777 | # Probably safetensors |
| 778 | return lazy_load_safetensors_file(fp, path) |
| 779 | else: |
| 780 | raise ValueError(f"unknown format: {path}") |
| 781 | |
| 782 | |
| 783 | In = TypeVar('In') |
no test coverage detected