Skip to content

Enable direct GLM-5.2 GGUF tensor mapping - #682

Open
justinchuby wants to merge 2 commits into
mainfrom
tyrell/glm52-real-preflight
Open

Enable direct GLM-5.2 GGUF tensor mapping#682
justinchuby wants to merge 2 commits into
mainfrom
tyrell/glm52-real-preflight

Conversation

@justinchuby

@justinchuby justinchuby commented Aug 27, 2026

Copy link
Copy Markdown
Member

Summary

  • promote glm-dsa from deferred tensor mapping to the existing glm_moe_dsa graph
  • restore official GLM-5.2 MLA/DSA/MoE config fields and map all base-decoder tensor families
  • represent GGUF's split K-B/V-B projections directly; quantized layout changes use the existing per-projection requantization path, never whole-model dequantization
  • retain the fail-closed routed DSA/MLA MTP rejection

HEAD: 5163cdc2082bad63a2ec87f41e9400890ea93443

Official checkpoint evidence

Source: UD-IQ1_S, 6 shards, exactly 216,715,360,960 bytes. Header-only validation found 1,809 tensors and 0 unmapped base-decoder tensors; the 21 remaining tensors are the appended routed DSA/MLA MTP block. No checkpoint bytes were copied.

Exact projection inventory:

  • dense layers 0-2: gate/up Q5_K, down Q6_K
  • routed gate/up IQ1_S: layers 3-5, 7, 10-28, 30-38, 49-67, 69, 71
  • routed gate/up IQ2_XXS: layers 6, 8-9, 29, 39-48, 68, 70, 72-77
  • routed down IQ3_XXS: layers 3-7, 9-74; IQ4_XS: layer 8 and 75-77
  • shared gate/up Q5_K: layers 3-7, 9-78; layer 8 is Q6_K
  • shared down Q6_K: layers 3-7, 9-78; layer 8 is Q8_0
  • router weights: F32
  • appended MTP layer 78: routed gate/up Q2_K, routed down Q3_K

Real streaming attempt

env -u MOBIUS_ALLOW_DENSE_MOE_EXPERTS -u MOBIUS_ENABLE_BQMOE_PERPROJ_V2 \
  PYTHONPATH=src PYTHONUNBUFFERED=1 python3 -c \
  "from mobius.integrations.gguf import build_from_gguf; build_from_gguf('/datadisks/disk5/justinchu/onnx-genai-models/unsloth-GLM-5.2-GGUF/checkpoint/UD-IQ1_S/GLM-5.2-UD-IQ1_S-00001-of-00006.gguf', keep_quantized=True, execution_provider='default', allow_dense_moe=False)"

No-dense-fallback evidence is explicit in the command: the opt-in environment variable is unset and allow_dense_moe=False. Routed IQ expert bytes stay on the native quantized MoE path.

First deterministic blocker:

NotImplementedError: glm-dsa GGUF MTP is rejected: the MTP block carries GLM DSA/MLA and routed-expert semantics; pinned loader behavior=executed-sidecar, block kind=routed-dsa-mla

Responsible API: mobius.integrations.gguf._mtp.validate_mtp_tensor_contract. The next slice is a dedicated GLM routed DSA/MLA MTP sidecar; this PR does not bypass, truncate, densely lower, or redesign it and does not touch the native CUDA IQ consumer.

Bytes and files

  • input: 6 GGUF files / 216,715,360,960 bytes
  • preflight projected output: 205,391,926,272 bytes
  • actual emitted output: 0 files / 0 bytes (validation stopped before publication)
  • /datadisks/disk5 free-space accounting: preflight delta 0; final attempt sample changed by 16,384 bytes while the checkpoint remained exactly the same six files and no export artifact appeared

Validation

  • 1567 passed, 1 skipped across registry, config mapping, tensor mapping/processors, GLM integration/model, and MTP tests
  • generated GGUF documentation check passed
  • git diff --check passed
  • official config closure: 78 base layers, 64 heads, Q-LoRA 2048, KV-LoRA 512, NoPE 192, RoPE 64, V 256, 256 experts, top-8

@justinchuby
justinchuby force-pushed the tyrell/glm52-real-preflight branch from c34b519 to 93e0fc6 Compare August 27, 2026 21:37
Promote glm-dsa GGUF import through exact config restoration, MLA/DSA tensor mappings, and split K/V-B projection handling.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@justinchuby
justinchuby force-pushed the tyrell/glm52-real-preflight branch from 93e0fc6 to 5163cdc Compare August 27, 2026 22:09
@github-actions

github-actions Bot commented Aug 27, 2026

Copy link
Copy Markdown

