Forward-over-reverse may result in a MethodError that seems to indicate that typetree is receiving an instance where it expects a type. In the MWE below, tanh can be replaced by any hyperbolic function (sinh, cosh, coth). No other function I've tried has triggered the issue.
using Enzyme
f(x) = sum(tanh, x) # or sinh/cosh/coth
function df!(dx, x)
make_zero!(dx)
autodiff_deferred(Reverse, f, Active, Duplicated(x, dx))
return nothing
end
function hvp!(hv, v, x)
make_zero!(hv)
autodiff(Forward, df!, Const, Duplicated(make_zero(x), hv), Duplicated(x, v))
return nothing
end
x = [0.5]
# primal: sanity check
@show f(x)
# gradient: works
dx = make_zero(x)
df!(dx, x)
@show dx
# hvp: error
v = first(onehot(x))
hv = make_zero(v)
hvp!(hv, v, x)
@show hv
Forward-over-reverse may result in a
MethodError
that seems to indicate thattypetree
is receiving an instance where it expects a type. In the MWE below,tanh
can be replaced by any hyperbolic function (sinh, cosh, coth). No other function I've tried has triggered the issue.Output: