Skip to main content

[![Build Status](https://travis-ci.com/pyro-ppl/numpyro.svg?branch=master)](https://travis-ci.com/pyro-ppl/numpyro) [![Documentation Status](https://readthedocs.org/projects/numpyro/badge/?version=latest)](https://numpyro.readthedocs.io/en/latest/?badge=latest)

# NumPyro

Probabilistic programming with Numpy powered by [JAX](https://github.com/google/jax) for autograd and JIT compilation to GPU/CPU.

## What is NumPyro?

NumPyro is a small probabilistic programming library built on [JAX](https://github.com/google/jax). It essentially provides a NumPy backend for [Pyro](https://github.com/pyro-ppl/pyro), with some minor changes to the inference API and syntax. Since we use JAX, we get autograd and JIT compilation to GPU / CPU for free. This is an alpha release under active development, so beware of brittleness, bugs, and changes to the API as the design evolves.

NumPyro is designed to be lightweight and focuses on providing a flexible substrate that users can build on:

  • Pyro Primitives: NumPyro programs can contain regular Python and NumPy code, in addition to [Pyro primitives](http://pyro.ai/examples/intro_part_i.html) like sample and param. The model code should look very similar to Pyro except for some minor differences between PyTorch and Numpy’s API. See [Examples](https://github.com/pyro-ppl/numpyro/#Examples).

  • Inference algorithms: NumPyro currently supports Hamiltonian Monte Carlo, including an implementation of the No U-Turn Sampler. One of the motivations for NumPyro was to speed up Hamiltonian Monte Carlo by JIT compiling the verlet integration step that includes multiple gradient computations. With JAX, we can compose jit and grad to compile the entire integration step into an XLA optimized kernel. We also eliminate Python overhead by JIT compiling the entire tree building stage in NUTS (this is possible using [Iterative NUTS](https://github.com/pyro-ppl/numpyro/wiki/Iterative-NUTS)). There is also a basic Variational Inference implementation for reparameterized distributions.

  • Distributions: The [numpyro.distributions](https://numpyro.readthedocs.io/en/latest/distributions.html) module provides distribution classes, constraints and bijective transforms. The distribution classes wrap over samplers implemented to work with JAX’s [functional pseudo-random number generator](https://github.com/google/jax#random-numbers-are-different). The design of the distributions module largely follows from [PyTorch](https://pytorch.org/docs/stable/distributions.html). A major subset of the API is implemented, and it contains most of the common distributions that exist in PyTorch. As a result, Pyro and PyTorch users can rely on the same API and batching semantics as in torch.distributions. In addition to distributions, constraints and transforms are very useful when operating on distribution classes with bounded support.

  • Effect handlers: Like Pyro, primitives like sample and param can be interpreted with side-effects using effect-handlers from the [numpyro.handlers](https://numpyro.readthedocs.io/en/latest/handlers.html) module, and these can be easily extended to implement custom inference algorithms and inference utilities.

## Installation

To install NumPyro with a CPU version of JAX, you can use pip:

` pip install numpyro `

To use NumPyro on the GPU, you will need to first [install](https://github.com/google/jax#installation) jax and jaxlib with CUDA support.

You can also install NumPyro from source:

` git clone https://github.com/pyro-ppl/numpyro.git # install jax/jaxlib first for CUDA support pip install -e .[dev] `

## Examples

For some examples on specifying models and doing inference in NumPyro:

Users will note that the API for model specification is largely the same as Pyro including the distributions API, by design. The interface for inference algorithms and other utility functions might deviate from Pyro in favor of a more functional style that works better with JAX. e.g. there is no global parameter store or random state.

## Future Work

In the near term, we plan to work on the following. Please open new issues for feature requests and enhancements:

  • Improving robustness of inference on different models, profiling and performance tuning.

  • More inference algorithms, particularly those that require second order derivaties or use HMC.

  • Integration with [Funsor](https://github.com/pyro-ppl/funsor) to support inference algorithms with delayed sampling.

  • Supporting more distributions, extending the distributions API, and adding more samplers to JAX.

  • Other areas motivated by Pyro’s research goals and application focus, and interest from the community.

Metadata

Release files for numpyro 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for numpyro 0.1.0
File Size Uploaded Provenance Actions
numpyro-0.1.0.tar.gz 73.8 kB Without provenance Details for numpyro-0.1.0.tar.gz

Release files / numpyro-0.1.0.tar.gz

Download URL numpyro-0.1.0.tar.gz
Size 73.8 kB
Tags Source
SHA-256 checksum
How to use checksums
3df3e54abfa195a51ceadc6d177ff629f79c5fe9c9a8f89547b3b1a73bd49840
BLAKE2b-256 checksum
How to use checksums
46b7e4e0624e9e948b1f1c4176ef01ac8dc3487fdc78f897494bdfe15932e51b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Python-urllib/3.6

Security for numpyro 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page