fix(rotation): persist rotation config and apply online Hadamard for inference and calibration - #2980
Merged
Merged
Conversation
…inference Cherry-pick/adapt from GPT-QModel-Ultra#66: - Persist in and round-trip via . - Fuse exact Hadamard into weights during rotation. - Add JIT Hadamard extension in (vendored from Dao-AILab/fast-hadamard-transform, BSD-3-Clause) plus . - Attach // to QuantLinear modules at and after . Restrict rotation to /. - Call in and . - Disable when is enabled. - Add and README/MANIFEST attribution/license.
…g, version, and attributions
🤖 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:
|
…down_proj - Extract apply_online_hadamard so HookedLinear and BaseQuantLinear share the same transform. - rotate_mlp_output now sets online_full_had/had_K/K on the nn.Linear before it becomes HookedLinear. - HookedLinear.from_linear copies rotation state and forward applies H to the activation used for GPTQ calibration. - Add unit test verifying HookedLinear cancellation and hook input transform.
devin-ai-integration
Bot
force-pushed
the
devin/cherrypick-rotation
branch
from
July 25, 2026 08:03
98de772 to
d192083
Compare
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
Cherry-pick/adapt the rotation persistence + online-Hadamard work from GPT-QModel-Ultra#66, plus a calibration fix. The original inference-only fix caused a
gsm8k_platinumregression becausemlp.down_projweights contained the fused HadamardHwhile GPTQ was still calibrating on the rawdown_projinputm. This PR makesHookedLinearapply the same online Hadamard during calibration/replay so the GPTQ Hessian matches the inference activation distribution.What Changed
QuantizeConfigemits/round-tripsrotationinquantize_config.json.rotate_mlp_outputfuses a full exact Hadamard intomlp.down_projweights and now storesonline_full_had/had_K/Kon thenn.Linearso the state survives theHookedLinearconversion used during GPTQ.apply_online_hadamard(...)ingptqmodel/quantization/rotation/hadamard_utils.py;BaseQuantLinear._apply_rotation_to_inputandHookedLinear.forwardboth call it.HookedLinear.from_linearcopies rotation state from the sourcenn.Linear.TorchLinear._forwardandTritonV2Linear.forwardcall_apply_rotation_to_inputbefore the quantized matmul.BaseGPTQModel.quantize()/from_quantized()attach online-Hadamard state tomlp.down_projand reject rotation for unsupported backends.BaseQuantizeConfigdisablesoffload_to_diskwhenrotationis set (rotation needs materialized weights).tests/test_rotation_persistence.pyverifies config round-trip, online-state setup, forward routing, Hadamard cancellation, andHookedLinearcalibration-path cancellation.return xflagged by code-quality review.Tests
Full-dataset
Evalutionon Llama-3.2-1B-Instruct (4-bit GPTQ,rotation='hadamard') against a non-rotated 4-bit baseline and a dense BF16 reference:acc,numacc,examThe rotated model recovers the
gsm8k_platinumregression and scores between the dense reference and the non-rotated baseline;arc_challengeis unchanged within noise.Review Requirements
Notes
The JIT
fast_hadamard_transformextension is vendored from Dao-AILab/fast-hadamard-transform (Tri Dao, BSD-3-Clause) undergptqmodel_ext/hadamard/and only used by thegptq_torch/gptq_tritonbackends.