Skip to content

[Kernel] AllSpark W8A16: CUDA (5090/4090) + ROCm (RDNA4) - #3490

Merged
Qubitium merged 10 commits into
ModelCloud:mainfrom
Lumea-art:feat/allspark-kernel
Nov 3, 2026
Merged

Qubitium merged 10 commits into
ModelCloud:mainfrom
Lumea-art:feat/allspark-kernel

Conversation

@Lumea-art

@Lumea-art Lumea-art commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Adds the AllSpark W8A16 backend for GPTQ and AWQ checkpoints. GPTQModel.load(..., backend=BACKEND.ALLSPARK) selects the quantization format and CUDA/RDNA4 implementation automatically.

  • 8-bit, per-channel (group_size=-1), fp16 and bf16. GPTQ requires symmetric quantization and desc_act=False; AWQ supports affine zero points.
  • CUDA capability 8.0–12.0; ROCm gfx1200/gfx1201. Explicit backend selection; AUTO priorities are unchanged.
  • CUDA fused GEMM through M=1024, then temporary dequantization + cuBLAS. RDNA4 WMMA through M=16, then temporary dequantization + Torch matmul. No retained dense-weight cache.
  • AWQ supports packing and loading; GPTQ is a load/repack target. JIT sources ship in wheels and source distributions.

Final review fixes in f25fcfa8c: per-call CUDA scratch, FP32 split-K partials/reduction, CUDA/HIP input/device guards, HIP sentinel bounds, AWQ dtype moves, and package-source inclusion.

Validation Result
RTX 4090, all five AllSpark test files 43 passed, 176 hardware-specific skips
RDNA4 gfx1201, same files 183 passed, 36 hardware-specific skips
Backend naming/gating + AllSpark selection 34 passed, 1 skipped
Ruff / diff checks Passed
Wheel + sdist / installed-wheel source discovery Passed
Real Qwen2.5-0.5B, both devices and dtypes 168 AllSpark layers; coherent generation

The local AWQ end-to-end checkpoint is a lossless layout conversion of the real GPTQ checkpoint, not a fresh AWQ calibration. The contributor separately validated a real AWQ checkpoint and perplexity on the 5090 at e22efa869; that device has not been rerun after the final CUDA fixes.

Reproduce timing with random weights and a random eviction buffer:

PYTHONPATH=. python scripts/benchmark_allspark_w8a16.py --awq --m 1 8 16
PYTHONPATH=. python scripts/benchmark_allspark_w8a16.py --awq --dtype bfloat16 --m 1 8 16

Current fp16/bf16 timing tables. The 4090 uses GDDR6X; hot timings measure cache residency, and flushed timings include the event-based launch path.

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

Copy link
Copy Markdown
Contributor Author

Second commit adds AllSparkLinear and exercises the packing path.

tests/test_allspark_linear.py   3 passed   (M=1/16/64)
tests/test_allspark_jit.py      4 passed
ruff check gptqmodel tests       clean

Also checked against a real 8-bit checkpoint (Qwen2.5-0.5B,
layers.0.mlp.gate_proj, K=896 N=4864): 2.7e-4 at M=1 and M=16, 2.1e-4 at M=64,
0 at M=256.

Two things worth knowing:

  1. To produce an AllSpark-compatible checkpoint you need group_size=-1, and
    that currently fails unless act_group_aware=False:

    ValueError: Module self_attn.q_proj -> act_group_aware=True requires
    group_size > 0, got -1.

    If AllSpark becomes a first-class backend, that path probably wants either a
    clearer error or an automatic fallback.

  2. The checkpoint stores qzeros=127 while the effective zero point is 128. I
    checked both against the original fp16 weights: 0.93% with 128 (just 8-bit
    quantization noise) vs 3.6% with 127. AllSpark ignores qzeros and assumes
    128, which is why has_pz=False works, but anything reading qzeros directly
    will be off by one LSB.

Not done yet: the loader still has to pick AllSparkLinear when the checkpoint
asks for backend=gptq_allspark. I have not touched the format matrix in
importer.py, since that depends on whether this becomes its own backend.

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).
@Lumea-art
Lumea-art force-pushed the feat/allspark-kernel branch from 63cdf19 to a3c00e6 Compare November 2, 2026 23:35
@Qubitium

Qubitium commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator

@Lumea-art Thanks for the pr! We have both 4090 and access to Ampere and GB10 to test this. I would recommend AllSpark as dedicated backend as backend=allspark, also try to qualify it for awq as normally both gptq/awq kernels can be shared bt adding qzero branching logic to the kernel. As for auto selection, we will determine that after all the bechmarks return.

For the second part of the question, I am not sure yet. I will run some tests on the draft pr before I can say for sure which direction we should go as in is dspark a runtime converted format or should be a full on disk format. I would lean to the runtime convert at the moment.

load-only like Marlin/ExllamaV2, or raw-weight packing too?

Qubitium commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator

4090 numbers for the AllSpark vs Marlin microbenchmark

Ran the PR's protocol on an RTX 4090 (sm_89, 72 MiB L2), commit a3c00e60b.

Setup: K=4096, N=11008, fp16, random uint8 weights + per-column fp16 scales (45.1 MB of weight bytes). Marlin is gptq_marlin_gemm on the same GPTQ-8bit qweight/scales (uint8b128, use_fp32_reduce=True). 20 warmup + 100 timed calls, median, CUDA events per call.

tests/test_allspark_jit.py + tests/test_allspark_linear.py: 7 passed.

Hot cache (same protocol as the table above)

M allspark ms marlin ms allspark / marlin
1 0.0205 0.0365 1.78x
8 0.0215 0.0379 1.76x
16 0.0225 0.0389 1.73x
24 0.0246 0.0396 1.61x
32 0.0254 0.0399 1.57x
64 0.0348 0.0474 1.36x
128 0.0572 0.0696 1.22x
256 0.1014 0.1190 1.17x

L2-flushed (weights read from GDDR6X)

A 512 MiB random fp32 buffer is reduced before every timed call so the 45.1 MB matrix is evicted from the 72 MiB L2. GB/s is weight bytes / time, same convention as the PR.

M allspark ms marlin ms allspark GB/s marlin GB/s
1 0.0573 0.0644 786 700
8 0.0581 0.0635 776 710
16 0.0584 0.0638 773 707
24 0.0599 0.0645 753 699
32 0.0604 0.0645 747 699
64 0.0642 0.0699 702 645
128 0.0697 0.0775 647 582
256 0.1103 0.1278 409 353

What this says

  • On the 4090 the hot row keeps the entire 45.1 MB matrix in 72 MiB L2, so it is an L2-bandwidth comparison rather than a memory-bandwidth one. The flushed row is the memory-roof comparison; there allspark and marlin are within ~10% for M<=32 (both ~780-870 GB/s, 77-86% of the 1008 GB/s GDDR6X nominal).
  • AllSpark is faster than Marlin at every M in the hot row; the M~24 crossover in the 5090 table does not reproduce here. The 5090 table's 980-1023 GB/s sits at its stated ~1 TB/s roof, so that run may be memory-bound rather than L2-bound; on the 4090 the larger L2 clearly holds the matrix and the hot row is an L2 comparison.
  • Per-call events include ~8 us of launch overhead (measured with a 1-element add in the same loop). CUDA-graph replay of the pure kernel at M=8 gives 0.0135 ms allspark vs 0.0260 ms marlin; at M=16, 0.0145 vs 0.0276.
  • Numerics against the dequantized reference: allspark 4.1e-4 relative error (fp16), marlin 5e-7 (fp32 reduce). Both are far inside the 0.02 test bound.
  • Caveat: one shape, one card, no end-to-end checkpoint here. This does fill in the sm_89 number the PR said it could not provide.

Repeated on the second 4090; medians matched within noise.

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.

Qubitium commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator

Pushed the benchmark to this PR branch as scripts/benchmark_allspark_w8a16.py (commit 2528e0aeb), so the 4090 numbers above are reproducible instead of just quoted.

python scripts/benchmark_allspark_w8a16.py

Options: --dtype float16|bfloat16, --shapes 4096x11008 4096x4096, --m 1 8 16 ..., --modes hot flushed graph, --json out.json, --iters/--warmup.

What it does: random uint8 weights + per-output-channel scales, K=4096 N=11008 by default, Marlin through gptq_marlin_gemm on the same GPTQ-format qweight/scales, median of 100 calls after 20 warmups, plus relative error against the dequantized reference. It warms the GPU clocks first, since a cold card reports ~30% low.

Three modes, because the single "hot" number is easy to misread:

  • hot — back-to-back calls. On a card whose L2 holds the 45.1 MB matrix this is a cache measurement, not a memory measurement.
  • flushed — a random 512 MiB fp32 buffer is reduced before every timed call. Random, not zero-filled: a zero or compressible buffer can be squashed by memory compression and fail to evict the weights.
  • graph — CUDA-graph replay, which removes the ~8 us per-call launch overhead the event-based modes include.

Re-run on the 4090 with the committed script (--iters 30):

M allspark hot marlin hot allspark flush marlin flush allspark graph marlin graph
1 0.0205 0.0366 0.0573 0.0647 0.0131 0.0241
8 0.0215 0.0381 0.0583 0.0645 0.0134 0.0255
16 0.0221 0.0389 0.0584 0.0653 0.0145 0.0270
24 0.0245 0.0393 0.0603 0.0653 0.0189 0.0274
32 0.0255 0.0399 0.0604 0.0653 0.0193 0.0277
64 0.0348 0.0488 0.0642 0.0718 0.0287 0.0358
128 0.0567 0.0706 0.0707 0.0797 0.0528 0.0581
256 0.1013 0.1208 0.1116 0.1300 0.0946 0.1063

ms, fp16. bf16 also runs; AllSpark's relative error goes from 4.1e-4 (fp16) to 3.2e-3 (bf16), which is output rounding rather than an arithmetic difference.

One caveat for whoever runs this next: on a card with less L2 than the weight matrix, hot and flushed converge and the first column stops being a fair comparison against any table that was measured L2-resident. Worth stating which mode a number came from in any comparison table.

Benchmark code is currently in 2528e0a

@Qubitium

Qubitium commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator

I will likely do a refractor on the backends, in separte PR, so that we longer have gptq_marlin and awq_marlin and just have single backend=marlin which auto routes to correct sub-marlin based on weight format. This should keep our backends list so much cleaner. Forgot the exact reason why this was not done before but will check again .

Pending: #3491

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

Qubitium commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator

RDNA4 (gfx1200/gfx1201) port — landed on this branch, with gfx1201 numbers

Commit 007df035e. Opt-in behind gptq_allspark (not in AUTO selection), easy to drop if you disagree.

Device: AMD Radeon AI PRO R9700, gfx1201, 32 CU, torch 2.16.0.dev+rocm10.1, hip 7.16. K=4096, N=11008, random uint8 codes + per-channel scales, 20 warmup + 100 timed calls, median, weight bytes only, ms.

M HIP fp16 hot flushed graph HIP bf16 hot flushed graph Triton fp16 hot Triton bf16 hot speedup bf16
1 0.0719 0.0988 0.0734 0.0747 0.1003 0.0697 0.1247 0.1341 1.80x
4 0.0659 0.0998 0.0689 0.0678 0.1000 0.0711 0.1983 0.4266 6.29x
8 0.0664 0.1017 0.0689 0.0687 0.1007 0.0710 0.1988 0.4263 6.20x
16 0.0723 0.1010 0.0698 0.0683 0.1031 0.0710 0.1997 0.4280 6.27x

Device read baseline on the same card: 602–606 GB/s (256 MiB random reduce), so flushed (~450 GB/s) is ~74% of achievable read bandwidth, and flushed is flat in M for both dtypes — weight-bandwidth-bound, as expected.

bf16 is now at parity with fp16

bf16 dequant was slower than fp16 in the L2-resident case. Same harness, same seed, M=8 hot:

fp16 bf16
before 0.0712 0.0840
after 0.0721 0.0676

Cause: __float2bfloat16() emits a NaN-aware compare + select per value, and gfx1200/1201 have no v_cvt_pk_bf16_* instruction to replace it with. The dequant inputs are (2^23 + code) * scale, always finite, so the NaN check is dead work:

a = u0 + 0x7FFFu + ((u0 >> 16) & 1u);   // integer RNE
b = u1 + 0x7FFFu + ((u1 >> 16) & 1u);
o = perm_b32(a, b, 0x03020706u);        // [a.b2, a.b3, b.b2, b.b3]

That removes 16× (v_cmp_u_f32 + v_cndmask_b32 + s_wait_alu + v_or_b32) per kernel body and adds 8× v_perm_b32: bf16 body 1431 → 1356 instructions, fp16 unchanged at 1209. bf16 now matches fp16 and, in this run, edges it out.

Qualification in the same commit

  • gptq_allspark lists DEVICE.ROCM; AllSparkLinear picks the HIP repack/GEMM on ROCm and keeps the CUDA path unchanged. The layouts differ (CUDA tiles N in 32s, WMMA pads to 128), so the module pairs repack with kernel and keeps both packed buffers non-persistent.
  • Fixed allspark_supported() returning True on ROCm: gfx1201 reports compute capability 12.0, inside the Ampere..Blackwell window, so the loader would have built the CUDA kernel under hipcc.
  • ROCm JIT flags discover the toolkit root (ROCM_PATH/ROCM_HOME/torch's ROCM_HOME) instead of hardcoding /opt/rocm, which is needed because the pip wheels ship libamdhip64.so.7 without the dev symlink.
  • Compile-time #error for any arch other than gfx1200/1201, plus a runtime sentinel the kernel stamps, so a silently empty body cannot ship.
  • M > 16 unpacks to a local temporary (no dense cache); a test asserts module tensor bytes do not grow across forwards.

Tests: 25 passed on gfx1201 (test_allspark_hip.py 19, test_allspark_linear.py 6 — fp16 and bf16, non-128-aligned N, M>16 fallback) and 10 passed on the 4090. test_allspark_linear.py now runs on both device paths, so a mismatched layout pairing fails the test instead of producing garbage.

Reproducing

python scripts/benchmark_allspark_hip_w8a16.py           # hot/flushed/graph, fp16 vs bf16
python scripts/benchmark_allspark_hip_w8a16.py --triton  # adds the Triton columns

Same protocol as scripts/benchmark_allspark_w8a16.py; the flush buffer is random, not zero-filled, so it cannot be squashed by memory compression and fail to evict the weights.

Not done

  • AWQ in the HIP port: the zero-point branch exists but is untested against a real AWQ checkpoint.
  • gfx1250: it has global_load_async_to_lds_b128, so the staging could become a real async pipeline there, but it is a different instruction set and untested.

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.

Qubitium commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

AllSpark AWQ 8-bit on RDNA4 (gfx1201)

AWQ-8 is now supported by the HIP AllSpark kernel: backend=awq_allspark, AllSparkAwqLinear, group sizes -1/16/32/64/128, fp16 and bf16, RDNA4 only.

What was needed

  • AWQ packs along N (qweight is (K, ceil(N*8/32))) while GPTQ-8 packs along K — new repack (allspark_hip_repack_awq) into the same WMMA fragment order.
  • AWQ carries a per-K-group zero point. GroupCnt/GroupSize in the kernel are real now: the scale/zero row is selected per 16-wide k-tile. GPTQ still reads its single per-channel row, unchanged.
  • bf16 now applies the zero point before the scale, in fp32 — the old ordering was (code-128)*scale - zero, which is wrong when the zero point is a code, not a bias-128 offset. fp16 subtracts the residual zero-128 after its existing conversion.
  • Group index is incremental instead of k / (GroupSize/kKTile); RDNA has no integer-divide instruction and the per-k-tile divide alone cost ~12 µs at group_size 32.

Bug found and fixed during validation: every entry point now takes a c10::cuda::CUDAGuard. 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 → NaN. Reproduced on 4× R9700, covered by a regression test.

Validation (gfx1201, 72 tests)

check result
fp64 oracle, fp16 + bf16, groups −1/16/32/64/128, M=1/4/16 within 1 output ULP
non-128-aligned N (11024) passes
zero point ≠ 128 (constant 200) passes — 128 is not assumed
pack → post_init → forward vs dense weight 0.36 % (8-bit noise)
M>16 prefill fallback passes, no dense weight cached
full Llama-3.2-1B AWQ-8 vs fp32 gold 1.86e-2 max rel; torch AWQ backend 2.10e-2

Throughput (K=4096, N=11008, 200 iters, device read baseline 607 GB/s, random weights)

dtype path M=1 M=4 M=8 M=16
fp16 GPTQ hot 71.0 µs / 635 70.3 / 641 65.8 / 686 66.0 / 683
fp16 AWQ gs=−1 65.8 / 685 65.4 / 689 65.7 / 687 65.7 / 686
fp16 AWQ gs=128 67.3 / 670 68.3 / 660 67.7 / 666 68.1 / 662
fp16 AWQ gs=32 78.2 / 577 79.1 / 570 78.2 / 577 78.1 / 577
bf16 GPTQ hot 65.3 / 690 65.7 / 686 66.2 / 681 66.4 / 679
bf16 AWQ gs=−1 70.4 / 640 69.6 / 648 70.4 / 640 70.8 / 637
bf16 AWQ gs=128 72.8 / 620 74.2 / 608 73.8 / 611 74.3 / 607

Graph-replay: fp16 AWQ gs=−1 reaches 62.6 µs / 720 GB/s (M=4). Flushed (weights evicted): 99–105 µs / 430–455 GB/s across all AWQ configs.

bf16 and fp16 are now within 7 % of each other at the same config (the earlier ~28 % bf16 deficit was the dequant ALU path, fixed in the previous commit). AWQ gs=−1 matches GPTQ; grouped AWQ pays 2–6 % at gs=128 and ~18 % at gs=32 for the extra per-tile scale/zero traffic. Reproduce with:

python scripts/benchmark_allspark_hip_w8a16.py --awq-group -1 32 128 --m 1 4 8 16 --iters 200
python -m pytest tests/test_allspark_hip.py tests/test_allspark_awq.py tests/test_allspark_linear.py

CUDA is untouched: the AWQ tests skip off gfx1200/1201, and AllSparkLinear GPTQ still passes on the 4090.

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

Qubitium commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

Correction + rebase: AWQ is per-channel only, and one allspark backend

Two things in my previous comment are now wrong, so flagging them explicitly.

1. Group sizes. AWQ is group_size=-1 only. Grouped zeros forced a per-16-wide-k-tile scale/zero reload; that is the whole reason gs=128 and gs=32 were slower in the table above. With one group over all of K the scales/zeros are (1, N) and the kernel loads them once, outside the k-loop, so the group branch, the group counter and pad_scale_grouped_kernel are gone. SUPPORTS_GROUP_SIZE = [-1], and pack() / allspark_hip_repack_awq() raise instead of silently mis-scaling. --awq-group -1 32 128 is now just --awq.

2. Backend name. Rebased on upstream/main and followed #3491: GPTQ_ALLSPARK and AWQ_ALLSPARK collapse into one BACKEND.ALLSPARK. AllSparkLinear (GPTQ) and AllSparkAwqLinear (AWQ) both declare it; method/format picks the sub-kernel. Old strings still load via the legacy alias table.

bf16 now matches fp16 on both paths (this was the remaining ~7% gap; the dequant fix landed earlier, this run confirms it survives the simplification).

gfx1201 (R9700, 32 CU), K=4096 N=11008, 200 iters, random weights, device read baseline 607 GB/s. Hot, µs / GB/s:

dtype path M=1 M=4 M=8 M=16
fp16 GPTQ 71.6 / 629 65.4 / 689 66.2 / 682 66.0 / 683
fp16 AWQ 70.7 / 638 65.9 / 684 65.8 / 685 65.1 / 692
bf16 GPTQ 74.7 / 603 66.7 / 676 67.8 / 665 67.4 / 669
bf16 AWQ 74.7 / 604 65.7 / 686 65.7 / 687 66.0 / 683
Triton bf16 reference 144.2 / 313 427.1 / 106 424.9 / 106 427.0 / 106

Graph replay at M=8: fp16 GPTQ 63.3 µs (712 GB/s), fp16 AWQ 63.3 (712), bf16 GPTQ 65.4 (690), bf16 AWQ 64.4 (700). Flushed is flat at 98–103 µs (440–460 GB/s) for every config, i.e. weight-bandwidth-bound.

Tests, gfx1201: test_allspark_hip.py + test_allspark_awq.py 40 passed; with test_allspark_linear.py + test_allspark_jit.py 46 passed / 4 skipped. 4090: 10 passed, AWQ suite skips as intended.

python scripts/benchmark_allspark_hip_w8a16.py --awq --triton --m 1 4 8 16 --iters 200
python -m pytest tests/test_allspark_hip.py tests/test_allspark_awq.py

Commit 421b66612 on feat/allspark-kernel.

@Qubitium Qubitium changed the title [RFC][Kernel] AllSpark W8A16: JIT scaffold + numerics (BACKEND wiring pending) [RFC][Kernel] AllSpark W8A16: CUDA (5090/4090) + ROCm (RDNA4) Nov 3, 2026
@Qubitium

Qubitium commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

@Lumea-art ROCm (RDNA4) kernels for AllSpark added. I will handle the validation of the Ampere/Rocm code and you can handle the rest (5090).

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

Copy link
Copy Markdown
Contributor Author

5090 side is done.

Tests on the current tip (38047ef):

tests/test_allspark_jit.py
tests/test_allspark_linear.py
tests/test_allspark_hip.py
tests/test_allspark_awq.py          10 passed, 40 skipped
ruff check gptqmodel tests

The skips are HIP and AWQ on CUDA, as intended.

End to end, on an 8-bit group_size=-1 Qwen2.5-0.5B checkpoint:

GPTQModel.load(ckpt, backend=BACKEND.ALLSPARK)   168 AllSparkLinear
forward + generate                               works

One bug in the benchmark you pushed: scripts/benchmark_allspark_w8a16.py used
BACKEND.GPTQ_MARLIN, which #3491 removed, so it raised AttributeError before
timing anything. Fixed to BACKEND.MARLIN in 38047ef. I grepped the other
benchmark scripts for removed enum members; that was the only one.

Numbers from the committed script on this card, K=4096 N=11008 fp16, all from
one run so the columns are comparable:

M    as hot  mr hot | as flush mr flush | as GB/s mr GB/s
1    0.0622  0.0602 |  0.1042   0.1103  |   433     409
8    0.0355  0.0469 |  0.0952   0.1076  |   474     419
16   0.0326  0.0496 |  0.1054   0.1227  |   428     368

Which is:

M     hot      flushed
1     0.97x    1.06x
8     1.32x    1.13x
16    1.52x    1.16x

The flushed numbers are in the same place as your 4090 (1.09-1.12x), a little
better at 8 and 16. The hot numbers are well below your 1.76x, which I think is
the smaller L2: this card has 64 MiB against the 4090's 72 MiB, so the 45 MB
matrix still fits but with far less headroom, plus the laptop power limit. At
M=1 the hot case is actually 3% slower than marlin here.

The number I would trust from a 5090 is the flushed one, about 1.1x, since that
is what a decode loop looks like once layers stop being cache resident.

Numerics: 2.05e-4 for allspark against the dequantized reference, 6.5e-7 for
marlin. That gap is the fp16 output rounding floor rather than arithmetic - the
error does not grow with K (3.6e-4 at K=1024 to 4.8e-4 at K=8192) and C_frag is
float.

Two caveats, both about this machine rather than the kernel:

  • The hot column drifts badly when the full sweep runs here. One 8-point run put
    M=24 at 0.34 ms while a 3-point run of the same kernel gives 0.08 ms. On this
    laptop, shortening the sweep is worth more than raising --iters.
  • The best I see is 474 GB/s against a measured 551 GB/s ceiling for a 1 GiB
    reduce on this card.

I have not touched the ROCm path or the AWQ code. If you want anything else
checked on the 5090 say so; otherwise I will stay out of the way until this is
merged.

One separate thing, not for this PR: producing the AllSpark checkpoint needs
group_size=-1, and quantizing with that currently dies on
"act_group_aware=True requires group_size > 0". It looks like a no-op flag in
that case, and I have a two-line fix plus a test. I will open it as its own PR
once this one lands, unless you would rather fold it in here.

@Qubitium

Qubitium commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

One separate thing, not for this PR: producing the AllSpark checkpoint needs
group_size=-1, and quantizing with that currently dies on
"act_group_aware=True requires group_size > 0". It looks like a no-op flag in
that case, and I have a two-line fix plus a test. I will open it as its own PR
once this one lands, unless you would rather fold it in here.

@Lumea-art Great! Let's do that on a seprate PR.

@Qubitium

Qubitium commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator

@Lumea-art Do you have the AllSpark compatible checkpoint that I can download to do e2e tests instead of synthetic testing?

real 8-bit checkpoint (Qwen2.5-0.5B)

@Lumea-art

Copy link
Copy Markdown
Contributor Author

No hosted copy right now - sorry,my egress to HF goes through a mirror that will not
accept uploads. Two options, pick whichever is less work for you.

  1. Generate it, about a minute on a 5090:

    from gptqmodel import BACKEND, GPTQModel
    from gptqmodel.quantization import GPTQConfig
    import torch

    calib = ["The quick brown fox jumps over the lazy dog and keeps on running."] * 64
    cfg = GPTQConfig(bits=8, group_size=-1, act_group_aware=False)
    m = GPTQModel.load("Qwen/Qwen2.5-0.5B-Instruct", cfg, device="cuda:0",
    dtype=torch.bfloat16)
    m.quantize(calib, batch_size=1, backend=BACKEND.TORCH)
    m.save("/tmp/qwen05b-w8")
    m.unload()

    m = GPTQModel.load("/tmp/qwen05b-w8", backend=BACKEND.ALLSPARK, device="cuda:0")

  2. I can attach the 614 MB safetensors to a GitHub release on my fork, it is
    under the 2 GB asset limit. Say the word and I will upload it today.

act_group_aware=False is needed on current main; that is the issue split into
the other PR. With that applied it can be left off.

What is inside, in case you check it before loading:

qweight   (224, 4864) int32    K=896, 4 codes per word along K
scales    (1, 4864)   fp16     group_size=-1
qzeros    (1, 1216)   int32    stores 127, but the effective zero is 128

That last line matters: 127 is not the real zero point. I checked both against
the original fp16 weights - 128 gives 0.93% error, i.e. 8-bit quantization
noise, while 127 gives 3.6%. AllSpark ignores qzeros and assumes 128, which is
why it matches.

Loaded here: 168 AllSparkLinear, and "The capital of France is" comes back as
"A. Paris". One layer under the torch backend differs from allspark by 2.16e-3
against marlin's 1.67e-3, both measured against torch.

@Qubitium Qubitium changed the title [RFC][Kernel] AllSpark W8A16: CUDA (5090/4090) + ROCm (RDNA4) [Kernel] AllSpark W8A16: CUDA (5090/4090) + ROCm (RDNA4) Nov 3, 2026
@Qubitium

Qubitium commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

@Lumea-art Got it. I just trained the same 0.8B model and it was fast as you demonostrated. Right now I am fixing RDNA4 bf16 major e2e accuracy drift. Once that's done, this PR is good to go.

@Lumea-art

Copy link
Copy Markdown
Contributor Author

Good to hear. I will stay out of the branch until your RDNA4 fix lands -
nothing I push now would help and it would only add noise to a diff that is
already where you want it.

One thing that might help with the drift: the bf16 baseline on CUDA. Same
checkpoint, same corpus, allspark kernel on sm_120, everything in bf16:

base bf16 model        13.2209
8-bit, torch backend   13.2515
8-bit, allspark        13.2710    (+0.38% over base)

On CUDA the bf16 path costs 0.38% and does not drift. If RDNA4 lands well above
that, it is in the HIP dequant or the zero-point ordering rather than in
anything shared with the CUDA kernel.

Which 0.8B did you use? I will run the same model here so the perplexity
numbers are actually comparable - mine above are Qwen2.5-0.5B, so they are only
useful to you as an order of magnitude.

Ping me when the fix is in and I will re-run the 5090 suite on the final tip
before you merge.

Qubitium commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

RDNA4 (gfx1201): bf16 vs fp16 vs torch reference

Numbers below are from the current tip 38047ef45, K=4096 N=11008, 200 iters, random weights, device read baseline 606.9 GB/s (AMD Radeon AI PRO R9700, gfx1201, 32 CU, torch 2.16 ROCm, hip 7.16.26385).

dtype path M=1 M=4 M=8 M=16
fp16 GPTQ 70.9 µs / 636 GB/s 65.1 / 692 65.4 / 690 65.2 / 692
fp16 AWQ 63.9 / 706 65.4 / 690 65.4 / 690 64.8 / 696
bf16 GPTQ 74.6 / 604 66.2 / 681 67.2 / 671 66.7 / 676
bf16 AWQ 75.5 / 597 65.3 / 690 65.4 / 689 65.8 / 685

Graph replay, M=8: fp16 GPTQ 62.7 µs (720 GB/s), bf16 GPTQ 64.8 (696), fp16 AWQ 62.8 (718), bf16 AWQ 64.2 (703). Flushed is flat at 98–102 µs (440–460 GB/s) in every configuration.

bf16 now tracks fp16 to within ~3% on the GPTQ path and is at parity on AWQ. The M=1 GPTQ row (604 vs 636) is the only remaining gap.

bf16 accuracy against the torch reference

Kernel arithmetic, fp32 output vs an fp64 gold (excludes output rounding), across all four (K,N) shapes in the model:

K N max rel cos
896 4864 2.23e-7 1.00000000
4864 896 1.95e-7 1.00000000
896 128 9.05e-8 1.00000000
896 896 7.65e-8 1.00000000

Against TorchLinear's dequant+matmul path on the same 8-bit weights, same layer, bf16: 7.4e-8 at M=1 and 1.03e-3 at M=8, cos 1.0000000. The HIP tests already assert bf16 visible error stays inside one output ULP, which is the guard for this.

End-to-end, Qwen2.5-0.5B 8-bit group_size=-1, M=1 decode logits against the fp16 base model:

run max rel min cos
allspark fp16 9.20e-2 0.996
torch fp16 9.18e-2 0.996
base model bf16 1.89e-1 0.979
torch bf16 2.23e-1 0.962
allspark bf16 2.99e-1 0.919

Read that table carefully before calling the last row a kernel problem. Layer-level AllSpark bf16 and torch bf16 agree to 7e-8, so the spread is not arithmetic. The unquantized base model in bf16 is already 1.9e-1 from the fp16 base, and torch's 8-bit bf16 run sits at 2.2e-1; AllSpark is at 3.0e-1 on the same scale. bf16 at 8 mantissa bits over 24 layers, measured against an fp16 reference, is coarser than the quantization noise being measured. AllSpark fp16 and torch fp16 land within 2.4e-3 of each other, i.e. the kernel adds ~2.4e-4 on top of quantization noise, matching the microbenchmark.

generate() output is byte-identical between AllSpark and TorchLinear in fp16, and bf16 text is coherent on both.

What the bf16 fix was

__float2bfloat16() emits a NaN-aware compare plus select per value, and the manual half-word pack added shifts and ORs — ~200 extra ALU instructions across the kernel, ~28% slower than fp16 in the L2-resident case. gfx1200/gfx1201 have no v_cvt_pk_bf16_* (the assembler rejects it), so the replacement is integer round-to-nearest-even plus one v_perm_b32: two adds and one perm per packed pair. Inputs are always finite (2^23 + code) * scale, so the NaN select is dead work and RNE is exact. The scale is applied in fp32 before the pack.

Tests, gfx1201: test_allspark_hip.py + test_allspark_awq.py + test_allspark_linear.py + test_allspark_jit.py 46 passed / 4 skipped (skips are CUDA-only cases). 4090: 10 passed.

python scripts/benchmark_allspark_hip_w8a16.py --awq --triton --m 1 4 8 16 --iters 200

No code change beyond what is already on the branch; the bf16 dequant fix has been in 007df035e since the HIP port landed.

@Qubitium

Qubitium commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator

@Lumea-art RNDA4 bf16 fix is in. You are free to push whatever you need to complete on your end. RNDA4 numbers also look good. Almost full bw saturation at the tested shapes.

@Lumea-art

Lumea-art commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor Author

Re-ran the 5090 suite on 38047ef - no code change on the branch since last
time, as you said. All green:

ruff check gptqmodel tests                 clean
tests/test_allspark_{jit,linear,hip,awq}   10 passed, 40 skipped
load ckpt with backend=allspark            168 AllSparkLinear
generate                                   coherent

perplexity, 3577 tokens, 512-token windows
  torch backend      13.2515
  allspark           13.2710    (+0.147%)

One thing I checked while I was in there: on CUDA an AWQ checkpoint now gets a
normal "no kernel" failure rather than a wrong answer, because AllSparkAwqLinear
declares SUPPORTS_DEVICES = [DEVICE.ROCM] and the selector filters on the device
family. That is the right behaviour, just worth knowing it is deliberate.

CUDA AWQ is the only gap I am aware of, and it is a follow-up rather than
something for this PR - the HIP side has an AWQ repack, the CUDA side still only
has the N32K16 GPTQ one.

Nothing blocking from my side. Shout if you want anything re-run before the
merge.

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

Qubitium commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator

AWQ W8A16, f25fcfa8c, K=4096/N=11008, random weights, 20 warmups/100 iterations. All times are µs. Flushed runs use a random 512 MiB eviction buffer.

Device M fp16 hot bf16 hot fp16 flushed bf16 flushed fp16 graph bf16 graph
RTX 4090 (GDDR6X) 1 24.42 24.58 61.41 61.41 14.24 14.88
RTX 4090 (GDDR6X) 8 24.58 24.58 61.84 61.44 15.26 16.16
RTX 4090 (GDDR6X) 16 29.39 28.67 65.54 65.25 19.43 19.33
RDNA4 gfx1201 1 81.84 85.46 110.16 112.18 64.51 68.73
RDNA4 gfx1201 8 77.02 78.40 112.40 111.92 63.51 65.02
RDNA4 gfx1201 16 77.76 78.74 114.78 114.04 64.05 65.45

Both runtimes use the shared BACKEND.ALLSPARK. CUDA consumes zero_awq - 128; HIP consumes raw AWQ zeros. Tests cover both conventions, endpoint zeros, and a deliberately incorrect zero-buffer control.

The RDNA4 bf16 conversion uses integer round-to-nearest-even plus byte packing. CUDA keeps split-K partials and reduction in FP32. Current timings show close fp16/bf16 performance.

PYTHONPATH=. python scripts/benchmark_allspark_w8a16.py --awq --m 1 8 16
PYTHONPATH=. python scripts/benchmark_allspark_w8a16.py --awq --dtype bfloat16 --m 1 8 16

Hot/graph results include cache reuse; flushed GB/s counts weight reads only. The .gitignore warning and explicit handwritten-HIP exceptions are included.

@Qubitium

Qubitium commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator

Correction to my earlier reply: BaseQuantLinear.validate() calls cached_validate_once() whether or not a device is supplied. The unsupported-runtime guard therefore protects both cases; there was no device-supplied bypass. The selector's family prefilter is additional filtering in AUTO selection.

CUDA AWQ is now supported through the shared BACKEND.ALLSPARK; the runtime chooses CUDA or RDNA4 and the checkpoint method chooses GPTQ or AWQ. group_size=K is the normalized equivalent of -1, meaning one full-K group.

@Qubitium

Qubitium commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

@Lumea-art Please test the awq allspark kernel on your 5090

@Lumea-art

Copy link
Copy Markdown
Contributor Author

Thanks for the correction - you are right about the mechanism. The device
filter at importer.py:1355 only runs when a device is supplied, so the
device-less path went through validate_once() at 1474 and hit
allspark_hip_supported(). My earlier note pointed at the wrong guard, and the
one that actually protected the path would not have caught a caller that passed
a device.

On the AWQ kernel: I had already run it on sm_120 before your message, on
e22efa8.

tests/test_allspark_awq_cuda.py                        10 passed
  test_awq_matches_fp64_oracle                       fp16 + bf16
  test_awq_zero_point_convention_is_load_bearing     fp16 + bf16
  test_awq_rejects_grouped_zeros                     fp16 + bf16

all five files together                                20 passed, 40 skipped
ruff check gptqmodel tests                             clean

Same pass/skip counts as your 4090 run; the skips are the RDNA4-only cases.

End to end with a real AWQ 8-bit group_size=-1 checkpoint (Qwen2.5-0.5B):

backend=torch      torch kernels          "Paris, and it has a population of"
backend=allspark   168 AllSparkAwqLinear  "Paris, and it is located in the"

logits allspark vs torch: rel 3.15e-3, argmax identical everywhere

Perplexity on the same corpus as my GPTQ numbers (3577 tokens, 512-token
windows):

AWQ 8-bit, torch backend    13.2798
AWQ 8-bit, allspark         13.2786

If the zero were being applied with the wrong sign that would move by far more
than 0.009%, so the negative control holds on this card too.

Benchmark of the AWQ path here, K=4096 N=11008 fp16:

M     hot     flushed   GB/s    graph
1     0.0601  0.0741    609     0.0409
8     0.0484  0.0961    469     0.0411
16    0.0540  0.1148    393     0.0430

Laptop caveat unchanged: those three points are one short run, the hot column
drifts when the full sweep runs here.

On the diff: I checked that the three-value return from allspark_repack has no
stale callers (utils/allspark.py:182, qlinear/allspark.py:180, the benchmark and
the JIT test), and two small things caught my eye, neither blocking.

utils/allspark.py:164 assert AWQ_ORDER is not None can never fail - if it is
there just to keep the import used, dropping both reads cleaner.

:170 accepts group_size == k while :174 then rejects anything that is not a
single scale row, so a real k-group checkpoint would surface the shape message
instead of the group_size one. Not wrong, just two checks disagreeing about
what the function supports.

Nothing else I would change, and nothing to push from me.

@Qubitium

Qubitium commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

Final review fixes pushed as f25fcfa8c:

  • Ship all CUDA/HIP JIT sources in wheel and sdist.
  • Use per-call CUDA scratch; no cross-device/stream sharing or retained dense fallback weights.
  • Keep CUDA split-K partials and reduction in FP32.
  • Fix HIP sentinel scale-buffer bounds; validate devices, shapes, dtypes and alignment.
  • Preserve AWQ dtype moves; cover empty inputs, padded shapes, pack boundaries, concurrent streams, graph replay, and storage lifetime.
Final AllSpark suite Passed Hardware-specific skips
RTX 4090 43 176
RDNA4 gfx1201 183 36

Backend/selector checks: 34 passed, 1 skipped. Ruff, package builds, installed-wheel source discovery and git diff --check pass.

RDNA4 retains the rtol=atol=2e-3 FP32 oracle gate. Eight bf16 midpoint cases are individually adjudicated: adjacent output values, maximum accumulator error 1.22e-5, and exact midpoint-crossing evidence. Tests reject nonadjacent or non-midpoint mismatches.

Real Qwen2.5-0.5B generation is coherent on both devices in fp16/bf16, with 168 AllSpark layers. The local AWQ checkpoint is a lossless layout conversion of the real GPTQ weights. On the 4090, maximum normalized model-logit differences versus Torch are 1.46% fp16 and 3.68% bf16; model outputs are not claimed bit-identical.

Updated timing tables show current fp16/bf16 parity. FP32 CUDA split scratch uses four bytes per partial instead of two; M=16 graph latency is about 19 µs on the 4090. No persistent dense-weight bytes remain.

Ready for another review. Not merged. The contributor's 5090 results cover e22efa869, before this final patch.

@Qubitium

Qubitium commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

@Lumea-art Some corrections pushed. Run your tests one more time on 5090 before I merge

@Lumea-art

Copy link
Copy Markdown
Contributor Author

Ran the full suite on f25fcfa.

ruff check gptqmodel tests                             clean
tests/test_allspark_{jit,linear,hip,awq,awq_cuda}.py   43 passed, 176 skipped

Same counts as your 4090 run. The skips are the RDNA4-only cases.

End to end, two 8-bit group_size=-1 checkpoints of Qwen2.5-0.5B:

GPTQ, backend=allspark    168 AllSparkLinear    "Paris. The city has a population of"
AWQ,  backend=allspark    168 AllSparkAwqLinear  coherent
AWQ logits vs torch backend: rel 4.13e-3, argmax identical everywhere

Perplexity, 3577 tokens of English from the repo docs, 512-token windows:

GPTQ 8-bit   torch 13.2515    allspark 13.2597    (+0.062%)
AWQ  8-bit   torch 13.2798    allspark 13.2799    (+0.001%)

The GPTQ delta moved from +0.147% on e22efa8 to +0.062% here, which is what I
would expect from moving the split-K partials to FP32 - the change is visible in
the end-to-end number, not just in the unit tests.

Timing on this card, same script, one short run each:

GPTQ  M   hot     flushed  graph     err
      1   0.0366  0.1076   0.0429    2.05e-4
      8   0.0445  0.0799   0.0391    2.06e-4
      16  0.2676  0.1571   0.1117    2.06e-4

AWQ   M   hot     flushed  graph     err
      1   0.0365  0.0807   0.0389    4.00e-4
      8   0.0569  0.0916   0.0391    4.13e-4
      16  0.0426  0.0802   0.0391    3.86e-4

The GPTQ M=16 row is the known laptop artifact - the sweep drifts and that point
lands high; the same kernel in a three-point run is 0.04-0.06 ms. AWQ is flat
across the three sizes here.

Nothing blocking from my side.

@Qubitium
Qubitium merged commit 8a6a03f into ModelCloud:main Nov 3, 2026
1 check passed
@Lumea-art

Copy link
Copy Markdown
Contributor Author

Merged - thanks. Follow-up opened as #3515 : a CUDA-graph regression test for
the AllSpark GEMM, one test file, no product code changes.

The PR body has a short scope note on what the test does and does not catch -
short version, it guards host round-trips, not allocations inside the capture
region.

Qubitium added a commit that referenced this pull request Nov 4, 2026
…ntization pipeline (#3532)

* feat(kernel): scaffold AllSpark W8A16 JIT extension

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.

* feat(kernel): add AllSparkLinear (load-only) with GPTQ 8-bit repack

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

* bench(allspark): add reproducible W8A16 hot/flushed/graph benchmark

Adds the script behind the 4090 numbers on #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.

* feat(allspark): add RDNA4 (gfx1200/gfx1201) HIP port for the W8A16 GEMM

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

* feat(allspark): AWQ 8-bit zero-point GEMM for RDNA4

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.

* refactor(allspark): one `allspark` backend, AWQ per-channel only

Follows #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.

* fix(allspark): benchmark script used the removed GPTQ_MARLIN enum

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

* feat(allspark): qualify the AWQ 8-bit path on CUDA, warn about hip ignore 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.

* fix(allspark): harden packaging, scratch lifetime and numerical validation

* feat(arch): shared CUDA tuning-family classification + hw parity contract

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

* fix(arch): classify explicit sm_*/capability inputs on ROCm hosts

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.

* perf(paroquant): per-family, row-banded Triton GEMM launch table

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.

* feat(awq): portable Triton GEMV for the FORMAT.GEMV packed layout

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.

* docs: hardware tuning parity policy for RTX 4090 (Ada) and RDNA4

* feat(gguf): enable the fused Triton kernels on ROCm

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.

* feat(rocm): actionable ROCm refusals for the CUDA-only backends

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.

* feat(triton): RTX 4090 (Ada, SM 8.9) tuned launch tables

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.

* test(ada): Torch-oracle A/B coverage and benchmark for the SM 8.9 tables

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.

* docs(rocm): RDNA4 matrix update; correct the AWQ GEMV decode-benchmark 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.

* perf(awq): measured RDNA4 (gfx1201) rules for the AWQ Triton GEMM scheduler

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.

* feat(paroquant): measured RTX 4090 (Ada, SM 8.9) GEMM launch tile

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.

* feat(awq): measured RTX 4090 (Ada, SM 8.9) portable Triton GEMV tile

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.

* docs(awq): correct the Ada GEMV speedup claim to the measured range

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.

* bench(ada): paroquant and portable AWQ GEMV sections; measured range fix

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

* test(hw-parity): enforce the AWQ GEMV table and both AWQ GEMM profiles

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.

* docs: record the profile-keyed AWQ GEMM and GGUF parity assertions

---------

Co-authored-by: fanxi <fanxi@local>
Co-authored-by: Lumea-art <[email protected]>
Co-authored-by: codex <codex@local>
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