Giter VIP home page Giter VIP logo

hesscale's Introduction

HesScale: Scalable Computation of Hessian Diagonals

HesScale is built on top of Pytorch and BackPack. It allows for Hessian diagonals to backpropagate through the layers of the network.

Installation:

1. You need to have environemnt with python 3.7:

python3.7 -m venv .hesscale
source .hesscale/bin/activate

2. Install Dependencies:

python -m pip install --upgrade pip
pip install .

Run a minimal example:

We added a couple of minimal examples in the examples directory for easier understanding of how to use this package. Here is a minimal example:

import torch
from backpack import backpack, extend
from optimizers.adahesscale import AdaHesScale

hidden_units = 128
n_obs = 6
n_classes = 10
lr = 0.0004
batch_size = 1

model = torch.nn.Sequential(
    torch.nn.Linear(n_obs, hidden_units),
    torch.nn.Sigmoid(),
    torch.nn.Linear(hidden_units, hidden_units),
    torch.nn.Tanh(),
    torch.nn.Linear(hidden_units, n_classes),
)
loss_func = torch.nn.CrossEntropyLoss()
optimizer = AdaHesScale(model.parameters(), lr=lr)

extend(model)
extend(loss_func)

inputs = torch.randn((batch_size, n_obs))
target_class = torch.randint(0, n_classes, (batch_size,))

prediction = model(inputs)
optimizer.zero_grad()
loss = loss_func(prediction, target_class)

with backpack(optimizer.method):
    loss.backward()

optimizer.step()

Contributing

We appreciate any help to extend HesScale to recurrent neural networks. If you consider contributing, please fork the repo and create a pull request.

License

Distributed under the MIT License. See LICENSE for more information.

Reproduction

To reproduce the experiments in the paper, you run the scripts in experiemnts directory for reproducing the approximation-quality experiment and the computational-cost experiment. For reproducing the training plots, please refer to the our other repo that uses DeepOBS for complete reproduction of our optimization results.

How to cite

If you use our code, please consider citing our paper too.

Elsayed, M., & Mahmood, A. R. (2022). HesScale: Scalable Computation of Hessian Diagonals. arXiv preprint arXiv:2210.11639.

hesscale's People

Contributors

mohmdelsayed avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

hesscale's Issues

Supported Layers Tracker

Here is a list of the torch.nn modules to be supported for HesScale.

  • Loss functions
    • MSELoss
    • CrossEntropyLoss
  • Activations
    • ReLU
    • Sigmoid
    • Tanh
    • LeakyReLU
    • LogSigmoid
    • ELU
    • SELU
  • Others:
    • Linear
    • Dropout
    • Flatten
  • CNN related layers:
    • MaxPool1d
    • MaxPool2d
    • AvgPool1d
    • MaxPool3d
    • AvgPool2d
    • AvgPool3d
    • ZeroPad2d
    • Conv1d
    • Conv2d
    • Conv3d
    • ConvTranspose1d
    • ConvTranspose2d
    • ConvTranspose3d
  • Recurrent related layers:
    • RNN
    • LSTM

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.