aleximmer/Laplace
aleximmer/Laplace has 553 GitHub stars and 94 forks. GitHot measured 0 stars in 24 hours and +1 in 7 days. Last checked 2026-11-21 12:37 UTC. Last push 2026-11-12.
Measured star growth
- in 24h
- 0
- in 7 days
- +1
- in 15 days
- Collecting history
- in 1 month
- Collecting history
Net star changes over overlapping periods, not daily totals. Missing measurements are left blank. Stars measure attention, not software quality.
About
Laplace approximations for Deep Learning.
Machine LearningREADME.md
OriginalThe 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.
[!IMPORTANT] As a user, one should not expect Laplace to work automatically. That is, one should experiment with different Laplace's options (hessian_factorization, prior precision tuning method, predictive method, backend, etc!). Try looking at various papers that use Laplace for references on how to set all those options depending on the applications/problems at hand.
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://[email protected]/wiseodd/asdl@asdfghjkl
Simple usage
[!TIP] Check out https://aleximmer.github.io/Laplace for more usage examples and API reference.
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 CategoricalLikelihood, Laplace
# Pre-trained model
model = load_map_model()
# User-specified LA flavor
la = Laplace(model, CategoricalLikelihood(),
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
[!WARNING] AI-assisted contributions are welcome, but you must understand the problem you are solving. You must also understand the solutions your AI agent proposes and review them yourself. When opening a PR, you must write the description yourself. First-time contributors must disclose their AI usage and confirm that they understand the changes.
Explore related projects
Loading…
