Skip to content

CUDA: Enable small_k (regardless of K) for MMVQ on Jetson Orin when bs=1 - #30858

Closed
meitmt wants to merge 1 commit into
ggml-org:masterfrom
meitmt:cuda-orin-mmvq-small-k
Closed

meitmt wants to merge 1 commit into
ggml-org:masterfrom
meitmt:cuda-orin-mmvq-small-k

Conversation

@meitmt

@meitmt meitmt commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Overview

MMVQ normally uses small_k when nwarps > 1 and K is small enough for a thread block to cover a row in one loop iteration. There are also rules based on the data type and GPU architecture. On Orin, the default single-column layout processes one row per block for most types. It processes two rows per block for Q1_0, Q2_K, Q3_K, IQ1_S, and IQ1_M.

This PR removes the K-size limit for single-column MMVQ without ids on Jetson Orin (cc == GGML_CUDA_CC_ORIN). It keeps the nwarps > 1 check. It also keeps the rule that single-column IQ3_XXS and IQ3_S do not use small_k on Orin. The change applies to AGX Orin, Orin NX, and Orin Nano. It was tested on an Orin Nano Super Developer Kit.

Use llama-bench test on Orin Nano Super in different quant types, with MAXN_SUPER + jetson_clocks, decode (tg128) speed rose. Only modify libggml-cuda.so for each comparison.

Use LFM2.5.

  • The best improvement was seen with Q4_0, where decoding speed increased by approximately 38%. The worst performance was observed with Q3_K_S, where decoding speed decreased by 1%.
  • Common quantization formats show strong performance: Q4_K_M yields a 15% improvement, Q4_K_S an 18% improvement, and Q8_0 a 23% improvement.
  • The prefill speed remains unchanged.
  • There is only a minor improvement when using some K-quant types.

Reason

For single-column MMVQ on Orin, the GENERIC parameter table sets nwarps to 4. The small_k layout sets the number of rows per block to nwarps, 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 change is in should_use_small_k, inside mul_mat_vec_q_switch_ncols_dst. It sets use to nwarps > 1 when all four conditions are met:

  • GGML_CUDA_CC_IS_NVIDIA(cc)
  • cc == GGML_CUDA_CC_ORIN (compute capability 8.7)
  • c_ncols_dst == 1
  • !has_ids

The !has_ids check excludes the MUL_MAT_ID path used for MoE. The data type checks still run after this new condition.

Result

Quantization sweep (compare-llama-bench.py, LFM2.5-VL-3B LM quantized with llama-quantize --pure)

Model Test t/s master t/s PR Speedup
lfm2 2.6B IQ4_NL - 4.5 bpw pp512 1198.33 1199.29 1.00
lfm2 2.6B IQ4_NL - 4.5 bpw tg128 34.28 41.82 1.22
lfm2 2.6B IQ4_XS - 4.25 bpw pp512 1259.57 1259.66 1.00
lfm2 2.6B IQ4_XS - 4.25 bpw tg128 29.56 30.01 1.02
lfm2 2.6B Q2_K_M pp512 742.21 741.80 1.00
lfm2 2.6B Q2_K_M tg128 39.92 40.68 1.02
lfm2 2.6B Q3_K_S pp512 952.01 952.37 1.00
lfm2 2.6B Q3_K_S tg128 23.58 23.41 0.99
lfm2 2.6B Q4_0 pp512 1204.30 1209.39 1.00
lfm2 2.6B Q4_0 tg128 32.43 44.71 1.38
lfm2 2.6B Q4_1 pp512 1087.72 1091.42 1.00
lfm2 2.6B Q4_1 tg128 34.28 43.28 1.26
lfm2 2.6B Q4_K_S pp512 1087.90 1090.69 1.00
lfm2 2.6B Q4_K_S tg128 29.20 34.40 1.18
lfm2 2.6B Q5_0 pp512 1162.86 1165.25 1.00
lfm2 2.6B Q5_0 tg128 29.80 35.86 1.20
lfm2 2.6B Q5_1 pp512 1042.51 1044.23 1.00
lfm2 2.6B Q5_1 tg128 29.40 38.40 1.31
lfm2 2.6B Q5_K_S pp512 1047.94 1049.46 1.00
lfm2 2.6B Q5_K_S tg128 26.19 27.83 1.06
lfm2 2.6B Q6_K pp512 961.04 962.94 1.00
lfm2 2.6B Q6_K tg128 25.68 26.32 1.02
lfm2 2.6B Q8_0 pp512 1207.03 1211.76 1.00
lfm2 2.6B Q8_0 tg128 22.24 27.29 1.23
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 488.9 382.9 +27.7%
q4_1 4096x14336 436.1 381.8 +14.2%
q5_0 4096x14336 596.5 523.7 +13.9%
q5_1 4096x14336 576.8 513.7 +12.3%
q8_0 4096x14336 802.6 705.5 +13.8%
q2_K 4096x14336 339.2 300.1 +13.0%
q3_K 4096x14336 569.7 501.5 +13.6%
q4_K 4096x14336 543.2 488.4 +11.2%
q4_K 4096x4096 193.8 155.2 +24.8%
q4_K 6144x4096 305.0 227.2 +34.3%
q4_K 14336x4096 687.3 511.5 +34.4%
q5_K 4096x14336 656.7 591.0 +11.1%
q6_K 4096x14336 754.3 664.0 +13.6%
iq4_nl 4096x14336 537.3 448.5 +19.8%
iq4_xs 4096x14336 489.2 434.5 +12.6%
mxfp4 4096x14336 625.5 534.2 +17.1%
nvfp4 4096x14336 536.2 498.8 +7.5%
iq2_s 4096x14336 577.0 441.9 +30.6%
iq2_xs 4096x14336 511.4 425.1 +20.3%
iq2_xxs 4096x14336 467.4 407.0 +14.8%
iq1_s 4096x14336 404.3 354.5 +14.0%
iq1_m 4096x14336 431.6 393.2 +9.8%
q1_0 4096x14336 219.3 199.2 +10.1%
q2_0 4096x14336 297.6 242.6 +22.7%
iq3_s 4096x14336 613.7 613.6 0.0% (excluded, unchanged)
iq3_xxs 4096x14336 519.7 520.4 -0.1% (excluded, unchanged)
f16 4096x14336 1174.9 1176.2 -0.1% (not MMVQ)
LFM2.5 models as distributed (tg128, t/s)
Model Power master PR Speedup
LFM2.5-2.6B Q4_K_M MAXN_SUPER 28.63 32.97 1.15
LFM2.5-VL-3B Q4_K_M MAXN_SUPER 28.64 32.98 1.15
LFM2.5-VL-3B Q4_0 MAXN_SUPER 31.75 42.52 1.34
LFM2.5-VL-3B Q8_0 MAXN_SUPER 22.24 27.27 1.23
LFM2.5-2.6B Q4_K_M default 25 W 26.24 30.20 1.15
LFM2.5-VL-3B Q4_K_M default 25 W 26.22 30.25 1.15

Additional information

GGML_CUDA_DISABLE_FUSION will have an impact on this PR. Disabling the fusion will lead to a slight decrease in decoding speed on the master branch, whereas this PR will see a notable improvement in decoding speed. Even in PR scenarios, disabling fusion results in faster decoding speeds compared to having it enabled.

Fused gate/up path (GGML_CUDA_DISABLE_FUSION, tg128, t/s, 2 rounds each)
Model CUDA fusion master PR 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

This PR has been tested exclusively on the Jetson Orin Nano, and evaluations were conducted solely for the LFM2.5 series of models.

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.

Check master PR
test-backend-ops -o MUL_MAT -b CUDA0 (2 runs each) 2445/2445 2445/2445
llama-perplexity LFM2.5-2.6B Q4_K_M, WikiText-2, -c 512 --chunks 10 -ub 1 38.0967 ± 2.83712 38.0967 ± 2.83712
llama-perplexity LFM2.5-VL-3B Q4_K_M, same settings 13.3141 ± 0.75384 13.3141 ± 0.75384

Environment

  • Jetson Orin Nano Super Developer Kit, 8 GB
  • JetPack 6.2 (L4T 36.4.3), CUDA 12.6
  • MAXN_SUPER + jetson_clocks, and a set of comparisons at the default 25W power level.
  • baseline: Measurement based on master 7951f60, branch based on commit 0ce8cd1

Related

#20635

#28285

#26843

#15034

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>
GGML_CUDA_DISABLE_FUSION=1 llama-bench -m <model> -p 0 -n 128 -r 5 -ngl 99
test-backend-ops perf -o MUL_MAT -b CUDA0 -p 'n=1,'
test-backend-ops -o MUL_MAT -b CUDA0
llama-perplexity -m <model> -f wiki.test.raw -c 512 -b 512 -ub 1 --chunks 10 -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. Meanwhile, AI assisted in reviewing PRs and providing suggestions for revisions. All PR body was written by me.

@meitmt
meitmt requested a review from a team as a code owner October 20, 2026 07:00
@meitmt meitmt changed the title <CUDA: Enable small_k (regardless of K) for MMVQ on Jetson Orin when … CUDA: Enable small_k (regardless of K) for MMVQ on Jetson Orin when bs=1 Oct 20, 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 Oct 20, 2026
@JohannesGaessler

Copy link
Copy Markdown
Contributor

Handle this by adding an entry to mmvq_parameter_table_id instead.

@meitmt

meitmt commented Oct 27, 2026

Copy link
Copy Markdown
Contributor Author

Handle this by adding an entry to mmvq_parameter_table_id instead.

OK. I rework it as a parameter table entry in #31268 .

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.

2 participants