Skip to content

feat(triton): tuned RTX 4090 (Ada) + RDNA4 kernel paths for every quantization pipeline - #3532

Merged
Qubitium merged 28 commits into
ModelCloud:mainfrom
Qubitium:pr3490
Nov 4, 2026
Merged

Qubitium merged 28 commits into
ModelCloud:mainfrom
Qubitium:pr3490

Conversation

@Qubitium

@Qubitium Qubitium commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator

Summary

Adds measured, hardware-dispatched launch tables for RTX 4090 (Ada, SM 8.9) and RDNA4 (gfx1201, wave32) across every quantization pipeline that ships a tuned Triton path, plus the post-quant inference dispatch and the fallbacks for pipelines that cannot run on one of the two families.

Both families are first-class: a hardware-free CI gate (tests/test_hw_parity_contract.py) fails if any tuned launch table is missing either ada or rdna4.

Pipeline × hardware coverage

Pipeline 4090 (Ada) RDNA4 (gfx1201)
GPTQ GEMV GemvLaunch(max_block_k=256, block_n=8, num_warps=8) GemvLaunch(max_block_k=512, block_n=16, num_warps=4)
GPTQ fused small-M GEMM GemmLaunch(16,16,256,4,2), gate M≤16, K≤2048, N≤2048, FP16+BF16 GemmLaunch(32,32,256,4,2), gate M≤16, K≤17408, FP16 only
GPTQ dequant DequantLaunch(x_block=512, num_warps=1, num_stages=2) DequantLaunch(x_block=2048, num_warps=4, num_stages=1)
ParoQuant GEMM new row-banded (16,64,64,4,4) / (32,64,64,8,4) / (64,64,64,8,4) (4,64,64,4,1) / (32,64,64,4,2) / (64,128,64,4,2)
AWQ GEMM _VERIFIED_4090_FP16_RULES re-verified against the live device new _VERIFIED_RDNA4_PROFILE = ("AMD Radeon AI PRO R9700", "gfx1201", 32, 34_208_743_424) + 8 rules
AWQ portable GEMV new (block_n=32, block_k=512, num_warps=8, num_stages=1) (block_n=64, block_k=512, num_warps=4, num_stages=1)
GGUF Triton SM89 fixed tiles for Q4_K/Q5_K/Q6_K, keyed by qtype/padded-in/out/row-band kernel enabled on ROCm, generic configs; AUTO → GGUF_TRITON

Measured speedups (microbenchmarks on the two hosts)

  • GPTQ GEMV (Ada): 1.09–1.18x hot, 1.10–1.19x flushed on large projections.
  • GPTQ fused GEMM (Ada): 1.09–1.65x hot, in both FP16 and BF16.
  • ParoQuant GEMM: 1.14–3.29x (Ada), 1.31–1.72x (RDNA4).
  • AWQ GEMM (RDNA4): 1.67–10.01x via the new profile rules.
  • AWQ portable GEMV: 1.02–1.40x (Ada); on RDNA4 it wins only at small K (1.38x / 1.05x / 0.97x / 0.81x / 0.94x vs GEMM), so it stays explicit-selection only.
  • GGUF Triton (RDNA4): 5.03–13.09x vs the Torch path; SM89 fixed tiles are 1.02–1.15x and bit-identical to the autotuned config (unmeasured shapes keep autotune).

Oracle validation

Independent Torch/FP64 oracles only — expected values are never produced by the kernel under test.

  • 4090 (probe2.py, real quantization, bits 2/4/8 × FP16/BF16 × M=1/8/64): routing is M1→GEMV, M8→fused GEMM, M64→general; the fused output is bit-identical to portable dequant + matmul in all 18 cases. Max error relative to output max: ≤5.2e-4 (FP16), ≤4.1e-3 (BF16, ≈1 ULP). output.dtype == input.dtype everywhere; no dense weight attribute appears after one or repeated forwards.
  • R9700: M1→GEMV (FP16 and BF16), M8 FP16→fused GEMM, BF16 M8/M64→general (correctly FP16-only). Bit-identical except a single 1-ULP element at 8-bit FP16 M1.

Tests

Backend Result
CUDA (SM 8.9) 399 passed, 157 skipped
ROCm (gfx1201) 313 passed, 211 skipped
Hardware-free parity contract 10 passed on both

New suites: test_gptq_ada_{gemm,gemv,dequant}.py, test_awq_ada_plan.py, test_awq_gemv_ada.py, test_awq_rdna4_plan.py, test_gguf_ada_fixed_launch.py, test_gguf_rocm_triton.py, test_paroquant_ada_launch.py, test_hw_parity_contract.py, plus scripts/benchmark_ada_kernels.py.

Two upstream test-gating bugs were fixed on the way: the ParoQuant native-CUDA parity tests now skip on ROCm (where torch.cuda.is_available() is true but the CUDA kernel cannot build), and the Ada gate test no longer assumes an unregistered host when it runs on RDNA4.

Deliberate exclusions (actionable, not silent fallbacks)

  • QQQ on ROCm → QQQ_TORCH (Marlin-derived inline PTX with its own quant contract; not ported).
  • Marlin / Machete / Swordfish / BitBLAS / W4A-NVFP4 on ROCm → actionable refusal naming the supported alternatives.
  • Native AWQ GEMV / GEMV_FAST / LLM_AWQ on ROCm → superseded by the portable AWQ_GEMV_TRITON.
  • GGUF SM89 fixed tiles never fire on RDNA4 (generic configs instead).
  • bitsandbytes remains CUDA/CPU only.

Notes

  • Includes a merge of upstream/main (v7.9.0); conflicts were limited to qlinear/__init__.py and resolved by keeping upstream's _device_family while retaining the ROCm refusal messages.
  • No persistent dequantized/expanded weight caches are introduced; only packed layouts plus scales/zeros/g_idx persist, and temporary tiles are bounded.

Docs

  • docs/hw-tuning-parity.md — the parity policy both families must satisfy.
  • docs/rocm-rdna4.md — updated support matrix.

fanxi and others added 28 commits November 3, 2026 07:02
Vendors the AllSpark Ampere W8A16 fused GEMM from vLLM #12931 and wires it
into GPTQModel's TorchOpsJitExtension machinery. Kernel sources are copied
verbatim except for the vLLM registration macro, which is replaced by a
TORCH_LIBRARY binding in allspark_torch.cpp.

Verified on an RTX 5090 (sm_120, CUDA 13.0, torch 2.14.1+cu132). Relative
error against a dequantized reference at N=K=4096: 3.5e-4 (M=1), 3.4e-4
(M=16), 1.9e-4 (M=256), 0.0 (M=2048, cublas path).

Two flags are required and are set in utils/allspark.py:
  -U__CUDA_NO_HALF_CONVERSIONS__ and friends, because torch's cpp_extension
  disables the implicit float->half casts this kernel relies on, plus -lcublas.

Not wired into BACKEND yet; AllSparkLinear, backend registration and the
Marlin comparison are still to come.
Adds BACKEND.GPTQ_ALLSPARK, a GPTQQuantLinear subclass and a test that packs a
weight the way an 8-bit checkpoint stores it, repacks it into N32K16 order and
compares the GEMM against the dequantized reference.

Two things surfaced while wiring it up:

- the module has to hoist the extension load into post_init(), otherwise the
  first repack runs before torch.ops is populated.
- an 8-bit group_size=-1 checkpoint stores qzeros=127 while the effective zero
  point is 128, which matches the kernel's symmetric assumption. Verified
  against the original fp16 weights: 0.93% error with 128 versus 3.6% with 127.

Validated on a real 8-bit Qwen2.5-0.5B layer (gate_proj, K=896 N=4864):
relative error 2.7e-4 (M=1), 2.7e-4 (M=16), 2.1e-4 (M=64), 0 (M=256).
Adds the script behind the 4090 numbers on ModelCloud#3490 so anyone can rerun it
on their own card. Reports hot (L2-resident), L2-flushed (device memory),
and CUDA-graph timings for AllSpark vs Marlin at K=4096 N=11008, plus
relative error against the dequantized reference.

The flushed pass uses a random 512 MiB buffer, not a zero-filled one, so
memory compression cannot leave the weights resident and turn the
memory-roof measurement into another cache measurement.
Ports the AllSpark W8A16 kernel to RDNA4 wave32 WMMA:

  * cp.async / ldmatrix / mma.sync -> global->register->LDS staging, plain
    16B LDS reads in the repack's own fragment order, and
    v_wmma_f32_16x16x16_{f16,bf16}_w32_gfx12
  * prmt.b32 -> v_perm_b32 (AMD selector semantics re-derived on hardware)
  * __CUDA_ARCH__ guards -> __HIP_DEVICE_COMPILE__ + __gfx1200__/__gfx1201__,
    with a compile-time #error and a runtime sentinel so a silently empty
    kernel cannot ship
  * bf16 dequant: replace __float2bfloat16 (a NaN compare + select per value,
    ~200 extra ALU instructions per kernel body) with integer RNE plus one
    v_perm_b32. gfx1200/1201 have no v_cvt_pk_bf16_* instruction. bf16 was
    27% slower than fp16 in the L2-resident case; it is now at parity.

