Repository navigation
Fix Mooncake gradients through the MTKParameters rules - #5288
utkuyilmaz1903 wants to merge 2 commits into
Conversation
remake_buffer and SetInitialUnknownsMTKParameters rules
PR: #5288 Reviewed head: 9f8d0fc Risk assessment
Review reportVERDICT: CHANGES Riskmedium-high (MH1: the shared reverse-mode rules change core parameter and initial-condition rebuilds on common differentiation paths). The affected users are fitting or differentiating ModelingToolkit models with Mooncake or another ChainRules backend. The patch reaches Blocking findings
Nonblocking findingsNone What I ran
What I did not verify
Head link: 9f8d0fc 🤖 Posted by an AI agent — harness: codex-cli 0.172.0 · model: gpt-6.2-sol |
The
remake_bufferandSetInitialUnknownsrrules return the cotangent of the old parameter object as aTangent{MTKParameters}, andMTKMooncakeExtonly converted theNamedTupleform, so both@from_rrulepullbacks threw. That broke Mooncake throughsetp_oopand throughremake(prob; u0), the example from #4180. The extension now converts theTangent(it also triggers on ChainRulesCore, which Mooncake depends on anyway), and theremake_bufferpullback copies the cotangent of an array parameter, which was a view that@from_rrulecan't accumulate.A callable parameter whose value has a numeric field, like a ModelingToolkitNeuralNets network, broke the same paths: the value sits in the
nonnumericportion, Mooncake gives it a tangent, and theMTKParametersandremake_bufferrules passed that struct cotangent on to the bridge. Both rules now givenonnumericno cotangent, which is howMTKMooncakeExtalready treats it. This came up getting MethodOfLines' neural network tutorial to train with Mooncake.test/extensions/mooncake.jl, against ForwardDiffsetp_oop(prob, [α, q[1]])ArgumentErrorsetp_oop(prob, q), array parameterArgumentErrorremake(prob; u0)ArgumentErrorsetp_oopandu0MethodErrorThe other AD files of the Extensions group pass as before, on Julia 1.10 and 1.13. Mooncake in the test env adds only Mooncake, DispatchDoctor and MistyClosures to the manifest.
Fixes SciML/SciMLSensitivity.jl#1712