Skip to main content

scipy Linear operators for curvature matrices in PyTorch

Project description

Logo Linear Operators for Curvature Matrices in PyTorch

Python 3.9+ tests Coveralls

This library provides linear operators---a unified interface for matrix-free computation---for deep learning curvature matrices in PyTorch. curvlinops is inspired by SciPy's sparse.linalg.LinearOperator interface and implements a PyTorch version.

You can read our position paper to know more about why combining linear operators with curvature matrices might be a good idea.

Main features:

  • Broad support of curvature matrices. curvlinops supports many common curvature matrices and approximations thereof, such as the Hessian, Fisher, generalized Gauss-Newton, and K-FAC (overview, visual tour).

  • Unified interface. All linear operators share the same interface, making it easy to switch between curvature matrices.

  • Purely PyTorch. All computations can run on a GPU.

  • SciPy export. You can export a curvlinops linear operator to a SciPy LinearOperator with .to_scipy(). This allows plugging it into scipy, while carrying out the heavy lifting (matrix-vector multiplies) in PyTorch on GPU. My favorite example is scipy.sparse.linalg.eigsh that lets you compute a subset of eigen-pairs (example).

  • Randomized estimation algorithms. curvlinops offers functionality to estimate properties the matrix represented by a linear operators, like its spectral density (example), inverse (example), trace & diagonal (example).

Installation

pip install curvlinops-for-pytorch

Useful Links

Citation

If you find curvlinops useful for your work, consider citing our position paper

@article{dangel2025position,
  title =        {Position: Curvature Matrices Should Be Democratized via Linear
                  Operators},
  author =       {Dangel, Felix and Eschenhagen, Runa and Ormaniec, Weronika and
                  Fernandez, Andres and Tatzel, Lukas and Kristiadi, Agustinus},
  journal =      {arXiv 2501.19183},
  year =         2025,
}

Future ideas

  • Refactor the back-end for curvature-matrix multiplication into pure functions to improve recycle-ability and ease the use of torch.compile.

  • Multi-GPU support.

  • Include more curvature matrices

Logo mage credits

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

curvlinops_for_pytorch-3.0.0.tar.gz (1.7 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

curvlinops_for_pytorch-3.0.0-py3-none-any.whl (81.1 kB view details)

Uploaded Python 3

File details

Details for the file curvlinops_for_pytorch-3.0.0.tar.gz.

File metadata

  • Download URL: curvlinops_for_pytorch-3.0.0.tar.gz
  • Upload date:
  • Size: 1.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for curvlinops_for_pytorch-3.0.0.tar.gz
Algorithm Hash digest
SHA256 52ff661821147705f66a981ea090c750ad9e4c741c06f46d8282c5e63c776066
MD5 204550045c3092f80daf484cfc7c48b1
BLAKE2b-256 eff8b7802ed76a1bf7fbe12bfd44f128b95c11a0cda02744bb5238d307b9c9bf

See more details on using hashes here.

File details

Details for the file curvlinops_for_pytorch-3.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for curvlinops_for_pytorch-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a27cf3f519b94da73a3ddecd9fab8ece9e42e20cce37fba717b4c55f6ebc60c5
MD5 7ef027412596ad307e627b1f6bdb38d7
BLAKE2b-256 728e5093b920d5bdaf4106335f076b92c05b1857c114566e1738da143fd909cb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page