Skip to content

Kyojin: open-source engine that runs 100 GB-class open models (GLM-5.3, Qwen3.8, DeepSeek V4.1) on one desktop machine. AMD Strix Halo, NVIDIA RTX and Apple Mac. OpenAI API, built on ExLlamaV3.

GGUF loader: refuse per-expert slices of float stacked tensors

YanissAmzda23e43bfc22
diff --git a/exllamav3/loader/gguf_collection.py b/exllamav3/loader/gguf_collection.py
index e0163c3..4e57d2a 100644
--- a/exllamav3/loader/gguf_collection.py
+++ b/exllamav3/loader/gguf_collection.py
@@ -280,6 +280,10 @@ class GGUFCollection:
raise ValueError("transpose not supported for quant payloads")
return t.to(dev)
if ty in (0, 1, 30): # F32 / F16 / BF16 (BF16 widened to float32: bit shift, exact)
+ if exp_idx is not None:
+ # Not implemented for float payloads: refuse by name rather than return the whole stack.
+ raise ValueError(f"per-expert slice of a {({0: 'F32', 1: 'F16', 30: 'BF16'})[ty]} "
+ f"stacked tensor is not supported: {mapped} (expert {exp_idx})")
dt = np.float32 if ty == 0 else np.float16
es = 4 if ty == 0 else 2
n = int(np.prod(dims))
diff --git a/tests/test_gguf_expert_slice_names.py b/tests/test_gguf_expert_slice_names.py
index dceb81a..302f8ae 100644
--- a/tests/test_gguf_expert_slice_names.py
+++ b/tests/test_gguf_expert_slice_names.py
@@ -89,3 +89,31 @@ def test_missing_slice_not_found(gguf):
assert not c.has_tensor("y")
finally:
c.name_map = {}
+
+
+def _write_float_gguf(path, name, ty, es, dims):
+ def s(x):
+ b = x.encode()
+ return struct.pack("<Q", len(b)) + b
+ n = int(np.prod(dims))
+ data = np.zeros(n * es, dtype=np.uint8).tobytes()
+ blob = b"GGUF" + struct.pack("<IQQ", 3, 1, 0)
+ blob += s(name) + struct.pack("<I", len(dims)) + struct.pack("<" + "Q" * len(dims), *dims) + struct.pack("<I", ty) + struct.pack("<Q", 0)
+ blob += b"\0" * (-len(blob) % 32) + data
+ with open(path, "wb") as f:
+ f.write(blob)
+
+
[email protected]("ty,es,label", [(0, 4, "F32"), (1, 2, "F16"), (30, 2, "BF16")])
+def test_float_stacked_slice_refused(ty, es, label):
+ with tempfile.TemporaryDirectory() as d:
+ p = os.path.join(d, "f.gguf")
+ _write_float_gguf(p, "blk.0.ffn_gate_exps.weight", ty, es, (K, N, E))
+ c = GGUFCollection(p)
+ with pytest.raises(ValueError, match=rf"{label} stacked tensor is not supported: blk\.0\.ffn_gate_exps\.weight \(expert 2\)"):
+ c.get_tensor("blk.0.ffn_gate_exps.e2.weight")
+ c.name_map = {"model.layers.0.mlp.experts.2.gate_proj.weight": "blk.0.ffn_gate_exps.e2.weight"}
+ with pytest.raises(ValueError, match=r"not supported"):
+ c.get_tensor("model.layers.0.mlp.experts.2.gate_proj.weight")
+ t = c.get_tensor("blk.0.ffn_gate_exps.weight") # the whole stack still loads
+ assert t.numel() == K * N * E