Skip to main content

Automatic distributed training for ML models: detects hardware, picks a strategy, tunes batch size.

Project description

Autotrainer

CI PyPI Python License: MIT Code style: ruff

Automatic distributed training and optimization for ML models. Give it a model and data - it detects your hardware (local GPUs or a SLURM cluster), picks the distribution strategy, and can infer the loss function, optimizer, learning rate, and schedule, or search for the best training hyperparameters.

Supports PyTorch (DDP, SLURM multi-node), TensorFlow/Keras (Mirrored / MultiWorker strategies), scikit-learn, XGBoost, and LightGBM - all through one API.

import autotrainer

# Smart defaults: loss, optimizer, LR, and schedule inferred and printed
model, loader, opt, loss_fn, sched = autotrainer.auto(model, loader)

# Or search for the best training recipe for YOUR model
best_model, best_params, study = autotrainer.tune(model, train_loader, val_loader)

# tune() also handles sklearn / XGBoost / LightGBM (curated default spaces)
best_est, params, study = autotrainer.tune(XGBClassifier(), (X, y), (X_val, y_val))

# Or fully hands-free: search the recipe, then train the winner to completion
model, params, study = autotrainer.fit(model, train_loader, val_loader)
autotrainer run train.py         # local: 1 or many GPUs, auto-detected
srun autotrainer run train.py    # SLURM: multi-node, zero config
autotrainer doctor               # diagnose your environment first

Install

From PyPI:

pip install autotrainer[torch]            # just PyTorch
pip install autotrainer[torch,boosting]   # PyTorch + XGBoost/LightGBM

Only psutil is required by default; each ML framework is an opt-in extra (torch, sklearn, tf, boosting, tune). Install only what you use.

Install (dev mode)

Using uv (recommended):

uv venv
# On Windows:
.venv\Scripts\activate
# On macOS/Linux:
source .venv/bin/activate

uv pip install -e ".[dev,torch,sklearn,tf,boosting,tune]"

Or using standard pip:

pip install -e ".[dev,torch,sklearn,tf,boosting,tune]"

Use

In your training script, add one line (plus set_epoch at each epoch start, so distributed shuffling gives every epoch a fresh order):

import autotrainer
model, loader, optimizer = autotrainer.prepare(model, loader, optimizer)

for epoch in range(epochs):
    autotrainer.set_epoch(loader, epoch)  # no-op when not distributed
    # ... your normal training loop

Then launch:

autotrainer info                 # show what was detected
autotrainer run train.py         # local machine (1 or many GPUs)

On SLURM, inside your sbatch script:

#SBATCH --nodes=2
#SBATCH --ntasks-per-node=4
#SBATCH --gres=gpu:4
srun autotrainer run train.py

One-call training: fit()

fit() is the whole pipeline in one call - give it a model and data, get back the best model it can produce on your hardware:

model, params, study = autotrainer.fit(model, train_loader, val_loader, trials=30)
  1. Tune: Optuna searches lr / weight decay / optimizer / batch size on short trials. Launched distributed, the trials are split across all ranks via a shared journal-file study - one trial per process, every GPU busy during the search.
  2. Train: the winning recipe is retrained from your model's original init through prepare() - so autotrainer run distributes it across every GPU/node - with warmup+cosine, mixed precision, and early stopping on the val loss. The best epoch's weights are returned.

Pass checkpoint="fit.ckpt" to make it preemption-safe: the full training state is saved every epoch, and rerunning the same script resumes where it died (skipping the search) - ideal for requeued SLURM jobs.

For long searches under multi-process launches, raise the collective timeout with AUTOTRAINER_TIMEOUT (seconds) - see .env.example.

Optional: auto batch size

best = autotrainer.find_batch_size(model, my_one_step_fn)

Documentation

Roadmap

  • Multi-node boosting (xgboost.dask / lightgbm.dask across a SLURM allocation) — currently single-node threads only.
  • Stabilization toward 1.0: freeze the public API (mypy strict mode and real 2-rank distributed tests already gate CI).
  • More schedulers and search spaces beyond warmup+cosine and the default Optuna recipe.

See CHANGELOG.md for the full version history, and open or upvote issues to prioritize these.

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

autotrainer-0.9.0.tar.gz (48.9 kB view details)

Uploaded Source

Built Distribution

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

autotrainer-0.9.0-py3-none-any.whl (36.7 kB view details)

Uploaded Python 3

File details

Details for the file autotrainer-0.9.0.tar.gz.

File metadata

  • Download URL: autotrainer-0.9.0.tar.gz
  • Upload date:
  • Size: 48.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for autotrainer-0.9.0.tar.gz
Algorithm Hash digest
SHA256 468d5b487cf1d870035fbcc90884316d81f2101fd4596816604b1d0bc79d05df
MD5 c3cbc82c8f85c4965ffa5ee9269322a2
BLAKE2b-256 c29b9660ff4485c535449c1247f91bf5ab661730bece8f44750bdd28c6a3a694

See more details on using hashes here.

Provenance

The following attestation bundles were made for autotrainer-0.9.0.tar.gz:

Publisher: ci.yml on OriAlpha/Autotrainer

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file autotrainer-0.9.0-py3-none-any.whl.

File metadata

  • Download URL: autotrainer-0.9.0-py3-none-any.whl
  • Upload date:
  • Size: 36.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for autotrainer-0.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b16d3524fb6cb3a5b0e95e1680fa72af0cb66b6f619796410fa5dfd1c7aaf4cc
MD5 b0e9aa4dede05848825fac2e36b85bf0
BLAKE2b-256 07de04a64301ede0c17a7d209893921fb2bddabf38698e83c86e1bb09122d202

See more details on using hashes here.

Provenance

The following attestation bundles were made for autotrainer-0.9.0-py3-none-any.whl:

Publisher: ci.yml on OriAlpha/Autotrainer

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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