tensorflow / tensorflow

An Open Source Machine Learning Framework for Everyone
https://tensorflow.org
Apache License 2.0
186.21k stars 74.29k forks source link

Wrong gradient from complex determinant #49946

Open ramonpeter opened 3 years ago

ramonpeter commented 3 years ago

System information

Describe the current behavior I implemented a straightforward example which illustrates the issue: I have a 2-dimensional tensor which is mapped to a complex tensor as:

x_i -> z_i = (x_i, lamb_i * x_i)

with some real values for lambda = [lambda_1, lambda_2]. Afterwards I calculate the Jacobian (with respect to x) and its determinant, which is also easy to do as it is just a 2x2 matrix. In the end, I take |det|^2 as final output L.

Analytically, you would now get for the gradient: grad L = [ 2 lambda_1 (1+lambda_2^2), 2 lambda_2 (1+lambda_1^2)

So if you insert lambda_test = [ 1.0 , 2.0] You should obtain: grad L(lambda_test) = [ 10, 8]

However, Tensorflow yields: TF-Grad = [-14, -8.8], which obviously is completely off.

Additionally, we also implemented a simple numerical derivative ourselves (just the basic definition of the gradient in terms of difference quotient). This calculation does yield the correct gradient (within numerical uncertainties)

Standalone code to reproduce the issue The issue can be reproduced in this gist.

tilakrayal commented 3 years ago

@jvishnuvardhan , I was able to reproduce the issue in tf v2.4,v2.5 and nightly.Please find the gist of it here. Issue is still replicating in 2.9.0. Thank you!

ramonpeter commented 3 years ago

Is there any new insight in what is going wrong?

ramonpeter commented 2 years ago

Just as an update: The issue stills persists in tf v.2.8

tilakrayal commented 3 weeks ago

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.

github-actions[bot] commented 2 weeks ago

This issue is stale because it has been open for 7 days with no activity. It will be closed if no further activity occurs. Thank you.

ramonpeter commented 2 weeks ago

I tested my gist again with the latest tensorflow version and it still gives the same ill-behaviour. So the bug is still there.