Library / SDK
aleximmer/Laplace avatar
aleximmer/Laplace

laplace-torch puts a Laplace approximation around a PyTorch model you already have

Laplace approximations for Deep Learning.

550 stars91 forksPythonMIT

At a glance

What is it?
The laplace package fits a Gaussian approximation over the weights of a neural network so you get predictive uncertainty, marginal-likelihood estimates and model selection on top of a trained PyTorch model. It suits a researcher who wants Bayesian-flavoured uncertainty without retraining from scratch, and it carries a warning from its own maintainers that nothing works out of the box.
Who is it for?
laplace-torch fits a researcher or engineer with a trained PyTorch model who needs predictive uncertainty, model selection or continual learning without re-running training. It does not fit a team expecting a default that works, because the maintainers state plainly that Laplace does not work automatically and the options have to be tuned per problem.
Can I use it commercially?
Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository last received commits 2 days ago.
What is it written in?
Mainly Python, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on October 22, 2026, and from our analysis. They are not legal advice.

Editorial analysis

What problem the package actually solves

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.

The problem it solves is that a standard trained network gives you a point estimate and no idea how wrong it might be. Bayesian deep learning would give you a posterior over weights, but retraining with variational inference or MCMC is a large, slow commitment. The Laplace approximation sits between the two: you keep the network you trained, and you approximate the posterior around that point with a Gaussian whose curvature comes from the Hessian of the loss.

That framing explains the audience. The user is someone who already has a trained model and wants uncertainty over its predictions, a marginal likelihood for model selection, or a way to do continual learning without forgetting, and who does not want to change the training pipeline. The topic tags on the repository match that intent exactly: approximate-bayesian-inference, deep-learning, laplace-approximation and neural-network.

The scope is broader than the classical use of the method. As well as the weight-space approximation, the package includes function-space estimators selected through `Laplace` with `subset_of_weights="all"` and `hessian_structure="gp"`: ELLA uses `functional_approximation="nystrom"`, while VaLLA uses `functional_approximation="variational"`.

The API is three calls: construct, fit, then predict

The surface area is small, and the README example shows the whole shape of it. You construct a `Laplace` object with the model, the task type and a choice of approximation flavour, you fit it to training data, you tune the prior precision, and then you predict.

python
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")

Reading that snippet tells you most of what you need. `subset_of_weights="all"` means the approximation covers every parameter rather than only the last layer. `hessian_structure="diag"` selects a diagonal Hessian approximation over all parameters, which is the cheap option. `la.fit(train_loader)` computes the curvature from the training data, `la.optimize_prior_precision` runs a grid search with cross-validation over the prior precision using a GLM predictive with a probit link, and the final call predicts with the same predictive setting.

The two knobs are separate on purpose. The Hessian structure decides how the curvature is approximated and what it costs to compute, while the prior precision decides how wide the posterior is, and the second is fitted rather than guessed because it matters a great deal for the resulting intervals.

The maintainers say explicitly that nothing works automatically

This is the most useful paragraph in the README, and it is flagged as IMPORTANT rather than buried.

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.

That list of options is the real API surface. `hessian_factorization` picks the linear algebra used to invert the Hessian, the prior precision tuning method decides whether the prior precision is optimised by grid search or left at a default, the predictive method decides how the posterior predictive is formed, and the backend decides which Hessian approximation library computes the curvature. Four axes, each with several choices, and the combinations interact.

The practical consequence for an adopter is that the library gives you the machinery and not the recipe. A sensible workflow is to read the papers the README points at for guidance on which combination suits your problem, treat the first set of intervals you get as provisional, and check them against something you can validate, such as a calibration curve. The repository ships an examples directory that includes a calibration example and a calibration example for the GP variant, which is a hint about what the maintainers consider the natural sanity check.

Weight space and function space, two different routes to the same goal

Most Laplace work in deep learning approximates the posterior over weights. The package also supports estimators that work in function space, which is a different route to the same predictive uncertainty.

The README points at two of them. ELLA, documented in docs/ella.md, uses `functional_approximation="nystrom"`, which means the approximation is built from a Nystrom approximation rather than from a direct weight-space Hessian. VaLLA, documented in docs/valla.md, uses `functional_approximation="variational"`. Both are selected through the same `Laplace` constructor, with `subset_of_weights="all"` and `hessian_structure="gp"`.

The reason this distinction matters is computational. The weight-space route needs curvature for every parameter, which is fine for a small last layer and expensive for a full network. A function-space estimator sidesteps that by working in the space of model outputs, which is where the predictive lives anyway. If your model is large and you need uncertainty on every input, that difference can be the difference between something that fits on a single GPU and something that does not.

The repository carries runnable scripts for both, with examples/ella.py and examples/valla.py, plus a bayesopt_example.py and a reward_modeling_example.py, so the intended use is not limited to plain classification.

Installing it, and the optional backend

The package is published to PyPI as `laplace-torch`, so the normal install is one command.

bash
pip install laplace-torch

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

bash
pip install -e .

And there is a third path, for a specific backend. The README says that if you want to use the `asdfghjkl` backend, install it via a git URL rather than from PyPI.

bash
pip install git+https://[email protected]/wiseodd/asdl@asdfghjkl

The pinned dependencies give you a sense of the size of the install. `torch >= 2.0` and `torchvision >= 0.15` pull in PyTorch, and alongside them come `asdfghjkl == 0.1a4`, `backpack-for-pytorch`, `curvlinops-for-pytorch >= 3.0.1`, `scipy >= 1.12`, `numpy`, `tqdm >= 4.66`, `opt_einsum`, `torchmetrics` and `torchvision`. Python must be 3.10 or newer, and the classifiers list 3.10, 3.11 and 3.12. The build backend is `uv_build`, and the repository carries a uv.lock and a uv_overrides.txt, so a reproducible environment is available for anyone using uv.

One detail to plan around: `asdfghjkl` is pinned to the alpha release `0.1a4`, and the optional git install above pulls a branch of the same project. If you maintain a curated dependency set, an alpha-pinned package in the tree is worth raising early.

Version 0.3, an alpha status, and a licence that is easy to live with

The package metadata describes itself honestly. The version is 0.3, the classifier reads Development Status:: 3 - Alpha, and the operating system classifier is OS Independent. The description field is plain: laplace - Laplace approximations for deep learning.

The release history shows the pace. Version 0.3 was released on 2026-10-13, 0.2.3 on 2026-10-03, and before that 0.2.2.2 on 2024-11-27. So a long gap, then two releases ten days apart, and the last push to the repository was on 2026-10-20. The project is not archived and is being worked on.

The licence is MIT, which is the least restrictive option and means the code can be used inside a commercial or closed product without obligations beyond keeping the notice. That matters more than usual for a library that sits inside a training or serving stack, since there is no copyleft requirement that would make you publish your own service code.

The development setup is conventional and well signposted. There is a makefile, pytest with testpaths set to tests and a cuda marker for tests that need an NVIDIA GPU, ruff for linting and formatting, and a docs dependency group pinning mkdocs 1.6.1, its theme at 9.5.34 and mkdocstrings. The developer guide is at aleximmer.github.io/Laplace/devs_guide, and pull requests are welcomed.

The documentation site is the real API reference, with separate pages for ELLA and VaLLA under docs/, and it is where you should look before writing the options yourself.

The paper, the reference code, and where this approach stops being the right one

The project is tied to a specific publication, and the README asks you to cite it. The paper Laplace Redux, by Daxberger, Kristiadi, Immer, Eschenhagen, Bauer and Hennig, at NeurIPS 2021, introduces the library, gives an introduction to the Laplace approximation, reviews its use in deep learning and argues for its versatility. The BibTeX entry is in the README, and the code that reproduces the paper's experiments is published separately at github.com/runame/laplace-redux, with examples for predictive uncertainty quantification, model selection and continual learning.

That separate repository is worth a look before you commit, because it shows what the authors considered a working configuration for each task, which is exactly the guidance the IMPORTANT note tells you to get from the literature.

The limits are real and worth stating plainly. A Laplace approximation is a local approximation around the mode, so it says little about a far-away region of weight space, and a network trained with a wide flat basin and one trained into a sharp minimum are not approximated equally well. The diagonal Hessian over all parameters, which the README example uses, discards the correlations between weights that a full Hessian would capture, so the uncertainty can be overconfident in directions the network actually uses. And the whole computation needs curvature information, which for a large model means extra passes over the data or an approximation scheme of its own.

The alternative approach with a different shape is the ensemble route: train several models with different seeds and read the disagreement between them as uncertainty. It costs several training runs, but it needs no Hessian and no tuning of a prior precision, and it degrades more gracefully. A variational method is the other comparison point, and it is the one the package is explicitly positioned against, since the whole argument of Laplace Redux is that post-hoc approximation on an existing network beats changing the training objective. For model selection specifically, the marginal-likelihood estimation the package provides is the reason to choose it over an ensemble, since ensembles do not give you a comparable score.

Editorial conclusion

laplace-torch fits a researcher or engineer with a trained PyTorch model who needs predictive uncertainty, model selection or continual learning without re-running training. It does not fit a team expecting a default that works, because the maintainers state plainly that Laplace does not work automatically and the options have to be tuned per problem. Install with `pip install laplace-torch`, and before trusting any number, reproduce the README example on your own model and confirm the prior precision search in `optimize_prior_precision` gives a sensible result, since a badly chosen prior precision silently widens or narrows every posterior interval.

Frequently asked questions

How do I install laplace-torch?

Run `pip install laplace-torch` for the published release, or clone the repository and run `pip install -e .` to use changes before they appear in a release. The optional `asdfghjkl` backend is installed from a git URL. Python 3.10 or newer is required, and the package pulls in torch 2.0 or newer.

What does the Laplace class in laplace-torch do?

You construct it with your model, a task type and a flavour such as `subset_of_weights="all"` with `hessian_structure="diag"`, then call `fit` to compute the curvature from training data, `optimize_prior_precision` to tune the prior precision, and the object itself to predict with a chosen predictive method.

Does laplace-torch work out of the box?

The maintainers say it does not. The README states that one should not expect Laplace to work automatically and should experiment with the options, including hessian_factorization, the prior precision tuning method, the predictive method and the backend, and look at papers that use Laplace for guidance on setting them.

What is the difference between ELLA and VaLLA in the laplace package?

Both are function-space estimators selected through the `Laplace` constructor with `subset_of_weights="all"` and `hessian_structure="gp"`. ELLA uses `functional_approximation="nystrom"` and VaLLA uses `functional_approximation="variational"`, and each has its own page under docs/.

What licence is laplace-torch under?

MIT, as declared in pyproject.toml and the LICENSE.txt file at the repository root. The package metadata lists the development status as 3 - Alpha at version 0.3, released on 2026-10-13.

Official sources

  1. aleximmer/Laplace on GitHub
  2. License: MIT
  3. Project website
  4. README
  5. Releases
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/aleximmer-laplace.svg)](https://hysenlabs.com/projects/aleximmer-laplace)

Was this useful?