Repository navigation
feat(rocm): RDNA4 (gfx1200/gfx1201/gfx1250) kernel and quantization support - #3478
Conversation
…upport
Adds RDNA4 as a first-class ROCm target alongside the existing gfx950 (CDNA4)
support. The MI350/gfx950 kernels were audited and kept behaviourally identical;
RDNA4 reuses the same kernels with per-architecture tuning instead of inheriting
CDNA constants.
Architecture abstraction (new gptqmodel/utils/arch.py)
normalize_arch / rocm_arch (cached per device) / arch_class / is_rdna4 /
is_rocm_fused_arch / wave_size / gate_limits / gemm_fused_dtypes.
Never uses torch.cuda.get_device_capability for AMD: on ROCm it returns an
unrelated numeric pair, which is what the old gfx950 string checks worked
around. All previous hard-coded "gfx950" gates now go through this module.
Inference kernels (per-architecture launch tables)
- gptq_gemm: rdna4 tile (32, 32) / num_warps=4; gate (16, 17408) measured on
gfx1201. The fused small-M GEMM is FP16-only on RDNA4 (BF16 measured
0.43x-1.42x of the split path, median 0.85x), so BF16 takes
dequantize+matmul. GEMV stays enabled for both dtypes.
- gptq_gemv: rdna4 block_n=16 / num_warps=4.
- dequant: rdna4 (x_block=2048, num_warps=4, num_stages=1) measured at a
74.5 us geomean vs the CDNA tile's 81.7 us; output stays bit-identical.
- tl.dot lowers to v_wmma_f32_16x16x16_f16 on wave32; verified in the
generated .amdgcn, not assumed.
Quantization paths
- rocm.quantize_tuning(device): per-arch BLAS backend (rocBLAS default on
both CDNA and RDNA4), AMP flag, and a reduced RDNA4 prewarm payload.
- FP8: stop inferring AMD dtype/FP8 support from an NVIDIA compute
capability; _scaled_mm accepts e4m3fn/e5m2 and rejects the fnuz encodings on
gfx1201 with a single log line and a dequantize+matmul fallback.
- EXL3: AUTO resolves to EXL3_TORCH on ROCm (the EXL3 tensor-core GEMM
dispatch table is nullptr for HIP).
- GGUF/VPTQ/ParoQuant/AWQ: an explicit ROCm decision per backend instead of
inheriting a CUDA default.
Correctness fixes found while auditing (these are not RDNA4-only)
- QQQ and EXL3 skipped every module when `dynamic` was None, because
`dynamic_get` returns None for "no matching rule" and the call sites tested
it for truthiness. EXL3 quantization was a silent no-op; QQQ raced the JIT.
Both now test `is False`; QQQ also validates the runtime in `_validate` so
AUTO picks QQQTorchLinear up front instead of failing on first forward.
- AWQ GEMV / GEMV_FAST / LLM_AWQ claimed ROCm support but their native CUDA
extension cannot be built by hipcc (cuda_fp16.h, CUDA inline asm, 64-bit
warp mask). They are now CUDA-only with an actionable error pointing at
AWQ_GEMM_TRITON.
- QQQ's native W4A8 kernel is CUDA-only inline PTX (cp.async/mma.sync/
ldmatrix); it is rejected on ROCm up front rather than after an ~18 s JIT
compile that then fails.
Verification (AMD Radeon AI PRO R9700, gfx1201, HIP 7.16.26385, devices 2-3)
- GPTQ fused GEMV/GEMM numerics vs an independent Torch oracle: pass, both
FP16 and BF16 where enabled; 92 gfx950-only cases skip as designed.
- AWQ Triton GEMM vs an independent Torch oracle: pass.
- Full suite for the touched areas: 376 passed, 181 skipped.
- End-to-end 4-bit quantization of Qwen3-0.6B: 588 int32 packed tensors,
no dense weight retained.
- gfx1200 / gfx1250 have no hardware here; they share the gfx1201 family table
and are documented as not independently measured.
Deps: none. Docs: docs/rocm-rdna4.md, README AMD row,
scripts/benchmark_rdna4_{quant,inference}.py.
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved critical defects cause ROCm forward failures and incorrect FP8 fallback weights, while a CUDA reduction-mask regression can produce undefined results.
22 open issues
Fix ROCm Hadamard dtype mismatch and add a forward test · New Preserve inverse-scale semantics in the CPU fallback · New Do not advertise unvalidated ROCm NVFP4 support · New Use a full warp mask for CUDA reductions · New Restrict native-cast fallback to ROCm and avoid repeated retries · New Return no ROCm architecture for non-CUDA devices · New Recognize gfx9 architecture strings as wave64 · New Preserve disabled backend tokens before resolving defaults · New Associate assembly dumps with the requested kernel · New Set the quantization device instead of relying on device_map · New Check retained weights after actual forward passes · New Clear the cached validation result after the ROCm test · New Test disabled backend tokens through the setter path · New Remove AWQ GEMV from the AMD support row · New Correct the BF16 regression range in the documentation · New Align documented coverage with the tests · New Remove the unsupported --model benchmark argument · New Align the tuning comment with the published measurements · New Update the stale RDNA4 gate comment · New Update the stale RDNA4 prewarm measurement description · New
And 2 more that still need to be addressed.
What changed in this PR
Adds RDNA4-aware ROCm inference and quantization support alongside gfx950 through shared architecture detection, per-architecture kernel tuning, and explicit backend compatibility decisions.
Changes:
- Introduces architecture-specific GPTQ GEMV, GEMM, and dequantization launch settings.
- Updates ROCm quantization tuning, dtype handling, and backend fallbacks; fixes QQQ/EXL3 dynamic-rule skipping.
- Adds regression tests, hardware-gated oracle cases, benchmark scripts, and support documentation.
This pull request requires changes. Critical findings affect EXL3 forward execution, FP8 inverse-scale correctness, ROCm FP4 routing, and CUDA reductions. Additional dispatch, benchmark, test-isolation, coverage, and documentation issues remain unresolved.
| File | Description |
|---|---|
tests/test_vptq.py |
Updates HIP skip conditions for VPTQ accelerator tests. |
tests/test_rocm_quant_tuning.py |
Tests BLAS, AMP, prewarm, and block-size policies. |
tests/test_rocm_fp8_gating.py |
Tests FP8 failure handling and fallback selection. |
tests/test_rocm_exl3_auto.py |
Tests EXL3 AUTO backend selection. |
tests/test_rocm_backend_gating.py |
Adds backend restriction and QQQ regression cases. |
tests/test_rocm_awq_gemv_gating.py |
Tests native AWQ GEMV restrictions and loader errors. |
tests/test_quant_dtype.py |
Adds ROCm dtype-advertisement coverage. |
tests/test_exllamav3_dynamic_skip.py |
Tests unmatched rules, explicit exclusions, and overrides. |
tests/test_dequant_launch_config.py |
Pins architecture-specific dequantization launch settings. |
tests/test_arch.py |
Tests architecture normalization, lookup, classification, and gates. |
tests/kernels/test_selection.py |
Updates native QQQ ROCm rejection expectations. |
tests/kernels/test_gptq_rocm_gemv.py |
Adds RDNA4 launch and numerical-oracle cases. |
tests/kernels/test_gptq_rocm_gemm.py |
Adds dispatch, dtype-gate, oracle, and storage-check cases. |
scripts/benchmark_rdna4_quant.py |
Adds quantization-stage timing and memory reporting. |
scripts/benchmark_rdna4_inference.py |
Adds fused-versus-split timing and assembly reporting. |
README.md |
Updates AMD support and fused-kernel guidance. |
gptqmodel/utils/rocm.py |
Adds architecture-aware BLAS, AMP, and prewarm tuning. |
gptqmodel/utils/linalg_warmup.py |
Groups prewarm operations for architecture-specific selection. |
gptqmodel/utils/backend.py |
Documents ROCm AWQ packing behavior. |
gptqmodel/utils/arch.py |
Adds cached architecture classification, wave sizes, and dispatch gates. |
gptqmodel/quantization/paroquant/optimization.py |
Routes automatic AMP selection through ROCm tuning. |
gptqmodel/quantization/gsq_cuda_relaxation.py |
Updates reduction masks and wave-aligned launch sizing. |
gptqmodel/quantization/dtype.py |
Separates ROCm dtype advertisement from NVIDIA capability checks. |
gptqmodel/quantization/awq/modules/triton/scheduler.py |
Includes HIP architecture in scheduling identities. |
gptqmodel/nn_modules/triton_utils/gptq_gemv.py |
Adds architecture-specific GEMV launch settings. |
gptqmodel/nn_modules/triton_utils/gptq_gemm.py |
Adds architecture-specific GEMM tiles and gate metadata. |
gptqmodel/nn_modules/triton_utils/dequant.py |
Adds architecture-specific dequantization launches. |
gptqmodel/nn_modules/qlinear/vptq_cuda.py |
Adds explicit native-runtime validation and ROCm rejection. |
gptqmodel/nn_modules/qlinear/torch.py |
Applies shared architecture, shape, and activation-dtype gates. |
gptqmodel/nn_modules/qlinear/qqq.py |
Validates native-runtime availability early and rejects ROCm. |
gptqmodel/nn_modules/qlinear/paroquant_triton.py |
Declares ROCm support and normalizes validation failures. |
gptqmodel/nn_modules/qlinear/gguf_triton.py |
Rejects ROCm execution and bypasses NVIDIA capability probing. |
gptqmodel/nn_modules/qlinear/gemv_fast_awq.py |
Restricts GEMV_FAST and LLM_AWQ to CUDA. |
gptqmodel/nn_modules/qlinear/gemv_awq.py |
Restricts native AWQ GEMV to CUDA with actionable errors. |
gptqmodel/nn_modules/qlinear/fp8.py |
Adds native-dequantization fallback and failure diagnostics. |
gptqmodel/models/loader.py |
Updates EXL3 AUTO selection and rejects native AWQ GEMV layouts on ROCm. |
gptqmodel/models/base.py |
Selects portable QQQ packing on ROCm. |
gptqmodel/models/_const.py |
Bypasses NVIDIA capability checks on ROCm. |
gptqmodel/looper/qqq_processor.py |
Fixes dynamic exclusions and selects the portable ROCm backend. |
gptqmodel/looper/exllamav3_processor.py |
Distinguishes unmatched dynamic rules from explicit exclusions. |
docs/rocm-rdna4.md |
Documents support, measurements, limitations, and verification commands. |
Review effort: Max
Correctness - EXL3 Torch backend: cast the cached Hadamard matrix to the activation dtype so EXL3_TORCH (AUTO on ROCm) actually forwards instead of raising `Half != float`. Add ROCm forward + FP64 oracle tests and CPU dtype tests. - FP8: the cast-failure fallback is now a ROCm-only, sticky probe (NVIDIA OOM/bugs propagate again), and the CPU path passes the reciprocal as an ordinary scale so the inverse-scale semantics are preserved exactly (row/tensor/block). - ROCm no longer advertises NVFP4: torchao's NVFP4 forward has no HIP kernel, so FP4 passthrough checkpoints keep the decode path on gfx9x too. - GSQ: restore the full warp mask on CUDA (`__activemask()` only for HIP), where independent thread scheduling makes an active-mask shuffle undefined. - arch: `_device_index` ignores non-cuda device types; `wave_size` answers gfx9x/gfx1x architecture strings without a device query. - rocm: disabled BLAS opt-out tokens survive `quantize_tuning` so `quant_blas_backend` stays a no-op, with a setter-level test. Tests / tooling / docs - Storage rule: assert no dense weight after first and repeated forwards through the fused GEMV/GEMM and the split fallbacks. - Clear `cached_validate_once` in ROCm-gating teardown; split the tuning test into unknown-token and disabled-token cases; CodeQL import/return cleanups. - Fix the inference dump fallback to match the dispatched kernel, drop the unsupported `--model` from the docs command, restrict the quant benchmark to `--device`, and correct the ASM marker to ASCII English. - Docs: BF16 0.43x-1.42x (median 0.85x), group sizes 128/256, GEMV comment matches the published table, stale gate/prewarm comments, AWQ GEMV removed from the AMD row, `e4m3fnuz` typo.
Apply `compute_device_filter` before staging replicas in ForwardExecutor so excluded GPUs never receive a module copy, and remember each module's quantization device so the final packed weights are built on that GPU instead of the loader's index-less `DEVICE.CUDA` default (which always resolved to cuda:0). Adds resolve_pack_device plus regression tests.
|
All 25 review findings reproduced on real gfx1201 (R9700) and were valid — none were false positives. Fixed in Correctness
Device pinning (new)
Tests
Docs/tooling
Remaining (intentional, documented): Marlin/Machete/Swordfish/BitBLAS/W4A-NVFP4/AWQ GEMV/EXL2/QQQ native/GGUF Triton stay CUDA-only with explicit rejection on ROCm; gfx1200/gfx1250 untested (no hardware); BF16 fused GEMM tiles untuned. Tests: CUDA env 192 passed / 3 skipped; ROCm env GEMV+GEMM 96 passed / 92 skipped. @Qubitium could you take another look? |
|
@ZX-ModelCloud Update readme and documentation that for ROCm we will only support >= rocm 10.1. Add warning to gptqmodel init/loader to detect rocm < 10.1 and emit warning logs that for users to upgrade to latest >= 10.1 version |
Updated. |



Adds RDNA4 (
gfx1200/gfx1201/gfx1250) as a first-class ROCm target alongside the existinggfx950(CDNA4) support.The MI350/
gfx950kernels were audited and kept behaviourally identical — the existing gate values remain a compatibility contract, pinned by tests. RDNA4 reuses the same kernels with per-architecture tuning instead of inheriting CDNA constants.Architecture abstraction (new
gptqmodel/utils/arch.py)normalize_arch/rocm_arch(cached per device) /arch_class/is_rdna4/is_rocm_fused_arch/wave_size/gate_limits/gemm_fused_dtypes.Every previous hard-coded
"gfx950"check now routes through this module. It never usestorch.cuda.get_device_capabilityfor AMD — on ROCm that returns an unrelated numeric pair, which is exactly what the old string checks worked around.Inference kernels
Per-architecture launch tables replace single module-level constants:
cdna4(gfx950, unchanged)rdna4(measured on gfx1201)gptq_gemm(16, 16)/ warps 4, gate(16, 5120)(32, 32)/ warps 4, gate(16, 17408)gptq_gemvblock_n=16/ warps 4dequant(1024, 1, 1)(2048, 4, 1)— 74.5 us vs 81.7 us geomean, output bit-identicaltl.dotlowers tov_wmma_f32_16x16x16_f16on wave32 — verified in the generated.amdgcn, not assumed.Quantization paths
rocm.quantize_tuning(device): per-arch BLAS backend (rocBLAS remains the default on both CDNA and RDNA4 — the hipBLASLt Tensile libraries forgfx120*exist but are untuned), AMP flag, reduced RDNA4 prewarm payload._scaled_mmacceptse4m3fn/e5m2and rejects thefnuzencodings on gfx1201 with one log line and a dequantize+matmul fallback.AUTOresolves toEXL3_TORCHon ROCm (the EXL3 tensor-core GEMM dispatch table isnullptrfor HIP).Correctness fixes found while auditing (not RDNA4-only)
dynamicwasNone:dynamic_getreturnsNonefor "no matching rule" and both call sites tested it for truthiness. EXL3 quantization was a no-op that saved dense weights; QQQ raced the JIT. Both now testis False. QQQ also validates the runtime inside_validate, soAUTOpicksQQQTorchLinearup front instead of failing on the first forward after an ~18 s compile.GEMV/GEMV_FAST/LLM_AWQclaimed ROCm support but their native CUDA extension cannot be built by hipcc (cuda_fp16.h, CUDA-only inline asm, 64-bit warp mask). Now CUDA-only with an actionable error pointing atAWQ_GEMM_TRITON.cp.async/mma.sync/ldmatrix) and is rejected on ROCm up front rather than after a failing build.These are deliberately included: without them the "RDNA4 support" claims would be false for those methods.
Verification
Hardware: AMD Radeon AI PRO R9700,
gfx1201, HIP 7.16.26385, torch 2.16.0.dev20261029+rocm10.1, devices 2–3 (0–1 excluded per a hardware limit).gfx950-only cases skip as designedHonest scope limits
gfx1200/gfx1250have no hardware here. They share thegfx1201family table and are documented as not independently measured.