Skip to content

ForwardDiff local steps ​

Loading ForwardDiff gives each coupling and modifier without its own pullback! a dual-number local step in the reverse-mode rules. Without it, a gradient through such a coupling or modifier falls back to plain AD, which is slower. ForwardDiff gradients themselves use plain AD:

julia
using ComposableRecurrences, ForwardDiff
r = Recurrence([0.5, 0.3])
loss(R) = sum(r(R; history = [1.0, 1.0]))
round.(ForwardDiff.gradient(loss, fill(1.1, 4)); digits = 3)

# output

4-element Vector{Float64}:
 2.17
 1.615
 1.04
 0.613