xfuser 0.3__tar.gz → 0.3.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. {xfuser-0.3 → xfuser-0.3.2}/LICENSE.txt +1 -1
  2. {xfuser-0.3/xfuser.egg-info → xfuser-0.3.2}/PKG-INFO +152 -87
  3. xfuser-0.3/PKG-INFO → xfuser-0.3.2/README.md +141 -102
  4. xfuser-0.3.2/comfyui-xdit/__init__.py +2 -0
  5. xfuser-0.3.2/comfyui-xdit/host.py +253 -0
  6. xfuser-0.3.2/comfyui-xdit/launch_host.py +45 -0
  7. xfuser-0.3.2/comfyui-xdit/nodes.py +176 -0
  8. xfuser-0.3.2/comfyui-xdit/utils.py +7 -0
  9. {xfuser-0.3 → xfuser-0.3.2}/setup.py +26 -6
  10. {xfuser-0.3 → xfuser-0.3.2}/xfuser/__init__.py +5 -1
  11. xfuser-0.3.2/xfuser/__version__.py +1 -0
  12. {xfuser-0.3 → xfuser-0.3.2}/xfuser/config/args.py +26 -0
  13. {xfuser-0.3 → xfuser-0.3.2}/xfuser/config/config.py +21 -1
  14. {xfuser-0.3 → xfuser-0.3.2}/xfuser/core/cache_manager/cache_manager.py +16 -2
  15. {xfuser-0.3 → xfuser-0.3.2}/xfuser/core/distributed/runtime_state.py +161 -23
  16. {xfuser-0.3 → xfuser-0.3.2}/xfuser/core/long_ctx_attention/__init__.py +2 -0
  17. {xfuser-0.3 → xfuser-0.3.2}/xfuser/core/long_ctx_attention/hybrid/attn_layer.py +17 -10
  18. {xfuser-0.3 → xfuser-0.3.2}/xfuser/core/long_ctx_attention/ring/ring_flash_attn.py +4 -4
  19. xfuser-0.3.2/xfuser/core/long_ctx_attention/ulysses/__init__.py +5 -0
  20. xfuser-0.3.2/xfuser/core/long_ctx_attention/ulysses/attn_layer.py +160 -0
  21. {xfuser-0.3 → xfuser-0.3.2}/xfuser/envs.py +38 -39
  22. {xfuser-0.3 → xfuser-0.3.2}/xfuser/model_executor/layers/attention_processor.py +327 -218
  23. {xfuser-0.3 → xfuser-0.3.2}/xfuser/model_executor/layers/embeddings.py +56 -1
  24. {xfuser-0.3 → xfuser-0.3.2}/xfuser/model_executor/models/base_model.py +3 -4
  25. {xfuser-0.3 → xfuser-0.3.2}/xfuser/model_executor/models/transformers/__init__.py +2 -0
  26. xfuser-0.3.2/xfuser/model_executor/models/transformers/cogvideox_transformer_3d.py +125 -0
  27. {xfuser-0.3 → xfuser-0.3.2}/xfuser/model_executor/models/transformers/hunyuan_transformer_2d.py +2 -0
  28. {xfuser-0.3 → xfuser-0.3.2}/xfuser/model_executor/models/transformers/transformer_flux.py +39 -22
  29. {xfuser-0.3 → xfuser-0.3.2}/xfuser/model_executor/pipelines/__init__.py +2 -0
  30. {xfuser-0.3 → xfuser-0.3.2}/xfuser/model_executor/pipelines/base_pipeline.py +50 -21
  31. xfuser-0.3.2/xfuser/model_executor/pipelines/pipeline_cogvideox.py +423 -0
  32. {xfuser-0.3 → xfuser-0.3.2}/xfuser/model_executor/pipelines/pipeline_flux.py +15 -23
  33. {xfuser-0.3 → xfuser-0.3.2}/xfuser/model_executor/pipelines/pipeline_hunyuandit.py +6 -5
  34. {xfuser-0.3 → xfuser-0.3.2}/xfuser/model_executor/pipelines/pipeline_latte.py +12 -7
  35. {xfuser-0.3 → xfuser-0.3.2}/xfuser/model_executor/pipelines/pipeline_stable_diffusion_3.py +1 -0
  36. {xfuser-0.3 → xfuser-0.3.2}/xfuser/model_executor/schedulers/__init__.py +4 -0
  37. xfuser-0.3.2/xfuser/model_executor/schedulers/scheduling_ddim_cogvideox.py +57 -0
  38. xfuser-0.3.2/xfuser/model_executor/schedulers/scheduling_dpm_cogvideox.py +57 -0
  39. xfuser-0.3.2/xfuser/parallel.py +54 -0
  40. xfuser-0.3/README.md → xfuser-0.3.2/xfuser.egg-info/PKG-INFO +167 -81
  41. {xfuser-0.3 → xfuser-0.3.2}/xfuser.egg-info/SOURCES.txt +11 -1
  42. xfuser-0.3.2/xfuser.egg-info/requires.txt +14 -0
  43. xfuser-0.3.2/xfuser.egg-info/top_level.txt +2 -0
  44. xfuser-0.3/xfuser/__version__.py +0 -1
  45. xfuser-0.3/xfuser/model_executor/layers/transformers_blocks.py +0 -509
  46. xfuser-0.3/xfuser/parallel.py +0 -42
  47. xfuser-0.3/xfuser.egg-info/requires.txt +0 -8
  48. xfuser-0.3/xfuser.egg-info/top_level.txt +0 -1
  49. {xfuser-0.3 → xfuser-0.3.2}/setup.cfg +0 -0
  50. {xfuser-0.3 → xfuser-0.3.2}/xfuser/config/__init__.py +0 -0
  51. {xfuser-0.3 → xfuser-0.3.2}/xfuser/core/__init__.py +0 -0
  52. {xfuser-0.3 → xfuser-0.3.2}/xfuser/core/cache_manager/__init__.py +0 -0
  53. {xfuser-0.3 → xfuser-0.3.2}/xfuser/core/distributed/__init__.py +0 -0
  54. {xfuser-0.3 → xfuser-0.3.2}/xfuser/core/distributed/group_coordinator.py +0 -0
  55. {xfuser-0.3 → xfuser-0.3.2}/xfuser/core/distributed/parallel_state.py +0 -0
  56. {xfuser-0.3 → xfuser-0.3.2}/xfuser/core/distributed/utils.py +0 -0
  57. {xfuser-0.3 → xfuser-0.3.2}/xfuser/core/long_ctx_attention/hybrid/__init__.py +0 -0
  58. {xfuser-0.3 → xfuser-0.3.2}/xfuser/core/long_ctx_attention/hybrid/utils.py +0 -0
  59. {xfuser-0.3 → xfuser-0.3.2}/xfuser/core/long_ctx_attention/ring/__init__.py +0 -0
  60. {xfuser-0.3 → xfuser-0.3.2}/xfuser/core/utils/__init__.py +0 -0
  61. {xfuser-0.3 → xfuser-0.3.2}/xfuser/core/utils/timer.py +0 -0
  62. {xfuser-0.3 → xfuser-0.3.2}/xfuser/logger.py +0 -0
  63. {xfuser-0.3 → xfuser-0.3.2}/xfuser/model_executor/__init__.py +0 -0
  64. {xfuser-0.3 → xfuser-0.3.2}/xfuser/model_executor/base_wrapper.py +0 -0
  65. {xfuser-0.3 → xfuser-0.3.2}/xfuser/model_executor/layers/__init__.py +0 -0
  66. {xfuser-0.3 → xfuser-0.3.2}/xfuser/model_executor/layers/base_layer.py +0 -0
  67. {xfuser-0.3 → xfuser-0.3.2}/xfuser/model_executor/layers/conv.py +0 -0
  68. {xfuser-0.3 → xfuser-0.3.2}/xfuser/model_executor/layers/feedforward.py +0 -0
  69. {xfuser-0.3 → xfuser-0.3.2}/xfuser/model_executor/layers/register.py +0 -0
  70. {xfuser-0.3 → xfuser-0.3.2}/xfuser/model_executor/models/__init__.py +0 -0
  71. {xfuser-0.3 → xfuser-0.3.2}/xfuser/model_executor/models/transformers/base_transformer.py +0 -0
  72. {xfuser-0.3 → xfuser-0.3.2}/xfuser/model_executor/models/transformers/latte_transformer_3d.py +0 -0
  73. {xfuser-0.3 → xfuser-0.3.2}/xfuser/model_executor/models/transformers/pixart_transformer_2d.py +0 -0
  74. {xfuser-0.3 → xfuser-0.3.2}/xfuser/model_executor/models/transformers/register.py +0 -0
  75. {xfuser-0.3 → xfuser-0.3.2}/xfuser/model_executor/models/transformers/transformer_sd3.py +0 -0
  76. {xfuser-0.3 → xfuser-0.3.2}/xfuser/model_executor/pipelines/pipeline_pixart_alpha.py +0 -0
  77. {xfuser-0.3 → xfuser-0.3.2}/xfuser/model_executor/pipelines/pipeline_pixart_sigma.py +0 -0
  78. {xfuser-0.3 → xfuser-0.3.2}/xfuser/model_executor/pipelines/register.py +0 -0
  79. {xfuser-0.3 → xfuser-0.3.2}/xfuser/model_executor/schedulers/base_scheduler.py +0 -0
  80. {xfuser-0.3 → xfuser-0.3.2}/xfuser/model_executor/schedulers/register.py +0 -0
  81. {xfuser-0.3 → xfuser-0.3.2}/xfuser/model_executor/schedulers/scheduling_ddim.py +0 -0
  82. {xfuser-0.3 → xfuser-0.3.2}/xfuser/model_executor/schedulers/scheduling_ddpm.py +0 -0
  83. {xfuser-0.3 → xfuser-0.3.2}/xfuser/model_executor/schedulers/scheduling_dpmsolver_multistep.py +0 -0
  84. {xfuser-0.3 → xfuser-0.3.2}/xfuser/model_executor/schedulers/scheduling_flow_match_euler_discrete.py +0 -0
  85. {xfuser-0.3 → xfuser-0.3.2}/xfuser.egg-info/dependency_links.txt +0 -0
