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.htmlVerified import paths — ran on the pinned version, not inferred.
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.
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.
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()`.
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.
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()`.