What are intended side-effects of pyro.sample?


I was quite surprised to realize that model() and guide() may return nothing, e.g. like in SVI tutorial Part I.

For me it was a clear sign of some intended side-effects they’re expected to evoke. Looking deeper I’ve found that pyro.sample indeed causes some side-effects, but its documentation says almost nothing about it, but rather refers to SVI tutorials Part I and Part II, where I failed to find any details on this. I guess it will be difficult to understand SVI tutorials without clarifying what those side-effects are.

Models, guides and pyro.sample are the central entities of the whole Pyro, so it would be nice to get some more idea on what they really do if their return value could even be ignored.

Thanks in advance for any hints!

UPD.: as I see from sources the side-effect is strongly related with some stack of the messages. Maybe it’s a good idea if someone could add a description of the message stack used?


Other details

Hi, to learn more about how Pyro works internally I recommend starting by reading the minipyro example/tutorial, which is a complete implementation of a simple version of the Pyro language in only a couple hundred lines of code. This should help answer your questions about how pyro.sample statements are evaluated. If you want more details about effect handlers after that, you might want to check out the effect handler tutorial, which explains more about the messages sent and processed at sample sites in the full version of Pyro.

1 Like