HCMS: Head-Chunked Multi-Stream Pipeline for Communication-Computation Overlap in Long-Sequence Parallel Attention

Chao Yuan\(^{1}\), Pan Li\(^{1}\), Yingnan Sun\(^{1}\), Jing Liu\(^{1}\)
\(^{1}\)Bilibili Inc., Shanghai, China
{yuanchao, lipan02, sunyingnan, liujing04}
bilibili.com?


Abstract

All-to-all based sequence parallelism methods execute communication and computation strictly in serial when processing medium-long sequences, resulting in hardware resource underutilization. This paper proposes Head-Chunked Multi-Stream Pipeline (HCMS), which exploits the computational independence of multi-head attention by partitioning attention heads into multiple chunks and achieving fine-grained communication-computation overlap through dual CUDA streams. HCMS is orthogonally compatible with existing optimizations such as FlashAttention and SDPA, requires no modification to underlying kernels, supports uneven partitioning while maintaining numerical equivalence. Experiments validate the effectiveness across four GPU platforms at 2-8 GPU scales: for typical video generation sequence lengths of 31K-56K tokens, HCMS achieves 10%-17.5% speedup over the Ulysses baseline and 5%-14.5% speedup over Ring Attention; end-to-end acceleration of 6.8% is achieved on the Wan2.2 model. Theoretical analysis shows that HCMS benefits are positively correlated with communication ratio \(\rho\), and its use is recommended when \(\rho>20\%\).

Keywords: Sequence Parallelism; Communication-Computation Overlap; Distributed Attention; CUDA Streams; Long Sequence Processing

1 Introduction↩︎

Large-scale Transformer models [1] have achieved breakthrough advances in natural language processing [2], [3], computer vision [4], and multimodal generation. Video generation represents one of the most prominent application scenarios [5][8]. Taking models such as Sora [9] and Wan2.2 as examples, generating 2-4 second videos at 720P resolution corresponds to sequence lengths of approximately 31K-56K tokens in latent space. This medium-long sequence processing requirement makes sequence parallelism a critical technique—distributing sequences across multiple GPUs to accelerate computation.

However, all-to-all based sequence parallelism schemes, represented by DeepSpeed Ulysses [10], exhibit significant efficiency issues: communication and computation execute strictly in serial, causing hardware resource underutilization. We observe that under typical configurations of 4-8 GPUs with PCIe interconnect and 31K-100K token sequence lengths, the communication ratio \(\rho\) typically ranges from 15% to 40%. This characteristic provides substantial room for communication optimization—through communication-computation overlap, a theoretical speedup upper bound of \(1/(1-\rho)\) can be achieved.

Existing sequence parallelism methods each have their limitations. Ring Attention [11] employs a ring communication pattern where overlap depends on block-level pipelined execution; when the number of blocks is small, overlap effectiveness is limited, and \(P-1\) rounds of serial communication are required. Although DeepSpeed Ulysses requires fewer communication rounds, its original implementation executes communication and computation completely in serial, failing to exploit overlap optimization.

A fundamental property of multi-head attention is that computations across different heads are mutually independent. This independence implies that the serial dependency of “communication \(\rightarrow\) computation” can be relaxed at the head granularity—rather than waiting for all heads’ input data to complete communication before starting computation, computation for any head can begin immediately once its data is ready. This property provides the theoretical foundation for achieving fine-grained communication-computation overlap at the head dimension.

Based on this insight, we propose the Head-Chunked Multi-Stream Pipeline (HCMS) method, which partitions attention heads into multiple independent chunks and achieves fine-grained pipelining through dual CUDA streams. HCMS supports uneven chunk partitioning with performance variance less than 1%, and is orthogonally compatible with existing attention optimizations such as FlashAttention and SDPA without requiring kernel modifications. Experiments demonstrate that HCMS achieves significant speedups across four GPU platforms at 2-8 GPU scales: for typical video generation sequence lengths of 31K-56K tokens, 4-GPU configurations achieve 17.5% speedup and 8-GPU configurations achieve 16.4% speedup, outperforming Ring Attention by 5%-14.5%. In end-to-end validation on the Wan2.2 video generation model, attention layers achieve 18.3% speedup and the complete pipeline achieves 6.8% speedup.

The main contributions of this paper are as follows:

  • Head Chunking Partitioning Strategy: We leverage the computational independence of multi-head attention to partition attention heads into \(C\) chunks, thereby decoupling the originally serial communication-computation dependency into \(C\) independently schedulable subtasks, achieving fine-grained parallelism without altering computational semantics. This method supports uneven partitioning (when \(H \bmod C \neq 0\)), and experiments show that performance variance compared to even partitioning is less than \(1\%\).

  • Theoretical Modeling and Applicability Analysis: We establish a performance model for HCMS and derive the optimal chunk count \(C^* = \sqrt{T_{comm}/\beta}\), clearly defining its applicability: significant benefits can be achieved when communication ratio \(\rho > 20\%\), while benefits are limited when \(\rho < 10\%\).

  • Cross-Platform Experimental Validation: Across four GPU platforms with \(2\)\(8\) GPU configurations, for sequence lengths of \(31\text{K}\)\(56\text{K}\) tokens, HCMS achieves \(5\%\)\(14.5\%\) speedup over Ring Attention and \(10\%\)\(17.5\%\) speedup over the Ulysses baseline. Furthermore, the method is fully compatible with PyTorch autograd and can be directly used for distributed training, achieving \(3.5\%\) training speedup while maintaining numerical equivalence.

2 Related Work↩︎

2.1 Sequence Parallelism Methods↩︎

Sequence parallelism distributes the sequence dimension across multiple devices [12], [13], primarily including ring communication-based methods and all-to-all based methods. The computations of different heads in multi-head attention are mutually independent, and this computational independence forms the theoretical foundation of our method.

Ring Attention [11] employs a ring communication pattern, partitioning sequences into \(P\) blocks and achieving distributed attention computation through \(P-1\) rounds of KV block passing. Its advantage lies in high memory efficiency, enabling processing of arbitrarily long sequences. However, Ring Attention’s communication-computation overlap is limited by block granularity: overlap is only effective when computation time exceeds communication time. Furthermore, \(P-1\) rounds of serial communication make total latency proportional to \(P\). Subsequent work such as Striped Attention [14] optimized for causal attention, but the video generation scenarios we focus on use bidirectional attention, making these optimizations not directly applicable.

DeepSpeed Ulysses [10] employs an all-to-all communication pattern: the input all-to-all rearranges data from “sequence-sharded, heads-complete” to “sequence-complete, heads-sharded”, and after attention computation, the output all-to-all performs the inverse transformation. Compared to Ring Attention’s \(P-1\) communication rounds, Ulysses requires only 2 rounds of all-to-all, with fewer communication rounds and better compatibility with FlashAttention [15], [16]. However, in Ulysses’ original implementation, communication and computation execute completely in serial, which is precisely the optimization target of this paper.

Megatron Context Parallelism [17], [18] provides both ring communication and all-gather modes. USP [19] unifies Ring and Ulysses into a single framework and proposes tile-based communication overlap techniques; LoongTrain [20] employs 2D parallelism across sequence and head dimensions to support million-scale token training; DistFlashAttn [21] extends FlashAttention to distributed scenarios; Colossal-AI [22] and LightSeq [13] provide unified distributed training frameworks. These works focus on the combination and scheduling of parallelism strategies, while HCMS focuses on the underlying communication-computation overlap implementation based on Ulysses; the two are orthogonal and composable.

In summary, existing sequence parallelism methods have the following limitations in communication-computation overlap: (1) Ring Attention’s overlap granularity is constrained by block size, and requires \(P-1\) communication rounds; (2) Ulysses achieves fewer communication rounds but lacks overlap mechanisms in its original implementation; (3) Tile-based overlap methods require modifications to underlying attention kernels, limiting their compatibility. HCMS addresses these gaps by introducing head-level chunking that enables fine-grained overlap while maintaining native compatibility with existing attention implementations.

2.2 Communication-Computation Overlap↩︎

Communication-computation overlap is a classical technique in distributed optimization [23], [24], widely applied in gradient synchronization [25], [26], ZeRO [27] parameter prefetching, and pipeline parallelism [28][30]. In the domain of distributed attention, tile-based methods [31], [32] achieve communication-computation overlap at the matrix level but require modifications to underlying attention kernels. In contrast, HCMS operates at a higher abstraction level—the attention head dimension—and is natively compatible with existing attention optimizations such as FlashAttention and SDPA, enabling orthogonal composition.

3 Method↩︎

3.1 Problem Formulation↩︎

Consider all-to-all based sequence parallel attention [10]. Input \(\boldsymbol{X} \in \mathbb{R}^{B \times (L/P) \times D}\) is distributed across \(P\) GPUs, with the forward pass consisting of: QKV projection \(\rightarrow\) RoPE [33] positional encoding \(\rightarrow\) input all-to-all \(\rightarrow\) attention computation \(\rightarrow\) output all-to-all \(\rightarrow\) output projection. The input all-to-all rearranges data from sequence-sharded to head-sharded, and the output all-to-all performs the inverse transformation. In the baseline implementation, communication and computation execute strictly in serial, with total execution time: \[T_{baseline} = T_{comm} + T_{attn} + T_{other}, \quad T_{comm} = T_{in} + T_{out}\] where \(T_{other}\) represents fixed overhead such as QKV projection and positional encoding. Defining the communication ratio \(\rho = T_{comm}/T_{baseline}\), under 4-8 GPU PCIe configurations \(\rho\) typically ranges from 15% to 40%, making communication-computation overlap a substantial optimization opportunity.

3.2 Method Overview↩︎

The core idea of HCMS is to partition attention heads into multiple chunks and achieve pipelined overlap between communication and computation through dual CUDA streams. Figure 1 illustrates the overall architecture.

Figure 1: HCMS method overview. (a) Baseline executes communication and computation serially; (b) HCMS decomposes operations into C chunks, with dual streams executing in parallel to achieve communication-computation overlap.

As shown in the figure, HCMS comprises three key components: (1) Head Chunking partitions attention heads into \(C\) independent chunks; (2) the dual-stream pipeline uses communication stream \(S_{comm}\) and compute stream \(S_{comp}\) for overlapped execution; (3) CUDA Event synchronization ensures correctness of data dependencies. We detail each component below.

3.3 Head Chunking Strategy↩︎

Property 1 (Computational Independence of Multi-Head Attention). In multi-head attention, given a total of \(H\) attention heads, for any two distinct heads \(h_i\) and \(h_j\) (\(i \neq j\)): \[\boldsymbol{O}_{h_i} = f(\boldsymbol{Q}_{h_i}, \boldsymbol{K}_{h_i}, \boldsymbol{V}_{h_i})\] The output of head \(h_i\) depends only on head \(h_i\)’s own inputs and is independent of other heads.

Based on Property 1, we can partition \(H\) attention heads into \(C\) chunks, with each chunk independently completing communication and computation. Let the \(c\)-th chunk contain \(H_c\) heads: \[H = \sum_{c=0}^{C-1} H_c, \quad H_c = \left\lfloor \frac{H}{C} \right\rfloor + \mathbb{1}_{c < H \bmod C}\]

