pyro-ppl / pyro

Deep universal probabilistic programming with Python and PyTorch
http://pyro.ai
Apache License 2.0
8.5k stars 981 forks source link

Distributions Tutorial #3133

Open chadrs2 opened 2 years ago

chadrs2 commented 2 years ago

I'm using SVI in pyro and one of the model distributions, torch nor pyro supports. I had to develop my own implementation of that distribution. Can you create some clear guide on how to develop your own distribution / how pyro uses it? This would be extremely helpful when debugging my code and improving runtime.

martinjankowiak commented 2 years ago

@chadrs2 hello chad, thanks for the suggestion. we're aware of this gap but have not had time to write such a tutorial. one reason for that is that the answer to "how does pyro use distributions" is a bit complicated and depends on the particular inference algorithm. for example if you use a distribution d in a model and use SVI or HMC for inference, all you really need is to implement d.log_prob: a sample method is not strictly necessary (although might be used for initialization in the HMC case). if you use d in a guide in SVI, however, then you need a sample method, and indeed you probably want a rsample method to get reparameterized gradients if doing so is possible and as described in this tutorial.

note that this design doc, while a bit old, may be a helpful place to look for generic details about pyro's distributions api (which is built on top of pytorch's).