`hessQuik`

`hessQuik`: Fast Hessian computation of composite functions - Published in JOSS (2022)

https://github.com/elizabethnewman/hessquik

Science Score: 95.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 8 DOI reference(s) in README and JOSS metadata
  • Academic publication links
    Links to: joss.theoj.org
  • Committers with academic emails
    1 of 3 committers (33.3%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
    Published in Journal of Open Source Software

Keywords

derivatives gpu-acceleration neural-network
Last synced: 6 months ago · JSON representation

Repository

Computing gradients and Hessians of feed-forward networks with GPU acceleration

Basic Info
  • Host: GitHub
  • Owner: elizabethnewman
  • License: mit
  • Language: Python
  • Default Branch: main
  • Homepage:
  • Size: 3.94 MB
Statistics
  • Stars: 20
  • Watchers: 2
  • Forks: 1
  • Open Issues: 0
  • Releases: 1
Topics
derivatives gpu-acceleration neural-network
Created about 4 years ago · Last pushed about 2 years ago
Metadata Files
Readme License

README.md

hessQuik

DOI

A lightweight package for fast, GPU-accelerated computation of gradients and Hessians of functions constructed via composition.

Statement of Need

Deep neural networks (DNNs) and other composition-based models have become a staple of data science, garnering state-of-the-art results and gaining widespread use in the scientific community, particularly as surrogate models to replace expensive computations. The unrivaled universality and success of DNNs is due, in part, to the convenience of automatic differentiation (AD) which enables users to compute derivatives of complex functions without an explicit formula. Despite being a powerful tool to compute first-order derivatives (gradients), AD encounters computational obstacles when computing second-order derivatives (Hessians).

Knowledge of second-order derivatives is paramount in many growing fields and can provide insight into the optimization problem solved to build a good model. Hessians are notoriously challenging to compute efficiently with AD and cumbersome to derive and debug analytically. Hence, many algorithms approximate Hessian information, resulting in suboptimal performance. To address these challenges, hessQuik computes Hessians analytically and efficiently with an implementation that is accelerated on GPUs.

Documentation

For package usage and details, see our paper in the Journal of Open Source Software.

For detailed documentation, visit https://hessquik.readthedocs.io/.

Installation

From PyPI: console pip install hessQuik

From Github: console python -m pip install git+https://github.com/elizabethnewman/hessQuik.git

Dependencies

These dependencies are installed automatically with pip. * torch (recommended version >= 1.10.0, but code will run with version >= 1.5.0)

Getting Started

Once you have installed hessQuik, you can import as follows:

python import hessQuik.activations as act import hessQuik.layers as lay import hessQuik.networks as net

You can construct a hessQuik network from layers as follows: python d = 10 # dimension of the input features widths = [32, 64] # hidden channel dimensions f = net.NN(lay.singleLayer(d, widths[0], act=act.antiTanhActivation()), lay.resnetLayer(widths[0], h=1.0, act=act.softplusActivation()), lay.singleLayer(widths[0], widths[1], act=act.quadraticActivation()) )

You can obtain gradients and Hessians via python nex = 20 # number of examples x = torch.randn(nex, d) fx, dfx, d2fx = f(x, do_gradient=True, do_Hessian=True)

Support for Laplacians and Directional Derivatives

If you only require Laplacians, not full Hessians, you can obtain the gradients and Laplacians via python fx, dfx, lapfd2x = f(x, do_gradient=True, do_Laplacian=True)

If you only require evaluations of the Jacobian and Hessian along certain directions, you can provide the directions in forward_mode via python k = 3 # number of directions v = torch.randn(k, d) fx, vdfx, vd2fxv = f(x, do_gradient=True, do_Hessian=True, v=v, forward_mode=True) and in backward_mode via python m = widths[-1] # dimension of output features v = torch.randn(m, k) fx, dfxv, d2fxv = f(x, do_gradient=True, do_Hessian=True, v=v, forward_mode=False)

Some important notes: * Currently, this functionality is only supported for singleLayer, resnetLayer, and networks using only these types of layers, including fullyConnectedNN and resnetNN. * If do_Hessian=True, then the full Hessian will be computed, even if do_Laplacian=True as well. * Laplacians can only be computed in forward mode. Hence, if do_Laplacian=True and full Hessians are not requested, hessQuik will compute derivatives with forward_mode=True automatically. * For evaluating of derivatives along certain directions, the user must specify the mode of differentiation. Currently, this choice is not automated.

Examples

To make the code accessible, we provide some introductory Google Colaboratory notebooks.

Practical Use: Hermite Interpolation Open In Colab

Tutorial: Constructing and Testing hessQuik Layers Open In Colab

Timing Comparisons Open In Colab

Contributing

To contribute to hessQuik, follow these steps: 1. Fork the hessQuik repository 2. Clone your fork using console git clone https://github.com/<username>/hessQuik.git 3. Contribute to your forked repository 4. Create a pull request

If your code passes the necessary numerical tests and is well-documented, your changes and/or additions will be merged in the main hessQuik repository. You can find examples of the tests used in each file and related unit tests the tests directory.

Reporting Bugs

If you notice an issue with this repository, please report it using Github Issues. When reporting an implementation bug, include a small example that helps to reproduce the error. The issue will be addressed as quickly as possible.

How to Cite

@article{Newman2022, doi = {10.21105/joss.04171}, url = {https://doi.org/10.21105/joss.04171}, year = {2022}, publisher = {The Open Journal}, volume = {7}, number = {72}, pages = {4171}, author = {Elizabeth Newman and Lars Ruthotto}, title = {`hessQuik`: Fast Hessian computation of composite functions}, journal = {Journal of Open Source Software} }

Acknowledgements

This material is in part based upon work supported by the US National Science Foundation under Grant Number 1751636, the Air Force Office of Scientific Research Award FA9550-20-1-0372, and the US DOE Office of Advanced Scientific Computing Research Field Work Proposal 20-023231. Any opinions, findings, and conclusions or recommendations expressed in this material are those of the author(s) and do not necessarily reflect the views of the funding agencies.

Owner

  • Login: elizabethnewman
  • Kind: user
  • Company: Emory University

JOSS Publication

`hessQuik`: Fast Hessian computation of composite functions
Published
April 25, 2022
Volume 7, Issue 72, Page 4171
Authors
Elizabeth Newman ORCID
Emory University, Department of Mathematics
Lars Ruthotto ORCID
Emory University, Department of Mathematics
Editor
Mehmet Hakan Satman ORCID
Tags
python pytorch deep neural networks input convex neural networks

GitHub Events

Total
  • Watch event: 2
Last Year
  • Watch event: 2

Committers

Last synced: 7 months ago

All Time
  • Total Commits: 385
  • Total Committers: 3
  • Avg Commits per committer: 128.333
  • Development Distribution Score (DDS): 0.016
Past Year
  • Commits: 0
  • Committers: 0
  • Avg Commits per committer: 0.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
elizabethnewman e****n@e****u 379
Mehmet Hakan Satman m****n@g****m 3
Lars Ruthotto l****o 3
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 4
  • Total pull requests: 11
  • Average time to close issues: 6 days
  • Average time to close pull requests: about 2 hours
  • Total issue authors: 3
  • Total pull request authors: 3
  • Average comments per issue: 2.75
  • Average comments per pull request: 0.09
  • Merged pull requests: 9
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • GregaVrbancic (2)
  • elizabethnewman (1)
  • yhtang (1)
Pull Request Authors
  • elizabethnewman (8)
  • jbytecode (2)
  • lruthotto (1)
Top Labels
Issue Labels
good first issue (1)
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 36 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 1
  • Total versions: 6
  • Total maintainers: 1
pypi.org: hessquik

AD-free gradient and Hessian computations

  • Versions: 6
  • Dependent Packages: 0
  • Dependent Repositories: 1
  • Downloads: 36 Last month
Rankings
Dependent packages count: 10.1%
Stargazers count: 15.2%
Dependent repos count: 21.6%
Forks count: 22.6%
Average: 24.6%
Downloads: 53.3%
Maintainers (1)
Last synced: 6 months ago

Dependencies

setup.py pypi
  • torch *
.github/workflows/python-app.yml actions
  • actions/checkout v2 composite
  • actions/setup-python v2 composite