Skip to content

Commit 49c6c71

Browse files
justinchubyCopilot
andauthored
Add MiniMax-M2, Mistral4, and GLM-DSA GGUF graphs (#686)
## Summary - add exact explicit-float MiniMax-M2 import with non-square Q/O geometry, full-vector Q/K RMSNorm, partial NeoX RoPE, F32 correction-biased sigmoid routing, and dynamic/static KV coverage - add Mistral4 as its pinned DeepSeek-V2 MLA/MoE architecture, including a dedicated latent K-only cache and metadata-owned YaRN scaling; correct the vendored llama.cpp census that previously mislabeled it as Mistral3 - complete GLM-DSA tensor routing and split K/V-B transforms while preserving the dedicated DSA cache contract and fail-closed MTP boundary - promote all three graph routes in the registry/census and regenerate the GGUF support documentation This includes and supersedes the draft GLM-only work in #682. ## Post-review fixes - canonicalize `glm_dsa` aliases for validation/task/package dispatch while retaining the raw alias prefix for metadata reads; the alias-spelled GGUF proves the exact mixed full/shared indexer schedule, dedicated default task, complete indexer initializer materialization, and executable dense-MLA logits - consume Mistral4's serialized `rope.scaling.yarn_log_multiplier` through `yarn_apply_mscale`; an independent metadata oracle pins `0.0707`, factor `4`, qk dim `4` to `0.6028141`, and mutation to `0.1` discriminates the result - fail closed during Mistral4 config extraction unless the multiplier is a non-boolean finite number in the inclusive semantic range `[0.0, 0.1]`; the wire endpoint is `float(np.float32(0.1))`, used for both validation and normalization - reject NaN, `+inf`, `-inf`, negative values, and the immediate float32 successor above `0.1`; real `GGUFWriter`/`GGUFModel` round trips accept both endpoints and prove finite attention scale and rotary caches before graph execution - call the immediate Mistral4 superclass initializer and force `GlmMoeDsaTask()` when callers omit `task` - reply to and resolve both GitHub review threads ## Evidence and capability boundaries Pinned semantic source: `ggml-org/llama.cpp@8d9af256337d1a501250f9bbf4c0859a654bddd6`. All three real candidates exceed the 16 GiB bounded-artifact policy, so the PR records immutable metadata-only LFS evidence and uses reduced synthetic GGUFs for executable graph/cache parity: | Architecture | Smallest pinned candidate | Complete bytes | |---|---|---:| | `minimax-m2` | `mradermacher/MiniMax-M2-i1-GGUF@2d4f9b1a86d32ce4dfc47db312c8d6fcae8d7b37` / `MiniMax-M2.i1-IQ1_S.gguf` | 46,514,882,176 | | `mistral4` | `unsloth/Mistral-Small-4-119B-2603-GGUF@bd93c721735aa32c035c0f19e738cb3371fd56ff` / `Mistral-Small-4-119B-2603-UD-IQ1_M.gguf` | 32,306,941,632 | | `glm-dsa` | `unsloth/GLM-5.2-GGUF@abc55e72527792c6e77069c99b4cb7de16fa9f23` / six `UD-IQ1_S` shards | 216,715,360,960 | No GGUF payload was downloaded. Hub probes read file metadata only. Runtime support remains `DEFERRED`, and quantization-preserving import is `REJECTED`; callers must use `keep_quantized=False`. GLM routed DSA/MLA MTP, Mistral4 NextN/legacy MLA/Q-LoRA-free/nonzero-temperature layouts, and unowned GLM RoPE scaling all fail closed. There are no production model-ID or revision gates. **Coverage waivers:** real-weight L2/L4/L5 and runtime generation evidence cannot fit the artifact budget. Synthetic tests instead execute full-logit prefill/cached decode, MiniMax static cache, Mistral latent-vs-expanded MLA parity, GLM indexer scheduling, alias-spelled weight closure, and weight application. ## Rebase reconciliation Rebased onto #685 at `86e70a846b572a5266170420373781d2cac23450`. The combined tree preserves the Grok/GroveMoE/Hunyuan-MoE and MiniMax-M2/Mistral4/GLM-DSA cohorts in registry dispatch, tensor-contract validation, architecture fingerprint isolation, model coverage, parity exclusions, census, and generated docs. Combined pins are 105 supported architectures and `107` dependency-blocked / `100` evidence-only / `47` immediately implementable remaining routes. ## Validation - focused combined GGUF/model coverage suite: `2417 passed, 273 skipped` - immutable Hub metadata probes: `3 passed` - broad serial non-integration suite: `8981 passed, 64 skipped, 12 deselected, 1 subtest passed` - `lintrunner f --output oneline --all-files` and `lintrunner -a --output oneline` - `python scripts/generate_gguf_support_docs.py --check` - `git diff --check origin/main...HEAD` - changed-line mypy: `0` errors (`29` pre-existing production-file errors outside changed lines) - independent max-effort review found no significant issues and verified both cohorts, the float32 YaRN endpoint, pre-graph failure timing, fingerprint isolation, tensor mapping, cache semantics, census/docs, and fail-closed ordering Base: `86e70a846b572a5266170420373781d2cac23450` Head: `208f2cb3c7c5215ea9bcf8547a54109acf768bee` --------- Signed-off-by: Justin Chu <[email protected]> Co-authored-by: Copilot App <[email protected]> Copilot-Session: 0ee8718a-33b9-4015-9e20-3745bad54686
1 parent 86e70a8 commit 49c6c71

32 files changed

Lines changed: 3277 additions & 114 deletions

‎docs/api/build_from_gguf.md‎

Lines changed: 8 additions & 8 deletions
Large diffs are not rendered by default.

‎src/mobius/__main__.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,14 @@ def _resolve_static_cache_task(model_type: str) -> ModelTask:
180180
"--static-cache cannot represent Falcon-H1's per-layer K, V, "
181181
"convolution, and SSM states"
182182
)
183+
if model_type == "glm_moe_dsa":
184+
raise ValueError(
185+
"--static-cache cannot represent GLM-DSA's per-layer-varying packed DSA cache"
186+
)
187+
if model_type == "mistral4_gguf":
188+
raise ValueError(
189+
"--static-cache is not implemented for Mistral4's latent K-only cache"
190+
)
183191
if model_type == "gemma4":
184192
from mobius.tasks._gemma4 import Gemma4Task
185193

‎src/mobius/_registry.py‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@
111111
Llama4CausalLMModel,
112112
MageVLForConditionalGeneration,
113113
MaincoderCausalLMModel,
114+
MiniMaxM2GGUFCausalLMModel,
115+
Mistral4GGUFCausalLMModel,
114116
MoECausalLMModel,
115117
MoonshineForConditionalGeneration,
116118
NanoChatCausalLMModel,
@@ -492,6 +494,17 @@ def _detect_fallback_registration(hf_config) -> ModelRegistration | None:
492494
test_model_id="Maincode/Maincoder-1B",
493495
test_revision="088ec98640bdeb105f46a9ef6a1370ed5d0d2ea5",
494496
),
497+
"minimax_m2_gguf": ModelRegistration(
498+
MiniMaxM2GGUFCausalLMModel,
499+
family="minimax",
500+
variant="gguf",
501+
),
502+
"mistral4_gguf": ModelRegistration(
503+
Mistral4GGUFCausalLMModel,
504+
task="mistral4-gguf-text-generation",
505+
family="mistral",
506+
variant="gguf",
507+
),
495508
"bloom": ModelRegistration(BloomCausalLMModel),
496509
"orion": ModelRegistration(LayerNormCausalLMModel),
497510
"chatglm": ModelRegistration(ChatGLMCausalLMModel),

‎src/mobius/components/_deepseek_mla.py‎

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ def __init__(
4545
config: ArchitectureConfig,
4646
scale: float | None = None,
4747
linear_class: type | None = None,
48+
split_kv_b: bool = False,
4849
):
4950
super().__init__()
5051
if linear_class is None:
@@ -82,12 +83,25 @@ def __init__(
8283
bias=False,
8384
)
8485
self.kv_a_layernorm = RMSNorm(self.kv_lora_rank, eps=config.rms_norm_eps)
85-
# Decompresses latent KV into per-head k_nope + v
86-
self.kv_b_proj = linear_class(
87-
self.kv_lora_rank,
88-
self.num_heads * (self.qk_nope_head_dim + self.v_head_dim),
89-
bias=False,
90-
)
86+
self._split_kv_b = split_kv_b
87+
if split_kv_b:
88+
self.k_b_proj = linear_class(
89+
self.kv_lora_rank,
90+
self.num_heads * self.qk_nope_head_dim,
91+
bias=False,
92+
)
93+
self.v_b_proj = linear_class(
94+
self.kv_lora_rank,
95+
self.num_heads * self.v_head_dim,
96+
bias=False,
97+
)
98+
else:
99+
# Decompresses latent KV into per-head k_nope + v
100+
self.kv_b_proj = linear_class(
101+
self.kv_lora_rank,
102+
self.num_heads * (self.qk_nope_head_dim + self.v_head_dim),
103+
bias=False,
104+
)
91105

92106
self.o_proj = linear_class(
93107
self.num_heads * self.v_head_dim,
@@ -154,18 +168,28 @@ def forward(
154168

155169
# Decompress latent KV → per-head k_nope + v
156170
k_pass = self.kv_a_layernorm(op, k_pass)
157-
kv_decompressed = self.kv_b_proj(op, k_pass)
158-
# (B, S, num_heads * (nope + v_dim)) → (B, S, num_heads, nope + v_dim)
159-
kv_decompressed = op.Reshape(
160-
kv_decompressed,
161-
[0, 0, self.num_heads, self.qk_nope_head_dim + self.v_head_dim],
162-
)
163-
k_nope, value_states = op.Split(
164-
kv_decompressed,
165-
[self.qk_nope_head_dim, self.v_head_dim],
166-
axis=-1,
167-
_outputs=2,
168-
)
171+
if self._split_kv_b:
172+
k_nope = op.Reshape(
173+
self.k_b_proj(op, k_pass),
174+
[0, 0, self.num_heads, self.qk_nope_head_dim],
175+
)
176+
value_states = op.Reshape(
177+
self.v_b_proj(op, k_pass),
178+
[0, 0, self.num_heads, self.v_head_dim],
179+
)
180+
else:
181+
kv_decompressed = self.kv_b_proj(op, k_pass)
182+
# (B, S, num_heads * (nope + v_dim)) → (B, S, num_heads, nope + v_dim)
183+
kv_decompressed = op.Reshape(
184+
kv_decompressed,
185+
[0, 0, self.num_heads, self.qk_nope_head_dim + self.v_head_dim],
186+
)
187+
k_nope, value_states = op.Split(
188+
kv_decompressed,
189+
[self.qk_nope_head_dim, self.v_head_dim],
190+
axis=-1,
191+
_outputs=2,
192+
)
169193
# k_nope: (B, S, H, nope_dim) → (B, S, H*nope_dim)... not needed yet
170194
# value_states: (B, S, H, v_dim) → (B, S, H*v_dim) for Attention op
171195
value_states = op.Reshape(value_states, [0, 0, -1])

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

Lines changed: 114 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -505,11 +505,6 @@
505505
"Q/K permutation, optional long/short RoPE tensors, and a conditional dense-or-MoE "
506506
"loader. The existing MiniCPM graph does not prove this complete GGUF contract."
507507
),
508-
"minimax-m2": (
509-
"MiniMax-M2 uses full-vector Q/K norms, partial RoPE, and all-layer "
510-
"correction-biased routed experts under metadata-selected gating. Mobius has no "
511-
"exact graph or suffix-safe expert import for that topology."
512-
),
513508
"minimax-m3": (
514509
"MiniMax-M3 adds F32 sparse-indexer tensors and a second index-key cache with "
515510
"position/cell maps, block masks, rollback, and reorder semantics alongside main "
@@ -584,11 +579,6 @@
584579
"KV cache, and three chained heads selected by offsets. Mobius permits one head "
585580
"and cannot preserve that state or FP8 converter transform."
586581
),
587-
"mistral4": (
588-
"Mistral4 has no NextN metadata or MTP graph; it inherits Mistral3's conditional "
589-
"dense/MoE tensor loader and overrides graph construction. It is not llama, "
590-
"mistral alias text, or any DeepSeek/Qwen MTP family."
591-
),
592582
"step35": (
593583
"Step3.5 executes one or more interleaved-SWA NextN heads with optional gates, "
594584
"routed/shared experts, centered-norm transforms, per-layer head geometry, and "
@@ -1334,6 +1324,42 @@
13341324
"runtime packaging remains tracked by #605."
13351325
),
13361326
),
1327+
GGUFArchitectureSpec(
1328+
gguf_arch="minimax-m2",
1329+
model_type="minimax_m2_gguf",
1330+
module_type="minimax_m2_gguf",
1331+
config_key_map="minimax_m2",
1332+
config_postprocessor="minimax_m2",
1333+
tensor_map_recipe=("minimax_m2",),
1334+
required_metadata=(
1335+
"context_length",
1336+
"embedding_length",
1337+
"feed_forward_length",
1338+
"block_count",
1339+
"attention.head_count",
1340+
"attention.head_count_kv",
1341+
"attention.key_length",
1342+
"attention.value_length",
1343+
"attention.layer_norm_rms_epsilon",
1344+
"rope.freq_base",
1345+
"rope.dimension_count",
1346+
"expert_count",
1347+
"expert_used_count",
1348+
"expert_feed_forward_length",
1349+
"expert_gating_func",
1350+
),
1351+
runtime=Support.DEFERRED,
1352+
quantized_import=Support.REJECTED,
1353+
reason=(
1354+
"Exact explicit-float import owns MiniMax-M2's non-square Q/O geometry, "
1355+
"full-vector Q/K RMSNorm, partial NeoX RoPE, standard dynamic/static KV cache, "
1356+
"and F32 selection-biased sigmoid MoE routing. Loader-accepted Q/K/V biases "
1357+
"and fused QKV are rejected because the pinned graph ignores or cannot execute "
1358+
"them. Packed projection/expert import and runtime packaging remain deferred; "
1359+
"the smallest immutable public GGUF is 46,514,882,176 bytes, above the "
1360+
"16 GiB evidence budget. Use keep_quantized=False."
1361+
),
1362+
),
13371363
GGUFArchitectureSpec(
13381364
gguf_arch="plamo",
13391365
model_type="plamo",
@@ -2131,6 +2157,48 @@
21312157
runtime=Support.DEFERRED,
21322158
reason=_DEEPSEEK4_GGUF_GRAPH_REASON,
21332159
),
2160+
GGUFArchitectureSpec(
2161+
gguf_arch="mistral4",
2162+
model_type="mistral4_gguf",
2163+
module_type="mistral4_gguf",
2164+
config_key_map="mistral4",
2165+
config_postprocessor="mistral4",
2166+
tensor_map_recipe=("mistral4",),
2167+
tensor_processor="mistral4",
2168+
required_metadata=(
2169+
"context_length",
2170+
"embedding_length",
2171+
"feed_forward_length",
2172+
"block_count",
2173+
"attention.head_count",
2174+
"attention.head_count_kv",
2175+
"attention.key_length",
2176+
"attention.value_length",
2177+
"attention.key_length_mla",
2178+
"attention.value_length_mla",
2179+
"attention.q_lora_rank",
2180+
"attention.kv_lora_rank",
2181+
"attention.layer_norm_rms_epsilon",
2182+
"rope.freq_base",
2183+
"rope.dimension_count",
2184+
"expert_count",
2185+
"expert_used_count",
2186+
"expert_feed_forward_length",
2187+
"expert_shared_count",
2188+
),
2189+
rope_interleave=True,
2190+
runtime=Support.DEFERRED,
2191+
quantized_import=Support.REJECTED,
2192+
reason=(
2193+
"Exact explicit-float import owns Mistral4's DeepSeek-V2 MLA projections, "
2194+
"dense-prefix plus mandatory shared/routed MoE blocks, YaRN scaling, and one "
2195+
"graph-visible latent-plus-RoPE K cache per layer. Legacy non-MLA, Q-LoRA-free, "
2196+
"temperature-scaled, and NextN layouts fail closed. Packed import and runtime "
2197+
"packaging remain deferred; the smallest immutable public GGUF is "
2198+
"32,306,941,632 bytes, above the 16 GiB evidence budget. "
2199+
"Use keep_quantized=False."
2200+
),
2201+
),
21342202
# GLM-5.2 GGUFs (e.g. unsloth/GLM-5.2-GGUF) tag the architecture 'glm-dsa'
21352203
# (MLA + DeepSeek Sparse Attention + MoE) and mobius's registry key is
21362204
# 'glm_moe_dsa'. The format bridge is keyed on the authoritative
@@ -2142,12 +2210,43 @@
21422210
model_type="glm_moe_dsa",
21432211
aliases=frozenset({"glm_dsa"}),
21442212
config_key_map="glm_dsa",
2145-
tensor_map=Support.DEFERRED,
2213+
config_postprocessor="glm_dsa",
2214+
tensor_map_recipe=("glm_dsa",),
2215+
tensor_processor="glm_dsa",
2216+
required_metadata=(
2217+
"context_length",
2218+
"embedding_length",
2219+
"feed_forward_length",
2220+
"block_count",
2221+
"attention.head_count",
2222+
"attention.head_count_kv",
2223+
"attention.key_length",
2224+
"attention.value_length",
2225+
"attention.key_length_mla",
2226+
"attention.value_length_mla",
2227+
"attention.q_lora_rank",
2228+
"attention.kv_lora_rank",
2229+
"attention.layer_norm_rms_epsilon",
2230+
"rope.freq_base",
2231+
"rope.dimension_count",
2232+
"expert_count",
2233+
"expert_used_count",
2234+
"expert_feed_forward_length",
2235+
"expert_shared_count",
2236+
"attention.indexer.head_count",
2237+
"attention.indexer.key_length",
2238+
"attention.indexer.top_k",
2239+
),
2240+
rope_interleave=True,
2241+
quantized_import=Support.REJECTED,
21462242
reason=(
2147-
"Config extraction and the glm_moe_dsa graph are both available, but "
2148-
"no GGUF→HuggingFace tensor-name mapping has been written for GLM-5.2's "
2149-
"MLA + DSA-indexer tensor families yet, so weights cannot be routed "
2150-
"into the graph. " + _NO_TENSOR_MAP
2243+
"Exact explicit-float MLA, DSA indexer, dense-prefix/routed-MoE tensor routing, "
2244+
"and packed dynamic-cache graph construction are covered. Packed import remains "
2245+
"rejected because GLM-5.2's rank-3 K/V-B transforms and correction-biased routed "
2246+
"experts do not have an independently proven storage-preserving runtime path. "
2247+
"The released GGUF also carries a routed DSA/MLA MTP block outside the current "
2248+
"sidecar ABI, and representative real-weight runtime evidence exceeds the 16 GiB "
2249+
"artifact budget. Use keep_quantized=False."
21512250
),
21522251
),
21532252
GGUFArchitectureSpec(

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
#: Number of importable architectures. Pinned so that adding support is a
6161
#: deliberate act that also updates the documented support matrix, and so that
6262
#: accidentally losing an architecture is a failure rather than a silence.
63-
_EXPECTED_SUPPORTED_COUNT = 102
63+
_EXPECTED_SUPPORTED_COUNT = 105
6464
_PROMOTED_CONVENTIONAL_DECODERS = frozenset(
6565
{
6666
"bitnet",
@@ -85,6 +85,8 @@
8585
"gemma-embedding",
8686
"llama-embed",
8787
"maincoder",
88+
"minimax-m2",
89+
"mistral4",
8890
"starcoder",
8991
"xverse",
9092
}
@@ -328,6 +330,8 @@ def test_every_float_importable_architecture_has_a_quantized_verdict(self) -> No
328330
"mamba",
329331
"mamba2",
330332
"maincoder",
333+
"minimax-m2",
334+
"mistral4",
331335
"nemotron_h",
332336
"nemotron_h_moe",
333337
"neo-bert",
@@ -343,6 +347,7 @@ def test_every_float_importable_architecture_has_a_quantized_verdict(self) -> No
343347
"grok",
344348
"grovemoe",
345349
"hunyuan-moe",
350+
"glm-dsa",
346351
"hy_v3",
347352
"jais",
348353
"mpt",

0 commit comments

Comments
 (0)