Skip to content

feat(bitsandbytes): RDNA4 fused 4-bit GEMM (2.4x-6.3x vs vendor HIP kernel) - #3533

Merged
Qubitium merged 1 commit into
ModelCloud:mainfrom
Qubitium:bnb-rdna4
Nov 4, 2026
Merged

Qubitium merged 1 commit into
ModelCloud:mainfrom
Qubitium:bnb-rdna4

Conversation

@Qubitium

@Qubitium Qubitium commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator

Summary

bitsandbytes 0.50.2 installs and runs on ROCm 10.1, but its HIP 4-bit GEMM is tuned for CDNA wave64 and falls off a cliff on RDNA4 at exactly M >= 16 — a different, much slower kernel is selected (e.g. 95 us -> 324 us at K=N=4096).

This adds a fused Triton 4-bit GEMM for the row band where the vendor kernel is pathological. It dequantizes the packed NF4/FP4 codes inside the matmul, so the packed weights are read once and no dense weight buffer is ever written.

Follow-up to #3532 (the 4090 + RDNA4 kernel-parity work). This closes the last quantization pipeline that had no tuned RDNA4 path.

What changed

File Change
gptqmodel/nn_modules/qlinear/bitsandbytes_triton.py new: BnbGemmLaunch, _BNB_GEMM_LAUNCH = {ada, rdna4}, fused GEMM + dequant kernels, should_use() gate
gptqmodel/nn_modules/qlinear/bitsandbytes.py BitsAndBytesLinear.forward dispatches to the fused kernel for M >= min_m on tuned ROCm families
tests/kernels/test_bitsandbytes_rocm_triton.py new: CPU-only table/gate tests + FP64-oracle kernel tests
tests/test_hw_parity_contract.py register bitsandbytes_4bit_gemm in TUNED_PIPELINES
docs/rocm-rdna4.md, docs/hw-tuning-parity.md format notes, measurements, and the family-dependent-default policy

Dispatch policy

  • ROCm + tuned family (rdna4) + M >= 16 -> fused Triton kernel.
  • M < 16 -> bitsandbytes' own GEMV, which is ~2x faster than a tiled kernel here (measured; a GEMV port was prototyped and deliberately not shipped).
  • CUDA/Ada -> vendor cuBLAS kernels, which measured faster on every shape tested. The ada launch entry exists for the parity contract and for forced A/B runs via GPTQMODEL_BNB_TRITON=1.
  • INT8 -> untouched; bitsandbytes already runs at 48-78 us on RDNA4, no pathology.

Measured speedup (gfx1201, R9700, FP16, end-to-end module forward, 50 iters)

shape M bnb native fused Triton speedup
K=N=2048 16 109 us 76 us 1.44x
K=N=2048 64 133 us 69 us 1.93x
K=N=4096 16 378 us 83 us 4.55x
K=N=4096 64 327 us 103 us 3.17x
K=4096 N=11008 16 1025 us 183 us 5.59x
K=4096 N=11008 64 1006 us 287 us 3.51x

Packed-format verification

Verified byte-for-byte against bitsandbytes.functional.dequantize_4bit for NF4/FP4, block sizes 32/64/128, with and without compress_statistics:

  • flat index i = n*K + k; byte i // 2; even element = high nibble, odd = low nibble
  • absmax[(n*K + k) // blocksize]
  • compress_statistics=True: absmax is itself blockwise-quantized uint8, expanded once to FP32 (a scale tensor, not a dense weight)
  • codebook comes from quant_state.code (fp4 is not the e2m1 table)
  • gfx1201 shared-memory limit is 65536 B: (32,32,256,4,2) OOMs, final tile is (32,32,128,4,1)

Numerical validation

Independent FP64 Torch oracle that never calls the kernel under test:

  • dequantize: exact to FP32 vs FP64 decode (rtol/atol 1e-6)
  • matmul: rel-to-max <= 3.5e-4 (FP16), <= 2.7e-3 (BF16)
  • output.dtype == input.dtype in every case
  • repeated forwards bit-identical; no registered buffer changes shape; no buffer is a dense (out_features, in_features) weight

Tests

  • kernels/test_bitsandbytes_rocm_triton.py + test_hw_parity_contract.py + test_bitsandbytes.py: 53 passed, 12 skipped on both CUDA and ROCm.
  • Full hardware suites after the change:
    • CUDA (4090): 350 passed, 59 skipped
    • ROCm (R9700): 297 passed, 107 skipped
  • test_hw_parity_contract.py passes hardware-free and now enforces an ada + rdna4 tile for this pipeline.

Non-goals

  • No GEMV kernel (vendor is faster).
  • No INT8 replacement (no pathology).
  • No Ada default change (vendor wins there).

…ernel)

