{KFAC,EKFAC,Diagonal,Implicit} Fisher Matrices and finite width NTKs in PyTorch
Key metrics and engagement data
Repository has been active for 5 years, 10 months
Looks like this repository is a hidden gem!
No stargazers yet. Why not be the first to give it a star?
⭐0
Want deeper insights? Explore GitObs.com
NNGeometry allows you to:
FIM
and FIM_MonteCarlo
), as well as any matrix that is written as the covariance of gradients w.r.t. parameters, using efficient approximations such as low-rank matrices, KFAC, EKFAC, diagonal and so on. Some of these representations also work for hessians (Hessian
).GramMatrix
), even for multiple output functions.Jacobian
), or of any function such as the network's output.It offers a high level abstraction over the parameter and function spaces described by neural networks. As a simple example, a parameter space vector PVector
actually contains weight matrices, bias vectors, or convolutions kernels of the whole neural network (a set of tensors). Using NNGeometry's API, performing a step in parameter space (e.g. an update of your favorite optimization algorithm) is abstracted as a python addition: w_next = w_previous + epsilon * delta_w
.
In the Elastic Weight Consolidation continual learning technique, you want to compute $\left(\mathbf{w}-\mathbf{w}_{A}\right)^{\top}F\left(\mathbf{w}-\mathbf{w}_{A}\right)
$. It can be achieved with a diagonal approximation for the FIM using:
python1F = FIM(model=model,2 loader=loader,3 representation=PMatDiag)45regularizer = F.vTMv(w - w_a)
The first statement instantiates a diagonal matrix, and populates it with the diagonal coefficients of the FIM of the model model
computed using the examples from the dataloader loader
.
If diagonal is not sufficiently accurate then you could instead choose a KFAC approximation, by just changing PMatDiag
to PMatKFAC
in the above. Note that it internally involves very different operations, depending on the chosen representation (e.g. KFAC, EKFAC, ...).
You can visit the documentation at https://nngeometry.readthedocs.io.
More example usage are available in the repository https://github.com/tfjgeorge/nngeometry-examples.
You are now many who are using NNGeometry in your work: do not hesitate to drop me a line ([email protected]) about your project so that I have a better understanding of your use cases or the current limitations of the library.
We welcome any feature request or bug report in the issue tracker.
We also welcome contributions, please submit your PRs!
If you use NNGeometry in a published project, please cite our work using the following bibtex entry
tex1@software{george_nngeometry,2 author = {Thomas George},3 title = {{NNGeometry: Easy and Fast Fisher Information4 Matrices and Neural Tangent Kernels in PyTorch}},5 month = feb,6 year = 2021,7 publisher = {Zenodo},8 version = {v0.3},9 doi = {10.5281/zenodo.4532597},10 url = {https://doi.org/10.5281/zenodo.4532597}11}
This project is distributed under the MIT license (see LICENSE file). This project also includes code licensed under the BSD 3 clause as it borrows some code from https://github.com/owkin/grad-cnns.