Home

Awesome

boiler-pytorch

Basic framework for training stuff in PyTorch. It's quite tailored to projects I've been working on lately, so it's meant for personal use. Its sole purpose is to do away with boilrplate code, and having it here makes it easier to share it across projects.

Install

pip install boilr

Usage example/template

There's a usage example that can be useful as template. It's a basic VAE for MNIST quickly hacked together. The example files are:

Install requirements and run the example:

pip install -r requirements.txt
CUDA_VISIBLE_DEVICES=0 python example.py

For evaluation:

CUDA_VISIBLE_DEVICES=0 python example_evaluate.py --ll --ll-samples 100 --load $RUN_NAME

using the name of the folder in output/ generated from running the example.

Quick reference

Built-in functionalities

The following functionalities are available out-of-the-box:

Command-line arguments

There are built-in command-line arguments with default values. These defaults can be easily overridden programmatically when making the experiment class that subclasses boilr's. The built-in arguments are the following:

Additionally, for VAEExperimentManager, the following arguments are available:

Getting started

  1. subclass a base dataset manager class;
  2. subclass a base model class;
  3. subclass a base experiment manager class (the model class is used in here);
  4. make a short script that creates the experiment object, uses it to create a boilr.Trainer, and runs the trainer;
  5. optionally, subclass the base evaluator to set up an "offline" evaluation pipeline.

See below for more details.

Dataset manager class (1)

The class boilr.data.BaseDatasetManager must be subclassed. The subclass must implement the method _make_datasets which should return a tuple (train, test) with the training and test sets as PyTorch Datasets. A basic implementation of _make_dataloaders is already provided, but can be overridden to make custom data loaders.

Model class (2)

One of the model classes must be subclassed to inherit core methods in the base implementation boilr.models.BaseModel. These models also automatically subclass torch.nn.Module (so it must implement forward). In addition, boilr.models.BaseGenerativeModel (subclassing BaseModel) defines a method sample_prior that must be implemented by subclasses.

Experiment manager class (3)

One of the base experiment classes in boilr.experiments must be subclassed. The subclass must implement:

Typically should be overridden:

May be overridden for additional control:

Note: The class VAEExperimentManager implements default test_procedure and save_images methods for variational inference with VAEs.

Example training script (4)

from boilr import Trainer
from my_experiment import MyExperimentClass

if __name__ == "__main__":
    experiment = MyExperimentClass()
    trainer = Trainer(experiment)
    trainer.run()

Offline evaluator class (5)

If offline evaluation is necessary, boilr.eval.BaseOfflineEvaluator can be subclassed by implementing:

The method run can be executed by simply calling the evaluator object. See example_evaluate.py.

Notes