Abstract
As Large Language Models (LLMs) evolve toward processing ultra-long contexts (32k to 128k+ tokens), traditional distributed training strategies face significant memory and efficiency bottlenecks. We present Seq1F1B, a novel pipeline parallelism (PP) strategy that shifts the scheduling unit from the micro-batch to the sequence level. By exploiting the causal nature of Transformer attention, Seq1F1B allows for "streaming" forward and backward passes, significantly reducing pipeline bubbles and memory peaks. Our evaluation shows that Seq1F1B achieves a 1.14× throughput increase and a 50% reduction in memory footprint compared to the industry-standard 1F1B, enabling the training of a 30B parameter model on 64k-token sequences without activation recomputation.
Introduction
Training LLMs with long context windows is constrained by two primary factors: the Memory Wall and Pipeline Bubbles. In standard Pipeline Parallelism (PP), such as the 1F1B (one-forward-one-backward) schedule, the smallest schedulable unit is a micro-batch. With long sequences, a single micro-batch can exceed a GPU's memory capacity. Furthermore, the idle periods (bubbles) where GPUs wait for data from other stages become increasingly costly as sequence lengths grow, leading to poor hardware utilization.
Existing solutions like Sequence Parallelism (e.g., RingAttention) mitigate memory issues but often introduce high communication overhead. Seq1F1B addresses these challenges by making pipeline scheduling more granular and memory-efficient without the heavy communication tax.
Methodology
Sequence-Level Scheduling
The core innovation of Seq1F1B is the transition from micro-batch-level to sub-sequence-level scheduling. In a standard Transformer, the causal mask ensures that tokens only attend to preceding tokens. Seq1F1B leverages this by splitting a sequence into $k$ segments. As soon as the first segment completes its forward pass on one GPU, it can be immediately transmitted to the next stage, rather than waiting for the entire micro-batch to finish.
Computation-Wise Partitioning
Because Transformer attention has quadratic complexity, the latter half of a sequence requires more computation than the first half. A simple even split of a sequence would lead to load imbalances across the pipeline. Seq1F1B employs a FLOPs-based estimation strategy to partition sequences into uneven lengths, ensuring that each sub-segment results in roughly equal processing time across devices.
Interleaved Stages (Seq1F1B-I)
To further minimize idle time, the authors adapted the interleaved pipeline approach. In Seq1F1B-I, each GPU handles multiple non-consecutive layers (e.g., Device 1 handles layers 1-4 and 17-20). This granularity, combined with sequence-level scheduling, further compresses the pipeline bubbles during the warm-up and cooling-down phases.
Key Results
Throughput and Memory Efficiency
Seq1F1B demonstrates a significant performance leap over Megatron-LM's standard 1F1B implementation. By storing intermediate activations for sub-sequences rather than full micro-batches, the method reduces the memory peak by approximately 50%. This efficiency allowed the researchers to train a 30B parameter model on 64k sequences using 64× A100 GPUs—a feat previously impossible without slow activation recomputation strategies.
Model FLOPs Utilization (MFU)
When compared to Fully Sharded Data Parallelism (FSDP) combined with RingAttention, Seq1F1B maintains higher Model FLOPs Utilization (MFU). This is primarily due to the lower communication overhead inherent in pipeline parallelism compared to the frequent all-to-all communications required by RingAttention in long-context scenarios.
Conclusion and Future Work
Seq1F1B provides a robust framework for scaling LLM training to ultra-long contexts by rethinking the fundamental units of pipeline scheduling. While highly optimized for long sequences, future work will focus on improving performance for shorter contexts and integrating Seq1F1B with other distributed optimization techniques like ZeRO-3 and zero-bubble scheduling. The implementation is open-sourced to facilitate further research in efficient long-context training.
Summary updated