Tracker.jl icon indicating copy to clipboard operation
Tracker.jl copied to clipboard

Error when allocating in a function

Open mohamed82008 opened this issue 5 years ago • 0 comments

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

mohamed82008 avatar May 12 '19 02:05 mohamed82008