After partitioning, the QKV tensors are correspondingly decomposed: \[\boldsymbol{Q} = [\boldsymbol{Q}_0 \| \boldsymbol{Q}_1 \| \cdots \| \boldsymbol{Q}_{C-1}]\] where \(\|\) denotes concatenation along the head dimension, and \(\boldsymbol{Q}_c \in \mathbb{R}^{B \times (L/P) \times H_c \times D}\).

Lemma 1 (No Data Dependency Between Chunks). For any two chunks \(i\) and \(j\) (\(i \neq j\)), the computation of chunk \(i\) does not depend on the communication results of chunk \(j\): \[\boldsymbol{O}_i = g(\text{AllToAll}(\boldsymbol{Q}_i, \boldsymbol{K}_i, \boldsymbol{V}_i))\] which is independent of \(\boldsymbol{Q}_j, \boldsymbol{K}_j, \boldsymbol{V}_j\) and their communication results.

Lemma 1 indicates that communication and computation of different chunks can be scheduled independently, providing the theoretical foundation for pipelined overlap.

3.4 Dual-Stream Pipeline Architecture↩︎

Based on Head Chunking, we design a dual CUDA stream pipeline architecture:

  • Communication stream \(S_{comm}\): dedicated to executing all-to-all collective communication

  • Compute stream \(S_{comp}\): dedicated to executing attention computation

Pipeline execution consists of three phases, as shown in Figure 2:

Phase 1 - Input Communication: The communication stream sequentially initiates input all-to-all for each chunk, recording event \(E_c^{comm}\) upon completion of each chunk’s communication.

Phase 2 - Attention Computation: The compute stream monitors \(E_c^{comm}\) events; once chunk \(c\)’s input data is ready, computation begins immediately. Event \(E_c^{comp}\) is recorded upon completion.

Phase 3 - Output Communication: The communication stream monitors \(E_c^{comp}\) events; once chunk \(c\)’s computation completes, output all-to-all is initiated immediately.

Figure 2: HCMS pipeline execution timeline. Communication stream S_{comm} and compute stream S_{comp} execute in parallel, with dashed lines indicating CUDA Event synchronization dependencies.

3.5 CUDA Event Synchronization Mechanism↩︎

Pipeline correctness depends on precise dependency management. We define two types of CUDA Events:

  • \(E_c^{comm}\): recorded when chunk \(c\)’s input all-to-all completes

  • \(E_c^{comp}\): recorded when chunk \(c\)’s attention computation completes

Dependencies are expressed as: \[\begin{align} \text{Attn}_c &\leftarrow \text{wait}(E_c^{comm}) \\ A_c^{out} &\leftarrow \text{wait}(E_c^{comp}) \end{align}\]

Key observation: Due to Lemma 1, \(A_{c+1}^{in}\) does not need to wait for \(\text{Attn}_c\) or \(A_c^{out}\) to complete. This means: \[A_{c+1}^{in} \parallel \text{Attn}_c \parallel A_c^{out}\] All three can execute in parallel, subject to hardware resource constraints.

3.6 Algorithm Description↩︎

Algorithm 3 provides the complete pseudocode for HCMS.

Figure 3: Head-Chunked Multi-Stream Pipeline (HCMS)

3.7 Theoretical Analysis↩︎

We establish a theoretical performance model for HCMS, deriving the optimal chunk count and speedup upper bound; detailed derivations are provided in Appendix 7. Let communication time be \(T_{comm}\), per-chunk overhead be \(\beta\), and communication ratio \(\rho = T_{comm}/T_{total}\). The core conclusions are:

Theorem 1 (Optimal Chunk Count). The chunk count that minimizes HCMS execution time is \(C^* = \sqrt{T_{comm}/\beta}\).

Theorem 2 (Speedup Upper Bound). When \(\beta \to 0\) and \(C \to \infty\), the theoretical upper bound of HCMS speedup is \(S_{max} = 1/(1-\rho)\).

Applicability: HCMS benefits are positively correlated with communication ratio \(\rho\). When \(\rho > 20\%\), HCMS is recommended and can achieve 3%-24% speedup; when \(\rho < 10\%\), benefits are limited to less than 1%. Factors affecting \(\rho\) include GPU count, sequence length, and interconnect type, with PCIe interconnect scenarios typically having higher \(\rho\) than NVLink, making HCMS benefits more pronounced.

3.8 Comparison with Ring Attention and Ulysses↩︎

Table 1 compares HCMS with existing methods across multiple dimensions.

Table 1: Comparison of HCMS with existing methods
Property Ring Attn Ulysses HCMS
Comm. Pattern P2P Ring All-to-All All-to-All
Comm. Rounds \(P-1\) 2 2
Comm. Volume \(O(LD)\) \(O(LD)\) \(O(LD)\)
Overlap Block-level None Chunk-level
Granularity Block - Head
FlashAttn Requires mod. Native Native
Causal Mask Native Native Native
Optimal Long seq. Med-long High \(\rho\)

3pt

Comparison with Ring Attention: Ring Attention’s overlap occurs at the block level, communicating one complete KV block per round, while HCMS’s overlap occurs at the head level with finer granularity. Regarding communication rounds, Ring Attention requires \(P-1\) rounds of serial communication, while HCMS requires only 2 rounds. The two have different optimal scenarios: Ring Attention excels in very long sequence, memory-constrained scenarios, while HCMS performs better in medium-long sequence scenarios with high communication ratio.

Comparison with Ulysses: The two differ fundamentally in their optimization dimensions. Ulysses focuses on the choice between all-to-all and P2P communication patterns, treating communication and computation as atomic operations executed serially; HCMS introduces Head Chunking as a new partitioning abstraction, leveraging the computational independence of multi-head attention (Property 1) to decompose atomic operations into independently schedulable subtasks, thereby achieving fine-grained pipelining at the head dimension. This concept is general: any all-to-all based sequence parallelism scheme can introduce communication-computation overlap through Head Chunking, with HCMS’s application to Ulysses being just one instance.

4 Experiments↩︎

This section validates the effectiveness of HCMS. The core claims are:

  • Performance improvement: HCMS achieves 10%-17.5% speedup over Ulysses and 5%-14.5% over Ring Attention for typical video generation sequence lengths of 31K-56K tokens, validated across four GPU platforms at 2-8 GPU scales.

  • End-to-end benefits: In the Wan2.2 video generation model, attention layers achieve 18.3% speedup and the complete pipeline achieves 6.8% speedup.

  • No accuracy loss: HCMS output is identical to baseline across all configurations, supports training scenarios with 3.5% speedup, and reduces peak memory by 8.7%.

Appendix 9 contains complete experimental data and supplementary analysis.

4.1 Experimental Setup↩︎

Hardware environment: To validate generalization, we conduct experiments on four GPU platforms with configurations shown in Table 2. Software environment is PyTorch [34] 2.9.1, CUDA 12.8, collective communication via NCCL [35], with BF16 [36] numerical precision.

Table 2: Experimental platform configurations
Platform GPU Mem Interconn. Attention
A 4\(\times\)L20 46GB PCIe 4.0 FlashAttn-2
B 4\(\times\)4090 24GB PCIe 4.0 SDPA
C 4\(\times\)A10 22GB PCIe 4.0 SDPA
D 8\(\times\)5090 32GB PCIe 5.0 SDPA

3pt

Model configuration: We use typical parameters from video generation models [37], [38], shown in Table 3.

Table 3: Model configuration
Parameter Value
Hidden dim. \(D_{model}\) 5120
Attention heads \(H\) 40
Head dimension \(D\) 128
Latent resolution \(60 \times 104\)
Frames 9 / 21 / 33 / 45
Sequence length 56K / 131K / 206K / 281K

Evaluation metrics: We use end-to-end latency, throughput, and speedup ratio for performance evaluation, while verifying numerical consistency through maximum/mean error.

Baseline method: We use the standard implementation of DeepSpeed Ulysses [10] as the baseline. Ulysses is the mainstream sequence parallelism approach, with communication pattern consisting of input all-to-all, attention computation, and output all-to-all in three stages. In the original Ulysses implementation, communication and computation execute strictly in serial, which is precisely the optimization target of HCMS.

Implementation details: HCMS employs device-level stream caching to avoid frequent creation overhead, and KV Cache uses a chunk-organized list structure to support chunked computation. When \(H\) is not divisible by \(C\), a “more-first-less-later” uneven partitioning strategy is used; experiments show performance variance is less than 1%.

4.2 Main Results↩︎

Table 4 shows performance across different GPU configurations on each platform.

Table 4: Performance across different GPU counts, 131K tokens, \(C=4\)
Platform GPUs Ulysses HCMS Speedup
L20+FA 2 1896.8ms 1828.6ms 1.037\(\times\)
4 996.2ms 945.3ms 1.054\(\times\)
A10+SDPA 2 3424.1ms 3007.0ms 1.139\(\times\)
4 1643.2ms 1458.8ms 1.126\(\times\)
5090+SDPA 2 988.4ms 981.5ms 1.007\(\times\)
4 502.3ms 500.5ms 1.004\(\times\)
8 288.3ms 276.1ms 1.044\(\times\)

From the GPU scaling perspective, speedup correlates positively with communication ratio \(\rho\): the A10 platform with higher \(\rho\) achieves 12.6%-13.9% speedup; the L20 platform achieves 3.7%-5.4% speedup; the RTX 5090 8-GPU configuration achieves 4.4% speedup, validating HCMS effectiveness in large-scale parallel scenarios.

Table 5 shows performance comparison across different sequence lengths.

Table 5: Performance comparison across different sequence lengths, \(C=4\)
Seq. L20+FA 4-GPU 4090+SDPA 4-GPU 5090 8-GPU
2-3 (lr)4-5 (lr)6-7 Ulysses Spdup Ulysses Spdup Ulysses Spdup
56K 234.5ms 1.10\(\times\) 182.8ms 1.18\(\times\) 73.3ms 1.16\(\times\)
131K 996.4ms 1.06\(\times\) 725.9ms 1.07\(\times\) 288.3ms 1.05\(\times\)
206K 2262.2ms 1.04\(\times\) 1617.3ms 1.06\(\times\) 631.0ms 1.05\(\times\)
281K 4046.3ms 1.03\(\times\) 2868.1ms 1.04\(\times\) 1112.9ms 1.01\(\times\)

3pt

Experimental results show clear sequence length dependency: shorter sequences yield higher speedups. The 56K sequence achieves 17.5% speedup on 4090 4-GPU configuration and 16.4% speedup on 5090 8-GPU configuration. The 4090 platform achieves overall higher speedups than L20 because both platforms use PCIe 4.0 interconnect with similar communication time, while 4090 has shorter total execution time (182.8ms vs 234.5ms), resulting in higher communication ratio \(\rho\) and thus greater HCMS benefits. The A10 platform achieves 12.6%-13.9% speedup at 131K tokens, further validating the “higher communication ratio, greater benefits” principle. For 8-GPU scalability, the 5090 platform still achieves 16.4% speedup at 56K tokens, while benefits decrease to 0.9% at 281K tokens, consistent with theoretical expectations. All four platforms (L20, 4090, A10, 5090) at 2-8 GPU scales validate HCMS effectiveness, demonstrating cross-hardware, cross-scale generalization.

