You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
using Flux, Enzyme, Statistics, Random
functionenzyme_withgradient(f, x...)
args = []
for x in x
if x isa Number
push!(args, Enzyme.Active(x))
elsepush!(args, Enzyme.Duplicated(x, Enzyme.make_zero(x)))
endend
ad = Enzyme.set_runtime_activity(Enzyme.ReverseWithPrimal)
ret = Enzyme.autodiff(ad, Enzyme.Const(f), Enzyme.Active, args...)
g =ntuple(i -> x[i] isa Number ? ret[1][i] : args[i].dval, length(x))
return ret[2], g
endloss(model, x) =mean(model(x))
model = Flux.BatchNorm(2)
x =randn(Float32, 2, 5)
Flux.testmode!(model)
enzyme_withgradient(loss, model, x) # ok
Flux.trainmode!(model)
enzyme_withgradient(loss, model, x) # ERROR
output:
cc @wsmoses
The text was updated successfully, but these errors were encountered: