Automatic distributed training for ML models: detects hardware, picks a strategy, tunes batch size.
Project description
Autotrainer
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)
- 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.
- Train: the winning recipe is retrained from your model's original
init through
prepare()- soautotrainer rundistributes 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
- CHANGELOG - version history.
- API reference - generated with pdoc; build locally with
pdoc -o docs/build src/autotrainer. - Examples - runnable scripts for each framework and SLURM
.sbatchtemplates. - Environment variables - every knob autotrainer reads.
- Contributing | Security policy | Code of Conduct.
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
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 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
468d5b487cf1d870035fbcc90884316d81f2101fd4596816604b1d0bc79d05df
|
|
| MD5 |
c3cbc82c8f85c4965ffa5ee9269322a2
|
|
| BLAKE2b-256 |
c29b9660ff4485c535449c1247f91bf5ab661730bece8f44750bdd28c6a3a694
|
Provenance
The following attestation bundles were made for autotrainer-0.9.0.tar.gz:
Publisher:
ci.yml on OriAlpha/Autotrainer
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
autotrainer-0.9.0.tar.gz -
Subject digest:
468d5b487cf1d870035fbcc90884316d81f2101fd4596816604b1d0bc79d05df - Sigstore transparency entry: 2186057279
- Sigstore integration time:
-
Permalink:
OriAlpha/Autotrainer@2f75fc6f9e3437f7a57a777c0b10b7db503337b4 -
Branch / Tag:
refs/tags/v0.9.0 - Owner: https://github.com/OriAlpha
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@2f75fc6f9e3437f7a57a777c0b10b7db503337b4 -
Trigger Event:
release
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b16d3524fb6cb3a5b0e95e1680fa72af0cb66b6f619796410fa5dfd1c7aaf4cc
|
|
| MD5 |
b0e9aa4dede05848825fac2e36b85bf0
|
|
| BLAKE2b-256 |
07de04a64301ede0c17a7d209893921fb2bddabf38698e83c86e1bb09122d202
|
Provenance
The following attestation bundles were made for autotrainer-0.9.0-py3-none-any.whl:
Publisher:
ci.yml on OriAlpha/Autotrainer
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
autotrainer-0.9.0-py3-none-any.whl -
Subject digest:
b16d3524fb6cb3a5b0e95e1680fa72af0cb66b6f619796410fa5dfd1c7aaf4cc - Sigstore transparency entry: 2186057441
- Sigstore integration time:
-
Permalink:
OriAlpha/Autotrainer@2f75fc6f9e3437f7a57a777c0b10b7db503337b4 -
Branch / Tag:
refs/tags/v0.9.0 - Owner: https://github.com/OriAlpha
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@2f75fc6f9e3437f7a57a777c0b10b7db503337b4 -
Trigger Event:
release
-
Statement type: