Tracker.jl
Tracker.jl copied to clipboard
Error when allocating in a function
Hi!
The following example seems to expose a weird bug possibly related to allocation:
using Tracker
x = [1.0]
# Works
function f1(x)
@assert length(x) == 1
return (x .- sum(x))[1]
end
f1(x)
l_tracked, grad = Tracker.forward(f1, x)
l, ∂l∂θ = Tracker.data(l_tracked), Tracker.data(grad(1)[1])
# Errors
function f2(x)
@assert length(x) == 1
theta = x[1]
y = [theta]
return (y .- sum(y))[1]
end
f2(x)
l_tracked, grad = Tracker.forward(f2, x)
l, ∂l∂θ = Tracker.data(l_tracked), Tracker.data(grad(1)[1])
Ref: https://github.com/TuringLang/Turing.jl/issues/780