bitsandbytes 0.50.2's HIP 4-bit GEMM is tuned for CDNA wave64 and falls off
a cliff at M >= 16 on gfx1201. Route that row band to a fused Triton kernel
that dequantizes the packed NF4/FP4 codes inside the matmul, so no dense
weight buffer is ever materialized.

- new gptqmodel/nn_modules/qlinear/bitsandbytes_triton.py with family-keyed
  launch tables (ada, rdna4) and an FP64-oracle-verified packed layout
- BitsAndBytesLinear.forward dispatches for M >= 16 on tuned ROCm families;
  below that, and everywhere on CUDA, bitsandbytes' own GEMV/cuBLAS stays
- the Triton path is ROCm-only by default; GPTQMODEL_BNB_TRITON=1 forces it
  for Ada A/B runs, where the vendor kernel measured faster on every shape
- register the pipeline in tests/test_hw_parity_contract.py TUNED_PIPELINES
- docs: rocm-rdna4.md section + hw-tuning-parity.md note

Measured (gfx1201, FP16, 50 iters): 1.44x/1.93x at K=N=2048 M=16/64,
4.55x/3.17x at K=N=4096, 5.59x/3.51x at K=4096 N=11008.
Oracle: dequantize exact to FP32 vs FP64; matmul <=3.5e-4 (FP16),
<=2.7e-3 (BF16); dtype preserved; no dense buffers.
@Qubitium
Qubitium merged commit 3b2b28f into ModelCloud:main Nov 4, 2026
1 check failed
Qubitium added a commit to Qubitium/GPTQModel that referenced this pull request Nov 4, 2026
The hardware-parity work (ModelCloud#3532) and the bitsandbytes RDNA4 GEMM (ModelCloud#3533)
left ten violations in the CI lint scope (gptqmodel, docs/eora, tests,
setup.py): four unused imports, four import-ordering issues, one unused
local, and one dict() literal.

- drop unused imports: arch_class, AwqTritonPlan, numpy, gptq_gemm alias
- sort the import blocks in the bitsandbytes, GGUF, and AWQ GEMV tests
- remove the unused __doc__ probe and BACKEND import in the ROCm gating test
- rewrite the AWQ plan shape as a dict literal

README: fold the parity and bitsandbytes coverage into the 7.9.0 release
notes, list the new RDNA4 kernels in the platform table, and describe the
bitsandbytes ROCm dispatch.

ruff check gptqmodel docs/eora tests setup.py: all checks passed.
tests: CUDA 192 passed / 2 skipped, ROCm 120 passed / 1 skipped.
Qubitium added a commit that referenced this pull request Nov 4, 2026
…ME (#3534)

The hardware-parity work (#3532) and the bitsandbytes RDNA4 GEMM (#3533)
left ten violations in the CI lint scope (gptqmodel, docs/eora, tests,
setup.py): four unused imports, four import-ordering issues, one unused
local, and one dict() literal.

- drop unused imports: arch_class, AwqTritonPlan, numpy, gptq_gemm alias
- sort the import blocks in the bitsandbytes, GGUF, and AWQ GEMV tests
- remove the unused __doc__ probe and BACKEND import in the ROCm gating test
- rewrite the AWQ plan shape as a dict literal

README: fold the parity and bitsandbytes coverage into the 7.9.0 release
notes, list the new RDNA4 kernels in the platform table, and describe the
bitsandbytes ROCm dispatch.

ruff check gptqmodel docs/eora tests setup.py: all checks passed.
tests: CUDA 192 passed / 2 skipped, ROCm 120 passed / 1 skipped.
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.

1 participant