Boilerplate/Training library for PyTorch
Project description
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.Moduleoptim: torch.optim.Optimizerloss_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:
- You design the model
- should accept the
x(batch) from the dataset and should return ay^(predicted target) that is accepted by the loss function.
- should accept the
- 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
- should return a tuple (x, y) or (batch, target)
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:
- creating custom models and datasets that match the framework
- 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 datasetIMDB.
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file snl_toadstool-1.0.0.tar.gz.
File metadata
- Download URL: snl_toadstool-1.0.0.tar.gz
- Upload date:
- Size: 48.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dfd420283263aabc9bf20d7434312adf963b805e3066cc9d7c9c8fc8ef9b03af
|
|
| MD5 |
653672874088b8732360e26ffa09d288
|
|
| BLAKE2b-256 |
0c45e6a0ba4b480f842d4e11657390581aca81bd8c02386eb10a7651f2a14438
|
File details
Details for the file snl_toadstool-1.0.0-py3-none-any.whl.
File metadata
- Download URL: snl_toadstool-1.0.0-py3-none-any.whl
- Upload date:
- Size: 58.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
77652c5aa7e1f5c1e645457e190994668594f59cbf205e027273d6ada07d4f5d
|
|
| MD5 |
f4eabfabbd0ed51cb69c6870b8931218
|
|
| BLAKE2b-256 |
d3d5586c20b532c07b1caebd511d8b158f086aa081acbcfc6240eb2a55dafa71
|