-
Notifications
You must be signed in to change notification settings - Fork 74k
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
Wrong gradient in forward mode auto differentiation for tf.random.stateless_parameterized_truncated_normal
#56842
Comments
@eeDigitalSeal,
The |
Thanks @tilakrayal for your reply. I still don't get it why the code I provided give different gradient in forward mode and backward mode. I can see you changed the
But I think this |
@gowthamkpr, |
@eeDigitalSeal The issue here is that You'll get a correct answer if you increase the precision to |
@cantonios Thanks for your reply. But If I change the input dtype to tf.float64, this API would throw the following error. It seems that it only accepts float tensors as input.
And I think if backward gradient hits a NaN, it should give the original NaN value rather than handle it silently inside the framework? |
Click to expand!
Issue Type
Bug
Source
binary
Tensorflow Version
tf 2.9
Custom Code
Yes
OS Platform and Distribution
Linux Ubuntu 20.04
Mobile device
No response
Python version
3.9
Bazel version
No response
GCC/Compiler version
No response
CUDA/cuDNN version
No response
GPU model and memory
No response
Current Behaviour?
Jacobian matrix elements are not equal in forward mode and backward mode with the same input.
Standalone code to reproduce the issue
import tensorflow as tf import numpy as np shape = [2, 3] seed = [7, 17] means = 13.0 stddevs = tf.constant([[0.8059583, 0.09676647, 0.08382106], [0.8149866, 0.44204712, 0.5636599]], dtype=tf.float32) minvals = [-1.0, -2.0, -1000.0] maxvals = [[10000.0], [1.0]] name = None with tf.GradientTape(persistent=True, ) as g: g.watch(stddevs) tf.random.set_seed(42) res_backward = tf.random.stateless_parameterized_truncated_normal(shape, seed, means=means, stddevs=stddevs, minvals=minvals, maxvals=maxvals, ) # shape=(2,3,2,3) jacobian = g.jacobian(res_backward,stddevs) print(jacobian[0][1]) tangents = tf.constant([[0.,1.,0.], [0.,0.,0.]],shape=(2,3),dtype=tf.float32) with tf.autodiff.ForwardAccumulator(stddevs,tangents) as acc: res_forward = tf.random.stateless_parameterized_truncated_normal(shape, seed, means=means, stddevs=stddevs, minvals=minvals, maxvals=maxvals, ) print(acc.jvp(res_forward))
Relevant log output
The text was updated successfully, but these errors were encountered: