Skip to main content

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


Download files

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

Source Distribution

torch_secorder-0.0.1.tar.gz (20.2 kB view details)

Uploaded Source

Built Distribution

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

torch_secorder-0.0.1-py3-none-any.whl (28.4 kB view details)

Uploaded Python 3

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

Hashes for torch_secorder-0.0.1.tar.gz
Algorithm Hash digest
SHA256 a61d97cb0d5ee1f7250c8d6de0a6af0fcb127128304da8a991b98421f5e2a052
MD5 bee3d32465a00d961c257c539fd563cc
BLAKE2b-256 d107db974091550ec8bfafd55d5e4394b7c1ee82d71e5124e76db11fbe84b325

See more details on using hashes here.

Provenance

The following attestation bundles were made for torch_secorder-0.0.1.tar.gz:

Publisher: ci.yml on PyBrainn/torch-secorder

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for torch_secorder-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 685fff71a6070147118bab30734308ee719e829d75e3d48bc90e9279cbd8176c
MD5 e754e79b41c54036250736e7c90c3b1f
BLAKE2b-256 660e6440e01ca7c2233f7b40a16341e0abf52e68058fe60ce66918c202f9ede1

See more details on using hashes here.

Provenance

The following attestation bundles were made for torch_secorder-0.0.1-py3-none-any.whl:

Publisher: ci.yml on PyBrainn/torch-secorder

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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