Closed dominic-chang closed 6 months ago
If a function could mutate things in place, returning a constant output is well defined. You need to also define a rule for the const output case (which for this function would do nothing since it is read-only).
Sorry, I forgot to mention that I did try doing that, but still received the same error.
function reverse(config, ::Const{typeof(sqrt)}, dret::Const, tape, x::Active)
println("In custom reverse rule.")
return (zero(x.val), )
end
autodiff(Enzyme.Reverse, sqrt, Const, Active(0.5))
ERROR: Enzyme execution failed.
Enzyme: No custom augmented_primal rule was applicable for Tuple{ConfigWidth{1, false, false, (false, false)}, Const{typeof(sqrt)}, Type{Const{Float64}}, Active{Float64}}
dret should be Type{<:Const}
, not const. An actual value isn't passed unless it is active
I receive the same error with this method signature
function reverse(config::ConfigWidth{1}, ::Const{typeof(sqrt)}, dret::Type{<:Const}, tape, x::Active)
println("In custom reverse rule.")
xval = overwritten(config)[2] ? tape : x.val
return (zero(x.val), )
end
You also need the corresponding augmented primal rule as well (the error above says augmented_primal) wasn't found
Sorry. Your right. I missed that. This worked 😀
I'm trying to define custom autodiff rules on some special functions. Defining any custom autodiff rules however causes
Enzyme
to request a rule forConst
returns. Here's a MWEThe following error then occurs when a
Const
output is requested from a reverse diff