xfuser 0.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 (52) hide show
  1. xfuser-0.2/LICENSE.txt +202 -0
  2. xfuser-0.2/PKG-INFO +322 -0
  3. xfuser-0.2/README.md +301 -0
  4. xfuser-0.2/setup.cfg +4 -0
  5. xfuser-0.2/setup.py +37 -0
  6. xfuser-0.2/xfuser/__init__.py +16 -0
  7. xfuser-0.2/xfuser/__version__.py +1 -0
  8. xfuser-0.2/xfuser/config/__init__.py +26 -0
  9. xfuser-0.2/xfuser/config/args.py +198 -0
  10. xfuser-0.2/xfuser/config/config.py +222 -0
  11. xfuser-0.2/xfuser/distributed/__init__.py +52 -0
  12. xfuser-0.2/xfuser/distributed/group_coordinator.py +817 -0
  13. xfuser-0.2/xfuser/distributed/parallel_state.py +503 -0
  14. xfuser-0.2/xfuser/distributed/runtime_state.py +328 -0
  15. xfuser-0.2/xfuser/envs.py +134 -0
  16. xfuser-0.2/xfuser/logger.py +99 -0
  17. xfuser-0.2/xfuser/model_executor/__init__.py +0 -0
  18. xfuser-0.2/xfuser/model_executor/base_wrapper.py +40 -0
  19. xfuser-0.2/xfuser/model_executor/layers/__init__.py +13 -0
  20. xfuser-0.2/xfuser/model_executor/layers/attention_processor.py +748 -0
  21. xfuser-0.2/xfuser/model_executor/layers/base_layer.py +40 -0
  22. xfuser-0.2/xfuser/model_executor/layers/conv.py +159 -0
  23. xfuser-0.2/xfuser/model_executor/layers/embeddings.py +98 -0
  24. xfuser-0.2/xfuser/model_executor/layers/register.py +52 -0
  25. xfuser-0.2/xfuser/model_executor/models/__init__.py +5 -0
  26. xfuser-0.2/xfuser/model_executor/models/base_model.py +111 -0
  27. xfuser-0.2/xfuser/model_executor/models/transformers/__init__.py +13 -0
  28. xfuser-0.2/xfuser/model_executor/models/transformers/base_transformer.py +123 -0
  29. xfuser-0.2/xfuser/model_executor/models/transformers/pixart_transformer_2d.py +202 -0
  30. xfuser-0.2/xfuser/model_executor/models/transformers/register.py +58 -0
  31. xfuser-0.2/xfuser/model_executor/models/transformers/transformer_flux.py +180 -0
  32. xfuser-0.2/xfuser/model_executor/models/transformers/transformer_sd3.py +167 -0
  33. xfuser-0.2/xfuser/model_executor/pipelines/__init__.py +13 -0
  34. xfuser-0.2/xfuser/model_executor/pipelines/base_pipeline.py +289 -0
  35. xfuser-0.2/xfuser/model_executor/pipelines/pipeline_flux.py +501 -0
  36. xfuser-0.2/xfuser/model_executor/pipelines/pipeline_pixart_alpha.py +665 -0
  37. xfuser-0.2/xfuser/model_executor/pipelines/pipeline_pixart_sigma.py +625 -0
  38. xfuser-0.2/xfuser/model_executor/pipelines/pipeline_stable_diffusion_3.py +779 -0
  39. xfuser-0.2/xfuser/model_executor/pipelines/register.py +63 -0
  40. xfuser-0.2/xfuser/model_executor/schedulers/__init__.py +15 -0
  41. xfuser-0.2/xfuser/model_executor/schedulers/base_scheduler.py +43 -0
  42. xfuser-0.2/xfuser/model_executor/schedulers/register.py +50 -0
  43. xfuser-0.2/xfuser/model_executor/schedulers/scheduling_dpmsolver_multistep.py +169 -0
  44. xfuser-0.2/xfuser/model_executor/schedulers/scheduling_flow_match_euler_discrete.py +121 -0
  45. xfuser-0.2/xfuser/modules/__init__.py +0 -0
  46. xfuser-0.2/xfuser/modules/long_context_attention.py +396 -0
  47. xfuser-0.2/xfuser/parallel.py +52 -0
  48. xfuser-0.2/xfuser.egg-info/PKG-INFO +322 -0
  49. xfuser-0.2/xfuser.egg-info/SOURCES.txt +50 -0
  50. xfuser-0.2/xfuser.egg-info/dependency_links.txt +1 -0
  51. xfuser-0.2/xfuser.egg-info/requires.txt +8 -0
  52. xfuser-0.2/xfuser.egg-info/top_level.txt +1 -0
