Fix clip backward with broadcasted constant bounds - #2089
Open
Robertboy18 wants to merge 3 commits into
Open
Conversation
Signed-off-by: Robert joseph <robujsph2001@gmail.com>
Contributor
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe clip backward validation now permits broadcastable non-learnable bounds. A CPU test verifies forward outputs and input gradients against native PyTorch operations. ChangesBroadcastable Clip Bounds
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 6✅ Passed checks (6 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
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.
What does this PR do?
Type of change: Bug fix
Hey! I was experimenting with formalizing the clipping backward rule in Lean using TorchLean, and noticed a small discrepancy here.
ClipFunction.forwardsupports broadcastable tensor bounds, butbackwardraises the scalar-only error even when those bounds are constants and do not need gradients.This keeps the scalar restriction for learnable bounds, while allowing constant tensor bounds to broadcast normally. I also added a CPU regression test that compares both the output and input gradient against the equivalent PyTorch min/max operations.
I modeled the coordinatewise broadcasted input VJP in Lean as well and kernel-checked the result. The formalization is not included in this PR, but I'm happy to share it if useful :)
I used a bit of AI assistance during the investigation and debugging, then manually checked the code, tests, and Lean statement/results.
Usage
Testing
Before your PR is "Ready for review"
CONTRIBUTING.md: N/ASummary by CodeRabbit
Bug Fixes
Tests