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

Dual leakage #31

Open
MikeInnes opened this issue Jan 20, 2020 · 2 comments
Open

Dual leakage #31

MikeInnes opened this issue Jan 20, 2020 · 2 comments

Comments

@MikeInnes
Copy link

I can make the dual type leak out into a global variable:

julia> function f(x)
         global y = sin(x)
       end
f (generic function with 1 method)

julia> ForwardDiff2.D(f)(1)*1
0.5403023058681398

julia> y
(0.8414709848078965 + 0.5403023058681398ϵ₁)

Presumably this can happen any time a differentiated value escapes the program, e.g. when you have a global cache or similar.

@ChrisRackauckas
Copy link
Collaborator

I am assume that's going to be useful for defining mutable buffers.

@MikeInnes
Copy link
Author

FWIW, this is not just academic since it can lead to bad gradients (effectively a form of perturbation confusion). For example:

julia> function f(x)
         global y = sin(x)
       end
f (generic function with 1 method)

julia> g(x) = x+y
g (generic function with 1 method)

julia> ForwardDiff2.D(f)(2)*1
-0.4161468365471424

julia> ForwardDiff2.D(g)(2)*1
0.5838531634528576

Compare Zygote:

julia> gradient(f, 2)[1]
-0.4161468365471424

julia> gradient(g, 2)[1]
1.0

This is a little contrived, but a function that updates and uses a global cache in some way could follow the same pattern and get silent incorrect gradients.

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

2 participants