Skip to content

CUDA: optimize Orin single-column MMVQ - #31268

Merged
ggerganov merged 2 commits into
ggml-org:masterfrom
meitmt:cuda-orin-mmvq-table
Nov 20, 2026
Merged

ggerganov merged 2 commits into
ggml-org:masterfrom
meitmt:cuda-orin-mmvq-table

Conversation

@meitmt

@meitmt meitmt commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Overview

Following the maintainer's feedback in #30858, this PR adds MMVQ_PARAMETERS_ORIN to the MMVQ parameter table. For single-column operations, nine selected types use nwarps rows per block, which is four rows on Orin. Other types and other GPUs keep their current behavior. The change applies to AGX Orin, Orin NX, and Orin Nano. It was tested on a Jetson Orin Nano Super. @Andy1314Chen also tested it on an AGX Orin 32GB.

The build must include sm_87 for the Orin table to be selected. Use -DCMAKE_CUDA_ARCHITECTURES=87, or native when building on Orin. This follows the same compiled-architecture selection as the GB10 entry.

With LFM2.5-VL-3B on Orin Nano Super, MAXN_SUPER + jetson_clocks, the llama-bench results show:

  • Pure Q4_0 decode improves by about 38%.
  • The distributed Q4_K_M model improves by 15%. Pure Q4_K_S and Q8_0 improve by 18% and 23%.
  • Pure Q5_K_S improves by 6%, and pure Q6_K by about 2%.
  • Types outside the whitelist keep their current parameters. The tested pure Q2_K, Q3_K_S, and IQ4_XS models show no speed change at the precision reported in the table.
  • Prefill speed stays about the same.

Only libggml-cuda.so changes between the baseline and patched builds in each comparison.

Reason

For single-column MMVQ on Orin, the new table uses the same nwarps value as GENERIC: 4. This PR sets the number of rows per block to nwarps for the selected types, so each block processes four rows. Each thread computes part of all four rows.

This lets a thread issue more weight reads at the same time. It may help hide memory access latency. We have not yet confirmed whether memory latency or bandwidth limits the speed.

Change

The patch changes five parts of ggml/src/ggml-cuda/mmvq.cu:

  1. Add MMVQ_PARAMETERS_ORIN to mmvq_parameter_table_id.
  2. In the device-side get_device_table_id(), select it when __CUDA_ARCH__ == GGML_CUDA_CC_ORIN.
  3. In the host-side get_device_table_id(int cc), select it for NVIDIA when ggml_cuda_highest_compiled_arch(cc) == GGML_CUDA_CC_ORIN.
  4. In calc_nwarps, use the GENERIC values for Orin.
  5. In calc_rows_per_block, use nwarps rows for single-column operations on the whitelist. Other cases keep the GENERIC behavior, including its two-row cases for low-bit types.

The whitelist is Q4_0, Q4_1, Q5_0, Q5_1, Q8_0, Q4_K, Q5_K, Q6_K, and IQ4_NL. These are the same nine types for which the existing GB10 entry increases nwarps.

The first build used eight types, without Q6_K. Adding Q6_K raises the gain for the distributed Q4_K_M model from 10.6% to 15.1%. That model uses Q6_K for some tensors, including the output layer, which can benefit from this change even though a pure Q6_K model gains only about 2%.

A broader build also changed the other types, except IQ3_XXS and IQ3_S. Some of these types were 9–31% faster in isolated single-column mat-vec tests, but the tested full models gained at most 2%: Q2_K gained 1.8%, IQ4_XS gained 1.4%, and Q3_K_S slowed down by 0.7%. There are no full-model results for the other added types. They are left out of this PR.

The parameter table has no has_ids input, so single-token MUL_MAT_ID operations also use the new parameters for the selected types. test-backend-ops -o MUL_MAT_ID -b CUDA0 passes all 931 cases on both builds. MoE model performance was measured on Qwen3-30B-A3B by @Andy1314Chen.

Result

Baseline: 7894e8b92. The patch is based directly on this commit. All results in this section use MAXN_SUPER + jetson_clocks.

Models as distributed

LFM2.5-VL-3B, tg128 / pp512, tokens/s, mean of two interleaved rounds.

Model Test master PR Speedup
LFM2.5-VL-3B Q4_K_M tg128 28.64 32.97 1.15
LFM2.5-VL-3B Q4_K_M pp512 1068.46 1070.32 1.00
LFM2.5-VL-3B Q4_0 tg128 31.75 42.50 1.34
LFM2.5-VL-3B Q4_0 pp512 1195.30 1205.97 1.01

Pure quantizations

LFM2.5-VL-3B LM quantized with llama-quantize --pure, tg128, tokens/s. "In table" means the type is in the Orin whitelist. The "all types" ratios are from the broader experimental build, not the proposed patch.

Type master PR Speedup In table
Q4_0 32.44 44.73 1.38 yes
Q4_1 34.29 43.28 1.26 yes
Q5_0 29.81 35.82 1.20 yes
Q5_1 29.41 38.12 1.30 yes
Q8_0 22.24 27.28 1.23 yes
IQ4_NL 34.28 41.76 1.22 yes
Q4_K_S 29.21 34.41 1.18 yes
Q5_K_S 26.18 27.82 1.06 yes
Q6_K 25.67 26.31 1.02 yes
Q2_K 39.91 39.92 1.00 no (all types: 1.02)
Q3_K_S 23.57 23.58 1.00 no (all types: 0.99)
IQ4_XS 29.55 29.55 1.00 no (all types: 1.01)

pp512 changes by at most 0.4% for every type. Q4_0-Q8_0 were measured with the 8-type build, which launches the same kernel configuration as this PR for those types.

Single-column mat-vec (test-backend-ops perf -o MUL_MAT -b CUDA0 -p 'n=1,', µs/run, mean of 2)
type m x k master PR speedup
q4_0 4096x14336 486.8 381.0 +27.8%
q4_1 4096x14336 434.6 380.7 +14.2%
q5_0 4096x14336 596.4 522.7 +14.1%
q5_1 4096x14336 577.9 512.6 +12.7%
q8_0 4096x14336 799.7 704.9 +13.5%
q4_K 4096x14336 542.5 487.0 +11.4%
q4_K 4096x4096 192.5 152.4 +26.3%
q4_K 6144x4096 299.7 224.2 +33.6%
q4_K 14336x4096 685.6 508.3 +34.9%
q5_K 4096x14336 655.6 589.0 +11.3%
q6_K 4096x14336 752.8 662.0 +13.7%
iq4_nl 4096x14336 536.4 447.2 +19.9%
other types unchanged (−0.1% to +1.3%)

Additional information

Results on AGX Orin

Thanks to @Andy1314Chen, whose comment reports independent results on an AGX Orin 32GB, including dense and MoE Qwen3 models.

LFM2.5-VL-3B, tg128 speedup vs master. pp512 stays within 1.00–1.02 on AGX Orin.
Quant AGX Orin 32GB (@Andy1314Chen) Orin Nano Super (this PR)
Q4_0 1.33 1.34
Q4_K_M 1.11 1.15
Q4_K_S 1.16 1.18
Q8_0 1.19 1.23
Q5_K_S 1.07 1.06
Q6_K 1.00 1.02
Q2_K / Q3_K_S / IQ4_XS (not in table) 1.00 1.00

Qwen3, tg128, tokens/s, 3 rounds, MAXN + jetson_clocks

Model Quant master PR Speedup
Qwen3-8B (dense) Q4_K_M 26.44 27.45 1.04
Qwen3-8B (dense) Q4_0 pure 30.45 34.04 1.12
Qwen3-30B-A3B (MoE) Q4_K_M 42.94 47.67 1.11
Qwen3-30B-A3B (MoE) Q4_0 pure 47.30 57.41 1.21

CUDA fusion

The fusion results below were measured with the previous patch (#30858) on 7951f601e. They were not repeated for this version. Both Q6_K and Q4_0 use the same row configuration in the old and new patches.

These results help explain why pure Q6_K gains only about 2% with fusion enabled, while keeping Q6_K in the whitelist still helps the distributed Q4_K_M model. With CUDA fusion disabled, pure Q6_K gains 25% with the old patch. This suggests that fused CUDA paths limit the benefit in the pure model. The switch disables all CUDA fusions, so this test does not isolate the gate/up fusion alone.

Previous-version fusion results (#30858 on 7951f601e, tg128, tokens/s, 2 rounds each)
Model CUDA fusion Baseline 7951f601e Previous patch (#30858) Speedup
Q6_K (pure) enabled (default) 25.68 26.32 1.02
Q6_K (pure) disabled 24.70 30.98 1.25
Q4_0 (pure) enabled (default) 32.43 44.74 1.38
Q4_0 (pure) disabled 31.65 49.37 1.56

Performance was tested on the Jetson Orin Nano Super and the LFM2.5 model family.

Correctness

The order of accumulation along the K-dimension for each row remains unchanged; only the number of rows processed in each block has changed.

The following checks use baseline 7894e8b92 and the new patch.

Check master PR
test-backend-ops -o MUL_MAT -b CUDA0 2445/2445 2445/2445
test-backend-ops -o MUL_MAT_ID -b CUDA0 931/931 931/931
llama-perplexity VL-3B Q4_K_M, WikiText-2, -c 512 -b 512 -ub 1 --chunks 10 13.3141 ± 0.75384 13.3141 ± 0.75384
llama-perplexity VL-3B Q4_0, same settings 13.5030 ± 0.76657 13.5030 ± 0.76657

Environment

  • Jetson Orin Nano Super Developer Kit, 8 GB
  • JetPack 6.2 (L4T 36.4.3), CUDA 12.6
  • MAXN_SUPER + jetson_clocks, desktop stopped
  • Baseline and patch base: 7894e8b92
  • Build requirement: include sm_87 with -DCMAKE_CUDA_ARCHITECTURES=87, or native when building on Orin

Related

Command

llama-quantize --pure LFM2.5-VL-3B-F16.gguf model-<type>.gguf <type>
llama-bench -m <model> -p 512 -n 128 -r 5 -ngl 99 -o jsonl
scripts/compare-llama-bench.py -t llama-bench -i results.jsonl -b <baseline> -c <pr>
test-backend-ops perf -o MUL_MAT -b CUDA0 -p 'n=1,'
test-backend-ops -o MUL_MAT -b CUDA0
test-backend-ops -o MUL_MAT_ID -b CUDA0
llama-perplexity -m <model> -f wiki.test.raw -c 512 -b 512 -ub 1 --chunks 10 -ngl 99

# Previous-version fusion comparison: baseline 7951f601e and the patch from #30858.
GGML_CUDA_DISABLE_FUSION=0 llama-bench -m <model> -p 0 -n 128 -r 5 -ngl 99
GGML_CUDA_DISABLE_FUSION=1 llama-bench -m <model> -p 0 -n 128 -r 5 -ngl 99

Requirements

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: YES - Claude Code helped generate code and do experiments. I have reviewed the code line by line and understand it. Bottleneck analysis and tabular summarization are performed with the assistance of AI. Besides, AI assisted in reviewing this PR and providing suggestions for revisions. I wrote this PR body myself.

@meitmt
meitmt requested a review from a team as a code owner October 27, 2026 18:18
@github-actions github-actions Bot added ggml changes relating to the ggml tensor library for machine learning CUDA Related to the CUDA backend labels Oct 27, 2026
@Andy1314Chen

Copy link
Copy Markdown

Independent verification + the missing MoE data point (AGX Orin 32GB)

Following the open question in this PR ("MoE model performance has not been measured"), I ran the same base/head builds on an AGX Orin 32GB(L4T 36.4.4, CUDA 12.6.85, MAXN power mode, jetson_clocks applied, desktop stopped). Both builds with -DCMAKE_CUDA_ARCHITECTURES=87; only libggml-cuda.so differs. Protocol: llama-bench -p 512 -n 128 -r 5 -ngl 99, interleaved rounds.

1) Cross-check on the author's model (LFM2.5-VL-3B, tg128 speedup vs base):

quant AGX Orin 32GB (mine) Nano Super (author)
Q4_0 1.33 1.34
Q4_K_M 1.11 1.15
Q4_K_S 1.16 1.18
Q8_0 1.19 1.23
Q5_K_S 1.07 1.06
Q6_K 1.00 1.02
Q2_K_M / Q3_K_S / IQ4_XS (controls) 1.00 1.00

pp512 within 1.00-1.02, matching the author's "<=0.4%" observation. Absolute t/s ~2x the Nano Super numbers, tracking the DRAM bus (AGX Orin 204.8 GB/s vs Nano Super 102 GB/s) - consistent with bandwidth-bound decode, so ratios are comparable.

2) Dense (Qwen3-8B, 3 rounds):

quant base PR speedup pp512
Q4_K_M 26.44 27.45 1.038 1.000
Q4_0 pure 30.45 34.04 1.118 1.002

3) MoE (Qwen3-30B-A3B, 3 rounds) - first MoE datapoint for this PR:

quant base PR speedup pp512
Q4_K_M 42.94 47.67 1.110 0.998
Q4_0 pure 47.30 57.41 1.214 0.998

Takeaways:

  • The single-token MUL_MAT_ID path (the table has no has_ids input)
    benefits rather than regresses: +11% (Q4_K_M) / +21% (Q4_0) at bs=1 on
    a 128-expert MoE.
  • The Q4_K_M < Q4_0 gap matches the author's trend (mixed Q4_K_M +15% vs
    pure Q4_0 +38%): higher-precision / non-whitelist tensors in the mixed
    quant dilute the single-column effect.
  • Control types stay at 1.00 - the whitelist gating behaves as designed.

