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
Support of gradient for TF.MOD #6365
Comments
@ops.RegisterGradient("Mod") |
I would like to use In order to test the above solution, must I rebuild Tensorflow from source? I'm currently using 0.12.0rc1. Edit - Instructions for registering a gradient function can be found here: https://www.tensorflow.org/how_tos/adding_an_op/#implement_the_gradient_in_python |
@kleinma For Python-only changes such as above, you need not rebuild TensorFlow from source |
I'm not sure if mod in models is well-defined enough to know what the gradient should be in all cases. The angle case makes sense, but lots of uses of mod (binning, etc) are inherently discontinuous, certainly with integers. @girving, do you think we should provide a default mod gradient, or just let people override them appropriately for their application when they see this error? |
The gradient of mod is zero a.e., so it's TensorFlow gradient is zero everywhere. We should definitely define a zero gradient (returning None). |
@aselle Unassigning myself since I'm on leave. |
Any news guys? @girving |
Wait a sec guys! The gradient of tf.mod(x, y) w.r.t x is 1, except for x / y = integer where it is not defined... but since these points are a set of measure zero, the gradient should always be one (?). Gradient of int division (//) or floor is of course zero... One plot says it all:
Anyway, looking forward for the gradients! |
Ah, thought we were talking about integer mod, which has no gradient. Yes, float mod has gradient 1 w.r.t. x a.e., and also an a.e. defined gradient w.r.t. y. |
OK actually I just assumed tf.mod = % but didn't think about it further... |
@yuefengz Can you take a look? |
That stackexchange link is very helpful. I will implement the gradient function. |
@yuefengz thanks! |
@yuefengz any updates on your part? |
@yuntatsai is working on a change, we will check it soon. Thanks for your patience. |
Hello there,
When I include
tf.mod
in my Graph, I have this error:LookupError: No gradient defined for operation 'RNN/while/LSTM/Mod' (op type: Mod)
Will it be handled in the future?
Thanks!
References: https://www.tensorflow.org/api_docs/python/math_ops/arithmetic_operators#mod
Tensorflow version:
0.12.0-rc1
The text was updated successfully, but these errors were encountered: