Repository navigation
Add and precompile the non-isbits (OpaqueRef) AutoDePSpecialize path - #1110
ChrisRackauckas merged 4 commits into
Conversation
SciML#1107 added the AutoDePSpecialize specialization level but no workload exercised it, so the opaque-p solve compiled on first use and struct/array parameters saw no TTFX benefit. Add an AutoDePSpecialize problem (isbits `p` -> OpaqueParams, non-isbits `p` -> OpaqueRef) to the FirstOrder, QuasiNewton, and SpectralMethods `@compile_workload`s. Each container is a single wrapped-residual signature shared across all parameter types of its kind, so one precompiled solve per container serves first solves with any struct/array parameter. Measured (fresh process, first NewtonRaphson solve of a never-seen non-isbits parameter struct): FullSpecialize 3.02s, AutoDePSpecialize 0.88s after this change (vs 3.1s before, when the opaque path was not precompiled). Broyden and DFSane first solves likewise drop to ~1s. Patch-bumps the three touched sublibraries. Co-Authored-By: Chris Rackauckas <[email protected]>
SciML#1107 merged AutoDePSpecialize with an isbits-only policy (`should_opaque_p(p) = isbits(p) && !NullParameters`), so a non-isbits `p` was left concrete and got no de-specialization. Relax the policy to de-specialize any non-`NullParameters`, non-already-packed `p`, and pack via `pack_auto` so isbits payloads go to `OpaqueParams` (byte copy) and non-isbits payloads to `OpaqueRef` (by reference). Mirrors the ODE DiffEqBase path (SciML/OrdinaryDiffEq.jl#4005). This is what makes the non-isbits problem in the precompile workloads actually take the opaque path. Reverse-mode AD of `p` and symbolic parameter indexing remain unsupported under the opaque path (forward-solve latency tool); recover the payload with `RespecializeParams.unpack(sol.prob.p, typeof(p))`. Minor-bumps NonlinearSolveBase (extends the opt-in AutoDePSpecialize feature). Co-Authored-By: Chris Rackauckas <[email protected]>
Mirror of the DiffEqBase guard: the non-isbits path packs any non-isbits `p` (including MTKParameters) into an OpaqueRef, which breaks MTK's initialization pipeline and symbolic parameter indexing. Guard `maybe_opaque_wrap` with `!SciMLBase.has_sys(prob.f)` so a NonlinearProblem carrying a symbolic system falls back to the normal specialization — a no-op for such problems, which gain nothing from de-specialization. Adds a `SymbolCache`-backed regression test. Co-Authored-By: Chris Rackauckas <[email protected]>
|
Added the same MTK-safety guard as the ODE side (SciML/OrdinaryDiffEq.jl#4005). |
…ecialize Two gaps, both on the paths users actually hit: 1. The AutoDePSpecialize problems were only added to the FirstOrder, QuasiNewton and SpectralMethods workloads, which sweep individual algorithms. The polyalgorithm / no-algorithm sweep lives in the main NonlinearSolve workload, so `solve(prob)` (default algorithm selection via FastShortcutNonlinearPolyalg) never saw an opaque-p problem. 2. The workload's default sweep passes `abstol`/`verbose`, and the keyword NamedTuple's type participates in the specialization — so precompiling `solve(prob; kwargs...)` does not cover the bare `solve(prob)` that most user code writes. Add the opaque-p problems (isbits -> OpaqueParams, non-isbits -> OpaqueRef) to the main workload, and give them their own bare no-kwarg `solve(prob)` sweep. Measured (fresh process, non-isbits struct `p`, `solve(prob)` no algorithm): FullSpecialize 5.04s AutoDePSpecialize, before 3.11s AutoDePSpecialize, + polyalg probs 1.69s AutoDePSpecialize, + bare sweep 0.61s That matches the single-algorithm figure (0.72s), i.e. the polyalgorithm path now gets the same first-solve win. Verified: NonlinearSolveBase AutoDePSpecialize suite 23/23; polyalg/NewtonRaphson/Broyden/DFSane all converge on a non-isbits opaque-p problem. Co-Authored-By: Chris Rackauckas <[email protected]>
|
Good catch — the polyalgorithms were not covered, and chasing it turned up two separate gaps on the paths users actually hit. 1. Polyalgorithm / no-algorithm entry. My earlier commit only added the opaque-p problems to the FirstOrder/QuasiNewton/SpectralMethods workloads, which sweep individual algorithms. The polyalg + no-alg sweep lives in the main 2. Keyword-argument shape. The workload’s default sweep passes Fix adds the opaque-p problems to the main workload and gives them a bare no-kwarg Measured (fresh process, non-isbits struct
|
| first solve | |
|---|---|
| FullSpecialize | 5.04s |
| AutoDePSpecialize — before | 3.11s |
| AutoDePSpecialize — + polyalg problems | 1.69s |
| AutoDePSpecialize — + bare sweep | 0.61s |
0.61s matches the single-algorithm figure (0.72s), so the polyalgorithm path now gets the full first-solve win — an 8.2× improvement over FullSpecialize rather than the 1.6× it had.
Verified: NonlinearSolveBase AutoDePSpecialize suite 23/23; polyalg / NewtonRaphson / Broyden / DFSane all converge on a non-isbits opaque-p problem. Patch-bumps NonlinearSolve to 4.23.1.
Same class of gap as the ODE side (SciML/OrdinaryDiffEq.jl#4005), where solve(prob) with no algorithm was going 11.25s → 0.45s once added to the Default workload.
The workload's default sweep passes `abstol`/`verbose`. The keyword NamedTuple's type participates in the specialization, so those calls do not cover the bare `solve(prob)` that most user code writes. #1110 added a bare sweep for the AutoDePSpecialize problems only; extend it to every nonlinear and NLLS problem. Measured (fresh process, default-specialization problems, no algorithm): kwarg form bare, before bare, after NonlinearProblem 0.53s 1.54s 0.53s NLLS problem 0.63s 2.04s 0.63s Cost, measured by rebuilding both ways: precompile 49.8s -> 53.7s (+7.8%) cache .so 37.0MB -> 39.8MB (+7.6%) So ~8% more build for ~1.0-1.4s off every bare first solve. Load time is unchanged (2.80s vs 2.81s, within noise). Co-authored-by: ChrisRackauckas-Claude <[email protected]>
Please ignore until reviewed by @ChrisRackauckas.
Completes the non-isbits story for
AutoDePSpecializeon NonlinearSolve, mirroring the ODE side (SciML/OrdinaryDiffEq.jl#4005).Two parts, which only make sense together:
Non-isbits code path (
NonlinearSolveBase). Add AutoDePSpecialize specialization level (de-specialize p via OpaqueParams) #1107 mergedAutoDePSpecializewith an isbits-only policy (should_opaque_p(p) = isbits(p) && !NullParameters), so a non-isbitsp(e.g. a struct with aVectorfield, or a bare array) was left concrete and got no de-specialization. This relaxes the policy to de-specialize any non-NullParameters, non-already-packedp, packing viapack_auto: isbits →OpaqueParams(byte copy), non-isbits →OpaqueRef(by reference).Precompilation (
FirstOrder,QuasiNewton,SpectralMethods). Add AutoDePSpecialize specialization level (de-specialize p via OpaqueParams) #1107 shipped no workload exercisingAutoDePSpecializeat all, so even the isbits opaque path compiled on first use. This adds oneAutoDePSpecializeproblem per workload covering both containers (isbitsp.a, non-isbitsp[1]). Each container is a single wrapped-residual signature shared across all parameter types of its kind, so one precompiled solve per container serves first solves with any struct/array parameter.Measured (fresh process, first solve of a never-seen non-isbits parameter struct)
Without part 1, the non-isbits workload problem in part 2 would hit
should_opaque_p == falseand never take the opaque path. Verified end-to-end:NonlinearSolveBaseAutoDePSpecialize test suite (incl. new OpaqueRef + idempotency tests) passes 18/18; the three sublibraries precompile cleanly (workload solves run during precompilation and returnSuccess); fresh-process first solves timed above.Version bumps:
NonlinearSolveBaseminor (extends the opt-in feature);FirstOrder/QuasiNewton/SpectralMethodspatch.Caveats (same posture as the isbits path)
Reverse-mode AD of
p(SciMLSensitivity) and symbolic parameter indexing read the concrete parameter and are not supported under the opaque path — it is a forward-solve latency tool. Reverse-mode support is a planned follow-up. Recover the payload withRespecializeParams.unpack(sol.prob.p, typeof(p)).🤖 Generated with Claude Code
https://claude.ai/code/session_01UuAbA8hSnrirMrJjFqxwn5