Repository navigation
fix(gsq): staged AWQ inference-mode weights and FP8 Gram symmetry tolerance (#4561, #4579) - #4602
Merged
Merged
Conversation
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 #4561
Fixes #4579
#4561 — staged AWQ GSQ crashed after layer 0 on every GPU
Root cause.
refine_awq_staged_layerruns undertorch.inference_mode(False)and assignedlinear.weight.data = weight. The parameter was created under the looper's inference mode, so it is an inference tensor. Swapping.datafor a normal tensor left a parameter that reportsis_inference() == Falsebut has no version counter; the next view taken bypost_quantize->move_module_to_cpu_pinnedraisedRuntimeError: Inference tensors do not track version counter. This is device-generic (CUDA and ROCm), not ROCm-specific.Fix. Copy the fitted values into the existing parameter under
torch.inference_mode()instead of replacing.data. The parameter keeps its identity and inference state, and the staged weight is still published tonamed.state['wq'].#4579 — calibrated FP8 GSQ always aborted on ROCm
Root cause.
X.T @ Xis symmetric mathematically, but rocBLAS/hipBLASLt reduce the two triangles in different orders and leave normal fp32 skew (~2e-7 relative tomax|H|on gfx1201).refine_fp8_weightvalidated withtorch.allclose(H, H.T, rtol=1e-5, atol=1e-7). The absoluteatoldominates near-zero off-diagonals, so valid Grams were rejected and quantization aborted.Fix. Replaced the element-wise
allclosewith a scale-aware skew bound:max|H - H.T| <= 1e-5 * max|H|. Justification:1e-5is ~84 fp32 eps, comfortably above GEMM reduction-order noise (measured 1.9e-7 relative on the ROCm part) and far below a genuinely asymmetric matrix. I chose the scaled tolerance rather than a blanket loosening because the consumer_metric_factoralready symmetrises with0.5 * (H + H.T); the check now only guards grossly broken input. A gross-asymmetry test keeps the guard honest.Real ROCm BLAS probe (
906x896,x*3):torch.equal(G, G.T) = False, skew1.77e-3,max|G| = 9.43e3(1.9e-7 relative). Old check rejects that Gram; new check accepts it, andrefine_fp8_weightcompletes.Tests (real results)
Thread caps on every run:
OMP_NUM_THREADS=4 MKL_NUM_THREADS=4 OPENBLAS_NUM_THREADS=4 NUMEXPR_NUM_THREADS=4.RTX 4090 (
CUDA_VISIBLE_DEVICES=GPU-d458708b-c760-bbf1-08fb-8b8803a2157d), CUDA venv/opt/venvs/cu130t:pytest tests/test_gsq_staged_public.py -q -k gpu_survives_post_quantize-> 1 failed (RuntimeError: Inference tensors do not track version counter)pytest tests/test_gsq_candidate_chunks.py -q-> 1 failed (ValueError: FP8 GSQ Hessian must be symmetric), 7 passedpytest tests/test_gsq_staged_public.py tests/test_gsq_awq_code_recovery.py tests/test_gsq_candidate_chunks.py -q-> 150 passed, 58 skippedpytest tests/test_gsq_method_adapters.py -q-> 15 passedAMD R9700 (
HIP_VISIBLE_DEVICES=2only), ROCm venv/opt/venvs/rocm101t:pytest tests/test_gsq_candidate_chunks.py -q-> 8 passedpytest tests/test_gsq_staged_public.py -q -k gpu_survives_post_quantize-> 1 passedFP8Config(device=DEVICE.ROCM, gsq_calibration=True), 1-layer tiny Llama,BACKEND.FP8_TORCH) -> completes (OK True); the same real Gram fed directly torefine_fp8_weightfails with the old check and passes with the new one.Lint gate:
ruff check gptqmodel docs/eora tests setup.py->All checks passed!Limitations
linear.weight.data = weightacross inference_mode makes post_quantize view() raise #4561 regression test uses a tiny 2-layer model and forcesmove_module_to_cpu_pinned(pin_min_bytes=0)so the real view path runs (real 1B-class weights exceed the 8 MiB threshold naturally). It does not run the full Llama-3.2-1B end-to-end recipe from the issue.max|H|; it accepts fp32 Gram rounding and still rejects gross asymmetry. The calibrated collector stores FP32, which is the supported input.