Closed
Description
MWE:
using Zygote
import ChainRulesCore.rrule
using ChainRulesCore: NoTangent
using AbstractDifferentiation
function myfunc(x)
println("This should not print if I have an rrule.")
x
end
rrule(::typeof(myfunc), x) = (x, (y -> (NoTangent(), y)))
println("Zygote run:")
Zygote.gradient(myfunc, 1) # nothing prints
println("AD run:")
AD.derivative(AD.ZygoteBackend(), myfunc, 1) # something prints
The code inside of myfunc should never run. In addition to possible inefficiency, this may lead to incorrect/confusing results for stateful functions or stochastic functions.
Metadata
Metadata
Assignees
Labels
No labels