Skip to content

feat(rocm): RDNA4 (gfx1200/gfx1201/gfx1250) kernel and quantization support - #3478

Merged
Qubitium merged 5 commits into
mainfrom
rdna4/kernels-and-quant
Nov 2, 2026
Merged

Qubitium merged 5 commits into
mainfrom
rdna4/kernels-and-quant

Conversation

@ZX-ModelCloud

@ZX-ModelCloud ZX-ModelCloud commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator

Adds RDNA4 (gfx1200 / gfx1201 / gfx1250) as a first-class ROCm target alongside the existing gfx950 (CDNA4) support.

The MI350/gfx950 kernels 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 uses torch.cuda.get_device_capability for 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:

Kernel cdna4 (gfx950, unchanged) rdna4 (measured on gfx1201)
gptq_gemm (16, 16) / warps 4, gate (16, 5120) (32, 32) / warps 4, gate (16, 17408)
gptq_gemv unchanged block_n=16 / warps 4
dequant (1024, 1, 1) (2048, 4, 1) — 74.5 us vs 81.7 us geomean, output bit-identical
  • 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 there. GEMV stays enabled for both dtypes.
  • tl.dot lowers to v_wmma_f32_16x16x16_f16 on wave32 — verified in the generated .amdgcn, not assumed.
  • RDNA4 is wave32 vs CDNA's wave64, so the launch shape is re-measured rather than inherited.

Quantization paths

  • rocm.quantize_tuning(device): per-arch BLAS backend (rocBLAS remains the default on both CDNA and RDNA4 — the hipBLASLt Tensile libraries for gfx120* exist but are untuned), AMP flag, 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 one 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 per-backend ROCm decision instead of inheriting a CUDA default.

Correctness fixes found while auditing (not RDNA4-only)

  • QQQ and EXL3 silently skipped every module when dynamic was None: dynamic_get returns None for "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 test is False. QQQ also validates the runtime inside _validate, so AUTO picks QQQTorchLinear up front instead of failing on the first forward after an ~18 s compile.
  • AWQ GEMV / GEMV_FAST / LLM_AWQ claimed 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 at AWQ_GEMM_TRITON.
  • QQQ's native W4A8 kernel is CUDA-only inline PTX (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).

Check Result
GPTQ fused GEMV / GEMM vs independent Torch oracle pass (FP16 + BF16 where enabled); 92 gfx950-only cases skip as designed
AWQ Triton GEMM vs independent Torch oracle pass
Full suite for touched areas 376 passed, 181 skipped
End-to-end 4-bit Qwen3-0.6B quantization 588 int32 packed tensors, no dense weight retained

Honest scope limits

  • gfx1200 / gfx1250 have no hardware here. They share the gfx1201 family table and are documented as not independently measured.
  • Methods with no RDNA4 native kernel: Marlin, Machete, Swordfish, BitBLAS, W4A-NVFP4, AWQ GEMV family, EXL2, QQQ native, GGUF Triton. These are CUDA-only (largely inline PTX that hipify cannot translate). This PR does not give them RDNA4 paths — it makes them fail honestly instead of claiming support. Porting them is a separate, much larger effort.
  • No RDNA4-specific AWQ tile was tuned (not measured, so no constants invented).
  • ParoQuant AMP stays off on RDNA4; not separately measured there.

…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.
Comment thread tests/test_rocm_quant_tuning.py Fixed
Comment thread tests/test_quant_dtype.py Fixed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

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

Comment thread gptqmodel/models/loader.py Resolved
Comment thread gptqmodel/nn_modules/qlinear/fp8.py Resolved
Comment thread gptqmodel/quantization/dtype.py Resolved
Comment thread gptqmodel/nn_modules/qlinear/fp8.py Resolved
Comment thread gptqmodel/utils/arch.py Resolved
Comment thread gptqmodel/utils/linalg_warmup.py Resolved
Comment thread scripts/benchmark_rdna4_inference.py Resolved
Comment thread tests/test_quant_dtype.py Resolved
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.
Comment thread tests/test_rocm_quant_tuning.py Fixed
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.

ZX-ModelCloud commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator Author

All 25 review findings reproduced on real gfx1201 (R9700) and were valid — none were false positives. Fixed in 15b253470 and f7506adbc:

Correctness

  • EXL3: fixed Hadamard dtype promotion (c10::Half != float), added FP64 oracle.
  • FP8: sticky ROCm-only probe, correct CPU reciprocal semantics, no FP4 advertised on ROCm.
  • GSQ: CUDA full-mask sync, HIP __activemask() only on HIP.
  • Arch: non-CUDA arch returns None; wave size decided per gfx9x/gfx1x string.
  • BLAS: disabled tokens are preserved, rocblas no longer forced.

Device pinning (new)

  • compute_device_filter now applies before replica staging, so excluded GPUs no longer get a module copy.
  • Packing now uses each module's quantization GPU instead of the loader's index-less DEVICE.CUDA (which always hit cuda:0). Verified: excluded GPU peak 0 MiB, pack_gpu on cuda:1 for all 168 modules.

Tests

  • Real-forward assertion for quantized storage, kernel-name-matched dump scan, benchmark device restriction.
  • Regression tests for pack device resolution, disabled BLAS tokens, CodeQL mixed-return.

Docs/tooling

  • Corrected BF16 speedups (0.43–1.42x, median 0.85x), group sizes 128/256, AWQ GEMV row, e4m3fnuz, GEMM counts, ASCII-only text, and TRITON_KERNEL_DUMP/TRITON_DUMP_DIR instead of AMDGCN_ENABLE_DUMP.

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. tests/test_selection.py 3 failures also fail on base bbe3ae8d2 (pre-existing).

@Qubitium could you take another look?

@Qubitium
Qubitium marked this pull request as ready for review November 2, 2026 06:16
@Qubitium

Qubitium commented Nov 2, 2026

Copy link
Copy Markdown
Collaborator

@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

@ZX-ModelCloud

Copy link
Copy Markdown
Collaborator Author

@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.

Comment thread gptqmodel/utils/rocm.py Dismissed
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.

3 participants