Skip to content

KelvinKan/hessQuik

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

228 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hessQuik

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

Installation

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:

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:

d = 10 # dimension of the input features
widths = [32, 64] # hidden channel dimensions
f = net.NN(lay.singleLayer(d, widths[0], act.antiTanhActivation()), 
           lay.resnetLayer(widths[0], h=1.0, act.softplusActivation()),
           lay.singleLayer(widths[0], widths[1], act.quadraticActivation())
           )

You can obtain gradients and Hessians via

nex = 20 # number of examples
x = torch.randn(nex, d)
fx, dfx, d2fx = f(x, do_gradient=True, do_Hessian=True)

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
git clone https://github.com/<username>/hessQuik.git
  1. Contribute to your forked repository
  2. 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 implemetnation bug, include a small example that helps to reproduce the error. The issue will be addressed as quickly as possible.

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.

About

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

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • Python 64.4%
  • Jupyter Notebook 29.6%
  • TeX 6.0%