DeepSpeed Ulysses: System Optimizations for Enabling Training of Extreme Long Sequence Transformer Models

Sam Ade Jacobs, Masahiro Tanaka, Chengming Zhang, Minjia Zhang, Shuaiwen Leon Song, Samyam Rajbhandari, Yuxiong HearXiv 2023 · DOI

Introduction

The rapid evolution of Large Language Models (LLMs) has shifted focus toward "long-context" reasoning capabilities. Applications such as whole-book summarization, genomic sequence analysis, and long-form video generation require models to process sequences far exceeding the typical limits of standard Transformer architectures. While established techniques like Data Parallelism (DP), Tensor Parallelism (TP), and Pipeline Parallelism (PP) effectively scale model size and batch size, Sequence Parallelism (SP) has historically struggled with efficiency and scalability. DeepSpeed Ulysses addresses this gap, enabling the training of Transformer models with sequences exceeding one million tokens while significantly improving throughput.

The Bottleneck in Sequence Parallelism

Existing sequence parallelism methods often encounter severe bottlenecks as sequence lengths ($N$) grow. Specifically, the communication volume in prior SP implementations typically scales linearly with $N$, regardless of the number of GPUs ($P$) employed. This $O(N)$ complexity creates a fixed overhead that prevents effective scaling to extreme sequence lengths. Furthermore, many existing solutions are tightly coupled with specific attention implementations, making them difficult to adapt to new, optimized kernels like FlashAttention or various sparse attention mechanisms.

DeepSpeed Ulysses: The All-to-All Pivot

The core innovation of DeepSpeed Ulysses is a novel approach to sequence parallelism that utilizes highly optimized all-to-all collective communication. The process follows a structured "pivot" mechanism:

  1. Sequence Partitioning: The input sequence is initially partitioned along the sequence dimension across $P$ GPUs, with each GPU holding a chunk of size $N/P$.
  2. The First All-to-All Pivot: Before the attention computation, an all-to-all communication reshuffles the data. This ensures that each GPU receives the full sequence ($N$) but only for a subset of the attention heads ($hc/P$).
  3. Parallel Attention Computation: Each GPU computes attention for its assigned heads independently. Since each GPU now possesses the complete sequence for its specific heads, any standard or optimized attention kernel can be utilized without modification.
  4. The Second All-to-All Pivot: Following the attention block, a second all-to-all collective reshuffles the data back to the original sequence-parallel distribution ($N/P$ sequence chunks) for subsequent processing in layers like the MLP block.
DeepSpeed Ulysses architecture featuring all-to-all communication pivots before and after parallel attention computation.

This design is fundamentally attention-agnostic, providing a "plug-and-play" framework that supports dense, sparse, and future attention optimizations with minimal code refactoring.

Comparative Advantages

DeepSpeed Ulysses offers several theoretical and practical advantages over previous state-of-the-art methods like Megatron-SP and ColAI-SP. The most critical advantage is the reduction in communication complexity to $O(N/P)$. In this regime, doubling both the sequence length and the number of GPUs results in a constant communication overhead per link, facilitating massive scalability.

Comparison of DeepSpeed Ulysses against other sequence parallelism methods across communication complexity and memory efficiency.

As shown in the comparison above, DeepSpeed Ulysses is the only method that achieves $O(M/P)$ communication complexity (where $M$ is proportional to sequence length) while remaining attention-agnostic and parameter-memory efficient. Its synergy with ZeRO-3 further allows it to handle both massive model parameters and extreme sequence lengths simultaneously.

Performance and Scalability

Evaluations conducted on clusters of up to 256 NVIDIA A100 GPUs demonstrate the system's superior performance. DeepSpeed Ulysses successfully trained models with sequence lengths of over one million tokens, achieving a 2.5x increase in training throughput compared to the Megatron-LM baseline.

The system achieved a sustained throughput of over 175 TFlops per GPU, which is approximately 54% of the hardware's theoretical peak. Importantly, experimental results confirm that this optimization has zero impact on model convergence; the loss curves remain identical to those produced by standard training methods.

Conclusion

DeepSpeed Ulysses represents a significant step forward in training extreme long-sequence models. By reimagining sequence parallelism through efficient all-to-all communication, it breaks the sequence length barrier while maintaining high hardware utilization and ease of use. While the degree of parallelism is currently constrained by the number of attention heads, the system's modularity and efficiency make it a foundational tool for the next generation of long-context generative AI.

Summary updated

BibTeX
@misc{jacobs2023deepspeed,
  author = {Sam Ade Jacobs and Masahiro Tanaka and Chengming Zhang and Minjia Zhang and Shuaiwen Leon Song and Samyam Rajbhandari and Yuxiong He},
  title = {{DeepSpeed Ulysses: System Optimizations for Enabling Training of Extreme Long Sequence Transformer Models}},
  year = {2023},
  eprint = {2309.14509},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2309.14509},
}
Figure