Repository navigation
fix(awq): resolve fp16-only GEMV dtype before calibration (#4394) - #4424
Merged
Merged
Conversation
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
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.
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 #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:The GEMV/GEMV_FAST/LLM_AWQ kernels declare
SUPPORTS_DTYPES = [torch.float16], but nothing checked or resolved the dtype up front.dtype=torch.float16worked as a manual workaround.Fix
Extended the existing
_coerce_quantized_awq_dtype()helper ingptqmodel/models/loader.pyinstead of adding a parallel check: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.dtype="auto"): resolves totorch.float16and logs the change.from_pretrainedapplies 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.dtype=: raisesValueErrorduring 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.GEMV_FAST/LLM_AWQwas folded into this helper, so there is one resolution point.Tests
New
tests/test_awq_gemv_dtype_4394.pyplus additions totests/test_awq_loader_dtype.py:ValueError, never the late layer-0 error;GEMV,GEMV_FAST,LLM_AWQunder 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
dtypeon a GEMV-layout checkpoint load now raises instead of silently coercing (previouslyGEMV_FAST/LLM_AWQwere silently forced to fp16). This follows the issue's "reject at config/load time" contract.SUPPORTS_DTYPESofAwqGEMVLinear,AwqGEMVFastLinear,LLMAwqLinear,AwqGEMVTritonLinearand the MLX GEMV holders confirm.from_quantizedcaptures "explicit dtype" before a model class'srequire_dtypeoverride, so a forced class dtype is treated as auto and may be cast to fp16._reject_native_awq_gemv_on_rocm) unchanged: ROCm cannot be run here, so the claim thatAWQ_GEMV_TRITONworks there is unverified.