Skip to main content

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

Install name: torch-simpletrainerImport name: simpletrainer

From PyPI

Install the correct PyTorch build for your platform first

pip install torch-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_model utilities
  • Logging: optional Weights & Biases (auto-skips if not installed)

🤝 Contributing

Issues and PRs are welcome.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

torch_simpletrainer-0.1.1.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

torch_simpletrainer-0.1.1-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file torch_simpletrainer-0.1.1.tar.gz.

File metadata

  • Download URL: torch_simpletrainer-0.1.1.tar.gz
  • Upload date:
  • Size: 7.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.13

File hashes

Hashes for torch_simpletrainer-0.1.1.tar.gz
Algorithm Hash digest
SHA256 b5f5d86f71e8c334e68d820f56d173f306fb84f14165e6a6a582cebdab2b58d3
MD5 b3764796fb5a040baf573e3ace71635f
BLAKE2b-256 51c3705c16a468da3ed43073b9282091adb40d98753dbaa4d923dbdc91451caa

See more details on using hashes here.

File details

Details for the file torch_simpletrainer-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for torch_simpletrainer-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 33f6f2d76eacfe627a5327e9fde07099a53325ae0254b03f4cc73665f526067b
MD5 9f41e8706aab96dfa540990c59f1a755
BLAKE2b-256 0bcb0e080545ae55dd1f6b20379c5ff4389705abe57f1f00ef78579641d21b8a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page