Repository navigation
fix(awq): gate the model-wide GEMM pack kernel on the global width (#5408) - #5443
Merged
Merged
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #5408.
Problem
AWQConfig(bits=4, group_size=128, dynamic={"model.layers.1.mlp.down_proj": {"bits": 8}})is supported:AWQProcessor._resolve_qlinear_kernelalready returnsAwqTorchLinearfor a module whose width the native CUDA GEMM kernel cannot unpack. ButBaseQModel.quantizecallsselect_quant_linear(..., pack=True, backend=preferred_backend, dynamic=self.quantize_config.dynamic)twice before calibration (models/base.py, the pre-validation andself.qlinear_kernel), and with the default CUDA backend (awq_gemm_pack_backend->BACKEND.AWQ_GEMM) the explicit-backend branch validatesAwqGEMMLinearagainst every dynamic width and raises:backend=BACKEND.AWQ_TORCHworks 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:_dynamic_bits_supported(kernel, bits, dynamic)mirrorsBaseQuantLinear._validate_dynamic_bits(single-width kernels reject any different width; multi-width kernels check membership).gate_dynamicisNoneonly whenpack and quant_method == METHOD.AWQ and format == FORMAT.GEMMand 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.pack=False) keeps the full dynamic gate, so an explicitBACKEND.AWQ_GEMMload of a checkpoint with an 8-bit module is still refused up front._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).Tests
New
tests/test_awq_dynamic_bits_gate_5408.py(7 nodes, CPU only, fake kernels so no CUDA extension is needed):_dynamic_bits_supportedmirrors the kernel contract for single-width, multi-width,None, and non-bitsdynamic rules.pack=Truewith a{"bits": 8}rule on a 4-bit run handsdynamic=Noneto validation (fails before the change).pack=False(load) keeps 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 CPUselect_quant_linear(..., backend=BACKEND.AWQ_TORCH, pack=True)still returnsAwqTorchLinearwith and without a dynamic width.bash format/check.shpasses.Not verified locally
This host has one GB10 (sm_121) and no CUDA toolkit (
CUDA_HOMEunset), soAwqGEMMLinear's CUDA extension cannot be built and the end-to-endquantize -> save -> loadrepro 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-moduleAwqTorchLinearfallback itself is already covered bytests/test_awq_per_module_bits.py.