LightSeq: : Sequence Level Parallelism for Distributed Training of Long Context Transformers

Dacheng Li, Rulin Shao, Anze Xie, Eric P. Xing, Joseph E. Gonzalez, Ion Stoica, Xuezhe Ma, Hao Zhang

TL;DR

This paper introduces LightSeq, a novel approach for training large language models (LLMs) with extremely long contexts. By partitioning the sequence instead of attention heads, LightSeq achieves significant speedups and enables training on much longer sequences than existing methods like Megatron-LM, overcoming a key bottleneck in LLM development.

What Problem Does This Paper Address?

Large Language Models (LLMs) are becoming increasingly powerful, especially when they can process very long sequences of text. This capability is crucial for tasks like understanding entire documents, generating comprehensive code, or engaging in extended conversations. However, training these models with long sequences dramatically increases their memory requirements. Existing distributed training systems, such as Megatron-LM, often tackle this by parallelizing computations across different attention heads. While effective to a degree, this approach has a critical limitation: it cannot scale beyond the number of attention heads available in the model. This becomes a problem as many modern LLM architectures have a fixed number of heads, and some research even suggests that fewer heads might be beneficial in the future. This limitation hinders the ability to train LLMs on truly long contexts and limits the flexibility of model design.

Methods

LightSeq introduces a new paradigm for distributed LLM training by employing sequence-level parallelism. Instead of splitting the work across attention heads, LightSeq divides the input sequence itself among different processing units (e.g., GPUs). This approach offers several key advantages:

  • Architecture Agnostic: It works with any model architecture, regardless of the number of attention heads, making it highly versatile.
  • Reduced Communication: LightSeq significantly cuts down on communication overhead. It achieves this by:
  • Overlapping Communication with Computation: It intelligently schedules communication tasks to happen concurrently with computation, hiding latency.
  • Novel Gradient Checkpointing: A specialized checkpointing scheme is introduced that avoids redundant computations, particularly for memory-efficient attention mechanisms like FlashAttention. This is crucial because standard checkpointing can lead to recomputing attention forward passes unnecessarily.
  • Distributed Memory-Efficient Attention (DISTATTN): A core component that enables efficient attention computation across distributed workers by carefully managing key and value tensors.
  • Load Balancing: For causal language modeling (where tokens only attend to previous ones), LightSeq implements a load-balancing strategy to ensure no worker is idle for extended periods, maximizing computational efficiency.

Datasets

The paper evaluates LightSeq on the Llama-7B model and its variants. Specific datasets are not explicitly mentioned as being trained on, but rather the models are evaluated on their ability to handle varying sequence lengths (from 32K to 512K) and different attention head configurations.

Key Insights and Ideas

  • Sequence-Level Parallelism is Key: The fundamental insight is that partitioning the sequence is a more scalable and flexible approach for long-context training than partitioning attention heads. This unlocks training for models with arbitrary head counts.
  • Communication is the Bottleneck: For long contexts, communication overhead becomes a major performance limiter. LightSeq's strategies for overlapping communication with computation and reducing its volume are critical for achieving speedups.
  • Memory-Efficient Attention Needs Smarter Checkpointing: The paper highlights that standard gradient checkpointing is suboptimal when combined with modern memory-efficient attention kernels (like FlashAttention), which already have their own recomputation mechanisms. LightSeq's "rematerialization-aware" checkpointing addresses this directly.
  • Flexibility Trumps Fixed Architectures: The ability to handle models with arbitrary numbers of attention heads (like Llama-33H) without performance degradation is a significant advantage over methods that rely on head divisibility.

Key Results

  • Significant Speedups: LightSeq achieves end-to-end training speedups of up to 1.24-2.01x compared to Megatron-LM on various Llama models.
  • Extended Sequence Lengths: LightSeq enables training on 2-8x longer sequences compared to Megatron-LM, especially for models with fewer attention heads. For instance, it supports 512K sequence lengths across various head configurations, while Megatron-LM's support decreases significantly with fewer heads.
  • Reduced Communication Volume: LightSeq requires up to 4.7x less communication than Megatron-LM on popular LLMs.
  • Component Contributions: Ablation studies show that load balancing, communication-computation overlap, and rematerialization-aware checkpointing all contribute to the overall performance gains.

Limitations and Future Work

  • Shorter Sequences and MHA: LightSeq can be slightly slower than some other methods (like DeepSpeed-Ulysses) on shorter sequence lengths and Multi-Head Attention (MHA) models. This is attributed to the communication primitives used in those methods being more advantageous in scenarios where LightSeq's overlapping technique doesn't fully hide communication latency.
  • P2P Optimization: The authors plan to further optimize P2P communication, particularly in a topology-aware manner, to improve performance on shorter sequences and MHA models.
  • Further Optimization of Communication Primitives: For scenarios with shorter contexts and less communication overhead, optimizing the underlying communication primitives could yield further gains.

Summary updated

BibTeX
@inproceedings{li2023lightseq,
  author = {Dacheng Li and Rulin Shao and Anze Xie and Eric P. Xing and Joseph E. Gonzalez and Ion Stoica and Xuezhe Ma and Hao Zhang},
  title = {{LightSeq: : Sequence Level Parallelism for Distributed Training of Long Context Transformers}},
  booktitle = {WANT @ NeurIPS},
  year = {2023},
  url = {https://openreview.net/forum?id=qScA3fL49l},
}
Figure