Skip to content

[CUDA] Add opt-in single-warp INT4 GEMV for FP16 decode - #33952

Open
Sunghoon Choi (hanbitmyths) wants to merge 4 commits into
mainfrom
sunghcho/qwen-vl-single-warp-int4-gemv-20261106
Open

Sunghoon Choi (hanbitmyths) wants to merge 4 commits into
mainfrom
sunghcho/qwen-vl-single-warp-int4-gemv-20261106

Conversation

@hanbitmyths

@hanbitmyths Sunghoon Choi (hanbitmyths) commented Nov 6, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Opt-in single-warp CUDA GEMV for FP16, M=1, symmetric INT4/group32, no bias/zero points, at (N,K)=(1024,2048) and (2048,6144).
  • Enable only with ORT_ENABLE_SINGLE_WARP_INT4_GEMV=1; the global specialization-disable control wins. Other dispatch and metadata fallbacks are unchanged.
  • (2048,2048) remains eight-warp because its one-warp hot-cache path regresses; historical gains for that shape do not describe current dispatch.

Companion: ORT #33932 handles capture/lifecycle.

Reported validation: 10 eligibility/graph + 2 numerical CUDA cases; 448 CUDA-event cells verify the excluded-shape fallback and bit-identical nonzero outputs. No CPU fallback.

Draft: consumer GPUs and the narrowed whitelist's model gain are unmeasured. No Qwen2 model speedup or default-enablement recommendation.

Performance: Qwen3-VL-2B

Combined package/runtime results, not isolated gains from this PR. Production uses decoder INT4/group32; optimized uses 66 INT8 + 131 INT4 projections, FP16 vision/embeddings/KV, pruned prefill and decoder capture.

A100-SXM4-80GB

Historical production: Oct 28 (b679913a2310); optimized: Nov 5 frozen clean gate.

Tokens Production TTFT ms Optimized TTFT ms Production decode tok/s Optimized decode tok/s Change
128 21.25 10.73 232.16 349.41 +50.50%
512 29.52 17.66 230.47 340.51 +47.75%
2048 62.12 47.78 219.57 325.15 +48.08%
4096 122.50 100.42 212.16 304.94 +43.73%
7680 241.71 206.10 202.21 288.68 +42.76%

H200

Baseline: official qwen3-vl-2b-instruct-cuda-gpu:2 on published ORT 1.31.1 / GenAI 0.19.0, CUDA 13. Optimized: retained Nov 8 FPA1 results, not rerun.

Workload Baseline TTFT ms Optimized TTFT ms Baseline decode tok/s Optimized decode tok/s Change (unpaired)
Text 128 9.06 8.04 220.0 514.9 +134.08%
Text 512 12.29 11.08 216.0 516.7 +139.25%
Text 2048 26.07 25.98 211.7 504.8 +138.42%
Text 4096 52.39 51.55 205.3 481.0 +134.26%
Text 7680 104.96 103.56 201.6 467.3 +131.85%
Image + text 30.55 40.90 216.9 514.4 +137.16%

Controls: batch 1, context 8192, FP16 KV, chunk 2048, 128 outputs, 8 inference threads, no prefix reuse. TTFT is HTTP first-token latency; decode uses 127 first-to-last intervals. A100: 7 production / 14 optimized samples. H200 baseline: 14 samples/row after warmups, GPU 1 / CPU cores 8-15; pre-rendered prompts, tokenization/image processing inside HTTP.

Limits: H200 is unpaired: prompts/harness differ; the new 448x448 image has 244 input tokens versus 356 historically. Ratios are descriptive, not causal speedups. A100 is not matched to the new H200 runtime; no cross-GPU hardware claim. Optimized ORT 5481f20b / GenAI 4e51307d + 41c96365 are frozen, not current PR-head benchmarks.

Review required: historical optimized export loses 9 AI2D answers versus the accepted native recipe; padded/batched capture limitations remain. No default promotion.

Extract the independent GEMV optimization, controls, documentation, numeric differentials, and native dispatch tests from the CUDA graph-ownership PR. Existing kernels remain the default and unsupported shapes or metadata keep their existing fallbacks.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Sunghoon Choi <sunghcho@microsoft.com>
Use only ORT_ENABLE_SINGLE_WARP_INT4_GEMV for operator-scoped opt-in. Preserve tensor-shape dispatch and default behavior; cover generic enablement, disablement, global override, and invalid controls without model-named aliases.

Signed-off-by: Sunghoon Choi <sunghcho@microsoft.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI 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.

🟡 Changes recommended

The CUDA numerical regression leaves CPU fallback enabled, allowing tests to pass even if FP16 MatMulNBits nodes stop running on CUDA.

1 open issue
What changed in this PR

Adds an opt-in single-warp INT4 GEMV path to CUDA MatMulNBits for three FP16 decode shapes. This separates the math optimization from the companion CUDA graph lifecycle work; consumer-GPU performance validation remains pending.

Changes:

  • Parameterizes kernel tiling and reduction unrolling while preserving defaults for existing callers.
  • Adds shape-restricted dispatch controlled by ORT_ENABLE_SINGLE_WARP_INT4_GEMV, with the existing global disable override.
  • Documents the controls and adds eligibility, launch-geometry, fallback, and numerical tests.
File Description
onnxruntime/​test/​providers/​cuda/​test_cases/​matmul_nbits_gemv_test.cc Adds eligibility and captured launch-geometry tests.
onnxruntime/​test/​contrib_ops/​matmul_4bits_test.cc Adds numerical tests across enablement settings and projection shapes.
onnxruntime/​contrib_ops/​cuda/​quantization/​matmul_nbits.cuh Defines shape eligibility and declares the single-warp launcher.
onnxruntime/​contrib_ops/​cuda/​quantization/​matmul_4bits.cu Adds opt-in dispatch with the global disable override.
onnxruntime/​contrib_ops/​cuda/​quantization/​matmul_4bits_m1_impl.cuh Parameterizes columns per block and reduction unrolling.
onnxruntime/​contrib_ops/​cuda/​quantization/​matmul_4bits_half.cu Implements the FP16 single-warp kernel launcher.
docs/​contrib_ops/​cuda/​matmul_nbits.md Documents enablement, supported shapes, and disable behavior.

Review effort: Balanced

Signed-off-by: Sunghoon Choi <sunghcho@microsoft.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@hanbitmyths

Copy link
Copy Markdown
Collaborator Author

CUDA numerical-routing review follow-up

Addressed the CPU-fallback comment in be5ed6f2.

The new numerical regression now sets the existing disable_cpu_ep_fallback option. Merely selecting the CUDA EP is no longer the routing evidence: CPU assignment/fallback is explicitly forbidden for this test.

Validation:

  • The numerical regression passed all 12 CUDA-only cells: generic opt-in enabled/unset/disabled across all four shapes, retaining the existing numerical tolerances.
  • Nine actual internal eligibility/launch/dispatch cases also passed without skips.
  • This was focused incremental validation: the changed numerical C++ test was recompiled and the native runner relinked; the six previously compiled CUDA units, internal test object, and provider artifacts were hash-verified and reused. It was not a clean full-tree rebuild.

The published change is test-only: no GPU kernel, eligibility, runtime control, or model-specific switch was added or changed. No fresh throughput/quality result is claimed.

The consumer-GPU benchmarking request is still hardware-blocked: the available devices are A100s, not consumer GPUs. This PR remains draft, and its existing historical performance/provenance caveats are unchanged.

Copilot AI 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.

🔵 Needs a closer look

The one-warp CUDA launch policy and tuned shape whitelist still require representative consumer-GPU benchmarks and human review before merging.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

Exclude 2048x2048 from the single-warp whitelist to avoid its H200 hot-cache regression. Preserve the other opt-in shapes and update eligibility, dispatch coverage, and documentation.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@hanbitmyths
Sunghoon Choi (hanbitmyths) marked this pull request as ready for review November 9, 2026 05:21

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.

AI-assisted source review at 8fe60f4e9b1b50fd6be38acf2616fc275de35978.

Reviewed the single-warp mapping, packed-weight/scale access, reductions, alignment, launch geometry, opt-in/global-disable precedence, fallback preservation, and test controls. Eligibility is restricted to FP16 M=1/block-32/no-zero-point/no-bias and the two whitelisted (N,K) shapes. The earlier CPU-fallback concern is addressed.

No new actionable findings in this pass. Independent host mapping probes covered every K element exactly once for K=2048 and K=6144, with corresponding packed bytes/scales in bounds. Reported head checks are 102 successful and one neutral. No CUDA compilation, GPU numerical execution, or performance benchmark was run; this review does not independently substantiate the claimed speedup.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants