Tiny DDP training toolkit for quick-launch distributed training loops.
Project description
torchlitex
Tiny DDP launcher + trainer that exists because PyTorch 2.x still thinks we enjoy 400 lines of torchrun boilerplate and cryptic NCCL errors. This trims it to ~20 lines and keeps fork happy on Vast.
Why not just torchrun?
- You like your code more than the 17 environment variables PyTorch asks you to memorize.
torchrunstill feels like a 2010 MPI cosplay.- You want fork-based spawn that doesn’t randomly faceplant on Vast.
- You want a one-function launcher + trainer, not a CLI maze.
Install
pip install -e .
# or with wandb logging
pip install -e .[wandb]
Quick start
from torchlitex.launcher import launch, DistributedConfig
from torchlitex.trainer import Trainer
from torch import nn, optim
import torch
def train_fn(rank, world_size, batch_size, epochs):
dataset = MyDataset(...)
model = MyModel(...)
loss_fn = nn.CrossEntropyLoss()
optimizer = optim.AdamW(model.parameters(), lr=3e-4)
trainer = Trainer(
model=model,
dataset=dataset,
loss_fn=loss_fn,
optimizer=optimizer,
grad_clip_norm=1.0,
log_every=10,
)
trainer.ddp_train_loop(rank, world_size, batch_size=batch_size, epochs=epochs, ckpt_path="ckpt.pt")
if __name__ == "__main__":
cfg = DistributedConfig(gpus=8) # backend auto-switches nccl/gloo
launch(train_fn, cfg, batch_size=64, epochs=20)
Features
- Fork-first DDP launcher (no torchrun, no elastic).
- Auto backend:
ncclwhen CUDA exists,gloowhen you’re on a laptop/CI. - Trainer: AMP toggle, grad clipping, gradient accumulation, microbatching, optional schedulers, eval hook, callbacks, and EMA support.
- Optional wandb init + logging on rank0 (install with
.[wandb]). - DistributedSampler + DataLoader defaults that just work.
- Start method auto-picks
spawnwhen CUDA is present (avoids forked-CUDA init errors); override toforkif you really want it. - Checkpoint utilities that handle optimizer/scaler safely.
- Rank-aware logging that doesn’t spam.
Testing levels
- Level 1: CPU unit tests (no dist).
- Level 2: CPU DDP (
backend="gloo", world_size=2) to validate spawn/env/sampler. - Level 3: Single GPU (
gpus=1) for end-to-end DDP path. - Level 4: Real multi-GPU (same code, just crank
gpus).
PyTorch 2.x roast (lightly toasted)
- DDP config still feels like “choose your own adventure” but every page ends with NCCL complaining.
- torch.distributed docs read like a treasure map; the treasure is another flag.
- “Just use torchrun” is 2020’s “have you tried turning it off and on again?”
torchlitex keeps the good bits of torch 2.x (SDPA, compile, etc.) and sidesteps the distributed busywork. Use it, ship models, spend less time appeasing the NCCL spirits.
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
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 torchlitex-0.1.5.tar.gz.
File metadata
- Download URL: torchlitex-0.1.5.tar.gz
- Upload date:
- Size: 10.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
744c5ab8a81af56b65cdc052467ce0bb143cef6f1f2f3bbd17249375774ad0cc
|
|
| MD5 |
e8ac50d30d10bee450e5de74ab7828d3
|
|
| BLAKE2b-256 |
73beb4320f03c414f12bd06d82356aa0fe90ca979f8b8df0644bc61a1850e2c0
|
File details
Details for the file torchlitex-0.1.5-py3-none-any.whl.
File metadata
- Download URL: torchlitex-0.1.5-py3-none-any.whl
- Upload date:
- Size: 10.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a00626518b89e1ddb3e0e25949ffd6f5fae6970970edae228f054175b4c91f2d
|
|
| MD5 |
9ee59b9c21314ddc5f6721ece54a7245
|
|
| BLAKE2b-256 |
d325196ad24b3013792ea3d664779ee8796c04dfc23103ada124c085e877c774
|