@@ -187,7 +187,7 @@
187
187
  same "printed page" as the copyright notice for easier
188
188
  identification within third-party archives.
189
189
 
190
- Copyright [2024] [PipeFusion Team]
190
+ Copyright [2024] [xDiT Team]
191
191
 
192
192
  Licensed under the Apache License, Version 2.0 (the "License");
193
193
  you may not use this file except in compliance with the License.
@@ -1,23 +1,28 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: xfuser
3
- Version: 0.3
3
+ Version: 0.3.2
4
4
  Summary: xDiT: A Scalable Inference Engine for Diffusion Transformers (DiTs) on multi-GPU Clusters
5
5
  Home-page: https://github.com/xdit-project/xDiT.
6
- Author: Jiannan Wang, Jiarui Fang, Jinzhe Pan, Aoyu Li
6
+ Author: xDiT Team
7
7
  Author-email: fangjiarui123@gmail.com
8
8
  Classifier: Programming Language :: Python :: 3
9
9
  Classifier: Operating System :: OS Independent
10
10
  Requires-Python: >=3.10
11
11
  Description-Content-Type: text/markdown
12
12
  License-File: LICENSE.txt
13
- Requires-Dist: torch>=2.3.0
14
- Requires-Dist: diffusers>=0.30.0
13
+ Requires-Dist: torch>=2.1.0
14
+ Requires-Dist: accelerate>=0.33.0
15
+ Requires-Dist: diffusers>=0.30.3
15
16
  Requires-Dist: transformers>=4.39.1
