Repository navigation
feat(bitsandbytes): RDNA4 fused 4-bit GEMM (2.4x-6.3x vs vendor HIP kernel) - #3533
Merged
Merged
Conversation
…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
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.
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.
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
gptqmodel/nn_modules/qlinear/bitsandbytes_triton.pyBnbGemmLaunch,_BNB_GEMM_LAUNCH = {ada, rdna4}, fused GEMM + dequant kernels,should_use()gategptqmodel/nn_modules/qlinear/bitsandbytes.pyBitsAndBytesLinear.forwarddispatches to the fused kernel forM >= min_mon tuned ROCm familiestests/kernels/test_bitsandbytes_rocm_triton.pytests/test_hw_parity_contract.pybitsandbytes_4bit_gemminTUNED_PIPELINESdocs/rocm-rdna4.md,docs/hw-tuning-parity.mdDispatch policy
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).adalaunch entry exists for the parity contract and for forced A/B runs viaGPTQMODEL_BNB_TRITON=1.Measured speedup (gfx1201, R9700, FP16, end-to-end module forward, 50 iters)
Packed-format verification
Verified byte-for-byte against
bitsandbytes.functional.dequantize_4bitfor NF4/FP4, block sizes 32/64/128, with and withoutcompress_statistics:i = n*K + k; bytei // 2; even element = high nibble, odd = low nibbleabsmax[(n*K + k) // blocksize]compress_statistics=True: absmax is itself blockwise-quantized uint8, expanded once to FP32 (a scale tensor, not a dense weight)quant_state.code(fp4 is not the e2m1 table)(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:
output.dtype == input.dtypein every case(out_features, in_features)weightTests
kernels/test_bitsandbytes_rocm_triton.py+test_hw_parity_contract.py+test_bitsandbytes.py: 53 passed, 12 skipped on both CUDA and ROCm.test_hw_parity_contract.pypasses hardware-free and now enforces anada+rdna4tile for this pipeline.Non-goals