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: 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).
Installationpip install jupyter pandas pyro-ppl seaborn torch
2 days, 14 hours ago passed
reStructuredText.. image:: https://readthedocs.org/projects/pyro-ppl/badge/?version=stable :target: https://docs.pyro.ai/en/stable/?badge=stable :alt: Documentation Status
HTML<a href='https://docs.pyro.ai/en/stable/?badge=stable'> <img src='https://readthedocs.org/projects/pyro-ppl/badge/?version=stable' alt='Documentation Status' /> </a>
python, pytorch, probabilistic-programming
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:
Install with extra packages:
To install the dependencies required to run the probabilistic models included in the / directories, please use the following command:
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:
or, with the dependency to run the probabilistic models included in the / directories:
Install Pyro from source:
Running Pyro from a Docker Container
Refer to the instructions here.
If you use Pyro, please consider citing:
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 PipFirst install PyTorch. Then install Pyro via pip:
Install from source
Running Docker ImageFollow 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.
Institutions Using Pyro:
(Add yours too!)
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.
Constrained samples from improper distribution are sampled from a HalfCauchy:
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:
- Snake discovery available reptiles
- Home depot field paint
- The rifleman series on dvd
- Zara mannequin
- Waterfowl apparel brands
- Youtube daves highway
- Softball game hairstyles
- Black ops enfield
- Golden lighting customer service
- Stacked pickup