Repository navigation
fix(cpu): decode int4pack fallbacks in a range-safe dtype (#5577) - #5596
Merged
Merged
Conversation
This was referenced Nov 20, 2026
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.
Summary
Fixes #5577.
#5495 made the checkpoint-layout AWQ dense decode range-safe, but two decodes still ran in the FP16 scale dtype: the live int4pack runtime decode after an eval warm-up, and the GPTQ
TorchFused/TorchAtendense fallback. A FP16 scale such as8192overflows toinf/NaNbefore the caller can widen the result, so the same layer returns30720without a grad andNaNwith one.What Changed
gptqmodel/nn_modules/qlinear/_decode_dtype.pywithdecode_dtype_for_scales()/scales_fit_dtype(). It selects the stored scale dtype while every decoded weight is finite and non-underflowing, and widens to FP32 (or FP64 for a pathological BF16 scale) only when needed. A wide activation dtype keeps its own dtype; undertorch.compilethe chooser reads only the dtype (a host reduction is not traceable) and keeps the historical narrow checkpoint-layout behavior.runtime_int4pack_dense_weight()now decodes scales, zeros, and codes in that dtype;int4pack_decode_dtype()reuses an AWQ module's_decode_dtype_for_activation()when present.PackableQuantLinear.dequantize_weight()/_dequantize_from_codes()accept an explicit decodedtype; the default is still the stored scale dtype.TorchFusedLinearandTorchAtenLinear(and their AWQ variants) decode the checkpoint and runtime weights in the range-safe dtype, and promote a wide decode to FP32 for the call instead of narrowing it back to the activation dtype before the product.tests/test_inference_fp16_overflov.pywith the no-grad warm-up regression for AWQ and cold/warm GPTQ cases (FP32 and FP16 activations, plus the FP32 grad check).Tests
The full file has 26 passed, 1 skipped, 12 failed on this host. Every failure is environmental: the AVX512 kernel classes are rejected on this non-AVX512 CPU, and the Marlin/AWQ-GEMM/ExllamaV2 tests require CUDA. They fail on
maintoo and do not touch the changed paths.Model Support / Module Plan
Not applicable: no model, alias, registry, or module-plan change.
Model test node IDs and results (or "not applicable"): not applicable.
AWQ onboarding safety
Not applicable: no model/alias or AWQ grouping/search/replay/fold change. The changed AWQ code is the existing dense decode fallback, and the new tests cover its range-safe decode directly.
AWQ evidence and per-variant policy (or "not applicable" with a reason): not applicable.
Logic Flow Documentation
Diagram summary: not applicable. This is a dtype chooser at the existing decode point; no selection order, lifecycle, or ownership contract changes.
Review Requirements
Kernel Accuracy Requirements
The new tests assert the exact decoded value (
30720) and the exact input gradient against the FP16-scale oracle in both cold and warmed states. The narrow path is unchanged when the stored scales fit the activation dtype.Not applicable: no fusion support, kernel inventory, or device-qualification change.