Skip to content

[BUG] AWQ GEMM quantize on CUDA rejects any per-module dynamic width (bits 3/8): model-wide AwqGEMMLinear gate runs before the per-module AwqTorchLinear fallback #5408

Closed

Description

@Qubitium

Found on main @ 1405751, RTX 5090 (sm_120), transformers 5.23.0.

What is wrong

AWQConfig accepts a per-module width through dynamic (for example {"bits": 8} on one layer of a 4-bit run). tests/test_awq_per_module_bits.py and AWQProcessor._resolve_qlinear_kernel (looper/awq_processor.py:726-735) document this: "RCO can allocate a different width per module. The CUDA GEMM/GEMV kernels unpack 4-bit codes only, so a non-4-bit module must use the portable torch kernel". The per-module fallback to AwqTorchLinear exists, but it never runs on a CUDA host with the default backend:

  • BaseQModel.quantize picks awq_gemm_pack_backend(...), which returns BACKEND.AWQ_GEMM on CUDA (utils/backend.py:279-281, models/base.py:2691-2698).
  • quantize then runs a model-wide select_quant_linear(..., dynamic=self.quantize_config.dynamic, backend=BACKEND.AWQ_GEMM) (models/base.py:2781). This validates AwqGEMMLinear against every dynamic width (nn_modules/qlinear/__init__.py:1028 _validate_dynamic_bits) and raises before calibration starts.

So any AWQ GEMM run with a non-4-bit dynamic width fails on CUDA unless the caller passes backend=BACKEND.AWQ_TORCH. With that backend the identical config quantizes, saves and reloads with the requested widths. So the format and the packer both support it, and only the up-front gate rejects it.

Repro

import torch
from gptqmodel import GPTQModel, BACKEND
from gptqmodel.quantization.config import AWQConfig, CalibrationConfig
dyn = {"model.layers.1.mlp.down_proj": {"bits": 8}}          # or {"bits": 3}
m = GPTQModel.load("Qwen/Qwen2.5-0.5B-Instruct", AWQConfig(bits=4, group_size=128, dynamic=dyn), dtype=torch.float16)  # 2-layer copy
m.quantize(CalibrationConfig(dataset=c4_rows[:16]))
  File "gptqmodel/models/base.py", line 2781, in quantize
  File "gptqmodel/utils/importer.py", line 1868, in select_quant_linear
ValueError: <class 'gptqmodel.nn_modules.qlinear.gemm_awq.AwqGEMMLinear'> not supported dynamic_bits, only support `[4]` bits

The same model and config with m.quantize(CalibrationConfig(dataset=c4_rows[:16]), backend=BACKEND.AWQ_TORCH) works. Save and GPTQModel.load give layers.0.mlp.down_proj as AwqMarlinLinear bits 4 and layers.1.mlp.down_proj as AwqMarlinLinear bits 8. The same failure occurs with regex rules ({"+:.*layers\\.1\\..*": {"bits": 8}}).

Suggested fix

When awq_gemm_pack_backend would choose AWQ_GEMM and dynamic assigns any width outside AwqGEMMLinear.SUPPORTS_BITS, either validate the model-wide candidate against the global width only (the per-module _resolve_qlinear_kernel already picks AwqTorchLinear for those modules), or choose AWQ_TORCH as the pack backend. Apply the same to GEMV/GEMV_FAST if they share the gate.

Test that should have caught it

tests/test_awq_per_module_bits.py uses stubs only and never calls quantize(). Add an end-to-end CUDA AWQ GEMM quantize with one {"bits": 8} module, then save, reload and check the per-module width.

Severity

Medium. A documented per-module configuration (and RCO's AWQ allocation, which writes such dynamic widths) is refused on the default CUDA path. It fails loudly before any work, and backend=BACKEND.AWQ_TORCH is a workaround.

🤖 Generated with Claude Code

Activity

  1. Qubitium commented on Nov 19, 2026

    @Qubitium
    CollaboratorAuthor

    Agent claim released: agent-fb5145b84190 finished this issue.

    Pull request: #5443

    AWQ: the model-wide select_quant_linear gate must validate the global width only, so per-module non-4-bit dynamic widths fall back to AwqTorchLinear in _resolve_qlinear_kernel instead of failing before calibration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions