PyTorch AutoTune
One call to apply PyTorch's built-in training optimizations — AMP, torch.compile, fused optimizers, TF32 and channels-last — with honest, measured expectations.
Honesty note (v1.0.3). Earlier versions of this README claimed a universal "4x speedup", benchmark tables (including an ImageNet row and an energy study) with no committed evidence, and a "beats torch.compile" comparison that its own mechanism contradicts — this package wraps
torch.compile. Those claims are retracted. What this package actually does: it saves you ~20 lines of boilerplate by applying PyTorch's own optimization features correctly in one call. The speedup those features give is real but workload-dependent, and every number below was measured with the committed script and can be reproduced.
What it does
from pytorch_autotune import quick_optimize
model, optimizer, scaler = quick_optimize(model) # AMP + compile + fused + TF32
One call applies, with sensible per-GPU defaults and manual overrides:
- Mixed precision (
torch.ampautocast +GradScaler) torch.compile(default /reduce-overhead/max-autotune)- Fused optimizers (
AdamW/Adamwithfused=True) - TF32 on Ampere+, channels-last for CNNs,
cudnn.benchmark
These are PyTorch's features, not this package's — the package is a convenience wrapper. If you're comfortable setting them up yourself, you don't need it.
Measured results
Measured with benchmarks/measure.py on an
A100-SXM4-40GB, PyTorch 2.13.0+cu129, 2026-08-25. ms/step is a full
training step (forward + loss + backward + optimizer), median-of-loop after
warmup, compile time excluded (it is real but one-off).
| Workload | Baseline fp32 eager | AutoTune | Speedup |
|---|---|---|---|
| ResNet-50, 224×224, batch 64 | 73.3 ms | 28.0 ms | 2.62× |
| ResNet-18, 32×32 (CIFAR-shape), batch 128 | 8.1 ms | 6.4 ms | 1.26× |
— same, but without torch.compile |
8.1 ms | 9.0 ms | 0.89× (slower!) |
— plain torch.compile, no AMP |
8.1 ms | 7.2 ms | 1.12× |
How to read this honestly:
- Compute-bound models benefit most (2.62× on the ResNet-50 step — mostly AMP's tensor cores plus compile's fusion). Small or launch-bound workloads benefit little, and some configurations lose to the fp32 baseline (the 0.89× row) — which is exactly why you should measure your own workload rather than trust any package's headline.
- Against
torch.compilealone, the full stack adds AMP's gains on top — it is not an alternative totorch.compileand does not "beat" it; it uses it. - Older GPUs with a larger fp16-vs-fp32 throughput gap (e.g. T4) can see larger AMP ratios on compute-bound CNNs; no number is claimed here for hardware this version was not measured on.
Installation
pip install pytorch-autotune
Usage
from pytorch_autotune import AutoTune
autotune = AutoTune(model, device='cuda', verbose=True)
model, optimizer, scaler = autotune.optimize(
optimizer_name='AdamW',
learning_rate=1e-3,
compile_mode='default', # or 'reduce-overhead' / 'max-autotune'
use_amp=True,
use_compile=True,
use_fused=True,
)
for data, target in train_loader:
data, target = data.cuda(), target.cuda()
optimizer.zero_grad(set_to_none=True)
with torch.amp.autocast('cuda'):
loss = criterion(model(data), target)
scaler.scale(loss).backward()
scaler.step(optimizer)
scaler.update()
Notes:
- The first iterations after
torch.compileare slow (compilation); plan a warmup. - Mixed precision changes numerics; validate your accuracy as you would with any AMP setup.
AutoTune.benchmark()times forward-only inference underno_grad— usebenchmarks/measure.pyfor training-step comparisons.
Limitations
- This is a wrapper, not a tuner: settings come from a small hardware table, not from measuring your model. (A measurement-driven version is the roadmap.)
- Measured on one GPU (A100). No claims for other hardware.
- No tests or CI yet.
Citation
@software{pytorch_autotune,
title = {PyTorch AutoTune: one-call PyTorch training optimization setup},
author = {Shrivastava, Chinmay},
year = {2025},
url = {https://github.com/JonSnow1807/pytorch-autotune},
version = {1.0.3}
}
Author
Chinmay Shrivastava — GitHub @JonSnow1807
License
MIT — see LICENSE.
Metadata
Release files for pytorch-autotune 1.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pytorch_autotune-1.0.3.tar.gz | 9.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pytorch_autotune-1.0.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 18.3 kB
Release files / pytorch_autotune-1.0.3.tar.gz
| Download URL | pytorch_autotune-1.0.3.tar.gz |
|---|---|
| Size | 9.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0354c338aeb813a460c61eeaf1f94a3b1544acb7b766f244359659fa6b570499
|
|
BLAKE2b-256 checksum How to use checksums |
f48e2008ffc5932d574426971fe76de3ff44efa72252fe82e80025b562ef3250
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.11
|
Release files / pytorch_autotune-1.0.3-py3-none-any.whl
| Download URL | pytorch_autotune-1.0.3-py3-none-any.whl |
|---|---|
| Size | 9.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5d5596114b226a6757e0df17114b0bcd86e9a0c1386a2b7b88516c3ee90d7199
|
|
BLAKE2b-256 checksum How to use checksums |
8ac7ef2f1644b4906e12bea755f9395ac958936715c0ad835826966dab04b596
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.11
|