xfuser 0.2__tar.gz → 0.3__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.
- {xfuser-0.2/xfuser.egg-info → xfuser-0.3}/PKG-INFO +43 -19
- xfuser-0.2/PKG-INFO → xfuser-0.3/README.md +36 -33
- {xfuser-0.2 → xfuser-0.3}/setup.py +6 -6
- {xfuser-0.2 → xfuser-0.3}/xfuser/__init__.py +5 -1
- xfuser-0.3/xfuser/__version__.py +1 -0
- xfuser-0.3/xfuser/config/args.py +291 -0
- {xfuser-0.2 → xfuser-0.3}/xfuser/config/config.py +78 -67
- xfuser-0.3/xfuser/core/__init__.py +15 -0
- xfuser-0.3/xfuser/core/cache_manager/__init__.py +5 -0
- xfuser-0.3/xfuser/core/cache_manager/cache_manager.py +214 -0
- {xfuser-0.2/xfuser → xfuser-0.3/xfuser/core}/distributed/__init__.py +12 -3
- {xfuser-0.2/xfuser → xfuser-0.3/xfuser/core}/distributed/group_coordinator.py +458 -197
- {xfuser-0.2/xfuser → xfuser-0.3/xfuser/core}/distributed/parallel_state.py +197 -253
- {xfuser-0.2/xfuser → xfuser-0.3/xfuser/core}/distributed/runtime_state.py +136 -77
- xfuser-0.3/xfuser/core/distributed/utils.py +188 -0
- xfuser-0.3/xfuser/core/long_ctx_attention/__init__.py +11 -0
- xfuser-0.3/xfuser/core/long_ctx_attention/hybrid/__init__.py +11 -0
- xfuser-0.3/xfuser/core/long_ctx_attention/hybrid/attn_layer.py +320 -0
- xfuser-0.3/xfuser/core/long_ctx_attention/hybrid/utils.py +11 -0
- xfuser-0.3/xfuser/core/long_ctx_attention/ring/__init__.py +5 -0
- xfuser-0.3/xfuser/core/long_ctx_attention/ring/ring_flash_attn.py +187 -0
- xfuser-0.3/xfuser/core/utils/__init__.py +1 -0
- xfuser-0.3/xfuser/core/utils/timer.py +19 -0
- {xfuser-0.2 → xfuser-0.3}/xfuser/model_executor/base_wrapper.py +18 -6
- {xfuser-0.2 → xfuser-0.3}/xfuser/model_executor/layers/__init__.py +2 -0
- {xfuser-0.2 → xfuser-0.3}/xfuser/model_executor/layers/attention_processor.py +507 -212
- {xfuser-0.2 → xfuser-0.3}/xfuser/model_executor/layers/conv.py +18 -8
- {xfuser-0.2 → xfuser-0.3}/xfuser/model_executor/layers/embeddings.py +15 -7
- xfuser-0.3/xfuser/model_executor/layers/feedforward.py +69 -0
- xfuser-0.3/xfuser/model_executor/layers/transformers_blocks.py +509 -0
- {xfuser-0.2 → xfuser-0.3}/xfuser/model_executor/models/base_model.py +40 -13
- {xfuser-0.2 → xfuser-0.3}/xfuser/model_executor/models/transformers/__init__.py +4 -0
- {xfuser-0.2 → xfuser-0.3}/xfuser/model_executor/models/transformers/base_transformer.py +18 -8
- xfuser-0.3/xfuser/model_executor/models/transformers/hunyuan_transformer_2d.py +262 -0
- xfuser-0.3/xfuser/model_executor/models/transformers/latte_transformer_3d.py +250 -0
- {xfuser-0.2 → xfuser-0.3}/xfuser/model_executor/models/transformers/pixart_transformer_2d.py +42 -21
- {xfuser-0.2 → xfuser-0.3}/xfuser/model_executor/models/transformers/transformer_flux.py +47 -23
- {xfuser-0.2 → xfuser-0.3}/xfuser/model_executor/models/transformers/transformer_sd3.py +61 -29
- {xfuser-0.2 → xfuser-0.3}/xfuser/model_executor/pipelines/__init__.py +4 -0
- {xfuser-0.2 → xfuser-0.3}/xfuser/model_executor/pipelines/base_pipeline.py +110 -34
- {xfuser-0.2 → xfuser-0.3}/xfuser/model_executor/pipelines/pipeline_flux.py +62 -58
- xfuser-0.3/xfuser/model_executor/pipelines/pipeline_hunyuandit.py +919 -0
- xfuser-0.3/xfuser/model_executor/pipelines/pipeline_latte.py +375 -0
- {xfuser-0.2 → xfuser-0.3}/xfuser/model_executor/pipelines/pipeline_pixart_alpha.py +9 -5
- {xfuser-0.2 → xfuser-0.3}/xfuser/model_executor/pipelines/pipeline_pixart_sigma.py +9 -5
- {xfuser-0.2 → xfuser-0.3}/xfuser/model_executor/pipelines/pipeline_stable_diffusion_3.py +15 -24
- {xfuser-0.2 → xfuser-0.3}/xfuser/model_executor/schedulers/__init__.py +4 -0
- {xfuser-0.2 → xfuser-0.3}/xfuser/model_executor/schedulers/base_scheduler.py +14 -7
- xfuser-0.3/xfuser/model_executor/schedulers/scheduling_ddim.py +62 -0
- xfuser-0.3/xfuser/model_executor/schedulers/scheduling_ddpm.py +53 -0
- {xfuser-0.2 → xfuser-0.3}/xfuser/model_executor/schedulers/scheduling_dpmsolver_multistep.py +54 -22
- {xfuser-0.2 → xfuser-0.3}/xfuser/model_executor/schedulers/scheduling_flow_match_euler_discrete.py +14 -8
- {xfuser-0.2 → xfuser-0.3}/xfuser/parallel.py +7 -17
- xfuser-0.2/README.md → xfuser-0.3/xfuser.egg-info/PKG-INFO +57 -12
- {xfuser-0.2 → xfuser-0.3}/xfuser.egg-info/SOURCES.txt +25 -7
- xfuser-0.3/xfuser.egg-info/requires.txt +8 -0
- xfuser-0.2/xfuser/__version__.py +0 -1
- xfuser-0.2/xfuser/config/args.py +0 -198
- xfuser-0.2/xfuser/modules/__init__.py +0 -0
- xfuser-0.2/xfuser/modules/long_context_attention.py +0 -396
- xfuser-0.2/xfuser.egg-info/requires.txt +0 -8
- {xfuser-0.2 → xfuser-0.3}/LICENSE.txt +0 -0
- {xfuser-0.2 → xfuser-0.3}/setup.cfg +0 -0
- {xfuser-0.2 → xfuser-0.3}/xfuser/config/__init__.py +0 -0
- {xfuser-0.2 → xfuser-0.3}/xfuser/envs.py +0 -0
- {xfuser-0.2 → xfuser-0.3}/xfuser/logger.py +0 -0
- {xfuser-0.2 → xfuser-0.3}/xfuser/model_executor/__init__.py +0 -0
- {xfuser-0.2 → xfuser-0.3}/xfuser/model_executor/layers/base_layer.py +0 -0
- {xfuser-0.2 → xfuser-0.3}/xfuser/model_executor/layers/register.py +0 -0
- {xfuser-0.2 → xfuser-0.3}/xfuser/model_executor/models/__init__.py +0 -0
- {xfuser-0.2 → xfuser-0.3}/xfuser/model_executor/models/transformers/register.py +0 -0
- {xfuser-0.2 → xfuser-0.3}/xfuser/model_executor/pipelines/register.py +0 -0
- {xfuser-0.2 → xfuser-0.3}/xfuser/model_executor/schedulers/register.py +0 -0
- {xfuser-0.2 → xfuser-0.3}/xfuser.egg-info/dependency_links.txt +0 -0
- {xfuser-0.2 → xfuser-0.3}/xfuser.egg-info/top_level.txt +0 -0
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: xfuser
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3
|
|
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: Jiannan Wang, Jiarui Fang, Jinzhe Pan, Aoyu Li
|
|
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.
|
|
13
|
+
Requires-Dist: torch>=2.3.0
|
|
14
14
|
Requires-Dist: diffusers>=0.30.0
|
|
15
|
-
Requires-Dist: transformers
|
|
16
|
-
Requires-Dist: sentencepiece
|
|
15
|
+
Requires-Dist: transformers>=4.39.1
|
|
16
|
+
Requires-Dist: sentencepiece>=0.1.99
|
|
17
17
|
Requires-Dist: accelerate==0.33.0
|
|
18
|
-
Requires-Dist: beautifulsoup4
|
|
18
|
+
Requires-Dist: beautifulsoup4>=4.12.3
|
|
19
19
|
Requires-Dist: distvae
|
|
20
|
-
Requires-Dist: ftfy
|
|
20
|
+
Requires-Dist: ftfy>=6.2.0
|
|
21
21
|
|
|
22
22
|
<div align="center">
|
|
23
23
|
<!-- <h1>KTransformers</h1> -->
|
|
@@ -42,7 +42,7 @@ Requires-Dist: ftfy
|
|
|
42
42
|
- [🚀 QuickStart](#QuickStart)
|
|
43
43
|
- [✨ the xDiT's secret weapons](#secrets)
|
|
44
44
|
- [1. PipeFusion](#PipeFusion)
|
|
45
|
-
- [2.
|
|
45
|
+
- [2. Unified Sequence Parallel](#USP)
|
|
46
46
|
- [3. Hybrid Parallel](#hybrid_parallel)
|
|
47
47
|
- [4. CFG Parallel](#cfg_parallel)
|
|
48
48
|
- [5. Parallel VAE](#parallel_vae)
|
|
@@ -71,9 +71,12 @@ xDiT provides a suite of efficient parallel inference approaches for Diffusion M
|
|
|
71
71
|
|
|
72
72
|
The four parallel methods in xDiT can be configured in a hybrid manner, optimizing communication patterns to best suit the underlying network hardware.
|
|
73
73
|
|
|
74
|
-
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.
|
|
74
|
+
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
75
|
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
76
|
|
|
77
|
+
<div align="center">
|
|
78
|
+
<img src="assets/methods/xdit_method.png" alt="xdit methods">
|
|
79
|
+
</div>
|
|
77
80
|
|
|
78
81
|
We also have implemented the following parallel stategies for reference:
|
|
79
82
|
|
|
@@ -109,6 +112,7 @@ As we can see, PipeFusion and Sequence Parallel achieve lowest communication cos
|
|
|
109
112
|
|
|
110
113
|
<h2 id="updates">📢 Updates</h2>
|
|
111
114
|
|
|
115
|
+
* 🎉**August 9, 2024**: Support Latte sequence parallel version. The inference scripts are [examples/latte_example](examples/latte_example.py).
|
|
112
116
|
* 🎉**August 8, 2024**: Support Flux sequence parallel version. The inference scripts are [examples/flux_example](examples/flux_example.py).
|
|
113
117
|
* 🎉**August 2, 2024**: Support Stable Diffusion 3 hybrid parallel version. The inference scripts are [examples/sd3_example](examples/sd3_example.py).
|
|
114
118
|
* 🎉**July 18, 2024**: Support PixArt-Sigma and PixArt-Alpha. The inference scripts are [examples/pixartsigma_example.py](examples/pixartsigma_example.py), [examples/pixartalpha_example.py](examples/pixartalpha_example.py).
|
|
@@ -120,13 +124,18 @@ As we can see, PipeFusion and Sequence Parallel achieve lowest communication cos
|
|
|
120
124
|
|
|
121
125
|
<h2 id="support-dits">🎯 Supported DiTs</h2>
|
|
122
126
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
127
|
+
| Model Name | CFG | SP | PipeFusion |
|
|
128
|
+
| --- | --- | --- | --- |
|
|
129
|
+
| [🎬 Latte](https://huggingface.co/maxin-cn/Latte-1) | ❎ | ✔️ | ❎ |
|
|
130
|
+
| [🔵 HunyuanDiT-v1.2-Diffusers](https://huggingface.co/Tencent-Hunyuan/HunyuanDiT-v1.2-Diffusers) | ✔️ | ✔️ | ✔️ |
|
|
131
|
+
| [🟠 Flux](https://huggingface.co/black-forest-labs/FLUX.1-schnell) | NA | ✔️ | ❎ |
|
|
132
|
+
| [🔴 PixArt-Sigma](https://huggingface.co/PixArt-alpha/PixArt-Sigma-XL-2-1024-MS) | ✔️ | ✔️ | ✔️ |
|
|
133
|
+
| [🟢 PixArt-alpha](https://huggingface.co/PixArt-alpha/PixArt-alpha) | ✔️ | ✔️ | ✔️ |
|
|
134
|
+
| [🟠 Stable Diffusion 3](https://huggingface.co/stabilityai/stable-diffusion-3-medium-diffusers) | ✔️ | ✔️ | ✔️ |
|
|
129
135
|
|
|
136
|
+
### Supported by legacy version only:
|
|
137
|
+
|
|
138
|
+
- [🔴 DiT-XL](https://huggingface.co/facebook/DiT-XL-2-256)
|
|
130
139
|
|
|
131
140
|
<h2 id="perf">📈 Performance</h2>
|
|
132
141
|
|
|
@@ -162,18 +171,26 @@ Here are the benchmark results for Pixart-Alpha using the 20-step DPM solver as
|
|
|
162
171
|
|
|
163
172
|
<h2 id="QuickStart">🚀 QuickStart</h2>
|
|
164
173
|
|
|
165
|
-
1. Install
|
|
174
|
+
### 1. Install from pip
|
|
175
|
+
|
|
176
|
+
```
|
|
177
|
+
pip install xfuser
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
### 2. Install from source
|
|
181
|
+
|
|
182
|
+
#### 2.1 Install yunchang for sequence parallel.
|
|
166
183
|
|
|
167
184
|
Install yunchang from [feifeibear/long-context-attention](https://github.com/feifeibear/long-context-attention).
|
|
168
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`.
|
|
169
186
|
|
|
170
|
-
2. Install xDiT
|
|
187
|
+
#### 2.2 Install xDiT
|
|
171
188
|
|
|
172
189
|
```
|
|
173
190
|
python setup.py install
|
|
174
191
|
```
|
|
175
192
|
|
|
176
|
-
|
|
193
|
+
### 2. Usage
|
|
177
194
|
|
|
178
195
|
We provide examples demonstrating how to run models with xDiT in the [./examples/](./examples/) directory.
|
|
179
196
|
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.
|
|
@@ -255,7 +272,7 @@ examples/pixartalpha_example.py \
|
|
|
255
272
|
--num_inference_steps 20 \
|
|
256
273
|
--warmup_steps 0 \
|
|
257
274
|
--prompt "A small dog" \
|
|
258
|
-
--
|
|
275
|
+
--use_cfg_parallel
|
|
259
276
|
```
|
|
260
277
|
|
|
261
278
|
|
|
@@ -318,5 +335,12 @@ We also welcome developers to join and contribute more features and models to th
|
|
|
318
335
|
archivePrefix={arXiv},
|
|
319
336
|
primaryClass={cs.CV}
|
|
320
337
|
}
|
|
338
|
+
|
|
339
|
+
@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}
|
|
344
|
+
}
|
|
321
345
|
```
|
|
322
346
|
|
|
@@ -1,24 +1,3 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: xfuser
|
|
3
|
-
Version: 0.2
|
|
4
|
-
Summary: xDiT: A Scalable Inference Engine for Diffusion Transformers (DiTs) on multi-GPU Clusters
|
|
5
|
-
Home-page: https://github.com/xdit-project/xDiT.
|
|
6
|
-
Author: Jiannan Wang, Jiarui Fang, Jinzhe Pan, Aoyu Li, Pengcheng Yang
|
|
7
|
-
Author-email: fangjiarui123@gmail.com
|
|
8
|
-
Classifier: Programming Language :: Python :: 3
|
|
9
|
-
Classifier: Operating System :: OS Independent
|
|
10
|
-
Requires-Python: >=3.10
|
|
11
|
-
Description-Content-Type: text/markdown
|
|
12
|
-
License-File: LICENSE.txt
|
|
13
|
-
Requires-Dist: torch>=2.2
|
|
14
|
-
Requires-Dist: diffusers>=0.30.0
|
|
15
|
-
Requires-Dist: transformers
|
|
16
|
-
Requires-Dist: sentencepiece
|
|
17
|
-
Requires-Dist: accelerate==0.33.0
|
|
18
|
-
Requires-Dist: beautifulsoup4
|
|
19
|
-
Requires-Dist: distvae
|
|
20
|
-
Requires-Dist: ftfy
|
|
21
|
-
|
|
22
1
|
<div align="center">
|
|
23
2
|
<!-- <h1>KTransformers</h1> -->
|
|
24
3
|
<p align="center">
|
|
@@ -42,7 +21,7 @@ Requires-Dist: ftfy
|
|
|
42
21
|
- [🚀 QuickStart](#QuickStart)
|
|
43
22
|
- [✨ the xDiT's secret weapons](#secrets)
|
|
44
23
|
- [1. PipeFusion](#PipeFusion)
|
|
45
|
-
- [2.
|
|
24
|
+
- [2. Unified Sequence Parallel](#USP)
|
|
46
25
|
- [3. Hybrid Parallel](#hybrid_parallel)
|
|
47
26
|
- [4. CFG Parallel](#cfg_parallel)
|
|
48
27
|
- [5. Parallel VAE](#parallel_vae)
|
|
@@ -71,9 +50,12 @@ xDiT provides a suite of efficient parallel inference approaches for Diffusion M
|
|
|
71
50
|
|
|
72
51
|
The four parallel methods in xDiT can be configured in a hybrid manner, optimizing communication patterns to best suit the underlying network hardware.
|
|
73
52
|
|
|
74
|
-
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.
|
|
53
|
+
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
54
|
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
55
|
|
|
56
|
+
<div align="center">
|
|
57
|
+
<img src="assets/methods/xdit_method.png" alt="xdit methods">
|
|
58
|
+
</div>
|
|
77
59
|
|
|
78
60
|
We also have implemented the following parallel stategies for reference:
|
|
79
61
|
|
|
@@ -109,6 +91,7 @@ As we can see, PipeFusion and Sequence Parallel achieve lowest communication cos
|
|
|
109
91
|
|
|
110
92
|
<h2 id="updates">📢 Updates</h2>
|
|
111
93
|
|
|
94
|
+
* 🎉**August 9, 2024**: Support Latte sequence parallel version. The inference scripts are [examples/latte_example](examples/latte_example.py).
|
|
112
95
|
* 🎉**August 8, 2024**: Support Flux sequence parallel version. The inference scripts are [examples/flux_example](examples/flux_example.py).
|
|
113
96
|
* 🎉**August 2, 2024**: Support Stable Diffusion 3 hybrid parallel version. The inference scripts are [examples/sd3_example](examples/sd3_example.py).
|
|
114
97
|
* 🎉**July 18, 2024**: Support PixArt-Sigma and PixArt-Alpha. The inference scripts are [examples/pixartsigma_example.py](examples/pixartsigma_example.py), [examples/pixartalpha_example.py](examples/pixartalpha_example.py).
|
|
@@ -120,13 +103,18 @@ As we can see, PipeFusion and Sequence Parallel achieve lowest communication cos
|
|
|
120
103
|
|
|
121
104
|
<h2 id="support-dits">🎯 Supported DiTs</h2>
|
|
122
105
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
106
|
+
| Model Name | CFG | SP | PipeFusion |
|
|
107
|
+
| --- | --- | --- | --- |
|
|
108
|
+
| [🎬 Latte](https://huggingface.co/maxin-cn/Latte-1) | ❎ | ✔️ | ❎ |
|
|
109
|
+
| [🔵 HunyuanDiT-v1.2-Diffusers](https://huggingface.co/Tencent-Hunyuan/HunyuanDiT-v1.2-Diffusers) | ✔️ | ✔️ | ✔️ |
|
|
110
|
+
| [🟠 Flux](https://huggingface.co/black-forest-labs/FLUX.1-schnell) | NA | ✔️ | ❎ |
|
|
111
|
+
| [🔴 PixArt-Sigma](https://huggingface.co/PixArt-alpha/PixArt-Sigma-XL-2-1024-MS) | ✔️ | ✔️ | ✔️ |
|
|
112
|
+
| [🟢 PixArt-alpha](https://huggingface.co/PixArt-alpha/PixArt-alpha) | ✔️ | ✔️ | ✔️ |
|
|
113
|
+
| [🟠 Stable Diffusion 3](https://huggingface.co/stabilityai/stable-diffusion-3-medium-diffusers) | ✔️ | ✔️ | ✔️ |
|
|
129
114
|
|
|
115
|
+
### Supported by legacy version only:
|
|
116
|
+
|
|
117
|
+
- [🔴 DiT-XL](https://huggingface.co/facebook/DiT-XL-2-256)
|
|
130
118
|
|
|
131
119
|
<h2 id="perf">📈 Performance</h2>
|
|
132
120
|
|
|
@@ -162,18 +150,26 @@ Here are the benchmark results for Pixart-Alpha using the 20-step DPM solver as
|
|
|
162
150
|
|
|
163
151
|
<h2 id="QuickStart">🚀 QuickStart</h2>
|
|
164
152
|
|
|
165
|
-
1. Install
|
|
153
|
+
### 1. Install from pip
|
|
154
|
+
|
|
155
|
+
```
|
|
156
|
+
pip install xfuser
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
### 2. Install from source
|
|
160
|
+
|
|
161
|
+
#### 2.1 Install yunchang for sequence parallel.
|
|
166
162
|
|
|
167
163
|
Install yunchang from [feifeibear/long-context-attention](https://github.com/feifeibear/long-context-attention).
|
|
168
164
|
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`.
|
|
169
165
|
|
|
170
|
-
2. Install xDiT
|
|
166
|
+
#### 2.2 Install xDiT
|
|
171
167
|
|
|
172
168
|
```
|
|
173
169
|
python setup.py install
|
|
174
170
|
```
|
|
175
171
|
|
|
176
|
-
|
|
172
|
+
### 2. Usage
|
|
177
173
|
|
|
178
174
|
We provide examples demonstrating how to run models with xDiT in the [./examples/](./examples/) directory.
|
|
179
175
|
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.
|
|
@@ -255,7 +251,7 @@ examples/pixartalpha_example.py \
|
|
|
255
251
|
--num_inference_steps 20 \
|
|
256
252
|
--warmup_steps 0 \
|
|
257
253
|
--prompt "A small dog" \
|
|
258
|
-
--
|
|
254
|
+
--use_cfg_parallel
|
|
259
255
|
```
|
|
260
256
|
|
|
261
257
|
|
|
@@ -318,5 +314,12 @@ We also welcome developers to join and contribute more features and models to th
|
|
|
318
314
|
archivePrefix={arXiv},
|
|
319
315
|
primaryClass={cs.CV}
|
|
320
316
|
}
|
|
317
|
+
|
|
318
|
+
@article{fang2024unified,
|
|
319
|
+
title={USP: a Unified Sequence Parallelism Approach for Long Context Generative AI},
|
|
320
|
+
author={Fang, Jiarui and Zhao, Shangchun},
|
|
321
|
+
journal={arXiv preprint arXiv:2405.07719},
|
|
322
|
+
year={2024}
|
|
323
|
+
}
|
|
321
324
|
```
|
|
322
325
|
|
|
@@ -10,18 +10,18 @@ if __name__ == "__main__":
|
|
|
10
10
|
|
|
11
11
|
setup(
|
|
12
12
|
name="xfuser",
|
|
13
|
-
author="Jiannan Wang, Jiarui Fang, Jinzhe Pan, Aoyu Li
|
|
13
|
+
author="Jiannan Wang, Jiarui Fang, Jinzhe Pan, Aoyu Li",
|
|
14
14
|
author_email="fangjiarui123@gmail.com",
|
|
15
15
|
packages=find_packages(),
|
|
16
16
|
install_requires=[
|
|
17
|
-
"torch>=2.
|
|
17
|
+
"torch>=2.3.0",
|
|
18
18
|
"diffusers>=0.30.0",
|
|
19
|
-
"transformers",
|
|
20
|
-
"sentencepiece",
|
|
19
|
+
"transformers>=4.39.1",
|
|
20
|
+
"sentencepiece>=0.1.99",
|
|
21
21
|
"accelerate==0.33.0",
|
|
22
|
-
"beautifulsoup4",
|
|
22
|
+
"beautifulsoup4>=4.12.3",
|
|
23
23
|
"distvae",
|
|
24
|
-
"ftfy",
|
|
24
|
+
"ftfy>=6.2.0",
|
|
25
25
|
],
|
|
26
26
|
url="https://github.com/xdit-project/xDiT.",
|
|
27
27
|
description="xDiT: A Scalable Inference Engine for Diffusion Transformers (DiTs) on multi-GPU Clusters",
|
|
@@ -2,7 +2,9 @@ from xfuser.model_executor.pipelines import (
|
|
|
2
2
|
xFuserPixArtAlphaPipeline,
|
|
3
3
|
xFuserPixArtSigmaPipeline,
|
|
4
4
|
xFuserStableDiffusion3Pipeline,
|
|
5
|
-
xFuserFluxPipeline
|
|
5
|
+
xFuserFluxPipeline,
|
|
6
|
+
xFuserLattePipeline,
|
|
7
|
+
xFuserHunyuanDiTPipeline,
|
|
6
8
|
)
|
|
7
9
|
from xfuser.config import xFuserArgs, EngineConfig
|
|
8
10
|
|
|
@@ -11,6 +13,8 @@ __all__ = [
|
|
|
11
13
|
"xFuserPixArtSigmaPipeline",
|
|
12
14
|
"xFuserStableDiffusion3Pipeline",
|
|
13
15
|
"xFuserFluxPipeline",
|
|
16
|
+
"xFuserLattePipeline",
|
|
17
|
+
"xFuserHunyuanDiTPipeline",
|
|
14
18
|
"xFuserArgs",
|
|
15
19
|
"EngineConfig",
|
|
16
20
|
]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.3"
|
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
import argparse
|
|
3
|
+
import dataclasses
|
|
4
|
+
from dataclasses import dataclass
|
|
5
|
+
from typing import Optional, List, Tuple, Union
|
|
6
|
+
|
|
7
|
+
import torch
|
|
8
|
+
import torch.distributed
|
|
9
|
+
|
|
10
|
+
from xfuser.logger import init_logger
|
|
11
|
+
from xfuser.core.distributed import init_distributed_environment
|
|
12
|
+
from xfuser.config.config import (
|
|
13
|
+
EngineConfig,
|
|
14
|
+
ParallelConfig,
|
|
15
|
+
TensorParallelConfig,
|
|
16
|
+
PipeFusionParallelConfig,
|
|
17
|
+
SequenceParallelConfig,
|
|
18
|
+
DataParallelConfig,
|
|
19
|
+
ModelConfig,
|
|
20
|
+
InputConfig,
|
|
21
|
+
RuntimeConfig,
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
logger = init_logger(__name__)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class FlexibleArgumentParser(argparse.ArgumentParser):
|
|
28
|
+
"""ArgumentParser that allows both underscore and dash in names."""
|
|
29
|
+
|
|
30
|
+
def parse_args(self, args=None, namespace=None):
|
|
31
|
+
if args is None:
|
|
32
|
+
args = sys.argv[1:]
|
|
33
|
+
|
|
34
|
+
# Convert underscores to dashes and vice versa in argument names
|
|
35
|
+
processed_args = []
|
|
36
|
+
for arg in args:
|
|
37
|
+
if arg.startswith("--"):
|
|
38
|
+
if "=" in arg:
|
|
39
|
+
key, value = arg.split("=", 1)
|
|
40
|
+
key = "--" + key[len("--") :].replace("-", "_")
|
|
41
|
+
processed_args.append(f"{key}={value}")
|
|
42
|
+
else:
|
|
43
|
+
processed_args.append("--" + arg[len("--") :].replace("-", "_"))
|
|
44
|
+
else:
|
|
45
|
+
processed_args.append(arg)
|
|
46
|
+
|
|
47
|
+
return super().parse_args(processed_args, namespace)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def nullable_str(val: str):
|
|
51
|
+
if not val or val == "None":
|
|
52
|
+
return None
|
|
53
|
+
return val
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
@dataclass
|
|
57
|
+
class xFuserArgs:
|
|
58
|
+
"""Arguments for xFuser engine."""
|
|
59
|
+
|
|
60
|
+
# Model arguments
|
|
61
|
+
model: str
|
|
62
|
+
download_dir: Optional[str] = None
|
|
63
|
+
trust_remote_code: bool = False
|
|
64
|
+
# Runtime arguments
|
|
65
|
+
warmup_steps: int = 1
|
|
66
|
+
# use_cuda_graph: bool = True
|
|
67
|
+
use_parallel_vae: bool = False
|
|
68
|
+
# use_profiler: bool = False
|
|
69
|
+
use_torch_compile: bool = False
|
|
70
|
+
# Parallel arguments
|
|
71
|
+
# data parallel
|
|
72
|
+
data_parallel_degree: int = 1
|
|
73
|
+
use_cfg_parallel: bool = False
|
|
74
|
+
# sequence parallel
|
|
75
|
+
ulysses_degree: Optional[int] = None
|
|
76
|
+
ring_degree: Optional[int] = None
|
|
77
|
+
# tensor parallel
|
|
78
|
+
tensor_parallel_degree: int = 1
|
|
79
|
+
split_scheme: Optional[str] = "row"
|
|
80
|
+
# pipefusion parallel
|
|
81
|
+
pipefusion_parallel_degree: int = 1
|
|
82
|
+
num_pipeline_patch: Optional[int] = None
|
|
83
|
+
attn_layer_num_for_pp: Optional[List[int]] = None
|
|
84
|
+
# Input arguments
|
|
85
|
+
height: int = 1024
|
|
86
|
+
width: int = 1024
|
|
87
|
+
num_inference_steps: int = 20
|
|
88
|
+
prompt: Union[str, List[str]] = ""
|
|
89
|
+
negative_prompt: Union[str, List[str]] = ""
|
|
90
|
+
no_use_resolution_binning: bool = False
|
|
91
|
+
seed: int = 42
|
|
92
|
+
output_type: str = "pil"
|
|
93
|
+
|
|
94
|
+
@staticmethod
|
|
95
|
+
def add_cli_args(parser: FlexibleArgumentParser):
|
|
96
|
+
"""Shared CLI arguments for xFuser engine."""
|
|
97
|
+
# Model arguments
|
|
98
|
+
model_group = parser.add_argument_group("Model Options")
|
|
99
|
+
model_group.add_argument(
|
|
100
|
+
"--model",
|
|
101
|
+
type=str,
|
|
102
|
+
default="PixArt-alpha/PixArt-XL-2-1024-MS",
|
|
103
|
+
help="Name or path of the huggingface model to use.",
|
|
104
|
+
)
|
|
105
|
+
model_group.add_argument(
|
|
106
|
+
"--download-dir",
|
|
107
|
+
type=nullable_str,
|
|
108
|
+
default=xFuserArgs.download_dir,
|
|
109
|
+
help="Directory to download and load the weights, default to the default cache dir of huggingface.",
|
|
110
|
+
)
|
|
111
|
+
model_group.add_argument(
|
|
112
|
+
"--trust-remote-code",
|
|
113
|
+
action="store_true",
|
|
114
|
+
help="Trust remote code from huggingface.",
|
|
115
|
+
)
|
|
116
|
+
|
|
117
|
+
# Runtime arguments
|
|
118
|
+
runtime_group = parser.add_argument_group("Runtime Options")
|
|
119
|
+
runtime_group.add_argument(
|
|
120
|
+
"--warmup_steps", type=int, default=1, help="Warmup steps in generation."
|
|
121
|
+
)
|
|
122
|
+
# runtime_group.add_argument("--use_cuda_graph", action="store_true")
|
|
123
|
+
runtime_group.add_argument("--use_parallel_vae", action="store_true")
|
|
124
|
+
# runtime_group.add_argument("--use_profiler", action="store_true")
|
|
125
|
+
runtime_group.add_argument(
|
|
126
|
+
"--use_torch_compile",
|
|
127
|
+
action="store_true",
|
|
128
|
+
help="Enable torch.compile to accelerate inference in a single card",
|
|
129
|
+
)
|
|
130
|
+
|
|
131
|
+
# Parallel arguments
|
|
132
|
+
parallel_group = parser.add_argument_group("Parallel Processing Options")
|
|
133
|
+
parallel_group.add_argument(
|
|
134
|
+
"--use_cfg_parallel",
|
|
135
|
+
action="store_true",
|
|
136
|
+
help="Use split batch in classifier_free_guidance. cfg_degree will be 2 if set",
|
|
137
|
+
)
|
|
138
|
+
parallel_group.add_argument(
|
|
139
|
+
"--data_parallel_degree", type=int, default=1, help="Data parallel degree."
|
|
140
|
+
)
|
|
141
|
+
parallel_group.add_argument(
|
|
142
|
+
"--ulysses_degree",
|
|
143
|
+
type=int,
|
|
144
|
+
default=None,
|
|
145
|
+
help="Ulysses sequence parallel degree. Used in attention layer.",
|
|
146
|
+
)
|
|
147
|
+
parallel_group.add_argument(
|
|
148
|
+
"--ring_degree",
|
|
149
|
+
type=int,
|
|
150
|
+
default=None,
|
|
151
|
+
help="Ring sequence parallel degree. Used in attention layer.",
|
|
152
|
+
)
|
|
153
|
+
parallel_group.add_argument(
|
|
154
|
+
"--pipefusion_parallel_degree",
|
|
155
|
+
type=int,
|
|
156
|
+
default=1,
|
|
157
|
+
help="Pipefusion parallel degree. Indicates the number of pipeline stages.",
|
|
158
|
+
)
|
|
159
|
+
parallel_group.add_argument(
|
|
160
|
+
"--num_pipeline_patch",
|
|
161
|
+
type=int,
|
|
162
|
+
default=None,
|
|
163
|
+
help="Number of patches the feature map should be segmented in pipefusion parallel.",
|
|
164
|
+
)
|
|
165
|
+
parallel_group.add_argument(
|
|
166
|
+
"--attn_layer_num_for_pp",
|
|
167
|
+
default=None,
|
|
168
|
+
nargs="*",
|
|
169
|
+
type=int,
|
|
170
|
+
help="List representing the number of layers per stage of the pipeline in pipefusion parallel",
|
|
171
|
+
)
|
|
172
|
+
parallel_group.add_argument(
|
|
173
|
+
"--tensor_parallel_degree",
|
|
174
|
+
type=int,
|
|
175
|
+
default=1,
|
|
176
|
+
help="Tensor parallel degree.",
|
|
177
|
+
)
|
|
178
|
+
parallel_group.add_argument(
|
|
179
|
+
"--split_scheme",
|
|
180
|
+
type=str,
|
|
181
|
+
default="row",
|
|
182
|
+
help="Split scheme for tensor parallel.",
|
|
183
|
+
)
|
|
184
|
+
|
|
185
|
+
# Input arguments
|
|
186
|
+
input_group = parser.add_argument_group("Input Options")
|
|
187
|
+
input_group.add_argument(
|
|
188
|
+
"--height", type=int, default=1024, help="The height of image"
|
|
189
|
+
)
|
|
190
|
+
input_group.add_argument(
|
|
191
|
+
"--width", type=int, default=1024, help="The width of image"
|
|
192
|
+
)
|
|
193
|
+
input_group.add_argument(
|
|
194
|
+
"--prompt", type=str, nargs="*", default="", help="Prompt for the model."
|
|
195
|
+
)
|
|
196
|
+
input_group.add_argument("--no_use_resolution_binning", action="store_true")
|
|
197
|
+
input_group.add_argument(
|
|
198
|
+
"--negative_prompt",
|
|
199
|
+
type=str,
|
|
200
|
+
nargs="*",
|
|
201
|
+
default="",
|
|
202
|
+
help="Negative prompt for the model.",
|
|
203
|
+
)
|
|
204
|
+
input_group.add_argument(
|
|
205
|
+
"--num_inference_steps",
|
|
206
|
+
type=int,
|
|
207
|
+
default=20,
|
|
208
|
+
help="Number of inference steps.",
|
|
209
|
+
)
|
|
210
|
+
runtime_group.add_argument(
|
|
211
|
+
"--seed", type=int, default=42, help="Random seed for operations."
|
|
212
|
+
)
|
|
213
|
+
runtime_group.add_argument(
|
|
214
|
+
"--output_type",
|
|
215
|
+
type=str,
|
|
216
|
+
default="pil",
|
|
217
|
+
help="Output type of the pipeline.",
|
|
218
|
+
)
|
|
219
|
+
|
|
220
|
+
return parser
|
|
221
|
+
|
|
222
|
+
@classmethod
|
|
223
|
+
def from_cli_args(cls, args: argparse.Namespace):
|
|
224
|
+
# Get the list of attributes of this dataclass.
|
|
225
|
+
attrs = [attr.name for attr in dataclasses.fields(cls)]
|
|
226
|
+
# Set the attributes from the parsed arguments.
|
|
227
|
+
engine_args = cls(**{attr: getattr(args, attr) for attr in attrs})
|
|
228
|
+
return engine_args
|
|
229
|
+
|
|
230
|
+
def create_config(
|
|
231
|
+
self,
|
|
232
|
+
) -> Tuple[EngineConfig, InputConfig]:
|
|
233
|
+
if not torch.distributed.is_initialized():
|
|
234
|
+
logger.warning(
|
|
235
|
+
"Distributed environment is not initialized. " "Initializing..."
|
|
236
|
+
)
|
|
237
|
+
init_distributed_environment()
|
|
238
|
+
|
|
239
|
+
model_config = ModelConfig(
|
|
240
|
+
model=self.model,
|
|
241
|
+
download_dir=self.download_dir,
|
|
242
|
+
trust_remote_code=self.trust_remote_code,
|
|
243
|
+
)
|
|
244
|
+
|
|
245
|
+
runtime_config = RuntimeConfig(
|
|
246
|
+
warmup_steps=self.warmup_steps,
|
|
247
|
+
# use_cuda_graph=self.use_cuda_graph,
|
|
248
|
+
use_parallel_vae=self.use_parallel_vae,
|
|
249
|
+
use_torch_compile=self.use_torch_compile,
|
|
250
|
+
# use_profiler=self.use_profiler,
|
|
251
|
+
)
|
|
252
|
+
|
|
253
|
+
parallel_config = ParallelConfig(
|
|
254
|
+
dp_config=DataParallelConfig(
|
|
255
|
+
dp_degree=self.data_parallel_degree,
|
|
256
|
+
use_cfg_parallel=self.use_cfg_parallel,
|
|
257
|
+
),
|
|
258
|
+
sp_config=SequenceParallelConfig(
|
|
259
|
+
ulysses_degree=self.ulysses_degree,
|
|
260
|
+
ring_degree=self.ring_degree,
|
|
261
|
+
),
|
|
262
|
+
tp_config=TensorParallelConfig(
|
|
263
|
+
tp_degree=self.tensor_parallel_degree,
|
|
264
|
+
split_scheme=self.split_scheme,
|
|
265
|
+
),
|
|
266
|
+
pp_config=PipeFusionParallelConfig(
|
|
267
|
+
pp_degree=self.pipefusion_parallel_degree,
|
|
268
|
+
num_pipeline_patch=self.num_pipeline_patch,
|
|
269
|
+
attn_layer_num_for_pp=self.attn_layer_num_for_pp,
|
|
270
|
+
),
|
|
271
|
+
)
|
|
272
|
+
|
|
273
|
+
engine_config = EngineConfig(
|
|
274
|
+
model_config=model_config,
|
|
275
|
+
runtime_config=runtime_config,
|
|
276
|
+
parallel_config=parallel_config,
|
|
277
|
+
)
|
|
278
|
+
|
|
279
|
+
input_config = InputConfig(
|
|
280
|
+
height=self.height,
|
|
281
|
+
width=self.width,
|
|
282
|
+
use_resolution_binning=not self.no_use_resolution_binning,
|
|
283
|
+
batch_size=len(self.prompt) if isinstance(self.prompt, list) else 1,
|
|
284
|
+
prompt=self.prompt,
|
|
285
|
+
negative_prompt=self.negative_prompt,
|
|
286
|
+
num_inference_steps=self.num_inference_steps,
|
|
287
|
+
seed=self.seed,
|
|
288
|
+
output_type=self.output_type,
|
|
289
|
+
)
|
|
290
|
+
|
|
291
|
+
return engine_config, input_config
|