🔥 pyro
Lightweight Machine Learning framework allowing plug-and-play training for Pytorch models
- ⚡ Lightning inspired
- 💾 Support for wandb and checkpoints out-of-the-box
- 📊 Pretty logs, plots and support for metrics
- ✨ Fully type-safe
- 🪶 Lightweight and easy to use
Examples
See 📓 notebooks for examples using pyro. In particular, you can find:
- Iris : Simplest example training a small MLP on the Iris dataset.
- SmolVLM on Flowers102 : Features from SmolVLM vision model are extracted and used to train a linear classifier on the Flowers102 dataset, reaching a test accuracy of 98.6%.
Usage
You can use 🔥 pyro with minimal code changes and forever forget about writing training loops. Here is an example of a pyro model and training script to get you started.
1. Define your Model
import torch
import pyroml as p
class MySOTAModel(p.PyroModule):
def __init__(self):
super().__init__()
self.loss_fn = torch.nn.MyLossFunction()
# Optionally, configure your own optimizer and scheduler, see more in the docs
def configure_optimizers(self, _):
self.optimizer = torch.optim.AdamW(self.parameters(), lr=tr.lr)
self.scheduler = torch.optim.lr_scheduler.StepLR(
self.optimizer, step_size=1, gamma=0.99
)
def step(self, batch, stage: p.Stage):
# Extract data from your dataset batch
# Batches and model are moved to the appropriate device automatically
x, y = batch
# Forward the model
preds = self(x)
# Compute the loss
loss = self.loss_fn(preds, y)
# Optionally, register some metrics
self.log(loss=loss.item(), accuracy=compute_accuracy(preds, y))
# Return loss when training, otherwise return predictions
if stage == p.Stage.TRAIN:
return loss
return preds
2. Instantiate a Trainer
trainer = p.Trainer(
lr=0.01,
max_epochs=32,
batch_size=16,
# And many other options such as device, precision, callbacks, ...
)
3. Run training, validation and testing
# Fit the model on given training set and evaluate the model during training
train_tracker = trainer.fit(model, training_dataset, validation_dataset)
print(train_tracker.records)
# Plot metric curves registered during training
train_tracker.plot(epoch=True)
# Evaluate your model after training
validation_tracker = trainer.evaluate(model, validation_dataset)
print(validation_tracker.records)
# Test your model on some testing set
_, test_preds = trainer.predict(model, test_dataset)
print("Test Predictions", test_preds)
Requirements
- Python ^3.10 | ^3.11 | ^3.12
- Recommended: Poetry v2 (docs)
Installation
pip
# CPU only version
pip install pyroml
# OR with CUDA-enabled PyTorch and torchvision
pip install pyroml[cuda]
# Additional dependencies that you might require
pip install pyroml[extra]
poetry
# CPU only version
poetry add pyroml
# OR with CUDA-enabled PyTorch and torchvision
poetry add pyroml[cuda] --source pytorch-cu124
# Additional dependencies that you might require
poetry add [...] --extras extra
Locally
# Clone the repo
git clone https://github.com/peacefulotter/pyroml.git
cd pyroml
# Install dependencies
poetry config virtualenvs.in-project true
poetry install --with cpu,dev # ,cuda
Tests
Running tests has been made easy using pytest. First install the package and run the script:
poetry install --with test
./run_tests.sh
Metadata
Release files for pyroml 2.1.2
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 |
|---|---|---|---|---|
| pyroml-2.1.2.tar.gz | 34.6 kB | Without provenance | Details for pyroml-2.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyroml-2.1.2-py3-none-any.whl | Python 3 | none | any | Details for pyroml-2.1.2-py3-none-any.whl |
Total release size: 87.0 kB
Release files / pyroml-2.1.2.tar.gz
| Download URL | pyroml-2.1.2.tar.gz |
|---|---|
| Size | 34.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d07f86c36fca4093925b803c4b83efd4ae5608621f5fe28007596883ea99a360
|
|
BLAKE2b-256 checksum How to use checksums |
a77d0a568e772d9bb5b8d7cee13adbf3b9caa2ea4b76a23d9ed980ea26c75ac2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.6.1
|
Release files / pyroml-2.1.2-py3-none-any.whl
| Download URL | pyroml-2.1.2-py3-none-any.whl |
|---|---|
| Size | 52.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ea249a0ba5c8569aa0f25e78defaf8691e6d4e36be26dfcee983d09bdf3fd1ee
|
|
BLAKE2b-256 checksum How to use checksums |
03deab1fe6e1cbce15ec182466e29d4ea43b3a9d004553c09504f13afa624345
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.6.1
|
Security for pyroml 2.1.2
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.