Skip to main content

Summary

The primary objective of Toadstool is to provide the PyTorch boilerplate for training and testing loops, along with a callback interface that allows for any customizability you'd like. (See: models/dl_utils.py)

A secondary objective of Toadstool is to provide generally useful callbacks and other methods for conducting deep learning experiments. (See: everything else)

Toadstool is meant to be a shallow abstraction over PyTorch and thus does not abstract many decisions other training libraries will hide from end users.

Basic Usage

from toadstool import Trainer
from toadstool.models.callbacks import CudaCallback, EarlyStopping, GradClipCallback, MonitorCallback

num_epochs = 5
t = Trainer(model, optim, loss_fn,
            callbacks=[GradClipCallback(),
                       MonitorCallback(),
                       EarlyStopping(patience=1),
                       CudaCallback(device)],
               opt_to_none=True)
t.fit(num_epochs, trainl, validl)

In its simplest form:

  • model: torch.nn.Module
  • optim: torch.optim.Optimizer
  • loss_fn: torch.nn.modules.loss.*
  • trainl, validl: torch.nn.data.dataloader

However, all are duck typed, so you can easily wrap them to suit your needs.

Basic tenets of Toadstool:

  1. You design the model
    • should accept the x (batch) from the dataset and should return a y^ (predicted target) that is accepted by the loss function.
  2. You design the data
    • should return a tuple (x, y) or (batch, target)
      • x is passed to the model
      • y is passed to the loss function

Examples

The following examples aim to demonstrate the basic use case of toadstool. Toadstool focuses on handling the boilerplate PyTorch code of running data through a model. While Toadstool does come with some example models and datasets that match the expected Toadstool format (see Basic Usage), these exemplars are not required to be used. The Toadstool models and datasets were originally created for a specific task, but are intended to be generic enough to be useful on additional tasks.

The expected use cases of Toadstool are:

  1. creating custom models and datasets that match the framework
  2. creating callbacks and wrappers that adapt already created models and datasets to the framework

Included examples:

example.ipynb

Task: Sentiment classification on IMDB dataset

Format: Utilizes Toadstool model (toadstool.models.zoo.TransformerModel) on the torchtext dataset IMDB.

Advanced Topics

Distributed training

src/toadstool/distributed.py contains helper functions for setting up a process group and executing a run_fn worker call for that process group.

Especially useful along with toadstool.models.utils fsdp_wrap and ddp_wrap to automatically shard/distribute data and model interactions across the process group.

Contributing

Please insure any pull requests pass ruff format, ruff check, and pytest

Testing

Tests are in the tests folder. See documentation on pytest for information on how to write and extend these tests. The tests are a blend of unit and behavior tests.

To test, make sure you have installed pytest and the other dependencies needed for the toadstool codebase. Then, in the app root, run:

pytest

for more extensive tests of the given example models

pytest --models

Release files for snl-toadstool 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for snl-toadstool 1.0.0
File Size Uploaded
snl_toadstool-1.0.0.tar.gz 48.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for snl-toadstool 1.0.0
File Interpreter ABI Platform
snl_toadstool-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 106.9 kB

Release files / snl_toadstool-1.0.0.tar.gz

Download URL snl_toadstool-1.0.0.tar.gz
Size 48.2 kB
Tags Source
SHA-256 checksum
How to use checksums
dfd420283263aabc9bf20d7434312adf963b805e3066cc9d7c9c8fc8ef9b03af
BLAKE2b-256 checksum
How to use checksums
0c45e6a0ba4b480f842d4e11657390581aca81bd8c02386eb10a7651f2a14438
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.2

Release files / snl_toadstool-1.0.0-py3-none-any.whl

Download URL snl_toadstool-1.0.0-py3-none-any.whl
Size 58.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
77652c5aa7e1f5c1e645457e190994668594f59cbf205e027273d6ada07d4f5d
BLAKE2b-256 checksum
How to use checksums
d3d5586c20b532c07b1caebd511d8b158f086aa081acbcfc6240eb2a55dafa71
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.2

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page