Registry / ai-ml / numpyro

numpyro

JSON →
library0.21.0pypypi✓ verified 21d ago

NumPyro is a probabilistic programming library that leverages JAX for automatic differentiation, JIT compilation, and GPU/TPU acceleration. It allows users to build and infer Bayesian models with a flexible and composable API inspired by Pyro. NumPyro is currently at version 0.20.1 and maintains a regular release cadence, often releasing minor versions monthly or bi-monthly with new features, bug fixes, and performance improvements.

pip install numpyro[cuda12_pip] -f https://storage.googleapis.com/jax-releases/jax_cuda_releases.html
INSTALL
IMPORT
SIG · NUMPYRO
N
numpyro
ai-mlpythonv0.21.0
Install
13.0s avg
Import
3047ms
Disk
592MB
Pass rate
5/ 10
Env Coverage5 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.19.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
build_error
glibc
py 3.103.910 runs
installs and imports cleanly · install 13.0s · import 3.047s · 566MB
592MB installed
● package 592MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

numpyro
import numpyro
numpyro.distributions
import numpyro.distributions as dist
numpyro.infer
from numpyro.infer import MCMC, NUTS
jax.random.PRNGKey
import jax; key = jax.random.PRNGKey(0); key1, key2 = jax.random.split(key)
key = jax.random.PRNGKey(0); result1 = some_func(key); result2 = another_func(key)
JAX PRNGKeys are consumed and must be split before each use.

This quickstart demonstrates a basic Bayesian linear regression model using NumPyro with the NUTS sampler. It sets up a simple model, generates synthetic data, performs MCMC inference, and prints a summary of the posterior samples. It highlights proper `jax.random.PRNGKey` handling and passing data to the model.

import jax import jax.numpy as jnp import numpyro import numpyro.distributions as dist from numpyro.infer import MCMC, NUTS # Optional: Uncomment to force CPU-only execution # jax.config.update("jax_platform_name", "cpu") def model(x, obs=None): # Prior for intercept a = numpyro.sample("a", dist.Normal(0, 1)) # Prior for slope b = numpyro.sample("b", dist.Normal(0, 1)) # Prior for observation noise, must be positive sigma = numpyro.sample("sigma", dist.HalfCauchy(1)) # Linear model mean mu = a + b * x # Likelihood numpyro.sample("obs", dist.Normal(mu, sigma), obs=obs) # Generate some dummy data rng_key_data, rng_key_model = jax.random.split(jax.random.PRNGKey(0)) true_a = 0.5 true_b = 2.0 true_sigma = 0.8 N_samples = 100 x_data = jax.random.normal(rng_key_data, (N_samples,)) y_data = true_a + true_b * x_data + jax.random.normal(rng_key_data, (N_samples,)) * true_sigma # MCMC setup kernel = NUTS(model) mcmc = MCMC( kernel, num_warmup=500, num_samples=1000, num_chains=1, progress_bar=False, # Set to True for interactive use jit_model_args=True, ) # Run MCMC mcmc.run(rng_key_model, x=x_data, obs=y_data) mcmc.print_summary() # # To get posterior samples: # samples = mcmc.get_samples() # # print("\nSampled parameters:", {k: v.shape for k, v in samples.items()})
Debug
Known issues
gotchaNumPyro's performance and stability are highly dependent on JAX and JAXlib versions. Incompatible versions can lead to cryptic errors or poor performance.
fix
Always install `jax` and `jaxlib` using the officially recommended method for your hardware (CPU/GPU/TPU) and ensure compatibility with your `numpyro` version. Consult the JAX installation guide and `numpyro`'s dependencies.
affects: All versions
gotchaJAX's random number generation uses a functional approach where `jax.random.PRNGKey`s are consumed upon use and must be explicitly split for subsequent operations. Reusing the same key will lead to identical 'random' results.
fix
Use `jax.random.split(key)` to generate new, independent keys for each random operation or branch in your JAX/NumPyro code. For MCMC, a new key should be passed to `mcmc.run()`.
affects: All versions
gotchaJAX's JIT compilation (which NumPyro heavily utilizes) requires functions to be 'pure' (no side effects, deterministic output for given inputs, no global state changes). Violating this can prevent compilation or lead to incorrect results.
fix
Ensure your models are pure functions. Avoid Python control flow (loops, conditionals) that depend on data values; use JAX's `jax.lax` primitives (e.g., `jax.lax.scan`, `jax.lax.cond`) for data-dependent logic inside JIT-compiled functions.
affects: All versions
breakingIn NumPyro 0.18.0, the internal caching mechanism for `plates` within `AutoGuide` was removed. This might affect users who relied on inspecting or manipulating internal `_plates` attributes of custom `AutoGuide` implementations.
fix
Refactor custom `AutoGuide` implementations to avoid relying on internal, non-public attributes. Focus on the public API for defining guides. The `sample_posterior()` signature was also unified, requiring updates to direct calls if not using the standard `mcmc.get_samples()`.
affects: >=0.18.0
Upgrade
Version history
0.21.0latest on PyPI · released May 2, 2026
Audit
Dependencies
jaxrequiredCore dependency for automatic differentiation, JIT compilation, and device management.
jaxlibrequiredJAX's compiled backend; must be compatible with JAX and your hardware (CPU/GPU/TPU).
optaxoptionalUsed for optimizers in some inference algorithms and contributions.
funsoroptionalUsed internally for some advanced inference and distribution functionalities.
Agent activity
12 hits · last 30 days
node
8
Amazon
1
Resources
numpyro — pip install numpyro · libregistry