A simple, flexible training framework for PyTorch models.
Project description
simpletrainer
🚀 Overview
simpletrainer keeps your PyTorch training tidy: metrics, early stopping, LR schedules, checkpoints, and optional W&B. Supports binary, multiclass, multilabel classification and regression.
🧩 Installation
From PyPI
Install the correct PyTorch build for your platform first
pip install simpletrainer
From source
git clone https://github.com/rahaahmadi/simpletrainer.git
cd simpletrainer
pip install -e .
⚙️ Quickstart Example
import torch
from torch import nn, optim
from torch.utils.data import DataLoader, TensorDataset
from simpletrainer import BaseTrainer
X = torch.randn(512, 16)
y = (torch.randn(512) > 0).float()
ds = TensorDataset(X, y)
train_loader = DataLoader(ds, batch_size=64, shuffle=True)
test_loader = DataLoader(ds, batch_size=128)
model = nn.Sequential(nn.Linear(16, 32), nn.ReLU(), nn.Linear(32, 1))
criterion = nn.BCEWithLogitsLoss()
optimizer = optim.Adam(model.parameters(), lr=1e-3)
scheduler = optim.lr_scheduler.ReduceLROnPlateau(optimizer, mode="max", patience=2)
trainer = BaseTrainer(
model=model,
train_loader=train_loader,
test_loader=test_loader,
criterion=criterion,
optimizer=optimizer,
scheduler=scheduler,
task_type="binary",
early_stopping_patience=5,
grad_clip=1.0,
wandb_project="my-project", # optional
)
best_epoch, best_metrics = trainer.fit(num_epochs=25, save_path="checkpoints/run/model")
print("Best epoch:", best_epoch)
print("Best metrics:", best_metrics)
✨ Features
- Tasks:
binary classification,multiclass classification,multilabel classification,regression - Metrics: AUC / F1 / Accuracy (classification), MSE / MAE / R² (regression)
- Training features: early stopping, gradient clipping, LR schedulers
- Checkpointing:
save_model/load_modelutilities - Logging: optional Weights & Biases (auto-skips if not installed)
🤝 Contributing
Issues and PRs are welcome.
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 torch_simpletrainer-0.1.0.tar.gz.
File metadata
- Download URL: torch_simpletrainer-0.1.0.tar.gz
- Upload date:
- Size: 7.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1725a8c9b4b44c53a48856ebbc74f1a3429d2ae5fd7c6f65c9fd333fe75ab700
|
|
| MD5 |
8efef164dff3f5282ce09546f0ed642d
|
|
| BLAKE2b-256 |
504a7fedaf2bb82df35da3bbadecef78f5ab5826b2d44a1e4473162f68ff1778
|
File details
Details for the file torch_simpletrainer-0.1.0-py3-none-any.whl.
File metadata
- Download URL: torch_simpletrainer-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2f99aca7d5bcef86f4b7d87e41c60f13d1a436828fe99ceb657d81d35cc1b67a
|
|
| MD5 |
feb66b3e51c42b43eaad34b6169d8736
|
|
| BLAKE2b-256 |
95d3759a03ee4c7d3119911c61a77ebb64a6f717971662976057f88a9c1f15ad
|