Skip to content

Commit ec1ca64

Browse files
committed
add parallel doc
1 parent 01b2f4f commit ec1ca64

5 files changed

Lines changed: 201 additions & 0 deletions

File tree

_articles/Parallel.md

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
---
2+
layout: post
3+
title: "Parallel Mechanism of LightX2V"
4+
author: "LightX2V Team"
5+
date: 2026-05-19
6+
tags: [Parallel]
7+
---
8+
9+
## I. Overview of LightX2V's Parallel Mechanism
10+
11+
LightX2V is a distributed inference engine specifically designed for video generation tasks. It achieves multi-GPU acceleration through DiT parallelism, CFG parallelism, and hybrid parallelism.
12+
13+
#### DiT Parallelism
14+
15+
The video generation workload has the unique feature of "long sequences + small batches," which fundamentally distinguishes its best parallel strategies from the traditional methods used for large language models (LLMs) with "large models + high concurrency." The DiT parallelism of LightX2V mainly adopts sequence parallelism (SP) rather than the traditional tensor parallelism (TP) or data parallelism (DP). The specific reasons are as follows:
16+
17+
1. **Long sequence: SP is superior to TP in many aspects**
18+
19+
TP mainly addresses the pressure of the model dimension (d_model), while SP focuses on relieving pressure of the sequence dimension (L). Currently, the primary challenge of video generation tasks lies in "ultra-long sequences" rather than "super-large models," which makes the advantages of TP less prominent, while SP is a more direct and efficient solution.
20+
21+
At present, the parameter sizes of mainstream video generation models range from several billion to hundreds of billions, usually smaller than trillion-parameter LLMs, which leads to relatively limited computing and memory pressure on a single gpu. At the same time, video generation needs to take into account both temporal and spatial dimensions, and the resulting sequence is much longer than the typical LLM input sequence. The sequence length is calculated as frames × spatial_tokens_per_frame. Even for short videos, it can reach tens of thousands of tokens. Therefore, solving the problem of "ultra-long sequences" is a more urgent requirement for video generation tasks.
22+
23+
SP distributes the computing load and memory pressure of long sequences across multiple devices. Compared with TP, it has advantages in terms of communication volume, scalability and computing efficiency, which will be detailed later.
24+
25+
2. **Small Batch: A Staged Limitation of DP**
26+
27+
At this period, the core goal of video generation inference is to achieve high-quality real-time generation for a single task, and thus batch_size=1 is widely used. Under this setting, DP becomes invalid due to the fact that "there is no data to be divided," and thus cannot exert its advantages.
28+
29+
This is not an inherent defect of DP, but a stage state determined by the current task objective. If future workloads shift towards batch generation or need to serve multiple independent requests simultaneously, DP will re-emerge as a valuable parallel strategy, complementing SP/TP.
30+
31+
#### CFG Parallelism
32+
33+
Unlike traditional LLMs, video diffusion models use Classifier-Free Guidance (CFG), which requires computing both conditional predictions and unconditional predictions. LightX2V implements CFG parallelization, where different GPUs concurrently compute the conditional branches and the unconditional branches, and then aggregate the results.
34+
35+
This CFG parallelism mechanism is limited to 2 GPUs, one for conditional judgment and the other for unconditional judgment.
36+
37+
#### Hybrid Parallelism
38+
39+
LightX2V supports enabling both DiT parallelism and CFG parallelism simultaneously to jointly utilize the distributed GPU resources.
40+
41+
LightX2V employs a two-dimensional grid called device_mesh for parallel management, organizing the GPUs into a (cfg_p_size, seq_p_size) dimension, where cfg_p_size × seq_p_size equals the total number of GPUs:
42+
43+
- The **cfg_p** dimension: used for Classifier-Free Guidance parallelism.
44+
- The **seq_p** dimension: used for DiT sequence parallelism.
45+
46+
---
47+
48+
## II. Main Methods of DiT Sequence Parallelism
49+
50+
DiT computation is the bottleneck of video generation inference, and DiT sequence parallelism is the core of LightX2V's parallel strategy. Currently, LightX2V supports two representative sequence parallelism methods: Ulysses and Ring-Attention.
51+
52+
### Ulysses
53+
54+
The Ulysses method proposed by the DeepSpeed team works on the principle of performing data redistribution through two efficient all-to-all communications. This enables parallel processing of the attention calculation stage in the attention head dimension and parallel processing of other calculation stages in the sequence dimension.
55+
56+
#### Principle
57+
58+
The Ulysses method proposed by the DeepSpeed team redistributes data through two all-to-all communications. This enables the attention calculation stage to be processed across the head dimension, and the other calculation stages to be processed across the sequence dimension.
59+
60+
![Ulysses workflow diagram]({{ site.baseurl }}/assets/Parallel-blog/img2.PNG)
61+
62+
#### Workflow
63+
64+
1. **Sequence splitting:** Divide the input tokens along the sequence dimension and distribute them to each GPU.
65+
2. **Sequence parallel computation:** Complete the calculation phases before the attention phase.
66+
3. **Attention phase:**
67+
1. **Sequence-to-head exchange:** Before the attention calculation, through all-to-all communication, each GPU obtains the complete sequence but only handles a subset of the attention heads.
68+
2. **Local computation:** Each GPU performs Attention computation on the complete sequence for its assigned subset of attention heads.
69+
3. **Head-to-sequence exchange:** After the attention calculation, through all-to-all communication, each GPU recovers to the split along the sequence dimension and has all the attention heads.
70+
4. **Sequence parallel computation:** Complete the calculation phases after the attention phase.
71+
72+
### Ulysses-4090 Variant
73+
74+
LightX2V has specially designed the Ulysses-4090 variant for the RTX 4090 GPU. It replaces all-to-all collective communication with manual P2P communication to achieve better performance on consumer-grade hardware.
75+
76+
### Ring-Attention
77+
78+
#### Principle
79+
80+
Ring Attention, proposed by the University of California, Berkeley, draws on the block-wise computation principle of FlashAttention. It treats the long sequence as a series of "building blocks" (K/V blocks) that need to be assembled sequentially, and distributes them to each GPU. Then, it exchanges the blocks along a ring-shaped communication structure (Ring) like a pipeline until the attention computation for the entire sequence is completed.
81+
82+
![Ring-Attention workflow diagram]({{ site.baseurl }}/assets/parallel-blog/ring-attention-workflow.png)
83+
84+
#### Workflow
85+
86+
1. **Sequence splitting:** Divide the input tokens along the sequence dimension and distribute them to each GPU.
87+
2. **Sequence parallel computation:** Complete the calculation phases before the attention phase.
88+
3. **Attention phase:**
89+
1. **Ring communication:** Gradually send and receive the respective current K/V blocks between adjacent GPUs through ring-shaped point-to-point communication.
90+
2. **Block-wise computation:** After receiving a new set of K/V blocks, each GPU performs the calculation with the local Q block, and updates the attention output and normalization factors.
91+
3. **Iterative traversal:** Iterate through steps 2 and 3 sequentially until the entire ring is traversed.
92+
4. **Sequence parallel computation:** Complete the calculation phases after the attention phase.
93+
94+
### Technology Selection
95+
96+
We compare the core characteristics of Ulysses, Ring-Attention, and Tensor Parallelism (TP) across metrics such as communication volume, scalability, and computational efficiency, using the following definitions:
97+
98+
- **L:** Total sequence length.
99+
- **N:** Number of parallel devices.
100+
- **d:** Model hidden dimension.
101+
- **H:** Total number of attention heads.
102+
- **Hardware friendliness:**
103+
- For linear layers, computational efficiency is highest if the matrix is regular and wide, i.e., the hidden dimension d are multiples of specific values (e.g., 128, 256) and the multiplier is large enough to fully utilize the number of SMs. SP maintains the integrity of d, making it easier to meet the requirements of hardware. But TP splits d into d/N, which may degrade the computation shape and reduce computational efficiency.
104+
- For attention, extremely long sequences impose cache pressure. After the sequence is divided into blocks, the shorter sequence length brings better data locality and higher computational efficiency.
105+
106+
#### Comparative Analysis
107+
108+
The following is a breakdown and comparison of the three parallelization strategies:
109+
110+
1. **Ulysses**
111+
- **Parallel Dimension:** Attention Heads.
112+
- **Communication Volume:**
113+
- Global: ≈ 4 × L × d.
114+
- Per Device: ≈ (4 × L × d) / N.
115+
- Note: (4: Number of qkvo tensors)
116+
- Feature: The global communication volume is constant, independent of N. Increasing N directly reduces the communication burden on each device, resulting in minimal per-device overhead.
117+
- **Scalability:**
118+
- Upper Bound: ≤ H.
119+
- Feature: Limited by the inherent structure of the model (the number of heads), only valid for counting devices that can be divided evenly by H. The limitations of the GQA/MQA architecture are even more prominent.
120+
- **Computational Efficiency:**
121+
- Linear Layers: hardware friendliness = High
122+
- Attention Layers: hardware friendliness = Medium
123+
- Feature: Preserves full d for optimal linear shape. Full sequence L brings cache pressure for attention computation.
124+
125+
2. **Ring-Attention**
126+
- **Parallel Dimension:** Sequence Length.
127+
- **Communication Volume:**
128+
- Global: ≈ 2 × L × d × N.
129+
- Per Device: ≈ 2 × L × d.
130+
- Note: (2: Number of kv tensors)
131+
- Feature: Global volume increases with N, and per-device volume is constant.
132+
- **Scalability:**
133+
- Upper Bound: ≤ L.
134+
- Feature: Excellent in theory, limited only by the total sequence length. Enables processing of infinitely long sequences with sufficient devices.
135+
- **Computational Efficiency:**
136+
- Linear Layers: hardware friendliness = High
137+
- Attention Layers: hardware friendliness = High
138+
- Feature: Preserves full d for optimal linear shape. Splits sequence L and can achieve more hardware-efficient attention computation.
139+
140+
3. **Tensor Parallelism (TP)**
141+
- **Parallel Dimension:** Attention Heads.
142+
- **Communication Volume:**
143+
- Global: ≈ 2 × L × d × N.
144+
- Per Device: ≈ 2 × L × d.
145+
- Note: (2: Allreduce two-stage communication ratio)
146+
- Feature: Global volume increases with N, and per-device volume is constant.
147+
- **Scalability:**
148+
- Upper Bound: ≤ H.
149+
- Feature: Limited by the model's number of heads, similar to Ulysses.
150+
- **Computational Efficiency:**
151+
- Linear Layers: hardware friendliness = Low
152+
- Attention Layers: hardware friendliness = Medium
153+
- Feature: Splits d, degrading linear shape. Full sequence L brings cache pressure for attention computation.
154+
155+
#### Synthesis and Selection Guidelines
156+
157+
Based on the analysis above:
158+
159+
- **Communication Advantage:** Ulysses > Ring-Attention > TP
160+
- **Scalability Advantage:** Ring-Attention > Ulysses ≈ TP
161+
- **Computational Efficiency Advantage:** Ring-Attention > Ulysses > TP
162+
163+
TP exhibits comprehensive disadvantages compared to SP for long-sequence video generation tasks. Ulysses excels in minimizing communication burden but is limited by the head count (H). Ring-Attention imposes higher global communication pressure, but offers superior scalability and computational efficiency.
164+
165+
Therefore, for sequence parallelism technology selection:
166+
167+
- Prefer Ulysses when the model is relatively lightweight with abundant heads, and inter-device bandwidth is limited.
168+
- For other long-sequence scenarios, Ring-Attention might be more advantageous.
169+
170+
---
171+
172+
## III. Performance Evaluation
173+
174+
### Parallel Configuration Example
175+
176+
A typical parallel configuration of LightX2V is as follows. This configuration uses 4-way sequence parallelism and 2-way CFG parallelism, requiring a total of 8 GPUs. The DiT parallelism method is specified as Ulysses, with fp8 communication optimization enabled.
177+
178+
```json
179+
"parallel": {
180+
"cfg_p_size": 2,
181+
"seq_p_size": 4,
182+
"seq_p_fp8_comm": true,
183+
"seq_p_attn_type": "ulysses"
184+
}
185+
```
186+
187+
### Parallel Performance
188+
189+
On the RTX 5090 platform, for a video generation task using the Hunyuan 1.5-8B model for Image-to-Video (I2V) at 480p resolution with CFG enabled, all evaluated cases utilized int8 linear and sage attention optimizations. The per-step Diffusion Transformer (DiT) latency comparison is shown in the figure below, demonstrating good parallel efficiency even on consumer-grade GPUs with lower-speed interconnection.
190+
191+
![Hunyuan 1.5-8B parallel performance on RTX 5090]({{ site.baseurl }}/assets/Parallel-blog/img3.png)
192+
193+
Compared to leading open-source frameworks such as SGLang Diffusion, xDiT, and FastVideo, LightX2V demonstrates significant performance advantages. The comparison of per-step DiT latency for the Wan 2.1-14B model on an I2V 480p video generation task across multiple platforms is shown in the figure below. Specifically, LightX2V delivers a 1.59x speedup over the fastest open-source baseline on H100, a 2.73x speedup on RTX 5090, and a 3.26x speedup on RTX 4090.
194+
195+
![Wan 2.1-14B parallel performance comparison]({{ site.baseurl }}/assets/Parallel-blog/img4.png)

assets/Parallel-blog/img1.PNG

321 KB
Loading

assets/Parallel-blog/img2.PNG

139 KB
Loading

assets/Parallel-blog/img3.png

Lines changed: 3 additions & 0 deletions
Loading

assets/Parallel-blog/img4.png

Lines changed: 3 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)