Skip to content

Fix reverse AD through despecialized parameters - #1228

Merged
ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:codex/autodespecialize-reverse-ad
Sep 5, 2026
Merged

ChrisRackauckas merged 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:codex/autodespecialize-reverse-ad

Conversation

@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member

Please ignore this draft until it has been reviewed by @ChrisRackauckas.

What changed

Reverse-mode sensitivity calculations now unwrap DespecializedParameters before the inner adjoint solve and restore the wrapper-shaped cotangent at the outer AD boundary. Enzyme accumulation now follows structured non-tunable fields through that wrapper, while the Mooncake bridge converts the resulting nested NamedTuple cotangents into Mooncake forward/reverse data.

This is the NonlinearSolveBase companion needed by SciML/ModelingToolkit.jl#5062: that PR intentionally despecializes MTK initialization problems, which exposed the existing reverse-AD assumptions about concrete parameter layout. The separate #1226 addresses a prewrapped-function signature mismatch and does not handle these structured cotangents.

Regression evidence

Before this fix, SciMLSensitivity/test/Core8/desauty_dae_mwe.jl reported 13 pass, 4 errors, 5 broken: Enzyme and Mooncake could not propagate through the newly despecialized SCC initialization problems. After the initial exception paths were repaired, the same run reported 17 pass, 4 fail, 5 broken because all four SCC parameter gradients were zero. The new structured Mooncake regression test also failed before the final converter with:

ArgumentError: The fdata type @NamedTuple{values::Vector{Float64}}, rdata type Mooncake.NoRData, and tangent type @NamedTuple{values::Vector{Float64}} combination is not supported with @from_chainrules or @from_rrule.

With this change, the same downstream SCC test reports:

Test Summary:               | Pass  Broken  Total      Time
DAE with SCC Initialization |   21       5     26  14m26.0s

The five broken assertions predate this change and were not altered.

Verification

  • GROUP=Adjoint julia +1.12 --project=. -e 'using Pkg; Pkg.test()' — all three safe testsets passed: 6/6 Adjoint, 3/3 maybe_wrap_nonlinear_f, and 1/1 Enzyme reverse-mode.
  • julia +1.12 --project=test/Adjoint -e 'using Test; include("test/Adjoint/adjoint_tests__item1.jl")' — exit 0, including vector and nested structured AutoDespecialize gradients through Zygote and Mooncake.
  • julia +1.10 --project=test/Adjoint -e 'using Test; include("test/Adjoint/adjoint_tests__item1.jl")' — exit 0.
  • julia +1.12 --project=lib/NonlinearSolveBase -e 'using Pkg; Pkg.test()' — 366/366 assertions passed after developing the already-open SparseColumnPivotedQR fix described below; the new Enzyme accumulation test was 10/10.
  • GROUP=QA julia +1.12 --project=. -e 'using Pkg; Pkg.test()' — 28/28 passed with the same dependency fix developed.
  • julia +1.12 --project=. -e 'include("test/Core8/desauty_dae_mwe.jl")' in SciMLSensitivity with local ModelingToolkit and NonlinearSolveBase — 21 passed, 5 pre-existing broken.
  • SnoopCompileCore.@snoop_invalidations while loading NonlinearSolveBase, ChainRulesCore, and Mooncake — upstream and this branch are exactly equal at logedges=397, logmeths=8543.
  • julia +1.12 -m Runic --check <changed Julia files> — clean.
  • typos <changed files> — clean.
  • git diff --check — clean.

The unmodified dependency resolve currently fails before tests because AMD 0.5.4 removed the private AMD.SS_Int binding used by SparseColumnPivotedQR 2.1.7. This reproduces on clean NonlinearSolve master. The existing fix SciML/SparseColumnPivotedQR.jl#71 replaces that private access with public colamd; its CI is green, and developing it while retaining AMD 0.5.4 makes clean-master and this branch pass. The regression is tracked at SciML/SparseColumnPivotedQR.jl#72.

Review notes

The Mooncake method is deliberately restricted to ChainRulesCore.Tangent{SciMLBase.DespecializedParameters}. Mooncake documents increment_and_get_rdata! as the extension point when @from_chainrules cannot convert a tangent combination; a broad NamedTuple method here would be type piracy beyond this package's wrapper.

I did not run GROUP=Everything, GPU jobs, downstream packages beyond the targeted SciMLSensitivity regression, or the docs build. No public API or documentation changed.

🤖 Generated with Codex (version unknown; model: unknown; session: local thread 01a06c1d-564b-7ef0-ada6-d83a233b55e2)

Co-Authored-By: Chris Rackauckas <[email protected]>

Co-Authored-By: OpenAI Codex <[email protected]>

Agent-Harness: Codex (version unknown)

Agent-Model: unknown

Agent-Session: local thread 01a06c1d-564b-7ef0-ada6-d83a233b55e2
@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member Author

CI is fully resolved: 29 checks passed, 3 skipped, and 64 failed. An exhaustive audit of all 64 failed-job logs found AMD.SS_Int in every one; there are no unclassified failures. The failures occur during dependency precompilation before the changed reverse-AD paths or their tests run.

