pytorch/torchtitan

A PyTorch native platform for training generative AI models

What it solves

Training large AI models from scratch is historically complex: researchers must stitch together multiple libraries for parallel computing, model definitions, and post-training steps, often rewriting model code between phases. Torchtitan removes that friction by offering a single, readable PyTorch-native codebase that carries a model from initial pretraining through supervised fine-tuning to reinforcement learning, without needing to rewrite the model for different parallel strategies or training stages.

How it works

Torchtitan builds on PyTorch's native distributed tools—FSDP2, DTensor, and DeviceMesh—to let models declare how they should be sharded across GPUs and nodes. Parallelism types such as tensor, pipeline, context, and expert parallel can be stacked into N-dimensional layouts directly from PyTorch primitives. Users define every run as a Python "recipe"—a function that returns a full configuration object—so changing a run means editing a function, not passing dozens of flags. The same model definitions and kernels are reused in the trainer and during vLLM-based generation for reinforcement learning (TitanRL), with a bitwise-reproducible mode ensuring identical batches across training and inference. The project includes verified recipes for multiple frontier models (Llama, Qwen, DeepSeek, Kimi, gpt-oss, Muse, FLUX), along with techniques like MXFP8/NVFP4 low-precision training, Dist-MoE, activation checkpointing, and Hugging Face checkpoint compatibility.

Who it’s for

Researchers and engineers who need to pretrain or post-train large generative models at scale. It suits those who want a minimal, hackable codebase to experiment with novel architectures or parallelism schemes, and who prefer PyTorch-native code over custom training frameworks. It also serves teams that want to go from pretraining to RL in one stack without rewriting model code.

Highlights

  • Composable parallelism: FSDP2, tensor, pipeline, context, and expert parallelism stack into N-D layouts via PyTorch's DeviceMesh and DTensor.
  • Pretraining to RL in one stack: TitanRL reuses the same model definitions and kernels in training and vLLM generation, with a bitwise-reproducible batch-invariant mode.
  • Frontier model support: includes verified recipes for Llama 3, Qwen3/3.5/3.6/3.8, DeepSeek V3/V4, gpt-oss, Kimi K2.7/K3, Muse variants, and FLUX (text-to-image).
  • Python recipes as configuration: every run is a function you can read, copy, and modify; component overrides allow custom kernels and modules.
  • Built-in observability and debugging: metrics (loss, memory, throughput, TFLOPs, MFU), profiling, memory snapshots, deterministic mode, and silent data corruption replay.
  • Extensible and maintainable: new ideas go first into an experiments folder; validated features merge into core, with a clear model-addition guide.

Related

  • Project
  • Project
  • Project
  • Project
  • Project