-
Notifications
You must be signed in to change notification settings - Fork 26.3k
clamp now has subgradient 1 at min and max #7049
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm. Add a test maybe (and comments!), if someconfused soul reverts this?
tools/autograd/derivatives.yaml
Outdated
| self: grad * ((self >= min) * (self <= max)).type_as(grad) | ||
|
|
||
| - name: clamp_min(Tensor self, Scalar min) | ||
| self: grad * (self > min).type_as(grad) |
This comment was marked as off-topic.
This comment was marked as off-topic.
Sorry, something went wrong.
|
Yes, this subtle formula tweak definitely merits a comment. A link to the issue is a good start, and maybe something like "Gradient is not defined at the boundaries, but empirically it's helpful to be able to get gradient on min and max." EDIT: And perhaps it points its way to a more general principle: if you need to return the gradient at a nondifferentiable point, and you have |
apaszke
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree a comment would be nice. @ezyang I don't think we should commit to that principle. We could use it to guide some choices, but I don't want to have ops that will have to do an extra pass to check for boundary conditions and fill the gradients if it's expensive.
* subgradient 1 at min and max for clamp * clamp max and clamp min too * add comment
* subgradient 1 at min and max for clamp * clamp max and clamp min too * add comment
addresses #7002