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

destructure's gradient is confused by trainable #72

Open
mcabbott opened this issue May 1, 2022 · 0 comments
Open

destructure's gradient is confused by trainable #72

mcabbott opened this issue May 1, 2022 · 0 comments
Labels
bug Something isn't working gradients

Comments

@mcabbott
Copy link
Member

mcabbott commented May 1, 2022

Example:

using Optimisers, Functors, Zygote

struct TwoThirds a; b; c; end  # from the tests
Functors.@functor TwoThirds (a, c)
Optimisers.trainable(x::TwoThirds) = (a = x.a,)

mtt = TwoThirds([1.0, 2.0], [3.0], [4.0, 5.0])
v, re = destructure(mtt)
re(100v)  # TwoThirds([100.0, 200.0], [3.0], [4.0, 5.0])

gradient(mtt) do x
  w, _ = destructure(x)
  1000 * prod(w)
end  # ((a = [2000.0, 1000.0], b = nothing, c = [4.0, 5.0]),)

Here b is correct (excluded from children), but c (non-trainable child) has a value not a gradient.

@mcabbott mcabbott added the bug Something isn't working label May 1, 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 gradients
Projects
None yet
Development

No branches or pull requests

1 participant