Make index autodiff errors explicitly recommend stop_gradient#3820
Open
dogukanveziroglu wants to merge 6 commits into
Open
Make index autodiff errors explicitly recommend stop_gradient#3820dogukanveziroglu wants to merge 6 commits into
dogukanveziroglu wants to merge 6 commits into
Conversation
zcbenz
reviewed
Jul 9, 2026
zcbenz
left a comment
Collaborator
There was a problem hiding this comment.
Looks good to me, thanks! I think it makes sense also adding the error message to masked ops.
6868aa9 to
4715c89
Compare
Contributor
Author
|
Force pushed for fixing my author signature. Plus fixing the CI issue. |
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.
Based on the discussion in #3612 and the closing note in #1439, this makes gather match the other index-based ops, if gradients reach index arguments, users now get an explicit error asking them to use
mx.stop_gradientinstead of getting a silent zero VJP.I also updated the related error messages and added small regression tests for both the error case and the intended workaround. (Tests might be unnecessary so I can trim them if you want)
This actually happens on mask VJP error messages too. I didn't add them on this PR but I can add a similar
stop_gradienton there too.