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

Rule for exp mutates its input #512

Closed
mcabbott opened this issue Aug 25, 2021 · 2 comments · Fixed by #588
Closed

Rule for exp mutates its input #512

mcabbott opened this issue Aug 25, 2021 · 2 comments · Fixed by #588
Assignees
Labels
bug Something isn't working

Comments

@mcabbott
Copy link
Member

mcabbott commented Aug 25, 2021

Should these agree?

julia> using Zygote

julia> gradient(x -> sum(abs, exp(x)' + exp(x)'), [1 2; 3 4.0])
([169.91192742898497 320.5548284667717; 232.38736013199076 434.4143324629697],)

julia> gradient(x -> sum(abs, 2 * exp(x)'), [1 2; 3 4.0])
([226.54923657197995 427.40643795569565; 309.849813509321 579.2191099506263],)

I think the problem is that the rule for exp mutates the gradient it receives, which isn't safe as there's no guarantee this isn't shared with other rules -- here, the rule for + is doing Δ -> (Δ, Δ).

From here #381 (comment), but not sure when this was introduced. Haven't tried to check whether other rules do this too.

Xref FluxML/Zygote.jl#981 maybe --- it would be nice to change the convention to mutate Δ freely by default, and copy only when necessary.

@oxinabox
Copy link
Member

Yeah, this should be fixed.

At it's root this is the same problem as the accumulation in presence of aliasing.
AD is not linearly typed, but rather linearly typed if you have a special dupe and elim operators that I need to understand.

@sethaxen
Copy link
Member

I'm not certain why I chose to mutate the cotangents. Definitely seems to be problematic.

@mcabbott mcabbott added the bug Something isn't working label Aug 30, 2021
@sethaxen sethaxen self-assigned this Jan 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants