Repository navigation
CUDA: optimize Orin single-column MMVQ - #31268
Conversation
|
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 1) Cross-check on the author's model (LFM2.5-VL-3B, tg128 speedup vs base):
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):
3) MoE (Qwen3-30B-A3B, 3 rounds) - first MoE datapoint for this PR:
Takeaways:
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. |
There was a problem hiding this comment.
Instead of patching the existing branch, make a new one for Orin and inline the new device function.
There was a problem hiding this comment.
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.
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]>
* CUDA: optimize Orin single-column MMVQ * Create a separate Orin branch in `calc_rows_per_block`
* CUDA: optimize Orin single-column MMVQ * Create a separate Orin branch in `calc_rows_per_block`
* CUDA: optimize Orin single-column MMVQ * Create a separate Orin branch in `calc_rows_per_block`
Overview
Following the maintainer's feedback in #30858, this PR adds
MMVQ_PARAMETERS_ORINto the MMVQ parameter table. For single-column operations, nine selected types usenwarpsrows 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, ornativewhen 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, thellama-benchresults show:Q4_0decode improves by about 38%.Q4_K_Mmodel improves by 15%. PureQ4_K_SandQ8_0improve by 18% and 23%.Q5_K_Simproves by 6%, and pureQ6_Kby about 2%.Q2_K,Q3_K_S, andIQ4_XSmodels show no speed change at the precision reported in the table.Only
libggml-cuda.sochanges between the baseline and patched builds in each comparison.Reason
For single-column MMVQ on Orin, the new table uses the same
nwarpsvalue as GENERIC: 4. This PR sets the number of rows per block tonwarpsfor 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:MMVQ_PARAMETERS_ORINtommvq_parameter_table_id.get_device_table_id(), select it when__CUDA_ARCH__ == GGML_CUDA_CC_ORIN.get_device_table_id(int cc), select it for NVIDIA whenggml_cuda_highest_compiled_arch(cc) == GGML_CUDA_CC_ORIN.calc_nwarps, use the GENERIC values for Orin.calc_rows_per_block, usenwarpsrows 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, andIQ4_NL. These are the same nine types for which the existing GB10 entry increasesnwarps.The first build used eight types, without
Q6_K. AddingQ6_Kraises the gain for the distributedQ4_K_Mmodel from 10.6% to 15.1%. That model usesQ6_Kfor some tensors, including the output layer, which can benefit from this change even though a pureQ6_Kmodel gains only about 2%.A broader build also changed the other types, except
IQ3_XXSandIQ3_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_Kgained 1.8%,IQ4_XSgained 1.4%, andQ3_K_Sslowed 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_idsinput, so single-tokenMUL_MAT_IDoperations also use the new parameters for the selected types.test-backend-ops -o MUL_MAT_ID -b CUDA0passes 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.
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.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)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.
Qwen3, tg128, tokens/s, 3 rounds, MAXN +
jetson_clocksCUDA fusion
The fusion results below were measured with the previous patch (#30858) on
7951f601e. They were not repeated for this version. BothQ6_KandQ4_0use the same row configuration in the old and new patches.These results help explain why pure
Q6_Kgains only about 2% with fusion enabled, while keepingQ6_Kin the whitelist still helps the distributedQ4_K_Mmodel. With CUDA fusion disabled, pureQ6_Kgains 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)7951f601ePerformance 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
7894e8b92and the new patch.test-backend-ops -o MUL_MAT -b CUDA0test-backend-ops -o MUL_MAT_ID -b CUDA0llama-perplexityVL-3B Q4_K_M, WikiText-2,-c 512 -b 512 -ub 1 --chunks 10llama-perplexityVL-3B Q4_0, same settingsEnvironment
jetson_clocks, desktop stopped7894e8b92-DCMAKE_CUDA_ARCHITECTURES=87, ornativewhen building on OrinRelated
small_klayout with the same four-row arrangement. This PR leaves thesmall_kselection rules unchanged.Command
Requirements