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

Reverse mode jacobian is wrong for matrix input #1391

Open
gdalle opened this issue Apr 17, 2024 · 0 comments
Open

Reverse mode jacobian is wrong for matrix input #1391

gdalle opened this issue Apr 17, 2024 · 0 comments

Comments

@gdalle
Copy link
Contributor

gdalle commented Apr 17, 2024

This seems related to the wrong jacobian shape of #1332 but it turns out even a reshape is not enough:

julia> using Enzyme

julia> x = float.(reshape(1:6, 2, 3))
2×3 Matrix{Float64}:
 1.0  3.0  5.0
 2.0  4.0  6.0

julia> f(x) = fill(sum(abs2, x), 6);

julia> jac_forward = Enzyme.jacobian(Enzyme.Forward, f, x)
6×6 Matrix{Float64}:
 2.0  4.0  6.0  8.0  10.0  12.0
 2.0  4.0  6.0  8.0  10.0  12.0
 2.0  4.0  6.0  8.0  10.0  12.0
 2.0  4.0  6.0  8.0  10.0  12.0
 2.0  4.0  6.0  8.0  10.0  12.0
 2.0  4.0  6.0  8.0  10.0  12.0

julia> jac_reverse = reshape(Enzyme.jacobian(Enzyme.Reverse, f, x, Val(6), Val(1)), 6, 6)
6×6 Matrix{Float64}:
  2.0   2.0   2.0   4.0   4.0   4.0
  6.0   6.0   6.0   8.0   8.0   8.0
 10.0  10.0  10.0  12.0  12.0  12.0
  2.0   2.0   2.0   4.0   4.0   4.0
  6.0   6.0   6.0   8.0   8.0   8.0
 10.0  10.0  10.0  12.0  12.0  12.0
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