Skip to main content

laplacekit

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.

Docs Quickstart In depth Plugins
Python 3.11+ PyTorch 2.15+ License: MIT

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 class lk.KFAC instead of an instance, raises a TypeError that tells what's the correct argument.
  • print(post) shows every choice a fit made.
  • lk.testing checks a new plugin against its interface and the laws it must satisfy.
  • print(lk.health()) reports whether the install works: the torch version, the curvlinops pin, 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.0

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

Source distribution (sdist)

Source distribution for laplacekit 1.0.0
File Size Uploaded Provenance Actions
laplacekit-1.0.0.tar.gz 176.7 kB With provenance Details for laplacekit-1.0.0.tar.gz

Built distribution (wheel)

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

Total release size: 370.0 kB

Release files / laplacekit-1.0.0.tar.gz

Download URL laplacekit-1.0.0.tar.gz
Size 176.7 kB
Tags Source
SHA-256 checksum
How to use checksums
59ddc72862dabdbf879d388d2ea6100f8d7c120a316ea4cdd92230d01d2acc8c
BLAKE2b-256 checksum
How to use checksums
b598eeb5b4b50bb8b8ed9285ba4959f80b25428bdf2c8c522a3cad35e59eabf5
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 Nov 30, 2026.

Transparency log

Release files / laplacekit-1.0.0-py3-none-any.whl

Download URL laplacekit-1.0.0-py3-none-any.whl
Size 193.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
39fc9f72c6fdabc7d225bebd57dcaa6ba797c37cff22fb6fd9c93caa7129c699
BLAKE2b-256 checksum
How to use checksums
1cf5c4e8319acc7f144828bbce4f09ab232c4b6cfe96ba74bd53f89e5d3ea10b
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 Nov 30, 2026.

Transparency log

Security for laplacekit 1.0.0

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.

Select from 2 files

Attestation for laplacekit-1.0.0.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 Nov 30, 2026.

Transparency log

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