You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
eig3 produces NaN gradients for eigenvalue-only loss at repeated eigenvalues #2010
Differentiating the sum of wp.eig3()'s eigenvalues produces NaN input gradients for diag(2,2,3) on both CPU and CUDA. The forward loss is finite.
Expected behavior
For a symmetric matrix, the sum of its eigenvalues is its trace. The input gradient should therefore be the identity matrix for both inputs below, including the one with repeated eigenvalues.
While working on a private project, I also encountered this issue. I noticed that its impact extends beyond eigenvalue-based losses: even a loss that does not depend on the eigendecomposition at all can have its gradient contaminated by an unrelated eig3() call recorded on the same tape.
For diag(2, 2, 3), differentiating trace(A) gives the expected identity gradient. Adding a separate eig3() diagnostic kernel to the same tape makes that gradient NaN, even though the diagnostic output is not used by the loss.
Without the diagnostic: loss 7, gradient is the identity matrix.
With the diagnostic: loss 7, all nine gradient entries are NaN.
The expected gradient is the identity matrix in both cases because the loss is unchanged. Unlike the original reproducer, this loss does not depend on either output of eig3(). The NaNs therefore also affect an otherwise valid, independent gradient when the decomposition is recorded only for diagnostics on the same tape. This broadens the impact beyond eigenvalue-based losses.
The backward pass now skips the eigenvector derivative when its incoming gradient is zero, avoiding singular eigenvalue-gap calculations while preserving the eigenvalue contribution and gradient accumulation. This fixes the reported eigenvalue-sum loss and prevents an unused eig3() diagnostic on the same tape from contaminating an independent trace-loss gradient. This issue is ready to close as completed.
Public API behavior
Both kernel overloads of wp.eig3() support smooth, permutation-invariant eigenvalue-only losses, including eigenvalue sums and sums of squares at repeated eigenvalues. Gradients through eigenvectors can still be unreliable at close or repeated eigenvalues; selecting an individual eigenvalue can also be nondifferentiable at a repeated eigenvalue.
Test coverage
warp/tests/matrix/test_mat.py adds analytical loss and gradient checks covering both overloads and float16, float32, and float64 on CPU and CUDA. Cases include distinct, repeated, closely spaced, rotated, negative, identity, and zero matrices, plus gradient accumulation.
Mixed batches check zero eigenvector gradients alongside small nonzero eigenvector gradients, with normalized checks that ensure those small contributions are preserved.
Behavioral verification
The original reproducer and the unused-diagnostic trace-loss reproducer both produced finite identity gradients on CPU and CUDA. All 30 focused eigen-decomposition tests passed.
Activity
moritzvii commentedon Oct 3, 2026
While working on a private project, I also encountered this issue. I noticed that its impact extends beyond eigenvalue-based losses: even a loss that does not depend on the eigendecomposition at all can have its gradient contaminated by an unrelated
eig3()call recorded on the same tape.For
diag(2, 2, 3), differentiatingtrace(A)gives the expected identity gradient. Adding a separateeig3()diagnostic kernel to the same tape makes that gradient NaN, even though the diagnostic output is not used by the loss.Minimal reproducer, saved as a Python file:
Observed with Warp
1.19.0.dev0:7, gradient is the identity matrix.7, all nine gradient entries are NaN.The expected gradient is the identity matrix in both cases because the loss is unchanged. Unlike the original reproducer, this loss does not depend on either output of
eig3(). The NaNs therefore also affect an otherwise valid, independent gradient when the decomposition is recorded only for diagnostics on the same tape. This broadens the impact beyond eigenvalue-based losses.Prevent eig3 NaNs from zero adjoints (NVIDIAGH-2010)
Prevent eig3 NaNs from zero adjoints (NVIDIAGH-2010)
Fix eig3 eigenvalue-only gradients [NVIDIAGH-2010]
shi-eric commentedon Oct 8, 2026
This is addressed by 109b6fa.
The backward pass now skips the eigenvector derivative when its incoming gradient is zero, avoiding singular eigenvalue-gap calculations while preserving the eigenvalue contribution and gradient accumulation. This fixes the reported eigenvalue-sum loss and prevents an unused
eig3()diagnostic on the same tape from contaminating an independent trace-loss gradient. This issue is ready to close as completed.Public API behavior
Both kernel overloads of
wp.eig3()support smooth, permutation-invariant eigenvalue-only losses, including eigenvalue sums and sums of squares at repeated eigenvalues. Gradients through eigenvectors can still be unreliable at close or repeated eigenvalues; selecting an individual eigenvalue can also be nondifferentiable at a repeated eigenvalue.Test coverage
warp/tests/matrix/test_mat.pyadds analytical loss and gradient checks covering both overloads and float16, float32, and float64 on CPU and CUDA. Cases include distinct, repeated, closely spaced, rotated, negative, identity, and zero matrices, plus gradient accumulation.Behavioral verification
The original reproducer and the unused-diagnostic trace-loss reproducer both produced finite identity gradients on CPU and CUDA. All 30 focused eigen-decomposition tests passed.