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

Dicts in struct fields don't propagate gradients #1115

Closed
SBuercklin opened this issue Nov 4, 2021 · 2 comments
Closed

Dicts in struct fields don't propagate gradients #1115

SBuercklin opened this issue Nov 4, 2021 · 2 comments

Comments

@SBuercklin
Copy link
Contributor

SBuercklin commented Nov 4, 2021

If we insert a Dict into a struct field and do some calculations with that Dict, we get a nothing derivative with respect to that field.

Example is on 0.6.29. I included a second field to show that gradients still accumulate for the other fields.

struct Container
    x
    y
end
f_dict(d,y) = d[:a]^2 + y^3
f_container(c) = c.x[:a]^2 + c.y^3

d = Dict(:a => 3)
c = Container(d, 4.0)

Zygote.gradient(f_dict, d, 4.0)
# (Dict{Any, Any}(:a => 6.0), 48.0)

Zygote.gradient(f_container, c)
# ((x = nothing, y = 48.0),)
@SBuercklin
Copy link
Contributor Author

Duplicate of #717

@CarloLucibello
Copy link
Member

@SBuercklin we have many Dict-related issues
dictionary
I suggest to use NamedTuple instead of dictionary whenever possible

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