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

Splatting and mutation? #347

Closed
marcoct opened this issue Sep 27, 2019 · 2 comments · Fixed by #358
Closed

Splatting and mutation? #347

marcoct opened this issue Sep 27, 2019 · 2 comments · Fixed by #358

Comments

@marcoct
Copy link

marcoct commented Sep 27, 2019

I ran into some unexpected nothings that depend on whether splatting was used or not.

I tried simplifying it into a minimal example---it seems like the problem might involve some combination of splatting and mutation.

import Zygote

mutable struct MyMutable
    value::Float64
end

function foo!(m::MyMutable, x)
    m.value = x
end

function baz(args)
    m = MyMutable(0.)
    # foo!(m, args[1]) # grad(1.) works as expected
    foo!(m, args...) # grad(1.) gives 'nothing'
    m.value
end

value, grad = Zygote.pullback(baz, (1.0,))
@assert grad(1.) == ((1.0,),)

PS: Zygote looks like great work, and we're looking forward to using it for AD within https://github.com/probcomp/Gen/

@DoktorMike
Copy link

I'm looking forward to this too as it will combine two of my favorite projects in julia. 😊 Will follow this!

MikeInnes added a commit that referenced this issue Oct 3, 2019
@MikeInnes
Copy link
Member

Your analysis is spot on -- Core._apply just assumed that f was pure, so didn't bother calling its adjoint with nothing as input. Thanks for the report and nice test case.

Glad to hear you're looking at this for Gen!

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

Successfully merging a pull request may close this issue.

3 participants