cache-dit 0.1.1.dev2__py3-none-any.whl → 0.1.3__py3-none-any.whl
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.
- cache_dit/_version.py +2 -2
- cache_dit/cache_factory/__init__.py +3 -1
- cache_dit/cache_factory/dual_block_cache/diffusers_adapters/cogvideox.py +1 -1
- cache_dit-0.1.3.dist-info/METADATA +356 -0
- {cache_dit-0.1.1.dev2.dist-info → cache_dit-0.1.3.dist-info}/RECORD +8 -7
- cache_dit-0.1.3.dist-info/licenses/LICENSE +53 -0
- cache_dit-0.1.1.dev2.dist-info/METADATA +0 -31
- {cache_dit-0.1.1.dev2.dist-info → cache_dit-0.1.3.dist-info}/WHEEL +0 -0
- {cache_dit-0.1.1.dev2.dist-info → cache_dit-0.1.3.dist-info}/top_level.txt +0 -0
cache_dit/_version.py
CHANGED
|
@@ -17,5 +17,5 @@ __version__: str
|
|
|
17
17
|
__version_tuple__: VERSION_TUPLE
|
|
18
18
|
version_tuple: VERSION_TUPLE
|
|
19
19
|
|
|
20
|
-
__version__ = version = '0.1.
|
|
21
|
-
__version_tuple__ = version_tuple = (0, 1,
|
|
20
|
+
__version__ = version = '0.1.3'
|
|
21
|
+
__version_tuple__ = version_tuple = (0, 1, 3)
|
|
@@ -160,7 +160,9 @@ def apply_cache_on_pipe(pipe: DiffusionPipeline, *args, **kwargs):
|
|
|
160
160
|
elif cache_type == CacheType.DBPrune:
|
|
161
161
|
return apply_db_prune_on_pipe(pipe, *args, **kwargs)
|
|
162
162
|
elif cache_type == CacheType.NONE:
|
|
163
|
-
logger.warning(
|
|
163
|
+
logger.warning(
|
|
164
|
+
f"Cache type is {cache_type}, no caching will be applied."
|
|
165
|
+
)
|
|
164
166
|
return pipe
|
|
165
167
|
else:
|
|
166
168
|
raise ValueError(f"Unknown cache type: {cache_type}")
|
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: cache_dit
|
|
3
|
+
Version: 0.1.3
|
|
4
|
+
Summary: 🤗 CacheDiT: A Training-free and Easy-to-use Cache Acceleration Toolbox for Diffusion Transformers
|
|
5
|
+
Author: DefTruth, vipshop.com, etc.
|
|
6
|
+
Maintainer: DefTruth, vipshop.com, etc
|
|
7
|
+
Project-URL: Repository, https://github.com/vipshop/cache-dit.git
|
|
8
|
+
Project-URL: Homepage, https://github.com/vipshop/cache-dit.git
|
|
9
|
+
Requires-Python: >=3.10
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Requires-Dist: packaging
|
|
13
|
+
Requires-Dist: torch
|
|
14
|
+
Requires-Dist: transformers
|
|
15
|
+
Requires-Dist: diffusers
|
|
16
|
+
Provides-Extra: all
|
|
17
|
+
Provides-Extra: dev
|
|
18
|
+
Requires-Dist: pre-commit; extra == "dev"
|
|
19
|
+
Requires-Dist: pytest<8.0.0,>=7.0.0; extra == "dev"
|
|
20
|
+
Requires-Dist: pytest-html; extra == "dev"
|
|
21
|
+
Requires-Dist: expecttest; extra == "dev"
|
|
22
|
+
Requires-Dist: hypothesis; extra == "dev"
|
|
23
|
+
Requires-Dist: transformers; extra == "dev"
|
|
24
|
+
Requires-Dist: diffusers; extra == "dev"
|
|
25
|
+
Requires-Dist: accelerate; extra == "dev"
|
|
26
|
+
Requires-Dist: peft; extra == "dev"
|
|
27
|
+
Requires-Dist: protobuf; extra == "dev"
|
|
28
|
+
Requires-Dist: sentencepiece; extra == "dev"
|
|
29
|
+
Requires-Dist: opencv-python-headless; extra == "dev"
|
|
30
|
+
Requires-Dist: ftfy; extra == "dev"
|
|
31
|
+
Dynamic: license-file
|
|
32
|
+
Dynamic: provides-extra
|
|
33
|
+
Dynamic: requires-dist
|
|
34
|
+
Dynamic: requires-python
|
|
35
|
+
|
|
36
|
+
<div align="center">
|
|
37
|
+
<p align="center">
|
|
38
|
+
<h3>🤗 CacheDiT: A Training-free and Easy-to-use Cache Acceleration <br>Toolbox for Diffusion Transformers</h3>
|
|
39
|
+
</p>
|
|
40
|
+
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/cache-dit.png >
|
|
41
|
+
<div align='center'>
|
|
42
|
+
<img src=https://img.shields.io/badge/Language-Python-brightgreen.svg >
|
|
43
|
+
<img src=https://img.shields.io/badge/PRs-welcome-9cf.svg >
|
|
44
|
+
<img src=https://img.shields.io/badge/PyPI-pass-brightgreen.svg >
|
|
45
|
+
<img src=https://static.pepy.tech/badge/cache-dit >
|
|
46
|
+
<img src=https://img.shields.io/badge/Python-3.10|3.11|3.12-9cf.svg >
|
|
47
|
+
<img src=https://img.shields.io/badge/Release-v0.1.3-brightgreen.svg >
|
|
48
|
+
</div>
|
|
49
|
+
<p align="center">
|
|
50
|
+
DeepCache is for UNet not DiT. Most DiT cache speedups are complex and not training-free. CacheDiT provides <br>a series of training-free, UNet-style cache accelerators for DiT: DBCache, DBPrune, FBCache, etc.
|
|
51
|
+
</p>
|
|
52
|
+
</div>
|
|
53
|
+
|
|
54
|
+
## 🤗 Introduction
|
|
55
|
+
|
|
56
|
+
<div align="center">
|
|
57
|
+
<p align="center">
|
|
58
|
+
<h3>DBCache: Dual Block Caching for Diffusion Transformers</h3>
|
|
59
|
+
</p>
|
|
60
|
+
</div>
|
|
61
|
+
|
|
62
|
+
**DBCache**: **Dual Block Caching** for Diffusion Transformers. We have enhanced `FBCache` into a more general and customizable cache algorithm, namely `DBCache`, enabling it to achieve fully `UNet-style` cache acceleration for DiT models. Different configurations of compute blocks (**F8B12**, etc.) can be customized in DBCache. Moreover, it can be entirely **training**-**free**. DBCache can strike a perfect **balance** between performance and precision!
|
|
63
|
+
|
|
64
|
+
<div align="center">
|
|
65
|
+
<p align="center">
|
|
66
|
+
DBCache, <b> L20x1 </b>, Steps: 28, "A cat holding a sign that says hello world with complex background"
|
|
67
|
+
</p>
|
|
68
|
+
</div>
|
|
69
|
+
|
|
70
|
+
|Baseline(L20x1)|F1B0 (0.08)|F1B0 (0.20)|F8B8 (0.15)|F12B12 (0.20)|F16B16 (0.20)|
|
|
71
|
+
|:---:|:---:|:---:|:---:|:---:|:---:|
|
|
72
|
+
|24.85s|15.59s|8.58s|15.41s|15.11s|17.74s|
|
|
73
|
+
|<img src=https://github.com/vipshop/cache-dit/raw/main/assets/NONE_R0.08_S0.png width=105px>|<img src=https://github.com/vipshop/cache-dit/raw/main/assets/DBCACHE_F1B0S1_R0.08_S11.png width=105px> | <img src=https://github.com/vipshop/cache-dit/raw/main/assets/DBCACHE_F1B0S1_R0.2_S19.png width=105px>|<img src=https://github.com/vipshop/cache-dit/raw/main/assets/DBCACHE_F8B8S1_R0.15_S15.png width=105px>|<img src=https://github.com/vipshop/cache-dit/raw/main/assets/DBCACHE_F12B12S4_R0.2_S16.png width=105px>|<img src=https://github.com/vipshop/cache-dit/raw/main/assets/DBCACHE_F16B16S4_R0.2_S13.png width=105px>|
|
|
74
|
+
|**Baseline(L20x1)**|**F1B0 (0.08)**|**F8B8 (0.12)**|**F8B12 (0.20)**|**F8B16 (0.20)**|**F8B20 (0.20)**|
|
|
75
|
+
|27.85s|6.04s|5.88s|5.77s|6.01s|6.20s|
|
|
76
|
+
|<img src=https://github.com/user-attachments/assets/70ea57f4-d8f2-415b-8a96-d8315974a5e6 width=105px>|<img src=https://github.com/user-attachments/assets/fc0e1a67-19cc-44aa-bf50-04696e7978a0 width=105px> |<img src=https://github.com/user-attachments/assets/d1434896-628c-436b-95ad-43c085a8629e width=105px>|<img src=https://github.com/user-attachments/assets/aaa42cd2-57de-4c4e-8bfb-913018a8251d width=105px>|<img src=https://github.com/user-attachments/assets/dc0ba2a4-ef7c-436d-8a39-67055deab92f width=105px>|<img src=https://github.com/user-attachments/assets/aede466f-61ed-4256-8df0-fecf8020c5ca width=105px>|
|
|
77
|
+
|
|
78
|
+
<div align="center">
|
|
79
|
+
<p align="center">
|
|
80
|
+
DBCache, <b> L20x4 </b>, Steps: 20, case to show the texture recovery ability of DBCache
|
|
81
|
+
</p>
|
|
82
|
+
</div>
|
|
83
|
+
|
|
84
|
+
These case studies demonstrate that even with relatively high thresholds (such as 0.12, 0.15, 0.2, etc.) under the DBCache **F12B12** or **F8B16** configuration, the detailed texture of the kitten's fur, colored cloth, and the clarity of text can still be preserved. This suggests that users can leverage DBCache to effectively balance performance and precision in their workflows!
|
|
85
|
+
|
|
86
|
+
<div align="center">
|
|
87
|
+
<p align="center">
|
|
88
|
+
<h3>DBPrune: Dynamic Block Prune with Residual Caching</h3>
|
|
89
|
+
</p>
|
|
90
|
+
</div>
|
|
91
|
+
|
|
92
|
+
**DBPrune**: We have further implemented a new **Dynamic Block Prune** algorithm based on **Residual Caching** for Diffusion Transformers, referred to as DBPrune. DBPrune caches each block's hidden states and residuals, then **dynamically prunes** blocks during inference by computing the L1 distance between previous hidden states. When a block is pruned, its output is approximated using the cached residuals.
|
|
93
|
+
|
|
94
|
+
|Baseline(L20x1)|Pruned(24%)|Pruned(35%)|Pruned(38%)|Pruned(45%)|Pruned(60%)|
|
|
95
|
+
|:---:|:---:|:---:|:---:|:---:|:---:|
|
|
96
|
+
|24.85s|19.43s|16.82s|15.95s|14.24s|10.66s|
|
|
97
|
+
|<img src=https://github.com/vipshop/cache-dit/raw/main/assets/NONE_R0.08_S0.png width=105px>|<img src=https://github.com/vipshop/cache-dit/raw/main/assets/DBPRUNE_F1B0_R0.03_P24.0_T19.43s.png width=105px> | <img src=https://github.com/vipshop/cache-dit/raw/main/assets/DBPRUNE_F1B0_R0.04_P34.6_T16.82s.png width=105px>|<img src=https://github.com/vipshop/cache-dit/raw/main/assets/DBPRUNE_F1B0_R0.05_P38.3_T15.95s.png width=105px>|<img src=https://github.com/vipshop/cache-dit/raw/main/assets/DBPRUNE_F1B0_R0.06_P45.2_T14.24s.png width=105px>|<img src=https://github.com/vipshop/cache-dit/raw/main/assets/DBPRUNE_F1B0_R0.2_P59.5_T10.66s.png width=105px>|
|
|
98
|
+
|
|
99
|
+
<div align="center">
|
|
100
|
+
<p align="center">
|
|
101
|
+
DBPrune, <b> L20x1 </b>, Steps: 28, "A cat holding a sign that says hello world with complex background"
|
|
102
|
+
</p>
|
|
103
|
+
</div>
|
|
104
|
+
|
|
105
|
+
Moreover, both DBCache and DBPrune are **plug-and-play** solutions that works hand-in-hand with [ParaAttention](https://github.com/chengzeyi/ParaAttention). Users can easily tap into its **Context Parallelism** features for distributed inference.
|
|
106
|
+
|
|
107
|
+
<p align="center">
|
|
108
|
+
♥️ Please consider to leave a ⭐️ Star to support us ~ ♥️
|
|
109
|
+
</p>
|
|
110
|
+
|
|
111
|
+
## ©️Citations
|
|
112
|
+
|
|
113
|
+
```BibTeX
|
|
114
|
+
@misc{CacheDiT@2025,
|
|
115
|
+
title={CacheDiT: A Training-free and Easy-to-use cache acceleration Toolbox for Diffusion Transformers},
|
|
116
|
+
url={https://github.com/vipshop/cache-dit.git},
|
|
117
|
+
note={Open-source software available at https://github.com/vipshop/cache-dit.git},
|
|
118
|
+
author={vipshop.com},
|
|
119
|
+
year={2025}
|
|
120
|
+
}
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## 👋Reference
|
|
124
|
+
|
|
125
|
+
<div id="reference"></div>
|
|
126
|
+
|
|
127
|
+
The **CacheDiT** codebase was adapted from FBCache's implementation at the [ParaAttention](https://github.com/chengzeyi/ParaAttention/tree/main/src/para_attn/first_block_cache). We would like to express our sincere gratitude for this excellent work!
|
|
128
|
+
|
|
129
|
+
## 📖Contents
|
|
130
|
+
|
|
131
|
+
<div id="contents"></div>
|
|
132
|
+
|
|
133
|
+
- [⚙️Installation](#️installation)
|
|
134
|
+
- [⚡️Dual Block Cache](#dbcache)
|
|
135
|
+
- [🎉First Block Cache](#fbcache)
|
|
136
|
+
- [⚡️Dynamic Block Prune](#dbprune)
|
|
137
|
+
- [🎉Context Parallelism](#context-parallelism)
|
|
138
|
+
- [⚡️Torch Compile](#compile)
|
|
139
|
+
- [🎉Supported Models](#supported)
|
|
140
|
+
- [👋Contribute](#contribute)
|
|
141
|
+
- [©️License](#license)
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
## ⚙️Installation
|
|
145
|
+
|
|
146
|
+
<div id="installation"></div>
|
|
147
|
+
|
|
148
|
+
You can install the stable release of `cache-dit` from PyPI:
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
pip3 install cache-dit
|
|
152
|
+
```
|
|
153
|
+
Or you can install the latest develop version from GitHub:
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
pip3 install git+https://github.com/vipshop/cache-dit.git
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## ⚡️DBCache: Dual Block Cache
|
|
160
|
+
|
|
161
|
+
<div id="dbcache"></div>
|
|
162
|
+
|
|
163
|
+

|
|
164
|
+
|
|
165
|
+
**DBCache** provides configurable parameters for custom optimization, enabling a balanced trade-off between performance and precision:
|
|
166
|
+
|
|
167
|
+
- **Fn**: Specifies that DBCache uses the **first n** Transformer blocks to fit the information at time step t, enabling the calculation of a more stable L1 diff and delivering more accurate information to subsequent blocks.
|
|
168
|
+
- **Bn**: Further fuses approximate information in the **last n** Transformer blocks to enhance prediction accuracy. These blocks act as an auto-scaler for approximate hidden states that use residual cache.
|
|
169
|
+
- **warmup_steps**: (default: 0) DBCache does not apply the caching strategy when the number of running steps is less than or equal to this value, ensuring the model sufficiently learns basic features during warmup.
|
|
170
|
+
- **max_cached_steps**: (default: -1) DBCache disables the caching strategy when the running steps exceed this value to prevent precision degradation.
|
|
171
|
+
- **residual_diff_threshold**: The value of residual diff threshold, a higher value leads to faster performance at the cost of lower precision.
|
|
172
|
+
|
|
173
|
+
For a good balance between performance and precision, DBCache is configured by default with **F8B8**, 8 warmup steps, and unlimited cached steps.
|
|
174
|
+
|
|
175
|
+
```python
|
|
176
|
+
from diffusers import FluxPipeline
|
|
177
|
+
from cache_dit.cache_factory import apply_cache_on_pipe, CacheType
|
|
178
|
+
|
|
179
|
+
pipe = FluxPipeline.from_pretrained(
|
|
180
|
+
"black-forest-labs/FLUX.1-dev",
|
|
181
|
+
torch_dtype=torch.bfloat16,
|
|
182
|
+
).to("cuda")
|
|
183
|
+
|
|
184
|
+
# Default options, F8B8, good balance between performance and precision
|
|
185
|
+
cache_options = CacheType.default_options(CacheType.DBCache)
|
|
186
|
+
|
|
187
|
+
# Custom options, F8B16, higher precision
|
|
188
|
+
cache_options = {
|
|
189
|
+
"cache_type": CacheType.DBCache,
|
|
190
|
+
"warmup_steps": 8,
|
|
191
|
+
"max_cached_steps": 8, # -1 means no limit
|
|
192
|
+
"Fn_compute_blocks": 8, # Fn, F8, etc.
|
|
193
|
+
"Bn_compute_blocks": 16, # Bn, B16, etc.
|
|
194
|
+
"residual_diff_threshold": 0.12,
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
apply_cache_on_pipe(pipe, **cache_options)
|
|
198
|
+
```
|
|
199
|
+
Moreover, users configuring higher **Bn** values (e.g., **F8B16**) while aiming to maintain good performance can specify **Bn_compute_blocks_ids** to work with Bn. DBCache will only compute the specified blocks, with the remaining estimated using the previous step's residual cache.
|
|
200
|
+
|
|
201
|
+
```python
|
|
202
|
+
# Custom options, F8B16, higher precision with good performance.
|
|
203
|
+
cache_options = {
|
|
204
|
+
# 0, 2, 4, ..., 14, 15, etc. [0,16)
|
|
205
|
+
"Bn_compute_blocks_ids": CacheType.range(0, 16, 2),
|
|
206
|
+
# If the L1 difference is below this threshold, skip Bn blocks
|
|
207
|
+
# not in `Bn_compute_blocks_ids`(1, 3,..., etc), Otherwise,
|
|
208
|
+
# compute these blocks.
|
|
209
|
+
"non_compute_blocks_diff_threshold": 0.08,
|
|
210
|
+
}
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
## 🎉FBCache: First Block Cache
|
|
214
|
+
|
|
215
|
+
<div id="fbcache"></div>
|
|
216
|
+
|
|
217
|
+

|
|
218
|
+
|
|
219
|
+
**DBCache** is a more general cache algorithm than **FBCache**. When Fn=1 and Bn=0, DBCache behaves identically to FBCache. Therefore, you can either use the original FBCache implementation directly or configure **DBCache** with **F1B0** settings to achieve the same functionality.
|
|
220
|
+
|
|
221
|
+
```python
|
|
222
|
+
from diffusers import FluxPipeline
|
|
223
|
+
from cache_dit.cache_factory import apply_cache_on_pipe, CacheType
|
|
224
|
+
|
|
225
|
+
pipe = FluxPipeline.from_pretrained(
|
|
226
|
+
"black-forest-labs/FLUX.1-dev",
|
|
227
|
+
torch_dtype=torch.bfloat16,
|
|
228
|
+
).to("cuda")
|
|
229
|
+
|
|
230
|
+
# Using FBCache directly
|
|
231
|
+
cache_options = CacheType.default_options(CacheType.FBCache)
|
|
232
|
+
|
|
233
|
+
# Or using DBCache with F1B0.
|
|
234
|
+
# Fn=1, Bn=0, means FB Cache, otherwise, Dual Block Cache
|
|
235
|
+
cache_options = {
|
|
236
|
+
"cache_type": CacheType.DBCache,
|
|
237
|
+
"warmup_steps": 8,
|
|
238
|
+
"max_cached_steps": 8, # -1 means no limit
|
|
239
|
+
"Fn_compute_blocks": 1, # Fn, F1, etc.
|
|
240
|
+
"Bn_compute_blocks": 0, # Bn, B0, etc.
|
|
241
|
+
"residual_diff_threshold": 0.12,
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
apply_cache_on_pipe(pipe, **cache_options)
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
## ⚡️DBPrune: Dynamic Block Prune
|
|
248
|
+
|
|
249
|
+
<div id="dbprune"></div>
|
|
250
|
+
|
|
251
|
+

|
|
252
|
+
|
|
253
|
+
We have further implemented a new **Dynamic Block Prune** algorithm based on **Residual Caching** for Diffusion Transformers, which is referred to as **DBPrune**. DBPrune caches each block's hidden states and residuals, then dynamically prunes blocks during inference by computing the L1 distance between previous hidden states. When a block is pruned, its output is approximated using the cached residuals. DBPrune is currently in the experimental phase, and we kindly invite you to stay tuned for upcoming updates.
|
|
254
|
+
|
|
255
|
+
```python
|
|
256
|
+
from diffusers import FluxPipeline
|
|
257
|
+
from cache_dit.cache_factory import apply_cache_on_pipe, CacheType
|
|
258
|
+
|
|
259
|
+
pipe = FluxPipeline.from_pretrained(
|
|
260
|
+
"black-forest-labs/FLUX.1-dev",
|
|
261
|
+
torch_dtype=torch.bfloat16,
|
|
262
|
+
).to("cuda")
|
|
263
|
+
|
|
264
|
+
# Using DBPrune
|
|
265
|
+
cache_options = CacheType.default_options(CacheType.DBPrune)
|
|
266
|
+
|
|
267
|
+
apply_cache_on_pipe(pipe, **cache_options)
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
<div align="center">
|
|
271
|
+
<p align="center">
|
|
272
|
+
DBPrune, <b> L20x1 </b>, Steps: 28, "A cat holding a sign that says hello world with complex background"
|
|
273
|
+
</p>
|
|
274
|
+
</div>
|
|
275
|
+
|
|
276
|
+
|Baseline(L20x1)|Pruned(24%)|Pruned(35%)|Pruned(38%)|Pruned(45%)|Pruned(60%)|
|
|
277
|
+
|:---:|:---:|:---:|:---:|:---:|:---:|
|
|
278
|
+
|24.85s|19.43s|16.82s|15.95s|14.24s|10.66s|
|
|
279
|
+
|<img src=https://github.com/vipshop/cache-dit/raw/main/assets/NONE_R0.08_S0.png width=105px>|<img src=https://github.com/vipshop/cache-dit/raw/main/assets/DBPRUNE_F1B0_R0.03_P24.0_T19.43s.png width=105px> | <img src=https://github.com/vipshop/cache-dit/raw/main/assets/DBPRUNE_F1B0_R0.04_P34.6_T16.82s.png width=105px>|<img src=https://github.com/vipshop/cache-dit/raw/main/assets/DBPRUNE_F1B0_R0.05_P38.3_T15.95s.png width=105px>|<img src=https://github.com/vipshop/cache-dit/raw/main/assets/DBPRUNE_F1B0_R0.06_P45.2_T14.24s.png width=105px>|<img src=https://github.com/vipshop/cache-dit/raw/main/assets/DBPRUNE_F1B0_R0.2_P59.5_T10.66s.png width=105px>|
|
|
280
|
+
|
|
281
|
+
## 🎉Context Parallelism
|
|
282
|
+
|
|
283
|
+
<div id="context-parallelism"></div>
|
|
284
|
+
|
|
285
|
+
**CacheDiT** are **plug-and-play** solutions that works hand-in-hand with [ParaAttention](https://github.com/chengzeyi/ParaAttention). Users can **easily tap into** its **Context Parallelism** features for distributed inference. Firstly, install `para-attn` from PyPI:
|
|
286
|
+
|
|
287
|
+
```bash
|
|
288
|
+
pip3 install para-attn # or install `para-attn` from sources.
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
Then, you can run **DBCache** with **Context Parallelism** on 4 GPUs:
|
|
292
|
+
|
|
293
|
+
```python
|
|
294
|
+
from diffusers import FluxPipeline
|
|
295
|
+
from para_attn.context_parallel import init_context_parallel_mesh
|
|
296
|
+
from para_attn.context_parallel.diffusers_adapters import parallelize_pipe
|
|
297
|
+
from cache_dit.cache_factory import apply_cache_on_pipe, CacheType
|
|
298
|
+
|
|
299
|
+
pipe = FluxPipeline.from_pretrained(
|
|
300
|
+
"black-forest-labs/FLUX.1-dev",
|
|
301
|
+
torch_dtype=torch.bfloat16,
|
|
302
|
+
).to("cuda")
|
|
303
|
+
|
|
304
|
+
# Context Parallel from ParaAttention
|
|
305
|
+
parallelize_pipe(
|
|
306
|
+
pipe, mesh=init_context_parallel_mesh(
|
|
307
|
+
pipe.device.type, max_ulysses_dim_size=4
|
|
308
|
+
)
|
|
309
|
+
)
|
|
310
|
+
|
|
311
|
+
# DBCache with F8B8 from this library
|
|
312
|
+
apply_cache_on_pipe(
|
|
313
|
+
pipe, **CacheType.default_options(CacheType.DBCache)
|
|
314
|
+
)
|
|
315
|
+
```
|
|
316
|
+
|
|
317
|
+
## ⚡️Torch Compile
|
|
318
|
+
|
|
319
|
+
<div id="compile"></div>
|
|
320
|
+
|
|
321
|
+
**CacheDiT** are designed to work compatibly with `torch.compile`. For example:
|
|
322
|
+
|
|
323
|
+
```python
|
|
324
|
+
apply_cache_on_pipe(
|
|
325
|
+
pipe, **CacheType.default_options(CacheType.DBCache)
|
|
326
|
+
)
|
|
327
|
+
# Compile the Transformer module
|
|
328
|
+
pipe.transformer = torch.compile(pipe.transformer)
|
|
329
|
+
```
|
|
330
|
+
However, users intending to use **CacheDiT** for DiT with **dynamic input shapes** should consider increasing the **recompile** **limit** of `torch._dynamo` to achieve better performance.
|
|
331
|
+
|
|
332
|
+
```python
|
|
333
|
+
torch._dynamo.config.recompile_limit = 96 # default is 8
|
|
334
|
+
torch._dynamo.config.accumulated_recompile_limit = 2048 # default is 256
|
|
335
|
+
```
|
|
336
|
+
Otherwise, the recompile_limit error may be triggered, causing the module to fall back to eager mode.
|
|
337
|
+
|
|
338
|
+
## 🎉Supported Models
|
|
339
|
+
|
|
340
|
+
<div id="supported"></div>
|
|
341
|
+
|
|
342
|
+
- [🚀FLUX.1](https://github.com/vipshop/cache-dit/raw/main/src/cache_dit/cache_factory/dual_block_cache/diffusers_adapters)
|
|
343
|
+
- [🚀CogVideoX](https://github.com/vipshop/cache-dit/raw/main/src/cache_dit/cache_factory/dual_block_cache/diffusers_adapters)
|
|
344
|
+
- [🚀Mochi](https://github.com/vipshop/cache-dit/raw/main/src/cache_dit/cache_factory/dual_block_cache/diffusers_adapters)
|
|
345
|
+
|
|
346
|
+
## 👋Contribute
|
|
347
|
+
<div id="contribute"></div>
|
|
348
|
+
|
|
349
|
+
How to contribute? Star this repo or check [CONTRIBUTE.md](./CONTRIBUTE.md).
|
|
350
|
+
|
|
351
|
+
## ©️License
|
|
352
|
+
|
|
353
|
+
<div id="license"></div>
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
We have followed the original License from [ParaAttention](https://github.com/chengzeyi/ParaAttention), please check [LICENSE](./LICENSE) for more details.
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
cache_dit/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
-
cache_dit/_version.py,sha256=
|
|
2
|
+
cache_dit/_version.py,sha256=NIzzV8ZM0W-CSLuEs1weG4zPrn_-8yr1AwwI1iuS6yo,511
|
|
3
3
|
cache_dit/logger.py,sha256=dKfNe_RRk9HJwfgHGeRR1f0LbskJpKdGmISCbL9roQs,3443
|
|
4
4
|
cache_dit/primitives.py,sha256=A2iG9YLot3gOsZSPp-_gyjqjLgJvWQRx8aitD4JQ23Y,3877
|
|
5
|
-
cache_dit/cache_factory/__init__.py,sha256=
|
|
5
|
+
cache_dit/cache_factory/__init__.py,sha256=5RNuhWakvvqrOV4vkqrEBA7d-V1LwcNSsjtW14mkqK8,5255
|
|
6
6
|
cache_dit/cache_factory/taylorseer.py,sha256=0W29ykJg3MnyLAB2KFicsl11Xe41cDYPgI60bquG_NY,2495
|
|
7
7
|
cache_dit/cache_factory/utils.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
8
8
|
cache_dit/cache_factory/dual_block_cache/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
9
|
cache_dit/cache_factory/dual_block_cache/cache_context.py,sha256=EJ-uhA2-sWMW1jNDhcBtjHDqSn8lUzfKbYoPfZDQhZU,49665
|
|
10
10
|
cache_dit/cache_factory/dual_block_cache/diffusers_adapters/__init__.py,sha256=C6tfXHpdY8YFV3gk74dr_IpYH4bO4ItbPCQYud3NgAM,1667
|
|
11
|
-
cache_dit/cache_factory/dual_block_cache/diffusers_adapters/cogvideox.py,sha256=
|
|
11
|
+
cache_dit/cache_factory/dual_block_cache/diffusers_adapters/cogvideox.py,sha256=1_n-RFMiL3v2SjhSfFrPH5Mn5Dq9z4BesVK8GN_nh2g,2404
|
|
12
12
|
cache_dit/cache_factory/dual_block_cache/diffusers_adapters/flux.py,sha256=UbE6nIF-EtA92QxIZVMzIssdZKQSPAVX1hchF9R8drU,2754
|
|
13
13
|
cache_dit/cache_factory/dual_block_cache/diffusers_adapters/mochi.py,sha256=qxMu1L3ycT8F-uxpGsmFQBY_BH1vDiGIOXgS_Qbb7dM,2391
|
|
14
14
|
cache_dit/cache_factory/dynamic_block_prune/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -24,7 +24,8 @@ cache_dit/cache_factory/first_block_cache/diffusers_adapters/cogvideox.py,sha256
|
|
|
24
24
|
cache_dit/cache_factory/first_block_cache/diffusers_adapters/flux.py,sha256=Dcd4OzABCtyQCZNX2KNnUTdVoO1E1ApM7P8gcVYzcK0,2733
|
|
25
25
|
cache_dit/cache_factory/first_block_cache/diffusers_adapters/mochi.py,sha256=lQTClo52OwPbNEE4jiBZQhfC7hbtYqnYIABp_vbm_dk,2363
|
|
26
26
|
cache_dit/cache_factory/first_block_cache/diffusers_adapters/wan.py,sha256=IVH-lroOzvYb4XKLk9MOw54EtijBtuzVaKcVGz0KlBA,2656
|
|
27
|
-
cache_dit-0.1.
|
|
28
|
-
cache_dit-0.1.
|
|
29
|
-
cache_dit-0.1.
|
|
30
|
-
cache_dit-0.1.
|
|
27
|
+
cache_dit-0.1.3.dist-info/licenses/LICENSE,sha256=Dqb07Ik2dV41s9nIdMUbiRWEfDqo7-dQeRiY7kPO8PE,3769
|
|
28
|
+
cache_dit-0.1.3.dist-info/METADATA,sha256=PkDyfGzvMzMinTNlqCX_B3VGbNsPUvLdBQTyEywQ8zE,16806
|
|
29
|
+
cache_dit-0.1.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
30
|
+
cache_dit-0.1.3.dist-info/top_level.txt,sha256=ZJDydonLEhujzz0FOkVbO-BqfzO9d_VqRHmZU-3MOZo,10
|
|
31
|
+
cache_dit-0.1.3.dist-info/RECORD,,
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# License
|
|
2
|
+
|
|
3
|
+
## Acceptance
|
|
4
|
+
|
|
5
|
+
By using the software, you agree to all of the terms and conditions below.
|
|
6
|
+
|
|
7
|
+
## Copyright License
|
|
8
|
+
|
|
9
|
+
The licensor grants you a non-exclusive, royalty-free, worldwide, non-sublicensable, non-transferable license to use, copy, distribute, make available, and prepare derivative works of the software, in each case subject to the limitations and conditions below.
|
|
10
|
+
|
|
11
|
+
## Limitations
|
|
12
|
+
|
|
13
|
+
You may not provide the software to third parties as a hosted or managed service, where the service provides users with access to any substantial set of the features or functionality of the software.
|
|
14
|
+
|
|
15
|
+
You may not move, change, disable, or circumvent the license key functionality in the software, and you may not remove or obscure any functionality in the software that is protected by the license key.
|
|
16
|
+
|
|
17
|
+
You may not alter, remove, or obscure any licensing, copyright, or other notices of the licensor in the software. Any use of the licensor’s trademarks is subject to applicable law.
|
|
18
|
+
|
|
19
|
+
## Patents
|
|
20
|
+
|
|
21
|
+
The licensor grants you a license, under any patent claims the licensor can license, or becomes able to license, to make, have made, use, sell, offer for sale, import and have imported the software, in each case subject to the limitations and conditions in this license. This license does not cover any patent claims that you cause to be infringed by modifications or additions to the software. If you or your company make any written claim that the software infringes or contributes to infringement of any patent, your patent license for the software granted under these terms ends immediately. If your company makes such a claim, your patent license ends immediately for work on behalf of your company.
|
|
22
|
+
|
|
23
|
+
## Notices
|
|
24
|
+
|
|
25
|
+
You must ensure that anyone who gets a copy of any part of the software from you also gets a copy of these terms.
|
|
26
|
+
|
|
27
|
+
If you modify the software, you must include in any modified copies of the software prominent notices stating that you have modified the software.
|
|
28
|
+
No Other Rights
|
|
29
|
+
|
|
30
|
+
These terms do not imply any licenses other than those expressly granted in these terms.
|
|
31
|
+
|
|
32
|
+
## Termination
|
|
33
|
+
|
|
34
|
+
If you use the software in violation of these terms, such use is not licensed, and your licenses will automatically terminate. If the licensor provides you with a notice of your violation, and you cease all violation of this license no later than 30 days after you receive that notice, your licenses will be reinstated retroactively. However, if you violate these terms after such reinstatement, any additional violation of these terms will cause your licenses to terminate automatically and permanently.
|
|
35
|
+
|
|
36
|
+
## No Liability
|
|
37
|
+
|
|
38
|
+
As far as the law allows, the software comes as is, without any warranty or condition, and the licensor will not be liable to you for any damages arising out of these terms or the use or nature of the software, under any kind of legal claim.
|
|
39
|
+
Definitions
|
|
40
|
+
|
|
41
|
+
The licensor is the entity offering these terms, and the software is the software the licensor makes available under these terms, including any portion of it.
|
|
42
|
+
|
|
43
|
+
## Definitions
|
|
44
|
+
|
|
45
|
+
you refers to the individual or entity agreeing to these terms.
|
|
46
|
+
|
|
47
|
+
your company is any legal entity, sole proprietorship, or other kind of organization that you work for, plus all organizations that have control over, are under the control of, or are under common control with that organization. control means ownership of substantially all the assets of an entity, or the power to direct its management and policies by vote, contract, or otherwise. Control can be direct or indirect.
|
|
48
|
+
|
|
49
|
+
your licenses are all the licenses granted to you for the software under these terms.
|
|
50
|
+
|
|
51
|
+
use means anything you do with the software requiring one of your licenses.
|
|
52
|
+
|
|
53
|
+
trademark means trademarks, service marks, and similar rights.
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: cache_dit
|
|
3
|
-
Version: 0.1.1.dev2
|
|
4
|
-
Summary: ⚡️DBCache: A Training-free UNet-style Cache Acceleration for Diffusion Transformers
|
|
5
|
-
Author: DefTruth, vipshop.com, etc.
|
|
6
|
-
Maintainer: DefTruth, vipshop.com, etc
|
|
7
|
-
Project-URL: Repository, https://github.com/vipshop/DBCache.git
|
|
8
|
-
Project-URL: Homepage, https://github.com/vipshop/DBCache.git
|
|
9
|
-
Requires-Python: >=3.10
|
|
10
|
-
Requires-Dist: packaging
|
|
11
|
-
Requires-Dist: torch
|
|
12
|
-
Requires-Dist: transformers
|
|
13
|
-
Requires-Dist: diffusers
|
|
14
|
-
Provides-Extra: all
|
|
15
|
-
Provides-Extra: dev
|
|
16
|
-
Requires-Dist: pre-commit; extra == "dev"
|
|
17
|
-
Requires-Dist: pytest<8.0.0,>=7.0.0; extra == "dev"
|
|
18
|
-
Requires-Dist: pytest-html; extra == "dev"
|
|
19
|
-
Requires-Dist: expecttest; extra == "dev"
|
|
20
|
-
Requires-Dist: hypothesis; extra == "dev"
|
|
21
|
-
Requires-Dist: transformers; extra == "dev"
|
|
22
|
-
Requires-Dist: diffusers; extra == "dev"
|
|
23
|
-
Requires-Dist: accelerate; extra == "dev"
|
|
24
|
-
Requires-Dist: peft; extra == "dev"
|
|
25
|
-
Requires-Dist: protobuf; extra == "dev"
|
|
26
|
-
Requires-Dist: sentencepiece; extra == "dev"
|
|
27
|
-
Requires-Dist: opencv-python-headless; extra == "dev"
|
|
28
|
-
Requires-Dist: ftfy; extra == "dev"
|
|
29
|
-
Dynamic: provides-extra
|
|
30
|
-
Dynamic: requires-dist
|
|
31
|
-
Dynamic: requires-python
|
|
File without changes
|
|
File without changes
|