Skip to main content

A toolkit for training pytorch models

Project description

Introduction

This package contains a Trainer class that streamlines the training of models and recording of results. The Trainer class is designed in a modular way using Mixins. This approach can be used to extend its capabilities beyond what it currently provides. Additionally, the class makes use of an eventing pattern that allows users to register event handlers that will be executed at specified points in training. The Trainer class can be found in trainer.py. All of the Mixins are stored in mixins.py. The module events.py contains the definitions of possible events and utils.py contains other miscellaneous code.

Installation

simply install from PyPi using pip install pt-trainer

Usage

Initialize a Trainer instance by passing a PyTorch model (inherited from nn.Module), PyTorch Dataloader instance, optimizer (PyTorch or apex) and a loss function that accepts the model prediction and targets and returns a loss tensor. Alternatively, a Trainer can be created from a config file. The config file should be another python file and contain the following variables:

  • MODEL: class of the model
  • DATASET: class of the dataset
  • LOSS: class of the loss function
  • OPTIMIZER: class of the optimizer
  • LOGDIR: path to the directory in which files generated by the trainer will be written
  • model: dict with kwargs for MODEL
  • dataset: dict with kwargs for DATASET
  • dataloader: dict with kwargs for the dataloader that will wrap DATASET
  • loss: dict with kwargs for LOSS
  • optimizer: dict with kwargs for OPTIMIZER
  • trainer: dict with kwargs for the Trainer class, such as split_sample

Optionally the APEX variable and apex dict can be specified to wrap the OPTIMIZER.

Once initialized, you can register event handlers using the method register_event_handler, specifying the handler and the event on which it will be called. There are four possible events: before training, each step, each epoch and after training.

Training is then executed using the train method and passing either n_epochs or n_steps.

Example

In the folder titled 'examples' I have set up a simple case of training a feed-forward neural net on a portion of MNIST. This examples illustrates how to setup the config and how to use the trainer. Try running dummy_training.py if you want to train the model.

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

pt-trainer-0.0.8.tar.gz (11.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pt_trainer-0.0.8-py3-none-any.whl (15.3 kB view details)

Uploaded Python 3

File details

Details for the file pt-trainer-0.0.8.tar.gz.

File metadata

  • Download URL: pt-trainer-0.0.8.tar.gz
  • Upload date:
  • Size: 11.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.1

File hashes

Hashes for pt-trainer-0.0.8.tar.gz
Algorithm Hash digest
SHA256 4e9eb8933c0b46896cb1c6354e76633c7c3fd0ea96680031d24a48e37d51321a
MD5 f171f78129ee2f3a54dc078685f3ead1
BLAKE2b-256 d62273f8b80b4d45a3aa1d500fa018cec0353585153c80c37401dcbed13aea7b

See more details on using hashes here.

File details

Details for the file pt_trainer-0.0.8-py3-none-any.whl.

File metadata

  • Download URL: pt_trainer-0.0.8-py3-none-any.whl
  • Upload date:
  • Size: 15.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.1

File hashes

Hashes for pt_trainer-0.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 8e625ef5e45e9c99613cc2570f352a469b1cbcf2f8cb015694ef6334cd059fbf
MD5 28e87e9f28994f3d7453934d1ed4e21d
BLAKE2b-256 9ca2a6ba8c28e1d3378ac4c0d2630a93df098e9c86288acf8a1e70ec6882bc69

See more details on using hashes here.

Supported by

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