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
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)
| File | Size | Uploaded | |
|---|---|---|---|
| snl_toadstool-1.0.0.tar.gz | 48.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| 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
|