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 #43

Closed
willtebbutt opened this issue Dec 12, 2018 · 1 comment
Closed

Incorrect gradient #43

willtebbutt opened this issue Dec 12, 2018 · 1 comment

Comments

@willtebbutt
Copy link
Member

This is example is a simplified version of something I'm doing with FillArrays and Zygote, and definitely computes the wrong result. Any thoughts?

using Zygote, Flux

# A vector of length 10
struct MyFill{T} <: AbstractVector{T}
    value::T
end
Base.getindex(m::MyFill, n::Int) = m.value
Base.size(m::MyFill) = (10,)

foo(x) = sum(MyFill(x))

# This yields the right answer :)
Flux.gradient(foo, 5.0)

# This yields the wrong answer :(
Zygote.gradient(foo, 5.0)
@MikeInnes
Copy link
Member

This now throws an error, rather than giving wrong gradients. You can fix the error by doing:

Zygote.@adjoint MyFill(x) = MyFill(x), x -> (sum(x),)

MikeInnes added a commit that referenced this issue Dec 17, 2018
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

2 participants