PyTorch trainer
Are you tired of writing those same epoch and data-loader loops to train your PyTorch module ? Look no further, PyTorch trainer is a library that hides all those boring training lines of code that should be native to PyTorch.
You will also benefit from the following features:
- Early stopping: stop training after a period of stagnation
- Checkpointing: save model and estimator at regular intervals
- CSV file writer to output logs
- Several metrics are available: all default PyTorch loss functions, Accuracy, MAE
- Progress bar from console
- SIGINT handling: handle CTRL-C
- Model's data type (
float32,float64)
Example
Code examples can be found in the example folder.
Here is a simple example:
import torch
import pytorchtrainer as ptt
# Your usual model, optimizer, loss function and data loaders
model = MyModel()
optimizer = torch.optim.Adam(self.model.parameters(), lr=1e-3)
criterion = torch.nn.MSELoss()
train_loader = MyTrainDataloader()
validation_loader = MyValidationDataloader()
# instantiate a default trainer
trainer = ptt.create_default_trainer(model, optimizer, criterion)
# optionally save a checkpoint after every 10 epochs
trainer.register_post_epoch_callback(ptt.checkpoint.SaveCheckpointCallback(save_every=10))
# optionally compute validation loss after every epoch
validation_callback = ptt.callback.ValidationCallback(validation_loader, ptt.metric.TorchLoss(criterion), validate_every=1)
trainer.register_post_epoch_callback(validation_callback)
# optionally save training and validation loss after every iteration using default save directory
trainer.register_post_iteration_callback(ptt.callback.CsvWriter(save_every=1,
extra_header=[validation_callback.state_attribute_name],
callback=lambda state: [state.get(validation_callback.state_attribute_name)]))
# run the training
trainer.train(train_loader, max_epochs=100)
Dependencies
- python > 3.5
- pytorch > 1.0.0 (install instructions from the official PyTorch website)
Contributing
Feel free to submit an issue or pull request. But before you do please read the contributing guidelines
Metadata
Release files for pytorchtrainer 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pytorchtrainer-0.2.1.tar.gz | 14.0 kB | Without provenance | Details for pytorchtrainer-0.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pytorchtrainer-0.2.1-py3-none-any.whl | Python 3 | none | any | Details for pytorchtrainer-0.2.1-py3-none-any.whl |
Total release size: 29.3 kB
Release files / pytorchtrainer-0.2.1.tar.gz
| Download URL | pytorchtrainer-0.2.1.tar.gz |
|---|---|
| Size | 14.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
28821a04052fe527d6a770e5cdb9eb70f31302c3a6e726bd7533c76c140fb47c
|
|
BLAKE2b-256 checksum How to use checksums |
728c8c60ea5a271da20463c08a2df382371107f52be5b69a21c07b3eb063c6f8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.14.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.5.7
|
Release files / pytorchtrainer-0.2.1-py3-none-any.whl
| Download URL | pytorchtrainer-0.2.1-py3-none-any.whl |
|---|---|
| Size | 15.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
92b9319e9be77d801e31448f1b243fa7b9183b4babd170679de80271391d44a1
|
|
BLAKE2b-256 checksum How to use checksums |
fd15a213a07abd20f3f9063b16dcf50793e7823a963b75495132787fab4d5a28
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.14.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.35.0 CPython/3.5.7
|
Security for pytorchtrainer 0.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.