Skip to content

Commit 6715f09

Browse files
justinchubyCopilot
andauthored
Defer remaining hybrid GGUF architectures (#594)
## Summary - pin suffix-exact loader tensor inventories for `bailingmoe3`, `deepseek4`, `kimi-k3`, `kimi-linear`, and `lfm2moe` at llama.cpp `8d9af256337d1a501250f9bbf4c0859a654bddd6` - register explicit DEFERRED verdicts that reject before config extraction, quantization handling, model lookup, or graph construction - remove the unsafe DeepSeek-V4 GGUF dense-fallback claim while preserving the valid Hugging Face `deepseek_v4` registration - document exact schedule, mixed-state, MoE, auxiliary/MTP, and quantization constraints ## Validation - focused GGUF tests: 885 passed - broad non-integration suite excluding unrelated baseline `glm_moe_dsa` shape-inference failure: 6223 passed, 52 skipped - full lint: clean - independent high-confidence review: no significant findings ## Stack Targets `justinchuby-expand-hybrid-gguf-cohort` / #588. --------- Signed-off-by: Justin Chu <[email protected]> Co-authored-by: Copilot App <[email protected]>
1 parent bd54679 commit 6715f09

9 files changed

Lines changed: 180 additions & 179 deletions

File tree

‎docs/api/build_from_gguf.md‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,13 @@ reason.
154154
|---|---|---|---|---|
155155
| `arcee` | — | `arcee` | runtime deferred | supported |
156156
| `arwkv7` | — | — | config deferred; tensor_map deferred; graph deferred; runtime deferred | unreachable |
157+
| `bailingmoe3` | — | — | config deferred; tensor_map deferred; graph deferred; runtime deferred | unreachable |
157158
| `bert` | — | `bert` | runtime deferred | supported |
158159
| `bloom` | — | `bloom` | tensor_map deferred | unreachable |
159160
| `clip` | — | — | config rejected; tensor_map rejected; graph rejected; runtime rejected | unreachable |
160161
| `cohere2` | — | `cohere2` | runtime deferred | supported |
161162
| `deci` | — | `llama` | supported | supported |
162-
| `deepseek4` | — | `deepseek_v4` | supported | supported |
163+
| `deepseek4` | — | — | config deferred; tensor_map deferred; graph deferred; runtime deferred | unreachable |
163164
| `dflash` | — | `DFlashDraftModel` | runtime deferred | supported |
164165
| `dream` | — | `dream` | runtime deferred | supported |
165166
| `eagle3` | — | `Eagle3DraftModel` | runtime deferred | supported |
@@ -180,7 +181,10 @@ reason.
180181
| `jamba` | — | `jamba` | runtime deferred | rejected |
181182
| `jina-bert-v2` | — | — | config deferred; tensor_map deferred; graph deferred; runtime deferred | unreachable |
182183
| `jina-bert-v3` | — | — | config deferred; tensor_map deferred; graph deferred; runtime deferred | unreachable |
184+
| `kimi-k3` | — | — | config deferred; tensor_map deferred; graph deferred; runtime deferred | unreachable |
185+
| `kimi-linear` | — | — | config deferred; tensor_map deferred; graph deferred; runtime deferred | unreachable |
183186
| `lfm2` | — | `lfm2` | runtime deferred | supported |
187+
| `lfm2moe` | — | — | config deferred; tensor_map deferred; graph deferred; runtime deferred | unreachable |
184188
| `llada` | — | `llada` | runtime deferred | supported |
185189
| `llada-moe` | — | `llada` | runtime deferred | supported |
186190
| `llama` | `mistral` | `llama` | supported | supported |

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

Lines changed: 77 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,46 @@
117117
"the wrong recurrence. Build from a supported source/runtime instead."
118118
)
119119

