Skip to content

Commit 75ac6af

Browse files
justinchubyCopilot
andcommitted
Align hybrid GGUF tests with main contracts
Preserve the post-#586 fail-closed quantization policy during the hybrid cohort replay. Keep explicit float fallback execution coverage, validate the complete MTP schedule, and pin the new quantized-import architectures. Co-authored-by: Copilot App <[email protected]> Signed-off-by: Justin Chu <[email protected]>
1 parent d13db1b commit 75ac6af

3 files changed

Lines changed: 28 additions & 11 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
"gpt2",
8181
"granitemoe",
8282
"hunyuan-dense",
83+
"lfm2",
8384
"llada",
8485
"llada-moe",
8586
"llama",
@@ -97,6 +98,7 @@
9798
"qwen35",
9899
"qwen35moe",
99100
"qwen3moe",
101+
"qwen3next",
100102
"rnd1",
101103
"smollm3",
102104
"stablelm",

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3638,21 +3638,26 @@ def test_lfm2_float_prefill_decode_threads_only_mixer_specific_state(
36383638
assert outputs[1]["present.1.key"].shape == (1, 2, 4, 8)
36393639
assert all(np.isfinite(output["logits"]).all() for output in outputs)
36403640

3641-
def test_lfm2_quantized_source_dequantizes_without_state_or_logit_loss(
3641+
def test_lfm2_quantized_preservation_fails_closed_and_float_import_executes(
36423642
self, tmp_path: Path
36433643
) -> None:
36443644
from mobius.integrations.gguf import build_from_gguf
36453645

36463646
path = tmp_path / "lfm2-q4.gguf"
36473647
_write_lfm2_gguf(path, quantized=True)
3648-
preserved = build_from_gguf(path, keep_quantized=True)["model"]
3648+
with pytest.raises(
3649+
ValueError,
3650+
match=r"Cannot keep Q4_0 projection .*MatMulNBits",
3651+
):
3652+
build_from_gguf(path, keep_quantized=True)
3653+
36493654
explicit_float = build_from_gguf(path, keep_quantized=False)["model"]
36503655

3651-
assert "MatMulNBits" not in {node.op_type for node in preserved.graph}
3652-
for actual, expected in zip(self._run_lfm2(preserved), self._run_lfm2(explicit_float)):
3653-
assert set(actual) == set(expected)
3654-
for name in actual:
3655-
np.testing.assert_allclose(actual[name], expected[name], rtol=0, atol=0)
3656+
assert "MatMulNBits" not in {node.op_type for node in explicit_float.graph}
3657+
outputs = self._run_lfm2(explicit_float)
3658+
assert outputs[0]["present.0.conv_state"].shape == (1, 32, 2)
3659+
assert outputs[1]["present.1.key"].shape == (1, 2, 4, 8)
3660+
assert all(np.isfinite(output["logits"]).all() for output in outputs)
36563661

36573662
def test_qwen35_float_and_quantized_prefill_decode_thread_mixed_state(
36583663
self, tmp_path: Path

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ def _write_qwen35_mtp_gguf(
6060
# UINT32 == GGUFValueType 4.
6161
writer.add_key_value(f"{architecture}.nextn_predict_layers", mtp_count, 4)
6262
writer.add_key_value(f"{architecture}.attention.key_length", _HD, 4)
63-
writer.add_array(f"{architecture}.attention.recurrent_layers", [False, False])
63+
writer.add_array(
64+
f"{architecture}.attention.recurrent_layers",
65+
[False] * (1 + mtp_count),
66+
)
6467
writer.add_array(f"{architecture}.rope.dimension_sections", [4, 4, 0, 0])
6568
writer.add_ssm_conv_kernel(3)
6669
writer.add_ssm_inner_size(32)
@@ -294,7 +297,7 @@ def _unexpected_build(*args, **kwargs):
294297
monkeypatch.setattr(core_builder, "build_from_module", _unexpected_build)
295298
with pytest.raises(
296299
ValueError,
297-
match=r"nextn_predict_layers=2.*exactly one MTP sidecar head",
300+
match=r"has 2 MTP blocks.*exactly one appended MTP block",
298301
):
299302
build_from_gguf(str(path))
300303
assert built is False
@@ -325,14 +328,21 @@ def test_optional_tables_use_exact_dedicated_or_fallback_contract(
325328
dedicated_head=dedicated_head,
326329
tied_output=tied_output,
327330
)
328-
package = build_from_gguf(path, keep_quantized=quantized)
331+
preserve_quantization = quantized and not (dedicated_embedding or dedicated_head)
332+
if quantized and not preserve_quantization:
333+
with pytest.raises(
334+
ValueError,
335+
match=r"Cannot keep Q4_0 (?:embedding|output) .* quantized",
336+
):
337+
build_from_gguf(path, keep_quantized=True)
338+
package = build_from_gguf(path, keep_quantized=preserve_quantization)
329339
head = package.mtp_head
330340
assert head is not None
331341
target_initializers = package["model"].graph.initializers
332342
assert "model.embed_tokens.weight" in target_initializers
333343
if tied_output:
334344
assert not any(name.startswith("lm_head.") for name in target_initializers)
335-
elif quantized:
345+
elif preserve_quantization:
336346
assert {
337347
"lm_head.weight",
338348
"lm_head.scales",

0 commit comments

Comments
 (0)