Pyro ppl

Pyro ppl DEFAULT

Getting Started With Pyro: Tutorials, How-to Guides and Examples¶

Welcome! This page collects tutorials written by the Pyro community. If you’re having trouble finding or understanding anything here, please don’t hesitate to ask a question on our forum!

New users: getting from zero to one¶

If you’re new to probabilistic programming or variational inference, you might want to start by reading the series Introductory Tutorials. If you’re new to PyTorch, you may also benefit from reading the official introduction “Deep Learning with PyTorch.”

After that, you’re ready to get started using Pyro! (Yes, really!) Follow the instructions on the front page to install Pyro and look carefully through the series Practical Pyro and PyTorch, especially the first Bayesian regression tutorial. This tutorial goes step-by-step through solving a simple Bayesian machine learning problem with Pyro, grounding the concepts from the introductory tutorials in runnable code. Industry users interested in serving predictions from a trained model in C++ should also read the PyroModule tutorial.

Most users who reach this point will also find our guide to tensor shapes in Pyro essential reading. Pyro makes extensive use of the behavior of “array broadcasting” baked into PyTorch and other array libraries to parallelize models and inference algorithms, and while it can be difficult to understand this behavior initially, applying the intuition and rules of thumb there will go a long way toward making your experience smooth and avoiding nasty shape errors.

Core functionality: Deep learning, discrete variables and customizable inference¶

A basic familiarity with this introductory material is all you will need to dive right into exploiting Pyro’s two biggest strengths: integration with deep learning and automated exact inference for discrete latent variables. The former is described with numerous examples in the series Deep Generative Models. All are elaborations on the basic idea of the variational autoencoder, introduced in great detail in the first tutorial of this series.

Pyro’s facility with discrete latent variable models like the hidden Markov model is surveyed in the series Discrete Latent Variables. Making use of this in your own work will require careful reading of our overview and programming guide that opens this series.

Another feature of Pyro is its programmability, the subject of a series of tutorials in Customizing Inference. Users working with large models where only part of the model needs special attention may be interested in pyro.contrib.easyguide, introduced in the first tutorial of the series. Meanwhile, machine learning researchers interested in developing variational inference algorithms may wish to peruse the guide to implementing custom variational objectives, and a companion example that walks through implementing “Boosting BBVI”.

Particularly enthusiastic users and potential contributors, especially those interested in contributing to Pyro’s core components, may even be interested in how Pyro itself works under the hood, partially described in the series Understanding Pyro's Internals. The mini-pyro example contains a complete and heavily commented implementation of a small version of the Pyro language in just a few hundred lines of code, and should serve as a more digestable introduction to the real thing.

Practical Pyro and PyTorch¶

Discrete Latent Variables¶

Application: Time Series¶

Application: Gaussian Processes¶

Application: Epidemiology¶

Application: Biological sequences¶

Application: Experimental Design¶

Application: Object Tracking¶

Other Inference Algorithms

Understanding Pyro's Internals¶



Statistical Rethinking is an excellent book for applied Bayesian data analysis. The accompanying codes for the book are written in R and Stan. They are then ported to Python language using PyMC3. Recently, Pyro emerges as a scalable and flexible Bayesian modeling tool (see its tutorial page), so to attract statisticians to this new library, I decided to make a Pyronic version for the codes in this repository. Inspired by the PyMC3onic version, I keep the codes in this repository as close as possible to the original codes in the book.

To say a bit more about Pyro, it is a universal probabilistic programming language which is built on top of PyTorch, a very popular platform for deep learning. If you are familiar with numpy, the transition from to is rather straightforward (as demonstrated in this tutorial).




pip install jupyter pandas pyro-ppl seaborn torch
  1. Honey 1 word cookies
  2. Gabriel clothing company reviews
  3. Weasley christmas sweater



Project Slug


Last Built

2 days, 14 hours ago passed


