Skip to content

CUDA: size routed MoE MMQ N-tiles from typical expert width on RDNA3 (recreated) - #28552

Merged
IMbackK merged 2 commits into
masterfrom
pr-24546-recreated
Sep 9, 2026
Merged

IMbackK merged 2 commits into
masterfrom
pr-24546-recreated

Conversation

@pwilkin

@pwilkin pwilkin commented Sep 7, 2026

Copy link
Copy Markdown
Member

Overview

Recreated #24546

Additional information

Added some remarks from @JohannesGaessler on top of the original.

Requirements

ravel7524 and others added 2 commits September 7, 2026 16:39
…24546)

* adjust ncols_picker for routed MoE in mul_mat_q_case function

* Adding CDNA, RDNA2 and RDNA4

* fix: update mmq_use_routed_moe_ncols_picker to include NVIDIA + Volta support

* feat: enhance mmq configuration for various architectures with moe_ncols_min_cc support

* refactor: replace moe_ncols_min_cc with use_typical_moe_ncols in mmq configuration files

* HIP: mmq: enable typical moe ncols on RDNA4

---------

Co-authored-by: Carl Philipp Klemm <carl@uvos.xyz>
@pwilkin
pwilkin requested a review from a team as a code owner September 7, 2026 14:41

@JohannesGaessler JohannesGaessler left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let me quickly check the RDNA4 performance as well but LGTM based on static code analysis.