Performance Comparison

Comparing 2605d6d9ce3353

Model Metric Baseline Current Delta
bert (feature-extraction) model_size_bytes 359 KB 359 KB +0.0%
bert (feature-extraction) num_nodes 68 68 +0.0%
falcon model_size_bytes 364 KB 364 KB +0.0%
falcon num_nodes 66 66 +0.0%
gemma2 model_size_bytes 428 KB 428 KB +0.0%
gemma2 num_nodes 105 105 +0.0%
gpt2 model_size_bytes 324 KB 324 KB +0.0%
gpt2 num_nodes 54 54 +0.0%
llama model_size_bytes 425 KB 425 KB +0.0%
llama num_nodes 60 60 +0.0%
llama (static-cache) model_size_bytes 425 KB 425 KB +0.0%
llama (static-cache) num_nodes 56 56 +0.0%
mamba (ssm-text-generation) model_size_bytes 296 KB 296 KB +0.0%
mamba (ssm-text-generation) num_nodes 94 94 +0.0%
phi3 model_size_bytes 421 KB 421 KB +0.0%
phi3 num_nodes 58 58 +0.0%
phi3 (static-cache) model_size_bytes 421 KB 421 KB +0.0%
phi3 (static-cache) num_nodes 54 54 +0.0%
qwen2 model_size_bytes 425 KB 425 KB +0.0%
qwen2 num_nodes 60 60 +0.0%
qwen2 (static-cache) model_size_bytes 425 KB 425 KB +0.0%
qwen2 (static-cache) num_nodes 56 56 +0.0%
qwen3_5_moe (hybrid-text-generation) model_size_bytes 506 KB 506 KB +0.0%
qwen3_5_moe (hybrid-text-generation) num_nodes 265 265 +0.0%
qwen3_5_text (hybrid-text-generation) model_size_bytes 458 KB 458 KB +0.0%
qwen3_5_text (hybrid-text-generation) num_nodes 127 127 +0.0%
qwen3_5_vl (hybrid-qwen-vl) model_size_bytes 977 KB 977 KB +0.0%
qwen3_5_vl (hybrid-qwen-vl) num_nodes 450 450 +0.0%
t5 (seq2seq) model_size_bytes 836 KB 836 KB +0.0%
t5 (seq2seq) num_nodes 176 176 +0.0%
whisper (speech-to-text) model_size_bytes 1008 KB 1008 KB +0.0%
whisper (speech-to-text) num_nodes 128 128 +0.0%

No performance regressions.

@github-actions

github-actions Bot commented Aug 27, 2026

Copy link
Copy Markdown

🏗️ Architecture Diff

Comparing 2605d6d9ce3353

Model Sub-model Changes Status
bert (feature-extraction) model 0
falcon model 0
gemma2 model 0
gemma4 (gemma4) decoder 0
gemma4 (gemma4) embedding 0
gemma4 (gemma4) vision_encoder 0
gemma4_text model 0
gpt2 model 0
llama model 0
llama (static-cache) model 0
mamba (ssm-text-generation) model 0
phi3 model 0
phi3 (static-cache) model 0
qwen model 0
qwen (static-cache) model 0
qwen2 model 0
qwen2 (static-cache) model 0
qwen2_moe model 0
qwen2_moe (static-cache) model 0
qwen3 model 0
qwen3 (static-cache) model 0
qwen3_5_moe (hybrid-text-generation) model 0
qwen3_5_text (hybrid-text-generation) model 0
qwen3_5_vl (hybrid-qwen-vl) decoder 0
qwen3_5_vl (hybrid-qwen-vl) embedding 0
qwen3_5_vl (hybrid-qwen-vl) vision_encoder 0
qwen3_moe model 0
qwen3_moe (static-cache) model 0
qwen3_next (hybrid-text-generation) model 0
t5 (seq2seq) decoder 0
t5 (seq2seq) encoder 0
whisper (speech-to-text) decoder 0
whisper (speech-to-text) encoder 0

No architecture changes detected.


Legend: ⚪ No change · 🔵 Minor (attrs/inits) · 🟡 Moderate (nodes added/removed) · 🔴 Major (interface changed)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 39ff6824-d35f-4d3b-8f5f-043a7119a100
@justinchuby

Copy link
Copy Markdown
Member Author

Independent revision evidence (Deckard; original author was not consulted):

  • HEAD: 9ce335384cd4329c369b7612830c2fa7dd2ad4c7
  • Dense use_dsa=False now preserves fused kv_b_proj.weight; splitting remains restricted to the explicit DSA graph path. The default/official DSA path and its fail-closed behavior are unchanged.
  • Added exact full graph-parameter alignment coverage for both DSA and dense paths; corrected the previously double-prefixed test fixture.
  • Route census now records the implemented-but-runtime-validation-pending architecture:glm-dsa route as exact evidence-only evidence (108 evidence-only / 52 immediately-implementable).

