Skip to content

hadamard_q4_0.py: rotate MLA projections; W4A4 MoE results for Qwen3.6-35B-A3B and GLM-4.7-Flash - #201

Merged
bong-water-water-bong merged 1 commit into
mainfrom
w4a4-moe-mla
Sep 28, 2026
Merged

bong-water-water-bong merged 1 commit into
mainfrom
w4a4-moe-mla

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Follow-up to #199.

  • tools/hadamard_q4_0.py rotates the DeepSeek-2 MLA projections (attn_q_a, attn_q_b, attn_kv_a_mqa, attn_kv_b, attn_k_b, attn_v_b), so GLM-4.7-Flash files take the W4A4 route. Invariant check passes (562 Q4_0 tensors, all rotated).
  • docs/lean.md: measured results on Strix Halo (KLD against each model's Q8_0, wikitext-2 40 x 512, llama-bench 3 runs, ROCmFPX 16b234a3):
Q4_0 rotated Route pp512 tg128 KLD
Qwen3.6-35B-A3B exact int8 1,454 63.3 0.046
W4A4 attn + experts 1,616 63.9 0.077
GLM-4.7-Flash exact int8 904 58.6 0.528
W4A4 attn + experts 1,599 61.9 0.587

GLM-4.7-Flash's high KLD is not W4A4's: a plain unrotated Q4_0 on the exact path scores 0.493, any single tensor group at Q4_0 costs ~0.14, and the Q8_0 reference agrees across backends (KLD 0.015, PPL 10.44 HIP / 11.01 Vulkan). The docs say so and don't recommend the route for that model yet.

🤖 Generated with Claude Code

…6-35B-A3B and GLM-4.7-Flash

The tool now rotates the DeepSeek-2 MLA projections (attn_q_a, attn_q_b,
attn_kv_a_mqa, attn_kv_b, attn_k_b, attn_v_b), so GLM-4.7-Flash files take
the W4A4 route. docs/lean.md gains the measurements: Qwen3.6-35B-A3B +11%
prefill (delta-net layers dominate), GLM-4.7-Flash +77% pp512 at +0.06 KLD,
and a note that GLM-4.7-Flash degrades under plain Q4_0 on its own (KLD 0.49
unrotated, exact path), so the route is not recommended for it yet.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@context7

context7 Bot commented Sep 28, 2026

Copy link
Copy Markdown

Docs7 for 1bit-monster/engine

Result Status Action
Deployment ➖ Not used —
Content review ➖ Did not run. This site has no agent runs available this month. Wait for the monthly reset or check your Docs7 plan. —

Commit 11d9494

@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

199 - Partially compliant

Compliant requirements:

  • third_party/llama.cpp-rocmfpx updated to commit 16b234a3
  • tools/hadamard_q4_0.py updated to rotate MoE experts and shared experts
  • docs/lean.md updated with new documentation and measured results

Non-compliant requirements:

  • None

Requires further human verification:

  • None
⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Missing Invariant Check for MLA Projections

The updated tools/hadamard_q4_0.py script now includes MLA projections (attn_q_a, attn_q_b, attn_kv_a_mqa, attn_kv_b, attn_k_b, attn_v_b) in the rotation logic, but there is no explicit invariant check to ensure that these new projections are correctly rotated. This could lead to incorrect tensor rotations that may affect model accuracy or performance.

# MoE: the routed experts (one [experts, rows, K] stack each, rotated along K like any
# matmul weight) and the shared expert; the router (ffn_gate_inp) is not quantized
"ffn_gate_exps", "ffn_up_exps", "ffn_down_exps",
"ffn_gate_shexp", "ffn_up_shexp", "ffn_down_shexp",
# MLA (DeepSeek-2 family: GLM-4.7-Flash, ...): the query and KV low-rank projections
# and the per-head K/V expansions
"attn_q_a", "attn_q_b", "attn_kv_a_mqa", "attn_kv_b", "attn_k_b", "attn_v_b")
Inconsistent KLD Reporting

The documentation reports KLD values for different models and routes, but there is inconsistency in how these values are presented. Specifically, the KLD values for GLM-4.7-Flash are reported as 0.528 and 0.587, which are significantly higher than those for Qwen3.6-35B-A3B (0.046 and 0.077). This discrepancy should be explained in the documentation, as it may indicate a fundamental issue with how the model is handled under Q4_0 quantization.

| Q4_0, rotated | Route | pp512 | pp2048 | tg128 | PPL | Mean KLD | Same top token |
|---|---|---|---|---|---|---|---|
| Qwen3.6-35B-A3B (Q8_0 PPL 5.825; 401 tensors, 18,832 MiB) | exact int8 | 1,454 | 1,408 | 63.3 | 5.981 | 0.046 | 90.6% |
| | W4A4 on attention only | 1,514 | 1,478 | 64.0 | 6.032 | 0.058 | 89.6% |
| | **W4A4 on attention and experts** | **1,616** | **1,579** | 63.9 | 6.117 | **0.077** | **88.0%** |
| GLM-4.7-Flash (Q8_0 PPL 10.41; 562 tensors, 16,171 MiB) | exact int8 | 904 | 853 | 58.6 | 7.973 | 0.528 | 83.1% |
| | W4A4 on attention only | 1,029 | 861 | 61.3 | 8.130 | 0.550 | 81.3% |
| | **W4A4 on attention and experts** | **1,599** | **1,239** | 61.9 | 8.455 | **0.587** | **79.3%** |

Qwen3.6-35B-A3B gains only about 11%: most of its layers are delta-net layers, whose prompt
work does not run through a Q4_0 matmul. GLM-4.7-Flash (DeepSeek-2 layout, MLA attention; the
tool rotates the MLA projections `attn_q_a`, `attn_q_b`, `attn_kv_a_mqa`, `attn_kv_b`,
`attn_k_b`, `attn_v_b`) gains 77% at pp512, and W4A4 adds KLD 0.06, as on the Qwen models.

GLM-4.7-Flash does not take plain Q4_0 well, W4A4 or not. A plain, unrotated Q4_0 on the exact
path already scores KLD 0.493 against the Q8_0; any single group of tensors at Q4_0 (the
experts, the attention, or the shared expert, dense layer and embedding) costs about 0.14 on its
own. Its wikitext perplexity drops under Q4_0 (10.41 to 7.97-8.73) because the output
distribution flattens, so perplexity alone reads this model the wrong way round. The Q8_0
reference is sound: it gives PPL 10.44 on upstream HIP and 11.01 on Vulkan, and KLD 0.015
across backends. For GLM-4.7-Flash, use a higher-precision file; the W4A4 route is not worth its
accuracy there until the Q4_0 base is better.

@bong-water-water-bong
bong-water-water-bong merged commit 0145cd9 into main Sep 28, 2026
11 checks passed
@bong-water-water-bong
bong-water-water-bong deleted the w4a4-moe-mla branch September 28, 2026 17:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant