Skip to content

[BUG] AWQ quantize: model-wide bits=8 / bits=3 (FORMAT.GEMM) fails on CUDA with the default backend before calibration; the AWQ_TORCH packer is never selected #6135

Done

Description

@Qubitium

Summary

METHOD_SUPPORTED_BITS[METHOD.AWQ] advertises (2, 3, 4, 8), and docs/awq-dequant-layouts.md says the gemm layout is packed by AwqGEMMLinear for 4-bit and by AwqTorchLinear for 2/3/8-bit. On a CUDA host, quantize() with the default backend=BACKEND.AUTO still picks BACKEND.AWQ_GEMM for the pack kernel, whatever the global width is. The model-wide select_quant_linear(...) gate then rejects AwqGEMMLinear for any width other than 4, so AWQConfig(bits=8) or AWQConfig(bits=3) fails before calibration starts:

ValueError: <class 'gptqmodel.nn_modules.qlinear.gemm_awq.AwqGEMMLinear'> only supports `[4]` bits: actual bits = `8`

The packer and the runtime both support these widths. The same config and model quantize, save, reload and generate correctly if the caller passes backend=BACKEND.AWQ_TORCH to quantize(). Only the AUTO pack-backend choice is wrong. #5408 / #5443 fixed the per-module dynamic case by gating on the global width. A non-4-bit global width still takes the GEMM gate.

Introduced by

Long-standing. awq_gemm_pack_backend was added in 3c539a930 / #3271 and has always returned AWQ_GEMM on CUDA. 8-bit and 3-bit AWQ were added to METHOD_SUPPORTED_BITS in 0aaf40e95 / #3561. Still present at d81ad345e and at origin/main 73e3d953f.

Location

gptqmodel/models/base.py:3153-3161 (HEAD d81ad345e):

                if format_code == FORMAT.GEMM:
                    ...
                    preferred_backend = awq_gemm_pack_backend(
                        device_type=quant_device_type,
                        is_rocm=IS_ROCM,
                        weight_only=self.quantize_config.uses_weight_only_lifecycle(),
                    )

gptqmodel/utils/backend.py:299-301:

    if weight_only or is_rocm or device_type != "cuda":
        return BACKEND.AWQ_TORCH
    return BACKEND.AWQ_GEMM          # regardless of bits

This is followed by the model-wide gate at gptqmodel/models/base.py:3251 (select_quant_linear(bits=self.quantize_config.runtime_bits, ..., backend=BACKEND.AWQ_GEMM, pack=True)). That gate raises because AwqGEMMLinear.SUPPORTS_BITS = [4].

Reproduction

I ran this on an A100 with transformers 5.23 and torch 2.15:

import torch
from gptqmodel import GPTQModel, QuantizeConfig, CalibrationConfig, BACKEND
from gptqmodel.quantization import FORMAT, METHOD

qc = QuantizeConfig(bits=8, group_size=128, sym=False, quant_method=METHOD.AWQ, format=FORMAT.GEMM)  # same with bits=3
m = GPTQModel.load("Qwen/Qwen2.5-0.5B-Instruct", quantize_config=qc, dtype=torch.bfloat16)
m.quantize(CalibrationConfig(dataset=wikitext_train_texts[:128], batch_size=4, concat_size=512))

Output:

  File "gptqmodel/models/base.py", line 3251, in quantize
    _ = select_quant_linear(
  File "gptqmodel/utils/importer.py", line 1834, in select_quant_linear
    raise ValueError(err)
ValueError: <class 'gptqmodel.nn_modules.qlinear.gemm_awq.AwqGEMMLinear'> only supports `[4]` bits: actual bits = `8`

bits=3, group_size=32 fails the same way (actual bits = 3).

With m.quantize(..., backend=BACKEND.AWQ_TORCH), the same 8-bit BF16 asym run quantizes, saves and reloads without errors. Reloaded wikitext-2 perplexity (40x512 tokens) is 18.12 with AUTO (AwqMarlinLinear), 18.11 with AWQ_TORCH and 18.12 with MARLIN. The BF16 FP baseline is 18.12. So the format itself works end to end.

Expected vs actual

Expected: an AWQ GEMM run at a supported global width other than 4 (2/3/8) packs with AwqTorchLinear, as the docs and the METHOD_SUPPORTED_BITS comment ("Request GEMM plus AWQ_TORCH; the AWQ processor also selects it for non-4-bit GEMM modules") describe.
Actual: quantize() raises before calibration unless the user knows to pass backend=BACKEND.AWQ_TORCH.

Suggested fix

When AUTO resolves the AWQ GEMM pack backend, return BACKEND.AWQ_TORCH whenever quantize_config.runtime_bits != 4. Do this in awq_gemm_pack_backend (pass bits) or at the call site in BaseQModel.quantize. Then the model-wide gate validates the kernel that will actually pack. Add a regression that runs AWQConfig(bits=8) and AWQConfig(bits=3) with the default backend on CUDA.

Activity

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