Skip to main content

The laplace package facilitates the application of Laplace approximations for entire neural networks, subnetworks of neural networks, or just their last layer. The package enables posterior approximations, marginal-likelihood estimation, and various posterior predictive computations. It includes both weight-space and function-space Laplace approximations.

There is also a corresponding paper, Laplace Redux — Effortless Bayesian Deep Learning, which introduces the library, provides an introduction to the Laplace approximation, reviews its use in deep learning, and empirically demonstrates its versatility and competitiveness. Please consider referring to the paper when using our library:

@inproceedings{laplace2021,
  title={Laplace Redux--Effortless {B}ayesian Deep Learning},
  author={Erik Daxberger and Agustinus Kristiadi and Alexander Immer
          and Runa Eschenhagen and Matthias Bauer and Philipp Hennig},
  booktitle={{N}eur{IPS}},
  year={2021}
}

The code to reproduce the experiments in the paper is also publicly available; it provides examples of how to use our library for predictive uncertainty quantification, model selection, and continual learning.

Installation

To install laplace with pip, run the following:

pip install laplace-torch

To use changes in this repository before they appear in a published release, clone the repository and install it from the checkout:

pip install -e .

The default backend, Curvlinops, is always installed. The ASDL and BackPACK backends are optional extras:

pip install "laplace-torch[asdl]"      # AsdlGGN, AsdlEF, AsdlHessian
pip install "laplace-torch[backpack]"  # BackPackGGN, BackPackEF
pip install "laplace-torch[all]"       # both

Extras can be combined, e.g. pip install "laplace-torch[asdl,backpack]". Curvlinops currently depends on BackPACK, so a plain install still pulls it in.

The old asdfghjkl backend, which LowRankLaplace needs, is not on PyPI. Install it via:

pip install git+https://git@github.com/wiseodd/asdl@asdfghjkl

Simple usage

In the following example, a pre-trained model is loaded, then the Laplace approximation is fit to the training data (using a diagonal Hessian approximation over all parameters), and the prior precision is optimized with cross-validation "gridsearch". After that, the resulting LA is used for prediction with the "probit" predictive for classification.

from laplace import Laplace

# Pre-trained model
model = load_map_model()

# User-specified LA flavor
la = Laplace(model, "classification",
             subset_of_weights="all",
             hessian_structure="diag")
la.fit(train_loader)
la.optimize_prior_precision(
    method="gridsearch",
    pred_type="glm",
    link_approx="probit",
    val_loader=val_loader
)

# User-specified predictive approx.
pred = la(x, pred_type="glm", link_approx="probit")

Contributing

Pull requests are very welcome. Please follow the guidelines in https://aleximmer.github.io/Laplace/devs_guide

Metadata

Release files for laplace-torch 0.5

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

Source distribution (sdist)

Source distribution for laplace-torch 0.5
File Size Uploaded Provenance Actions
laplace_torch-0.5.tar.gz 144.9 kB Without provenance Details for laplace_torch-0.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for laplace-torch 0.5
File Interpreter ABI Platform Actions
laplace_torch-0.5-py3-none-any.whl Python 3 none any Details for laplace_torch-0.5-py3-none-any.whl

Total release size: 303.7 kB

Release files / laplace_torch-0.5.tar.gz

Download URL laplace_torch-0.5.tar.gz
Size 144.9 kB
Tags Source
SHA-256 checksum
How to use checksums
1c9a843f445bb5814662738a09c810afe310bc9db0bde6271b76cd660759adb4
BLAKE2b-256 checksum
How to use checksums
239611599bb582c2057b744a35b99ac624c63e8d258fa09b8e082de52e1f5a5f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"NixOS","version":"26.05","id":"yarara","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / laplace_torch-0.5-py3-none-any.whl

Download URL laplace_torch-0.5-py3-none-any.whl
Size 158.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
383275060450bc40c9f61b3499aefa96b2900326f3a31ca8eda0b34ecb828993
BLAKE2b-256 checksum
How to use checksums
bfad6637605471d1b16e0abdb0f36f093b5f5049caddfd37bdf048bd4585e3bc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.21 {"installer":{"name":"uv","version":"0.11.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"NixOS","version":"26.05","id":"yarara","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for laplace-torch 0.5

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.

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