Repository navigation
fix(qqq): honour damp_auto_increment in Hessian recovery - #5932
Merged
Merged
Conversation
QQQConfig accepted and serialized damp_auto_increment, but the QQQ solve made exactly one damping attempt: a rank-deficient Hessian raised from torch.linalg.cholesky instead of retrying at the next candidate. Extract GPTQ's damping-recovery policy (configured damp probe, additive grid, diagonal floor) into a module-level helper and call it from QQQ, which keeps its own inverse-factor convention. QQQ now reports the damp it actually applied, and a zero increment remains the explicit no-recovery control. The CUDA OOM retry still restores the original diagonal, moves H/W to the host, and re-runs recovery there. A numerical failure that exhausts recovery raises torch._C._LinAlgError without falling back to CPU. Tests: rank-deficient recovery matches an explicit damp control bit for bit; healthy layers do not start recovery; applied damp is reported; zero increment fails; a large-enough grid recovers an indefinite matrix. The existing #4400 numerical-failure test now uses cholesky_ex info != 0 so the grid and floor are exercised before the expected failure. Fixes #5858
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
QQQConfigaccepts and serializesdamp_auto_increment, but the QQQ solvemade exactly one damping attempt: a rank-deficient Hessian raised
torch.linalg.choleskyinstead of retrying at the next candidate. Starting thesame fixture at
damp_percent=0.01succeeded, which is exactly the candidatethe configured increment describes.
Extract GPTQ's damping-recovery policy (configured damp probe, additive
damp_auto_incrementgrid, diagonal floor) into a module-levelrecover_damped_hessian_factorhelper and call it from QQQ. QQQ keeps its owninverse-factor convention (lower Cholesky factor, then the inverse's upper
factor), so only the damping decision is shared. A zero increment remains the
explicit no-recovery control.
Fixes #5858
What Changed
gptqmodel/quantization/gptq.py: move the existinghessian_inversedamping body into
recover_damped_hessian_factor(H, *, damp_percent, damp_auto_increment, name, npu_block_size) -> (factor | None, used_damp).GPTQ behaviour is unchanged; the helper restores the Hessian diagonal
between candidates and only mutates it on the final floor attempt.
gptqmodel/quantization/qqq.py: call the shared helper withpercdampandself.qcfg.damp_auto_increment. The CUDA OOM retry is preserved (restore theoriginal diagonal, move
H/Wto the host, re-run recovery there). Anumerical failure that exhausts recovery uses the existing sample-count
fallback when configured and otherwise raises
torch._C._LinAlgErrorwithout moving to CPU. The reported damp is the one actually applied.
docs/quantizer-moe.md#41-damping-recovery-inside-the-hessian-solve:document the shared recovery flow and the QQQ/GPTQ split.
tests/test_qqq_damp_recovery_5858.py; the existing [MEM] MoE/OOM: shared-input Hessian adoption keeps 3 C^2 per pair (+0.96 GiB/20% peak on Qwen1.5-MoE), quantized MoE reload materializes bf16 experts on host (12.2 vs 4.2 GiB RSS), OOM CPU fallback missing in QQQ/EXL3 and after GPTQ inverse #4400numerical-failure test now drives
cholesky_extoinfo != 0on every CUDAprobe so recovery is genuinely exercised before the expected failure.
Out of scope: no change to GPTQ's selection order or to the sample-count
fallback policy itself.
Tests
The new coverage fails on the parent commit (
LinAlgErrorwhere recovery isexpected), and the #4400 rewrite fails on this branch if the CPU fallback
message appears for a numerical failure.
Measured Impact
Conditions: aarch64, torch 2.11.0+cu130, CPU FP16,
torch.set_num_threads(1).The before/after runs use the issue's exact script: tiny Llama, 128 hidden
size, one layer, 32 calibration tokens,
QQQConfig(bits=4, group_size=-1, fallback=None, device="cpu", offload_to_disk=False, damp_percent=1e-10, damp_auto_increment=0.01)and themodel.layers.0.self_attn.q_projtarget.The control run uses an explicit
damp_percent=0.01with the same weights.torch._C._LinAlgError(leading minor 34)damp_percent=0.01controldamp_auto_increment=0LinAlgErrorLinAlgErrorLogic Flow Documentation
The shared flow is documented with shipped symbol names in
docs/quantizer-moe.md#41-damping-recovery-inside-the-hessian-solve,which repeats this diagram:
flowchart TD A["QQQ._quantize_impl / GPTQ.hessian_inverse"] --> B["recover_damped_hessian_factor(H)"] B --> C{"try_factor at damp_percent"} C -- success --> S["return factor, damp_percent"] C -- failure --> D{"damp_auto_increment == 0"} D -- yes --> E["try diagonal floor"] D -- no --> F["probe damp_percent + increment"] F -- success --> S2["return factor, candidate damp"] F -- failure --> G["walk additive grid, endpoint first"] G -- success --> S2 G -- failure --> E E -- success --> S3["return factor, floor candidate"] E -- failure --> N["return None, 1.0"] N --> R["QQQ: configured fallback or LinAlgError;<br/>GPTQ: existing no-Hessian fallback"] style S fill:#d1e7dd,stroke:#0f5132,color:#0f5132 style S2 fill:#d1e7dd,stroke:#0f5132,color:#0f5132 style S3 fill:#d1e7dd,stroke:#0f5132,color:#0f5132 style N fill:#f9d5d5,stroke:#af3b3b,color:#222 style R fill:#f9d5d5,stroke:#af3b3b,color:#222recover_damped_hessian_factor,try_factor,damp_auto_increment,QQQ._quantize_impl,GPTQ.hessian_inverse).docs/repeats the diagram and is alreadylinked from
README.mdvia the quantizer calibration flows link.Review Requirements
I or an AI agent (such as Codex or Claude) have:
Notes
hessian_inversenow resolvesnpu_block_sizeonly when the Hessianis on an NPU, matching the old lazy lookup.
leaves the applied damping in
H;His released before the block passeither way.
test_qqq_numerical_failure_does_not_retry_on_cpureplaces aone-shot
torch.linalg.choleskyfailure with an always-indefinitecholesky_ex: with recovery enabled, a one-shot failure is expected to berecovered, so it no longer proves the no-CPU-fallback contract.