Timing gradient routes with DifferentiationInterface
Loading ADTypes and DifferentiationInterface defines gradient_routes. It times the gradient of a recurrence by each route its modifiers can take, after checking that the routes agree:
step_pullback, the rule with eachstep_pullbackmethod as written, where a modifier of the recurrence has one;local derivative, the rule with eachstepdifferentiated by one forward-mode pass;plain AD, the backend on the whole loop without the rule.
The cost of a gradient by route reads the rows it returns for a modifier written outside the package.
julia
using ComposableRecurrences, ADTypes, DifferentiationInterface, Mooncake
using ComposableRecurrences: Depletion, gradient_routes
r = Recurrence(fill(0.1, 10); modifiers = (Depletion(1000.0),))
gradient_routes(
AutoMooncake(; config = nothing), r, fill(1.1, 100); history = ones(10)
)The built-in Depletion has no step_pullback method, so this call returns the local derivative and plain AD rows.