I stumbled onto this behaviour recently and I’m unsure if it’s intentional, or what to do about it. If I update a function definition, invocations of gradient() seem to use the old definition even as the rest of the notebook sees the update.
I am using Julia 1.1.1, Flux 0.10.0, Zygote 0.4.5, and IJulia 1.20.0.
Running a cell with
using Revise
using Flux
function f(x)
return x[1]^2
end
x=[3]
gds = gradient(() -> f(x), params(x))
gds.grads
will work correctly. If I change f to return x[1]^3, instead it will not. The gradient invocation will still work off the old definition, even though the rest of the notebook sees the new one. Is this intentional? Is there a command I can use to force Flux/Zygote to recompile the function without restarting the kernel entirely?