Skip to content

ggml-cuda: size MMQ tile to MoE tokens-per-expert - #39

Merged
roberteg16 merged 1 commit into
gfx11from
rogarcia.mmq-moe-tile-size
Jul 13, 2026
Merged

ggml-cuda: size MMQ tile to MoE tokens-per-expert#39
roberteg16 merged 1 commit into
gfx11from
rogarcia.mmq-moe-tile-size

Conversation

@roberteg16

Copy link
Copy Markdown

What this changes

An MoE prefill optimization for the MMQ (quantized matmul) path. For MUL_MAT_ID, mul_mat_q_case picks the tile width (mmq_x) by tiling over ncols_max, which assumes every token can land in a single tile column range - the worst case of all tokens routed to one expert. In practice each expert receives only about ncols_dst / nchannels_y tokens, so at large ncols_max the selection lands on wide tiles (e.g. mmq_x=128) that are mostly empty per expert.

This computes the tile width from ~2x the average tokens-per-expert instead: when expert_bounds != nullptr, ncols_to_tile = min(2 * ceil(ncols_dst / nchannels_y), ncols_max). The 2x covers routing imbalance, and larger batches converge back to ncols_max, so dense (non-MoE) matmuls are unaffected. The heuristic is restricted to RDNA3.5 (GGML_CUDA_CC_IS_RDNA3_5), the only architecture it has been tuned and validated on.

Benchmarks

Measured on gfx1151 (Radeon 8060S), Qwen3.6-35B-A3B Q4_K_M, -ngl 999 -r 1, built with -DGGML_HIP_ROCWMMA_FATTN=OFF. Baseline is gfx11 at the same commit base.

test baseline t/s this PR t/s delta
pp128 549.01 1051.11 +91.5%
pp1024 1133.77 1580.15 +39.4%
tg128 53.31 53.14 -0.3% (noise)

Prefill throughput improves substantially; decode is untouched (the change only affects batched-matmul tiling). -r 1 has no error bars, but the prefill deltas are far outside run-to-run noise.

For MUL_MAT_ID, choose the tile width from ~2x the average tokens-per-expert
(ncols_dst/nchannels_y) instead of ncols_max, so the common per-expert tiles
are filled instead of mostly empty at mmq_x=128.

Assisted-by: Claude Opus 4 (1M context)

@mgehre-amd mgehre-amd left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nice!

@roberteg16

Copy link
Copy Markdown
Author

I tried a variety of real texts and improvements remain. I'll keep the changes.

@roberteg16
roberteg16 merged commit fee8f99 into gfx11 Jul 13, 2026
6 checks passed
@roberteg16
roberteg16 deleted the rogarcia.mmq-moe-tile-size branch July 13, 2026 14:21
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