MCPcopy
hub / github.com/tinygrad/tinygrad / gguf_load

Function gguf_load

tinygrad/llm/gguf.py:158–177  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

156 return [pathlib.Path(f"{m.group(1)}-{i:05d}-of-{total:05d}.gguf") for i in range(1, total+1)]
157
158def 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

Callers 7

from_ggufMethod · 0.90
test_multi_part_loadMethod · 0.90
_test_gguf_loadMethod · 0.90
_test_gguf_gemvMethod · 0.90
build_ggufMethod · 0.90
loadFunction · 0.90

Calls 5

TensorClass · 0.90
_gguf_parseFunction · 0.85
_gguf_split_pathsFunction · 0.85
getMethod · 0.45
updateMethod · 0.45

Tested by 4

test_multi_part_loadMethod · 0.72
_test_gguf_loadMethod · 0.72
_test_gguf_gemvMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…