Abstract
Context parallelism has emerged as a key technique to support long-context training, a growing trend in generative AI for modern large models. However, existing context parallel methods rely on static parallelization configurations that overlook the dynamic nature of training data, specifically, the variability in sequence lengths and token relationships (i.e., attention patterns) across samples. As a result, these methods often suffer from unnecessary communication overhead and imbalanced computation. In this paper, we present DCP, a dynamic context parallel training framework that introduces fine-grained blockwise partitioning of both data and computation. By enabling flexible mapping of data and computation blocks to devices, DCP can adapt to varying sequence characteristics, effectively reducing communication and improving memory and computation balance. Micro-benchmarks demonstrate that DCP accelerates attention by 1.19x~2.45x under causal masks and 2.15x~3.77x under sparse attention patterns. Additionally, we observe up to 0.94x~1.16x end-to-end training speed-up for causal masks, and 1.00x~1.46x for sparse masks.
Introduction
Training Large Language Models (LLMs) with massive context windows—ranging from 128K to 2M tokens—is essential for modern generative AI applications. To manage the immense memory requirements of these sequences, researchers utilize Context Parallelism (CP), which distributes a single sequence across multiple GPUs. However, current CP implementations are largely static, partitioning every batch identically regardless of the underlying data characteristics.
This "one-size-fits-all" approach introduces two major inefficiencies. First, real-world datasets are often "top-heavy," containing a few very long sequences and many shorter ones. Static CP treats these sequences uniformly, leading to redundant communication for shorter sequences. Second, modern training often employs sparse masks, such as sliding windows or shared question masks in RLHF. Static partitioning assumes a standard causal mask, resulting in significant computational load imbalances when these assumptions are violated.
The DCP Framework
DCP (Dynamic Context Parallelism) addresses these challenges by treating context parallelism as a dynamic optimization problem. The framework is built upon three primary pillars:
1. Fine-Grained Blockwise Partitioning
Rather than splitting sequences into large, rigid chunks, DCP divides Query (Q), Key (K), and Value (V) tensors into small, manageable blocks. This granularity allows for a much more flexible mapping of data and computation blocks across the GPU cluster, enabling the system to adapt to the specific needs of each batch.
2. Hypergraph Partitioning
To determine the optimal placement of these blocks, DCP models the training batch as a hypergraph. In this model, vertices represent data and computation blocks, while hyperedges represent the dependencies between them. By utilizing off-the-shelf solvers like KaHyPar, DCP minimizes communication costs while maintaining a strict balance of memory and compute resources across devices.
3. Asynchronous Planning & Execution
Since the optimal partitioning plan changes with every iteration, DCP employs a decoupled architecture. A Planner runs on the CPU, pre-fetching metadata for the next batch and calculating the partitioning scheme in the background. Simultaneously, a custom Executor on the GPU runs the current iteration using high-performance fused kernels based on FlashAttention and Triton. This overlap ensures that the overhead of dynamic planning does not bottleneck the training process.
Experimental Evaluation
The authors evaluated DCP using datasets designed for long-context tasks, including LongAlign (for LLM alignment) and LongDataCollections (which exhibits a highly skewed sequence length distribution).
Key Insights
- Redundancy Reduction: DCP identifies that for shorter sequences, it is often more efficient to use standard Data Parallelism (keeping the sequence on one device) rather than forcing the overhead of Context Parallelism.
- Mask-Awareness: By utilizing block-based partitioning, DCP naturally ignores "dead zones" in sparse attention masks. This avoids unnecessary computation and bandwidth usage that static methods would otherwise incur.
- Hierarchical Placement: The framework prioritizes minimizing inter-node communication over intra-node communication, aligning with the bandwidth hierarchies of modern data centers.
Results
Micro-benchmarks for individual attention layers show that DCP outperforms state-of-the-art baselines (such as TransformerEngine and LoongTrain) by 1.19x to 2.45x under standard causal masks and 2.15x to 3.77x under sparse attention patterns.
In end-to-end training of a GPT-8B model, DCP achieved up to a 1.16x speedup for causal masks and a 1.46x speedup for sparse masks. Furthermore, DCP significantly reduced the total inter-node communication volume compared to Megatron-LM baselines, particularly as sequence length dynamism increased.
Limitations and Future Work
While DCP provides substantial gains, the authors noted that in certain causal mask scenarios, performance was slightly limited by the greedy scheduling algorithm's ability to perfectly overlap computation and communication. Additionally, as block counts increase on massive clusters, CPU planning time could potentially become a bottleneck. Future research will focus on refining the scheduling algorithms to better handle the "tail" of execution plans and further optimizing the planning phase for extreme scale.
Summary updated