Repository navigation
[CUDA] Support BF16 compact MatMulNBits - #32721
Merged
Merged
Conversation
Extend compact fpA_intB dispatch and eligibility to BF16 activations with INT4/INT8 weights at block_size=32. Validated with eight H200 CUDA provider tests.
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The prepacked-weight diagnostic incorrectly claims BF16 support begins at SM75 instead of SM80.
Get a fresh assessment by requesting another Copilot review.
Review effort: Balanced
Findings: 1
Open (1)
What changed in this PR
Extends compact CUDA MatMulNBits to support BF16 activations with INT4/INT8 weights on SM80+.
Changes:
- Adds BF16 eligibility, GEMM/GEMV dispatch, and profiler mappings.
- Retains BF16 kernel sources in compact builds.
- Adds coverage and documents hardware constraints.
| File | Description |
|---|---|
cmake/CMakeLists.txt |
Updates compact-kernel build descriptions. |
cmake/onnxruntime_cuda_source_filters.cmake |
Retains compact BF16 kernel sources. |
docs/contrib_ops/cuda/matmul_nbits.md |
Documents BF16 support and SM80 requirement. |
onnxruntime/contrib_ops/cuda/llm/fpA_intB_gemv/fpA_intB_gemv.cu |
Adds BF16 GEMV dispatch and validation. |
onnxruntime/contrib_ops/cuda/quantization/matmul_nbits.cc |
Adds BF16 eligibility and GEMM profiling. |
onnxruntime/contrib_ops/cuda/quantization/matmul_nbits.h |
Updates prepacked-weight diagnostics. |
onnxruntime/test/contrib_ops/cuda_kernels/fpA_intB_gemm_kernel_test.cc |
Adds compact BF16 kernel tests. |
onnxruntime/test/providers/cuda/test_cases/matmul_nbits_workspace_test.cc |
Tests BF16 eligibility and architecture gating. |
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Baiju Meswani (baijumeswani)
approved these changes
Sep 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Expand compact fpA_intB MatMulNBits support to BF16 activations while retaining FP16 support for INT4 and INT8 weights with block_size=32. This enables the compact CUDA path for BF16 workloads on SM80 and newer GPUs, adds the matching dispatch and eligibility coverage, and documents the supported contract.
Summary of Changes
Compact CUDA support
USE_COMPACT_FPA_INTB_GEMMGEMM and GEMV dispatch to BF16 activations for INT4 and INT8 weights.Build and documentation
cmake/CMakeLists.txtcmake/onnxruntime_cuda_source_filters.cmakedocs/contrib_ops/cuda/matmul_nbits.mdTests
Testing
lintrunner -apassed with Ruff and ClangFormat.onnxruntime_provider_testinbuild/cu130_fp4_bench/Release.MatMulNBitsruntime tests on an NVIDIA H200 (SM90); all passed, including FP16/BF16 INT4/INT8, BF16 small-M, no-zero-point, and bias cases.git diff --checkpassed.onnxruntime_ENABLE_CUDA_EP_INTERNAL_TESTS=OFFin the local build configuration.Motivation and Context
The compact fpA_intB implementation previously handled FP16 activations only. Adding BF16 support at the same block-size and weight-width contract allows the existing CUDA execution path to serve BF16 models without changing the INT2 behavior or requiring a separate fallback-specific implementation.
Checklist