Loads a .gguf file, returning the `kv_data` and `state_dict`. Multi-part splits are auto-merged when loaded by path. ```python import pathlib from tinygrad import Device, Tensor from tinygrad.llm.gguf import gguf_load gguf_tensor = Tensor(pathlib.Path("Meta-Llama-3-8B-Instruct.Q4_0.gg
(fn: Tensor|str|pathlib.Path)
| 156 | return [pathlib.Path(f"{m.group(1)}-{i:05d}-of-{total:05d}.gguf") for i in range(1, total+1)] |
| 157 | |
| 158 | def gguf_load(fn: Tensor|str|pathlib.Path) -> tuple[dict, dict[str, Tensor]]: |
| 159 | """ |
| 160 | Loads a .gguf file, returning the `kv_data` and `state_dict`. Multi-part splits are auto-merged when loaded by path. |
| 161 | |
| 162 | ```python |
| 163 | import pathlib |
| 164 | from tinygrad import Device, Tensor |
| 165 | from tinygrad.llm.gguf import gguf_load |
| 166 | |
| 167 | gguf_tensor = Tensor(pathlib.Path("Meta-Llama-3-8B-Instruct.Q4_0.gguf")).to(Device.DEFAULT) |
| 168 | kv_data, state_dict = gguf_load(gguf_tensor) |
| 169 | ``` |
| 170 | |
| 171 | NOTE: The provided tensor must be on a device that supports execution. |
| 172 | """ |
| 173 | kv, sd = _gguf_parse(fn if isinstance(fn, Tensor) else Tensor(pathlib.Path(fn))) |
| 174 | if kv.get('split.count', 1) <= 1: return kv, sd |
| 175 | if isinstance(fn, Tensor): raise ValueError("multi-part GGUF requires a path argument (got Tensor)") |
| 176 | for pp in _gguf_split_paths(pathlib.Path(fn), kv)[1:]: sd.update(_gguf_parse(Tensor(pp))[1]) |
| 177 | return kv, sd |
searching dependent graphs…