Skip to content
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

Possible bug in eigh derivative (for non-degenerate eigenvalues). #10527

Closed
sschoenholz opened this issue May 2, 2022 · 3 comments
Closed

Possible bug in eigh derivative (for non-degenerate eigenvalues). #10527

sschoenholz opened this issue May 2, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@sschoenholz
Copy link
Contributor

We stumbled across an error in the gradient when using eigh without any degenerate eigenvalues. Here is a simple repro (tested in Google colab with JAX version 0.3.4).

import jax.numpy as jnp
import jax.test_util as jtu

def fn(x):
  A = x[:, None] * x[None, :]
  _, U = jnp.linalg.eigh(A)
  return U @ x

x = jnp.array([1.0, 2.0, 3.0])
print(x[:, None] * x[None, :])  # Symmetric matrix.

print(fn(x))  # Reasonable output 

jtu.check_grads(fn, (x,), 1)

"""
AssertionError: 
Not equal to tolerance rtol=0.006, atol=0.006
JVP tangent
Mismatched elements: 3 / 3 (100%)
Max absolute difference: 5823.4707
Max relative difference: 1.0003492
 x: array([ 1.707243,  0.97609 , -1.043212], dtype=float32)
 y: array([ 2682.228 , -5822.4946,  2987.9426], dtype=float32)
"""
@sschoenholz sschoenholz added the bug Something isn't working label May 2, 2022
@YouJiacheng
Copy link
Contributor

YouJiacheng commented May 2, 2022

Why you said that a rank-1 3×3 matrix is "without any degenerate eigenvalues"?
For the title "eigh derivative for non-degenerate eigenvalues", I guess you might want to have well defined gradient with the part of eigenvalues which are not degenerate?
It seems that only the case that all eigenvalues is not degenerate is implemented.
https://github.com/google/jax/blob/44006c7e5c7032a5560a9bd62394034ea42ce3da/jax/_src/lax/linalg.py#L550-L558

@jakevdp
Copy link
Collaborator

jakevdp commented May 2, 2022

Hi - this looks like it does have degenerate eigenvalues (the eigenvalues are [0, 0, 14]) I think that in this case the gradient is not well defined - see the discussion in #669

@sschoenholz
Copy link
Contributor Author

Oops you're right! Hmm, back to the repro drawing board... this case is definitely degenerate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants