Source-linked AI summary

TorchTitan: One-stop PyTorch native solution for production ready LLM pre-training

Wanchao Liang, Tianyu Liu, Less Wright, Will Constable, Andrew Gu, Chien-Chin Huang, Iris Zhang, Wei Feng, Howard Huang, Junjie Wang, Sanket Purandare, Gokul Nadathur, Stratos Idreos

arXiv:2410.06511v3cs.CLcs.AIcs.DCcs.LG

TL;DR

Large-scale LLM training requires combining parallelism and optimization techniques, but existing systems are difficult to compose and maintain. TorchTitan unifies these techniques in a modular PyTorch-native system, with reported training accelerations over optimized baselines and support for long-context training through 4D parallelism.

  • Problem

    Training LLMs at scale requires balancing parallelism, computation, communication, and memory, while existing systems are difficult to compose and inflexible.

    Source: §1 · p. 2
  • Method

    TorchTitan uses PyTorch’s DTensor and DeviceMesh to unify distributed-training techniques in a modular system.

    Source: §1 · p. 2, §5 · p. 10
  • Results

    65.08% on Llama 3.1 8B (128 GPUs, 1D), 12.59% on Llama 3.1 70B (256 GPUs, 2D), and 30% on Llama 3.1 405B (512 GPUs, 3D) over optimized baselines.

    Source: §5 · p. 10
  • Takeaways & Limitations

    TorchTitan enables long-context training with 4D composability.

    Source: §5 · p. 10

    The original PyTorch FSDP1 implementation has limitations due to its FlatParameter implementation.

    Source: §2.1.2 · p. 4

Abstract

from arXiv · show

The development of large language models (LLMs) has been instrumental in advancing state-of-the-art natural language processing applications. Training LLMs with billions of parameters and trillions of tokens require sophisticated distributed systems that enable composing and comparing several state-of-the-art techniques in order to efficiently scale across thousands of accelerators. However, existing solutions are complex, scattered across multiple libraries/repositories, lack interoperability, and are cumbersome to maintain. Thus, curating and empirically comparing training recipes require non-trivial engineering effort. This paper introduces TorchTitan, an open-source, PyTorch-native distributed training system that unifies state-of-the-art techniques, streamlining integration and reducing overhead. TorchTitan enables 3D parallelism in a modular manner with elastic scaling, providing comprehensive logging, checkpointing, and debugging tools for production-ready training. It also incorporates hardware-software co-designed solutions, leveraging features like Float8 training and SymmetricMemory. As a flexible test bed, TorchTitan facilitates custom recipe curation and comparison, allowing us to develop optimized training recipes for Llama 3.1 and provide guidance on selecting techniques for maximum efficiency based on our experiences. We thoroughly assess TorchTitan on the Llama 3.1 family of LLMs, spanning 8 billion to 405 billion parameters, and showcase its exceptional performance, modular composability, and elastic scalability. By stacking training optimizations, we demonstrate accelerations of 65.08% with 1D parallelism at the 128-GPU scale (Llama 3.1 8B), an additional 12.59% with 2D parallelism at the 256-GPU scale (Llama 3.1 70B), and an additional 30% with 3D parallelism at the 512-GPU scale (Llama 3.1 405B) on NVIDIA H100 GPUs over optimized baselines.

1 Introduction

Training LLMs at scale requires balancing parallelism, computation, communication, and memory, yet existing distributed systems remain difficult to compose and operate. TorchTitan unifies PyTorch-native training techniques and evaluates their scalability and efficiency across Llama 3.1 models.

1 Introduction

  • Existing systems struggle with composability, flexibility, hardware utilization, production support, and dependence on external or poorly maintained dependencies.The cited gaps include limited distributed checkpointing scalability, cumbersome failure recovery, inadequate debugging tools, and failure to use PyTorch’s optimized kernels and compiler support.Source: §1 · p. 2
  • TorchTitan unifies parallelism and optimization techniques through PyTorch’s DTensor and DeviceMesh, providing a modular distributed-training system rather than a collection of isolated techniques.Its sharding primitives provide correct single-device semantics, while its unified template supports systematic configuration exploration and evaluation.Source: §1 · p. 2
  • The system extends DTensor for n-D sharding, torch.compile compatibility, and n-D model checkpointing while demonstrating composed parallelism and hardware-software optimizations.It also offers customizable activation checkpointing strategies for memory-computation trade-offs.Source: §1 · p. 3
  • TorchTitan adds scalable distributed checkpointing, Flight Recorder debugging, extensive logging, and training recipes with guidance for different model sizes and cluster configurations.These features support fast failure recovery and systematic choices for training efficiency.Source: §1 · p. 3
  • 65.08% on Llama 3.1 8B at 128 GPU scale (1D), 12.59% on Llama3.1 70B at 256 GPU scale (2D), and 30% on Llama3.1 405B at 512 GPU scale (3D) accelerations over optimized baselines; 4D parallelism enables long context training.The evaluation spans 8 to 512 GPUs and reports convergence and accuracy alongside efficiency.Source: §1 · p. 3

2 Elasticity through composability

TorchTitan’s modular design lets users compose selectable parallelism dimensions and training optimizations. It combines these with production-oriented checkpointing and debugging tools to support training at scale.

2 Elasticity through composability

  • TorchTitan composes selectable multi-dimensional shardings to make exploring training-efficiency optimizations at scale easier.Its code separates model definitions, parallelism helpers, and the training loop, with configuration through TOML files and command-line overrides.Source: §2 · p. 3

2.1.1 Large-scale model initialization using meta device

  • Meta-device initialization creates models using metadata before sharding parameters into DTensors and initializing them with correct layouts and RNG seeds.This addresses the challenge of instantiating large models without exceeding CPU or GPU memory limits.Source: §2.1.1 · p. 4

2.1.2 Fully Sharded Data Parallel

  • FSDP2 is TorchTitan’s default 1D parallelism, with often 7 percent lower per-GPU memory requirements and an average 1.5 percent performance gain versus FSDP1.Its per-parameter DTensor representation supports composability with model parallelism and features that manipulate individual parameters.Source: §2.1.2 · p. 4

2.1.3 Tensor Parallel

  • TorchTitan’s TP partitions parameters into DTensors without changing model code, while SP shards normalization or dropout computations along the sequence dimension.Loss Parallel avoids gathering all vocabulary-sharded outputs to compute cross-entropy, reducing memory use and communication overhead.Source: §2.1.3 · pp. 4–5

2.1.4 Pipeline Parallel

  • Pipeline parallelism divides models into stages and overlaps computation with communication across microbatches using configurable schedules.TorchTitan also supports ZeroBubble and Flexible-Interleaved-1F1B schedules.Source: §2.1.4 · p. 5

2.1.5 Context Parallelism

  • Context Parallelism adds a fourth dimension to DP, TP, and PP by splitting sequences across GPUs, enabling longer contexts without out-of-memory errors.On Llama 3.1 8B with 8 H100 GPUs, it supported context lengths up to 262,144 tokens with minor MFU degradation as CP degree increased.Source: §2.1.5 · p. 5

2.2.1 Navigating compute-memory trade-offs using activation checkpointing

  • Activation checkpointing trades recomputation during backward passes for lower peak GPU memory, with full AC, op-level SAC, and configurable layer-level SAC options.Layer-level SAC applies wrapping to a user-specified number of TransformerBlocks.Source: §2.2.1 · p. 5

2.2.2 Regional compilation to exploit torch.compile optimizations

  • Regional compilation compiles each TransformerBlock into a full graph compatible with distributed techniques and reduces compile time by reusing compilation for repeated layers.TorchTitan integrates AsyncTP for communication-computation overlap, selectively applies Float8 to linear layers, and provides distributed checkpointing and Flight Recorder debugging.Source: §2.2.2 · p. 6, §2.2.3 · p. 6, §2.2.4 · p. 6

3 Experimentation

The experiments assess TorchTitan across Llama 3.1 models from 8B to 405B, GPU scales from 8 to 512, and parallelism configurations up to 4D. They describe the hardware and measurement setup and explain how FSDP, TP, PP, and CP address scaling needs.

3 Experimentation

  • Experiments demonstrate elastic distributed training with TorchTitan on Llama 3.1 8B, 70B, and 405B, spanning 1D–4D parallelism and scales from 8 to 512 GPUs.A codebase walkthrough is in Appendix A, and Appendix B.10 contains additional experimental details and loss-convergence tests for correctness.Source: §3 · p. 7, §3.2 · p. 8

3.1 Experimental setup

  • The experiments use H100 hosts with eight GPUs each, NVSwitch, and a backend RDMA network connecting rack TOR switches.All experiments use the C4 English variant and the official Llama 3.1 tiktoken tokenizer.Source: §3.1 · p. 7

3.2 Performance

  • Performance experiments add individual optimization techniques on appropriate baselines, updating each higher-dimensional baseline to include prior techniques.Throughput is logged every 10 iterations and read at the 90th iteration; memory readings are stable across training. The tested H100s are non-standard, with HBM2e and lower TDP, and their exact peak TFLOPs are unknown.Source: §3.2 · pp. 7–8
  • 33% to 42% MFU is reported for 1D Llama 3.1 8B training on 8 or 128 H100 GPUs without Float8.The authors omit MFU when Float8 is enabled because BFLOAT16 and FP8 Tensor Cores have different peak FLOPS, making the metric ill-defined.Source: §3.2 · p. 8

3.3.1 Scaling with FSDP

  • FSDP (ZeRO) is a general first parallelism strategy when communication is faster than computation, but its collective latency grows linearly with world size.The passage gives up to 512 GPUs as an example of where FSDP may suffice and identifies TP and PP as model-parallel approaches that can be combined with FSDP at larger scales.Source: §3.3.1 · p. 9

3.3.2 2D Parallelism: TP with FSDP

  • Combining TP with FSDP can support strong scaling at fixed problem or batch size, reduce peak memory, and improve FLOP utilization through better matrix-multiplication shapes.TP adds blocking collectives and is typically limited to intra-node scaling, usually capped at degree 8; the passage says scaling beyond 4192 GPUs requires TP with PP.Source: §3.3.2 · p. 9

3.3.3 3D Parallelism: PP with 2D Parallelism

  • PP sends activations and gradients between stages peer-to-peer, reducing communication bandwidth needs and helping mitigate FSDP communication latency at large scales or in bandwidth-limited clusters.Pipeline efficiency depends on schedules and microbatch sizes, which affect pipeline bubbles.Source: §3.3.3 · p. 10

3.3.4 Long Context Training and 4D Parallelism

  • Context Parallelism (CP) supports ultra-long-context training by splitting the context (sequence) dimension across GPUs to avoid OOM errors; it can be used alone, with DP, or with 3D parallelism.With 3D parallelism, TP usually occupies the innermost DeviceMesh dimension and CP the next outer dimension.Source: §3.3.4 · p. 10

4 Related Work

The paper contrasts TorchTitan’s modular, DTensor- and DeviceMesh-based APIs with distributed-training frameworks that have limitations in integration, flexibility, or supported features. It also positions TorchTitan’s components as foundational tools that can be leveraged by other libraries.

  • Megatron-LM requires model modifications for TransformerEngine, lacks seamless FSDP integration with TP and PP, and does not support advanced pipeline schedules to minimize computation overhead.Source: §4 · p. 10
  • DeepSpeed depends on Megatron-LM for TP and CP and has limited support for FSDP and advanced pipeline schedules.Source: §4 · p. 10
  • veScale lacks support for FSDP, CP, SAC, Float8 training, and torch.compile, and offers three pipeline schedules compared with TorchTitan’s six.Source: §4 · p. 10
  • TorchTitan provides modular, composable APIs built on DTensor and DeviceMesh, while Slapo uses a schedule language and high-level primitives for progressive optimization.The authors note that the compared libraries each have strengths and describe TorchTitan as providing foundational components that can be leveraged by them; a detailed feature and code-complexity comparison is in Appendix B.9.Source: §4 · p. 10

5 Conclusion

TorchTitan combines parallelism, memory optimizations, and compiler integration in a modular LLM-training framework, with reported accelerations across three Llama 3.1 scales. The walkthrough describes applying pipeline, tensor, fully sharded, and context parallelism in sequence.

5 Conclusion

  • TorchTitan composes FSDP, TP, PP, and CP with Float8, activation checkpointing, and PyTorch compiler integration in a modular design.The modular design is described as supporting evolving architectures and hardware.Source: §5 · p. 10
  • 65.08% acceleration on Llama 3.1 8B at 128 GPUs (1D), 12.59% on 70B at 256 GPUs (2D), and 30% on 405B at 512 GPUs (3D) over optimized baselines.The conclusion also reports enabling long-context training with 4D composability.Source: §5 · p. 10

A Composable 4D parallelism walkthrough

  • The walkthrough first creates the model on the meta device, then splits it into pipeline stages using configured split points.For looped schedules, splitting can produce multiple model parts, each a stage-model chunk.Source: A Composable 4D parallelism walkthrough · p. 14
  • Pipeline splitting can use schedules such as 1F1B, GPipe, or interleaved 1F1B, selected through pipeline schedule configuration.Stages are created from manually supplied pipeline split points.Source: A Composable 4D parallelism walkthrough · pp. 14–15
  • TP and FSDP are applied in an SPMD-style function, with TP plans specifying parameter sharding for repeated TransformerBlocks.The walkthrough then wraps individual blocks and the full model with FSDP, using bfloat16 for parameter all-gather and activations and float32 for gradient reduce-scatter and optimizer updates.Source: A Composable 4D parallelism walkthrough · p. 15
  • Context parallelism is applied independently by running each training iteration inside a context manager.The walkthrough configures sequence dimensions, buffers, and a context-parallel rotation method for that context.Source: A Composable 4D parallelism walkthrough · pp. 15–16

B.1 Fully Sharded Data Parallel

FSDP2 changes parameter sharding and memory management while remaining composable with model parallelism. On Llama 2 7B, it uses less GPU memory and achieves faster throughput than FSDP1.

B.1 Fully Sharded Data Parallel

  • FSDP2 represents parameters as DTensors sharded on tensor dimension 0, improving composability with model parallelism and enabling sharded state dicts without communication.The DTensor representation also supports simpler meta-device initialization and finer-grained tensor quantization, including Float8.Source: §B.1 · p. 16
  • 7% lower average GPU memory on Llama 2 7B versus FSDP1, and 1.5% faster average throughput on Llama 2 7B.The throughput gains are attributed to two small performance improvements in reduce-scatter and final-block resharding.Source: §B.1 · p. 16
  • FSDP2’s memory-management rewrite avoids record stream, enabling deterministic memory release and lower per-GPU memory requirements than FSDP1.TorchTitan integrates FSDP2 as its default parallelism and includes auto-sharding defaults based on available world size.Source: §B.1 · p. 16

B.2 Hybrid Sharded Data Parallel

HSDP reduces FSDP communication overhead by dividing devices into shard groups and replica groups, allowing data-parallel scaling beyond a single FSDP group.

B.2 Hybrid Sharded Data Parallel

  • FSDP communication can outgrow its corresponding computation as all-gather and reduce-scatter latency rises linearly with group size, reducing MFU.The passage says adding GPUs can then become worthless for scaling.Source: §B.2 · p. 16
  • HSDP places FSDP shard groups and data-parallel replica groups on separate dimensions of a 2-D DeviceMesh, limiting FSDP communication to each shard group.Backward gradients are all-reduced across replica groups.Source: §B.2 · p. 16
  • The shard and replica group degrees are configurable, and their product gives the actual data-parallel world size.Source: §B.2 · p. 17

B.3 Tensor Parallel

Tensor Parallelism partitions transformer-layer attention and MLP computation across devices, while Pipeline Parallelism exposes configurable controls for ranks, stages, schedules, and microbatches.

B.3 Tensor Parallel

  • Tensor Parallelism partitions transformer-layer attention and MLP modules across devices so GPUs process the same batch with local parameter shards, adding collectives to synchronize intermediate activations.Source: §B.3 · p. 17
  • Figure 3 depicts Tensor Parallel data movement from left to right across two GPUs.Source: Figure 3 · p. 17
  • Tensor Parallelism requires a fast network such as NVLink and is commonly combined with FSDP, with TP within nodes and FSDP across nodes.Source: §B.3 · p. 17

B.4 Pipeline Parallel

  • Pipeline Parallelism configuration specifies participating ranks, layer split points, a schedule, and the number of microbatches.The split-point list determines the total pipeline stages; multi-stage schedules require more than one stage per pipeline rank.Source: §B.4 · p. 17
  • Figure 4 shows an FSDP2 plus Tensor Parallel sharding layout with TP degree 4 across two nodes of four GPUs.Source: Figure 4 · p. 18

B.5 Enabling 4D parallel training: Context-Parallel (CP)

TorchTitan combines context parallelism, activation-checkpointing choices, asynchronous collectives, and mixed-precision controls within a modular framework that supports integrating parallelism strategies and optimizations.

B.5 Enabling 4D parallel training: Context-Parallel (CP)

  • Context Parallelism replaces attention-operator calls through a context manager and shards DTensors along the sequence dimension, supporting ring attention and causal-attention load balancing.The passage states CP is compatible with FSDP, TP, PP, activation checkpointing, torch.compile, and DCP.Source: §B.5 · p. 18

B.6 Activation checkpointing

  • Selective Activation Checkpointing trades memory for recomputation through per-layer or per-operation policies; operation mode saves selected high-arithmetic-intensity intermediates and recomputes lower-intensity operations.The described policy flags matmul and scaled dot-product attention operations, saving every other matmul for throughput balance.Source: §B.6 · pp. 18–19

B.7 AsyncTP

  • AsyncTP uses SymmetricMemory collectives that are faster than standard NCCL collectives, but require NVSwitch and are generally available on H100 or newer GPUs.Source: §B.7 · p. 19

B.8 Customizing FSDP2 Mixed Precision in TorchTitan

  • TorchTitan configures FSDP2 mixed precision with BF16 parameters and FP32 gradient reduce-scatter by default to help maximize gradient-update stability and precision.Source: §B.8 · p. 19

B.9.1 TorchTitan enables new designs

  • Modularity, composability, and extensibility support integrating FSDP, TP, PP, CP, and optimizations such as selective activation checkpointing and Float8 training.The passage also identifies advanced pipeline schedules and integration of new techniques.Source: §B.9.1 · p. 19

B.9.2 Code Complexity and Maintainability

  • TorchTitan presents its codebase as compact and modular despite its feature set, and says this makes it easier to extend, maintain, and evolve while retaining high performance.The passage introduces a lines-of-code comparison with Megatron-LM and DeepSpeed.Source: §B.9.2 · p. 19

B.10.1 Performance

The experiments assess composability, performance, elastic scalability, and optimization gains across parallelism strategies and training techniques.

B.10.1 Performance

  • TorchTitan demonstrates integration of parallelisms and optimizations, performance improvements across them, and scaling with model size and GPU count.Source: §B.10.1 · p. 19
  • Table 1 compares eager execution with compiler support and reports further gains from Float8 training.Source: §B.10.1 · p. 20
  • Table 2 examines how earlier training gains change as the number of GPUs increases.Source: §B.10.1 · p. 20
  • Table 3 reports AsyncTP speed-up over 2D training combined with torch.compile and Float8 training.Source: §B.10.1 · p. 20
  • Table 4 compares Interleaved 1F1B scheduling with 1F1B on top of AsyncTP, torch.compile, and Float8 training.Source: §B.10.1 · p. 20
  • Table 5 tests Context Parallelism for long-context training at small scale, while Table 6 examines 4D parallelism composability and long-context training at large scale.Source: §B.10.1 · p. 20
  • The experiments use ZeRO-3 except with Pipeline Parallelism, where ZeRO-2 avoids per-microbatch all-gathers by gathering parameters once for the first microbatch and resharing after the last backward pass.Source: §B.10.1 · p. 20

B.10.2 Loss converging

The authors report that TorchTitan’s design principles influenced several PyTorch distributed training features. They also describe loss-convergence tests for individual techniques and combinations of parallelisms and optimizations.

B.10.2 Loss converging

  • TorchTitan’s design principles influenced FSDP2, AsyncTP, PP, and CP in PyTorch’s distributed library.The authors say they checked loss convergence for individual techniques and combinations of parallelisms and optimizations.Source: §B.10.2 · p. 21
  • “FSDP 8, CP 8” denotes an experiment with FSDP degree 8 and CP degree 8 on 64 GPUs.“FSDP 8” alone denotes an experiment with FSDP degree 8.Source: §B.10.2 · p. 21
  • The tests assume FSDP correctness, which can be further checked against DDP or single-device jobs.Source: §B.10.2 · p. 21
Loading 2410.06511v3…