Gradient of QR fails
See original GitHub issueThere seems to be a major bug in the gradient of the QR decomposition. The forward-mode derivative is accurate for Q but very far off for R. There also seems to be no check in the tests making sure the gradient is accurate.
This reproduces the error:
import jax
import jax.numpy as jnp
import numpy as np
x = np.random.randn(3, 3)
dx = np.random.randn(3, 3)
primals, tangents = jax.jvp(jnp.linalg.qr, (x,), (dx,))
q, r = primals
dq, dr = tangents
dt = 1e-6
dq_ = (np.linalg.qr(x + dt * dx)[0] - np.linalg.qr(x)[0]) / dt
dr_ = (np.linalg.qr(x + dt * dx)[1] - np.linalg.qr(x)[1]) / dt
assert jnp.allclose(x, q @ r, atol=1e-5, rtol=1e-5) # passes
assert jnp.allclose(dq, dq_, atol=1e-5, rtol=1e-5) # passes
assert jnp.allclose(dx, q @ dr_ + dq_ @ r, atol=1e-5, rtol=1e-5) # passes
assert jnp.allclose(dr, dr_, atol=1e-5, rtol=1e-5) # fails
Issue Analytics
- State:
- Created 3 years ago
- Comments:23 (23 by maintainers)
Top Results From Across the Web
Scanning QR code with color gradient - Apple Developer
When scanning a QR code with Apple's camera app, it has no problem scanning the QR code that has a color gradient. But...
Read more >Problems adding Qr field in externalWallHeatFluxTemperature ...
The problem is that the solver usually crashes when Qr is added to the patch's balance, I don't know why, I'm actually testing...
Read more >Qr Code Gradients - Osiset
This created a problem… how do I create a gradient on the Qr code? I came up with a solution: colorize the Qr...
Read more >8. Least squares
the problem is also called the linear least squares problem. Least squares ... gradient of is ... rewrite least squares solution using QR...
Read more >Conjugate Gradient Method - Stanford University
same as direct methods. • get advantage over dense if matrix-vector multiply is cheaper than n2. • with roundoff error, CG can work...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks. Yes, I saw the derivation, and checked it manually. The problem is perhaps deeper than the derivation itself and has more to do with something weird happening in the back end if the exact same function implemented as a jvp rule for a primitive gives different results than executing the bare function.
On Tue, Apr 28, 2020, 10:18 AM Jamie Townsend notifications@github.com wrote:
Thanks! And glad this was able to flush out the testing rng seed issue!