gptq_allspark now selects on ROCm (DEVICE.ROCM) and dispatches to the HIP
repack/GEMM; CUDA keeps the existing path unchanged. allspark_supported()
returns False under HIP because ROCm reports gfx1201 as compute capability
12.0, which would otherwise fall inside the Ampere..Blackwell window.

Numbers (R9700, gfx1201, 32 CU, K=4096 N=11008, weight bytes only):

  fp16 M=8  hot 0.065 ms (691 GB/s)  flushed 0.100 ms (450)  graph 0.063 ms (712)
  bf16 M=8  hot 0.067 ms (673 GB/s)  flushed 0.101 ms (448)  graph 0.065 ms (689)
  device read baseline: 602-606 GB/s

scripts/benchmark_allspark_hip_w8a16.py reproduces the table (hot/flushed/
graph, random flush buffer, optional Triton comparison).
Adds an AWQ 8-bit path to the AllSpark HIP/RDNA4 W8A16 kernel. AWQ differs
from GPTQ 8-bit by packing along N instead of K and by carrying an arbitrary
per-group zero point on the K axis, so this required both a new repack and a
grouped scale/zero read in the kernel.

Kernel (gptqmodel_ext/allspark_hip):
* GroupCnt/GroupSize are real now: scale/zero are read from a (GroupCnt, N32)
  block, with the row selected per k-tile inside the k-loop. GPTQ stays on the
  single per-channel row, so its code path is unchanged.
* bf16 takes the zero point before the scale, in fp32. The old ordering did
  (code - 128) * scale - zero, which is wrong for AWQ (zero point is a code,
  not a bias-128 offset). fp16 subtracts the residual (zero - 128) after its
  existing bias-128 conversion.
* Group selection is incremental instead of `k / (GroupSize / kKTile)`: RDNA
  has no integer divide instruction, and the per-k-tile divide cost ~12 us on
  gfx1201 at group_size 32.
* unpack_kernel and the grouped scale padding handle groups; the M > 16
  prefill fallback therefore works with zero points too.

Bindings:
* Add a c10::cuda::CUDAGuard to every entry point. Custom ops get no
  dispatcher device guard, so on a multi-GPU split the launcher ran on the
  current device with another device's pointers and produced NaN. This was
  reproduced on 4x gfx1201 and is covered by a test.

Python:
* AllSparkAwqLinear (backend `awq_allspark`), RDNA4 only, group sizes
  -1/16/32/64/128, fp16 and bf16. It packs through the shared AWQ packer so
  checkpoints stay byte-compatible, repacks into the WMMA fragment order once
  in post_init, and never keeps a dense weight.
* allspark_hip_repack_awq() and optional b_qzeros/group_size plumbing;
  allspark_hip_repack() now returns (packed, scales, zeros_or_None).

Validation (gfx1201): 72 passed. AWQ matches an fp64 oracle within one output
ULP for both dtypes across all group sizes, at M=1/4/16, and with a
non-128-aligned N. Module-level pack -> post_init -> forward reproduces the
dense weight to 8-bit noise, and a full Llama-3.2-1B AWQ-8bit model is closer
to the fp32 gold logits than the torch AWQ backend (1.86e-2 vs 2.10e-2).
CUDA is untouched: the AWQ tests skip there and AllSparkLinear still passes.
# Conflicts:
#	gptqmodel/utils/backend.py
Follows ModelCloud#3491 (marlin/machete/swordfish unification) for AllSpark.

Backend
* `BACKEND.GPTQ_ALLSPARK` and `BACKEND.AWQ_ALLSPARK` collapse into a single
  `BACKEND.ALLSPARK`. The checkpoint method/format picks `AllSparkLinear`
  (GPTQ) or `AllSparkAwqLinear` (AWQ); both declare `SUPPORTS_BACKENDS =
  [BACKEND.ALLSPARK]`. Old strings stay loadable via `_LEGACY_BACKEND_ALIASES`.

AWQ
* `group_size=-1` only. With one group over all of K the scale/zero are (1, N)
  and the kernel loads them once outside the k-loop. Grouped zeros forced a
  per-16-wide-k-tile reload: 2-6% slower at group_size=128 (~18% at 32) on
  gfx1201 with no accuracy benefit for the decode shapes this targets.
* `SUPPORTS_GROUP_SIZE = [-1]`; `pack()` and `allspark_hip_repack_awq()` reject
  any other grouping with a clear error instead of silently mis-scaling.

Kernel
* Drop `GroupCnt`/`GroupSize` from the params struct, the grouped scale/zero
  bookkeeping and `pad_scale_grouped_kernel`. Removes the group branch and
  counter from the k-loop; GPTQ 8-bit codegen is unchanged.

Verified on gfx1201 (4x R9700, torch 2.16 ROCm, hip 7.16): 40 passed for the
HIP + AWQ suites, 46 passed / 4 skipped including the linear and JIT tests.
CUDA (2x 4090): 10 passed, AWQ tests skip as intended.
ModelCloud#3491 collapsed the marlin backends into BACKEND.MARLIN, so
scripts/benchmark_allspark_w8a16.py raised AttributeError before it timed
anything. Legacy 'gptq_marlin' strings still normalize, the enum does not.
…nore rules

The CUDA extension already had the whole zero-point path: `has_zp`,
`B_zero`, and the repack already reordered it. Only the Python wrappers
passed `None`, so CUDA AWQ could not be exercised at all.

Wire it up:

* `allspark_repack()` now takes an optional per-N zero buffer and returns a
  3-tuple; `allspark_repack_awq()` unpacks the AWQ on-disk layout and feeds
  it. `allspark_gemm()` forwards `b_qzeros` and sets `has_zp`.
* `AllSparkAwqLinear` now declares `SUPPORTS_DEVICES = [CUDA, ROCM]` and
  picks the extension by runtime instead of hardcoding HIP.

The one device-specific detail is where the zero is applied: HIP subtracts
it inside the fp32 dequant `(code - zero) * scale`, while CUDA subtracts it
after its bias-128 conversion `((code - 128) - zero) * scale`. The CUDA
repack therefore stores `zero_awq - 128`. Getting this backwards is silent
(it just shifts every weight), so `test_awq_zero_point_convention_is_load_bearing`
uses a raw-zero negative control: correct 2.6e-4..2.6e-3 relative, raw
6.7e-1..7.3e-1.

Also add an AWQ mode to `scripts/benchmark_allspark_w8a16.py` so the CUDA
and ROCm AWQ numbers come from the same script as the GPTQ ones.

`.gitignore` gets a warning block: the hipify patterns silently drop a new
hand-written `*_hip.*` file, so each one needs its own negation.

Verified: 4090 CUDA 10/10 AWQ tests, 20/20 with the JIT+linear suites;
RDNA4 ROCm 46 passed / 4 skipped.
…ract

Add cuda_capability/cuda_arch/is_ada/tuning_family to gptqmodel.utils.arch so
every launch-constant table can key on one vocabulary (ada, hopper, blackwell,
cdna4, rdna4, rdna3, other) instead of ad-hoc capability checks. Add a
hardware-free contract test that fails when a tuned pipeline has no entry for
both RTX 4090 (ada) and RDNA4 (rdna4).
tuning_family() returned arch_class() for every input whenever torch.version.hip
was set, so a CUDA capability tuple or an sm_89 string was reported as "other"
on a ROCm host. The NVIDIA branch was unreachable there. That made
test_cuda_family_classification fail on gfx1201 and would have silently dropped
any launch-table lookup that was handed explicit CUDA metadata.

Only a gfx* string or a real device is resolved through arch_class(); an
explicit sm_* string or (major, minor) tuple is portable metadata and classifies
identically on CUDA and ROCm hosts. The sm_ parser is factored into
_tuning_family_from_sm() and shared by both branches.
The fused ParoQuant GEMM hardcoded decode (4,128,32,warps=4,stages=2) and
prefill (32,128,32,warps=8,stages=4) for every GPU. On wave32 gfx1201 the
prefill num_warps=8 tile is especially wrong: four warps already cover 128
lanes, and eight measured 1.65x slower at K=4096/N=4096/M=16 (137.6 vs 83.2us).

paroquant_gemm_launch_config(kind, device_or_arch, rows) now keys on
gptqmodel.utils.arch.tuning_family. Families without a measured entry keep the
historical pair, so Ada/Hopper/Blackwell and every unregistered target are
unchanged. rdna4 uses three measured bands (<=8 rows, 9..64, >64) selected from
the flattened row count; the wrappers pass input.shape[0].

Also fixes a latent correctness bug the wider BLOCK_K tiles exposed: the kernel
loads one scale/zero group per K tile and broadcasts it across the tile, so a
tile must never span more than one group. BLOCK_K is now clamped to group_size.
Before the clamp, BLOCK_K=64 with group_size 32 produced 0.6-1.0 relative error.

Measured on AMD Radeon AI PRO R9700 (gfx1201), FP16, 4-bit, group_size 128,
median of 21 iterations after 5 warm-ups, 256 MiB L2 flush before each timed
call, torch.cuda.synchronize around every call:

  M=1    K=14336 N=4096   181.30 vs 269.13 us  (1.48x)
  M=4    K=4096  N=4096    77.72 vs 102.18 us  (1.31x)
  M=16   K=14336 N=4096   206.87 vs 288.76 us  (1.40x)
  M=64   K=14336 N=4096   222.37 vs 325.10 us  (1.46x)
  M=128  K=5120  N=8192   186.06 vs 296.69 us  (1.59x)
  M=1024 K=14336 N=4096  1680.99 vs 2893.65 us (1.72x)

New-tile output is bit-identical to the old tile for group_size 32/64/128 and
both FP16 and BF16 inputs. Against an independent FP64 Torch oracle: FP16
max relative error 5.0e-4 over K/N 512..4096 and M 1..128; BF16 stays at its
pre-existing output-rounding floor (<=1.25 ULP versus the truth rounded once to
BF16), which is the documented 5e-3 test tolerance, not kernel arithmetic.
AWQ FORMAT.GEMV/GEMV_FAST/LLM_AWQ could only run through the native
gptqmodel_ext/awq JIT extension, which hipcc cannot build (cuda_fp16.h, CUDA
inline asm, 64-bit-only warp sync mask on wave32), so a GEMV-layout checkpoint
raised NotImplementedError on ROCm.

gptqmodel/quantization/awq/modules/triton/gemv.py now implements the same
computation with plain Triton. It reads the GEMV packing directly:

  qweight [N, K/8] int32, nibble i of word w = input column w*8+i (plain order,
    NOT the FORMAT.GEMM [K, N/8] AWQ interleave)
  qzeros  [N, ceil(groups/8)] int32 with the group axis padded to a word
  scales  [N, padded_groups] FP16

BLOCK_K is clamped to group_size because the kernel broadcasts one scale/zero
group across each K tile. Accumulation is FP32 and the output dtype is the
input dtype. Weights stay packed; nothing dense is materialized.

AwqGEMVTritonLinear (BACKEND.AWQ_GEMV_TRITON) reuses AwqGEMVLinear.pack, so the
packed buffers are byte-identical to the native layout, and declares
DEVICE.ROCM. SUPPORTS_FORMATS priority is 0, which is the documented
'supported but never AUTO-selected' marker: the AUTO order for FORMAT.GEMV is
unchanged (CUDA keeps the native kernel, ROCm keeps the actionable refusal), and
an explicit selection is now the supported ROCm placement. The loader rejection
takes a backend argument and exempts only that explicit choice.

Measured on AMD Radeon AI PRO R9700 (gfx1201), FP16, M==1, median of 21
iterations after 5 warm-ups, 256 MiB L2 flush before each timed call:
  K=2048  N=2048   48.3us vs 679.8us split (14.1x)
  K=4096  N=4096   93.2us vs 3164.1us       (33.9x)
  K=5120  N=8192  152.6us vs 7730.3us       (50.7x)
  K=14336 N=4096  229.3us vs 10771.2us      (47.0x)
  K=4096  N=11008 164.5us vs 8284.2us       (50.4x)
'split' is dequantize+matmul from the same packed buffers (cost floor). Against
the shipped FORMAT.GEMM Triton GEMM at M==1 this kernel is 1.7x-2.4x faster.

