Pyro¶
A Pyro model is a Python function whose calls pyro.sample register named sites, which Pyro's effect
handlers, the module pyro.poutine, record in an execution
trace (Bingham et al., 2019; Pyro Developers, n.d.-d). Conditioning the model on given latent values lets the test probe
evaluate the point QVR scores (Transpilation correctness).
How Pyro evaluates a log density¶
The probe conditions the model on the parameters \(\theta\) and the data \(y\), records its trace, and sums the log densities of its sites:
trace = pyro.poutine.trace(pyro.condition(model, data={**θ, **y})).get_trace(x)
log_p = trace.log_prob_sum()
Change of variables¶
The emitted model is in constrained coordinates, so \(\Psi_{\mathsf{Pyro}} = \mathrm{id}\). A probe of a guide that transforms coordinates would also need that guide's Jacobian.
Family parameterizations¶
Pyro's distributions are those of
torch.distributions, the hierarchy QVR's families
are built on, so the map is the identity for every QVR family with a pyro.distributions class:
\(\pi_{F, \mathsf{Pyro}} = \mathrm{id}\) and \(c_{F, \mathsf{Pyro}} = 0\).
Alternate constructor parameters retain their semantic names. The renderer reads
the shared constructor schemas and emits a keyword when its position would
otherwise select a different canonical parameter. This includes logits for
Bernoulli, count, one-hot, and relaxed categorical laws. Surface aliases are
resolved before this comparison; a location parameter thus remains a location
parameter regardless of its authored spelling. Independent parameterization
fixtures compare emitted scores with native and reference execution.
Emitted constructs¶
sample and observe. pyro.sample("x", <dist>) for a latent variable and
pyro.sample("y", <dist>, obs=y_data) for an observation, each a site of the trace.
Plates. Nested with pyro.plate(name, B): contexts
(pyro.plate) (Pyro Developers, n.d.-e), whose density
is the product over the \(B\) conditionally independent draws.
marginalize. The renderer enumerates the values of the latent variable, reduces with
torch.logsumexp, and adds the result with pyro.factor. With via it sums the rows of each group before
the reduction. The emitted density has the variable summed out.
score, let, return. pyro.factor("name", expr) for a score, an assignment for a let, and
Python's return.
Evidence¶
- Level 1. Structural tests check the emitted
modelfunction and the pipelineLower,PyroRenderer, andEmitPretty(python). - Level 2. Python's
astparser accepts the modules of the syntax matrix. - Level 3. On selected fixtures,
trace.log_prob_sum()is compared with the QVR density on the shared grid and tolerance (evidence).
Cited sources¶
Eli Bingham, Jonathan P. Chen, Martin Jankowiak, Fritz Obermeyer, Neeraj Pradhan, Theofanis Karaletsos, Rohit Singh, Paul Szerlip, Paul Horsfall, and Noah D. Goodman. Pyro: Deep Universal Probabilistic Programming. Journal of Machine Learning Research, 20(28):1–6, 2019. URL: https://www.jmlr.org/papers/v20/18-403.html.
Pyro Developers. Poutine: a guide to programming with effect handlers in Pyro. Pyro Tutorials, version 1.9.1, n.d.-d. URL: https://pyro.ai/examples/effect_handlers.html (visited on 2026-11-06).
Pyro Developers. Tensor shapes in Pyro. Pyro Tutorials, version 1.9.1, n.d.-e. URL: https://pyro.ai/examples/tensor_shapes.html (visited on 2026-11-06).