A lightweight package for fast, GPU-accelerated computation of gradients and Hessians of functions constructed via composition.
python -m pip install git+https://github.com/elizabethnewman/hessQuik.gitThese dependencies are installed automatically with pip.
- torch (recommended version >= 1.10.0, but code will run with version >= 1.5.0)
Once you have installed hessQuik, you can import as follows:
import hessQuik.activations as act
import hessQuik.layers as lay
import hessQuik.networks as netYou 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)To make the code accessible, we provide some introductory Google Colaboratory notebooks.
Practical Use: Hermite Interpolation
Tutorial: Constructing and Testing hessQuik Layers
To contribute to hessQuik, follow these steps:
- Fork the
hessQuikrepository - Clone your fork using
git clone https://github.com/<username>/hessQuik.git- Contribute to your forked repository
- 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.
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.
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.