Skip to content

fix: reject non-fp16 AWQ GEMV configs at load time (#4394) - #4420

Closed
Qubitium wants to merge 1 commit into
mainfrom
pr/4394
Closed

Qubitium wants to merge 1 commit into
mainfrom
pr/4394

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Summary

AwqGEMVLinear, AwqGEMVTritonLinear, and the GEMV_FAST/LLM_AWQ kernels declare SUPPORTS_DTYPES = [torch.float16], but that dtype was only checked when the module was constructed in layer-0 finalize. The AWQ search had already run by then, so a bf16 (or fp32) model paid for calibration and only then failed with NotImplementedError. This adds an up-front check at load time, before the model is loaded/calibrated, and names dtype=torch.float16 as the fix.

What Changed

  • gptqmodel/quantization/config.py: added AWQ_FP16_ONLY_FORMATS (GEMV, GEMV_FAST, LLM_AWQ) and AWQConfig.validate_dtype(), which raises an actionable ValueError for a non-fp16 target dtype while leaving GEMM/MARLIN/BITBLAS untouched.
  • gptqmodel/models/auto.py: GPTQModel.from_pretrained() (and therefore GPTQModel.load()) resolves the effective target dtype (explicit dtype, model require_dtype, otherwise auto_dtype) after the config/model definition is read and before model_definition.from_pretrained() is called. The guard runs before any model construction or calibration.
  • tests/test_awq_gemv_dtype_4394.py: regression tests for GEMV/GEMV_FAST/LLM_AWQ rejection, fp16 acceptance, GEMM/MARLIN/BITBLAS unaffected, load-time rejection before model load, explicit fp16 pass-through, and the require_dtype override.
  • Kernels are unchanged.

Tests

# new regression test, after the fix
$ python3 -m pytest -q tests/test_awq_gemv_dtype_4394.py
19 passed in 5.36s

# same test with the fix reverted: 16 failed, 3 passed
$ git checkout -- gptqmodel/quantization/config.py gptqmodel/models/auto.py
$ python3 -m pytest -q tests/test_awq_gemv_dtype_4394.py
16 failed, 3 passed in 5.83s

# AWQ config/validation suites
$ python3 -m pytest -q tests/test_awq_gemv_dtype_4394.py tests/test_awq_loader_dtype.py \
    tests/test_awq_affine_range.py tests/test_awq_dynamic_group_size.py \
    tests/test_awq_modules_to_not_convert_4195.py \
    tests/test_awq_modules_to_not_convert_lifecycle_4309.py \
    tests/test_awq_per_module_bits.py tests/test_awq_fp16_matmul_heuristic.py \
    tests/test_aw*q_position*.py
145 passed, 86 skipped in 12.65s

# config suites
$ python3 -m pytest -q tests/test_config_only_export.py \
    tests/test_config_per_module_validation_4200.py \
    tests/test_config_serialization_roundtrip_4201.py
47 passed in 5.89s

$ ruff check gptqmodel/quantization/config.py gptqmodel/models/auto.py \
    tests/test_awq_gemv_dtype_4394.py
All checks passed!

CPU-only, no model downloads. The compiled CUDA AWQ extensions are not built in this container, so the native GEMV/GEMV_FAST/LLM_AWQ kernels themselves were not executed; the fix is validated through the config/load-time guard and the existing CPU config tests.

Model Support / Module Plan

N/A — no new model types or registry entries.

Fixes #4394

@Qubitium

Copy link
Copy Markdown
Collaborator Author

Superseded by #4424, which merged the same #4394 fix (auto-cast to fp16 on the AUTO path, reject an explicit conflicting dtype). Closing to avoid a conflicting duplicate.

@Qubitium Qubitium closed this Nov 16, 2026
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