Efficient Scaling of LLM Training with Flexible Context Parallelism
Yifan Niu ⋅ Han Xiao ⋅ Dongyi Liu ⋅ Wei zhou ⋅ Jia Li
Abstract
Scaling long-context capabilities is crucial for Large Language Models (LLMs). However, real-world data contain a large number of sequences with heterogeneous lengths. Existing training libraries for LLMs rely on static parallelism strategies, which suffer from severe load imbalance, redundant communication, and suboptimal hardware utilization under data heterogeneity. In this work, we propose Flexible Context Parallelism (FCP), an efficient parallelism strategy that adaptively reconfigures communication groups and context parallelism degrees during LLM training. We support non-power-of-two Ring-CP degrees and combine memory-aware grouping with polynomial-time degree allocation, whose solve takes tens of milliseconds in the evaluated configurations. FCP is able to maintain high hardware efficiency even under extreme data heterogeneity. Experimental results demonstrate that FCP significantly outperforms Megatron-LM and DeepSpeed in both LLM and MLLM training, improving throughput across heterogeneous workloads on clusters of up to 64 devices. For extremely unbalanced batches, FCP even achieves 2.24 $\times$ speedup. The code is available at https://github.com/ivanniu/FCP.
Successful Page Load