EnzymeAD / Enzyme.jl

Julia bindings for the Enzyme automatic differentiator
https://enzyme.mit.edu
MIT License
443 stars 62 forks source link

Gradient returns wrong result for static arrays #1382

Closed touste closed 6 months ago

touste commented 6 months ago
julia> versioninfo()
Julia Version 1.10.2
Commit bd47eca2c8a (2024-03-01 10:14 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 20 × 13th Gen Intel(R) Core(TM) i9-13900H
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, goldmont)
Threads: 1 default, 0 interactive, 1 GC (on 20 virtual cores)

(@v1.10) pkg> st
Status `~/.julia/environments/v1.10/Project.toml`
  [7da242da] Enzyme v0.11.20
  [295af30f] Revise v3.5.14
  [90137ffa] StaticArrays v1.9.3

julia> using StaticArrays, Enzyme

julia> x = @SArray [5.0 0.0 6.0]
1×3 SMatrix{1, 3, Float64, 3} with indices SOneTo(1)×SOneTo(3):
 5.0  0.0  6.0

julia> dx = Enzyme.gradient(Enzyme.Reverse, prod, x)
1×3 SMatrix{1, 3, Float64, 3} with indices SOneTo(1)×SOneTo(3):
 0.0  0.0  0.0   <--- Should be [0 30 0]

Strange thing is that this is taken from the tests and ]test Enzyme runs without any issue...

wsmoses commented 6 months ago

Prior to a recent commit on Enzyme.jl#main gradient had the restriction that only Julia arrays were permitted as inputs. This has been alleviated already on main (which added the test).

touste commented 6 months ago

Oh that makes sense! Sorry for the confusion.