16
17
  Requires-Dist: sentencepiece>=0.1.99
17
- Requires-Dist: accelerate==0.33.0
18
18
  Requires-Dist: beautifulsoup4>=4.12.3
19
19
  Requires-Dist: distvae
20
- Requires-Dist: ftfy>=6.2.0
20
+ Requires-Dist: yunchang>=0.3.0
21
+ Requires-Dist: pytest
22
+ Requires-Dist: flask
23
+ Requires-Dist: opencv-python
24
+ Provides-Extra: flash-attn
25
+ Requires-Dist: flash_attn>=2.6.3; extra == "flash-attn"
21
26
 
22
27
  <div align="center">
23
28
  <!-- <h1>KTransformers</h1> -->
@@ -25,12 +30,15 @@ Requires-Dist: ftfy>=6.2.0
25
30
 
26
31
  <picture>
27
32
  <img alt="xDiT" src="./assets/XDiTlogo.png" width=50%>
28
-
29
33
  </picture>
30
34
 
31
35
  </p>
32
36
  <h3>A Scalable Inference Engine for Diffusion Transformers (DiTs) on multi-GPU Clusters</h3>
33
37
  <strong><a href="https://arxiv.org/abs/2405.14430">📃 Paper</a> | <a href="#QuickStart">🚀 Quick Start</a> | <a href="#support-dits">🎯 Supported DiTs</a> | <a href="#dev-guide">📚 Dev Guide </a> | <a href="https://github.com/xdit-project/xDiT/discussions">📈 Discussion </a> </strong>
