Skip to main content

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}
}

Metadata

Release files for torch-secorder 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for torch-secorder 0.0.1
File Size Uploaded Provenance Actions
torch_secorder-0.0.1.tar.gz 20.2 kB With provenance Details for torch_secorder-0.0.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for torch-secorder 0.0.1
File Interpreter ABI Platform Actions
torch_secorder-0.0.1-py3-none-any.whl Python 3 none any Details for torch_secorder-0.0.1-py3-none-any.whl

Total release size: 48.6 kB

Release files / torch_secorder-0.0.1.tar.gz

Download URL torch_secorder-0.0.1.tar.gz
Size 20.2 kB
Tags Source
SHA-256 checksum
How to use checksums
a61d97cb0d5ee1f7250c8d6de0a6af0fcb127128304da8a991b98421f5e2a052
BLAKE2b-256 checksum
How to use checksums
d107db974091550ec8bfafd55d5e4394b7c1ee82d71e5124e76db11fbe84b325
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 13, 2025.

Transparency log

Release files / torch_secorder-0.0.1-py3-none-any.whl

Download URL torch_secorder-0.0.1-py3-none-any.whl
Size 28.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
685fff71a6070147118bab30734308ee719e829d75e3d48bc90e9279cbd8176c
BLAKE2b-256 checksum
How to use checksums
660e6440e01ca7c2233f7b40a16341e0abf52e68058fe60ce66918c202f9ede1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 13, 2025.

Transparency log

Security for torch-secorder 0.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for torch_secorder-0.0.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 13, 2025.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page