An extensible, modern Laplace-approximation library for PyTorch, built on a plugin system. It supports modern models: Hugging Face LLMs, diffusion models, and reward models.
Install
pip install laplacekit
First-party plugins
The first-party plugins cover Hugging Face transformers and diffusers models, reward models (Bradley–Terry likelihood), subnetwork Laplace, heteroscedastic Laplace, function-space (GP) Laplace, and marginal-likelihood training.
To install all of them:
pip install "laplacekit[all]"
Or one at a time:
pip install "laplacekit[transformers]"
pip install "laplacekit[diffusers]"
pip install "laplacekit[subnet]"
pip install "laplacekit[heteroscedastic]"
pip install "laplacekit[reward]"
pip install "laplacekit[gp]"
pip install "laplacekit[marglik]"
Usage
Train your model as usual. Then fit the Laplace approximation and predict:
import laplacekit as lk
# Multi-class classification, last layer, tuned prior
posterior = lk.laplace(model, train_loader, lk.Categorical())
# Predicted probabilities
probs = lk.predict(posterior, x_test).probs
You can specify what kind of Laplace approximation do you want, and the resulting posterior can be saved and loaded:
# Fit the posterior
post = lk.laplace(
model,
train_loader,
lk.Gaussian(), # Gaussian likelihood for regression
hessian_approx=lk.KFAC(),
subset=lk.subsets.all,
prior=lk.priors.Layerwise(),
hyper_tuner=lk.GridSearch(lk.objectives.predictive_nll(val_loader), values=lams),
)
# Save the posterior
lk.save(post, "post.pt")
# Load the posterior
post = lk.load("post.pt", model)
What's new?
Plugin system. Think Neovim or VS Code: a new Laplace method (e.g., function-space) or component (e.g., curvature, likelihood, etc.) is a plugin/extension.
In Python's lingo: it's a PyPI package that satisfies laplacekit's protocols.
laplacekit is aware of the installed plugins: print(lk.plugins())---see documentation.
Similar to Neovim's :checkhealth command, print(lk.health()) tells us whether plugins are installed correctly or not.
The built-in methods are written the same way, against the same public interfaces, with no special access. So a third-party plugin is a first-class citizen.
Difference compared to other Laplace libraries:
Extending laplace-torch means subclassing BaseLaplace (a few thousand lines) and sending a PR.
laplax's and posteriors's functions can be freely composed, but there is no plugin host.
How it compares
laplacekit |
laplace-torch |
laplax |
posteriors |
|
|---|---|---|---|---|
| Framework | PyTorch | PyTorch | JAX | PyTorch |
| LLMs (Hugging Face, LoRA) without special code | ✅ | 🟡 | 🟡 | ✅ |
| Diffusion models | ✅ | ❌ | 🟡 | ❓ |
| Fit from your own training loop | ✅ | ❌ | ❓ | ✅ |
| Fully type-checked, with typed extension points | ✅ | ❌ | ❓ | ❓ |
| Options as typed objects and checked literals | ✅ | ❌ | ❌ | ✅ |
| Differentiate through the whole fit | ✅ | ❌ | ✅ | ✅ |
| Diagonal and full curvature | ✅ | ✅ | ✅ | ✅ |
| KFAC | ✅ | ✅ | ❌ | ❌ |
| Low-rank curvature | ✅ | ✅ | ✅ | ❌ |
| Last-layer Laplace | ✅ | ✅ | ❓ | ✅ |
| Subnetwork Laplace | ✅ | ✅ | ❓ | ✅ |
| Function-space (GP) Laplace | ✅ | ✅ | ❓ | ❌ |
| Linearized predictive | ✅ | ✅ | ✅ | 🟡 |
| Marginal-likelihood tuning | ✅ | ✅ | ✅ | ❌ |
| Marglik training | ✅ | ✅ | ❓ | ❓ |
✅ yes · 🟡 partly · ❌ no · ❓ not checked. Details on the Why page.
Agent workflow
laplacekit is designed so that a coding agent can write a new Laplace method without reading the core:
- Each extension point is a small typed interface---everything is typecheckable via
ty check. Perfect for harnessing agents. - Errors say what is missing and what would work instead, so the agent can correct its own mistakes easily.
For example, a wrong argument type, such as
hessian_approx="kron"or the classlk.KFACinstead of an instance, raises aTypeErrorthat tells what's the correct argument. print(post)shows every choice a fit made.lk.testingchecks a new plugin against its interface and the laws it must satisfy.print(lk.health())reports whether the install works: the torch version, thecurvlinopspin, autograd on a small model, float64, and each plugin's own checks.- The docs have an
llms.txt.
Citation
To cite laplacekit:
@software{kristiadi2026laplacekit,
author = {Kristiadi, Agustinus},
title = {{laplacekit}: An Extensible, Modern {Laplace}-Approximation Library for {PyTorch}},
year = {2026},
url = {https://github.com/laplacekit/laplacekit},
}
Metadata
Release files for laplacekit 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| laplacekit-1.0.1.tar.gz | 176.7 kB | With provenance | Details for laplacekit-1.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| laplacekit-1.0.1-py3-none-any.whl | Python 3 | none | any | Details for laplacekit-1.0.1-py3-none-any.whl |
Total release size: 370.0 kB
Release files / laplacekit-1.0.1.tar.gz
| Download URL | laplacekit-1.0.1.tar.gz |
|---|---|
| Size | 176.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
99198f7a59607c4f13a5ddc602184cae35edd6d42582e8eb876e076b6c2f6de6
|
|
BLAKE2b-256 checksum How to use checksums |
c50e84aa2d13a72e957683d6550bfe43813a2dcc9f04292709007bdf01d03874
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Dec 1, 2026.
Transparency logRelease files / laplacekit-1.0.1-py3-none-any.whl
| Download URL | laplacekit-1.0.1-py3-none-any.whl |
|---|---|
| Size | 193.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d212761c712e1d60cfd6694d6fda0dcd4e4d47cee1c8dfee26d29057141fb62a
|
|
BLAKE2b-256 checksum How to use checksums |
e71bd1276f861f79e46be519fadee07cb0dd0b26fce6d4ce77a5426722b56a8f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Dec 1, 2026.
Transparency logSecurity for laplacekit 1.0.1
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for laplacekit-1.0.1.tar.gz
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 Dec 1, 2026.
Transparency logA 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.