Reason analysis: Attention computation complexity is \(O(L^2)\), while communication complexity is \(O(L)\). As sequences grow longer, computation time increases much faster than communication time, causing communication ratio \(\rho\) to decrease and HCMS overlap benefits to diminish.

Figure 4 visualizes this trend.

Figure 4: Speedup versus sequence length. All three configurations show greater HCMS benefits for shorter sequences. The 5090 8-GPU configuration validates effectiveness in large-scale parallel scenarios.

Comparison with Ring Attention: Table 6 presents a three-way comparison of HCMS, Ring Attention, and Ulysses. For typical video generation sequence lengths of 31K-56K tokens, HCMS leads comprehensively: 14.5% faster than Ring at 31K tokens, 5.0% faster at 56K. For longer sequences above 131K, Ring is slightly better by 1.7%, with the crossover point at approximately 60-80K tokens.

Table 6: Three-way comparison: HCMS vs Ring Attention vs Ulysses, L20+FA 4-GPU
Seq. Ulysses Ring HCMS Best
31K 95.5ms 95.4ms 83.3ms HCMS (+14.5%)
56K 234.7ms 223.3ms 212.7ms HCMS (+5.0%)
131K 996.9ms 929.4ms 945.4ms Ring (+1.7%)

4.3 Ablation Studies↩︎

Table 7 shows the effect of different chunk counts on performance, with experimental configuration of 4 GPUs and 131K tokens.

Table 7: Performance with different chunk counts
Chunks Latency (ms) Speedup Rel. to Best
1 (Ulysses) 996.2 1.000\(\times\) -5.2%
2 951.5 1.047\(\times\) -0.7%
4 945.3 1.054\(\times\) -0.1%
5 944.5 1.055\(\times\) Best
8 963.8 1.034\(\times\) -2.0%
10 970.9 1.026\(\times\) -2.7%

Results show that as \(C\) increases from 1 to 5, speedup continuously improves because more chunks enable finer-grained communication-computation overlap. However, performance begins to decline when \(C\) exceeds 5, due to accumulated Event synchronization overhead and efficiency loss from overly fine computation granularity. In this configuration, the optimal point is \(C=5\), but \(C=4\) is already near-optimal and simpler to implement.

Uneven partitioning robustness: When \(H\) is not divisible by \(C\), a “more-first-less-later” strategy is used. Table 8 shows partitioning schemes and performance for different \(C\) values, with configuration \(H=40\), 4 GPUs, \(H_{per\_rank}=10\).

Table 8: Uneven chunk partitioning performance
\(C\) Type Chunk Sizes Imbal. Speedup
2 Even [5, 5] 0% 1.049\(\times\)
3 Uneven [4, 3, 3] 30% 1.056\(\times\)
4 Uneven [3, 3, 2, 2] 40% 1.055\(\times\)
5 Even [2, 2, 2, 2, 2] 0% 1.055\(\times\)
6 Uneven [2, 2, 2, 2, 1, 1] 60% 1.052\(\times\)

4pt

Even partitioning achieves average speedup of 1.044\(\times\), while uneven partitioning achieves 1.048\(\times\), with only 0.4% difference. This indicates that load imbalance effects are masked by pipelined execution, and the optimal \(C\) value need not satisfy divisibility.

Correctness and training support: HCMS output is identical to baseline across all configurations, with maximum error of 0. HCMS is compatible with PyTorch autograd, achieving 3.5% speedup for forward+backward combined execution and 8.7% reduction in peak memory; see Appendix 9 for details.

4.4 End-to-End Video Generation Validation↩︎

To validate HCMS effectiveness in real applications, we integrate it into the Wan2.2 video generation model [39] for end-to-end experiments.

Experimental setup: We use the Wan2.2 TI2V-5B model (Text-Image-to-Video 5B parameters) with 24 attention heads, 128 head dimension, 30-layer DiT [40], resolution 1280\(\times\)​704, and 4 GPUs with Ulysses sequence parallelism.

Attention layer benchmark: Table 9 shows attention layer performance for the TI2V-5B configuration with 24 heads and 4 GPUs across different sequence lengths.

Table 9: Wan2.2 TI2V-5B attention layer performance, 24 heads, 4 GPUs, \(C=6\)
Frames Seq. Length Ulysses HCMS Speedup
17 frames 17.6K 16.35ms 13.36ms +18.3%
49 frames 43.2K 72.61ms 61.87ms +14.8%
81 frames 70.4K 167.56ms 152.91ms +8.7%

End-to-end performance: Table 10 shows end-to-end performance for the complete video generation pipeline.

Table 10: Wan2.2 TI2V-5B end-to-end performance, 4 GPUs, \(C=6\)
Frames Video Duration Ulysses HCMS Speedup
17 frames 0.7s 1.69s/it 1.67s/it +1.2%
49 frames 2.0s 2.34s/it 2.18s/it +6.8%

For attention layer performance, the 17-frame short video configuration achieves 18.3% speedup, and the 49-frame medium-length video configuration achieves 14.8% speedup. For end-to-end performance, 49-frame video per-step inference time decreases from 2.34s to 2.18s, achieving measured speedup of 6.8%. In this configuration, the optimal chunk count is \(C=6\), i.e., 24 heads partitioned into 6 chunks with 4 heads per chunk, where more chunks provide better pipeline overlap.

End-to-end benefit analysis: Attention layers achieve 14.8% speedup, but end-to-end is only 6.8%, because the video generation pipeline includes other components such as T5 text encoding and VAE decoding. For pure DiT inference scenarios, HCMS end-to-end benefits will be closer to attention layer speedup.

5 Conclusion↩︎

This paper proposes Head-Chunked Multi-Stream Pipeline (HCMS), optimizing communication-computation overlap for sequence parallel attention in medium-long sequence scenarios of 31K-100K tokens such as video generation. By partitioning attention heads into independent chunks through the Head Chunking strategy and achieving fine-grained pipelining via dual CUDA streams, efficient parallelization of communication and computation is achieved without changing computational semantics. Theoretical analysis shows HCMS benefits are positively correlated with communication ratio \(\rho\), and its use is recommended when \(\rho > 20\%\).

Experiments validate effectiveness across four GPU platforms at 2-8 GPU scales: for typical video generation sequence lengths of 31K-56K tokens, HCMS achieves 10%-17.5% speedup over the Ulysses baseline and 5%-14.5% over Ring Attention; in Wan2.2 end-to-end validation, attention layers achieve 18.3% speedup and the complete pipeline achieves 6.8% speedup. HCMS supports uneven partitioning with performance variance less than 1%, is compatible with PyTorch autograd with 3.5% training speedup, and is orthogonally composable with frameworks such as USP and LoongTrain.

6 Discussion↩︎

Limitations: HCMS benefits are limited in compute-dominated scenarios where \(\rho < 10\%\), such as 281K token long sequences achieving only 3.0% speedup. Additionally, when chunk count \(C\) is too large, Event synchronization overhead accumulates noticeably, and implementation introduces multi-stream management complexity.

Future work: This paper validates up to 8-GPU scenarios; future work will extend to 16-GPU and cross-node scenarios. Other directions include: applying HCMS to backward pass gradient communication overlap, and implementing adaptive scheduling mechanisms that dynamically select \(C\) based on runtime profiling.

7 Detailed Theoretical Derivations↩︎

This section provides complete derivations for the HCMS theoretical performance model.

7.1 Notation↩︎

For convenience of analysis, we define the notation shown in Table 11:

Table 11: Notation for theoretical analysis
Symbol Meaning
\(T_{comm}\) Total comm. time, \(T_{comm} = T_{a2a,in} + T_{a2a,out}\)
\(T_{attn}\) Total attention computation time
\(T_0\) Fixed overhead (QKV proj., output proj.)
\(C\) Number of chunks
\(\beta\) Per-chunk overhead (Event sync, kernel launch)
\(\rho\) Communication ratio, \(\rho = T_{comm} / T_{total}\)

3pt

7.2 HCMS Time Model↩︎

Baseline execution time. In serial execution mode, total time is the sum of all stages: \[T_{base} = T_0 + T_{comm} + T_{attn}\]

HCMS execution time. In pipeline mode, \(H\) attention heads are partitioned into \(C\) chunks. Due to no data dependency between chunks (Lemma 1), computation of chunk \(i\) can execute in parallel with communication of chunk \(i+1\). Let per-chunk overhead be \(\beta\), then: \[\label{eq:hcms95time} T_{hcms}(C) = T_0 + \frac{T_{comm}}{C} + T_{attn} + C \cdot \beta\tag{1}\]

7.3 Optimal Chunk Count Derivation↩︎

Taking the derivative of Equation (1 ) with respect to \(C\) and setting it to zero yields \(C^* = \sqrt{T_{comm}/\beta}\). The second-order condition confirms this is a minimum.

7.4 Speedup Analysis↩︎

Let communication ratio \(\rho = T_{comm}/T_{total}\), the speedup is: \[\label{eq:speedup} S(C) = \frac{1}{1 - \rho \cdot \frac{C-1}{C} + \frac{C \cdot \beta}{T_{total}}}\tag{2}\]

When \(\beta \to 0\) and \(C \to \infty\), the speedup upper bound is \(S_{max} = 1/(1-\rho)\).

7.5 Theoretical Predictions vs. Experimental Validation↩︎

Table 12 shows comparison of theoretical predictions with measurements on the RTX 5090 platform. Time model prediction errors are all less than 1.4%.

Table 12: Theoretical predictions vs. measurements, RTX 5090 8-GPU
\(H\) Seq \(\rho\) \(\beta\) \(C^*\) Error Speedup
5-6 (ms) Pred. Meas.
40 56K 39.6% 1.41 5 5 0.58% 24.0%
40 131K 22.1% 6.83 1 5 0.52% 4.2%
24 56K 38.1% 1.23 3 3 1.38% 16.0%
24 131K 21.7% 5.52 3 3 1.15% 2.9%

3pt

7.6 Applicability Guidelines↩︎

Table 13 summarizes applicability for different communication ratios \(\rho\).

Table 13: Relationship between communication ratio and speedup
Comm. Ratio \(\rho\) Theor. \(S_{max}\) Meas. Spdup Recomm.
\(>35\%\) \(>1.54\times\) 16%-24% Highly rec.
20%-35% 1.25\(\times\)-1.54\(\times\) 3%-6% Recommended
10%-20% 1.11\(\times\)-1.25\(\times\) 1%-3% Optional
\(<10\%\) \(<1.11\times\) \(<1\%\) Limited

3pt

8 System Architecture↩︎

Figure 5 shows the complete system architecture of HCMS.

Figure 5: HCMS system architecture

9 Detailed Experimental Data↩︎

9.1 Correctness and Training Validation↩︎

HCMS output is identical to baseline across all configurations, as shown in Table 14. Forward+backward combined execution achieves 3.5% speedup (Table 15), with 8.7% reduction in peak memory (Table 16).

Table 14: Numerical correctness validation, BF16 precision
GPU Rank Max Diff Mean Diff Status
0 0.0 0.0 PASS
1 0.0 0.0 PASS
2 0.0 0.0 PASS
3 0.0 0.0 PASS
Table 15: Forward+backward combined performance, 4 GPUs, 131K tokens
Method Time (ms) Speedup
Ulysses 3292.5 1.000\(\times\)
HCMS (\(C\)=5) 3181.4 1.035\(\times\)
Table 16: GPU peak memory comparison, 4 GPUs, 131K tokens
Method Peak Memory (GB) Relative Change
Ulysses 6.767
HCMS 6.178 -8.7%

9.2 Complete Experimental Results↩︎

Table 17 summarizes complete results for all experimental configurations.

Table 17: Complete experimental results
Platform GPU Seq C Ulysses HCMS Spdup
L20+FA 4 56K 4 234.5 212.6 1.10\(\times\)
4 131K 4 996.2 945.3 1.05\(\times\)
4 206K 4 2262.2 2182.1 1.04\(\times\)
4 281K 4 4046.3 3928.4 1.03\(\times\)
2 131K 4 1896.8 1828.6 1.04\(\times\)
4090+SDPA 4 56K 4 182.8 155.6 1.18\(\times\)
4 131K 4 725.9 677.8 1.07\(\times\)
4 206K 4 1617.3 1525.8 1.06\(\times\)
4 281K 4 2868.1 2755.1 1.04\(\times\)
A10+SDPA 2 131K 4 3424.1 3007.0 1.14\(\times\)
4 131K 4 1643.2 1458.8 1.13\(\times\)
5090+SDPA 2 131K 4 988.4 981.5 1.01\(\times\)
4 131K 4 502.3 500.5 1.00\(\times\)
8 131K 4 288.3 276.1 1.04\(\times\)
8 56K 4 73.3 63.0 1.16\(\times\)
8 206K 4 631.0 603.3 1.05\(\times\)
8 281K 4 1112.9 1102.4 1.01\(\times\)

2.5pt

References↩︎

