Keep RFLUFactorization off the direct dual AD path (fixes #1052)#1057
Merged
ChrisRackauckas merged 1 commit intoJun 21, 2026
Merged
Conversation
PR SciML#1041 added RFLUFactorization to the direct dual solve path, taken whenever A carries duals. For ForwardDiff over an ODE solve (e.g. Rodas5P), the Rosenbrock W matrix carries duals, so every Newton solve factorized W in Dual arithmetic via RecursiveFactorization. RFLU's Float64 factorization is BLAS/SIMD-grade (cache-blocked, vectorized); routing the Dual problem through it falls back to generic scalar dual arithmetic and loses that speedup entirely. Measured on the issue's case: ~40x slower (0.07s -> 2.9s) and ~13x more allocation (15.6 MiB -> 199.9 MiB), with identical derivatives. The split primal/partials path already handles duals-in-A correctly: it factorizes the primal W once and reuses that factorization across the partial back-solves, which is what 3.85.1 did. Drop RFLU from _use_direct_dual_solve so it stays on that path. GenericLU/SpecializedLU/ SpecializedQR (cheap in dual arithmetic) and PureKLU are unaffected. Adds a regression test asserting RFLU is not routed to the direct path. Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Fixes #1052.
What happened
PR #1041 added
RFLUFactorization(andPureKLUFactorization) to_use_direct_dual_solve, taken wheneverAcarries duals. ForForwardDiffover an ODE solve (the issue'sRodas5Pcase), the RosenbrockWmatrix is the linear-solveAand carries duals, so every Newton solve was routed to factorizeWin Dual arithmetic via RecursiveFactorization instead of the split primal/partials path.RFLUFactorization'sFloat64factorization is BLAS/SIMD-grade (cache-blocked, vectorized). Routing the Dual problem through it falls back to generic scalar dual arithmetic and loses that speedup entirely. The split path — which 3.85.1 used — factorizes the primalWonce and reuses that factorization across the partial back-solves, and is both correct and far cheaper forA-carrying-duals.This PR
Drops only
RFLUFactorizationfrom_use_direct_dual_solve.GenericLU/SpecializedLU/SpecializedQR(genuinely cheap in dual arithmetic) andPureKLUFactorizationare left on the direct path unchanged.Verification (local, Julia 1.10)
Reproduced the issue's benchmark on the same seeded problem, identical base commit:
main(regressed)~40× faster, ~13× less allocation, derivative identical to 1e-15.
Correctness: RFLU (split path) vs GenericLU (direct path) derivative rel diff
2.3e-15; vs default linsolve0.0.test/Core/forwarddiff_overloads.jlruns green end-to-end, including the existing RFLU duals-in-A/ duals-in-bcorrectness checks and the new regression test (RFLU stays off the direct dual path (#1052)), which asserts_use_direct_dual_solve(RFLUFactorization()) == false.Runic --checkclean on the changed files.Note on PureKLU
I measured
PureKLUFactorizationon the direct path too: the penalty is small (~10–25%, no BLAS-grade fast path to lose), so it is intentionally left unchanged here to keep the PR surgical.Please ignore until reviewed by @ChrisRackauckas.
🤖 Generated with Claude Code