laplacekit 0.1a0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- laplacekit-0.1a0/PKG-INFO +183 -0
- laplacekit-0.1a0/README.md +143 -0
- laplacekit-0.1a0/pyproject.toml +212 -0
- laplacekit-0.1a0/pyproject.toml.orig +158 -0
- laplacekit-0.1a0/src/laplacekit/__init__.py +169 -0
- laplacekit-0.1a0/src/laplacekit/_health.py +461 -0
- laplacekit-0.1a0/src/laplacekit/core/__init__.py +263 -0
- laplacekit-0.1a0/src/laplacekit/core/_functorch.py +55 -0
- laplacekit-0.1a0/src/laplacekit/core/_pytree.py +213 -0
- laplacekit-0.1a0/src/laplacekit/core/_seed.py +169 -0
- laplacekit-0.1a0/src/laplacekit/core/curvature.py +1032 -0
- laplacekit-0.1a0/src/laplacekit/core/fit.py +896 -0
- laplacekit-0.1a0/src/laplacekit/core/layout.py +150 -0
- laplacekit-0.1a0/src/laplacekit/core/likelihoods.py +869 -0
- laplacekit-0.1a0/src/laplacekit/core/model.py +100 -0
- laplacekit-0.1a0/src/laplacekit/core/ops.py +1583 -0
- laplacekit-0.1a0/src/laplacekit/core/posteriors.py +2013 -0
- laplacekit-0.1a0/src/laplacekit/core/predictive.py +140 -0
- laplacekit-0.1a0/src/laplacekit/core/probe.py +457 -0
- laplacekit-0.1a0/src/laplacekit/core/random.py +96 -0
- laplacekit-0.1a0/src/laplacekit/core/serialize.py +655 -0
- laplacekit-0.1a0/src/laplacekit/core/subsets.py +260 -0
- laplacekit-0.1a0/src/laplacekit/core/tree.py +5 -0
- laplacekit-0.1a0/src/laplacekit/core/tuning.py +401 -0
- laplacekit-0.1a0/src/laplacekit/core/types.py +390 -0
- laplacekit-0.1a0/src/laplacekit/curvature.py +1687 -0
- laplacekit-0.1a0/src/laplacekit/curvlinops.py +616 -0
- laplacekit-0.1a0/src/laplacekit/data.py +213 -0
- laplacekit-0.1a0/src/laplacekit/distributed.py +5 -0
- laplacekit-0.1a0/src/laplacekit/front.py +510 -0
- laplacekit-0.1a0/src/laplacekit/function_space.py +1031 -0
- laplacekit-0.1a0/src/laplacekit/likelihoods.py +759 -0
- laplacekit-0.1a0/src/laplacekit/objectives.py +388 -0
- laplacekit-0.1a0/src/laplacekit/predictive.py +1095 -0
- laplacekit-0.1a0/src/laplacekit/priors.py +934 -0
- laplacekit-0.1a0/src/laplacekit/py.typed +0 -0
- laplacekit-0.1a0/src/laplacekit/subsets.py +181 -0
- laplacekit-0.1a0/src/laplacekit/testing.py +1325 -0
- laplacekit-0.1a0/src/laplacekit/tuning.py +386 -0
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: laplacekit
|
|
3
|
+
Version: 0.1a0
|
|
4
|
+
Summary: Extensible, modern Laplace-approximation library for PyTorch, built on a plugin system.
|
|
5
|
+
Author: Agustinus Kristiadi
|
|
6
|
+
Author-email: Agustinus Kristiadi <agustinus@kristia.de>
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
Classifier: Development Status :: 3 - Alpha
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
12
|
+
Requires-Dist: curvlinops-for-pytorch==3.0.1
|
|
13
|
+
Requires-Dist: packaging>=24
|
|
14
|
+
Requires-Dist: torch>=2.15
|
|
15
|
+
Requires-Dist: laplacekit-transformers ; extra == 'all'
|
|
16
|
+
Requires-Dist: laplacekit-diffusers ; extra == 'all'
|
|
17
|
+
Requires-Dist: laplacekit-subnet ; extra == 'all'
|
|
18
|
+
Requires-Dist: laplacekit-heteroscedastic ; extra == 'all'
|
|
19
|
+
Requires-Dist: laplacekit-reward ; extra == 'all'
|
|
20
|
+
Requires-Dist: laplacekit-gp ; extra == 'all'
|
|
21
|
+
Requires-Dist: laplacekit-marglik ; extra == 'all'
|
|
22
|
+
Requires-Dist: laplacekit-diffusers ; extra == 'diffusers'
|
|
23
|
+
Requires-Dist: laplacekit-gp ; extra == 'gp'
|
|
24
|
+
Requires-Dist: laplacekit-heteroscedastic ; extra == 'heteroscedastic'
|
|
25
|
+
Requires-Dist: laplacekit-marglik ; extra == 'marglik'
|
|
26
|
+
Requires-Dist: laplacekit-reward ; extra == 'reward'
|
|
27
|
+
Requires-Dist: laplacekit-subnet ; extra == 'subnet'
|
|
28
|
+
Requires-Dist: laplacekit-transformers ; extra == 'transformers'
|
|
29
|
+
Requires-Python: >=3.13
|
|
30
|
+
Project-URL: Homepage, https://laplacekit.org
|
|
31
|
+
Provides-Extra: all
|
|
32
|
+
Provides-Extra: diffusers
|
|
33
|
+
Provides-Extra: gp
|
|
34
|
+
Provides-Extra: heteroscedastic
|
|
35
|
+
Provides-Extra: marglik
|
|
36
|
+
Provides-Extra: reward
|
|
37
|
+
Provides-Extra: subnet
|
|
38
|
+
Provides-Extra: transformers
|
|
39
|
+
Description-Content-Type: text/markdown
|
|
40
|
+
|
|
41
|
+
<p align="center">
|
|
42
|
+
<picture>
|
|
43
|
+
<source media="(prefers-color-scheme: dark)" srcset="docs/assets/wordmark-dark.svg">
|
|
44
|
+
<img alt="laplacekit" src="docs/assets/wordmark-light.svg" width="330">
|
|
45
|
+
</picture>
|
|
46
|
+
</p>
|
|
47
|
+
|
|
48
|
+
<p align="center">
|
|
49
|
+
An extensible, modern <b>Laplace-approximation library</b> for PyTorch, built on a <b>plugin system</b>.
|
|
50
|
+
Modern models like HuggingFace LLMs, diffusion models, reward models are supported.
|
|
51
|
+
</p>
|
|
52
|
+
|
|
53
|
+
<p align="center">
|
|
54
|
+
<a href="https://laplacekit.org"><img alt="Docs" src="https://img.shields.io/badge/docs-laplacekit.org-1f6feb?style=for-the-badge"></a>
|
|
55
|
+
<a href="https://laplacekit.org/quickstart/basics.html"><img alt="Quickstart" src="https://img.shields.io/badge/quickstart-1f6feb?style=for-the-badge"></a>
|
|
56
|
+
<a href="https://laplacekit.org/examples/classification.html"><img alt="In depth" src="https://img.shields.io/badge/in%20depth-1f6feb?style=for-the-badge"></a>
|
|
57
|
+
<a href="https://laplacekit.org/plugins/overview.html"><img alt="Plugins" src="https://img.shields.io/badge/plugins-1f6feb?style=for-the-badge"></a>
|
|
58
|
+
<br>
|
|
59
|
+
<img alt="Python 3.13+" src="https://img.shields.io/badge/python-3.13%2B-3776ab?style=for-the-badge&logo=python&logoColor=white">
|
|
60
|
+
<img alt="PyTorch 2.15+" src="https://img.shields.io/badge/pytorch-2.15%2B-ee4c2c?style=for-the-badge&logo=pytorch&logoColor=white">
|
|
61
|
+
<a href="LICENSE"><img alt="License: MIT" src="https://img.shields.io/badge/license-MIT-555555?style=for-the-badge"></a>
|
|
62
|
+
</p>
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
## Install
|
|
66
|
+
|
|
67
|
+
```bash
|
|
68
|
+
pip install laplacekit
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## First-party plugins
|
|
72
|
+
|
|
73
|
+
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.
|
|
74
|
+
|
|
75
|
+
Install all of them:
|
|
76
|
+
|
|
77
|
+
```bash
|
|
78
|
+
pip install "laplacekit[all]"
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Or individually:
|
|
82
|
+
|
|
83
|
+
```bash
|
|
84
|
+
pip install "laplacekit[transformers]"
|
|
85
|
+
pip install "laplacekit[diffusers]"
|
|
86
|
+
pip install "laplacekit[subnet]"
|
|
87
|
+
pip install "laplacekit[heteroscedastic]"
|
|
88
|
+
pip install "laplacekit[reward]"
|
|
89
|
+
pip install "laplacekit[gp]"
|
|
90
|
+
pip install "laplacekit[marglik]"
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Usage
|
|
94
|
+
|
|
95
|
+
Train the model as usual, then fit and predict:
|
|
96
|
+
|
|
97
|
+
```python
|
|
98
|
+
import laplacekit as lk
|
|
99
|
+
|
|
100
|
+
# Multi-class classification, last layer, tuned prior
|
|
101
|
+
posterior = lk.laplace(model, train_loader, lk.Categorical())
|
|
102
|
+
|
|
103
|
+
# Predicted probabilities
|
|
104
|
+
probs = lk.predict(posterior, x_test).probs
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Various arguments, including serialization:
|
|
108
|
+
|
|
109
|
+
```python
|
|
110
|
+
# Fit the posterior
|
|
111
|
+
post = lk.laplace(
|
|
112
|
+
model,
|
|
113
|
+
train_loader,
|
|
114
|
+
lk.Gaussian(), # Gaussian likelihood for regression
|
|
115
|
+
hessian_approx=lk.KFAC(),
|
|
116
|
+
subset=lk.subsets.all,
|
|
117
|
+
prior=lk.priors.Layerwise(),
|
|
118
|
+
hyper_tuner=lk.GridSearch(lk.objectives.predictive_nll(val_loader), values=lams),
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
# Saving the posterior
|
|
122
|
+
lk.save(post, "post.pt")
|
|
123
|
+
|
|
124
|
+
# Load the posterior
|
|
125
|
+
post = lk.load("post.pt", model)
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## What's new?
|
|
129
|
+
|
|
130
|
+
**Plugin system.** Think Neovim or VS Code. A new Laplace method is a package:
|
|
131
|
+
install it with `pip` and pass it to `lk.laplace`. The built-in methods
|
|
132
|
+
are written the exact same way, against the same public interfaces, with no
|
|
133
|
+
special access. So a third-party method is a first-class citizen, and several
|
|
134
|
+
plugins can be mixed in one fit. Extending `laplace-torch` means subclassing
|
|
135
|
+
`BaseLaplace` (a few thousand lines) and sending a PR. `laplax` and
|
|
136
|
+
`posteriors` are libraries of functions: they can be composed, or a new method
|
|
137
|
+
written from scratch, but there is no plugin host.
|
|
138
|
+
|
|
139
|
+
## How it compares
|
|
140
|
+
|
|
141
|
+
| | <code><b>laplacekit</b></code> | [`laplace-torch`](https://github.com/aleximmer/Laplace) | [`laplax`](https://github.com/laplax-org/laplax) | [`posteriors`](https://github.com/normal-computing/posteriors) |
|
|
142
|
+
| --- | :---: | :---: | :---: | :---: |
|
|
143
|
+
| Framework | PyTorch | PyTorch | JAX | PyTorch |
|
|
144
|
+
| LLMs (Hugging Face, LoRA) without special code | ✅ | 🟡 | 🟡 | ✅ |
|
|
145
|
+
| Diffusion models | ✅ | ❌ | 🟡 | ❓ |
|
|
146
|
+
| Fit from your own training loop | ✅ | ❌ | ❓ | ✅ |
|
|
147
|
+
| Fully type-checked, with typed extension points | ✅ | ❌ | ❓ | ❓ |
|
|
148
|
+
| Options as typed objects and checked literals | ✅ | ❌ | ❌ | ✅ |
|
|
149
|
+
| Differentiate through the whole fit | ✅ | ❌ | ✅ | ✅ |
|
|
150
|
+
| Diagonal and full curvature | ✅ | ✅ | ✅ | ✅ |
|
|
151
|
+
| KFAC | ✅ | ✅ | ❌ | ❌ |
|
|
152
|
+
| Low-rank curvature | ✅ | ✅ | ✅ | ❌ |
|
|
153
|
+
| Last-layer Laplace | ✅ | ✅ | ❓ | ✅ |
|
|
154
|
+
| Subnetwork Laplace | ✅ | ✅ | ❓ | ✅ |
|
|
155
|
+
| Function-space (GP) Laplace | ✅ | ✅ | ❓ | ❌ |
|
|
156
|
+
| Linearized predictive | ✅ | ✅ | ✅ | 🟡 |
|
|
157
|
+
| Marginal-likelihood tuning | ✅ | ✅ | ✅ | ❌ |
|
|
158
|
+
| Marglik training | ✅ | ✅ | ❓ | ❓ |
|
|
159
|
+
|
|
160
|
+
✅ yes · 🟡 partly · ❌ no · ❓ not checked. Details on the [Why page](https://laplacekit.org/why.html#how-it-compares).
|
|
161
|
+
|
|
162
|
+
> [!TIP]
|
|
163
|
+
> Coming from `laplace-torch`? The [Why page](https://laplacekit.org/why.html#coming-from-laplace-torch)
|
|
164
|
+
> maps its API to <code><b>laplacekit</b></code>.
|
|
165
|
+
|
|
166
|
+
## Agent workflow
|
|
167
|
+
|
|
168
|
+
<code><b>laplacekit</b></code> is designed so that a coding agent can write a new Laplace
|
|
169
|
+
method without reading the core:
|
|
170
|
+
|
|
171
|
+
- Each extension point is a small typed interface in its own file, and `ty`
|
|
172
|
+
tells the agent it got something wrong in seconds.
|
|
173
|
+
- Errors say what's missing _and_ what would work instead, so the agent can fix
|
|
174
|
+
its own mistakes. A wrong argument type, such as `hessian_approx="kron"` or
|
|
175
|
+
the class `lk.KFAC` for an instance, raises a `TypeError` that names what to
|
|
176
|
+
pass.
|
|
177
|
+
- `print(post)` shows every choice a fit made, and `torch.manual_seed` (or a
|
|
178
|
+
`generator=` argument) makes reruns identical, as in torch.
|
|
179
|
+
- `lk.testing` checks a new plugin against its interface and the laws it must
|
|
180
|
+
satisfy.
|
|
181
|
+
- `print(lk.health())` reports whether the install works: the torch version,
|
|
182
|
+
the `curvlinops` pin, autograd on a small model, float64, and each plugin's own
|
|
183
|
+
checks.
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<picture>
|
|
3
|
+
<source media="(prefers-color-scheme: dark)" srcset="docs/assets/wordmark-dark.svg">
|
|
4
|
+
<img alt="laplacekit" src="docs/assets/wordmark-light.svg" width="330">
|
|
5
|
+
</picture>
|
|
6
|
+
</p>
|
|
7
|
+
|
|
8
|
+
<p align="center">
|
|
9
|
+
An extensible, modern <b>Laplace-approximation library</b> for PyTorch, built on a <b>plugin system</b>.
|
|
10
|
+
Modern models like HuggingFace LLMs, diffusion models, reward models are supported.
|
|
11
|
+
</p>
|
|
12
|
+
|
|
13
|
+
<p align="center">
|
|
14
|
+
<a href="https://laplacekit.org"><img alt="Docs" src="https://img.shields.io/badge/docs-laplacekit.org-1f6feb?style=for-the-badge"></a>
|
|
15
|
+
<a href="https://laplacekit.org/quickstart/basics.html"><img alt="Quickstart" src="https://img.shields.io/badge/quickstart-1f6feb?style=for-the-badge"></a>
|
|
16
|
+
<a href="https://laplacekit.org/examples/classification.html"><img alt="In depth" src="https://img.shields.io/badge/in%20depth-1f6feb?style=for-the-badge"></a>
|
|
17
|
+
<a href="https://laplacekit.org/plugins/overview.html"><img alt="Plugins" src="https://img.shields.io/badge/plugins-1f6feb?style=for-the-badge"></a>
|
|
18
|
+
<br>
|
|
19
|
+
<img alt="Python 3.13+" src="https://img.shields.io/badge/python-3.13%2B-3776ab?style=for-the-badge&logo=python&logoColor=white">
|
|
20
|
+
<img alt="PyTorch 2.15+" src="https://img.shields.io/badge/pytorch-2.15%2B-ee4c2c?style=for-the-badge&logo=pytorch&logoColor=white">
|
|
21
|
+
<a href="LICENSE"><img alt="License: MIT" src="https://img.shields.io/badge/license-MIT-555555?style=for-the-badge"></a>
|
|
22
|
+
</p>
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
## Install
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
pip install laplacekit
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## First-party plugins
|
|
32
|
+
|
|
33
|
+
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.
|
|
34
|
+
|
|
35
|
+
Install all of them:
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
pip install "laplacekit[all]"
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Or individually:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
pip install "laplacekit[transformers]"
|
|
45
|
+
pip install "laplacekit[diffusers]"
|
|
46
|
+
pip install "laplacekit[subnet]"
|
|
47
|
+
pip install "laplacekit[heteroscedastic]"
|
|
48
|
+
pip install "laplacekit[reward]"
|
|
49
|
+
pip install "laplacekit[gp]"
|
|
50
|
+
pip install "laplacekit[marglik]"
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Usage
|
|
54
|
+
|
|
55
|
+
Train the model as usual, then fit and predict:
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
import laplacekit as lk
|
|
59
|
+
|
|
60
|
+
# Multi-class classification, last layer, tuned prior
|
|
61
|
+
posterior = lk.laplace(model, train_loader, lk.Categorical())
|
|
62
|
+
|
|
63
|
+
# Predicted probabilities
|
|
64
|
+
probs = lk.predict(posterior, x_test).probs
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Various arguments, including serialization:
|
|
68
|
+
|
|
69
|
+
```python
|
|
70
|
+
# Fit the posterior
|
|
71
|
+
post = lk.laplace(
|
|
72
|
+
model,
|
|
73
|
+
train_loader,
|
|
74
|
+
lk.Gaussian(), # Gaussian likelihood for regression
|
|
75
|
+
hessian_approx=lk.KFAC(),
|
|
76
|
+
subset=lk.subsets.all,
|
|
77
|
+
prior=lk.priors.Layerwise(),
|
|
78
|
+
hyper_tuner=lk.GridSearch(lk.objectives.predictive_nll(val_loader), values=lams),
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
# Saving the posterior
|
|
82
|
+
lk.save(post, "post.pt")
|
|
83
|
+
|
|
84
|
+
# Load the posterior
|
|
85
|
+
post = lk.load("post.pt", model)
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## What's new?
|
|
89
|
+
|
|
90
|
+
**Plugin system.** Think Neovim or VS Code. A new Laplace method is a package:
|
|
91
|
+
install it with `pip` and pass it to `lk.laplace`. The built-in methods
|
|
92
|
+
are written the exact same way, against the same public interfaces, with no
|
|
93
|
+
special access. So a third-party method is a first-class citizen, and several
|
|
94
|
+
plugins can be mixed in one fit. Extending `laplace-torch` means subclassing
|
|
95
|
+
`BaseLaplace` (a few thousand lines) and sending a PR. `laplax` and
|
|
96
|
+
`posteriors` are libraries of functions: they can be composed, or a new method
|
|
97
|
+
written from scratch, but there is no plugin host.
|
|
98
|
+
|
|
99
|
+
## How it compares
|
|
100
|
+
|
|
101
|
+
| | <code><b>laplacekit</b></code> | [`laplace-torch`](https://github.com/aleximmer/Laplace) | [`laplax`](https://github.com/laplax-org/laplax) | [`posteriors`](https://github.com/normal-computing/posteriors) |
|
|
102
|
+
| --- | :---: | :---: | :---: | :---: |
|
|
103
|
+
| Framework | PyTorch | PyTorch | JAX | PyTorch |
|
|
104
|
+
| LLMs (Hugging Face, LoRA) without special code | ✅ | 🟡 | 🟡 | ✅ |
|
|
105
|
+
| Diffusion models | ✅ | ❌ | 🟡 | ❓ |
|
|
106
|
+
| Fit from your own training loop | ✅ | ❌ | ❓ | ✅ |
|
|
107
|
+
| Fully type-checked, with typed extension points | ✅ | ❌ | ❓ | ❓ |
|
|
108
|
+
| Options as typed objects and checked literals | ✅ | ❌ | ❌ | ✅ |
|
|
109
|
+
| Differentiate through the whole fit | ✅ | ❌ | ✅ | ✅ |
|
|
110
|
+
| Diagonal and full curvature | ✅ | ✅ | ✅ | ✅ |
|
|
111
|
+
| KFAC | ✅ | ✅ | ❌ | ❌ |
|
|
112
|
+
| Low-rank curvature | ✅ | ✅ | ✅ | ❌ |
|
|
113
|
+
| Last-layer Laplace | ✅ | ✅ | ❓ | ✅ |
|
|
114
|
+
| Subnetwork Laplace | ✅ | ✅ | ❓ | ✅ |
|
|
115
|
+
| Function-space (GP) Laplace | ✅ | ✅ | ❓ | ❌ |
|
|
116
|
+
| Linearized predictive | ✅ | ✅ | ✅ | 🟡 |
|
|
117
|
+
| Marginal-likelihood tuning | ✅ | ✅ | ✅ | ❌ |
|
|
118
|
+
| Marglik training | ✅ | ✅ | ❓ | ❓ |
|
|
119
|
+
|
|
120
|
+
✅ yes · 🟡 partly · ❌ no · ❓ not checked. Details on the [Why page](https://laplacekit.org/why.html#how-it-compares).
|
|
121
|
+
|
|
122
|
+
> [!TIP]
|
|
123
|
+
> Coming from `laplace-torch`? The [Why page](https://laplacekit.org/why.html#coming-from-laplace-torch)
|
|
124
|
+
> maps its API to <code><b>laplacekit</b></code>.
|
|
125
|
+
|
|
126
|
+
## Agent workflow
|
|
127
|
+
|
|
128
|
+
<code><b>laplacekit</b></code> is designed so that a coding agent can write a new Laplace
|
|
129
|
+
method without reading the core:
|
|
130
|
+
|
|
131
|
+
- Each extension point is a small typed interface in its own file, and `ty`
|
|
132
|
+
tells the agent it got something wrong in seconds.
|
|
133
|
+
- Errors say what's missing _and_ what would work instead, so the agent can fix
|
|
134
|
+
its own mistakes. A wrong argument type, such as `hessian_approx="kron"` or
|
|
135
|
+
the class `lk.KFAC` for an instance, raises a `TypeError` that names what to
|
|
136
|
+
pass.
|
|
137
|
+
- `print(post)` shows every choice a fit made, and `torch.manual_seed` (or a
|
|
138
|
+
`generator=` argument) makes reruns identical, as in torch.
|
|
139
|
+
- `lk.testing` checks a new plugin against its interface and the laws it must
|
|
140
|
+
satisfy.
|
|
141
|
+
- `print(lk.health())` reports whether the install works: the torch version,
|
|
142
|
+
the `curvlinops` pin, autograd on a small model, float64, and each plugin's own
|
|
143
|
+
checks.
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "laplacekit"
|
|
3
|
+
version = "0.1a0"
|
|
4
|
+
description = "Extensible, modern Laplace-approximation library for PyTorch, built on a plugin system."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "MIT"
|
|
7
|
+
requires-python = ">=3.13"
|
|
8
|
+
classifiers = [
|
|
9
|
+
"Development Status :: 3 - Alpha",
|
|
10
|
+
"Operating System :: OS Independent",
|
|
11
|
+
"Programming Language :: Python :: 3.13",
|
|
12
|
+
"Programming Language :: Python :: 3.14",
|
|
13
|
+
]
|
|
14
|
+
dependencies = [
|
|
15
|
+
"curvlinops-for-pytorch==3.0.1",
|
|
16
|
+
"packaging>=24",
|
|
17
|
+
"torch >= 2.15",
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
[[project.authors]]
|
|
21
|
+
name = "Agustinus Kristiadi"
|
|
22
|
+
email = "agustinus@kristia.de"
|
|
23
|
+
|
|
24
|
+
[project.optional-dependencies]
|
|
25
|
+
transformers = ["laplacekit-transformers"]
|
|
26
|
+
diffusers = ["laplacekit-diffusers"]
|
|
27
|
+
subnet = ["laplacekit-subnet"]
|
|
28
|
+
heteroscedastic = ["laplacekit-heteroscedastic"]
|
|
29
|
+
reward = ["laplacekit-reward"]
|
|
30
|
+
gp = ["laplacekit-gp"]
|
|
31
|
+
marglik = ["laplacekit-marglik"]
|
|
32
|
+
all = [
|
|
33
|
+
"laplacekit-transformers",
|
|
34
|
+
"laplacekit-diffusers",
|
|
35
|
+
"laplacekit-subnet",
|
|
36
|
+
"laplacekit-heteroscedastic",
|
|
37
|
+
"laplacekit-reward",
|
|
38
|
+
"laplacekit-gp",
|
|
39
|
+
"laplacekit-marglik",
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
[project.urls]
|
|
43
|
+
Homepage = "https://laplacekit.org"
|
|
44
|
+
|
|
45
|
+
[build-system]
|
|
46
|
+
requires = ["uv_build>=0.13.0,<0.14"]
|
|
47
|
+
build-backend = "uv_build"
|
|
48
|
+
|
|
49
|
+
[dependency-groups]
|
|
50
|
+
dev = [
|
|
51
|
+
"pytest>=8",
|
|
52
|
+
"ty>=0.0.104",
|
|
53
|
+
"ruff>=0.14",
|
|
54
|
+
"import-linter>=2.1",
|
|
55
|
+
"laplacekit-transformers",
|
|
56
|
+
"laplacekit-diffusers",
|
|
57
|
+
"laplacekit-subnet",
|
|
58
|
+
"laplacekit-heteroscedastic",
|
|
59
|
+
"laplacekit-reward",
|
|
60
|
+
"laplacekit-gp",
|
|
61
|
+
"laplacekit-marglik",
|
|
62
|
+
"transformers>=5.23.0",
|
|
63
|
+
"diffusers>=0.43.0",
|
|
64
|
+
"peft>=0.21.3",
|
|
65
|
+
"pyyaml>=6",
|
|
66
|
+
"quartodoc>=0.9",
|
|
67
|
+
"griffe<2",
|
|
68
|
+
]
|
|
69
|
+
docs = [
|
|
70
|
+
"quarto-cli>=1.10",
|
|
71
|
+
"quartodoc>=0.9",
|
|
72
|
+
"griffe<2",
|
|
73
|
+
"ipykernel>=6",
|
|
74
|
+
"matplotlib>=3.9",
|
|
75
|
+
"jupyter-cache>=1",
|
|
76
|
+
"pyyaml>=6",
|
|
77
|
+
"nbformat>=5",
|
|
78
|
+
"nbclient>=0.10",
|
|
79
|
+
"scikit-learn>=1.9.1",
|
|
80
|
+
"laplacekit-transformers",
|
|
81
|
+
"laplacekit-diffusers",
|
|
82
|
+
"laplacekit-subnet",
|
|
83
|
+
"laplacekit-heteroscedastic",
|
|
84
|
+
"laplacekit-reward",
|
|
85
|
+
"laplacekit-gp",
|
|
86
|
+
"laplacekit-marglik",
|
|
87
|
+
"laplacekit-example",
|
|
88
|
+
"peft>=0.21.3",
|
|
89
|
+
"diffusers>=0.43.0",
|
|
90
|
+
"torchvision>=0.29.1",
|
|
91
|
+
"datasets>=5.2.0",
|
|
92
|
+
]
|
|
93
|
+
|
|
94
|
+
[[tool.uv.index]]
|
|
95
|
+
name = "pytorch-cpu"
|
|
96
|
+
url = "https://download.pytorch.org/whl/cpu"
|
|
97
|
+
explicit = true
|
|
98
|
+
|
|
99
|
+
[tool.uv.workspace]
|
|
100
|
+
members = ["plugins/*"]
|
|
101
|
+
|
|
102
|
+
[[tool.uv.sources.torch]]
|
|
103
|
+
index = "pytorch-cpu"
|
|
104
|
+
|
|
105
|
+
[[tool.uv.sources.torchvision]]
|
|
106
|
+
index = "pytorch-cpu"
|
|
107
|
+
|
|
108
|
+
[tool.uv.sources.laplacekit-transformers]
|
|
109
|
+
workspace = true
|
|
110
|
+
|
|
111
|
+
[tool.uv.sources.laplacekit-diffusers]
|
|
112
|
+
workspace = true
|
|
113
|
+
|
|
114
|
+
[tool.uv.sources.laplacekit-subnet]
|
|
115
|
+
workspace = true
|
|
116
|
+
|
|
117
|
+
[tool.uv.sources.laplacekit-heteroscedastic]
|
|
118
|
+
workspace = true
|
|
119
|
+
|
|
120
|
+
[tool.uv.sources.laplacekit-reward]
|
|
121
|
+
workspace = true
|
|
122
|
+
|
|
123
|
+
[tool.uv.sources.laplacekit-gp]
|
|
124
|
+
workspace = true
|
|
125
|
+
|
|
126
|
+
[tool.uv.sources.laplacekit-marglik]
|
|
127
|
+
workspace = true
|
|
128
|
+
|
|
129
|
+
[tool.uv.sources.laplacekit-example]
|
|
130
|
+
git = "https://github.com/laplacekit/laplacekit-plugin-example"
|
|
131
|
+
|
|
132
|
+
[tool.ty.src]
|
|
133
|
+
include = [
|
|
134
|
+
"src",
|
|
135
|
+
"plugins/transformers/src",
|
|
136
|
+
"plugins/diffusers/src",
|
|
137
|
+
"plugins/subnet/src",
|
|
138
|
+
"plugins/heteroscedastic/src",
|
|
139
|
+
"plugins/reward/src",
|
|
140
|
+
"plugins/gp/src",
|
|
141
|
+
"plugins/marglik/src",
|
|
142
|
+
]
|
|
143
|
+
|
|
144
|
+
[tool.ty.environment]
|
|
145
|
+
python-version = "3.13"
|
|
146
|
+
|
|
147
|
+
[tool.ruff]
|
|
148
|
+
line-length = 100
|
|
149
|
+
target-version = "py313"
|
|
150
|
+
|
|
151
|
+
[tool.ruff.lint]
|
|
152
|
+
select = [
|
|
153
|
+
"E",
|
|
154
|
+
"F",
|
|
155
|
+
"I",
|
|
156
|
+
"UP",
|
|
157
|
+
"B",
|
|
158
|
+
"TID251",
|
|
159
|
+
"D",
|
|
160
|
+
]
|
|
161
|
+
ignore = [
|
|
162
|
+
"D100",
|
|
163
|
+
"D105",
|
|
164
|
+
"D107",
|
|
165
|
+
"D202",
|
|
166
|
+
]
|
|
167
|
+
|
|
168
|
+
[tool.ruff.lint.flake8-bugbear]
|
|
169
|
+
extend-immutable-calls = ["laplacekit_transformers.tasks.CausalLM"]
|
|
170
|
+
|
|
171
|
+
[tool.ruff.lint.pydocstyle]
|
|
172
|
+
convention = "google"
|
|
173
|
+
|
|
174
|
+
[tool.ruff.lint.flake8-tidy-imports.banned-api."torch.utils._pytree"]
|
|
175
|
+
msg = "Import pytree helpers strategy laplacekit.core._pytree only."
|
|
176
|
+
|
|
177
|
+
[tool.ruff.lint.flake8-tidy-imports.banned-api.curvlinops]
|
|
178
|
+
msg = "Only the Curvlinops adapter (laplacekit.curvlinops) imports curvlinops."
|
|
179
|
+
|
|
180
|
+
[tool.ruff.lint.per-file-ignores]
|
|
181
|
+
"src/laplacekit/core/_pytree.py" = ["TID251"]
|
|
182
|
+
"src/laplacekit/curvlinops.py" = ["TID251"]
|
|
183
|
+
"tests/test_curvlinops.py" = ["TID251"]
|
|
184
|
+
"docs/examples/*.py" = [
|
|
185
|
+
"E402",
|
|
186
|
+
"E501",
|
|
187
|
+
]
|
|
188
|
+
"docs/quickstart/*.py" = [
|
|
189
|
+
"E402",
|
|
190
|
+
"E501",
|
|
191
|
+
]
|
|
192
|
+
"docs/plugins/*.py" = [
|
|
193
|
+
"E402",
|
|
194
|
+
"E501",
|
|
195
|
+
]
|
|
196
|
+
"tests/**" = ["D"]
|
|
197
|
+
"plugins/*/tests/**" = ["D"]
|
|
198
|
+
"docs/**" = ["D"]
|
|
199
|
+
|
|
200
|
+
[tool.pytest.ini_options]
|
|
201
|
+
testpaths = [
|
|
202
|
+
"tests",
|
|
203
|
+
"plugins/transformers/tests",
|
|
204
|
+
"plugins/diffusers/tests",
|
|
205
|
+
"plugins/subnet/tests",
|
|
206
|
+
"plugins/heteroscedastic/tests",
|
|
207
|
+
"plugins/reward/tests",
|
|
208
|
+
"plugins/gp/tests",
|
|
209
|
+
"plugins/marglik/tests",
|
|
210
|
+
]
|
|
211
|
+
norecursedirs = ["tests/typing"]
|
|
212
|
+
filterwarnings = ["ignore:`torch.jit.script` is not supported:FutureWarning:torch.jit._script"]
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "laplacekit"
|
|
3
|
+
version = "0.1a0"
|
|
4
|
+
description = "Extensible, modern Laplace-approximation library for PyTorch, built on a plugin system."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
authors = [{ name = "Agustinus Kristiadi", email = "agustinus@kristia.de" }]
|
|
7
|
+
license = "MIT"
|
|
8
|
+
requires-python = ">=3.13"
|
|
9
|
+
classifiers = [
|
|
10
|
+
"Development Status :: 3 - Alpha",
|
|
11
|
+
"Operating System :: OS Independent",
|
|
12
|
+
"Programming Language :: Python :: 3.13",
|
|
13
|
+
"Programming Language :: Python :: 3.14",
|
|
14
|
+
]
|
|
15
|
+
dependencies = [
|
|
16
|
+
"curvlinops-for-pytorch==3.0.1",
|
|
17
|
+
"packaging>=24",
|
|
18
|
+
"torch >= 2.15",
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
[project.optional-dependencies]
|
|
22
|
+
transformers = ["laplacekit-transformers"]
|
|
23
|
+
diffusers = ["laplacekit-diffusers"]
|
|
24
|
+
subnet = ["laplacekit-subnet"]
|
|
25
|
+
heteroscedastic = ["laplacekit-heteroscedastic"]
|
|
26
|
+
reward = ["laplacekit-reward"]
|
|
27
|
+
gp = ["laplacekit-gp"]
|
|
28
|
+
marglik = ["laplacekit-marglik"]
|
|
29
|
+
all = [
|
|
30
|
+
"laplacekit-transformers",
|
|
31
|
+
"laplacekit-diffusers",
|
|
32
|
+
"laplacekit-subnet",
|
|
33
|
+
"laplacekit-heteroscedastic",
|
|
34
|
+
"laplacekit-reward",
|
|
35
|
+
"laplacekit-gp",
|
|
36
|
+
"laplacekit-marglik",
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
[project.urls]
|
|
40
|
+
Homepage = "https://laplacekit.org"
|
|
41
|
+
|
|
42
|
+
[build-system]
|
|
43
|
+
requires = ["uv_build>=0.13.0,<0.14"]
|
|
44
|
+
build-backend = "uv_build"
|
|
45
|
+
|
|
46
|
+
[dependency-groups]
|
|
47
|
+
dev = [
|
|
48
|
+
"pytest>=8",
|
|
49
|
+
"ty>=0.0.104",
|
|
50
|
+
"ruff>=0.14",
|
|
51
|
+
"import-linter>=2.1",
|
|
52
|
+
"laplacekit-transformers",
|
|
53
|
+
"laplacekit-diffusers",
|
|
54
|
+
"laplacekit-subnet",
|
|
55
|
+
"laplacekit-heteroscedastic",
|
|
56
|
+
"laplacekit-reward",
|
|
57
|
+
"laplacekit-gp",
|
|
58
|
+
"laplacekit-marglik",
|
|
59
|
+
"transformers>=5.23.0",
|
|
60
|
+
"diffusers>=0.43.0",
|
|
61
|
+
"peft>=0.21.3",
|
|
62
|
+
"pyyaml>=6",
|
|
63
|
+
"quartodoc>=0.9",
|
|
64
|
+
"griffe<2",
|
|
65
|
+
]
|
|
66
|
+
docs = [
|
|
67
|
+
"quarto-cli>=1.10",
|
|
68
|
+
"quartodoc>=0.9",
|
|
69
|
+
"griffe<2",
|
|
70
|
+
"ipykernel>=6",
|
|
71
|
+
"matplotlib>=3.9",
|
|
72
|
+
"jupyter-cache>=1",
|
|
73
|
+
"pyyaml>=6",
|
|
74
|
+
"nbformat>=5",
|
|
75
|
+
"nbclient>=0.10",
|
|
76
|
+
"scikit-learn>=1.9.1",
|
|
77
|
+
"laplacekit-transformers",
|
|
78
|
+
"laplacekit-diffusers",
|
|
79
|
+
"laplacekit-subnet",
|
|
80
|
+
"laplacekit-heteroscedastic",
|
|
81
|
+
"laplacekit-reward",
|
|
82
|
+
"laplacekit-gp",
|
|
83
|
+
"laplacekit-marglik",
|
|
84
|
+
"laplacekit-example",
|
|
85
|
+
"peft>=0.21.3",
|
|
86
|
+
"diffusers>=0.43.0",
|
|
87
|
+
"torchvision>=0.29.1",
|
|
88
|
+
"datasets>=5.2.0",
|
|
89
|
+
]
|
|
90
|
+
|
|
91
|
+
[[tool.uv.index]]
|
|
92
|
+
name = "pytorch-cpu"
|
|
93
|
+
url = "https://download.pytorch.org/whl/cpu"
|
|
94
|
+
explicit = true
|
|
95
|
+
|
|
96
|
+
[tool.uv.workspace]
|
|
97
|
+
members = ["plugins/*"]
|
|
98
|
+
|
|
99
|
+
[tool.uv.sources]
|
|
100
|
+
torch = [{ index = "pytorch-cpu" }]
|
|
101
|
+
torchvision = [{ index = "pytorch-cpu" }]
|
|
102
|
+
laplacekit-transformers = { workspace = true }
|
|
103
|
+
laplacekit-diffusers = { workspace = true }
|
|
104
|
+
laplacekit-subnet = { workspace = true }
|
|
105
|
+
laplacekit-heteroscedastic = { workspace = true }
|
|
106
|
+
laplacekit-reward = { workspace = true }
|
|
107
|
+
laplacekit-gp = { workspace = true }
|
|
108
|
+
laplacekit-marglik = { workspace = true }
|
|
109
|
+
# The docs' example plugin lives in its own repository, a template for new plugins.
|
|
110
|
+
laplacekit-example = { git = "https://github.com/laplacekit/laplacekit-plugin-example" }
|
|
111
|
+
|
|
112
|
+
[tool.ty.src]
|
|
113
|
+
include = ["src", "plugins/transformers/src", "plugins/diffusers/src", "plugins/subnet/src", "plugins/heteroscedastic/src", "plugins/reward/src", "plugins/gp/src", "plugins/marglik/src"] # tests/typing holds deliberate errors; test_typing_gate checks it
|
|
114
|
+
|
|
115
|
+
[tool.ty.environment]
|
|
116
|
+
python-version = "3.13"
|
|
117
|
+
|
|
118
|
+
[tool.ruff]
|
|
119
|
+
line-length = 100
|
|
120
|
+
target-version = "py313"
|
|
121
|
+
|
|
122
|
+
[tool.ruff.lint]
|
|
123
|
+
select = ["E", "F", "I", "UP", "B", "TID251", "D"]
|
|
124
|
+
# D100: module docstrings exist, but plugins' private modules vary. D105, D107: dunders and
|
|
125
|
+
# `__init__` are covered by the class docstring. D202: the house style puts a blank line
|
|
126
|
+
# after a function's docstring.
|
|
127
|
+
ignore = ["D100", "D105", "D107", "D202"]
|
|
128
|
+
|
|
129
|
+
[tool.ruff.lint.flake8-bugbear]
|
|
130
|
+
# Frozen dataclasses, safe as argument defaults (B008).
|
|
131
|
+
extend-immutable-calls = ["laplacekit_transformers.tasks.CausalLM"]
|
|
132
|
+
|
|
133
|
+
[tool.ruff.lint.pydocstyle]
|
|
134
|
+
convention = "google"
|
|
135
|
+
|
|
136
|
+
[tool.ruff.lint.flake8-tidy-imports.banned-api]
|
|
137
|
+
"torch.utils._pytree".msg = "Import pytree helpers strategy laplacekit.core._pytree only."
|
|
138
|
+
"curvlinops".msg = "Only the Curvlinops adapter (laplacekit.curvlinops) imports curvlinops."
|
|
139
|
+
|
|
140
|
+
[tool.ruff.lint.per-file-ignores]
|
|
141
|
+
"src/laplacekit/core/_pytree.py" = ["TID251"]
|
|
142
|
+
"src/laplacekit/curvlinops.py" = ["TID251"]
|
|
143
|
+
"tests/test_curvlinops.py" = ["TID251"] # compares the adapter with Curvlinops itself
|
|
144
|
+
"docs/examples/*.py" = ["E402", "E501"] # prose cells hold LaTeX and tables
|
|
145
|
+
"docs/quickstart/*.py" = ["E402", "E501"]
|
|
146
|
+
"docs/plugins/*.py" = ["E402", "E501"]
|
|
147
|
+
"tests/**" = ["D"]
|
|
148
|
+
"plugins/*/tests/**" = ["D"]
|
|
149
|
+
"docs/**" = ["D"]
|
|
150
|
+
|
|
151
|
+
[tool.pytest.ini_options]
|
|
152
|
+
testpaths = ["tests", "plugins/transformers/tests", "plugins/diffusers/tests", "plugins/subnet/tests", "plugins/heteroscedastic/tests", "plugins/reward/tests", "plugins/gp/tests", "plugins/marglik/tests"]
|
|
153
|
+
norecursedirs = ["tests/typing"]
|
|
154
|
+
filterwarnings = [
|
|
155
|
+
# torch's own torch._decomp calls torch.jit.script on the first forward-mode AD call, which
|
|
156
|
+
# warns on Python 3.14+. Not our code; the probe silences the same warning around its jvp.
|
|
157
|
+
"ignore:`torch.jit.script` is not supported:FutureWarning:torch.jit._script",
|
|
158
|
+
]
|