Skip to content

fix(gsq): staged AWQ inference-mode weights and FP8 Gram symmetry tolerance (#4561, #4579) - #4602

Merged
Qubitium merged 2 commits into
mainfrom
fix/issue-4561-4579-gsq
Nov 17, 2026
Merged

Qubitium merged 2 commits into
mainfrom
fix/issue-4561-4579-gsq

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Fixes #4561
Fixes #4579

#4561 — staged AWQ GSQ crashed after layer 0 on every GPU

Root cause. refine_awq_staged_layer runs under torch.inference_mode(False) and assigned linear.weight.data = weight. The parameter was created under the looper's inference mode, so it is an inference tensor. Swapping .data for a normal tensor left a parameter that reports is_inference() == False but has no version counter; the next view taken by post_quantize -> move_module_to_cpu_pinned raised RuntimeError: 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 to named.state['wq'].

#4579 — calibrated FP8 GSQ always aborted on ROCm

Root cause. X.T @ X is symmetric mathematically, but rocBLAS/hipBLASLt reduce the two triangles in different orders and leave normal fp32 skew (~2e-7 relative to max|H| on gfx1201). refine_fp8_weight validated with torch.allclose(H, H.T, rtol=1e-5, atol=1e-7). The absolute atol dominates near-zero off-diagonals, so valid Grams were rejected and quantization aborted.

Fix. Replaced the element-wise allclose with a scale-aware skew bound: max|H - H.T| <= 1e-5 * max|H|. Justification: 1e-5 is ~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_factor already symmetrises with 0.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, skew 1.77e-3, max|G| = 9.43e3 (1.9e-7 relative). Old check rejects that Gram; new check accepts it, and refine_fp8_weight completes.

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:

  • pre-fix pytest tests/test_gsq_staged_public.py -q -k gpu_survives_post_quantize -> 1 failed (RuntimeError: Inference tensors do not track version counter)
  • post-fix same command -> 1 passed
  • pre-fix pytest tests/test_gsq_candidate_chunks.py -q -> 1 failed (ValueError: FP8 GSQ Hessian must be symmetric), 7 passed
  • post-fix same command -> 8 passed
  • pytest tests/test_gsq_staged_public.py tests/test_gsq_awq_code_recovery.py tests/test_gsq_candidate_chunks.py -q -> 150 passed, 58 skipped
  • pytest tests/test_gsq_method_adapters.py -q -> 15 passed

AMD R9700 (HIP_VISIBLE_DEVICES=2 only), ROCm venv /opt/venvs/rocm101t:

  • pytest tests/test_gsq_candidate_chunks.py -q -> 8 passed
  • pytest tests/test_gsq_staged_public.py -q -k gpu_survives_post_quantize -> 1 passed
  • end-to-end calibrated FP8 GSQ (FP8Config(device=DEVICE.ROCM, gsq_calibration=True), 1-layer tiny Llama, BACKEND.FP8_TORCH) -> completes (OK True); the same real Gram fed directly to refine_fp8_weight fails with the old check and passes with the new one.

Lint gate: ruff check gptqmodel docs/eora tests setup.py -> All checks passed!

Limitations

@Qubitium
Qubitium merged commit f6a1c74 into main Nov 17, 2026
9 checks passed
@Qubitium
Qubitium deleted the fix/issue-4561-4579-gsq branch November 17, 2026 02:14
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