Abstract
Extending the context length of Large Language Models (LLMs) is crucial for advanced applications. Sequence parallelism (SP) is a key technique for long-context training, but existing methods assume homogeneous sequence lengths, leading to inefficiencies when processing real-world, long-tailed datasets. We propose FlexSP, a heterogeneity-adaptive sequence parallelism method that dynamically assigns optimal SP degrees based on sequence length. By modeling this as a linear programming optimization, FlexSP achieves up to a 1.98x speedup over state-of-the-art frameworks.
Introduction: The Challenge of Heterogeneous Workloads
As LLMs are pushed to handle context lengths exceeding 100k tokens, memory constraints necessitate the use of Sequence Parallelism (SP), which shards sequences across multiple GPUs. However, standard SP implementations apply a static, "one-size-fits-all" strategy. This approach is fundamentally flawed because training corpora like Wikipedia, GitHub, and CommonCrawl exhibit significant variability in sequence lengths.
As shown in the distribution above, most sequences are relatively short, while a few are extremely long. Applying a high SP degree (required for the longest sequences) to the entire batch forces shorter sequences into excessive "All-to-All" communication, often across slower inter-node networks, leading to severe resource under-utilization.
FlexSP Architecture
FlexSP addresses this by moving from static to flexible parallelism. It captures the variability in sequence lengths for each training step and assigns an optimal combination of scattering strategies.
The system architecture consists of two primary components:
- The Solver (CPU-side):
- Sequence Blaster: Sorts sequences and uses dynamic programming to chunk them into micro-batches, minimizing length variance and balancing token counts.
- Parallelism Planner: Models the assignment of sequences to GPU groups as a Mixed-Integer Linear Programming (MILP) problem. It uses sequence bucketing to maintain tractability.
- The Executor (GPU-side):
- Implements "Hot Switching" to manage NCCL communication groups dynamically. The solving phase is overlapped with GPU computation of the previous batch to hide overhead.
Experimental Evaluation
FlexSP was evaluated using GPT-series models (7B to 30B parameters) on datasets with varying skewness. Key findings include:
- Throughput Gains: FlexSP outperformed Megatron-LM by up to 1.98x and DeepSpeed by up to 1.72x.
- Communication Efficiency: By keeping shorter sequences in smaller SP groups (e.g., degree $\le 8$), FlexSP leverages high-speed intra-node NVLink rather than slower inter-node InfiniBand. This reduces the time spent on "All-to-All" communication, which can otherwise exceed computation time for short sequences.
- Model Accuracy: The mathematical cost model used for optimization proved highly accurate, with an execution time estimation error rate of less than 6%.
- Scalability: FlexSP demonstrated superior robustness as GPU counts increased, maintaining efficiency even as inter-node bandwidth became a bottleneck for baseline systems.
Conclusion
FlexSP demonstrates that embracing workload heterogeneity is a significant opportunity for optimization in distributed LLM training. By adaptively matching parallelism degrees to sequence lengths, FlexSP significantly reduces communication overhead and improves resource utilization. Future work includes integrating Context Parallelism (CP) for ultra-long contexts and further optimizing solver latency for high-frequency iteration environments.
Summary updated