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

Forward mode gradient error with argument of limited mutability #1821

Open
mhauru opened this issue Sep 13, 2024 · 0 comments
Open

Forward mode gradient error with argument of limited mutability #1821

mhauru opened this issue Sep 13, 2024 · 0 comments

Comments

@mhauru
Copy link
Contributor

mhauru commented Sep 13, 2024

julia> f(x) = sum(x)
f (generic function with 1 method)

julia> x = Hermitian(randn(2,2))
2×2 Hermitian{Float64, Matrix{Float64}}:
  0.656689  -0.377647
 -0.377647  -0.505356

julia> Enzyme.gradient(Enzyme.Forward, Enzyme.Const(f), x)
ERROR: ArgumentError: Cannot set a non-diagonal index in a Hermitian matrix
Stacktrace:
 [1] setindex!
   @ ~/.julia/juliaup/julia-1.10.5+0.aarch64.apple.darwin14/share/julia/stdlib/v1.10/LinearAlgebra/src/symmetric.jl:264 [inlined]
 [2] _setindex!
   @ ./abstractarray.jl:1431 [inlined]
 [3] setindex!
   @ ./abstractarray.jl:1396 [inlined]
 [4] #93
   @ ~/.julia/packages/Enzyme/TiboG/src/Enzyme.jl:967 [inlined]
 [5] macro expansion
   @ ./ntuple.jl:72 [inlined]
 [6] ntuple(f::Enzyme.var"#93#94"{Hermitian{Float64, Matrix{Float64}}, Int64}, ::Val{4})
   @ Base ./ntuple.jl:69
 [7] onehot
   @ ~/.julia/packages/Enzyme/TiboG/src/Enzyme.jl:963 [inlined]
 [8] gradient(::EnzymeCore.ForwardMode{…}, f::EnzymeCore.Const{…}, x::Hermitian{…})
   @ Enzyme ~/.julia/packages/Enzyme/TiboG/src/Enzyme.jl:1132
 [9] top-level scope
   @ REPL[60]:1
Some type information was truncated. Use `show(err)` to see complete types.

Types like Hermitian and Symmetric break the assumption made in onehot that all elements of the array are independent variables that can be setindex!ed freely. Not sure if there's some general solution to this, but maybe catering for stdlib types would be enough?

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