Repository navigation
Fix zero-adjoint SVD gradients (GH-2054) - #2064
fusheng-ji wants to merge 2 commits into
Conversation
|
No actionable comments were generated in the recent review. Summary
Change: Bug fix · Severity of issue fixed: Medium Merge Risk:
|
[Medium impact] The PR appears safe to merge. SummaryAdds zero-gradient shortcuts to SVD backward calculations so unused singular vectors do not introduce NaNs.
No actionable issues found. Tests were not run during this review. Reviews (4) · Last reviewed commit: "Merge branch 'main' into fusheng-ji/fix-..." · Reviewed by Greptile |
Inactive singular-vector derivatives can overflow in half precision and contaminate independent gradients. Skip those derivatives when their adjoints are exactly zero while retaining gradient accumulation and the general SVD adjoint. Signed-off-by: Wenbo Ji <[email protected]>
091d1e8 to
733930d
Compare
What problem are you trying to solve?
Closes #2054.
With half-precision
wp.svd2()andwp.svd3(), differentiating the squared singular-value norm ofA = 2Iproduces NaN input gradients instead of approximately4I. An unused SVD diagnostic on the same tape can also change the gradient of an independenttrace(A)loss fromIto NaN.The adjoint evaluates inverse squared-singular-value gaps even when singular-vector adjoints are zero. At repeated singular values, the regularized reciprocal overflows in half precision, and multiplication by zero introduces NaNs.
This is an independent correctness investigation; I do not currently have downstream application or production impact to report. Outside-implementation guidance has been requested in #2054; no maintainer assignment or approval is claimed.
What does this change?
U * diag(adj_sigma) * transpose(V)into the input adjoint.Public signatures, forward implementations, epsilon values and the general nonzero U/V adjoint formula are unchanged. This is independent of the SVD3 forward fix in #2063 and does not address the general repeated-spectrum findings in #2030.
Existing pull requests
svd2andsvd3produce NaN gradients for singular-value-only losses #2054 was found.Validation
Current source
733930ddf3ebe55f422cf1fbd7b59be2029ec15d, a single signed-off commit on official main0382a97e2c72911c1f6bba45274e12833a19d8e2. The previous merged head091d1e84has been replaced; the focused patch still contains onlysvd.h, the existing matrix tests and2054.fixed.md.uv run build_lib.py, exit 0. The loaded native libraries were built in this checkout; source cleanliness and library SHA256 hashes are recorded.git diff --checkpassed. Complete sanitized build/test output, commands and exit codes are published.Current report · Validation metadata · Environment and library hashes · SVD test log · Full matrix log · Build log · Checksums
Current numerical results
The standalone script covers two dimensions, two calling forms, five scenarios, three batch elements, three dtypes and three devices: 540 API/scenario/seed evaluations on
A = 2I, not independent random matrices. References are computed in NumPy float64 from actual inputs; an evaluation passes only when both loss and gradient are finite and within tolerance. The published CSV references and pass flags were also independently recomputed.The allowance is
atol + rtol * abs(expected); both tolerances are1e-2,1e-5and1e-10for FP16, FP32 and FP64. The FP16 residual is retained in the data.Per-evaluation CSV · Per-device summary · Measurement script · Reproduction commands · Plot script
Historical comparison
The unchanged assets at
40f663c6comparec47fe4c8(before) withe6185ac3(after), with 540 evaluations per revision: 144 FP16 failures before, zero failures after. Those measurements were not rerun as a new baseline here. The earlier baseline unit-test failure counts have no located original log and are not presented as verified conclusions; the current 78/295 test counts above are backed by complete fresh logs.Historical report · Before CSV · After CSV · Historical summary figure
Current evidence links are pinned to asset commit
8a23e20cccb4c3aebec2601ce7246e0603f73bde. Historical links remain pinned separately.Checklist
mainand contains one commit, unless a maintainer agreed to keep the change as multiple commits.+prefix only for changes that do not require a GitHub issue.