Skip to content

CUDA: fuse MoE gate/up matmuls and GLU in MMQ - #31188

Merged
gaugarg-nv merged 1 commit into
ggml-org:masterfrom
anujj:cuda-mmq-fused-gate-up-moe
Oct 28, 2026
Merged

gaugarg-nv merged 1 commit into
ggml-org:masterfrom
anujj:cuda-mmq-fused-gate-up-moe

Conversation

@anujj

@anujj anujj commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Extension of #29948 to MoE models: the same fused gate/up + GLU MMQ kernel now also runs for the expert FFNs (MUL_MAT_ID).

For prompt processing, the gate and up expert matmuls and the following GLU run as one mul_mat_q launch, exactly as for dense FFNs in #29948.

Performance

llama-bench -ngl 999 -fa on -p 16384 -n 0 -b 2048 -ub 2048 -ctk f16 -ctv f16 -r 5, tok/s:

GPU model master PR
DGX Spark (GB10) Qwen3-30B-A3B Q4_K_M 2911.4 3410.8 +17.2%
Qwen3.6-35B-A3B Q4_K_M 3235.8 3556.7 +9.9%
Qwen3.6-35B-A3B UD-Q4_K_M 3264.7 3561.8 +9.1%
RTX 5090 Qwen3-30B-A3B Q4_K_M 12611.7 13330.3 +5.7%
Qwen3.6-35B-A3B Q4_K_M 15000.3 15852.0 +5.7%
Qwen3.6-35B-A3B UD-Q4_K_M 15030.2 15947.8 +6.1%

Correctness

  • Perplexity (wiki.test, 8 chunks) is bit-identical to master for all three models on both GPUs.

Requirements

@github-actions github-actions Bot added testing Everything test related ggml changes relating to the ggml tensor library for machine learning CUDA Related to the CUDA backend labels Oct 26, 2026
@anujj
anujj force-pushed the cuda-mmq-fused-gate-up-moe branch from 7aa8ffe to 447ab31 Compare October 26, 2026 14:19
@anujj
anujj force-pushed the cuda-mmq-fused-gate-up-moe branch from 447ab31 to eb4eee1 Compare October 26, 2026 14:55
@anujj
anujj marked this pull request as ready for review October 27, 2026 04:35
@anujj
anujj requested review from a team and ggerganov as code owners October 27, 2026 04:35
@anujj

anujj commented Oct 27, 2026

Copy link
Copy Markdown
Contributor Author

Requesting @JohannesGaessler to review this

@gaugarg-nv
gaugarg-nv merged commit f5222f2 into ggml-org:master Oct 28, 2026
25 of 26 checks passed
PapyKahan added a commit to PapyKahan/llama.cpp that referenced this pull request Oct 28, 2026
Upstream's version is kept wherever it does what the branch did; the branch's stays where upstream has none:
- MoE cache: the constructor takes upstream's no_alloc flag beside the CPU share, buffers come from
  llama_memory_bufs::alloc_buf; phases and host mode as before.
- build_moe_ffn: the branch's experts lambda (cache slots, host mode, shared batches) with upstream's DeepSeek-4.1
  and Laguna changes.
- qwen4exp: the selection is built over the cache cells as upstream now does (ggml-org#30965, ggml-org#31243), the branch keeps
  its query chunks (ggml-org#30815's earlier version); upstream's hc_mix outputs and merged tensors.
- CUDA MMQ: the tile map of active MoE tiles also launches upstream's fused gate/up/GLU kernel (ggml-org#31188, ggml-org#29948);
  the fused paths zero the rows of negative ids as ggml_cuda_mul_mat_id does.
- CPU MUL_MAT_ID: upstream's -1 skip (ggml-org#26631) and the branch's two-pass grouping agree, negative ids are skipped.
- tests: the QSA chunk tests move with upstream's archs tests; a MUL_MAT_ID result marked by
  ggml_mul_mat_id_set_negative_ids runs on CUDA again, only unmarked ones are excluded ([TAG_MUL_MAT_ID_SKIP]).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01P3vd8iuiuxiev7wMPyJmSf
yzhou51 pushed a commit to yzhou51/llama.cpp that referenced this pull request Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CUDA Related to the CUDA backend ggml changes relating to the ggml tensor library for machine learning testing Everything test related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants