Skip to content

Commit 45c13ba

Browse files
authored
Prepare 1.1.0 release (#23)
2 parents dfd12ec + 3d7c612 commit 45c13ba

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+3115
-319
lines changed

.github/workflows/test.yaml

+5-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ on:
88
branches:
99
- development
1010
- master
11-
- release
1211

1312

1413
jobs:
@@ -30,8 +29,13 @@ jobs:
3029
python -m pip install --upgrade pip
3130
make install-test
3231
- name: Run test
32+
if: contains('refs/heads/master refs/heads/development', github.ref)
3333
run: |
3434
make test
35+
- name: Run test-light
36+
if: contains('refs/heads/master refs/heads/development', github.ref) != 1
37+
run: |
38+
make test-light
3539
3640
- name: Test coveralls - python ${{ matrix.python-version }}
3741
run: coveralls --service=github

README.md

+2-8
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ for deep learning matrices, such as
1111

1212
- the Hessian
1313
- the Fisher/generalized Gauss-Newton (GGN)
14+
- the Monte-Carlo approximated Fisher
15+
- the uncentered gradient covariance (aka empirical Fisher)
1416

1517
Matrix-vector products are carried out in PyTorch, i.e. potentially on a GPU.
1618
The library supports defining these matrices not only on a mini-batch, but
@@ -44,20 +46,12 @@ Other features that could be supported in the future include:
4446

4547
- Other matrices
4648

47-
- the un-centered gradient covariance (aka empirical Fisher)
4849
- the centered gradient covariance
4950
- terms of the [hierarchical GGN
5051
decomposition](https://arxiv.org/abs/2008.11865)
5152

5253
- Block-diagonal approximations (via `param_groups`)
5354

54-
- Inverse matrix-vector products by solving a linear system via conjugate
55-
gradients
56-
57-
- This could allow computing generalization metrics like the Takeuchi
58-
Information Criterion (TIC), using inverse matrix-vector products in
59-
combination with Hutchinson trace estimation
60-
6155
###### Logo mage credits
6256
- SciPy logo: Unknown, [CC BY-SA
6357
4.0](https://creativecommons.org/licenses/by-sa/4.0), via Wikimedia Commons

changelog.md

+56-1
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,64 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
## [1.1.0] - 2023-02-19
10+
11+
Adds various new features:
12+
13+
### Added/New
14+
15+
- Inverses of linear operators with multiplication via conjugate gradients
16+
([PR](https://github.com/f-dangel/curvlinops/pull/9),
17+
[example](https://curvlinops.readthedocs.io/en/latest/basic_usage/example_inverses.html))
18+
19+
- Spectral density estimation methods from [papyan2020traces](https://jmlr.org/beta/papers/v21/20-933.html)
20+
([PR](https://github.com/f-dangel/curvlinops/pull/14/files),
21+
[basic example](https://curvlinops.readthedocs.io/en/latest/basic_usage/example_verification_spectral_density.html))
22+
23+
- Add caching to recycle Lanczos iterations between densities with different hyperparameters
24+
([PR](https://github.com/f-dangel/curvlinops/pull/15),
25+
[demo 1](https://curvlinops.readthedocs.io/en/latest/basic_usage/example_verification_spectral_density.html#for-multiple-hyperparameters),
26+
[demo 2](https://curvlinops.readthedocs.io/en/latest/basic_usage/example_verification_spectral_density.html#id1))
27+
28+
- Example visualizing different supported curvature matrices
29+
([PR](https://github.com/f-dangel/curvlinops/pull/16),
30+
[example](https://curvlinops.readthedocs.io/en/latest/basic_usage/example_visual_tour.html))
31+
32+
- Linear operator for the uncentered gradient covariance matrix (aka 'empirical Fisher')
33+
([PR](https://github.com/f-dangel/curvlinops/pull/17))
34+
35+
- Example for computing eigenvalues with `scipy.linalg.sparse.eigsh`
36+
([PR](https://github.com/f-dangel/curvlinops/pull/18),
37+
[example](https://curvlinops.readthedocs.io/en/latest/basic_usage/example_eigenvalues.html))
38+
39+
- Linear operator for a Monte-Carlo approximation of the Fisher
40+
([PR1](https://github.com/f-dangel/curvlinops/pull/20),
41+
[PR2](https://github.com/f-dangel/curvlinops/pull/21),
42+
[example](https://curvlinops.readthedocs.io/en/latest/basic_usage/example_fisher_monte_carlo.html))
43+
44+
### Fixed/Removed
45+
46+
### Internal
47+
48+
- Refactor examples, extracting common `functorch` and array comparison methods
49+
([PR](https://github.com/f-dangel/curvlinops/pull/10))
50+
51+
- Add description of the library on the RTD landing page
52+
([PR](https://github.com/f-dangel/curvlinops/pull/11))
53+
54+
- Set up a proper test suite with cases
55+
([PR](https://github.com/f-dangel/curvlinops/pull/12))
56+
57+
- Add regression test cases
58+
([PR](https://github.com/f-dangel/curvlinops/pull/19))
59+
60+
- Update code to latest versions of linting CI
61+
([PR](https://github.com/f-dangel/curvlinops/pull/22))
62+
963
## [1.0.0] - 2022-09-30
1064

1165
Initial release
1266

13-
[Unreleased]: https://github.com/f-dangel/curvlinops/compare/1.0.0...HEAD
67+
[Unreleased]: https://github.com/f-dangel/curvlinops/compare/1.1.0...HEAD
68+
[1.1.0]: https://github.com/f-dangel/curvlinops/releases/tag/1.1.0
1469
[1.0.0]: https://github.com/f-dangel/curvlinops/releases/tag/1.0.0

curvlinops/__init__.py

+16
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,25 @@
11
"""``curvlinops`` library API."""
22

3+
from curvlinops.fisher import FisherMCLinearOperator
34
from curvlinops.ggn import GGNLinearOperator
5+
from curvlinops.gradient_moments import EFLinearOperator
46
from curvlinops.hessian import HessianLinearOperator
7+
from curvlinops.inverse import CGInverseLinearOperator
8+
from curvlinops.papyan2020traces.spectrum import (
9+
LanczosApproximateLogSpectrumCached,
10+
LanczosApproximateSpectrumCached,
11+
lanczos_approximate_log_spectrum,
12+
lanczos_approximate_spectrum,
13+
)
514

615
__all__ = [
716
"HessianLinearOperator",
817
"GGNLinearOperator",
18+
"EFLinearOperator",
19+
"FisherMCLinearOperator",
20+
"CGInverseLinearOperator",
21+
"lanczos_approximate_spectrum",
22+
"lanczos_approximate_log_spectrum",
23+
"LanczosApproximateSpectrumCached",
24+
"LanczosApproximateLogSpectrumCached",
925
]

curvlinops/_base.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from torch import device as torch_device
1919
from torch import from_numpy, tensor, zeros_like
2020
from torch.autograd import grad
21-
from torch.nn import Module
21+
from torch.nn import Module, Parameter
2222
from torch.nn.utils import parameters_to_vector
2323
from tqdm import tqdm
2424

@@ -33,7 +33,7 @@ def __init__(
3333
self,
3434
model_func: Callable[[Tensor], Tensor],
3535
loss_func: Callable[[Tensor, Tensor], Tensor],
36-
params: List[Tensor],
36+
params: List[Parameter],
3737
data: Iterable[Tuple[Tensor, Tensor]],
3838
progressbar: bool = False,
3939
check_deterministic: bool = True,
@@ -87,7 +87,7 @@ def __init__(
8787
self.to_device(old_device)
8888

8989
@staticmethod
90-
def _infer_device(params: List[Tensor]) -> torch_device:
90+
def _infer_device(params: List[Parameter]) -> torch_device:
9191
"""Infer the device on which to carry out matvecs.
9292
9393
Args:
@@ -154,7 +154,7 @@ def _check_deterministic(self):
154154
self.print_nonclose(grad1, grad2, rtol, atol)
155155
raise RuntimeError("Check for deterministic gradient failed.")
156156

157-
v = rand(self.shape[0])
157+
v = rand(self.shape[0]).astype(self.dtype)
158158
mat_v1 = self @ v
159159
mat_v2 = self @ v
160160

@@ -196,7 +196,7 @@ def _matvec(self, x: ndarray) -> ndarray:
196196
x_list = self._preprocess(x)
197197
out_list = [zeros_like(x) for x in x_list]
198198

199-
for (X, y) in self._loop_over_data():
199+
for X, y in self._loop_over_data():
200200
normalization_factor = self._get_normalization_factor(X, y)
201201

202202
for mat_x, current in zip(out_list, self._matvec_batch(X, y, x_list)):
@@ -268,7 +268,7 @@ def _loop_over_data(self) -> Iterable[Tuple[Tensor, Tensor]]:
268268
if self._progressbar:
269269
data_iter = tqdm(data_iter, desc="matvec")
270270

271-
for (X, y) in data_iter:
271+
for X, y in data_iter:
272272
X, y = X.to(self._device), y.to(self._device)
273273
yield (X, y)
274274

@@ -283,7 +283,7 @@ def gradient_and_loss(self) -> Tuple[List[Tensor], Tensor]:
283283
total_loss = tensor([0.0], device=self._device)
284284
total_grad = [zeros_like(p) for p in self._params]
285285

286-
for (X, y) in self._loop_over_data():
286+
for X, y in self._loop_over_data():
287287
loss = self._loss_func(self._model_func(X), y)
288288
normalization_factor = self._get_normalization_factor(X, y)
289289

curvlinops/examples/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Contains functionality for examples in the documentation."""

0 commit comments

Comments
 (0)