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

Incorrect gradient when diff path goes through a for loop #126

Open
dfdx opened this issue Sep 2, 2022 · 0 comments
Open

Incorrect gradient when diff path goes through a for loop #126

dfdx opened this issue Sep 2, 2022 · 0 comments

Comments

@dfdx
Copy link
Owner

dfdx commented Sep 2, 2022

From FluxML/NNlib.jl#434 (comment)

function prod2(xs::Vector)
    p = one(eltype(xs))
    for x in xs
        p = p * x
        p == 0 && break  # exit early once you know the answer
    end
    p
end

ChainRulesCore.@non_differentiable eltype(::Any)

function main()
    x = rand(3)
    Yota.grad(prod2, x)
    _, tape = trace(prod2, x; ctx=GradCtx())
end
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