Skip to content

fix(awq): pick a device-capable AWQ GEMM pack kernel off CUDA - #3271

Merged
Qubitium merged 1 commit into
mainfrom
rocm/gfx950-awq-gemm-portable-pack
Oct 14, 2026
Merged

Qubitium merged 1 commit into
mainfrom
rocm/gfx950-awq-gemm-portable-pack

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Problem

Data-driven AWQ quantization with format=FORMAT.GEMM and the default backend=BACKEND.AUTO aborts on ROCm/gfx950:

ValueError: AWQ: failed to build torch.ops JIT extension: Error building extension 'gptqmodel_awq_ops': ...

GPTQModel.quantize() hard-coded BACKEND.AWQ_GEMM for the GEMM export lifecycle, and AwqGEMMLinear requires the native AWQ extension whose sources include cusparse.h and CUDA-only inline asm (nv_bfloat16, "l"/"=f" asm constraints, 32-bit __shfl_down_sync masks). That extension never builds on ROCm, so the run died after a wasted ~7s compile attempt.

Fix

Route the choice through a new awq_gemm_pack_backend() helper:

  • real CUDA devices keep the native AWQ_GEMM kernel;
  • ROCm / XPU / NPU / CPU (and weight-only exports) pack with the portable torch kernel (AWQ_TORCH).

The portable kernel emits the identical AWQ GEMM layout for in-range codes, and the loader already selects AWQ_TORCH for AWQ checkpoints (gptqmodel/models/auto.py), so exported weights stay interoperable.

AwqGEMMLinear.validate_once() now reports the ROCm gap with an actionable message instead of triggering a doomed JIT build.

Validation (MI355X / gfx950)

  • method=AWQ, format=GEMM, backend=AUTO now quantizes end-to-end: OK quantize 4.01s on the tiny qwen2 fixture (previously a hard failure); packing kernel selected as AwqTorchLinear.
  • New unit tests in tests/test_awq_cuda_contract.py: portable-backend selection matrix, CUDA-only device contract, and the ROCm validate_once() message.
  • pytest -q tests/test_backend_naming.py tests/test_weight_only_config.py tests/test_awq_cuda_contract.py → 45 passed, 2 skipped.
  • Ruff clean.

Data-driven AWQ quantization with `format=FORMAT.GEMM` and the default
`backend=BACKEND.AUTO` aborted on ROCm/gfx950:

    ValueError: AWQ: failed to build torch.ops JIT extension: ...

`GPTQModel.quantize()` hard-coded `BACKEND.AWQ_GEMM` for the GEMM export
lifecycle, and `AwqGEMMLinear` needs the native AWQ extension, whose sources
include `cusparse.h` and CUDA-only inline asm.  That extension never builds
on ROCm, so the run died after a wasted ~7s compile attempt.

Route the choice through a new `awq_gemm_pack_backend()` helper: keep the
native kernel on real CUDA devices, and pack with the portable torch kernel
everywhere else (ROCm/XPU/NPU/CPU) plus for weight-only exports.  The
portable kernel emits the identical AWQ GEMM layout for in-range codes, and
the loader already selects `AWQ_TORCH` for AWQ checkpoints, so the exported
weights stay interoperable.

`AwqGEMMLinear.validate_once()` now reports the ROCm gap with an actionable
message instead of triggering a doomed JIT build.

Validated on MI355X (gfx950): `method=AWQ, format=GEMM, backend=AUTO` now
quantizes end-to-end (4.0s on the tiny qwen2 fixture, was a hard failure);
the packing kernel is selected as `AwqTorchLinear`.
@Qubitium
Qubitium merged commit 3c539a9 into main Oct 14, 2026
6 checks passed
@Qubitium
Qubitium deleted the rocm/gfx950-awq-gemm-portable-pack branch October 14, 2026 19:25
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.

1 participant