mmq: compacted MoE tiling for RDNA3.5 (default on)#63
Draft
roberteg16 wants to merge 1 commit into
Draft
Conversation
roberteg16
force-pushed
the
rogarcia.mmq-moe-compact-tiling
branch
2 times, most recently
from
July 21, 2026 09:04
fe413e4 to
3074413
Compare
Launch only the minimum number of mmq_x-wide column blocks implied by the actual per-expert token counts (padded to mmq_x) instead of the worst-case (ne02 * ceil(ne12/mmq_x)) grid. Modeled on vLLM's moe_align_block_size + fused_moe_kernel: a device kernel (mmq_build_moe_block_map) builds block_start (exclusive prefix sum of ceil(tokens_e/mmq_x)) and block_expert (block -> expert) from expert_bounds; the conventional-tiling kernel decodes blockIdx -> (it, jt, zt) via those arrays and padding blocks self-exit. The grid is sized to the host-known upper bound (graph-safe, no host readback). Gated on expert_bounds != null && RDNA3.5 && env GGML_CUDA_MMQ_MOE_COMPACT (default off). Dense, multi-GPU split and stream-K paths are unchanged. E2E Qwen3.6-35B-A3B (gfx1151, Q4_K_M, prefill, -r 40): +2.0-3.4% t/s at pp128/1024/4096. test-backend-ops MUL_MAT_ID: 790/790 pass. Co-Authored-By: Claude Opus 4 (1M context) <noreply@anthropic.com>
roberteg16
force-pushed
the
rogarcia.mmq-moe-compact-tiling
branch
from
July 21, 2026 09:47
3074413 to
f8c07eb
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Compacted grid for the MMQ Mixture-of-Experts matmul on RDNA3.5, enabled by default (previously opt-in via
GGML_CUDA_MMQ_MOE_COMPACT, now removed). Modeled on vLLM'smoe_align_block_size+fused_moe_kernel.Instead of the worst-case
(nty, ntx, ne02)grid -- wherentx = ceil(ne12/mmq_x)assumes all tokens land on one expert, so mostne02 * ntxcolumn-blocks belong to experts that early-exit -- this launches only the minimum number ofmmq_x-wide column blocks implied by the actual per-expert token counts (padded tommq_x).mmq_build_moe_block_map(single block, parallel prefix sum in shared memory +parallel binary-search scatter) builds from
expert_bounds:block_start[]-- exclusive prefix sum ofceil(tokens_e / mmq_x)(
block_start[ne02]= total real blocks, the device-side "num_tokens_post_padded").block_expert[]-- compacted column-block -> expert.blockIdx -> (it, jt, zt)via those arrays;padding blocks self-exit (
m_block >= block_start[n_experts]).ceil((ne_get_rows + ne02*(mmq_x-1)) / mmq_x)-> fixed per shape, no host readback(graph-safe).
Scope / safety
expert_bounds != nullptr && GGML_CUDA_CC_IS_RDNA3_5(cc). Theblock_expertpointer is the mode flag: non-null only for this launch.(they pass
nullptr, nullptr, 0).(it, jt, zt, wt)decode only re-enumerates the tiles the legacy gridwould have kept;
wt = 0is exact (MoE assertsne13 == 1),zt/jtstay in thesame ranges, padding blocks
returnbefore indexingblock_expert(no OOB).max_m_blocks >= MMQ_MAX_GRIDDIM_Y(65535).mm_ids_helperis left unmodified.Verification (gfx1151, Strix Halo)
Decode is provably unaffected (rocprofiler / GGML_ROOFLINE_OUT)
Per-op kernel traces confirm the compacted path is prefill-only:
MUL_MAT_IDdispatchesmul_mat_vec_q(MMVQ) +quantize_q8_1. Zeromul_mat_qand zerommq_build_moe_block_mapdispatches (0 of 603437 kernel launches in the tg128 trace).MUL_MAT_IDdispatchesmul_mat_q+quantize_mmq_q8_1+mm_ids_helper+mmq_build_moe_block_map.So enabling by default carries no decode risk: the MoE GEMM in decode never enters the MMQ path.
Prefill throughput, 4 MoE models (branch vs gfx11 integration baseline)
llama-bench -ngl 999 -n 128 -r 10 -t 8 -fa 1 --poll 50 -ctk f16 -ctv f16, uncontended via gpu-lock,ROCBLAS_USE_HIPBLASLT=1.Decode is unaffected (same-build A/B)
Toggling the compacted path on/off in the same build leaves decode throughput at parity (tg128,
-n 128 -r 10):Test plan
llama-benchprefill A/B across 4 MoE models (above).test-backend-ops -o MUL_MAT_IDwith default-on: 790/790 pass (gfx1151).