The same failure reproduces on clean NonlinearSolve master. It is tracked at SciML/SparseColumnPivotedQR.jl#72 and fixed by the green draft SciML/SparseColumnPivotedQR.jl#71. Developing that fix while retaining AMD 0.5.4 made the local NonlinearSolveBase suite pass 366/366 and root QA pass 28/28, as recorded in this PR body.

@ChrisRackauckas-Claude

ChrisRackauckas-Claude commented Sep 4, 2026 •

Copy link
Copy Markdown
Member Author

CI follow-up after the refreshed run:

Release ordering: this PR needs to own NonlinearSolveBase 2.49.3 because SciML/ModelingToolkit.jl#5062 now requires its reverse-mode AD fixes. #1226 currently also claims 2.49.3; after this PR is reviewed, merged, and released, that PR should rebase and bump to 2.49.4.

@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member Author

Retriggering the unchanged draft now that the transient SciPy link is reachable again and the exact Julia 1.10.12 Broyden reproducer passes locally.

@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member Author

The refreshed complete NonlinearSolve CI now passes, including the Julia 1.10 job that previously produced the isolated Broyden/Watson failure:

The only completed substantive non-green workflow is documentation, which timed out fetching a second, different SciPy-hosted URL: https://github.com/SciML/NonlinearSolve.jl/actions/runs/33930476101. This independently confirms the host-level failure described above. The downstream integration workflow remains in progress; its completed jobs are green.

@ChrisRackauckas-Claude
ChrisRackauckas-Claude marked this pull request as ready for review September 5, 2026 08:28
@ChrisRackauckas
ChrisRackauckas merged commit a6fc767 into SciML:master Sep 5, 2026
319 of 387 checks passed
ChrisRackauckas added a commit that referenced this pull request Sep 7, 2026
- NonlinearSolveBase: rebuild a pre-wrapped function when its signatures do not match u0/p (#1226)
- Fix reverse AD through despecialized parameters (#1228)
- Preserve Jacobian cache parameter representation (#1227)
- Preserve TrustRegion cache parameter representation on reinit (#1229)



Agent-Harness: Claude Code
Agent-Model: claude-opus-5[1m]
Claude-Session: https://claude.ai/code/session_014FEzNTLFutCmTEAZ3zBg5R

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
ChrisRackauckas added a commit that referenced this pull request Sep 7, 2026
- NonlinearSolveBase: rebuild a pre-wrapped function when its signatures do not match u0/p (#1226)
- Fix reverse AD through despecialized parameters (#1228)
- Preserve Jacobian cache parameter representation (#1227)
- Preserve TrustRegion cache parameter representation on reinit (#1229)
- Run runic on docstrings and markdown files (#1231)
- Release NonlinearSolveFirstOrder 2.5.1 (#1232)
- NonlinearSolveBase: report the wrapped arity for despecialization wrappers (#1230)



Agent-Harness: Claude Code
Agent-Model: claude-opus-5[1m]
Claude-Session: https://claude.ai/code/session_014FEzNTLFutCmTEAZ3zBg5R

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
ChrisRackauckas referenced this pull request Sep 7, 2026
- Drop stale [compat] majors older than one year (#1198)
- Drop @fastmath from L2_NORM/Linf_NORM so isfinite guards survive (#1182)
- Release 4.28.1 (#1202)
- Release 2.48.1 (#1206)
- Align QA NLsolve compat with root project (#1205)
- Widen NonlinearSolveBase LogExpFunctions compat to 0.3.28–1 (#1203)
- Continue polyalgorithm after stalled least-squares solves (#1204)
- Align Wrappers NLsolve compat with root project (#1208)
- Release 2.48.2 (#1210)
- Preserve despecialized parameters during reinit (#1199)



Agent-Harness: Claude Code
Agent-Model: claude-opus-5[1m]
Claude-Session: https://claude.ai/code/session_014FEzNTLFutCmTEAZ3zBg5R

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
ChrisRackauckas added a commit that referenced this pull request Sep 10, 2026
- Require all components to stall before resetting Broyden (#1184)
- Add adaptive Jacobian reuse to first-order solvers (#1072)
- Release 4.29.1 (#1220)
- Release 2.49.1 (#1221)
- Release 1.15.3 (#1222)
- Fix @static_timeit for TimerOutputs ≥ 0.5.27 (#1224) (#1225)
- NonlinearSolveBase: rebuild a pre-wrapped function when its signatures do not match u0/p (#1226)
- Fix reverse AD through despecialized parameters (#1228)
- Preserve Jacobian cache parameter representation (#1227)
- Preserve TrustRegion cache parameter representation on reinit (#1229)



Agent-Harness: Claude Code
Agent-Model: claude-opus-5[1m]
Claude-Session: https://claude.ai/code/session_014FEzNTLFutCmTEAZ3zBg5R

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
ChrisRackauckas referenced this pull request Sep 10, 2026
- Remove name duplicates in keyword arguments/named tuples (#1238)
- Add 32-bit Core CI lane via test_groups.toml (#1239)
- Add a native bounded trust-region solver (#1219)



Agent-Harness: Claude Code
Agent-Model: claude-opus-5[1m]
Claude-Session: https://claude.ai/code/session_014FEzNTLFutCmTEAZ3zBg5R

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
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.

2 participants