fix(qqq): accumulate Hessian in-place per device to reduce memory#2981
Merged
Conversation
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
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
Reduce QQQ quantization peak memory by avoiding a separate
columns x columnsxtxoutput tensor for every calibration batch and by freeing per-device Hessian partials as they are merged.Changes
QQQ.add_batch:calibration_data_device="balanced"/ multi-GPU MoE).float32.inp @ inp.t()directly into that buffer withaddmm_instead ofinp.matmul(inp.t())+add_.xtxtensor that is the same size as the Hessian for each batch.QQQ.materialize_hessian:popitem()anddel partialeach partial as it is added, so the peak during materialization isresult + one partialinstead ofresult + all partials.QQQ.quantize:diagindex tensor to live onH.deviceso the damping step is safe whenHhas been materialized on a different device fromself.dev.Validation
ruff check gptqmodel/quantization/qqq.py tests/test_qqq.pypasses.TestQQQHessianunit tests intests/test_qqq.pyverify thatadd_batch+materialize_hessianmatch the closed-form2/N * X^T Xreference for:cpu+cuda:0) accumulation,pytest tests/test_qqq.py::TestGroupSize::test_load_group_128 -vpassed on GPU 4.Closes memory-reduction follow-up for QQQ after #2115 / PR #2979.