Skip to content

Commit 781bb67

Browse files
justinchubyCopilot
andauthored
Add hybrid attention/recurrent GGUF cohort (#587)
## Summary - add pinned llama.cpp GGUF support for `lfm2`, `qwen35`, `qwen35moe`, and `qwen3next` - reconstruct exact per-layer attention/recurrent schedules and validate architecture dimensions and metadata fail-closed - enforce suffix-exact mixer tensor contracts, safe fused expert/V-head transforms, and no-drop quantization handling - emit deterministic mixed KV/conv/recurrent state ABIs and reject incompatible generic/static cache tasks - document pinned real-artifact header censuses and keep all four runtime verdicts deferred pending independent full-logit and stateful generation parity Stacked on #586 (`justinchuby-add-audio-codec-gguf-cohort`). Routed-expert Qwen3.5-MoE/Qwen3-Next MTP blocks are explicitly rejected until the MTP sidecar can represent their experts; dense Qwen3.5 MTP remains supported. ## Validation - `1640 passed` — full `src/mobius/integrations/gguf` suite - `6105 passed, 52 skipped` — broad non-integration suite - two unchanged unrelated `glm_moe_dsa` failures remain in ONNX checker/output shape inference - full `lintrunner f --output oneline --all-files` passed - final high-confidence review found no significant issues --------- Signed-off-by: Justin Chu <[email protected]> Co-authored-by: Copilot App <[email protected]> Copilot-Session: 5e542579-8cc6-4fcf-9019-0af2824b73bf
1 parent ea7f072 commit 781bb67

21 files changed

Lines changed: 2108 additions & 130 deletions

‎docs/api/build_from_gguf.md‎

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ reason.
177177
| `internlm2` | — | `internlm2` | supported | rejected |
178178
| `jina-bert-v2` | — | — | config deferred; tensor_map deferred; graph deferred; runtime deferred | unreachable |
179179
| `jina-bert-v3` | — | — | config deferred; tensor_map deferred; graph deferred; runtime deferred | unreachable |
180+
| `lfm2` | — | `lfm2` | runtime deferred | supported |
180181
| `llada` | — | `llada` | runtime deferred | supported |
181182
| `llada-moe` | — | `llada` | runtime deferred | supported |
182183
| `llama` | `mistral` | `llama` | supported | supported |
@@ -198,9 +199,10 @@ reason.
198199
| `qwen2` | — | `qwen2` | supported | supported |
199200
| `qwen2moe` | `qwen2_moe` | `qwen2_moe` | runtime deferred | supported |
200201
| `qwen3` | — | `qwen3` | supported | supported |
201-
| `qwen35` | — | `qwen3_5_text` | supported | supported |
202-
| `qwen35moe` | — | `qwen3_5_moe` | supported | supported |
202+
| `qwen35` | — | `qwen3_5_text` | runtime deferred | supported |
203+
| `qwen35moe` | — | `qwen3_5_moe` | runtime deferred | supported |
203204
| `qwen3moe` | `qwen3_moe` | `qwen3_moe` | runtime deferred | supported |
205+
| `qwen3next` | — | `qwen3_next` | runtime deferred | supported |
204206
| `qwen3tts` | — | — | config deferred; tensor_map deferred; graph deferred; runtime deferred | unreachable |
205207
| `rnd1` | — | `llada` | runtime deferred | supported |
206208
| `rwkv6` | — | — | config deferred; tensor_map deferred; graph deferred; runtime deferred | unreachable |
@@ -481,6 +483,56 @@ parity are still required for T5, and independently sourced full encoder-hidden
481483
parity is still required for T5 encoder, before either runtime verdict can become
482484
supported.
483485

486+
### Hybrid attention/recurrent GGUF contract
487+
488+
`lfm2`, `qwen35`, `qwen35moe`, and `qwen3next` use a mixed-state ABI. Full
489+
attention layers alone expose `past_key_values.N.key/value`; LFM2 convolution
490+
layers expose one `conv_state`, and gated-DeltaNet layers expose
491+
`conv_state` plus `recurrent_state`. Inputs and matching `present.N.*` outputs
492+
are ordered by decoder layer index. Generic/static KV cache tasks are rejected.
493+
494+
The schedule is reconstructed exactly as pinned llama.cpp does. LFM2 requires a
495+
per-layer `attention.head_count_kv` array (`0` means short convolution).
496+
Qwen hybrids prefer the explicit `attention.recurrent_layers` array; otherwise
497+
they use `full_attention_interval`, whose upstream default is 4. Appended MTP
498+
blocks are excluded from the trunk and must be full attention. Invalid lengths,
499+
zero intervals, recurrent MTP entries, wrong-mixer tensors, extra layers, and
500+
incomplete fused/legacy representations fail before graph construction.
501+
502+
DeltaNet key width is `ssm.state_size`; value-head width is
503+
`ssm.inner_size / ssm.time_step_rank`. The importer validates positive,
504+
divisible head/group/state/conv dimensions and preserves Qwen3.5's M-RoPE
505+
sections. Qwen3.5 reverses llama.cpp's V-head tiling; Qwen3-Next deliberately
506+
does not. No architecture in this cohort applies a Llama Q/K rotary
507+
permutation. Fused experts are gate-then-up in ascending expert order.
508+
Quantization scale/input-scale sidecars are rejected rather than dropped when
509+
Mobius cannot express them, and recurrent convolution/state roles use the float
510+
path.
511+
512+
Pinned pre-download artifact census:
513+
514+
| Architecture | GGUF revision and file | Size / LFS SHA-256 | Header census |
515+
|---|---|---|---|
516+
| LFM2 | `LiquidAI/LFM2.5-350M-GGUF@d86ad5aad24b8bd87a7c4821439e63e7ba589bc3` / `LFM2.5-350M-Q4_K_M.gguf` | 229,312,224 bytes / `7e6f72643caafc9a68256686638c4d7916f2cec76d1df478d4c3ddcd95a6aed4` | Bundled tokenizer/config metadata; 148 tensors, 16 layers, KV schedule `[0,0,8,0,0,8,0,0,8,0,8,0,8,0,8,0]`; F32/Q4_K/Q6_K |
517+
| Qwen3.5 dense | `ggml-org/Qwen3.5-0.8B-GGUF@8fea620810c4afa23dd6443f999a48574c1611a3` / `Qwen3.5-0.8B-Q4_0.gguf` | 563,036,064 bytes / `57d1997790d1744fba5b40a7317df71ea5e2acee28c47e78f0cce39c0703f8cf` | Bundled tokenizer/config metadata; 320 tensors, 24 layers, interval 4 with no explicit recurrent array; F32/Q4_0/Q8_0 |
518+
519+
No reasonably sized, immutable Qwen3.5-MoE artifact is active in the pinned
520+
llama.cpp corpus, and official Qwen3-Next GGUFs are split 80B artifacts. All
521+
four runtime verdicts therefore remain **deferred**. Graph/state threading is
522+
covered synthetically, but publication still requires independent real-weight
523+
full-logit parity and deterministic stateful generation parity. Mobius exposes
524+
only the latest recurrent state, not llama.cpp's optional bounded rollback
525+
snapshot planes; rollback/reorder-capable runtime packaging must remain
526+
disabled until that ABI is represented explicitly. Dense Qwen3.5 MTP sidecars
527+
use the post-final-norm `mtp_seed` output while preserving pre-norm
528+
`hidden_states.N` captures. Optional dedicated `nextn.embed_tokens`,
529+
`nextn.shared_head_norm`, and `nextn.shared_head_head` tensors are consumed
530+
when present; otherwise the sidecar explicitly falls back to the backbone
531+
embedding, final norm, and tied or untied output head. Qwen3.5-MoE and
532+
Qwen3-Next MTP blocks are rejected because the current sidecar builder cannot
533+
represent routed experts without dropping tensors. Separate MTP-only files
534+
are outside this cohort.
535+
484536
### Pure recurrent Mamba evidence
485537

486538
`mamba` and `mamba2` have config, suffix-exact C++ tensor-name closure,

‎src/mobius/__main__.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,9 @@ def _cmd_build_gguf(args: argparse.Namespace) -> None:
704704
)
705705

706706
spec_path = write_mtp_speculator_metadata(
707-
output_dir, backbone_config=getattr(pkg, "config", None)
707+
output_dir,
708+
backbone_config=getattr(pkg, "config", None),
709+
proposer_config=getattr(mtp_head, "config", None),
708710
)
709711
if spec_path is not None:
710712
print(f" speculator: {spec_path}")

‎src/mobius/_configs/_base.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,9 @@ class ArchitectureConfig(BaseModelConfig):
678678
# ``model(..., output_hidden_states=True).hidden_states[k + 1]`` in
679679
# transformers (where index 0 is the embedding output).
680680
output_layer_indices: list[int] | None = None
681+
# Emit the post-final-norm state as ``mtp_seed``. This is separate from
682+
# output_layer_indices, whose hidden_states.N outputs remain pre-final-norm.
683+
output_final_hidden_state: bool = False
681684

682685
@classmethod
683686
def from_transformers(cls, config, parent_config=None) -> ArchitectureConfig:
@@ -1716,6 +1719,9 @@ class Qwen35MtpConfig(CausalLMConfig):
17161719
(64-layer, hybrid) stack — the MTP head has exactly one layer.
17171720
"""
17181721

1722+
use_dedicated_embeddings: bool = False
1723+
use_dedicated_lm_head: bool = False
1724+
17191725
@classmethod
17201726
def from_transformers(cls, config, parent_config=None) -> Qwen35MtpConfig:
17211727
hf_config = config

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

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,19 +360,73 @@
360360
runtime=Support.DEFERRED,
361361
reason=_DIFFUSION_RUNTIME_VALIDATION_PENDING,
362362
),
363+
GGUFArchitectureSpec(
364+
gguf_arch="lfm2",
365+
model_type="lfm2",
366+
tensor_map_recipe=("lfm2",),
367+
required_metadata=(
368+
"attention.head_count_kv",
369+
"attention.layer_norm_rms_epsilon",
370+
"shortconv.l_cache",
371+
),
372+
runtime=Support.DEFERRED,
373+
reason=_RECURRENT_RUNTIME_VALIDATION_PENDING,
374+
),
363375
GGUFArchitectureSpec(
364376
gguf_arch="qwen35",
365377
model_type="qwen3_5_text",
366378
tensor_map_recipe=("llama", "qwen35_hybrid_extras"),
367379
offset_norm=True,
368380
v_head_reorder=True,
381+
required_metadata=(
382+
"attention.layer_norm_rms_epsilon",
383+
"rope.dimension_sections",
384+
"ssm.conv_kernel",
385+
"ssm.group_count",
386+
"ssm.inner_size",
387+
"ssm.state_size",
388+
"ssm.time_step_rank",
389+
),
390+
runtime=Support.DEFERRED,
391+
reason=_RECURRENT_RUNTIME_VALIDATION_PENDING,
369392
),
370393
GGUFArchitectureSpec(
371394
gguf_arch="qwen35moe",
372395
model_type="qwen3_5_moe",
373396
tensor_map_recipe=("llama", "moe_extras", "qwen35_hybrid_extras"),
374397
offset_norm=True,
375398
v_head_reorder=True,
399+
required_metadata=(
400+
"attention.layer_norm_rms_epsilon",
401+
"expert_count",
402+
"expert_used_count",
403+
"rope.dimension_sections",
404+
"ssm.conv_kernel",
405+
"ssm.group_count",
406+
"ssm.inner_size",
407+
"ssm.state_size",
408+
"ssm.time_step_rank",
409+
),
410+
runtime=Support.DEFERRED,
411+
reason=_RECURRENT_RUNTIME_VALIDATION_PENDING,
412+
),
413+
GGUFArchitectureSpec(
414+
gguf_arch="qwen3next",
415+
model_type="qwen3_next",
416+
tensor_map_recipe=("llama", "moe_extras", "qwen3next_hybrid_extras"),
417+
offset_norm=True,
418+
required_metadata=(
419+
"attention.layer_norm_rms_epsilon",
420+
"expert_count",
421+
"expert_used_count",
422+
"ssm.conv_kernel",
423+
"ssm.group_count",
424+
"ssm.inner_size",
425+
"ssm.state_size",
426+
"ssm.time_step_rank",
427+
),
428+
runtime=Support.DEFERRED,
429+
reason=_RECURRENT_RUNTIME_VALIDATION_PENDING,
376430
),
377431
# ---------------------------------------------------------------- Gemma
378432
GGUFArchitectureSpec(

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

Lines changed: 3 additions & 1 deletion
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",
@@ -152,7 +154,7 @@ def test_a_buildable_architecture_resolves_in_the_mobius_registry(self, spec) ->
152154

153155
def test_the_supported_set_is_pinned(self) -> None:
154156
"""Gaining or losing support is a deliberate, reviewable change."""
155-
assert len(supported_architectures()) == _EXPECTED_SUPPORTED_COUNT + 2
157+
assert len(supported_architectures()) == _EXPECTED_SUPPORTED_COUNT + 4
156158

157159
def test_quantized_import_set_is_pinned(self) -> None:
158160
"""Builder acceptance and rejection must come from an explicit policy set."""

0 commit comments

Comments
 (0)