-
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
tf.dynamic_stitch
gradient is incorrect
#7397
Comments
Ug. You're correct that the gradients are wrong, but I don't see how to fix it without a dramatic performance hit. Do you have any suggestions? |
Addresses tensorflow#7397 Also expanded unit tests to cover these cases.
Addresses tensorflow#7397 Also expanded unit tests to cover these cases.
Addresses tensorflow#7397 Expanded unit tests to cover these cases.
Addresses tensorflow#7397 Expanded unit tests to cover these cases.
Addresses tensorflow#7397 Expanded unit tests to cover these cases.
Addresses tensorflow#7397 Expanded unit tests to cover these cases.
Addresses tensorflow#7397 Expanded unit tests to cover these cases.
Automatically closing due to lack of recent activity. Please update the issue when new information becomes available, and we will reopen the issue. Thanks! |
The bug still exists, meaning that the |
Let's leave this open. Anyone interested should refer to the comments in #7487. The next step would have been to add a new C++ kernel to speed up the bookkeeping required by accurate gradients. |
Can we close this? |
The gradient implementation is still incorrect, as of TF 2.5.0rc. Here is an updated example showing the same error import tensorflow as tf
x = tf.zeros((1, 3))
analytic, numeric = tf.test.compute_gradient(
lambda x: tf.dynamic_stitch([[0], [0]], [x, tf.ones((1, 3))]), [x]
)
print("analytic")
print(analytic)
print("numeric")
print(numeric) gives
|
/cc @rthadur Can we update the label? |
I was able to replicate issues in |
Hi @drasmuss ! If we use two different indices like [0] , [1] or [0],[2] then results for analytical and theoritical from test.comput_gradient is same. Attached gist for reference. Thank you! |
Yes, this bug is caused by having duplicate indices. But that is defined and supported behaviour for dynamic stitch (e.g., see the documentation):
|
Ok @drasmuss ! |
I was able to reproduce this issue in TF Nighly 2.12.0-dev20221218. Please find the gist here. Thank you. |
I was able to replicate this issue in TF Nighly 2.13.0-dev20230419. Please find the gist here. Thank you. |
Hi, Thank you for opening this issue. Since this issue has been open for a long time, the code/debug information for this issue may not be relevant with the current state of the code base. The Tensorflow team is constantly improving the framework by fixing bugs and adding new features. We suggest you try the latest TensorFlow version with the latest compatible hardware configuration which could potentially resolve the issue. If you are still facing the issue, please create a new GitHub issue with your latest findings, with all the debugging information which could help us investigate. Please follow the release notes to stay up to date with the latest developments which are happening in the Tensorflow space. Thank you! |
This bug is still present in TensorFlow 2.16.1. The code from #7397 (comment) is still valid, and reproduces the bug. I have edited that into the original post for clarity. |
If possible, provide a minimal reproducible example (We usually don't have time to read hundreds of lines of your code)
Original reproduction code (TensorFlow 1.0)
Updated reproduction code (TensorFlow 2.16)
gives output
The numeric gradient correctly shows that
x
has no impact ony
(since the value ofx
is completely overwritten by a constant in thedynamic_stitch
). The analytic gradient is incorrect; it seems like the gradient calculation indynamic_stitch
does not handle the case where there are duplicate indices being merged.The text was updated successfully, but these errors were encountered: