Skip to content

Commit 2c6a6c9

Browse files
[docs] Add xDiT in section optimization (#9365)
* docs: add xDiT to optimization methods * fix: picture layout problem * docs: add more introduction about xdit & apply suggestions * Apply suggestions from code review Co-authored-by: Steven Liu <[email protected]> --------- Co-authored-by: Steven Liu <[email protected]>
1 parent a7361dc commit 2c6a6c9

File tree

2 files changed

+124
-0
lines changed

2 files changed

+124
-0
lines changed

docs/source/en/_toctree.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,8 @@
161161
title: DeepCache
162162
- local: optimization/tgate
163163
title: TGATE
164+
- local: optimization/xdit
165+
title: xDiT
164166
- sections:
165167
- local: using-diffusers/stable_diffusion_jax_how_to
166168
title: JAX/Flax

docs/source/en/optimization/xdit.md

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# xDiT
2+
3+
[xDiT](https://github.com/xdit-project/xDiT) is an inference engine designed for the large scale parallel deployment of Diffusion Transformers (DiTs). xDiT provides a suite of efficient parallel approaches for Diffusion Models, as well as GPU kernel accelerations.
4+
5+
There are four parallel methods supported in xDiT, including [Unified Sequence Parallelism](https://arxiv.org/abs/2405.07719), [PipeFusion](https://arxiv.org/abs/2405.14430), CFG parallelism and data parallelism. The four parallel methods in xDiT can be configured in a hybrid manner, optimizing communication patterns to best suit the underlying network hardware.
6+
7+
Optimization orthogonal to parallelization focuses on accelerating single GPU performance. In addition to utilizing well-known Attention optimization libraries, we leverage compilation acceleration technologies such as torch.compile and onediff.
8+
9+
The overview of xDiT is shown as follows.
10+
11+
<div class="flex justify-center">
12+
<img src="https://github.com/xdit-project/xDiT/raw/main/assets/methods/xdit_overview.png">
13+
</div>
14+
You can install xDiT using the following command:
15+
16+
17+
```bash
18+
pip install xfuser
19+
```
20+
21+
Here's an example of using xDiT to accelerate inference of a Diffusers model.
22+
23+
```diff
24+
import torch
25+
from diffusers import StableDiffusion3Pipeline
26+
27+
from xfuser import xFuserArgs, xDiTParallel
28+
from xfuser.config import FlexibleArgumentParser
29+
from xfuser.core.distributed import get_world_group
30+
31+
def main():
32+
+ parser = FlexibleArgumentParser(description="xFuser Arguments")
33+
+ args = xFuserArgs.add_cli_args(parser).parse_args()
34+
+ engine_args = xFuserArgs.from_cli_args(args)
35+
+ engine_config, input_config = engine_args.create_config()
36+
37+
local_rank = get_world_group().local_rank
38+
pipe = StableDiffusion3Pipeline.from_pretrained(
39+
pretrained_model_name_or_path=engine_config.model_config.model,
40+
torch_dtype=torch.float16,
41+
).to(f"cuda:{local_rank}")
42+
43+
# do anything you want with pipeline here
44+
45+
+ pipe = xDiTParallel(pipe, engine_config, input_config)
46+
47+
pipe(
48+
height=input_config.height,
49+
width=input_config.height,
50+
prompt=input_config.prompt,
51+
num_inference_steps=input_config.num_inference_steps,
52+
output_type=input_config.output_type,
53+
generator=torch.Generator(device="cuda").manual_seed(input_config.seed),
54+
)
55+
56+
+ if input_config.output_type == "pil":
57+
+ pipe.save("results", "stable_diffusion_3")
58+
59+
if __name__ == "__main__":
60+
main()
61+
62+
```
63+
64+
As you can see, we only need to use xFuserArgs from xDiT to get configuration parameters, and pass these parameters along with the pipeline object from the Diffusers library into xDiTParallel to complete the parallelization of a specific pipeline in Diffusers.
65+
66+
xDiT runtime parameters can be viewed in the command line using `-h`, and you can refer to this [usage](https://github.com/xdit-project/xDiT?tab=readme-ov-file#2-usage) example for more details.
67+
68+
xDiT needs to be launched using torchrun to support its multi-node, multi-GPU parallel capabilities. For example, the following command can be used for 8-GPU parallel inference:
69+
70+
```bash
71+
torchrun --nproc_per_node=8 ./inference.py --model models/FLUX.1-dev --data_parallel_degree 2 --ulysses_degree 2 --ring_degree 2 --prompt "A snowy mountain" "A small dog" --num_inference_steps 50
72+
```
73+
74+
## Supported models
75+
76+
A subset of Diffusers models are supported in xDiT, such as Flux.1, Stable Diffusion 3, etc. The latest supported models can be found [here](https://github.com/xdit-project/xDiT?tab=readme-ov-file#-supported-dits).
77+
78+
## Benchmark
79+
We tested different models on various machines, and here is some of the benchmark data.
80+
81+
82+
### Flux.1-schnell
83+
<div class="flex justify-center">
84+
<img src="https://github.com/xdit-project/xDiT/raw/main/assets/performance/flux/Flux-2k-L40.png">
85+
</div>
86+
87+
88+
<div class="flex justify-center">
89+
<img src="https://github.com/xdit-project/xDiT/raw/main/assets/performance/flux/Flux-2K-A100.png">
90+
</div>
91+
92+
### Stable Diffusion 3
93+
<div class="flex justify-center">
94+
<img src="https://github.com/xdit-project/xDiT/raw/main/assets/performance/sd3/L40-SD3.png">
95+
</div>
96+
97+
<div class="flex justify-center">
98+
<img src="https://github.com/xdit-project/xDiT/raw/main/assets/performance/sd3/A100-SD3.png">
99+
</div>
100+
101+
### HunyuanDiT
102+
<div class="flex justify-center">
103+
<img src="https://github.com/xdit-project/xDiT/raw/main/assets/performance/hunuyuandit/L40-HunyuanDiT.png">
104+
</div>
105+
106+
<div class="flex justify-center">
107+
<img src="https://github.com/xdit-project/xDiT/raw/main/assets/performance/hunuyuandit/A100-HunyuanDiT.png">
108+
</div>
109+
110+
<div class="flex justify-center">
111+
<img src="https://github.com/xdit-project/xDiT/raw/main/assets/performance/hunuyuandit/T4-HunyuanDiT.png">
112+
</div>
113+
114+
More detailed performance metric can be found on our [github page](https://github.com/xdit-project/xDiT?tab=readme-ov-file#perf).
115+
116+
## Reference
117+
118+
[xDiT-project](https://github.com/xdit-project/xDiT)
119+
120+
[USP: A Unified Sequence Parallelism Approach for Long Context Generative AI](https://arxiv.org/abs/2405.07719)
121+
122+
[PipeFusion: Displaced Patch Pipeline Parallelism for Inference of Diffusion Transformer Models](https://arxiv.org/abs/2405.14430)

0 commit comments

Comments
 (0)