test-backend-ops on both builds (CUDA0): MUL_MAT 2445/2445 and MUL_MAT_ID 931/931 pass.

@meitmt

meitmt commented Oct 31, 2026

Copy link
Copy Markdown
Contributor Author

Independent verification + the missing MoE data point (AGX Orin 32GB)

Following the open question in this PR ("MoE model performance has not been measured"), I ran the same base/head builds on an AGX Orin 32GB(L4T 36.4.4, CUDA 12.6.85, MAXN power mode, jetson_clocks applied, desktop stopped). Both builds with -DCMAKE_CUDA_ARCHITECTURES=87; only libggml-cuda.so differs. Protocol: llama-bench -p 512 -n 128 -r 5 -ngl 99, interleaved rounds.

1) Cross-check on the author's model (LFM2.5-VL-3B, tg128 speedup vs base):

quant AGX Orin 32GB (mine) Nano Super (author)
Q4_0 1.33 1.34
Q4_K_M 1.11 1.15
Q4_K_S 1.16 1.18
Q8_0 1.19 1.23
Q5_K_S 1.07 1.06
Q6_K 1.00 1.02
Q2_K_M / Q3_K_S / IQ4_XS (controls) 1.00 1.00
pp512 within 1.00-1.02, matching the author's "<=0.4%" observation. Absolute t/s ~2x the Nano Super numbers, tracking the DRAM bus (AGX Orin 204.8 GB/s vs Nano Super 102 GB/s) - consistent with bandwidth-bound decode, so ratios are comparable.

2) Dense (Qwen3-8B, 3 rounds):

quant base PR speedup pp512
Q4_K_M 26.44 27.45 1.038 1.000
Q4_0 pure 30.45 34.04 1.118 1.002
3) MoE (Qwen3-30B-A3B, 3 rounds) - first MoE datapoint for this PR:

quant base PR speedup pp512
Q4_K_M 42.94 47.67 1.110 0.998
Q4_0 pure 47.30 57.41 1.214 0.998
Takeaways:

  • The single-token MUL_MAT_ID path (the table has no has_ids input)
    benefits rather than regresses: +11% (Q4_K_M) / +21% (Q4_0) at bs=1 on
    a 128-expert MoE.
  • The Q4_K_M < Q4_0 gap matches the author's trend (mixed Q4_K_M +15% vs
    pure Q4_0 +38%): higher-precision / non-whitelist tensors in the mixed
    quant dilute the single-column effect.
  • Control types stay at 1.00 - the whitelist gating behaves as designed.

test-backend-ops on both builds (CUDA0): MUL_MAT 2445/2445 and MUL_MAT_ID 931/931 pass.

Thanks for your verification. It seems my PR does improve decode speed for quantized models on sm_87. I will include your results in my PR and credit you.

Comment thread ggml/src/ggml-cuda/mmvq.cu Outdated
Comment on lines 624 to 649

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.

Instead of patching the existing branch, make a new one for Orin and inline the new device function.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the review. As requested, I have created a separate Orin branch and implemented function inlining. SASS verification confirms that all behaviors remain unchanged compared to the previous version of the PR.

@JohannesGaessler JohannesGaessler added the merge ready A maintainer can use this label to indicate that they consider the changes final and ready to merge. label Nov 19, 2026
@ggerganov
ggerganov merged commit ea84d70 into ggml-org:master Nov 20, 2026
15 of 24 checks passed
edwardyoon added a commit to edwardyoon/focus-llama that referenced this pull request Nov 20, 2026
Upstream ea84d70 (ggml-org#31268, Orin single-column MMVQ) added an ORIN
table_id branch calling the old function name calc_nwarps. The fork
renamed it to calc_max_nwarps during the mma_q port, so nvcc failed
with 'identifier calc_nwarps is undefined' at mmvq.cu(592).

Co-authored-by: Qwen-Coder <[email protected]>
Kidplayer666 pushed a commit to Kidplayer666/llama.cpp that referenced this pull request Nov 20, 2026
* CUDA: optimize Orin single-column MMVQ

* Create a separate Orin branch in `calc_rows_per_block`
Annieren pushed a commit to Annieren/llama.cpp-upstream that referenced this pull request Nov 23, 2026
* CUDA: optimize Orin single-column MMVQ

* Create a separate Orin branch in `calc_rows_per_block`
Nindaleth pushed a commit to Nindaleth/llama.cpp that referenced this pull request Nov 26, 2026
* CUDA: optimize Orin single-column MMVQ

* Create a separate Orin branch in `calc_rows_per_block`
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 merge ready A maintainer can use this label to indicate that they consider the changes final and ready to merge.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants