Repository navigation
fix(autograd): stop ops::reshape from doubling gradients - #4
Merged
BESTTOOLBOX merged 1 commit intoOct 15, 2026
Merged
Conversation
Tensor::reshape already registers ReshapeBackward for its result with the new autograd engine. ops::reshape then registered it a second time, and Engine::register_node appends edges, so the input received the gradient twice. LoRALinear reshapes the LoRA output, so both LoRA gradients were doubled. This is the LoRAStepAlignment failure that every operator CI run has shown since June (grad_A max_abs_diff=0.30073). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
4 tasks
This was referenced Oct 14, 2026
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
Fixes #5.
With the default autograd engine (
USE_NEW_AUTOGRAD_ENGINE=ON),ops::reshaperegistered aReshapeBackwardnode thatTensor::reshapehad already registered for the same result.Engine::register_nodeappends edges, so every input passed throughops::reshapereceived its gradient twice.LoRALinearreshapes the LoRA output, so both LoRA gradients (A and B) were exactly 2×. This is theLoRAStepAlignmentfailure that every operator CI run has shown since June:The fix removes the duplicate registration under the new engine. The legacy-engine path is unchanged, since it overwrites
grad_fninstead of adding an edge.Impact
Correction: an earlier version of this description said Adam-trained runs were "probably only slightly affected". That was wrong.
ops::reshapecalls.Full analysis and reproduction: #5.
Testing
On macOS:
Result:
100% tests passed out of 29, includingLoRAStepAlignment. On the base branch, 28/29 pass, with the failure above.PR #3 (
codex/kto-bounded-memory) fails CI for the same pre-existing reason. It will pass once this merges and #3 is rebased.🤖 Generated with Claude Code