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 derivative of getindex() with repeating indices on CuArrays #821

Open
dfdx opened this issue Nov 7, 2020 · 3 comments
Open

Incorrect derivative of getindex() with repeating indices on CuArrays #821

dfdx opened this issue Nov 7, 2020 · 3 comments
Labels
bug Something isn't working CUDA All things GPU

Comments

@dfdx
Copy link

dfdx commented Nov 7, 2020

using Zygote
using CUDA

f(A, I) = sum(A[I])
A = rand(4)
I = [1, 3, 1]

# CPU - everything is OK
Zygote.gradient(f, A, I)
# ==> ([2.0, 0.0, 1.0, 0.0], nothing)

# GPU - dA[1] is incorrect
Zygote.gradient(f, cu(A), cu(I))
# => (Float32[1.0, 0.0, 1.0, 0.0], nothing)

I believe CPU version comes from ChainRules.jl which correctly adds several derivatives to dA[1], but I'm not sure what code is used for CUDA version.

Here is how I came to this issue and how I try to resolve it in Yota.

@CarloLucibello CarloLucibello added bug Something isn't working CUDA All things GPU labels Nov 19, 2020
@mcabbott
Copy link
Member

Similar to #600, see also JuliaGPU/CUDA.jl#89 and JuliaLang/julia#31407 .

@marius311
Copy link
Contributor

My brief reading of the linked CUDA issue suggests this can't be fixed? Could we add an error here? Just spent a bunch of time discovering subtly wrong results in my code / reducing to a MWE / eventually finding this already-filed issue. 😢

@ToucheSir
Copy link
Member

I thought JuliaDiff/ChainRules.jl#655 was the last word on this. If that works then we "just" need to do #1328.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working CUDA All things GPU
Projects
None yet
Development

No branches or pull requests

5 participants