Skip to content

Commit 62583ae

Browse files
justinchubyCopilot
andcommitted
Reject lossy Kimi Q4 projection reshapes
Kimi Linear reshapes its rank-3 MLA projections through dequantized values. Reject every quantized source format in preservation mode, including otherwise exact Q4_0 routes, and require the explicit float fallback. Co-authored-by: Copilot App <[email protected]> Signed-off-by: Justin Chu <[email protected]>
1 parent 3547f74 commit 62583ae

2 files changed

Lines changed: 18 additions & 24 deletions

File tree

‎src/mobius/integrations/gguf/_builder.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5153,10 +5153,10 @@ def _load_quantized_state_dict(
51535153
)
51545154
if explicitly_dequantized and quant_spec.dequantize is Support.SUPPORTED:
51555155
route = QuantImportRoute.DEQUANTIZE_FLOAT
5156-
if is_kimi_reshaped_projection and route is QuantImportRoute.NATIVE_BYTES:
5156+
if is_kimi_reshaped_projection:
51575157
if quant_spec.dequantize is not Support.SUPPORTED:
51585158
raise ValueError(
5159-
f"Cannot reshape native {quant_spec.name} tensor {hf_name}: "
5159+
f"Cannot reshape quantized {quant_spec.name} tensor {hf_name}: "
51605160
"the stored format has no supported dequantization route."
51615161
)
51625162
route = QuantImportRoute.DEQUANTIZE_REQUANTIZE

‎src/mobius/integrations/gguf/_builder_test.py‎

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6192,33 +6192,27 @@ def test_float_import_runtime_state_replay_reorder_and_roundtrip(
61926192
== model.metadata_props["mobius.cache_abi"]
61936193
)
61946194

6195-
def test_quantized_source_preserves_only_matmul_roles(self, tmp_path: Path) -> None:
6196-
from mobius.integrations.gguf import build_from_gguf
6197-
6198-
path = tmp_path / "kimi-linear-q4.gguf"
6199-
_write_kimi_linear_gguf(path, quantized=True)
6200-
model = build_from_gguf(path, keep_quantized=True)["model"]
6201-
quantized_inputs = [
6202-
node.inputs[1].name
6203-
for node in model.graph
6204-
if node.op_type == "MatMulNBits" and len(node.inputs) > 1
6205-
]
6206-
assert quantized_inputs
6207-
assert all(
6208-
not any(term in name for term in ("norm", "conv1d", "A_log", "dt_bias"))
6209-
for name in quantized_inputs
6210-
)
6211-
6212-
def test_native_quantized_mla_reshape_requires_explicit_dequantization(
6213-
self, tmp_path: Path
6195+
@pytest.mark.parametrize(
6196+
("native_quantized", "qtype_name"),
6197+
[(False, "Q4_0"), (True, "IQ4_NL")],
6198+
)
6199+
def test_quantized_mla_reshape_requires_explicit_dequantization(
6200+
self,
6201+
tmp_path: Path,
6202+
native_quantized: bool,
6203+
qtype_name: str,
62146204
) -> None:
62156205
from mobius.integrations.gguf import build_from_gguf
62166206

6217-
path = tmp_path / "kimi-linear-iq4-nl.gguf"
6218-
_write_kimi_linear_gguf(path, quantized=True, native_quantized=True)
6207+
path = tmp_path / f"kimi-linear-{qtype_name.lower()}.gguf"
6208+
_write_kimi_linear_gguf(
6209+
path,
6210+
quantized=True,
6211+
native_quantized=native_quantized,
6212+
)
62196213
with pytest.raises(
62206214
ValueError,
6221-
match=r"change the dequantized values.*attn_k_b\.weight \(IQ4_NL\)",
6215+
match=rf"change the dequantized values.*attn_k_b\.weight \({qtype_name}\)",
62226216
):
62236217
build_from_gguf(path, keep_quantized=True)
62246218

0 commit comments

Comments
 (0)