Validation:

  • python3 -m pytest src/mobius/models/glm_moe_dsa_test.py src/mobius/integrations/gguf/_glm_moe_dsa_test.py src/mobius/integrations/gguf/_tensor_processors_test.py src/mobius/integrations/gguf/_route_census_test.py -q --tb=short95 passed
  • python3 -m pytest tests/build_graph_test.py tests/weight_alignment_test.py -k glm_moe_dsa -q --tb=short5 passed, 1910 deselected
  • Targeted Ruff format check and git diff --checkpassed
  • Full non-integration/non-arch-validation unit suite — 4 failures + 4 errors; all eight reproduce unchanged on rejected HEAD 5163cdc2082bad63a2ec87f41e9400890ea93443 (runtime-evidence identity, Gemma3n/Gemma4 audio-shape, four heterogeneous static-cache metadata cases, ModernBERT decoder parity).

The 216.7 GB checkpoint was not rerun or copied. Please assign an independent reviewer other than the original author and this revision owner. Do not merge pending that review and CI.

@justinchuby

Copy link
Copy Markdown
Member Author

Exact-head CI follow-up for 9ce335384cd4329c369b7612830c2fa7dd2ad4c7: all six test matrix jobs passed (Ubuntu/Windows × Python 3.11/3.12/3.13). Independent review remains requested; no merge.

@justinchuby
justinchuby marked this pull request as ready for review August 28, 2026 05:53
@justinchuby
justinchuby requested review from a team and a lite review from Copilot August 28, 2026 05:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Enables direct GGUF tensor-name mapping and tensor-shape restoration for the GLM-5.2 glm-dsa architecture so GGUF weights can be routed into the existing glm_moe_dsa graph (without whole-model dequantization), while keeping the routed DSA/MLA MTP block fail-closed.

Changes:

  • Split MLA KV-B projection handling for GLM-5.2 by emitting distinct k_b_proj / v_b_proj parameters in the DSA attention path and adding a preprocess_weights() shim to split HF’s fused kv_b_proj.
  • Add glm-dsa GGUF tensor mapping + tensor processor to restore GGUF’s rank-3 K/V-B layouts to the graph’s expected linear row-major form, and wire this through the GGUF architecture registry.
  • Update/expand tests and documentation to reflect GLM-5.2’s official config geometry and the newly importable architecture count.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/mobius/models/glm_moe_dsa.py Emit split KV-B projections in GLM DSA attention and split HF fused KV-B weights during preprocessing.
src/mobius/models/glm_moe_dsa_test.py Add coverage ensuring preprocess_weights() covers all graph parameters and validates KV-B splitting.
src/mobius/integrations/gguf/_tensor_processors.py Add glm_dsa tensor processor to reshape split MLA K/V-B tensors into linear row order.
src/mobius/integrations/gguf/_tensor_processors_test.py Add unit test validating GLM-5.2 MLA K/V-B layout restoration.
src/mobius/integrations/gguf/_tensor_mapping.py Add GGUF→HF tensor-name mapping recipe for glm-dsa.
src/mobius/integrations/gguf/_route_census_test.py Update pinned route census expectations for architecture:glm-dsa.
src/mobius/integrations/gguf/_glm_moe_dsa_test.py Pin official GLM-5.2 geometry/config expectations and validate tensor-name mappings + config rejection cases.
src/mobius/integrations/gguf/_config_mapping.py Restore official GLM-5.2 config fields/constraints in GGUF postprocessing and enforce SIGMOID gating requirement.
src/mobius/integrations/gguf/_builder.py Treat glm-dsa MLA K/V-B projections as reshaped tensors (special-casing native-block replacement and quant import routing).
src/mobius/integrations/gguf/_arch_registry.py Promote glm-dsa from deferred tensor mapping to supported tensor mapping + processor + postprocessor wiring.
src/mobius/integrations/gguf/_arch_registry_test.py Update expected supported architecture count and include glm-dsa in the supported set.
src/mobius/components/_deepseek_mla.py Add optional split-KV-B projection construction/forward path for MLA modules.
docs/api/build_from_gguf.md Update support-matrix counts and move glm-dsa into the importable set while keeping runtime deferred.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

justinchuby added a commit that referenced this pull request Aug 28, 2026
## 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 <justinchuby@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 0ee8718a-33b9-4015-9e20-3745bad54686
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants