fix(qqq): per-device Hessian partials for balanced multi-GPU calibration#2979
Merged
Conversation
QQQ.add_batch previously accumulated a single H tensor on self.dev, which failed when balanced calibration placed module replicas on different GPUs. - Add per-device Hessian partials and a thread-safe accumulate step, mirroring the GPTQ path. - Materialize the global Hessian at quantize time from the merged partials, scaling by 2 / total_token_count (matching GPTQ math). - Add QQQ to ModelTest's post-quant validation backend dispatch. - Introduce tests/models/test_llama3_2_qqq.py with fast-mode arc/gsm8k baselines. Fixes #2115.
🤖 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
QQQ.add_batchkept a singleself.Htensor onself.dev. Under thebalancedcalibration data placement used by MoE models, module replicas run on different GPUs and deliver activations on those devices, so the old code crashed with a multi-device tensor error insideadd_batch(#2115).This change makes QQQ accumulate per-device Hessian partials under a lock and merge them into the global Hessian at
quantize()time, matching the existing GPTQ path. It also fixes thensamplesaccounting to count total token vectors instead of batch count, which aligns QQQ'sH = (2 / n) Σ x xᵀscaling with GPTQ math.What Changed
gptqmodel/quantization/qqq.pythreading.Lock, per-device_device_hessian_partials, and_device_sample_counts.add_batchto computextx = X Xᵀon the activation's device and accumulate it under the lock.materialize_hessian()to merge partials, move them toself.dev, and scale by2 / total_samples.quantize()now callsmaterialize_hessian()before Cholesky.free()clears the per-device partial dictionaries.tests/models/model_test.pyFORMAT.QQQtoperform_post_quant_validationbackend dispatch so QQQ post-quant evaluation loads withBACKEND.QQQinstead of falling through to the MARLIN/GEMM default.tests/models/test_llama3_2_qqq.py(new)test_llama3_2.pywith fast-mode arc/gsm8k baselines for Llama-3.2-1B-Instruct.Tests
Paste the exact test commands and results here:
Fixes #2115.
Review Requirements