Repository navigation
fix(gptq): stop holding the task Hessian across g.quantize() (#5026) - #5043
Merged
Merged
Conversation
…oud#5026) `GPTQProcessor.process()` bound the task's Hessian to a local `g_h` for a device assert and then called `g.quantize()` while that local was still alive. GPTAQ/FOEM release the Hessian themselves (`H = self.H; del self.H`) and rebind `H` to the activation-order permuted copy, so the surviving local kept the original unpermuted `[C, C]` fp32 tensor alive for the whole quantize -- including the peak where `H`, `dXXT` and the inverse are all live. That is 784 MiB per dense Hessian on an 8B down_proj (C = 14336), 1.25 GiB at C = 18432. Drop the local right after the assert. Measured by the issue on a 4-layer Llama-3.1-8B: GPTAQ peak 6280 -> 5496 MiB, FOEM 5472 -> 4688 MiB, GPTQ unchanged, and all 123 checkpoint tensors bitwise identical. Regression test: `tests/test_gptq_processor_hessian_lifetime_5026.py` runs the real `process()` preamble and stops inside `quantize()`, where it records the strong-reference count of the task Hessian. The task itself is one reference; the fix leaves exactly that (2 with `getrefcount`'s argument), the parent commit leaves 3.
Qubitium
added a commit
that referenced
this pull request
Nov 18, 2026
#5040 made `process()` call `task.release_hessian_state()` when `quantize()` raises; #5043's probe double predates that helper, so the probe fails with AttributeError instead of measuring the reference count. That leaves `tests/test_gptq_processor_hessian_lifetime_5026.py` red on main after #5047 removed the stale `del g_h`. Give the double a no-op hook.
This was referenced Nov 18, 2026
Qubitium
added a commit
that referenced
this pull request
Nov 18, 2026
) #5040 made `process()` call `task.release_hessian_state()` when `quantize()` raises; #5043's probe double predates that helper, so the probe fails with AttributeError instead of measuring the reference count. That leaves `tests/test_gptq_processor_hessian_lifetime_5026.py` red on main after #5047 removed the stale `del g_h`. Give the double a no-op hook.
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
GPTQProcessor.process()bound the task's Hessian to a localg_hfor a device assert and then calledg.quantize()while that local was still alive:GPTAQ/FOEM release the Hessian themselves (
H = self.H; del self.H,gptaq.py:450-451,foem.py:502-503) and then rebindHto the activation-order permuted copy. The surviving local kept the original unpermuted[C, C]fp32 tensor alive for the whole quantize — including the peak, whereH,dXXTand the inverse are all live.Closes #5026.
Fix
Drop the local right after the assert. One line plus the comment explaining why; no behavior change.
Measured by the issue (4-layer Llama-3.1-8B, 64 C4 rows):
The saving is
4*C^2bytes per module with a dense Hessian: 784 MiB on an 8B down_proj, 1.25 GiB at C = 18432.Tests
New
tests/test_gptq_processor_hessian_lifetime_5026.pyruns the realprocess()preamble and stops insidequantize(), where it records the strong-reference count of the task Hessian. The task itself is one reference; the probe allows exactly that (2 includinggetrefcount's own argument).Related GPTQ/GPTAQ coverage:
python -m pytest tests/test_gptaq_foem_batch.py tests/test_gptq_keep_mask_device.py -q # 12 passed, 3 skippedruff checkon the processor and the new test: All checks passed.Logic Flow Documentation
Not applicable: a local's lifetime changed; the flow is unchanged.
Model Support / Module Plan
Not applicable: no definition or plan change.