Skip to content

fix(awq): resolve fp16-only GEMV dtype before calibration (#4394) - #4424

Merged
Qubitium merged 1 commit into
mainfrom
fix/awq-gemv-dtype
Nov 16, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/awq-gemv-dtype

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Fixes #4394.

Problem

AWQConfig(bits=4, group_size=128, format=FORMAT.GEMV) on a bf16 model crashed in layer-0 finalize, after calibration had already run:

NotImplementedError: AwqGEMVTritonLinear only supports [torch.float16]: actual dtype = torch.bfloat16

The GEMV/GEMV_FAST/LLM_AWQ kernels declare SUPPORTS_DTYPES = [torch.float16], but nothing checked or resolved the dtype up front. dtype=torch.float16 worked as a manual workaround.

Fix

Extended the existing _coerce_quantized_awq_dtype() helper in gptqmodel/models/loader.py instead of adding a parallel check:

  • It now recognizes the fp16-only GEMV layouts even when backend=AUTO — AUTO has not resolved a concrete kernel at load time, but every kernel AUTO can select for those layouts is fp16-only, so the format alone decides.
  • Auto-selected dtype (the default dtype="auto"): resolves to torch.float16 and logs the change. from_pretrained applies this before the shell model is materialized, so the quantized and non-quantized modules all load in one dtype and the forward cannot mix dtypes. The quantize path therefore fails/casts before calibration.
  • Explicit unsupported dtype=: raises ValueError during load/config resolution, naming the kernel, the supported dtypes, and both fixes (dtype=torch.float16, or a GEMM format). It no longer silently overrides the caller.
  • The old hardcoded silent fp16 override for GEMV_FAST/LLM_AWQ was folded into this helper, so there is one resolution point.

Tests

New tests/test_awq_gemv_dtype_4394.py plus additions to tests/test_awq_loader_dtype.py:

  • AUTO + GEMV + bf16 → model loads entirely in fp16 (no bf16/fp16 mix);
  • AUTO + GEMV + fp16 → unchanged;
  • explicit bf16 + GEMV → clear early ValueError, never the late layer-0 error;
  • GEMM formats keep bf16;
  • helper-level cases for GEMV, GEMV_FAST, LLM_AWQ under AUTO and an explicit backend.

Pre-fix (production file stashed): 7 failed, 5 passed — both end-to-end cases and all new helper cases. Post-fix: 12 passed; with the ROCm gating suite 25 passed; AWQ GEMV/bias/kernel/pack suites → 71 passed; kernel device-error/selection/AWQ-rank → 190 passed, 53 skipped. ruff check → clean.

Residual risk

  • Intentional behavior change: an explicit unsupported dtype on a GEMV-layout checkpoint load now raises instead of silently coercing (previously GEMV_FAST/LLM_AWQ were silently forced to fp16). This follows the issue's "reject at config/load time" contract.
  • No GPU quantize end-to-end run here (no CUDA); the CPU E2E test verifies load-time resolution and whole-model fp16.
  • The AUTO branch assumes every kernel selectable for the three GEMV layouts is fp16-only, which the declared SUPPORTS_DTYPES of AwqGEMVLinear, AwqGEMVFastLinear, LLMAwqLinear, AwqGEMVTritonLinear and the MLX GEMV holders confirm.
  • from_quantized captures "explicit dtype" before a model class's require_dtype override, so a forced class dtype is treated as auto and may be cast to fp16.
  • Left the "related" ROCm AUTO gating (_reject_native_awq_gemv_on_rocm) unchanged: ROCm cannot be run here, so the claim that AWQ_GEMV_TRITON works there is unverified.

AWQ FORMAT.GEMV/GEMV_FAST/LLM_AWQ kernels declare SUPPORTS_DTYPES=[fp16], but the quantize path loaded a bf16 shell model and only failed in layer-0 finalize after the AWQ search had run. Extend _coerce_quantized_awq_dtype to the quantize path and teach it that AUTO selects fp16-only kernels for those layouts: auto-selected dtypes are fixed to fp16 (logged, whole model) while an explicit unsupported dtype raises a ValueError naming the conflict and both fixes. Apply the same explicit-dtype contract to checkpoint loads.
@Qubitium
Qubitium merged commit 89fa9f4 into main Nov 16, 2026
10 of 12 checks passed
@Qubitium
Qubitium deleted the fix/awq-gemv-dtype branch November 16, 2026 13:59
Qubitium added a commit that referenced this pull request Nov 16, 2026
…uantize (#4381) (#4426)

* fix: restore base modules and re-pick CPU kernels after weight-only quantize (#4381)

* fix(module-tree): quantize consumers after producers in six definitions (#4372) (#4427)

LongCat-Flash interleaves attn0 -> mlps0 -> attn1 -> mlps1, but the tree
emitted both attention sub-blocks before both MLPs. Its MLA q_a/kv_a and
q_b/kv_b also shared a subset. Restructure the layer declaration into
per-sub-block entries so the emitted subsets follow the forward order, and
split the MLA stages.

Also move the attention output projection after its producers in
kimi_linear, nemotron_h (including the Nemotron Omni copy), bailing_moe,
and deepseek_vl_v2, and give lfm2_moe's conv in_proj/out_proj distinct
subsets.

Add static subset-order assertions and a generic tiny-model data-flow
probe that perturbs each declared Linear and requires every consumer to be
in a later subset. Update the registered module-plan fixture, the bailing
shared-expert plan test, and teach _tiny_config about lfm2_moe layer types.
Add lfm2_moe to the AWQ fold-preservation families.

* fix(awq): resolve fp16-only GEMV dtype before calibration (#4394) (#4424)

AWQ FORMAT.GEMV/GEMV_FAST/LLM_AWQ kernels declare SUPPORTS_DTYPES=[fp16], but the quantize path loaded a bf16 shell model and only failed in layer-0 finalize after the AWQ search had run. Extend _coerce_quantized_awq_dtype to the quantize path and teach it that AUTO selects fp16-only kernels for those layouts: auto-selected dtypes are fixed to fp16 (logged, whole model) while an explicit unsupported dtype raises a ValueError naming the conflict and both fixes. Apply the same explicit-dtype contract to checkpoint loads.

* fix: honour cpu_workers and live kernel policy; warn on retired env vars (#4396) (#4423)

* fix(gguf): serialize ggml-cuda entry process-wide (#4378) (#4421)

* fix(gguf): serialize ggml-cuda entry process-wide (#4378)

`_GGMLBridge.cuda_backend_lock` handed out one lock per CUDA device, so forwards on cuda:0 and cuda:1 could be inside ggml-cuda at the same time. ggml-cuda shares cuBLAS handles and memory pools across devices; on 2x RTX 4090 with PYTHON_GIL=0, 4 threads x 200 forwards aborted 5 of 20 runs in cublasGemmEx.

Return one re-entrant process-wide lock from `cuda_backend_lock`. The per-device backend-handle map is unchanged, and single-thread latency is unchanged because a forward already took one lock.

Add CPU-runnable regression tests that assert both devices share one lock and that cross-device forwards never overlap inside the backend critical section. They fail on the pre-fix code (max_active == 2).

Update the GIL=0 ledger with the concurrency contract change.

* test(gguf): give the plan-weight fake the process-wide backend lock

The kernel takes the bridge's cuda_backend_lock for every ggml-cuda entry,
but _FakeBridge predated that contract and had no such method, so
test_kernel_builds_the_weight_once_for_many_batch_sizes failed whenever a
CUDA device was visible. Expose the lock from the fake.

* test(gguf): collect worker failures as Exception, not BaseException

Code Quality flagged the two worker-thread handlers. They still re-raise the
collected failure in the main thread; narrowing the catch keeps
KeyboardInterrupt/SystemExit out of the collected list.

* fix: restore base modules and re-pick CPU kernels after weight-only quantize (#4381)

* test(insession): use one import style for gptqmodel.models.base

Code Quality flagged the test for importing the module both as an alias and
with from-import. The two monkeypatches now target the module path by string,
which still rebinds the global that rehome_quantized_kernel looks up.
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