Skip to content

ggml-hrx: fix Qwen MoE fused router gfx1151 launch geometry (engine#108) - #12

Merged
bong-water-water-bong merged 1 commit into
1bit/hrx-vulkan-patchedfrom
fix/moe-router-experts-per-wave-launch-geometry
Sep 26, 2026
Merged

bong-water-water-bong merged 1 commit into
1bit/hrx-vulkan-patchedfrom
fix/moe-router-experts-per-wave-launch-geometry

Conversation

@bong-water-water-bong

Copy link
Copy Markdown

Fixes the second (and last remaining) bug in 1bit-MONSTER/engine#108.

PR #7 fixed the route-ids binding-length crash. That PR's description also claimed the second bug (wrong output once decode no longer crashes) was fixed by the same PR — it wasn't; the diff that actually merged only touched dispatch-moe-router.cpp's binding length. This PR is that missing second fix.

Root cause: qwen3_moe_router_projection_top8_fused_decode_f32's launch config hardcoded experts_per_wave = 4 when computing expert_tiles = expert_count / experts_per_wave (the kernel's workgroup count). But the kernel body dispatches its per-wave projection work through the qwen3_moe.router.fused.experts_per_wave template family, which resolves to 2 on gfx1151 (priority(20), the two-expert specialization) and only falls back to 4 on generic gfx11 targets (priority(1)). On gfx1151 this launched half the workgroups the projection body actually needs, so half the experts' router logits were never written — top-8 routing then selected from partially uninitialized logits, producing garbled completions whenever the fused router path was hit (i.e. whenever HRX0 runs the dense/router side of a Qwen MoE model).

Fix: compute experts_per_wave via the same template.apply<@qwen3_moe.router.fused.experts_per_wave>() the projection body already uses, instead of a hardcoded constant, so the launch geometry always matches what the kernel body assumes. One line.

Verified on gfx1151 (Strix Halo), Qwen3-Coder-30B-A3B-Instruct-Q4_K_M, -dev HRX0,Vulkan0 -ts 1,0 -ot exps=Vulkan0 (dense on HRX0, experts on Vulkan0 — the exact #108 repro):

  • Before this fix (PR ggml-hrx: fix the Qwen MoE fused router - route-ids binding length and gfx1151 launch geometry (engine#108) #7 alone): garbled output ("4SignATES first doesn..."), matching the issue's own reported symptom.
  • After this fix: correct on a variety of prompts (arithmetic, factual, multi-turn), deterministic across repeated identical requests with cache_prompt:false.
  • GGML_HRX_DISABLE_DISPATCH=moe_router reproduces the issue's documented fallback behavior exactly ("Compute error."), confirming the fused dispatch is genuinely what's being exercised and fixed, not bypassed.
  • Single-device -dev HRX0 (unaffected by this bug either way) unchanged.

The fused decode router kernel (qwen3_moe_router_projection_top8_fused_decode_f32)
hardcoded experts_per_wave=4 when computing its launch workgroup count
(expert_tiles = expert_count / experts_per_wave), but the kernel body dispatches
its per-wave projection work via the qwen3_moe.router.fused.experts_per_wave
template family, which resolves to 2 on gfx1151 (priority 20, the two-expert
variant) and only falls back to 4 on generic gfx11 targets (priority 1).

On gfx1151 this launched half the workgroups the projection body actually
needs, so half the experts logits were never written - top-8 routing then
selected from partially uninitialized logits, producing wrong output (garbled
completions) whenever the fused router path was hit. This is the second of
the two bugs #108 reports; PR #7 fixed the first (route-ids binding length)
but this one was never actually committed, despite being described as fixed.

Fix: compute experts_per_wave via the same template.apply the projection body
already uses, instead of a hardcoded constant, so the launch geometry always
matches what the kernel body assumes.
@github-actions github-actions Bot added the ggml label Sep 26, 2026
@bong-water-water-bong
bong-water-water-bong merged commit 1e775cd into 1bit/hrx-vulkan-patched Sep 26, 2026
1 check passed
@bong-water-water-bong
bong-water-water-bong deleted the fix/moe-router-experts-per-wave-launch-geometry branch September 26, 2026 09:03
bong-water-water-bong added a commit that referenced this pull request Oct 20, 2026
…ops (#118)

fused_context_claim kept GATED_DELTA_NET on HRX whenever any source was produced by an op. The
test-backend-ops GATED_DELTA_NET cases build q and k as L2_NORMs of leaves and v from a leaf. While
L2_NORM had no standalone HRX path those cases were skipped; gpu-kernels #12 added one, the GDN node
was then claimed through its L2_NORM inputs, no dispatch matches such a graph, and 31 cases failed
with "graph_compute: unsupported HRX node 0: GATED_DELTA_NET" (hw-gate run 39510505298, engine #480:
ops 618/649).

The model graphs (qwen35, qwen35moe, qwen3next) feed v from a view of the delta-net conv and q, k
from L2_NORMs of views of it, so the claim now also requires v produced by an op and q, k produced by
ops whose L2_NORM, if any, reads an op output.

Co-authored-by: bong-water-water-bong <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant