Skip to content

Mooncake: second-order adjoints (forward-over-reverse Hessian) not yet working #1427

Description

@ChrisRackauckas-Claude

docs/src/examples/ode/second_order_adjoints.md uses Mooncake for Phase 1 (Adam) but still uses Zygote for Phase 2 (NewtonTrustRegion) because Mooncake has no working forward-over-reverse path through SciMLSensitivity + OrdinaryDiffEq.

  • SecondOrder(AutoMooncake(), AutoMooncake()) raises "reverse-over-reverse not supported" (ArgumentError from build_derived_rrule).
  • SecondOrder(AutoForwardDiff(), AutoMooncake()) is blocked on Mooncake's IEEEFloat-only gradient interface — it rejects ForwardDiff.Dual as the primal type (ValueAndGradientReturnTypeError).

Mooncake's native prepare_hvp_cache / value_and_hvp!! works on simple functions (Rosenbrock), but on the neural ODE loss through OrdinaryDiffEq it hits:

  1. Missing foreigncall frules for :jl_get_world_counter and :jl_matching_methodsfixed in Add frule!!/rrule!! for :jl_get_world_counter and :jl_matching_methods chalk-lab/Mooncake.jl#1142.
  2. UndefRefError in _build_output_tangent_cartesian for IdDict tangent construction (Memory{Any} has #undef slots) — separate Mooncake bug.
  3. ArgumentError: Tangent types do not match primal types for ComponentArray closures captured into HVPCache's grad_f — separate Mooncake/CA issue.

Once Mooncake's forward-over-reverse matures, both phases can use Mooncake.

🤖 Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions