Skip to main content

Continual Resilient (CoRe) optimizer for PyTorch

Project description

Introduction

The module core_optimizer provides a PyTorch implementation of the Continual Resilient (CoRe) optimizer. The CoRe optimizer is a first-order gradient-based optimizer for stochastic and deterministic iterative optimizations. It applies weight-specific learning rate adaption depending on the optimization progress. Its algorithm combines Adam- and RPROP-like step size updates and employs weight regularization and decay.

Installation

The module core_optimizer can be installed using pip3 once the repository has been cloned.

git clone <core_optimizer-repository>
pip3 install ./core_optimizer

A non super user can install the package using a virtual environment or the --user flag. If there is no space left on device for TMPDIR, one can use TMPDIR=<PATH> in front of pip3, with <PATH> being a directory with more space for temporary files.

Usage

The CoRe optimizer can be applied in the same way as the optimizers in torch.optim. The only exception is the import of the optimizer.

from core_optimizer import CoRe

optimizer = CoRe(...)   # dots are placeholders for model parameters and optimizer hyperparameters

For comparison the following code block shows the usage of the Adam optimizer from torch.optim.

from torch.optim import Adam

optimizer = Adam(...)   # dots are placeholders for model parameters and optimizer hyperparameters

The minimal workflow of training a PyTorch model is shown in the next code block. Examples which are ready to go can be found in test_core_optimizer.py.

import torch
from core_optimizer import CoRe

# set up input and expected outputs for training
inputs = torch.tensor(...)   # dots are placeholders for input data
labels = torch.tensor(...)   # dots are placeholders for expected output data

# define loss function, model, and optimizer
loss_fn = torch.nn.modules.loss.TorchLoss()   # TorchLoss is a placeholder for any Torch loss function
model = TorchModel()   # TorchModel is a placeholder for any Torch model
optimizer = CoRe(model.parameters(), step_sizes=(1e-6, 1e-2))   # define CoRe optimizer

# run training steps
for i in range(...):   # dots are a placeholder for number of steps
    optimizer.zero_grad()   # zero optimizer's gradients
    outputs = model(inputs)   # predict output
    loss = loss_fn(outputs, labels)   # calculate loss
    loss.backward()   # calculate loss gradient
    optimizer.step()   # adjust model parameters

The algorithm and all hyperparameters of the CoRe optimizer are explained in the file docs.pdf.

How to Cite

When publishing results obtained with the CoRe optimizer, please cite M. Eckhoff, M. Reiher, Lifelong Machine Learning Potentials, J. Chem. Theory Comput. 19, 3509-3525 (2023) and M. Eckhoff, M. Reiher, CoRe Optimizer: An All-in-One Solution for Machine Learning, arXiv:2307.15663 [cs.LG] (2023).

Support and Contact

In case you encounter any problems or bugs, please write a message to lifelong_ml@phys.chem.ethz.ch.

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

core_optimizer-1.0.1.tar.gz (11.7 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page