Skip to main content
logo

Installation | Quickstart | Methods | Friends | Contributing | Citation | Documentation | Paper

What is posteriors?

General purpose python library for uncertainty quantification with PyTorch.

  • Composable: Use with transformers, lightning, torchopt, torch.distributions, pyro and more!
  • Extensible: Add new methods! Add new models!
  • Functional: Easier to test, closer to mathematics!
  • Scalable: Big model? Big data? No problem!
  • Swappable: Swap between algorithms with ease!

Installation

posteriors is available on PyPI and can be installed via pip:

pip install posteriors

Quickstart

posteriors is functional first and aims to be easy to use and extend. Let's try it out by training a simple model with variational inference:

from torchvision.datasets import MNIST
from torchvision.transforms import ToTensor
from torch import nn, utils, func
import torchopt
import posteriors

dataset = MNIST(root="./data", transform=ToTensor())
train_loader = utils.data.DataLoader(dataset, batch_size=32, shuffle=True)
num_data = len(dataset)

classifier = nn.Sequential(nn.Linear(28 * 28, 64), nn.ReLU(), nn.Linear(64, 10))
params = dict(classifier.named_parameters())


def log_posterior(params, batch):
    images, labels = batch
    images = images.view(images.size(0), -1)
    output = func.functional_call(classifier, params, images)
    log_post_val = (
        -nn.functional.cross_entropy(output, labels)
        + posteriors.diag_normal_log_prob(params) / num_data
    )
    return log_post_val, output


transform = posteriors.vi.diag.build(
    log_posterior, torchopt.adam(), temperature=1 / num_data
)  # Can swap out for any posteriors algorithm

state = transform.init(params)

for batch in train_loader:
    state, aux = transform.update(state, batch)

Observe that posteriors recommends specifying log_posterior and temperature such that log_posterior remains on the same scale for different batch sizes. posteriors algorithms are designed to be stable as temperature goes to zero.

Further, the output of log_posterior is a tuple containing the evaluation (single-element Tensor) and an additional argument (TensorTree) containing any auxiliary information we'd like to retain from the model call, here the model predictions. If you have no auxiliary information, you can simply return torch.tensor([]) as the second element. For more info see torch.func.grad (with has_aux=True) or the documentation.

Check out the tutorials for more detailed usage!

Methods

posteriors supports a variety of methods for uncertainty quantification, including:

With full details available in the API documentation.

posteriors is designed to be easily extensible, if you're favorite method is not listed above, raise an issue and we'll see what we can do!

Friends

Interfaces seamlessly with:

The functional transform interface is strongly inspired by frameworks such as optax and blackjax.

As well as other UQ libraries fortuna, laplace, numpyro, pymc and uncertainty-baselines.

Contributing

You can report a bug or request a feature by creating a new issue on GitHub.

If you want to contribute code, please check the contributing guide.

Citation

If you use posteriors in your research, please cite the library using the following BibTeX entry:

@inproceedings{duffield2025scalable,
    title={Scalable Bayesian Learning with posteriors},
    author={Samuel Duffield and Kaelan Donatella and Johnathan Chiu and Phoebe Klett and Daniel Simpson},
    booktitle={The Thirteenth International Conference on Learning Representations},
    year={2025},
    url={https://openreview.net/forum?id=fifXzmzeGy}
}

Metadata

Release files for posteriors 0.1.3

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

Source distribution (sdist)

Source distribution for posteriors 0.1.3
File Size Uploaded
posteriors-0.1.3.tar.gz 41.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for posteriors 0.1.3
File Interpreter ABI Platform
posteriors-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 95.5 kB

Release files / posteriors-0.1.3.tar.gz

Download URL posteriors-0.1.3.tar.gz
Size 41.7 kB
Tags Source
SHA-256 checksum
How to use checksums
afe8c2ac7971f56613cf9a0e1246d6fc1341028c136d3fe6fc5a62c6d8ad46da
BLAKE2b-256 checksum
How to use checksums
d0a731cbcff80fee0c92aff769badc94e7eb73177a515de95b8d3df25b136d6c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 7, 2026.

Transparency log

Release files / posteriors-0.1.3-py3-none-any.whl

Download URL posteriors-0.1.3-py3-none-any.whl
Size 53.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dd31fa6a901bf220aea5ab7829e9aa13366dfd25016efdc33509a16504512c01
BLAKE2b-256 checksum
How to use checksums
a4f99d3367706e34a57d144f14fb09b1bb11f9fc90e895fa47bad6b49237034c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 7, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

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