xfuser-0.2/LICENSE.txt ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [2024] [PipeFusion Team]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
xfuser-0.2/PKG-INFO ADDED
@@ -0,0 +1,322 @@
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
+ <div align="center">
23
+ <!-- <h1>KTransformers</h1> -->
24
+ <p align="center">
25
+
26
+ <picture>
27
+ <img alt="xDiT" src="./assets/XDiTlogo.png" width=50%>
28
+
29
+ </picture>
30
+
31
+ </p>
32
+ <h3>A Scalable Inference Engine for Diffusion Transformers (DiTs) on multi-GPU Clusters</h3>
33
+ <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>
34
+ </div>
35
+
36
+ <h2 id="agenda">Table of Contents</h2>
37
+
38
+ - [🔥 Meet xDiT](#meet-xdit)
39
+ - [📢 Updates](#updates)
40
+ - [🎯 Supported DiTs](#support-dits)
41
+ - [📈 Performance](#perf)
42
+ - [🚀 QuickStart](#QuickStart)
43
+ - [✨ the xDiT's secret weapons](#secrets)
44
+ - [1. PipeFusion](#PipeFusion)
45
+ - [2. USP](#USP)
46
+ - [3. Hybrid Parallel](#hybrid_parallel)
47
+ - [4. CFG Parallel](#cfg_parallel)
48
+ - [5. Parallel VAE](#parallel_vae)
49
+ - [📚 Develop Guide](#dev-guide)
50
+ - [🚧 History and Looking for Contributions](#history)
51
+ - [📝 Cite Us](#cite-us)
52
+
53
+
54
+ <h2 id="meet-xdit">🔥 Meet xDiT</h2>
55
+
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.
59
+
60
+ To meet real-time demand for DiTs applications, parallel inference is a must.
61
+ 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.
63
+
64
+ 1. Sequence Parallelism, [USP](https://arxiv.org/abs/2405.07719) is a unified sequence parallel approach combining DeepSpeed-Ulysses, Ring-Attention.
65
+
66
+ 2. [PipeFusion](https://arxiv.org/abs/2405.14430), a patch level pipeline parallelism using displaced patch by taking advantage of the diffusion model characteristics.
67
+
68
+ 3. Data Parallel: Processes multiple prompts or generates multiple images from a single prompt in parallel across images.
69
+
70
+ 4. CFG Parallel, also known as Split Batch: Activates when using classifier-free guidance (CFG) with a constant parallelism of 2.
71
+
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
+
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.
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
+
77
+
78
+ We also have implemented the following parallel stategies for reference:
79
+
80
+ 1. Tensor Parallelism
81
+ 2. [DistriFusion](https://arxiv.org/abs/2402.19481)
82
+
83
+ 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.)
84
+
85
+
86
+ 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.
87
+
88
+ 𝒑: Number of pixels;
89
+ 𝒉𝒔: Model hidden size;
90
+ 𝑳: Number of model layers;
91
+ 𝑷: Total model parameters;
92
+ 𝑵: Number of parallel devices;
93
+ 𝑴: Number of patch splits;
94
+ 𝑸𝑶: Query and Output parameter count;
95
+ 𝑲𝑽: KV Activation parameter count;
96
+ 𝑨 = 𝑸 = 𝑶 = 𝑲 = 𝑽: Equal parameters for Attention, Query, Output, Key, and Value;
97
+
98
+ <div align="center">
99
+
100
+ | | attn-KV | communication cost | param memory | activations memory | extra buff memory |
101
+ |:--------:|:-------:|:-----------------:|:-----:|:-----------:|:----------:|
102
+ | 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$ |
103
+ | DistriFusion* | stale | $2O(p \times hs)L$ | $P$ | $\frac{2}{N}A = \frac{1}{N}QO$ | $2AL = (KV)L$ |
104
+ | 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$ |
105
+ | 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$ |
106
+ | 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$ |
107
+
108
+ </div>
109
+
110
+ <h2 id="updates">📢 Updates</h2>
111
+
112
+ * 🎉**August 8, 2024**: Support Flux sequence parallel version. The inference scripts are [examples/flux_example](examples/flux_example.py).
113
+ * 🎉**August 2, 2024**: Support Stable Diffusion 3 hybrid parallel version. The inference scripts are [examples/sd3_example](examples/sd3_example.py).
114
+ * 🎉**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).
115
+ * 🎉**July 17, 2024**: Rename the project to xDiT. The project has evolved from a collection of parallel methods into a unified inference framework and supported the hybrid parallel for DiTs.
116
+ * 🎉**July 10, 2024**: Support HunyuanDiT. The inference script is [legacy/scripts/hunyuandit_example.py](./legacy/scripts/hunyuandit_example.py).
117
+ * 🎉**June 26, 2024**: Support Stable Diffusion 3. The inference script is [legacy/scripts/sd3_example.py](./legacy/scripts/sd3_example.py).
118
+ * 🎉**May 24, 2024**: PipeFusion is public released. It supports PixArt-alpha [legacy/scripts/pixart_example.py](./legacy/scripts/pixart_example.py), DiT [legacy/scripts/ditxl_example.py](./legacy/scripts/ditxl_example.py) and SDXL [legacy/scripts/sdxl_example.py](./legacy/scripts/sdxl_example.py).
119
+
120
+
121
+ <h2 id="support-dits">🎯 Supported DiTs</h2>
122
+
123
+ - [🟠 Flux](https://huggingface.co/black-forest-labs/FLUX.1-schnell)
124
+ - [🔴 PixArt-Sigma](https://huggingface.co/PixArt-alpha/PixArt-Sigma-XL-2-1024-MS)
125
+ - [🔵 HunyuanDiT-v1.2-Diffusers](https://huggingface.co/Tencent-Hunyuan/HunyuanDiT-v1.2-Diffusers)
126
+ - [🟢 PixArt-alpha](https://huggingface.co/PixArt-alpha/PixArt-alpha)
127
+ - [🟠 Stable Diffusion 3](https://huggingface.co/stabilityai/stable-diffusion-3-medium-diffusers)
128
+ - [🔴 DiT-XL](https://huggingface.co/facebook/DiT-XL-2-256)
129
+
130
+
131
+ <h2 id="perf">📈 Performance</h2>
132
+
133
+ 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).
134
+
135
+ **TBD**: Updates results on hybrid parallelism.
136
+
137
+ 1. The Latency on 4xA100-80GB (PCIe)
138
+
139
+ <div align="center">
140
+ <img src="./assets/latency-A100-PCIe.png" alt="A100 PCIe latency">
141
+ </div>
142
+
143
+ 2. The Latency on 8xL20-48GB (PCIe)
144
+
145
+ <div align="center">
146
+ <img src="./assets/latency-L20.png" alt="L20 latency">
147
+ </div>
148
+
149
+ 3. The Latency on 8xA100-80GB (NVLink)
150
+
151
+ <div align="center">
152
+ <img src="./assets/latency-A100-NVLink.png" alt="latency-A100-NVLink">
153
+ </div>
154
+
155
+ 4. The Latency on 4xT4-16GB (PCIe)
156
+
157
+ <div align="center">
158
+ <img src="./assets/latency-T4.png"
159
+ alt="latency-T4">
160
+ </div>
161
+
162
+
163
+ <h2 id="QuickStart">🚀 QuickStart</h2>
164
+
165
+ 1. Install yunchang for sequence parallel.
166
+
167
+ Install yunchang from [feifeibear/long-context-attention](https://github.com/feifeibear/long-context-attention).
168
+ 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
+
170
+ 2. Install xDiT
171
+
172
+ ```
173
+ python setup.py install
174
+ ```
175
+
176
+ 3. Usage
177
+
178
+ We provide examples demonstrating how to run models with xDiT in the [./examples/](./examples/) directory.
179
+ 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.
180
+
181
+ ```bash
182
+ bash examples/run.sh
183
+ ```
184
+
185
+ To inspect the available options for the PixArt-alpha example, use the following command:
186
+
187
+ ```bash
188
+ python ./examples/pixartalpha_example.py -h
189
+
190
+ ...
191
+
192
+ xFuser Arguments
193
+
194
+ options:
195
+ -h, --help show this help message and exit
196
+
197
+ Model Options:
198
+ --model MODEL Name or path of the huggingface model to use.
199
+ --download-dir DOWNLOAD_DIR
200
+ Directory to download and load the weights, default to the default cache dir of huggingface.
201
+ --trust-remote-code Trust remote code from huggingface.
202
+
203
+ Runtime Options:
204
+ --warmup_steps WARMUP_STEPS
205
+ Warmup steps in generation.
206
+ --use_parallel_vae
207
+ --seed SEED Random seed for operations.
208
+ --output_type OUTPUT_TYPE
209
+ Output type of the pipeline.
210
+
211
+ Parallel Processing Options:
212
+ --do_classifier_free_guidance
213
+ --use_split_batch Use split batch in classifier_free_guidance. cfg_degree will be 2 if set
214
+ --data_parallel_degree DATA_PARALLEL_DEGREE
215
+ Data parallel degree.
216
+ --ulysses_degree ULYSSES_DEGREE
217
+ Ulysses sequence parallel degree. Used in attention layer.
218
+ --ring_degree RING_DEGREE
219
+ Ring sequence parallel degree. Used in attention layer.
220
+ --pipefusion_parallel_degree PIPEFUSION_PARALLEL_DEGREE
221
+ Pipefusion parallel degree. Indicates the number of pipeline stages.
222
+ --num_pipeline_patch NUM_PIPELINE_PATCH
223
+ Number of patches the feature map should be segmented in pipefusion parallel.
224
+ --attn_layer_num_for_pp [ATTN_LAYER_NUM_FOR_PP ...]
225
+ List representing the number of layers per stage of the pipeline in pipefusion parallel
226
+ --tensor_parallel_degree TENSOR_PARALLEL_DEGREE
227
+ Tensor parallel degree.
228
+ --split_scheme SPLIT_SCHEME
229
+ Split scheme for tensor parallel.
230
+
231
+ Input Options:
232
+ --height HEIGHT The height of image
233
+ --width WIDTH The width of image
234
+ --prompt [PROMPT ...]
235
+ Prompt for the model.
236
+ --no_use_resolution_binning
237
+ --negative_prompt [NEGATIVE_PROMPT ...]
238
+ Negative prompt for the model.
239
+ --num_inference_steps NUM_INFERENCE_STEPS
240
+ Number of inference steps.
241
+ ```
242
+
243
+ Hybriding multiple parallelism techniques togather is essential for efficiently scaling.
244
+ It's important that the product of all parallel degrees matches the number of devices.
245
+ For instance, you can combine CFG, PipeFusion, and sequence parallelism with the command below to generate an image of a cute dog through hybrid parallelism.
246
+ Here ulysses_degree * pipefusion_parallel_degree * cfg_degree(use_split_batch) == number of devices == 8.
247
+
248
+
249
+ ```bash
250
+ torchrun --nproc_per_node=8 \
251
+ examples/pixartalpha_example.py \
252
+ --model models/PixArt-XL-2-1024-MS \
253
+ --pipefusion_parallel_degree 2 \
254
+ --ulysses_degree 2 \
255
+ --num_inference_steps 20 \
256
+ --warmup_steps 0 \
257
+ --prompt "A small dog" \
258
+ --use_split_batch
259
+ ```
260
+
261
+
262
+ ⚠️ Applying PipeFusion requires setting `warmup_steps`, also required in DistriFusion, typically set to a small number compared with `num_inference_steps`.
263
+ The warmup step impacts the efficiency of PipeFusion as it cannot be executed in parallel, thus degrading to a serial execution.
264
+ We observed that a warmup of 0 had no effect on the PixArt model.
265
+ Users can tune this value according to their specific tasks.
266
+
267
+
268
+ <h2 id="secrets">✨ The xDiT's Secret Weapons</h2>
269
+
270
+ The exceptional capabilities of xDiT stem from our innovative technologies.
271
+
272
+ <h3 id="PipeFusion">1. PipeFusion</h3>
273
+
274
+ [PipeFusion: Displaced Patch Pipeline Parallelism for Diffusion Models](./docs/methods/pipefusion.md)
275
+
276
+ <h3 id="USP">2. USP: Unified Sequence Parallelism</h3>
277
+
278
+ [USP: A Unified Sequence Parallelism Approach for Long Context Generative AI](./docs/methods/usp.md)
279
+
280
+ <h3 id="hybrid_parallel">3. Hybrid Parallel</h3>
281
+
282
+ [Hybrid Parallelism](./docs/methods/hybrid.md)
283
+
284
+ <h3 id="cfg_parallel">4. CFG Parallel</h3>
285
+
286
+ [CFG Parallel](./docs/methods/cfg_parallel.md)
287
+
288
+ <h3 id="parallel_vae">5. Parallel VAE</h3>
289
+
290
+ [Patch Parallel VAE](./docs/methods/parallel_vae.md)
291
+
292
+ <h2 id="dev-guide">📚 Develop Guide</h2>
293
+
294
+ [The implement and design of xdit framework](./docs/developer/The_implement_design_of_xdit_framework.md)
295
+
296
+ [Manual for adding new models](./docs/developer/Manual_for_Adding_New_Models.md)
297
+
298
+ <h2 id="history">🚧 History and Looking for Contributions</h2>
299
+
300
+ We conducted a major upgrade of this project in August 2024.
301
+
302
+ The latest APIs is located in the [xfuser/](./xfuser/) directory, supports hybrid parallelism. It offers clearer and more structured code but currently supports fewer models.
303
+
304
+ The legacy APIs is in the [legacy/](./legacy/) directory, limited to single parallelism. It supports a richer of parallel methods, including PipeFusion, Sequence Parallel, DistriFusion, and Tensor Parallel. CFG Parallel can be hybrid with PipeFusion but not with other parallel methods.
305
+
306
+ For models not yet supported by the latest APIs, you can run the examples in the [legacy/scripts/](./legacy/scripts/) directory. If you wish to develop new features on a model or require hybrid parallelism, stay tuned for further project updates.
307
+
308
+ We also welcome developers to join and contribute more features and models to the project. Tell us which model you need in xDiT in [discussions](https://github.com/xdit-project/xDiT/discussions).
309
+
310
+ <h2 id="cite-us">📝 Cite Us</h2>
311
+
312
+ ```
313
+ @article{wang2024pipefusion,
314
+ title={PipeFusion: Displaced Patch Pipeline Parallelism for Inference of Diffusion Transformer Models},
315
+ author={Jiannan Wang and Jiarui Fang and Jinzhe Pan and Aoyu Li and PengCheng Yang},
316
+ year={2024},
317
+ eprint={2405.07719},
318
+ archivePrefix={arXiv},
319
+ primaryClass={cs.CV}
320
+ }
321
+ ```
322
+