Comment thread ggml/src/ggml-cuda/mmq.cu
// On RDNA3 and RDNA4 it is faster to pick the tile size against this value instead of ne12.
int64_t ncols_opt = ne12;
if (GGML_CUDA_CC_IS_RDNA3_0(cc) || GGML_CUDA_CC_IS_RDNA4(cc)) {
ncols_opt = (ne12*n_expert_used + ne02 - 1) / ne02;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not sure the rounding actually makes a difference here but since this is just based on empirical evidence anyways I think it doesn't matter.

@JohannesGaessler JohannesGaessler self-assigned this Sep 7, 2026
@github-actions github-actions Bot added ggml changes relating to the ggml tensor library for machine learning CUDA Related to the CUDA backend labels Sep 7, 2026
@JohannesGaessler

Copy link
Copy Markdown
Contributor
Performance
GPU Model Microbatch size Test t/s e71b805 t/s f01a754 Speedup
RX 9060 XT deepseek2 16B Q4_0 1 pp1024@d32768 68.31 68.33 1.00
RX 9060 XT deepseek2 16B Q4_0 2 pp1024@d32768 73.93 74.00 1.00
RX 9060 XT deepseek2 16B Q4_0 4 pp1024@d32768 89.74 89.91 1.00
RX 9060 XT deepseek2 16B Q4_0 8 pp1024@d32768 102.66 102.94 1.00
RX 9060 XT deepseek2 16B Q4_0 16 pp1024@d32768 122.13 122.47 1.00
RX 9060 XT deepseek2 16B Q4_0 32 pp1024@d32768 132.73 133.21 1.00
RX 9060 XT deepseek2 16B Q4_0 64 pp1024@d32768 178.14 180.87 1.02
RX 9060 XT deepseek2 16B Q4_0 128 pp1024@d32768 187.85 193.90 1.03
RX 9060 XT deepseek2 16B Q4_0 256 pp1024@d32768 202.25 205.79 1.02
RX 9060 XT deepseek2 16B Q4_0 512 pp1024@d32768 211.01 212.35 1.01
RX 9060 XT gpt-oss 20B MXFP4 MoE 1 pp1024@d32768 78.43 78.42 1.00
RX 9060 XT gpt-oss 20B MXFP4 MoE 2 pp1024@d32768 123.79 123.91 1.00
RX 9060 XT gpt-oss 20B MXFP4 MoE 4 pp1024@d32768 202.65 202.62 1.00
RX 9060 XT gpt-oss 20B MXFP4 MoE 8 pp1024@d32768 311.52 311.08 1.00
RX 9060 XT gpt-oss 20B MXFP4 MoE 16 pp1024@d32768 453.13 451.79 1.00
RX 9060 XT gpt-oss 20B MXFP4 MoE 32 pp1024@d32768 650.98 640.71 0.98
RX 9060 XT gpt-oss 20B MXFP4 MoE 64 pp1024@d32768 812.44 839.89 1.03
RX 9060 XT gpt-oss 20B MXFP4 MoE 128 pp1024@d32768 882.50 987.39 1.12
RX 9060 XT gpt-oss 20B MXFP4 MoE 256 pp1024@d32768 1144.36 1245.05 1.09
RX 9060 XT gpt-oss 20B MXFP4 MoE 512 pp1024@d32768 1334.38 1373.03 1.03
RX 9060 XT granitemoe 3B Q4_0 1 pp1024@d32768 63.63 63.65 1.00
RX 9060 XT granitemoe 3B Q4_0 2 pp1024@d32768 130.93 131.07 1.00
RX 9060 XT granitemoe 3B Q4_0 4 pp1024@d32768 215.32 215.24 1.00
RX 9060 XT granitemoe 3B Q4_0 8 pp1024@d32768 288.20 288.15 1.00
RX 9060 XT granitemoe 3B Q4_0 16 pp1024@d32768 681.65 681.03 1.00
RX 9060 XT granitemoe 3B Q4_0 32 pp1024@d32768 1061.91 1050.74 0.99
RX 9060 XT granitemoe 3B Q4_0 64 pp1024@d32768 1274.30 1257.70 0.99
RX 9060 XT granitemoe 3B Q4_0 128 pp1024@d32768 1494.89 1546.09 1.03
RX 9060 XT granitemoe 3B Q4_0 256 pp1024@d32768 1695.15 1736.70 1.02
RX 9060 XT granitemoe 3B Q4_0 512 pp1024@d32768 1815.49 1842.24 1.01

@IMbackK
IMbackK merged commit d4abd57 into master Sep 9, 2026
11 of 23 checks passed
Patt92 pushed a commit to Patt92/llama.cpp that referenced this pull request Sep 9, 2026
Also retires the hand-tuned MUL_MAT_ID J thresholds. Upstream d4abd57 (ggml-org#28552)
re-landed routed-MoE tile sizing in the shape its maintainer asked for -- an
ncols_opt field on mmq_args, decided host-side -- and gated it to RDNA3.0 and
RDNA4. mmq.cu extends that gate to RDNA3.5 and drops the local heuristic and its
GGML_CUDA_MMQ_ID_J override with it.
zbrad pushed a commit to zbrad/llama.cpp that referenced this pull request Sep 10, 2026
…gml-org#28552)

Recreated from ggml-org#24546

---------

Co-authored-by: Carl Philipp Klemm <carl@uvos.xyz>

* CUDA: pick MMQ tile size against ncols_opt set on the host side

Assisted-by: Claude Fable 5.1
Claude-Session: https://claude.ai/code/session_011SYPfRhKoUpU3gMsGxq6go

---------

Co-authored-by: ravel7524 <58877666+ravel7524@users.noreply.github.com>
Co-authored-by: Carl Philipp Klemm <carl@uvos.xyz>
@BrewTestBot BrewTestBot mentioned this pull request Sep 14, 2026
1 task done
liquidspikes added a commit to liquidspikes/llama.cpp that referenced this pull request Sep 16, 2026
justinappler added a commit to justinappler/llama.cpp-strix-halo that referenced this pull request Sep 26, 2026
…NA3.5

Upstream ggml-org#28552/ggml-org#28935 land the routed-MoE ncols picker on RDNA3.5, which
Finding ggml-org#10 measured flat against our static J=48 cap, so the cap goes.
Upstream ggml-org#28102 routes WMMA to MMA_F16 at D=256 and bypasses our tile
config at prefill; guard it off on RDNA3.5 pending the G/N A/B.

Assisted-by: Claude Opus 5.5
roverdrubber added a commit to roverdrubber/llama.cpp that referenced this pull request Oct 15, 2026
…backend changes

A quantized weight that takes the dequantize and hipBLAS path was dequantized
to F16, so any activation past the F16 range came back as inf. On RDNA3 the
27B crosses into that path at 129 rows, which is why a long prompt returned
NaN logits while a short one did not. Quantized types now dequantize to F32 on
AMD; NVIDIA keeps F16 where its hardware is fast at it. The regression test
added later in this series (activations in [-4000, 4000], both sides of the
128-row cutover) returned inf for Q2_K, Q6_K and Q8_0 before this change.

The same commit carries the backend half of the upstream sync: the MMQ and
vec-dot changes (ggml-org#28552, ggml-org#26705), fast_bf16_hardware_available and the BF16
fallback (ggml-org#28846), the GGML_CUDA_FA_QUANTS build option, and ggml-org#26308 and ggml-org#28897.
The integrated-GPU host-buffer path stays disabled on HIP as well, because it
corrupts output there (upstream ggml-org#26209, reverted in ggml-org#28604).

MUL_MAT and MUL_MAT_ID pass on gfx1100 (1304/1304 and 892/892 at the tip of
this series).

Assisted-by: Claude Opus 5
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants