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

Gradients of logpdf with TuringDiagMvNormal return nothing #118

Open
nmheim opened this issue Oct 5, 2020 · 3 comments
Open

Gradients of logpdf with TuringDiagMvNormal return nothing #118

nmheim opened this issue Oct 5, 2020 · 3 comments

Comments

@nmheim
Copy link
Collaborator

nmheim commented Oct 5, 2020

This puzzles me a bit

using DistributionsAD, Distributions, Flux
using DistributionsAD: TuringDiagMvNormal

Flux.@functor TuringDiagMvNormal

m = [1.0]
S = [0.1]

f = TuringDiagMvNormal(m,S)
x = 5 .+ randn(1,100)

ps = Flux.params(f)
#loss() = sum(logpdf(f,x))    # this returns nothings the loop below
loss() = loglikelihood(f,x)      # this works fine

gs = Flux.gradient(loss, ps)
for p in ps
    display(gs[p])
end

I think the logpdf is not hit during the gradient computation somehow. adding an error() in here still just returns nothings...

@mohamed82008
Copy link
Member

This puzzles me a bit

Welcome to the club! It could be a Zygote bug.

@mohamed82008
Copy link
Member

Try making a MWE

@nmheim
Copy link
Collaborator Author

nmheim commented Oct 8, 2020

I think this is related to FluxML/Zygote.jl#692 / FluxML/Zygote.jl#522, because this works:

loss(m,S) = sum(logpdf(TuringDiagMvNormal(m,S),x))
gs = Zygote.gradient(loss, m, S)

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