fix: sanitize padded rows in the PointSolver implicit-diff rule for reverse mode - #685
Merged
Merged
Conversation
…everse mode Padded sentinel rows were zeroed to (0, 0) before the Jacobian evaluation — exactly where cluster profile centres sit, and an NFW's deflection Jacobian at its own centre is NaN. The forward tangent masks padded rows, but reverse mode transposes the rule into row-summed cotangents, so one NaN padded row poisoned every parameter's gradient (all-NaN grads in the #678 phase B cluster image_plane_solved cell; galaxy-scale cells were unaffected). Padded rows are now anchored at the first real solved image and the solve inputs are sanitized (identity a_mat, zero rhs) on non-finite rows only — legitimate near-critical divergence on real rows is still surfaced. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DnTmLoJjJgMTze5uAbg1Jd
This was referenced Aug 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #678 phase B — one of the two defects that killed the cluster
image_plane_solvedgradient cell on the A100s (the other is PyAutoLabs/PyAutoFit — traced values leaking into pytree aux).Problem
solve_padded_jvpzeroed padded sentinel rows to(0, 0)before evaluating the deflection Jacobian. Cluster profile centres sit at the origin, and an NFW's deflection Jacobian at its own centre is NaN. The forward tangent masks padded rows, so forward mode is clean — but reverse mode transposes the implicit rule into row-summed cotangents (ct_dbeta = Σ rows), so a single NaN padded row poisoned the gradient of every parameter. Result: all FOMs finite, all gradients NaN, on every draw of the cluster cell. Galaxy-scale cells never hit it.Fix
implicit_tangents_fromsanitizes the solve inputs on non-finite rows only (identitya_mat, zerorhs) so NaN can never enter the linear algebra in either mode. Real rows untouched — near-critical divergence is still surfaced, per the module's contract.Verification
test_autolens/suite: 507 passed.🤖 Generated with Claude Code
https://claude.ai/code/session_01DnTmLoJjJgMTze5uAbg1Jd