Oracle A/B (independent FP64 unpack, never the kernel's own math): FP16 max
relative error 4.5e-4; BF16 is at its <=1.25 ULP output-rounding floor.
Packed qweight/qzeros stay int32 and identical across repeated forwards.
GGUFTritonKernel now declares DEVICE.ROCM and validate_once no longer
hard-rejects ROCm; _cuda_device_capability already returned None there, so
ROCm keeps the generic launch configs and never selects the NVIDIA SM80/SM89
specializations.

Measured on gfx1201 (R9700, FP16, median of 21 iters after 5 warm-ups with a
256 MiB L2 flush): 5.0-13.1x faster than GGUFTorchLinear at M=1/16/128 for
Q4_K/Q5_K/Q6_K, so AUTO (priority 45 > 15) now resolves to the Triton kernel
on ROCm.

tests/kernels/test_gguf_rocm_triton.py validates the kernels against the
independent numpy GGUF block oracle (output dtype == input dtype, repeated
forwards bit-identical, 1.25-ULP visible drift budget) and covers the
generic-config selection on a ROCm host.
Marlin, Machete, Swordfish, BitBLAS and W4A-NVFP4 stay unsupported on ROCm;
this only makes the selection surface say so before it wastes time probing a
CUDA extension:

* Swordfish/Machete/BitBLAS validate_once() now reject a HIP host first
  (they previously reported 'runtime unavailable' or a bitblas install hint).
* BaseQuantLinear._validate_shared() keeps the reason raised by
  validate_device() and, for a CUDA-only kernel on a HIP target, names the
  portable *Torch/*Triton alternative instead of a bare 'unsupported device'.

AUTO is unchanged and still cannot reach them: the candidate list is filtered
by SUPPORTS_DEVICES (none lists DEVICE.ROCM) before any validation runs. Tests
assert both halves.
Add an explicit "ada" entry to every shared Triton launch table and route
CUDA devices through gptqmodel.utils.arch.tuning_family so an SM 8.9 GPU
actually reaches it.

- gptq_gemv: GemvLaunch(max_block_k=256, block_n=8, num_warps=8). Measured on
  one 4090 vs the 512 default: 1.09x-1.18x hot and 1.10x-1.19x flushed on the
  large projections (4096x4096 through 5120x12288); neutral below that.
- gptq_gemm: GemmLaunch(16,16,256,4,2) with a new trailing max_out_features
  field (default 0 keeps cdna4/rdna4 tuples byte-for-byte unchanged).
  Gate (small_m_max=16, max_in_features=2048, max_out_features=2048).
  Measured 1.09x-1.65x hot for K<=2048 & N<=1536 and 1.10x-1.41x flushed
  across K<=2048 & N<=2048 in FP16 and BF16; the 2048x2048 corner is hot
  neutral but flushed-positive. Losses outside the rectangle are gated off.
- dequant: DequantLaunch(x_block=512, num_warps=1, num_stages=2); best mean
  against the per-shape best (hot 1.007x, flushed 1.017x).
- qlinear/torch: the fused small-M GEMM now accepts (IS_ROCM or is_ada), and
  the arch token uses cuda_arch() instead of the ROCm-only gcnArchName.
- arch: gemm_fused_dtypes/gate_limits dispatch through tuning_family (same
  values for cdna4/rdna4) and expose gemm_fused_max_out_features().
- awq scheduler: the 4090 profile guard was re-verified exact on this host
  (2x RTX 4090: name, (8,9), 128 SMs, 50_950_569_984 bytes); no constant
  changed. BF16 rules are deliberately absent because awq_gemm_triton
  rejects non-FP16 input/scales.
- gguf_triton: SM89 fixed tiles for Q4_K/Q5_K/Q6_K, keyed by qtype, padded
  in_features, out_features and row band. Only exact measured shapes are
  wired (1.02x-1.15x, bit-identical to the autotuned launch); Q1_0 SM80/SM89
  and every unmeasured shape keep the autotuned generic kernel.

No persistent dequantized weight cache is introduced; every fused path still
consumes the packed weights and bounded tiles only.
Independent oracles only: every expected value is rebuilt with Torch integer
shifts and an FP64 accumulate/round; the kernels under test are never used to
produce their own reference.

New tests:
- test_gptq_ada_gemv.py / test_gptq_ada_gemm.py: launch-table dispatch (runs
  with CUDA_VISIBLE_DEVICES=-1), gate/dtype assertions, and real-GPU oracle
  A/B across bits 2/4/8, FP16 and BF16, desc_act and bias variants, in and out
  of the fused gate. The GEMM file also pins that "ada" enables only the
  measured FP16/BF16 dtypes and that no dense weight is retained after one or
  repeated forwards.
- test_gptq_ada_dequant.py: bits 2/4/8 in FP16/BF16 over four shapes against a
  CPU int-shift oracle, plus the module-level dequantize_weight path and a
  repeated-call storage check.
- test_gguf_ada_fixed_launch.py: SM89 selector grid (measured shapes and row
  bands only; SM80/86/90/100, unpadded widths and unmeasured rows fall through)
  and a real-GPU bit-exact A/B of the fixed tile vs the autotuned launch.
- test_awq_ada_plan.py: the 4090 four-field identity guard, FP16-only rules,
  exact-shape matching, and a real-device profile check.

Updated: the ROCm GEMV/GEMM and dequant table tests now pin sm_89 to its Ada
entry (the (8,9) tuple and the None default are covered too), and
test_hw_parity_contract keeps the both-families assertion plus a GGUF
Ada-only/autotuned-fallthrough check.

scripts/benchmark_ada_kernels.py reproduces every shipped number: device proof
(count/name/capability/SM/memory), GEMV vs the portable tile, small-M GEMM vs
dequantize+matmul, dequant vs default, and GGUF fixed vs autotuned. Median
after warmup, torch.cuda.synchronize around every launch, alternating 256 MiB
L2 flush, hot and flushed medians reported separately. GEMV/GEMM rows report
max abs/rel against an FP64 oracle (plus the once-rounded oracle) rather than
against the sibling kernel, and each row records retained-weight bytes and any
dense-weight candidate. --dry-run exits 0 without a GPU.
…k claim

docs/rocm-rdna4.md now records the closed RDNA4 gaps: AWQ FORMAT.GEMV via
BACKEND.AWQ_GEMV_TRITON, GGUF_TRITON on ROCm (AUTO, measured), the ParoQuant
per-family launch table, the actionable refusals for Marlin/Machete/Swordfish/
BitBLAS/W4A-NVFP4, and why QQQ has no Triton port (CUDA inline PTX plus a
distinct W4A8 packing/quant contract).

The AWQ GEMV row and section were also wrong: the 1.7-2.4x "faster than
FORMAT.GEMM at M==1" figure compared a raw kernel launch against a derived
baseline. Re-measured module-against-module on gfx1201 (M==1, FP16, gs=128,
median of 41 iterations after 20 warm-ups, 256 MiB L2 flush, CUDA events) the
two shipped kernels are at parity:

  K      N      GEMV us  GEMM us  vs GEMM  vs split
  2048   2048    68.0     93.5     1.38x    6.6x
  4096   4096   111.8    117.1     1.05x   19.1x
  5120   8192   170.2    165.1     0.97x   30.7x
  14336  4096   248.4    200.5     0.81x   29.3x
  4096  11008   186.0    175.6     0.94x   30.1x

So AWQ_GEMV_TRITON is documented as a ROCm portability/correctness path (the
6.6-30.7x win is over the dequantize+matmul floor it replaces), not a decode
speedup over FORMAT.GEMM. The module docstring carries the same corrected table.

tests/kernels/test_awq_rocm_triton.py gains an M==1 parity test: it transcodes
the GEMV packed buffers into the FORMAT.GEMM layout independently (nibble
interleave applied by hand, never by calling a kernel) and asserts both modules
produce the same output within one FP16 ULP band, so the "parity" wording is
pinned numerically even though timings cannot be asserted on a shared GPU.
…eduler

The AWQ Triton plan table only covered the RTX 4090, and _builtin_plan returned
None whenever identity[6] was set -- which is always true on ROCm -- so every
RDNA4 shape fell through to the generic 32/32/32 split_k=8 tile, a wave64/CDNA
shape that pays a split-K atomic-reduction pass on wave32.

A HIP host reports a seven-field device_identity: the six CUDA fields plus the
normalized gcnArchName appended last, with capability None. On the reference
R9700 the tuple is

  ('cuda', 0, 'AMD Radeon AI PRO R9700', None, 32, 34208743424, 'gfx1201')

_VERIFIED_RDNA4_PROFILE matches (name, gfx arch, compute units, total_memory)
from indices 2/6/4/5 exactly, so a different gfx arch, board name, CU count or
memory size cannot inherit the tiles. The CUDA 4090 branch is byte-for-byte
unchanged and is reached only by six-field CUDA identities, so neither profile
can match the other's device.

Measured on gfx1201, 4-bit AWQ FORMAT.GEMM, group_size 128, FP16, mode=auto,
median of 41 iterations after 20 warm-ups, 256 MiB L2 flush before every timed
call and CUDA events around each launch; "generic" is the legacy_plan tile the
device used before this table:

  (M, N, K, G)            tile (BM, BN, BK, split, warps, stages)  us      generic  speedup
  (32, 8192, 2048, 128)   (32, 64, 64, 1, 4, 2)                    89.3    348.8    3.90x
  (64, 8192, 2048, 128)   (64, 64, 64, 1, 4, 2)                   107.9    654.7    6.07x
  (64, 4096, 4096, 128)   (32, 64, 64, 1, 4, 4)                   105.9    366.8    3.46x
  (64, 2048, 8192, 128)   (16, 64, 64, 1, 4, 2)                   141.1    235.2    1.67x
  (127, 8192, 2048, 128)  (64, 128, 64, 1, 4, 2)                  121.9   1220.7   10.01x
  (128, 2048, 2048, 128)  (32, 64, 64, 1, 4, 4)                    78.0    339.6    4.35x
  (128, 8192, 2048, 128)  (64, 128, 64, 1, 4, 2)                  123.4   1228.7    9.96x
  (128, 4096, 4096, 128)  (64, 128, 64, 1, 4, 4)                  139.8    679.6    4.86x

Every swept shape won, so none is left to the generic policy; split_k=1 won
everywhere and num_warps=4 is 128 lanes on wave32. The table is FP16-only
because awq_gemm_triton rejects non-FP16 input and scales, and _builtin_plan
enforces the dtype triple.

Independent FP64 Torch oracle (unpacks qweight/qzeros itself, never the
kernel): max relative error 3.8e-04..4.6e-04 over the eight shapes, output
dtype preserved, repeated forwards bit-identical, no dense dequantized cache
(even through the real AwqGEMMTritonLinear forward).

tests/kernels/test_awq_rdna4_plan.py passes with no GPU (23 passed, 2 skipped):
the exact profile matches, wrong arch/name/CU/memory does not, non-FP16
returns None, unmeasured shapes fall through, the CUDA 4090 profile still
matches only a CUDA-shaped identity, and cross-shaped lookalikes match neither.
The ParoQuant fused GEMM table only had an rdna4 entry, so every other
family fell through to the historical (4,128,32,4,2)/(32,128,32,8,4)
tile.  Sweep the documented 252-tile grid on a 4090 (4-bit, gs=128,
FP16, 256 MiB L2 flush + torch.cuda.synchronize, median of 41 after 15
warm-ups) over (K,N) in {(2048,2048),(4096,4096),(5120,8192),
(14336,4096),(4096,11008)}.

Measured per-band winners, recorded explicitly as an "ada" row-banded
entry (decode <=8 rows, prefill 9..64, prefill_large >64):
  decode        (16, 64, 64, warps=4, stages=4)
  prefill       (32, 64, 64, warps=8, stages=4)
  prefill_large (64, 64, 64, warps=8, stages=4)

1.16x-3.37x faster than the historical fallback across the swept
matrix.  FP64-oracle max rel error 4.3e-4 (worst shape 14336x4096@1024),
dtype preserved.  rdna4, the default tile and _RDNA4_MEDIUM_MAX_ROWS
semantics are untouched; non-Ada families still get the default.
The portable AWQ GEMV table only had an rdna4 entry and launch_config()
mapped every non-gfx string to the portable default, so CUDA never
reached it.  Route the table through tuning_family() (the shared
vocabulary every other tuned Triton table uses) and add an "ada" entry.

Swept block_n {32,64,128} x max_block_k {256,512,1024} x num_warps
{2,4,8} x num_stages {1,2,3} on a 4090 for the FORMAT.GEMV packing
(group_size 128 clamps block_k, so max_block_k is a no-op at that
group), K,N in {(2048,2048),(4096,4096),(5120,8192),(14336,4096),
(4096,11008),(896,128)}, M==1, FP16, 256 MiB L2 flush +
torch.cuda.synchronize, median of 41 after 15 warm-ups.

Chosen Ada tile: block_n=32, max_block_k=512, num_warps=8, num_stages=1.
1.01x-1.40x faster than the portable default hot and 1.01x-1.16x
L2-flushed, never slower on any swept shape.  block_n=128 always lost.
FP64-oracle max rel error 3.4e-4.  rdna4 and _DEFAULT_AWQ_GEMV_LAUNCH
are untouched; unregistered families keep the portable default.
A longer interleaved A/B (120 hot/flushed iterations after 20 warm-ups)
shows the 896x128 case is a launch-bound ~2% loss, not a tie.  Record the
per-shape numbers honestly, state 1.02x-1.40x hot / 1.00x-1.14x flushed
on the five real projections, and pin the documented exception with a
test so it cannot be silently relaxed.
Add --sections paroquant,awq_gemv to scripts/benchmark_ada_kernels.py.
Both drive the shipped tuned tile against the previous fallback through
the same protocol (median after --warmup, torch.cuda.synchronize, 256 MiB
L2 flush) and report an independent FP64 oracle error plus dtype
preservation, so a future retune has a reproducible harness.

Also correct the ParoQuant table comment to the measured 1.14x-3.29x hot
range (it said 1.56x-3.40x from the tuning sweep's own reference).
The hardware-parity contract only covered the three shared GPTQ Triton
tables plus dedicated ParoQuant/GGUF assertions, so the AWQ paths that now
ship measured tiles could regress to a single-family table unnoticed.

- Add paroquant_gemm and awq_gemv to TUNED_PIPELINES. Both now carry an
  "ada" and an "rdna4" entry, so the existing per-family assertion covers
  them with no new logic.
- Pin the AWQ GEMM scheduler's exact device profiles. It keys rules on a
  device identity rather than a family token, so add a test that builds a
  six-field CUDA identity and a seven-field HIP identity from the shipped
  constants, asserts each resolves to its own measured rule, and asserts
  that a wrong gfx arch, board name, CU count, memory size, or non-FP16
  dtype returns None.

Hardware-free: 10 passed on both the CUDA and ROCm interpreters.
# Conflicts:
#	gptqmodel/nn_modules/qlinear/__init__.py
@Qubitium
Qubitium merged commit 4127615 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.

2 participants