A PyTorch library for second-order optimization and analysis
Project description
torch-secorder
A PyTorch-native library for efficient second-order computations in deep neural networks.
Overview
Torch-Secorder provides efficient implementations of second-order optimization utilities for PyTorch, including:
- Hessian-Vector Products (HVP)
- Jacobian-Vector Products (JVP)
- Vector-Jacobian Products (VJP)
- Gauss-Newton matrix computations
- Hessian trace estimation
These tools are essential for:
- Second-order optimization methods
- Natural gradient descent
- Curvature-based regularization
- Neural network analysis and debugging
Features
-
Hessian-Vector Products (HVP)
- Computation of Hv for any vector v
- Trace estimation using Hutchinson's method
- Support for distributed computation
- Automatic parameter handling
-
Hessian Diagonal
- Computation of Hessian diagonal elements
- Trace estimation using diagonal elements
- Support for custom vectors
- Gradient requirement validation
-
Trace Estimation
- HVP-based: Uses Hutchinson's method with random vectors
- Diagonal-based: Uses exact diagonal elements
- Both methods compute the same quantity
- Choose based on model size and accuracy requirements
-
Model Integration
- PyTorch model integration
- Parameter management
- Loss function support
- Model-specific computations
Installation
pip install torch-secorder
Or install from source:
git clone https://github.com/pybrainn/torch-secorder.git
cd torch-secorder
pip install -e .
Quick Start
See our documentation for detailed examples and tutorials.
Documentation
Contributing
We welcome contributions! Please see our Contributing Guide for details.
License
This project is licensed under the Apache 2.0 License - see the LICENSE file for details.
Citation
If you use this library in your research, please cite:
@software{torch_secorder2025,
author = PyBrainn,
title = {Torch-Secorder: Second-Order Optimization for PyTorch},
year = {2025},
publisher = {GitHub},
url = {https://github.com/pybrainn/torch-secorder}
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file torch_secorder-0.0.1.tar.gz.
File metadata
- Download URL: torch_secorder-0.0.1.tar.gz
- Upload date:
- Size: 20.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a61d97cb0d5ee1f7250c8d6de0a6af0fcb127128304da8a991b98421f5e2a052
|
|
| MD5 |
bee3d32465a00d961c257c539fd563cc
|
|
| BLAKE2b-256 |
d107db974091550ec8bfafd55d5e4394b7c1ee82d71e5124e76db11fbe84b325
|
Provenance
The following attestation bundles were made for torch_secorder-0.0.1.tar.gz:
Publisher:
ci.yml on PyBrainn/torch-secorder
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
torch_secorder-0.0.1.tar.gz -
Subject digest:
a61d97cb0d5ee1f7250c8d6de0a6af0fcb127128304da8a991b98421f5e2a052 - Sigstore transparency entry: 237317697
- Sigstore integration time:
-
Permalink:
PyBrainn/torch-secorder@0363f30c9a41a478d22c744e3934d4e2255d4c16 -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/PyBrainn
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@0363f30c9a41a478d22c744e3934d4e2255d4c16 -
Trigger Event:
push
-
Statement type:
File details
Details for the file torch_secorder-0.0.1-py3-none-any.whl.
File metadata
- Download URL: torch_secorder-0.0.1-py3-none-any.whl
- Upload date:
- Size: 28.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
685fff71a6070147118bab30734308ee719e829d75e3d48bc90e9279cbd8176c
|
|
| MD5 |
e754e79b41c54036250736e7c90c3b1f
|
|
| BLAKE2b-256 |
660e6440e01ca7c2233f7b40a16341e0abf52e68058fe60ce66918c202f9ede1
|
Provenance
The following attestation bundles were made for torch_secorder-0.0.1-py3-none-any.whl:
Publisher:
ci.yml on PyBrainn/torch-secorder
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
torch_secorder-0.0.1-py3-none-any.whl -
Subject digest:
685fff71a6070147118bab30734308ee719e829d75e3d48bc90e9279cbd8176c - Sigstore transparency entry: 237317714
- Sigstore integration time:
-
Permalink:
PyBrainn/torch-secorder@0363f30c9a41a478d22c744e3934d4e2255d4c16 -
Branch / Tag:
refs/tags/v0.0.1 - Owner: https://github.com/PyBrainn
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@0363f30c9a41a478d22c744e3934d4e2255d4c16 -
Trigger Event:
push
-
Statement type: