Skip to content

CUDA gradient error with broadcasting #1597

@CarloLucibello

Description

@CarloLucibello

This used to work, but currently fails on CI.
I tried with julia v1.11, Zygote v0.7.10 and CUDA v5.8.5

julia> using Zygote, CUDA

julia> a = Float32.(1:9)
9-element Vector{Float32}:
 1.0
 2.0
 3.0
 4.0
 5.0
 6.0
 7.0
 8.0
 9.0

julia> a_gpu = a |> cu
9-element CuArray{Float32, 1, CUDA.DeviceMemory}:
 1.0
 2.0
 3.0
 4.0
 5.0
 6.0
 7.0
 8.0
 9.0

julia> g3 = gradient(x -> sum(x .^ 3) / count(x .> 3), a)[1]
9-element Vector{Float32}:
  0.5
  2.0
  4.5
  8.0
 12.5
 18.0
 24.5
 32.0
 40.5

julia> gradient(x -> sum(x .^ 3) / count(x .> 3), a_gpu)[1] # WRONG GRADIENT
9-element CuArray{Float32, 1, CUDA.DeviceMemory}:
  0.42857146
  1.7142859
  3.8571432
  6.8571434
 10.714287
 15.428573
 21.000002
 27.428574
 34.714287

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions