Skip to main content

PyPI version License: MIT GitHub Repo stars PyPI - Python Version

Trainer Tools

A lightweight, hook-based training loop for PyTorch. trainer-tools abstracts away the boilerplate of training loops while remaining fully customizable via a powerful flexible hook system.

Full Documentation

📘 Read the complete documentation here!

There you will find in-depth guides and API references on:

  • Customizing train_step and eval_step validation runs
  • Powerful robust metric tracking
  • Writing your own custom hooks
  • All built-in hooks (AMP, Checkpointing, EMA, Gradient Accumulation, HF Accelerate, etc.)

Features

  • Hook System: Customize every step of the training lifecycle (before/after batch, step, epoch, fit).
  • Built-in Integrations: Comes with hooks for wandb or trackio, Progress Bar, and Checkpointing.
  • Optimization: Easy Automatic Mixed Precision (AMP), Gradient Accumulation, and Gradient Clipping.
  • Metrics: robust metric tracking and logging to JSONL or external trackers.
  • Memory Profiling: Built-in tools to debug CUDA memory leaks.

Installation

# Recommended installation (includes accelerate, trackio, and hydra)
pip install trainer-tools[core]

# Minimal installation
pip install trainer-tools

# With optional integrations
pip install trainer-tools[wandb]      # Weights & Biases logging
pip install trainer-tools[trackio]    # Trackio logging
pip install trainer-tools[hydra]      # Hydra config management
pip install trainer-tools[all]        # All optional dependencies

Quick Start

Here is a minimal example of training a simple model:

import torch
import torch.nn as nn
from torch.utils.data import DataLoader, TensorDataset
from trainer_tools.trainer import Trainer
from trainer_tools.hooks import MetricsHook, Accuracy, Loss, ProgressBarHook

# 1. Prepare Data
x = torch.randn(100, 10)
y = torch.randint(0, 2, (100,))
ds = TensorDataset(x, y)
dl = DataLoader(ds, batch_size=32)

# 2. Define Model and Optimizer
model = nn.Sequential(nn.Linear(10, 2))
optimizer = torch.optim.Adam(model.parameters(), lr=1e-3)

# 3. Define the Training Step
def train_step(batch, trainer):
    inputs, labels = batch
    logits = trainer.model(inputs)
    loss = nn.CrossEntropyLoss()(logits, labels)
    
    # Must return a dictionary containing at least the "loss" key!
    return {
        "loss": loss,
        "logits": logits,
        "labels": labels
    }

# 4. Setup Hooks
metrics = MetricsHook(metrics=[Accuracy(pred_key="logits", target_key="labels"), Loss()])
pbar = ProgressBarHook()

# 5. Train
trainer = Trainer(
    model=model,
    train_dl=dl,
    valid_dl=dl,
    optim=optimizer,
    train_step=train_step,
    epochs=5,
    hooks=[metrics, pbar],
    device="cuda" if torch.cuda.is_available() else "cpu"
)

trainer.fit()

Release files for trainer-tools 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for trainer-tools 0.5.0
File Size Uploaded
trainer_tools-0.5.0.tar.gz 132.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for trainer-tools 0.5.0
File Interpreter ABI Platform
trainer_tools-0.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 161.9 kB

Release files / trainer_tools-0.5.0.tar.gz

Download URL trainer_tools-0.5.0.tar.gz
Size 132.9 kB
Tags Source
SHA-256 checksum
How to use checksums
85240289e1edfb7b5b5b9f04c4de4f1e99e1d01d7bca5c0d7ec6356826e39037
BLAKE2b-256 checksum
How to use checksums
9f4636d6319b3664f3f269760dd8b2d6ed651753c98723c8b095b102da966ea6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 10, 2026.

Transparency log

Release files / trainer_tools-0.5.0-py3-none-any.whl

Download URL trainer_tools-0.5.0-py3-none-any.whl
Size 29.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
63904c94cf111e86ef1b1dec350f348dfcdf6dddd66c6c5a81154184f7b93302
BLAKE2b-256 checksum
How to use checksums
a967b9e62d2197f3439d2f0cbc9eb51065ec08c795ae7125f239d80c827220fd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 10, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.5.0 This release

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page