120+
_BAILINGMOE3_GRAPH_REASON = (
121+
"BailingMoE3 alternates head-wise KDA recurrent layers with gated MLA layers, "
122+
"so each sequence carries three causal-convolution histories plus a matrix state "
123+
"alongside attention cache. Its routed sigmoid/correction-bias experts, always-on "
124+
"shared experts, and optional single NextN block also require tensor and task "
125+
"contracts Mobius does not implement. Ordinary KV or Mamba state would be wrong."
126+
)
127+
128+
_DEEPSEEK4_GGUF_GRAPH_REASON = (
129+
"The pinned DeepSeek-V4 GGUF runtime uses a dedicated raw sliding-window, CSA, "
130+
"HCA, and indexer compressed-cache ABI with persistent compressor state, rollback "
131+
"snapshots, four-stream hyper-connections, hash/sqrt-softplus routing, and optional "
132+
"MTP storage. Mobius's Hugging Face DeepSeek-V4 graph intentionally exports a dense "
133+
"attention fallback with ordinary KV state, so it is not an exact GGUF runtime graph."
134+
)
135+
136+
_KIMI_K3_GRAPH_REASON = (
137+
"Kimi-K3 alternates KDA recurrent and NoPE MLA layers and requires convolution plus "
138+
"matrix state, sigmoid routed latent MoE with SiTU experts, optional shared experts, "
139+
"and cross-layer residual banks. Kimi-Linear is not an alias: its gates, expert "
140+
"activation, latent projections, and residual contract differ. Mobius has no exact "
141+
"graph or mixed-state task for either ABI."
142+
)
143+
144+
_KIMI_LINEAR_GRAPH_REASON = (
145+
"Kimi-Linear alternates KDA recurrent and NoPE MLA layers, carrying three rolling "
146+
"convolution histories and a per-head matrix state in addition to attention cache. "
147+
"Its two-stage decay/output gates and sigmoid correction-bias MoE routing are not "
148+
"represented by any Mobius graph or state task; aliasing it to Kimi-K3, Mamba, or "
149+
"ordinary attention would change the model."
150+
)
151+
152+
_LFM2MOE_GRAPH_REASON = (
153+
"LFM2MoE has an arbitrary per-layer attention/short-convolution schedule plus a "
154+
"dense-to-sigmoid-routed-MoE transition. Recurrent layers use F32 rolling convolution "
155+
"state with copy-on-write sequence reorder and bounded rollback snapshots, while "
156+
"attention layers use KV cache. The dense LFM2 graph and ordinary KV/static-cache "
157+
"tasks do not own that mixed state or the expert correction-bias semantics."
158+
)
159+
120160
_ENCODER_RUNTIME_VALIDATION_PENDING = (
121161
"Config extraction, exact pinned tensor closure, encoder-only task dispatch, and "
122162
"synthetic ORT execution are covered, but no pinned real GGUF artifact has passed "
@@ -572,6 +612,38 @@
572612
quantized_import=Support.REJECTED,
573613
reason=_RECURRENT_RUNTIME_VALIDATION_PENDING + " " + _NO_QUANTIZED_PROJECTION_REASON,
574614
),
615+
GGUFArchitectureSpec(
616+
gguf_arch="bailingmoe3",
617+
config=Support.DEFERRED,
618+
tensor_map=Support.DEFERRED,
619+
graph=Support.DEFERRED,
620+
runtime=Support.DEFERRED,
621+
reason=_BAILINGMOE3_GRAPH_REASON,
622+
),
623+
GGUFArchitectureSpec(
624+
gguf_arch="kimi-k3",
625+
config=Support.DEFERRED,
626+
tensor_map=Support.DEFERRED,
627+
graph=Support.DEFERRED,
628+
runtime=Support.DEFERRED,
629+
reason=_KIMI_K3_GRAPH_REASON,
630+
),
631+
GGUFArchitectureSpec(
632+
gguf_arch="kimi-linear",
633+
config=Support.DEFERRED,
634+
tensor_map=Support.DEFERRED,
635+
graph=Support.DEFERRED,
636+
runtime=Support.DEFERRED,
637+
reason=_KIMI_LINEAR_GRAPH_REASON,
638+
),
639+
GGUFArchitectureSpec(
640+
gguf_arch="lfm2moe",
641+
config=Support.DEFERRED,
642+
tensor_map=Support.DEFERRED,
643+
graph=Support.DEFERRED,
644+
runtime=Support.DEFERRED,
645+
reason=_LFM2MOE_GRAPH_REASON,
646+
),
575647
GGUFArchitectureSpec(
576648
gguf_arch="minimax-01",
577649
config=Support.DEFERRED,
@@ -785,10 +857,11 @@
785857
),
786858
GGUFArchitectureSpec(
787859
gguf_arch="deepseek4",
788-
model_type="deepseek_v4",
789-
tensor_map_recipe=("deepseek4",),
790-
config_key_map="deepseek4",
791-
rope_interleave=True,
860+
config=Support.DEFERRED,
861+
tensor_map=Support.DEFERRED,
862+
graph=Support.DEFERRED,
863+
runtime=Support.DEFERRED,
864+
reason=_DEEPSEEK4_GGUF_GRAPH_REASON,
792865
),
793866
# GLM-5.2 GGUFs (e.g. unsloth/GLM-5.2-GGUF) tag the architecture 'glm-dsa'
794867
# (MLA + DeepSeek Sparse Attention + MoE) and mobius's registry key is

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

Lines changed: 80 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@
6767
"bert",
6868
"cohere2",
6969
"deci",
70-
"deepseek4",
7170
"dflash",
7271
"dream",
7372
"eagle3",
@@ -154,7 +153,7 @@ def test_a_buildable_architecture_resolves_in_the_mobius_registry(self, spec) ->
154153

155154
def test_the_supported_set_is_pinned(self) -> None:
156155
"""Gaining or losing support is a deliberate, reviewable change."""
157-
assert len(supported_architectures()) == _EXPECTED_SUPPORTED_COUNT + 7
156+
assert len(supported_architectures()) == _EXPECTED_SUPPORTED_COUNT + 6
158157

159158
def test_falcon_h1_is_not_a_generic_falcon_alias(self) -> None:
160159
"""Falcon-H1 must fail before constructing the incompatible Falcon graph."""
@@ -628,6 +627,85 @@ def test_task_misdispatch_is_refused(self, architecture: str) -> None:
628627
get_arch_spec(architecture)
629628

630629

630+
class TestPinnedRemainingHybridCohort:
631+
"""Pin C06 loader closure while refusing incompatible state/task ABIs."""
632+
633+
_ARCHITECTURES = (
634+
"bailingmoe3",
635+
"deepseek4",
636+
"kimi-k3",
637+
"kimi-linear",
638+
"lfm2moe",
639+
)
640+
_EXPECTED_TENSOR_COUNTS: ClassVar[dict[str, int]] = {
641+
"bailingmoe3": 41,
642+
"deepseek4": 44,
643+
"kimi-k3": 46,
644+
"kimi-linear": 40,
645+
"lfm2moe": 24,
646+
}
647+
648+
@pytest.mark.parametrize("architecture", _ARCHITECTURES)
649+
def test_loader_inventory_is_suffix_exact(self, architecture: str) -> None:
650+
upstream = upstream_architectures()[architecture]
651+
names = set(upstream.tensor_names)
652+
assert len(names) == self._EXPECTED_TENSOR_COUNTS[architecture]
653+
assert upstream.expert_tensor_suffixes == ("weight",)
654+
assert all(name.endswith((".weight", ".bias", ".ssm_a")) for name in names)
655+
assert not any(name.endswith((".scale", ".input_scale")) for name in names)
656+
657+
def test_conditional_tensor_representations_are_not_conflated(self) -> None:
658+
bailing = set(upstream_architectures()["bailingmoe3"].tensor_names)
659+
deepseek = set(upstream_architectures()["deepseek4"].tensor_names)
660+
kimi_k3 = set(upstream_architectures()["kimi-k3"].tensor_names)
661+
kimi_linear = set(upstream_architectures()["kimi-linear"].tensor_names)
662+
lfm2moe = set(upstream_architectures()["lfm2moe"].tensor_names)
663+
664+
assert "blk.{bid}.nextn.eh_proj.weight" in bailing
665+
assert "blk.{bid}.ffn_gate_tid2eid.weight" in deepseek
666+
assert "blk.{bid}.indexer_compressor_kv.weight" in deepseek
667+
assert "blk.{bid}.ffn_routed_down.weight" in kimi_k3
668+
assert "blk.{bid}.attn_res_score.weight" in kimi_k3
669+
assert "blk.{bid}.ssm_g_b.weight" in kimi_linear
670+
assert "blk.{bid}.ssm_g_b.weight" not in kimi_k3
671+
assert "blk.{bid}.shortconv.conv.weight" in lfm2moe
672+
assert "blk.{bid}.ffn_gate_shexp.weight" not in lfm2moe
673+
674+
@pytest.mark.parametrize("architecture", _ARCHITECTURES)
675+
def test_no_unpinned_alias_or_config_mutation_is_reachable(
676+
self, architecture: str
677+
) -> None:
678+
spec = try_get_arch_spec(architecture)
679+
assert spec is not None
680+
assert not spec.aliases
681+
assert spec.model_type is None
682+
assert spec.config_key_map is None
683+
assert all(verdict is Support.DEFERRED for verdict in spec.verdicts.values())
684+
assert architecture not in GGUF_ARCH_TO_MODEL_TYPE
685+
686+
@pytest.mark.parametrize(
687+
("architecture", "state_terms"),
688+
[
689+
("bailingmoe3", ("convolution histories", "matrix state", "NextN")),
690+
("deepseek4", ("compressed-cache", "rollback", "ordinary KV")),
691+
("kimi-k3", ("matrix state", "latent MoE", "residual banks")),
692+
("kimi-linear", ("convolution histories", "matrix state", "correction-bias")),
693+
("lfm2moe", ("rolling convolution", "reorder", "rollback")),
694+
],
695+
)
696+
def test_state_and_schedule_mismatch_is_explicit(
697+
self, architecture: str, state_terms: tuple[str, ...]
698+
) -> None:
699+
reason = try_get_arch_spec(architecture).reason
700+
assert reason is not None
701+
for term in state_terms:
702+
assert term in reason
703+
704+
def test_hugging_face_deepseek_v4_registration_remains_valid(self) -> None:
705+
assert "deepseek_v4" in _REGISTRATIONS
706+
assert try_get_arch_spec("deepseek4").model_type is None
707+
708+
631709
class TestRejectionsAreActionable:
632710
"""An unsupported input must say what it is and what to do instead."""
633711

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4201,7 +4201,19 @@ def test_deferred_audio_architectures_fail_before_all_downstream_stages(
42014201
module_lookup.assert_not_called()
42024202
graph_build.assert_not_called()
42034203

4204-
@pytest.mark.parametrize("architecture", ["minimax-01", "plamo2", "falcon-h1"])
4204+
@pytest.mark.parametrize(
4205+
"architecture",
4206+
[
4207+
"minimax-01",
4208+
"plamo2",
4209+
"falcon-h1",
4210+
"bailingmoe3",
4211+
"deepseek4",
4212+
"kimi-k3",
4213+
"kimi-linear",
4214+
"lfm2moe",
4215+
],
4216+
)
42054217
def test_deferred_second_hybrid_cohort_fails_before_graph_construction(
42064218
self, architecture: str, tmp_path: Path
42074219
) -> None:

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

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -117,31 +117,6 @@
117117
"attention.sliding_window": "sliding_window",
118118
}
119119

120-
_DEEPSEEK4_KEY_MAP = {
121-
"attention.key_length": "head_dim",
122-
"rope.dimension_count": "qk_rope_head_dim",
123-
"attention.q_lora_rank": "q_lora_rank",
124-
"attention.sliding_window": "sliding_window",
125-
"expert_count": "num_local_experts",
126-
"expert_used_count": "num_experts_per_tok",
127-
"expert_feed_forward_length": "moe_intermediate_size",
128-
"expert_shared_count": "n_shared_experts",
129-
"expert_weights_scale": "routed_scaling_factor",
130-
"expert_weights_norm": "norm_topk_prob",
131-
"swiglu_clamp_exp": "swiglu_limit",
132-
"attention.indexer.head_count": "index_n_heads",
133-
"attention.indexer.key_length": "index_head_dim",
134-
"attention.indexer.top_k": "index_topk",
135-
"attention.output_group_count": "o_groups",
136-
"attention.output_lora_rank": "o_lora_rank",
137-
"attention.compress_ratios": "compress_ratios",
138-
"attention.compress_rope_freq_base": "compress_rope_theta",
139-
"hyper_connection.count": "hc_mult",
140-
"hyper_connection.sinkhorn_iterations": "hc_sinkhorn_iters",
141-
"hyper_connection.epsilon": "hc_eps",
142-
"hash_layer_count": "num_hash_layers",
143-
}
144-
145120
# GLM-5.2 ('glm-dsa') shares DeepSeek's MLA + MoE + DSA-indexer metadata layout
146121
# but omits the DeepSeek-V4-only hyper-connection / hash-routing / output-group
147122
# extensions. Keep the map to the discriminating MLA/MoE/DSA keys only, so the
@@ -219,7 +194,6 @@
219194
{
220195
"draft": _DRAFT_KEY_MAP,
221196
"muse_glimmer": _MUSE_GLIMMER_KEY_MAP,
222-
"deepseek4": _DEEPSEEK4_KEY_MAP,
223197
"glm_dsa": _GLM_DSA_KEY_MAP,
224198
"mamba": _MAMBA_KEY_MAP,
225199
"jamba": _JAMBA_KEY_MAP,

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

Lines changed: 0 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -410,69 +410,6 @@ def test_arch_to_model_type_mapping(self):
410410
assert GGUF_ARCH_TO_MODEL_TYPE["qwen2"] == "qwen2"
411411
assert GGUF_ARCH_TO_MODEL_TYPE["qwen35"] == "qwen3_5_text"
412412
assert GGUF_ARCH_TO_MODEL_TYPE["phi3"] == "phi3"
413-
assert GGUF_ARCH_TO_MODEL_TYPE["deepseek4"] == "deepseek_v4"
414-
415-
def test_deepseek4_config_extraction(self):
416-
metadata = {
417-
"general.architecture": "deepseek4",
418-
"deepseek4.embedding_length": 4096,
419-
"deepseek4.block_count": 43,
420-
"deepseek4.attention.head_count": 64,
421-
"deepseek4.attention.head_count_kv": 1,
422-
"deepseek4.attention.key_length": 512,
423-
"deepseek4.context_length": 1048576,
424-
"deepseek4.rope.dimension_count": 64,
425-
"deepseek4.rope.freq_base": 10000.0,
426-
"deepseek4.rope.scaling.type": "yarn",
427-
"deepseek4.rope.scaling.factor": 16.0,
428-
"deepseek4.rope.scaling.original_context_length": 65536,
429-
"deepseek4.rope.scaling.yarn_beta_fast": 32.0,
430-
"deepseek4.rope.scaling.yarn_beta_slow": 1.0,
431-
"deepseek4.attention.layer_norm_rms_epsilon": 1e-6,
432-
"deepseek4.expert_count": 256,
433-
"deepseek4.expert_used_count": 6,
434-
"deepseek4.expert_feed_forward_length": 2048,
435-
"deepseek4.expert_shared_count": 1,
436-
"deepseek4.expert_weights_scale": 1.5,
437-
"deepseek4.expert_weights_norm": True,
438-
"deepseek4.swiglu_clamp_exp": [10.0] * 43,
439-
"deepseek4.attention.q_lora_rank": 1024,
440-
"deepseek4.attention.sliding_window": 128,
441-
"deepseek4.attention.output_group_count": 8,
442-
"deepseek4.attention.output_lora_rank": 1024,
443-
"deepseek4.attention.indexer.head_count": 64,
444-
"deepseek4.attention.indexer.key_length": 128,
445-
"deepseek4.attention.indexer.top_k": 512,
446-
"deepseek4.attention.compress_ratios": [0, 0, 4, 128],
447-
"deepseek4.attention.compress_rope_freq_base": 160000.0,
448-
"deepseek4.hyper_connection.count": 4,
449-
"deepseek4.hyper_connection.sinkhorn_iterations": 20,
450-
"deepseek4.hyper_connection.epsilon": 1e-6,
451-
"deepseek4.hash_layer_count": 3,
452-
}
453-
454-
class _FakeModel:
455-
architecture = "deepseek4"
456-
457-
def __init__(self, values):
458-
self.metadata = values
459-
self.tensor_names = ["token_embd.weight", "output.weight"]
460-
461-
def get_metadata(self, key, default=None):
462-
return self.metadata.get(key, default)
463-
464-
config = gguf_to_config(_FakeModel(metadata))
465-
assert config.model_type == "deepseek_v4"
466-
assert config.head_dim == 512
467-
assert config.qk_rope_head_dim == 64
468-
assert config.num_local_experts == 256
469-
assert config.scoring_func == "sqrtsoftplus"
470-
assert config.hc_mult == 4
471-
assert config.num_hash_layers == 3
472-
assert config.swiglu_limit == pytest.approx(10.0)
473-
assert config.rope_interleave is True
474-
assert config.rope_type == "yarn"
475-
assert config.original_max_position_embeddings == 65536
476413

477414
def test_tie_embeddings_detected(self, tied_gguf: Path):
478415
model = GGUFModel(tied_gguf)

0 commit comments

Comments
 (0)