38
+ <p></p>
39
+
40
+ [![](https://dcbadge.limes.pink/api/server/https://discord.gg/YEWzWfCF9S)](https://discord.gg/YEWzWfCF9S)
41
+
34
42
  </div>
35
43
 
36
44
  <h2 id="agenda">Table of Contents</h2>
@@ -39,13 +47,20 @@ Requires-Dist: ftfy>=6.2.0
39
47
  - [📢 Updates](#updates)
40
48
  - [🎯 Supported DiTs](#support-dits)
41
49
  - [📈 Performance](#perf)
50
+ - [Flux.1](#perf_flux)
51
+ - [HunyuanDiT](#perf_hunyuandit)
52
+ - [SD3](#perf_sd3)
53
+ - [Pixart](#perf_pixart)
54
+ - [Latte](#perf_latte)
42
55
  - [🚀 QuickStart](#QuickStart)
43
- - [✨ the xDiT's secret weapons](#secrets)
44
- - [1. PipeFusion](#PipeFusion)
45
- - [2. Unified Sequence Parallel](#USP)
46
- - [3. Hybrid Parallel](#hybrid_parallel)
47
- - [4. CFG Parallel](#cfg_parallel)
48
- - [5. Parallel VAE](#parallel_vae)
56
+ - [✨ xDiT's Arsenal](#secrets)
57
+ - [Parallel Methods](#parallel)
58
+ - [1. PipeFusion](#PipeFusion)
59
+ - [2. Unified Sequence Parallel](#USP)
60
+ - [3. Hybrid Parallel](#hybrid_parallel)
61
+ - [4. CFG Parallel](#cfg_parallel)
62
+ - [5. Parallel VAE](#parallel_vae)
63
+ - [Compilation Acceleration](#compilation)
49
64
  - [📚 Develop Guide](#dev-guide)
50
65
  - [🚧 History and Looking for Contributions](#history)
51
66
  - [📝 Cite Us](#cite-us)
@@ -53,13 +68,14 @@ Requires-Dist: ftfy>=6.2.0
53
68
 
54
69
  <h2 id="meet-xdit">🔥 Meet xDiT</h2>
55
70
 
56
- Diffusion Transformers (DiTs), pivotal in text-to-image and text-to-video models, are driving advancements in high-quality image and video generation.
57
- With the escalating input sequence length in DiTs, the computational demand of the Attention mechanism grows **quadratically**!
58
- Consequently, multi-GPU and multi-machine deployments are essential to maintain real-time performance in online services.
71
+ Diffusion Transformers (DiTs) are driving advancements in high-quality image and video generation.
72
+ With the escalating input context length in DiTs, the computational demand of the Attention mechanism grows **quadratically**!
73
+ Consequently, multi-GPU and multi-machine deployments are essential to meet the **real-time** requirements in online services.
59
74
 
60
75
  To meet real-time demand for DiTs applications, parallel inference is a must.
61
76
  xDiT is an inference engine designed for the parallel deployment of DiTs on large scale.
62
- xDiT provides a suite of efficient parallel inference approaches for Diffusion Models.
77
+ xDiT provides a suite of efficient parallel approaches for Diffusion Models, as well as GPU kernel accelerations.
78
+
63
79
 
64
80
  1. Sequence Parallelism, [USP](https://arxiv.org/abs/2405.07719) is a unified sequence parallel approach combining DeepSpeed-Ulysses, Ring-Attention.
65
81
 
@@ -74,44 +90,26 @@ The four parallel methods in xDiT can be configured in a hybrid manner, optimizi
74
90
  As shown in the following picture, xDiT offers a set of APIs to adapt DiT models in [huggingface/diffusers](https://github.com/huggingface/diffusers) to hybrid parallel implementation through simple wrappers.
75
91
  If the model you require is not available in the model zoo, developing it yourself is straightforward; please refer to our [Dev Guide](#dev-guide).
76
92
 
77
- <div align="center">
78
- <img src="assets/methods/xdit_method.png" alt="xdit methods">
79
- </div>
80
-
81
93
  We also have implemented the following parallel stategies for reference:
82
94
 
83
95
  1. Tensor Parallelism
84
96
  2. [DistriFusion](https://arxiv.org/abs/2402.19481)
85
97
 
86
- The communication and memory costs associated with the aforementioned parallelism, except for the CFG and DP, in DiTs are detailed in the table below. (* denotes that communication can be overlapped with computation.)
87
-
88
98
 
89
- As we can see, PipeFusion and Sequence Parallel achieve lowest communication cost on different scales and hardware configurations, making them suitable foundational components for a hybrid approach.
90
-
91
- 𝒑: Number of pixels;
92
- 𝒉𝒔: Model hidden size;
93
- 𝑳: Number of model layers;
94
- 𝑷: Total model parameters;
95
- 𝑵: Number of parallel devices;
96
- 𝑴: Number of patch splits;
97
- 𝑸𝑶: Query and Output parameter count;
98
- 𝑲𝑽: KV Activation parameter count;
99
- 𝑨 = 𝑸 = 𝑶 = 𝑲 = 𝑽: Equal parameters for Attention, Query, Output, Key, and Value;
99
+ Optimization orthogonal to parallelization focuses on accelerating single GPU performance.
100
+ In addition to utilizing well-known Attention optimization libraries, we leverage compilation acceleration technologies such as `torch.compile` and `onediff`.
100
101
 
101
- <div align="center">
102
+ The overview of xDiT is shown as follows.
102
103
 
103
- | | attn-KV | communication cost | param memory | activations memory | extra buff memory |
104
- |:--------:|:-------:|:-----------------:|:-----:|:-----------:|:----------:|
105
- | Tensor Parallel | fresh | $4O(p \times hs)L$ | $\frac{1}{N}P$ | $\frac{2}{N}A = \frac{1}{N}QO$ | $\frac{2}{N}A = \frac{1}{N}KV$ |
106
- | DistriFusion* | stale | $2O(p \times hs)L$ | $P$ | $\frac{2}{N}A = \frac{1}{N}QO$ | $2AL = (KV)L$ |
107
- | Ring Sequence Parallel* | fresh | $2O(p \times hs)L$ | $P$ | $\frac{2}{N}A = \frac{1}{N}QO$ | $\frac{2}{N}A = \frac{1}{N}KV$ |
108
- | Ulysses Sequence Parallel | fresh | $\frac{4}{N}O(p \times hs)L$ | $P$ | $\frac{2}{N}A = \frac{1}{N}QO$ | $\frac{2}{N}A = \frac{1}{N}KV$ |
109
- | PipeFusion* | stale- | $2O(p \times hs)$ | $\frac{1}{N}P$ | $\frac{2}{M}A = \frac{1}{M}QO$ | $\frac{2L}{N}A = \frac{1}{N}(KV)L$ |
104
+ <picture>
105
+ <img alt="xDiT" src="./assets/methods/xdit_overview.png">
106
+ </picture>
110
107
 
111
- </div>
112
108
 
113
109
  <h2 id="updates">📢 Updates</h2>
114
110
 
111
+ * ⚙️**August 30, 2024**: Supporting(WIP) CogVideoX. The inference scripts are [examples/latte_example](examples/cogvideox_example.py).
112
+ * 🎉**August 26, 2024**: We apply torch.compile and [onediff](https://github.com/siliconflow/onediff) nexfort backend to accelerate GPU kernels speed.
115
113
  * 🎉**August 9, 2024**: Support Latte sequence parallel version. The inference scripts are [examples/latte_example](examples/latte_example.py).
116
114
  * 🎉**August 8, 2024**: Support Flux sequence parallel version. The inference scripts are [examples/flux_example](examples/flux_example.py).
117
115
  * 🎉**August 2, 2024**: Support Stable Diffusion 3 hybrid parallel version. The inference scripts are [examples/sd3_example](examples/sd3_example.py).
@@ -124,8 +122,11 @@ As we can see, PipeFusion and Sequence Parallel achieve lowest communication cos
124
122
 
125
123
  <h2 id="support-dits">🎯 Supported DiTs</h2>
126
124
 
125
+ <div align="center">
126
+
127
127
  | Model Name | CFG | SP | PipeFusion |
128
128
  | --- | --- | --- | --- |
129
+ | [🎬 CogVideoX](https://huggingface.co/THUDM/CogVideoX-2b) | ❎ | ❎ | ❎ |
129
130
  | [🎬 Latte](https://huggingface.co/maxin-cn/Latte-1) | ❎ | ✔️ | ❎ |
130
131
  | [🔵 HunyuanDiT-v1.2-Diffusers](https://huggingface.co/Tencent-Hunyuan/HunyuanDiT-v1.2-Diffusers) | ✔️ | ✔️ | ✔️ |
131
132
  | [🟠 Flux](https://huggingface.co/black-forest-labs/FLUX.1-schnell) | NA | ✔️ | ❎ |
@@ -133,64 +134,64 @@ As we can see, PipeFusion and Sequence Parallel achieve lowest communication cos
133
134
  | [🟢 PixArt-alpha](https://huggingface.co/PixArt-alpha/PixArt-alpha) | ✔️ | ✔️ | ✔️ |
134
135
  | [🟠 Stable Diffusion 3](https://huggingface.co/stabilityai/stable-diffusion-3-medium-diffusers) | ✔️ | ✔️ | ✔️ |
135
136
 
136
- ### Supported by legacy version only:
137
+ </div>
138
+
139
+ ### Supported by legacy version only, including DistriFusion and Tensor Parallel as the standalong parallel strategies:
137
140
 
138
- - [🔴 DiT-XL](https://huggingface.co/facebook/DiT-XL-2-256)
141
+ <div align="center">
142
+
143
+ [🔴 DiT-XL](https://huggingface.co/facebook/DiT-XL-2-256)
144
+ </div>
139
145
 
140
146
  <h2 id="perf">📈 Performance</h2>
141
147
 
142
- Here are the benchmark results for Pixart-Alpha using the 20-step DPM solver as the scheduler across various image resolutions. To replicate these findings, please refer to the script at [./legacy/scripts/benchmark.sh](./legacy/scripts/benchmark.sh).
148
+ <h3 id="perf_flux">Flux.1</h3>
143
149
 
144
- **TBD**: Updates results on hybrid parallelism.
150
+ 1. [Flux Performance Report](./docs/performance/flux.md)
145
151
 
146
- 1. The Latency on 4xA100-80GB (PCIe)
152
+ <h3 id="perf_hunyuandit">HunyuanDiT</h3>
147
153
 
148
- <div align="center">
149
- <img src="./assets/latency-A100-PCIe.png" alt="A100 PCIe latency">
150
- </div>
154
+ 2. [HunyuanDiT Performance Report](./docs/performance/hunyuandit.md)
151
155
 
152
- 2. The Latency on 8xL20-48GB (PCIe)
156
+ <h3 id="perf_sd3">SD3</h3>
153
157
 
154
- <div align="center">
155
- <img src="./assets/latency-L20.png" alt="L20 latency">
156
- </div>
158
+ 3. [Stable Diffusion 3 Performance Report](./docs/performance/sd3.md)
157
159
 
158
- 3. The Latency on 8xA100-80GB (NVLink)
160
+ <h3 id="perf_pixart">Pixart</h3>
159
161
 
160
- <div align="center">
161
- <img src="./assets/latency-A100-NVLink.png" alt="latency-A100-NVLink">
162
- </div>
162
+ 4. [Pixart-Alpha Performance Report (legacy)](./docs/performance/pixart_alpha_legacy.md)
163
163
 
164
- 4. The Latency on 4xT4-16GB (PCIe)
164
+ <h3 id="perf_latte">Pixart</h3>
165
165
 
166
- <div align="center">
167
- <img src="./assets/latency-T4.png"
168
- alt="latency-T4">
169
- </div>
166
+ 5. [Latte Performance Report](./docs/performance/latte.md)
170
167
 
171
168
 
172
169
  <h2 id="QuickStart">🚀 QuickStart</h2>
173
170
 
174
- ### 1. Install from pip
171
+ ### 1. Install from pip (current [version](./xfuser/__version__.py))
175
172
 
176
173
  ```
177
174
  pip install xfuser
175
+ # Or optionally, with flash_attn
176
+ pip install "xfuser[flash_attn]"
178
177
  ```
179
178
 
180
179
  ### 2. Install from source
181
180
 
182
- #### 2.1 Install yunchang for sequence parallel.
181
+ ```
182
+ pip install -e .
183
+ # Or optionally, with flash_attn
184
+ pip install -e ".[flash_attn]"
185
+ ```
183
186
 
184
- Install yunchang from [feifeibear/long-context-attention](https://github.com/feifeibear/long-context-attention).
185
- Please note that it has a dependency on flash attention and specific GPU model requirements. We recommend installing yunchang from the source code rather than using `pip install yunchang==0.2.0`.
187
+ Note that we use two self-maintained packages:
186
188
 
187
- #### 2.2 Install xDiT
189
+ 1. [yunchang](https://github.com/feifeibear/long-context-attention)
190
+ 2. [DistVAE](https://github.com/xdit-project/DistVAE)
188
191
 
189
- ```
190
- python setup.py install
191
- ```
192
+ The [flash_attn](https://github.com/Dao-AILab/flash-attention) used for yunchang should be >= 2.6.0
192
193
 
193
- ### 2. Usage
194
+ ### 3. Usage
194
195
 
195
196
  We provide examples demonstrating how to run models with xDiT in the [./examples/](./examples/) directory.
196
197
  You can easily modify the model type, model directory, and parallel options in the [examples/run.sh](examples/run.sh) within the script to run some already supported DiT models.
@@ -221,13 +222,15 @@ Runtime Options:
221
222
  --warmup_steps WARMUP_STEPS
222
223
  Warmup steps in generation.
223
224
  --use_parallel_vae
225
+ --use_torch_compile Enable torch.compile to accelerate inference in a single card
224
226
  --seed SEED Random seed for operations.
225
227
  --output_type OUTPUT_TYPE
226
228
  Output type of the pipeline.
229
+ --enable_sequential_cpu_offload
230
+ Offloading the weights to the CPU.
227
231
 
228
232
  Parallel Processing Options:
229
- --do_classifier_free_guidance
230
- --use_split_batch Use split batch in classifier_free_guidance. cfg_degree will be 2 if set
233
+ --use_cfg_parallel Use split batch in classifier_free_guidance. cfg_degree will be 2 if set
231
234
  --data_parallel_degree DATA_PARALLEL_DEGREE
232
235
  Data parallel degree.
233
236
  --ulysses_degree ULYSSES_DEGREE
@@ -275,37 +278,99 @@ examples/pixartalpha_example.py \
275
278
  --use_cfg_parallel
276
279
  ```
277
280
 
278
-
279
281
  ⚠️ Applying PipeFusion requires setting `warmup_steps`, also required in DistriFusion, typically set to a small number compared with `num_inference_steps`.
280
282
  The warmup step impacts the efficiency of PipeFusion as it cannot be executed in parallel, thus degrading to a serial execution.
281
283
  We observed that a warmup of 0 had no effect on the PixArt model.
282
284
  Users can tune this value according to their specific tasks.
283
285
 
284
286
 
285
- <h2 id="secrets">✨ The xDiT's Secret Weapons</h2>
286
287
 
287
- The exceptional capabilities of xDiT stem from our innovative technologies.
288
+ ### 4. Launch a Http Service
289
+
290
+ [Launching a Text-to-Image Http Service](./docs/developer/Http_Service.md)
291
+
292
+ ### 5. Launch ComfyUI
293
+
294
+ [Launching ComfyUI](./docs/developer/ComfyUI_xdit.md)
295
+
296
+
297
+ <h2 id="secrets">✨ The xDiT's Arsenal</h2>
298
+
299
+ The remarkable performance of xDiT is attributed to two key facets.
300
+ Firstly, it leverages parallelization techniques, pioneering innovations such as USP, PipeFusion, and hybrid parallelism, to scale DiTs inference to unprecedented scales.
301
+
302
+ Secondly, we employ compilation technologies to enhance execution on GPUs, integrating established solutions like `torch.compile` and `onediff` to optimize xDiT's performance.
303
+
304
+ <h3 id="parallel">1. Parallel Methods</h3>
305
+
306
+ As illustrated in the accompanying images, xDiTs offer a comprehensive set of parallelization techniques. For the DiT backbone, the foundational methods—Data, USP, PipeFusion, and CFG parallel—operate in a hybrid fashion. Additionally, the distinct methods, Tensor and DistriFusion parallel, function independently.
307
+ For the VAE module, xDiT offers a parallel implementation, [DistVAE](https://github.com/xdit-project/DistVAE), designed to prevent out-of-memory (OOM) issues.
308
+ The (<span style="color: red;">xDiT</span>) highlights the methods first proposed by use.
309
+
310
+ <div align="center">
311
+ <img src="assets/methods/xdit_method.png" alt="xdit methods">
312
+ </div>
313
+
314
+ The communication and memory costs associated with the aforementioned intra-image parallelism, except for the CFG and DP (they are inter-image parallel), in DiTs are detailed in the table below. (* denotes that communication can be overlapped with computation.)
288
315
 
289
- <h3 id="PipeFusion">1. PipeFusion</h3>
316
+ As we can see, PipeFusion and Sequence Parallel achieve lowest communication cost on different scales and hardware configurations, making them suitable foundational components for a hybrid approach.
317
+
318
+ 𝒑: Number of pixels;
319
+ 𝒉𝒔: Model hidden size;
320
+ 𝑳: Number of model layers;
321
+ 𝑷: Total model parameters;
322
+ 𝑵: Number of parallel devices;
323
+ 𝑴: Number of patch splits;
324
+ 𝑸𝑶: Query and Output parameter count;
325
+ 𝑲𝑽: KV Activation parameter count;
326
+ 𝑨 = 𝑸 = 𝑶 = 𝑲 = 𝑽: Equal parameters for Attention, Query, Output, Key, and Value;
327
+
328
+ <div align="center">
329
+
330
+ | | attn-KV | communication cost | param memory | activations memory | extra buff memory |
331
+ |:--------:|:-------:|:-----------------:|:-----:|:-----------:|:----------:|
332
+ | Tensor Parallel | fresh | $4O(p \times hs)L$ | $\frac{1}{N}P$ | $\frac{2}{N}A = \frac{1}{N}QO$ | $\frac{2}{N}A = \frac{1}{N}KV$ |
333
+ | DistriFusion* | stale | $2O(p \times hs)L$ | $P$ | $\frac{2}{N}A = \frac{1}{N}QO$ | $2AL = (KV)L$ |
334
+ | Ring Sequence Parallel* | fresh | $2O(p \times hs)L$ | $P$ | $\frac{2}{N}A = \frac{1}{N}QO$ | $\frac{2}{N}A = \frac{1}{N}KV$ |
335
+ | Ulysses Sequence Parallel | fresh | $\frac{4}{N}O(p \times hs)L$ | $P$ | $\frac{2}{N}A = \frac{1}{N}QO$ | $\frac{2}{N}A = \frac{1}{N}KV$ |
336
+ | PipeFusion* | stale- | $2O(p \times hs)$ | $\frac{1}{N}P$ | $\frac{2}{M}A = \frac{1}{M}QO$ | $\frac{2L}{N}A = \frac{1}{N}(KV)L$ |
337
+
338
+ </div>
339
+
340
+ <h4 id="PipeFusion">1.1. PipeFusion</h4>
290
341
 
291
342
  [PipeFusion: Displaced Patch Pipeline Parallelism for Diffusion Models](./docs/methods/pipefusion.md)
292
343
 
293
- <h3 id="USP">2. USP: Unified Sequence Parallelism</h3>
344
+ <h4 id="USP">1.2. USP: Unified Sequence Parallelism</h4>
294
345
 
295
346
  [USP: A Unified Sequence Parallelism Approach for Long Context Generative AI](./docs/methods/usp.md)
296
347
 
297
- <h3 id="hybrid_parallel">3. Hybrid Parallel</h3>
348
+ <h4 id="hybrid_parallel">1.3. Hybrid Parallel</h4>
298
349
 
299
350
  [Hybrid Parallelism](./docs/methods/hybrid.md)
300
351
 
301
- <h3 id="cfg_parallel">4. CFG Parallel</h3>
352
+ <h4 id="cfg_parallel">1.4. CFG Parallel</h4>
302
353
 
303
354
  [CFG Parallel](./docs/methods/cfg_parallel.md)
304
355
 
305
- <h3 id="parallel_vae">5. Parallel VAE</h3>
356
+ <h4 id="parallel_vae">1.5. Parallel VAE</h4>
306
357
 
307
358
  [Patch Parallel VAE](./docs/methods/parallel_vae.md)
308
359
 
360
+ <h3 id="compilation">Compilation Acceleration</h3>
361
+
362
+ We utilize two compilation acceleration techniques, [torch.compile](https://pytorch.org/tutorials/intermediate/torch_compile_tutorial.html) and [onediff](https://github.com/siliconflow/onediff), to enhance runtime speed on GPUs. These compilation accelerations are used in conjunction with parallelization methods.
363
+
364
+ We employ the nexfort backend of onediff. Please install it before use:
365
+
366
+ ```
367
+ pip install onediff
368
+ pip install -U nexfort
369
+ ```
370
+
371
+ For usage instructions, refer to the [example/run.sh](./examples/run.sh). Simply append `--use_torch_compile` or `--use_onediff` to your command. Note that these options are mutually exclusive, and their performance varies across different scenarios.
372
+
373
+
309
374
  <h2 id="dev-guide">📚 Develop Guide</h2>
310
375
 
311
376
  [The implement and design of xdit framework](./docs/developer/The_implement_design_of_xdit_framework.md)
@@ -337,10 +402,10 @@ We also welcome developers to join and contribute more features and models to th
337
402
  }
338
403
 
339
404
  @article{fang2024unified,
340
- title={USP: a Unified Sequence Parallelism Approach for Long Context Generative AI},
341
- author={Fang, Jiarui and Zhao, Shangchun},
342
- journal={arXiv preprint arXiv:2405.07719},
343
- year={2024}
405
+ title={USP: a Unified Sequence Parallelism Approach for Long Context Generative AI},
406
+ author={Fang, Jiarui and Zhao, Shangchun},
407
+ journal={arXiv preprint arXiv:2405.07719},
408
+ year={2024}
344
409
  }
345
410
  ```
346
411