[1]
A. Vaswani et al., “Attention is all you need,” in Advances in neural information processing systems, 2017, vol. 30, pp. 5998–6008.
[2]
J. Devlin, M.-W. Chang, K. Lee, and K. Toutanova, “BERT: Pre-training of deep bidirectional transformers for language understanding,” in Proceedings of the 2019 conference of the north american chapter of the association for computational linguistics: Human language technologies, volume 1 (long and short papers), 2019, pp. 4171–4186, doi: 10.18653/v1/N19-1423.
[3]
T. B. Brown et al., “Language models are few-shot learners,” arXiv preprint arXiv:2005.14165, May 2020, [Online]. Available: https://arxiv.org/abs/2005.14165.
[4]
A. Dosovitskiy et al., “An image is worth 16x16 words: Transformers for image recognition at scale,” in International conference on learning representations (ICLR), 2021, [Online]. Available: https://arxiv.org/abs/2010.11929.
[5]
W. Hong, M. Ding, W. Zheng, X. Liu, and J. Tang, “CogVideo: Large-scale pretraining for text-to-video generation via transformers.” 2022, [Online]. Available: https://arxiv.org/abs/2205.15868.
[6]
A. Blattmann et al., “Stable video diffusion: Scaling latent video diffusion models to large datasets,” arXiv preprint arXiv:2311.15127, 2023, [Online]. Available: https://arxiv.org/abs/2311.15127.
[7]
U. Singer et al., “Make-a-video: Text-to-video generation without text-video data,” arXiv preprint arXiv:2209.14792, 2022, [Online]. Available: https://arxiv.org/abs/2209.14792.
[8]
J. Ho, W. Chan, et al., “Imagen video: High definition video generation with diffusion models,” arXiv preprint arXiv:2210.02303, 2022, [Online]. Available: https://arxiv.org/abs/2210.02303.
[9]
OpenAI, “Video generation models as world simulators,” OpenAI, 2024. [Online]. Available: https://openai.com/research/video-generation-models-as-world-simulators.
[10]
S. A. Jacobs et al., “DeepSpeed ulysses: System optimizations for enabling training of extreme long sequence transformer models.” 2023, [Online]. Available: https://arxiv.org/abs/2309.14509.
[11]
H. Liu, M. Zaharia, and P. Abbeel, “Ring attention with blockwise transformers for near-infinite context.” 2023, [Online]. Available: https://arxiv.org/abs/2310.01889.
[12]
S. Li, F. Xue, Y. Li, and Y. You, “Sequence parallelism: Making 4D parallelism possible,” arXiv preprint arXiv:2105.13120, 2021, [Online]. Available: https://arxiv.org/abs/2105.13120.
[13]
D. Li et al., “LightSeq: Sequence level parallelism for distributed training of long context transformers,” in International conference on learning representations (ICLR), 2024, [Online]. Available: https://openreview.net/forum?id=qScA3fL49l.
[14]
Y. Liu, Z. Wang, Y. Zhang, D. Li, and K. Chen, “Striped attention: Faster ring attention for causal transformers,” arXiv preprint arXiv:2311.09431, 2023, [Online]. Available: https://arxiv.org/abs/2311.09431.
[15]
T. Dao, D. Y. Fu, S. Ermon, A. Rudra, and C. Ré, “FlashAttention: Fast and memory-efficient exact attention with IO-awareness,” in Advances in neural information processing systems, 2022, vol. 35, pp. 16377–16390.
[16]
T. Dao, “FlashAttention-2: Faster attention with better parallelism and work partitioning,” in The twelfth international conference on learning representations, 2024.
[17]
M. Shoeybi, M. Patwary, R. Puri, P. LeGresley, J. Casper, and B. Catanzaro, “Megatron-LM: Training multi-billion parameter language models using model parallelism,” in Proceedings of the international conference for high performance computing, networking, storage and analysis, 2019, pp. 1–15.
[18]
D. Narayanan et al., “Efficient large-scale language model training on GPU clusters using megatron-LM,” in Proceedings of the international conference for high performance computing, networking, storage and analysis, 2021.
[19]
J. Fang and S. Zhao, “USP: A unified sequence parallelism approach for long context generative AI.” 2024, [Online]. Available: https://arxiv.org/abs/2405.07719.
[20]
M. Wang et al., “LoongTrain: Efficient training of long-sequence LLMs with head-context parallelism,” arXiv preprint arXiv:2406.18485, 2024, [Online]. Available: https://arxiv.org/abs/2406.18485.
[21]
J. Fang, Z. Zhu, Y. Yu, and X. Liu, “DISTFLASHATTN: Distributed memory-efficient attention for long-context LLMs training,” arXiv preprint arXiv:2401.07248, 2024, [Online]. Available: https://arxiv.org/abs/2401.07248.
[22]
Z. Bian, H. Liu, et al., “Colossal-AI: A unified deep learning system for large-scale parallel training,” in 52nd international conference on parallel processing (ICPP), 2023, pp. 1–10, doi: 10.1145/3605573.3605613.
[23]
A. Jangda et al., “Breaking the computation and communication abstraction barrier in distributed machine learning workloads,” in Proceedings of the 27th ACM international conference on architectural support for programming languages and operating systems (ASPLOS), 2022, pp. 819–834.
[24]
A. Jangda et al., “CoCoNet: Co-optimizing computation and communication for distributed machine learning,” in Proceedings of machine learning and systems (MLSys), 2021, vol. 3, pp. 1–14, [Online]. Available: https://openreview.net/forum?id=8sTBZFXCnf.
[25]
A. Sergeev and M. Del Balso, “Horovod: Fast and easy distributed deep learning in TensorFlow,” arXiv preprint arXiv:1802.05799, 2018, [Online]. Available: https://arxiv.org/abs/1802.05799.
[26]
Y. Zhao et al., “PyTorch FSDP: Experiences on scaling fully sharded data parallel,” Proceedings of the VLDB Endowment, vol. 16, no. 12, pp. 3848–3860, 2023, doi: 10.14778/3611540.3611569.
[27]
S. Rajbhandari, J. Rasley, O. Ruwase, and Y. He, “ZeRO: Memory optimizations toward training trillion parameter models,” arXiv preprint arXiv:1910.02054, 2020.
[28]
Y. Huang et al., “GPipe: Efficient training of giant neural networks using pipeline parallelism,” in Advances in neural information processing systems, 2019, vol. 32.
[29]
D. Narayanan et al., “PipeDream: Generalized pipeline parallelism for DNN training,” in Proceedings of the 27th ACM symposium on operating systems principles (SOSP), 2019, pp. 1–15, doi: 10.1145/3341371.3359646.
[30]
P. Qi, X. Wan, G. Huang, and M. Lin, “Zero bubble (almost) pipeline parallelism,” in International conference on learning representations (ICLR), 2024, [Online]. Available: https://openreview.net/forum?id=tuzTN0eIO5.
[31]
Z. Zhong et al., “OverlapAttention: Tile-based overlap-driven efficient attention for distributed LLM,” arXiv preprint arXiv:2501.01005, 2025, [Online]. Available: https://arxiv.org/abs/2501.01005.
[32]
Z. Zhang, S. Zheng, Y. Wang, X. Li, and K. Chen, “Overlap communication with dependent computation via decomposition in large deep learning models,” in Proceedings of the 29th international conference on architectural support for programming languages and operating systems (ASPLOS), 2024, pp. 1–16, [Online]. Available: https://arxiv.org/abs/2312.08265.
[33]
J. Su, Y. Lu, S. Pan, A. Murtadha, B. Wen, and Y. Liu, “RoFormer: Enhanced transformer with rotary position embedding,” arXiv preprint arXiv:2104.09864, 2024.
[34]
A. Paszke et al., “PyTorch: An imperative style, high-performance deep learning library,” in Advances in neural information processing systems, 2019, vol. 32.
[35]
NVIDIA, “NCCL: Accelerated multi-GPU collective communications,” NVIDIA, 2015. [Online]. Available: https://developer.nvidia.com/nccl.
[36]
P. Micikevicius et al., “Mixed precision training,” in International conference on learning representations (ICLR), 2018, [Online]. Available: https://arxiv.org/abs/1710.03740.
[37]
P. Dhariwal and A. Nichol, “Diffusion models beat GANs on image synthesis,” arXiv preprint arXiv:2105.05233, 2021, [Online]. Available: https://arxiv.org/abs/2105.05233.
[38]
R. Rombach, A. Blattmann, D. Lorenz, P. Esser, and B. Ommer, “High-resolution image synthesis with latent diffusion models,” in Proceedings of the IEEE/CVF conference on computer vision and pattern recognition (CVPR), 2022, pp. 10684–10695, [Online]. Available: https://arxiv.org/abs/2112.10752.
[39]
Z. Wang et al., “Open-sora: Democratizing end-to-end video generation with transformers,” arXiv preprint arXiv:2403.17349, 2024, [Online]. Available: https://arxiv.org/abs/2403.17349.
[40]
W. Peebles and S. Xie, “Scalable diffusion models with transformers,” arXiv preprint arXiv:2212.09748, 2023.