Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when allocating in a function #29

Open
mohamed82008 opened this issue May 12, 2019 · 0 comments
Open

Error when allocating in a function #29

mohamed82008 opened this issue May 12, 2019 · 0 comments

Comments

@mohamed82008
Copy link
Collaborator

mohamed82008 commented May 12, 2019

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: TuringLang/Turing.jl#780

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant