Skip to content

fix: sanitize padded rows in the PointSolver implicit-diff rule for reverse mode - #685

Merged
Jammy2211 merged 1 commit into
mainfrom
feature/point-solver-padded-row-grads
Aug 1, 2026
Merged

fix: sanitize padded rows in the PointSolver implicit-diff rule for reverse mode#685
Jammy2211 merged 1 commit into
mainfrom
feature/point-solver-padded-row-grads

Conversation

@Jammy2211

Copy link
Copy Markdown
Collaborator

Part of #678 phase B — one of the two defects that killed the cluster image_plane_solved gradient cell on the A100s (the other is PyAutoLabs/PyAutoFit — traced values leaking into pytree aux).

Problem

solve_padded_jvp zeroed 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

  • Padded rows are anchored at the first real solved image (finite Jacobian; contribution still exactly zeroed by the masking).
  • implicit_tangents_from sanitizes the solve inputs on non-finite rows only (identity a_mat, zero rhs) 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

  • New numpy unit test: NaN padded rows never reach the solve; finite rows unchanged.
  • Full test_autolens/ suite: 507 passed.
  • Local CPU repro of the failing cluster cell: before the fix 0/8 random draws had finite gradients; after, 8/8 — with byte-identical FOMs (forward path untouched).

🤖 Generated with Claude Code

https://claude.ai/code/session_01DnTmLoJjJgMTze5uAbg1Jd

…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
@Jammy2211
Jammy2211 merged commit cb937d8 into main Aug 1, 2026
3 checks passed
@Jammy2211
Jammy2211 deleted the feature/point-solver-padded-row-grads branch August 1, 2026 12:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant