Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

laplacekit

An extensible, modern Laplace-approximation library for PyTorch, built on a plugin system. Modern models like HuggingFace LLMs, diffusion models, reward models are supported.

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

Install

pip install laplacekit

First-party plugins

Available first party plugins are: HuggingFace's transformers, diffusers models, reward models (Bradley-Terry likelihood), subnetwork Laplace, heteroscedastic Laplace, function-space GP-Laplace, and marginal-likelihood-based Laplace.

Install all of them:

pip install "laplacekit[all]"

Or individually:

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 the model as usual, then fit 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

Various arguments, including serialization:

# 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),
)

# Saving 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 is a package: install it with pip and pass it to lk.laplace. The built-in methods are written the exact same way, against the same public interfaces, with no special access. So a third-party method is a first-class citizen, and several plugins can be mixed in one fit. Extending laplace-torch means subclassing BaseLaplace (a few thousand lines) and sending a PR. laplax and posteriors are libraries of functions: they can be composed, or a new method written from scratch, 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 in its own file, and ty tells the agent it got something wrong in seconds.
  • Errors say what's missing and what would work instead, so the agent can fix its own mistakes. A wrong argument type, such as hessian_approx="kron" or the class lk.KFAC for an instance, raises a TypeError that names what to pass.
  • print(post) shows every choice a fit made, and torch.manual_seed (or a generator= argument) makes reruns identical, as in torch.
  • 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.

Metadata

Release files for laplacekit 0.1a0

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 0.1a0
File Size Uploaded Provenance Actions
laplacekit-0.1a0.tar.gz 175.1 kB Without provenance Details for laplacekit-0.1a0.tar.gz

Built distribution (wheel)

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

Total release size: 366.6 kB

Release files / laplacekit-0.1a0.tar.gz

Download URL laplacekit-0.1a0.tar.gz
Size 175.1 kB
Tags Source
SHA-256 checksum
How to use checksums
dbd507a37a3128d0e0cf8db59b9f273830c3e7c56a7e3ffdcff34568afe4765a
BLAKE2b-256 checksum
How to use checksums
7e4001ef44cf112f8f6b135ea861867ad5dea035b4248ff9656514c3910ac803
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 / laplacekit-0.1a0-py3-none-any.whl

Download URL laplacekit-0.1a0-py3-none-any.whl
Size 191.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f053ae7f5c8d705736ae127397cefd0d442409debde8f113df90c25706d5b077
BLAKE2b-256 checksum
How to use checksums
ed92926260dfba1329df45d7ca483a2eda3d1be72d5d8d87ec789fe0dcf21cdc
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 laplacekit 0.1a0

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