Skip to content

TorchTitan - PyTorch-Native LLM Pretraining Cheatsheet

TorchTitan - PyTorch-Native LLM Pretraining Cheatsheet

TorchTitan is an open-source, PyTorch-native platform for large-scale generative-model (LLM) pretraining. It is a clean-room reference implementation of PyTorch’s latest distributed-training techniques, composing 4D parallelism — data, tensor, pipeline, and context parallel — in a modular way, on top of FSDP2, torch.compile, and distributed checkpointing, with elastic scaling. It is the go-to starting point for teams that want to pretrain models using native PyTorch scaling rather than a third-party stack.

Distributed pretraining is resource-intensive. Validate configs on a small model/scale before committing a large multi-node run.

Installation

MethodCommand
From sourcegit clone https://github.com/pytorch/torchtitan && cd torchtitan && pip install -e .
RequirementsRecent PyTorch (nightly often recommended), CUDA GPUs
DatasetsUses HF datasets / tokenizers
Verifyrun a debug config on 1 GPU

Parallelism Dimensions (4D)

DimensionSplits
Data Parallel (FSDP2)The batch, sharding params/optimizer/grads
Tensor ParallelIndividual layers across GPUs
Pipeline ParallelThe model into stages across GPUs
Context ParallelLong sequences across GPUs

These compose: e.g. dp × tp × pp × cp maps a model onto a large GPU mesh.

Configuration

TorchTitan is driven by TOML config files plus command-line overrides.

# Launch training with a config (multi-GPU via torchrun)
CONFIG_FILE=./train_configs/llama3_8b.toml ./run_train.sh
Config sectionControls
[model]Architecture, size, flavor
[training]Batch size, steps, seq length, LR
[parallelism]data_parallel_shard_degree, tensor_parallel_degree, pipeline_parallel_degree, context_parallel_degree
[optimizer]Optimizer + hyperparameters
[checkpoint]Distributed checkpoint frequency/paths
[activation_checkpoint]Recomputation policy

Key Features

FeatureBenefit
FSDP2Modern fully-sharded data parallel
torch.compileGraph compilation for speed
Async distributed checkpointingSave/resume huge runs efficiently
Float8 / low precisionFaster training on supported hardware
Elastic scalingAdapt to changing GPU availability
Meta-device initBuild huge models without OOM at init

Launching Multi-Node

# torchrun across nodes (conceptual)
torchrun --nnodes=4 --nproc_per_node=8 \
  --rdzv_backend=c10d --rdzv_endpoint=$MASTER:29500 \
  -m torchtitan.train --job.config_file llama3_70b.toml
OverrideExample
Parallel degrees--parallelism.tensor_parallel_degree 8
Steps--training.steps 10000
Seq length--training.seq_len 8192
Compile--training.compile

Monitoring & Checkpoints

AspectHow
LoggingTensorBoard / W&B integration
MetricsLoss, tokens/sec, MFU (model FLOPs utilization)
CheckpointsDistributed checkpoint (DCP) save/load
ResumePoint the config at a checkpoint step

TorchTitan vs Other Training Frameworks

AspectTorchTitanMegatron-LMNanotron
OriginPyTorch teamNVIDIAHugging Face
StylePyTorch-native, composableFeature-rich, matureMinimalistic 3D
Parallelism4D (dp/tp/pp/cp)3D+ (extensive)3D
Best forNative PyTorch reference scalingMax-scale MoE/denseSmall, hackable 3D training

Resources