Home Page


  • reStructuredText

    .. image:: :target: :alt: Documentation Status
  • Markdown

    [![Documentation Status](](
  • HTML

    <a href=''> <img src='' alt='Documentation Status' /> </a>


python, pytorch, probabilistic-programming

Short URLs

Default Version


'latest' Version


MIA: Fritz Obermeyer, Deep probabilistic programming with Pyro; Primer by Eli Bingham

Build StatusCoverage StatusLatest VersionDocumentation StatusCII Best Practices

Getting Started | Documentation | Community | Contributing

Pyro is a flexible, scalable deep probabilistic programming library built on PyTorch. Notably, it was designed with these principles in mind:

  • Universal: Pyro is a universal PPL - it can represent any computable probability distribution.
  • Scalable: Pyro scales to large data sets with little overhead compared to hand-written code.
  • Minimal: Pyro is agile and maintainable. It is implemented with a small core of powerful, composable abstractions.
  • Flexible: Pyro aims for automation when you want it, control when you need it. This is accomplished through high-level abstractions to express generative and inference models, while allowing experts easy-access to customize inference.

Pyro was originally developed at Uber AI and is now actively maintained by community contributors, including a dedicated team at the Broad Institute. In 2019, Pyro became a project of the Linux Foundation, a neutral space for collaboration on open source software, open standards, open data, and open hardware.

For more information about the high level motivation for Pyro, check out our launch blog post. For additional blog posts, check out work on experimental design and time-to-event modeling in Pyro.


Installing a stable Pyro release

Install using pip:

Pyro supports Python 3.6+.

Install from source:

git clone [email protected]:pyro-ppl/pyro.git cd pyro git checkout master # master is pinned to the latest release pip install .

Install with extra packages:

To install the dependencies required to run the probabilistic models included in the / directories, please use the following command:

pip install pyro-ppl[extras]

Make sure that the models come from the same release version of the Pyro source code as you have installed.

Installing Pyro dev branch

For recent features you can install Pyro from source.

Install Pyro using pip:

pip install git+

or, with the dependency to run the probabilistic models included in the / directories:

pip install git+[extras]

Install Pyro from source:

git clone cd pyro pip install .# pip install .[extras] for running models in examples/tutorials

Running Pyro from a Docker Container

Refer to the instructions here.


If you use Pyro, please consider citing:


Ppl pyro

About Pyro

NumPyro Release We’re excited to announce the release of NumPyro, a NumPy-backed Pyro using JAX for automatic differentiation and JIT compilation, with over 100x speedup for HMC and NUTS! See the examples and documentation for more details.

Pyro is a universal probabilistic programming language (PPL) written in Python and supported by PyTorch on the backend. Pyro enables flexible and expressive deep probabilistic modeling, unifying the best of modern deep learning and Bayesian modeling. It was designed with these key principles:

Universal: Pyro can represent any computable probability distribution.
Scalable: Pyro scales to large data sets with little overhead.
Minimal: Pyro is implemented with a small core of powerful, composable abstractions.
Flexible: Pyro aims for automation when you want it, control when you need it.

Check out the blog post for more background or dive into the tutorials.

How to Install Pyro

Pyro supports Python 3.

Install via Pip

First install PyTorch. Then install Pyro via pip:

Install from source

Running Docker Image

Follow the instructions here.

Pyro is an Apache 2.0-Licensed Open Source Project

If you use Pyro or NumPyro in your research, please consider citing our papers.

@article{bingham2018pyro, author = {Bingham, Eli and Chen, Jonathan P. and Jankowiak, Martin and Obermeyer, Fritz and Pradhan, Neeraj and Karaletsos, Theofanis and Singh, Rohit and Szerlip, Paul and Horsfall, Paul and Goodman, Noah D.}, title = {{Pyro: Deep Universal Probabilistic Programming}}, journal = {Journal of Machine Learning Research}, year = {2018} } @article{phan2019composable, author = {Phan, Du and Pradhan, Neeraj and Jankowiak, Martin}, title = {Composable Effects for Flexible and Accelerated Probabilistic Programming in NumPyro}, journal = {arXiv preprint arXiv:1912.11554}, year = {2019} }

Institutions Using Pyro:

(Add yours too!)

An intro to Probabilistic Programming with Ubers Pyro

Pyro Models

Models are generated by a custom stan-to-pyro transpiler then manually modified for Pyro 0.3 compatibility, so there may be boilerplate in each example that is unnecessary to actually run the code. Models are from the Stan examples.

The data corresponding to each model is in JSON format and named . See to see an example of how to run a model.

The interface is unstable and may change in the future. Tested on PyTorch 1.0 and Pyro 0.3.


Initialized variables are uniformly sampled within their domains.

- real<lower=0,upper=100> sigma;+ sigma = pyro.sample("sigma", dist.Uniform(0., 100.))

Constrained samples from improper distribution are sampled from a HalfCauchy:

- real<lower=0> sigma;+ sigma_a1 = pyro.sample("sigma", dist.HalfCauchy(2.))

For inference to work, you may have to change the initializations of the model parameters.

Installation and Usage

To install the package, clone the repository to a directory on your machine and run or (depending on whether you want to edit the library).

Subsequently, to load the models:


The variable is a dictionary whose keys are the unique model name qualified by the collection that it is from, and whose value is a dictionary of model metadata, including the Pyro model function. For instance, the model from the BUGS model collection is in .

See for a full demonstration of how to load a model and its dataset and learn the guide program by stochastic variational inference (SVI).


Contributions welcome! Contributed examples need not follow the format of the current examples since they were automatically transpiled. However, please do include the data (or a toy dataset your example runs on).

If you have a polished example or a paper replication, you might want to consider contributing it to the Pyro examples.


If you use these models in your research, please consider citing:


Now discussing:


1506 1507 1508 1509 1510