Skip to content

fix(awq): gate the model-wide GEMM pack kernel on the global width (#5408) - #5443

Merged
Qubitium merged 1 commit into
mainfrom
fix/awq-dynamic-bits-model-wide-gate-5408
Nov 19, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/awq-dynamic-bits-model-wide-gate-5408

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Fixes #5408.

Problem

AWQConfig(bits=4, group_size=128, dynamic={"model.layers.1.mlp.down_proj": {"bits": 8}}) is supported: AWQProcessor._resolve_qlinear_kernel already returns AwqTorchLinear for a module whose width the native CUDA GEMM kernel cannot unpack. But BaseQModel.quantize calls select_quant_linear(..., pack=True, backend=preferred_backend, dynamic=self.quantize_config.dynamic) twice before calibration (models/base.py, the pre-validation and self.qlinear_kernel), and with the default CUDA backend (awq_gemm_pack_backend -> BACKEND.AWQ_GEMM) the explicit-backend branch validates AwqGEMMLinear against every dynamic width and raises:

ValueError: <class 'AwqGEMMLinear'> not supported dynamic_bits, only support `[4]` bits

backend=BACKEND.AWQ_TORCH works around it, which shows the format and the packer both support the config; only the up-front model-wide gate rejects it.

Change

In select_quant_linear, the explicit-backend branch now validates the AWQ GEMM pack candidate against the global width when the dynamic map assigns a width the candidate cannot unpack:

  • New _dynamic_bits_supported(kernel, bits, dynamic) mirrors BaseQuantLinear._validate_dynamic_bits (single-width kernels reject any different width; multi-width kernels check membership).
  • gate_dynamic is None only when pack and quant_method == METHOD.AWQ and format == FORMAT.GEMM and some dynamic width is unsupported. The model-wide kernel is only the default for the modules that match it; the per-module processor fallback packs the rest.
  • Load-time selection (pack=False) keeps the full dynamic gate, so an explicit BACKEND.AWQ_GEMM load of a checkpoint with an 8-bit module is still refused up front.
  • GEMV/GEMV_FAST have no per-module width fallback in _resolve_qlinear_kernel, so they keep the full gate (the issue's "apply the same if they share the gate" does not apply: relaxing there would move the failure to pack time).
  • Other methods and formats are unchanged.

Tests

New tests/test_awq_dynamic_bits_gate_5408.py (7 nodes, CPU only, fake kernels so no CUDA extension is needed):

  • _dynamic_bits_supported mirrors the kernel contract for single-width, multi-width, None, and non-bits dynamic rules.
  • AWQ GEMM pack=True with a {"bits": 8} rule on a 4-bit run hands dynamic=None to validation (fails before the change).
  • pack=False (load) keeps the full map.
  • A kernel that supports 2-8 bits keeps the map.
  • A same-width dynamic rule keeps the map.
  • GEMV and non-AWQ methods keep the full map.

On the pre-fix tree the new gate node fails (the helper node fails at import of the missing attribute). Neighbouring suites: test_awq_per_module_bits.py, test_cpu_kernel_constraints_4181.py, test_hf_packing_api.py, test_npu_support.py, test_mlx_method_selection.py, test_lazy_kernel_registry_import.py, test_awq_dynamic_group_size.py -> 242 passed, 38 skipped. A real CPU select_quant_linear(..., backend=BACKEND.AWQ_TORCH, pack=True) still returns AwqTorchLinear with and without a dynamic width. bash format/check.sh passes.

Not verified locally

This host has one GB10 (sm_121) and no CUDA toolkit (CUDA_HOME unset), so AwqGEMMLinear's CUDA extension cannot be built and the end-to-end quantize -> save -> load repro on a CUDA host could not be run here. The test pins the exact value (dynamic) the model-wide gate receives, which is the behaviour that raised; the per-module AwqTorchLinear fallback itself is already covered by tests/test_awq_per_module_bits.py.

…5408)

`AWQConfig(dynamic={"...": {"bits": 8}})` on a 4-bit GEMM run is supported:
`AWQProcessor._resolve_qlinear_kernel` packs a module whose dynamic width the
native CUDA GEMM kernel cannot unpack with the portable `AwqTorchLinear`. The
pre-quantize `select_quant_linear(..., pack=True)` call validated the
model-wide `AwqGEMMLinear` candidate against every dynamic width instead and
raised `ValueError: ... not supported dynamic_bits, only support [4] bits`
before calibration started.

Relax that gate for the AWQ GEMM *pack* path only: when the selected kernel
declares support for fewer widths than the dynamic map assigns, validate the
model-wide candidate against the global width (the per-module processor
fallback owns the rest). Load-time selection (`pack=False`), GEMV/GEMV_FAST
(no per-module width fallback) and every other method keep the full gate.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant