cache-dit 0.1.5__tar.gz → 0.1.7__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.
Potentially problematic release.
This version of cache-dit might be problematic. Click here for more details.
- {cache_dit-0.1.5 → cache_dit-0.1.7}/PKG-INFO +53 -19
- {cache_dit-0.1.5 → cache_dit-0.1.7}/README.md +49 -15
- {cache_dit-0.1.5 → cache_dit-0.1.7}/bench/bench.py +50 -13
- {cache_dit-0.1.5 → cache_dit-0.1.7}/requirements.txt +3 -3
- {cache_dit-0.1.5 → cache_dit-0.1.7}/src/cache_dit/_version.py +2 -2
- {cache_dit-0.1.5 → cache_dit-0.1.7}/src/cache_dit/cache_factory/dynamic_block_prune/prune_context.py +11 -3
- {cache_dit-0.1.5 → cache_dit-0.1.7}/src/cache_dit.egg-info/PKG-INFO +53 -19
- {cache_dit-0.1.5 → cache_dit-0.1.7}/src/cache_dit.egg-info/requires.txt +3 -3
- {cache_dit-0.1.5 → cache_dit-0.1.7}/.github/workflows/issue.yml +0 -0
- {cache_dit-0.1.5 → cache_dit-0.1.7}/.gitignore +0 -0
- {cache_dit-0.1.5 → cache_dit-0.1.7}/.pre-commit-config.yaml +0 -0
- {cache_dit-0.1.5 → cache_dit-0.1.7}/CONTRIBUTE.md +0 -0
- {cache_dit-0.1.5 → cache_dit-0.1.7}/LICENSE +0 -0
- {cache_dit-0.1.5 → cache_dit-0.1.7}/MANIFEST.in +0 -0
- {cache_dit-0.1.5 → cache_dit-0.1.7}/assets/DBCACHE_F12B12S4_R0.2_S16.png +0 -0
- {cache_dit-0.1.5 → cache_dit-0.1.7}/assets/DBCACHE_F12B16S4_R0.08_S6.png +0 -0
- {cache_dit-0.1.5 → cache_dit-0.1.7}/assets/DBCACHE_F16B16S2_R0.2_S14.png +0 -0
- {cache_dit-0.1.5 → cache_dit-0.1.7}/assets/DBCACHE_F16B16S4_R0.2_S13.png +0 -0
- {cache_dit-0.1.5 → cache_dit-0.1.7}/assets/DBCACHE_F1B0S1_R0.08_S11.png +0 -0
- {cache_dit-0.1.5 → cache_dit-0.1.7}/assets/DBCACHE_F1B0S1_R0.2_S19.png +0 -0
- {cache_dit-0.1.5 → cache_dit-0.1.7}/assets/DBCACHE_F8B0S2_R0.12_S12.png +0 -0
- {cache_dit-0.1.5 → cache_dit-0.1.7}/assets/DBCACHE_F8B16S1_R0.2_S18.png +0 -0
- {cache_dit-0.1.5 → cache_dit-0.1.7}/assets/DBCACHE_F8B8S1_R0.08_S9.png +0 -0
- {cache_dit-0.1.5 → cache_dit-0.1.7}/assets/DBCACHE_F8B8S1_R0.12_S12.png +0 -0
- {cache_dit-0.1.5 → cache_dit-0.1.7}/assets/DBCACHE_F8B8S1_R0.15_S15.png +0 -0
- {cache_dit-0.1.5 → cache_dit-0.1.7}/assets/DBCache.png +0 -0
- {cache_dit-0.1.5 → cache_dit-0.1.7}/assets/DBPRUNE_F1B0_R0.03_P24.0_T19.43s.png +0 -0
- {cache_dit-0.1.5 → cache_dit-0.1.7}/assets/DBPRUNE_F1B0_R0.04_P34.6_T16.82s.png +0 -0
- {cache_dit-0.1.5 → cache_dit-0.1.7}/assets/DBPRUNE_F1B0_R0.05_P38.3_T15.95s.png +0 -0
- {cache_dit-0.1.5 → cache_dit-0.1.7}/assets/DBPRUNE_F1B0_R0.06_P45.2_T14.24s.png +0 -0
- {cache_dit-0.1.5 → cache_dit-0.1.7}/assets/DBPRUNE_F1B0_R0.07_P52.3_T12.53s.png +0 -0
- {cache_dit-0.1.5 → cache_dit-0.1.7}/assets/DBPRUNE_F1B0_R0.08_P52.4_T12.52s.png +0 -0
- {cache_dit-0.1.5 → cache_dit-0.1.7}/assets/DBPRUNE_F1B0_R0.09_P59.2_T10.81s.png +0 -0
- {cache_dit-0.1.5 → cache_dit-0.1.7}/assets/DBPRUNE_F1B0_R0.12_P59.5_T10.76s.png +0 -0
- {cache_dit-0.1.5 → cache_dit-0.1.7}/assets/DBPRUNE_F1B0_R0.12_P63.0_T9.90s.png +0 -0
- {cache_dit-0.1.5 → cache_dit-0.1.7}/assets/DBPRUNE_F1B0_R0.1_P62.8_T9.95s.png +0 -0
- {cache_dit-0.1.5 → cache_dit-0.1.7}/assets/DBPRUNE_F1B0_R0.2_P59.5_T10.66s.png +0 -0
- {cache_dit-0.1.5 → cache_dit-0.1.7}/assets/DBPRUNE_F1B0_R0.3_P63.1_T9.79s.png +0 -0
- {cache_dit-0.1.5 → cache_dit-0.1.7}/assets/NONE_R0.08_S0.png +0 -0
- {cache_dit-0.1.5 → cache_dit-0.1.7}/assets/cache-dit.png +0 -0
- {cache_dit-0.1.5 → cache_dit-0.1.7}/bench/.gitignore +0 -0
- {cache_dit-0.1.5 → cache_dit-0.1.7}/docs/.gitignore +0 -0
- {cache_dit-0.1.5 → cache_dit-0.1.7}/examples/.gitignore +0 -0
- {cache_dit-0.1.5 → cache_dit-0.1.7}/examples/run_cogvideox.py +0 -0
- {cache_dit-0.1.5 → cache_dit-0.1.7}/examples/run_flux.py +0 -0
- {cache_dit-0.1.5 → cache_dit-0.1.7}/examples/run_mochi.py +0 -0
- {cache_dit-0.1.5 → cache_dit-0.1.7}/pyproject.toml +0 -0
- {cache_dit-0.1.5 → cache_dit-0.1.7}/pytest.ini +0 -0
- {cache_dit-0.1.5 → cache_dit-0.1.7}/setup.cfg +0 -0
- {cache_dit-0.1.5 → cache_dit-0.1.7}/setup.py +0 -0
- {cache_dit-0.1.5 → cache_dit-0.1.7}/src/cache_dit/__init__.py +0 -0
- {cache_dit-0.1.5 → cache_dit-0.1.7}/src/cache_dit/cache_factory/__init__.py +0 -0
- {cache_dit-0.1.5 → cache_dit-0.1.7}/src/cache_dit/cache_factory/dual_block_cache/__init__.py +0 -0
- {cache_dit-0.1.5 → cache_dit-0.1.7}/src/cache_dit/cache_factory/dual_block_cache/cache_context.py +0 -0
- {cache_dit-0.1.5 → cache_dit-0.1.7}/src/cache_dit/cache_factory/dual_block_cache/diffusers_adapters/__init__.py +0 -0
- {cache_dit-0.1.5 → cache_dit-0.1.7}/src/cache_dit/cache_factory/dual_block_cache/diffusers_adapters/cogvideox.py +0 -0
- {cache_dit-0.1.5 → cache_dit-0.1.7}/src/cache_dit/cache_factory/dual_block_cache/diffusers_adapters/flux.py +0 -0
- {cache_dit-0.1.5 → cache_dit-0.1.7}/src/cache_dit/cache_factory/dual_block_cache/diffusers_adapters/mochi.py +0 -0
- {cache_dit-0.1.5 → cache_dit-0.1.7}/src/cache_dit/cache_factory/dynamic_block_prune/__init__.py +0 -0
- {cache_dit-0.1.5 → cache_dit-0.1.7}/src/cache_dit/cache_factory/dynamic_block_prune/diffusers_adapters/__init__.py +0 -0
- {cache_dit-0.1.5 → cache_dit-0.1.7}/src/cache_dit/cache_factory/dynamic_block_prune/diffusers_adapters/cogvideox.py +0 -0
- {cache_dit-0.1.5 → cache_dit-0.1.7}/src/cache_dit/cache_factory/dynamic_block_prune/diffusers_adapters/flux.py +0 -0
- {cache_dit-0.1.5 → cache_dit-0.1.7}/src/cache_dit/cache_factory/dynamic_block_prune/diffusers_adapters/mochi.py +0 -0
- {cache_dit-0.1.5 → cache_dit-0.1.7}/src/cache_dit/cache_factory/first_block_cache/__init__.py +0 -0
- {cache_dit-0.1.5 → cache_dit-0.1.7}/src/cache_dit/cache_factory/first_block_cache/cache_context.py +0 -0
- {cache_dit-0.1.5 → cache_dit-0.1.7}/src/cache_dit/cache_factory/first_block_cache/diffusers_adapters/__init__.py +0 -0
- {cache_dit-0.1.5 → cache_dit-0.1.7}/src/cache_dit/cache_factory/first_block_cache/diffusers_adapters/cogvideox.py +0 -0
- {cache_dit-0.1.5 → cache_dit-0.1.7}/src/cache_dit/cache_factory/first_block_cache/diffusers_adapters/flux.py +0 -0
- {cache_dit-0.1.5 → cache_dit-0.1.7}/src/cache_dit/cache_factory/first_block_cache/diffusers_adapters/mochi.py +0 -0
- {cache_dit-0.1.5 → cache_dit-0.1.7}/src/cache_dit/cache_factory/first_block_cache/diffusers_adapters/wan.py +0 -0
- {cache_dit-0.1.5 → cache_dit-0.1.7}/src/cache_dit/cache_factory/taylorseer.py +0 -0
- {cache_dit-0.1.5 → cache_dit-0.1.7}/src/cache_dit/cache_factory/utils.py +0 -0
- {cache_dit-0.1.5 → cache_dit-0.1.7}/src/cache_dit/logger.py +0 -0
- {cache_dit-0.1.5 → cache_dit-0.1.7}/src/cache_dit/primitives.py +0 -0
- {cache_dit-0.1.5 → cache_dit-0.1.7}/src/cache_dit.egg-info/SOURCES.txt +0 -0
- {cache_dit-0.1.5 → cache_dit-0.1.7}/src/cache_dit.egg-info/dependency_links.txt +0 -0
- {cache_dit-0.1.5 → cache_dit-0.1.7}/src/cache_dit.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cache_dit
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.7
|
|
4
4
|
Summary: 🤗 CacheDiT: A Training-free and Easy-to-use Cache Acceleration Toolbox for Diffusion Transformers
|
|
5
5
|
Author: DefTruth, vipshop.com, etc.
|
|
6
6
|
Maintainer: DefTruth, vipshop.com, etc
|
|
@@ -10,9 +10,9 @@ Requires-Python: >=3.10
|
|
|
10
10
|
Description-Content-Type: text/markdown
|
|
11
11
|
License-File: LICENSE
|
|
12
12
|
Requires-Dist: packaging
|
|
13
|
-
Requires-Dist: torch
|
|
14
|
-
Requires-Dist: transformers
|
|
15
|
-
Requires-Dist: diffusers
|
|
13
|
+
Requires-Dist: torch>=2.5.1
|
|
14
|
+
Requires-Dist: transformers>=4.51.3
|
|
15
|
+
Requires-Dist: diffusers>=0.33.1
|
|
16
16
|
Provides-Extra: all
|
|
17
17
|
Provides-Extra: dev
|
|
18
18
|
Requires-Dist: pre-commit; extra == "dev"
|
|
@@ -44,10 +44,10 @@ Dynamic: requires-python
|
|
|
44
44
|
<img src=https://img.shields.io/badge/PyPI-pass-brightgreen.svg >
|
|
45
45
|
<img src=https://static.pepy.tech/badge/cache-dit >
|
|
46
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.
|
|
47
|
+
<img src=https://img.shields.io/badge/Release-v0.1.7-brightgreen.svg >
|
|
48
48
|
</div>
|
|
49
49
|
<p align="center">
|
|
50
|
-
DeepCache is for UNet not DiT. Most DiT cache speedups are complex and not training-free. CacheDiT
|
|
50
|
+
DeepCache is for UNet not DiT. Most DiT cache speedups are complex and not training-free. CacheDiT <br>offers a set of training-free cache accelerators for DiT: 🔥DBCache, DBPrune, FBCache, etc🔥
|
|
51
51
|
</p>
|
|
52
52
|
</div>
|
|
53
53
|
|
|
@@ -55,7 +55,7 @@ Dynamic: requires-python
|
|
|
55
55
|
|
|
56
56
|
<div align="center">
|
|
57
57
|
<p align="center">
|
|
58
|
-
<h3
|
|
58
|
+
<h3>🔥 DBCache: Dual Block Caching for Diffusion Transformers</h3>
|
|
59
59
|
</p>
|
|
60
60
|
</div>
|
|
61
61
|
|
|
@@ -77,7 +77,7 @@ Dynamic: requires-python
|
|
|
77
77
|
|
|
78
78
|
<div align="center">
|
|
79
79
|
<p align="center">
|
|
80
|
-
|
|
80
|
+
DBCache, <b> L20x4 </b>, Steps: 20, case to show the texture recovery ability of DBCache
|
|
81
81
|
</p>
|
|
82
82
|
</div>
|
|
83
83
|
|
|
@@ -85,7 +85,7 @@ These case studies demonstrate that even with relatively high thresholds (such a
|
|
|
85
85
|
|
|
86
86
|
<div align="center">
|
|
87
87
|
<p align="center">
|
|
88
|
-
<h3
|
|
88
|
+
<h3>🔥 DBPrune: Dynamic Block Prune with Residual Caching</h3>
|
|
89
89
|
</p>
|
|
90
90
|
</div>
|
|
91
91
|
|
|
@@ -102,10 +102,10 @@ These case studies demonstrate that even with relatively high thresholds (such a
|
|
|
102
102
|
</p>
|
|
103
103
|
</div>
|
|
104
104
|
|
|
105
|
-
Moreover,
|
|
105
|
+
Moreover, **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.
|
|
106
106
|
|
|
107
107
|
<p align="center">
|
|
108
|
-
|
|
108
|
+
♥️ Please consider to leave a ⭐️ Star to support us ~ ♥️
|
|
109
109
|
</p>
|
|
110
110
|
|
|
111
111
|
## ©️Citations
|
|
@@ -135,7 +135,7 @@ The **CacheDiT** codebase was adapted from FBCache's implementation at the [Para
|
|
|
135
135
|
- [🎉First Block Cache](#fbcache)
|
|
136
136
|
- [⚡️Dynamic Block Prune](#dbprune)
|
|
137
137
|
- [🎉Context Parallelism](#context-parallelism)
|
|
138
|
-
- [
|
|
138
|
+
- [🔥Torch Compile](#compile)
|
|
139
139
|
- [🎉Supported Models](#supported)
|
|
140
140
|
- [👋Contribute](#contribute)
|
|
141
141
|
- [©️License](#license)
|
|
@@ -210,6 +210,17 @@ cache_options = {
|
|
|
210
210
|
}
|
|
211
211
|
```
|
|
212
212
|
|
|
213
|
+
<div align="center">
|
|
214
|
+
<p align="center">
|
|
215
|
+
DBCache, <b> L20x1 </b>, Steps: 28, "A cat holding a sign that says hello world with complex background"
|
|
216
|
+
</p>
|
|
217
|
+
</div>
|
|
218
|
+
|
|
219
|
+
|Baseline(L20x1)|F1B0 (0.08)|F1B0 (0.20)|F8B8 (0.15)|F12B12 (0.20)|F16B16 (0.20)|
|
|
220
|
+
|:---:|:---:|:---:|:---:|:---:|:---:|
|
|
221
|
+
|24.85s|15.59s|8.58s|15.41s|15.11s|17.74s|
|
|
222
|
+
|<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>|
|
|
223
|
+
|
|
213
224
|
## 🎉FBCache: First Block Cache
|
|
214
225
|
|
|
215
226
|
<div id="fbcache"></div>
|
|
@@ -323,14 +334,19 @@ apply_cache_on_pipe(pipe, **cache_options)
|
|
|
323
334
|
pip3 install para-attn # or install `para-attn` from sources.
|
|
324
335
|
```
|
|
325
336
|
|
|
326
|
-
Then, you can run **DBCache** with **Context Parallelism** on 4 GPUs:
|
|
337
|
+
Then, you can run **DBCache** or **DBPrune** with **Context Parallelism** on 4 GPUs:
|
|
327
338
|
|
|
328
339
|
```python
|
|
340
|
+
import torch.distributed as dist
|
|
329
341
|
from diffusers import FluxPipeline
|
|
330
342
|
from para_attn.context_parallel import init_context_parallel_mesh
|
|
331
343
|
from para_attn.context_parallel.diffusers_adapters import parallelize_pipe
|
|
332
344
|
from cache_dit.cache_factory import apply_cache_on_pipe, CacheType
|
|
333
345
|
|
|
346
|
+
# Init distributed process group
|
|
347
|
+
dist.init_process_group()
|
|
348
|
+
torch.cuda.set_device(dist.get_rank())
|
|
349
|
+
|
|
334
350
|
pipe = FluxPipeline.from_pretrained(
|
|
335
351
|
"black-forest-labs/FLUX.1-dev",
|
|
336
352
|
torch_dtype=torch.bfloat16,
|
|
@@ -343,13 +359,31 @@ parallelize_pipe(
|
|
|
343
359
|
)
|
|
344
360
|
)
|
|
345
361
|
|
|
346
|
-
#
|
|
362
|
+
# DBPrune with default options from this library
|
|
347
363
|
apply_cache_on_pipe(
|
|
348
|
-
pipe, **CacheType.default_options(CacheType.
|
|
364
|
+
pipe, **CacheType.default_options(CacheType.DBPrune)
|
|
349
365
|
)
|
|
366
|
+
|
|
367
|
+
dist.destroy_process_group()
|
|
350
368
|
```
|
|
369
|
+
Then, run the python test script with `torchrun`:
|
|
370
|
+
```bash
|
|
371
|
+
torchrun --nproc_per_node=4 parallel_cache.py
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
<div align="center">
|
|
375
|
+
<p align="center">
|
|
376
|
+
DBPrune, <b> L20x4 </b>, Steps: 28, "A cat holding a sign that says hello world with complex background"
|
|
377
|
+
</p>
|
|
378
|
+
</div>
|
|
379
|
+
|
|
380
|
+
|Baseline(L20x1)|Pruned(24%)|Pruned(35%)|Pruned(38%)|Pruned(45%)|Pruned(60%)|
|
|
381
|
+
|:---:|:---:|:---:|:---:|:---:|:---:|
|
|
382
|
+
|24.85s|19.43s|16.82s|15.95s|14.24s|10.66s|
|
|
383
|
+
|8.54s (L20x4)|7.20s (L20x4)|6.61s (L20x4)|6.09s (L20x4)|5.54s (L20x4)|4.22s (L20x4)|
|
|
384
|
+
|<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>|
|
|
351
385
|
|
|
352
|
-
##
|
|
386
|
+
## 🔥Torch Compile
|
|
353
387
|
|
|
354
388
|
<div id="compile"></div>
|
|
355
389
|
|
|
@@ -357,7 +391,7 @@ apply_cache_on_pipe(
|
|
|
357
391
|
|
|
358
392
|
```python
|
|
359
393
|
apply_cache_on_pipe(
|
|
360
|
-
pipe, **CacheType.default_options(CacheType.
|
|
394
|
+
pipe, **CacheType.default_options(CacheType.DBPrune)
|
|
361
395
|
)
|
|
362
396
|
# Compile the Transformer module
|
|
363
397
|
pipe.transformer = torch.compile(pipe.transformer)
|
|
@@ -368,7 +402,7 @@ However, users intending to use **CacheDiT** for DiT with **dynamic input shapes
|
|
|
368
402
|
torch._dynamo.config.recompile_limit = 96 # default is 8
|
|
369
403
|
torch._dynamo.config.accumulated_recompile_limit = 2048 # default is 256
|
|
370
404
|
```
|
|
371
|
-
Otherwise, the recompile_limit error may be triggered, causing the module to fall back to eager mode.
|
|
405
|
+
Otherwise, the recompile_limit error may be triggered, causing the module to fall back to eager mode.
|
|
372
406
|
|
|
373
407
|
## 🎉Supported Models
|
|
374
408
|
|
|
@@ -381,7 +415,7 @@ Otherwise, the recompile_limit error may be triggered, causing the module to fal
|
|
|
381
415
|
## 👋Contribute
|
|
382
416
|
<div id="contribute"></div>
|
|
383
417
|
|
|
384
|
-
How to contribute? Star this repo or check [CONTRIBUTE.md](./CONTRIBUTE.md).
|
|
418
|
+
How to contribute? Star ⭐️ this repo to support us or check [CONTRIBUTE.md](./CONTRIBUTE.md).
|
|
385
419
|
|
|
386
420
|
## ©️License
|
|
387
421
|
|
|
@@ -9,10 +9,10 @@
|
|
|
9
9
|
<img src=https://img.shields.io/badge/PyPI-pass-brightgreen.svg >
|
|
10
10
|
<img src=https://static.pepy.tech/badge/cache-dit >
|
|
11
11
|
<img src=https://img.shields.io/badge/Python-3.10|3.11|3.12-9cf.svg >
|
|
12
|
-
<img src=https://img.shields.io/badge/Release-v0.1.
|
|
12
|
+
<img src=https://img.shields.io/badge/Release-v0.1.7-brightgreen.svg >
|
|
13
13
|
</div>
|
|
14
14
|
<p align="center">
|
|
15
|
-
DeepCache is for UNet not DiT. Most DiT cache speedups are complex and not training-free. CacheDiT
|
|
15
|
+
DeepCache is for UNet not DiT. Most DiT cache speedups are complex and not training-free. CacheDiT <br>offers a set of training-free cache accelerators for DiT: 🔥DBCache, DBPrune, FBCache, etc🔥
|
|
16
16
|
</p>
|
|
17
17
|
</div>
|
|
18
18
|
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
|
|
21
21
|
<div align="center">
|
|
22
22
|
<p align="center">
|
|
23
|
-
<h3
|
|
23
|
+
<h3>🔥 DBCache: Dual Block Caching for Diffusion Transformers</h3>
|
|
24
24
|
</p>
|
|
25
25
|
</div>
|
|
26
26
|
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
|
|
43
43
|
<div align="center">
|
|
44
44
|
<p align="center">
|
|
45
|
-
|
|
45
|
+
DBCache, <b> L20x4 </b>, Steps: 20, case to show the texture recovery ability of DBCache
|
|
46
46
|
</p>
|
|
47
47
|
</div>
|
|
48
48
|
|
|
@@ -50,7 +50,7 @@ These case studies demonstrate that even with relatively high thresholds (such a
|
|
|
50
50
|
|
|
51
51
|
<div align="center">
|
|
52
52
|
<p align="center">
|
|
53
|
-
<h3
|
|
53
|
+
<h3>🔥 DBPrune: Dynamic Block Prune with Residual Caching</h3>
|
|
54
54
|
</p>
|
|
55
55
|
</div>
|
|
56
56
|
|
|
@@ -67,10 +67,10 @@ These case studies demonstrate that even with relatively high thresholds (such a
|
|
|
67
67
|
</p>
|
|
68
68
|
</div>
|
|
69
69
|
|
|
70
|
-
Moreover,
|
|
70
|
+
Moreover, **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.
|
|
71
71
|
|
|
72
72
|
<p align="center">
|
|
73
|
-
|
|
73
|
+
♥️ Please consider to leave a ⭐️ Star to support us ~ ♥️
|
|
74
74
|
</p>
|
|
75
75
|
|
|
76
76
|
## ©️Citations
|
|
@@ -100,7 +100,7 @@ The **CacheDiT** codebase was adapted from FBCache's implementation at the [Para
|
|
|
100
100
|
- [🎉First Block Cache](#fbcache)
|
|
101
101
|
- [⚡️Dynamic Block Prune](#dbprune)
|
|
102
102
|
- [🎉Context Parallelism](#context-parallelism)
|
|
103
|
-
- [
|
|
103
|
+
- [🔥Torch Compile](#compile)
|
|
104
104
|
- [🎉Supported Models](#supported)
|
|
105
105
|
- [👋Contribute](#contribute)
|
|
106
106
|
- [©️License](#license)
|
|
@@ -175,6 +175,17 @@ cache_options = {
|
|
|
175
175
|
}
|
|
176
176
|
```
|
|
177
177
|
|
|
178
|
+
<div align="center">
|
|
179
|
+
<p align="center">
|
|
180
|
+
DBCache, <b> L20x1 </b>, Steps: 28, "A cat holding a sign that says hello world with complex background"
|
|
181
|
+
</p>
|
|
182
|
+
</div>
|
|
183
|
+
|
|
184
|
+
|Baseline(L20x1)|F1B0 (0.08)|F1B0 (0.20)|F8B8 (0.15)|F12B12 (0.20)|F16B16 (0.20)|
|
|
185
|
+
|:---:|:---:|:---:|:---:|:---:|:---:|
|
|
186
|
+
|24.85s|15.59s|8.58s|15.41s|15.11s|17.74s|
|
|
187
|
+
|<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>|
|
|
188
|
+
|
|
178
189
|
## 🎉FBCache: First Block Cache
|
|
179
190
|
|
|
180
191
|
<div id="fbcache"></div>
|
|
@@ -288,14 +299,19 @@ apply_cache_on_pipe(pipe, **cache_options)
|
|
|
288
299
|
pip3 install para-attn # or install `para-attn` from sources.
|
|
289
300
|
```
|
|
290
301
|
|
|
291
|
-
Then, you can run **DBCache** with **Context Parallelism** on 4 GPUs:
|
|
302
|
+
Then, you can run **DBCache** or **DBPrune** with **Context Parallelism** on 4 GPUs:
|
|
292
303
|
|
|
293
304
|
```python
|
|
305
|
+
import torch.distributed as dist
|
|
294
306
|
from diffusers import FluxPipeline
|
|
295
307
|
from para_attn.context_parallel import init_context_parallel_mesh
|
|
296
308
|
from para_attn.context_parallel.diffusers_adapters import parallelize_pipe
|
|
297
309
|
from cache_dit.cache_factory import apply_cache_on_pipe, CacheType
|
|
298
310
|
|
|
311
|
+
# Init distributed process group
|
|
312
|
+
dist.init_process_group()
|
|
313
|
+
torch.cuda.set_device(dist.get_rank())
|
|
314
|
+
|
|
299
315
|
pipe = FluxPipeline.from_pretrained(
|
|
300
316
|
"black-forest-labs/FLUX.1-dev",
|
|
301
317
|
torch_dtype=torch.bfloat16,
|
|
@@ -308,13 +324,31 @@ parallelize_pipe(
|
|
|
308
324
|
)
|
|
309
325
|
)
|
|
310
326
|
|
|
311
|
-
#
|
|
327
|
+
# DBPrune with default options from this library
|
|
312
328
|
apply_cache_on_pipe(
|
|
313
|
-
pipe, **CacheType.default_options(CacheType.
|
|
329
|
+
pipe, **CacheType.default_options(CacheType.DBPrune)
|
|
314
330
|
)
|
|
331
|
+
|
|
332
|
+
dist.destroy_process_group()
|
|
315
333
|
```
|
|
334
|
+
Then, run the python test script with `torchrun`:
|
|
335
|
+
```bash
|
|
336
|
+
torchrun --nproc_per_node=4 parallel_cache.py
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
<div align="center">
|
|
340
|
+
<p align="center">
|
|
341
|
+
DBPrune, <b> L20x4 </b>, Steps: 28, "A cat holding a sign that says hello world with complex background"
|
|
342
|
+
</p>
|
|
343
|
+
</div>
|
|
344
|
+
|
|
345
|
+
|Baseline(L20x1)|Pruned(24%)|Pruned(35%)|Pruned(38%)|Pruned(45%)|Pruned(60%)|
|
|
346
|
+
|:---:|:---:|:---:|:---:|:---:|:---:|
|
|
347
|
+
|24.85s|19.43s|16.82s|15.95s|14.24s|10.66s|
|
|
348
|
+
|8.54s (L20x4)|7.20s (L20x4)|6.61s (L20x4)|6.09s (L20x4)|5.54s (L20x4)|4.22s (L20x4)|
|
|
349
|
+
|<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>|
|
|
316
350
|
|
|
317
|
-
##
|
|
351
|
+
## 🔥Torch Compile
|
|
318
352
|
|
|
319
353
|
<div id="compile"></div>
|
|
320
354
|
|
|
@@ -322,7 +356,7 @@ apply_cache_on_pipe(
|
|
|
322
356
|
|
|
323
357
|
```python
|
|
324
358
|
apply_cache_on_pipe(
|
|
325
|
-
pipe, **CacheType.default_options(CacheType.
|
|
359
|
+
pipe, **CacheType.default_options(CacheType.DBPrune)
|
|
326
360
|
)
|
|
327
361
|
# Compile the Transformer module
|
|
328
362
|
pipe.transformer = torch.compile(pipe.transformer)
|
|
@@ -333,7 +367,7 @@ However, users intending to use **CacheDiT** for DiT with **dynamic input shapes
|
|
|
333
367
|
torch._dynamo.config.recompile_limit = 96 # default is 8
|
|
334
368
|
torch._dynamo.config.accumulated_recompile_limit = 2048 # default is 256
|
|
335
369
|
```
|
|
336
|
-
Otherwise, the recompile_limit error may be triggered, causing the module to fall back to eager mode.
|
|
370
|
+
Otherwise, the recompile_limit error may be triggered, causing the module to fall back to eager mode.
|
|
337
371
|
|
|
338
372
|
## 🎉Supported Models
|
|
339
373
|
|
|
@@ -346,7 +380,7 @@ Otherwise, the recompile_limit error may be triggered, causing the module to fal
|
|
|
346
380
|
## 👋Contribute
|
|
347
381
|
<div id="contribute"></div>
|
|
348
382
|
|
|
349
|
-
How to contribute? Star this repo or check [CONTRIBUTE.md](./CONTRIBUTE.md).
|
|
383
|
+
How to contribute? Star ⭐️ this repo to support us or check [CONTRIBUTE.md](./CONTRIBUTE.md).
|
|
350
384
|
|
|
351
385
|
## ©️License
|
|
352
386
|
|
|
@@ -16,6 +16,7 @@ def get_args() -> argparse.ArgumentParser:
|
|
|
16
16
|
# General arguments
|
|
17
17
|
parser.add_argument("--steps", type=int, default=28)
|
|
18
18
|
parser.add_argument("--repeats", type=int, default=2)
|
|
19
|
+
parser.add_argument("--seed", type=int, default=0)
|
|
19
20
|
parser.add_argument("--cache", type=str, default=None)
|
|
20
21
|
parser.add_argument("--alter", action="store_true", default=False)
|
|
21
22
|
parser.add_argument("--l1-diff", action="store_true", default=False)
|
|
@@ -26,12 +27,9 @@ def get_args() -> argparse.ArgumentParser:
|
|
|
26
27
|
parser.add_argument("--warmup-steps", type=int, default=0)
|
|
27
28
|
parser.add_argument("--max-cached-steps", type=int, default=-1)
|
|
28
29
|
parser.add_argument("--max-pruned-steps", type=int, default=-1)
|
|
29
|
-
parser.add_argument("--
|
|
30
|
-
parser.add_argument(
|
|
31
|
-
|
|
32
|
-
action="store_true",
|
|
33
|
-
default=False,
|
|
34
|
-
)
|
|
30
|
+
parser.add_argument("--ulysses", type=int, default=None)
|
|
31
|
+
parser.add_argument("--compile", action="store_true", default=False)
|
|
32
|
+
parser.add_argument("--gen-device", type=str, default="cuda")
|
|
35
33
|
return parser.parse_args()
|
|
36
34
|
|
|
37
35
|
|
|
@@ -116,10 +114,41 @@ def main():
|
|
|
116
114
|
args = get_args()
|
|
117
115
|
logger.info(f"Arguments: {args}")
|
|
118
116
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
117
|
+
# Context Parallel from ParaAttention
|
|
118
|
+
if args.ulysses is not None:
|
|
119
|
+
try:
|
|
120
|
+
import torch.distributed as dist
|
|
121
|
+
from para_attn.context_parallel import init_context_parallel_mesh
|
|
122
|
+
from para_attn.context_parallel.diffusers_adapters import parallelize_pipe
|
|
123
|
+
|
|
124
|
+
# Initialize distributed process group
|
|
125
|
+
dist.init_process_group()
|
|
126
|
+
torch.cuda.set_device(dist.get_rank())
|
|
127
|
+
|
|
128
|
+
logger.info(f"Ulysses: {args.ulysses}")
|
|
129
|
+
|
|
130
|
+
pipe = FluxPipeline.from_pretrained(
|
|
131
|
+
os.environ.get("FLUX_DIR", "black-forest-labs/FLUX.1-dev"),
|
|
132
|
+
torch_dtype=torch.bfloat16,
|
|
133
|
+
).to("cuda")
|
|
134
|
+
|
|
135
|
+
parallelize_pipe(
|
|
136
|
+
pipe, mesh=init_context_parallel_mesh(
|
|
137
|
+
pipe.device.type, max_ulysses_dim_size=args.ulysses
|
|
138
|
+
)
|
|
139
|
+
)
|
|
140
|
+
except ImportError as e:
|
|
141
|
+
logger.error(
|
|
142
|
+
"para-attn is not installed, please install it "
|
|
143
|
+
"with `pip install para-attn.`"
|
|
144
|
+
)
|
|
145
|
+
args.ulysses = None
|
|
146
|
+
raise e
|
|
147
|
+
else:
|
|
148
|
+
pipe = FluxPipeline.from_pretrained(
|
|
149
|
+
os.environ.get("FLUX_DIR", "black-forest-labs/FLUX.1-dev"),
|
|
150
|
+
torch_dtype=torch.bfloat16,
|
|
151
|
+
).to("cuda")
|
|
123
152
|
|
|
124
153
|
cache_options, cache_type = get_cache_options(args.cache, args)
|
|
125
154
|
|
|
@@ -149,7 +178,7 @@ def main():
|
|
|
149
178
|
image = pipe(
|
|
150
179
|
"A cat holding a sign that says hello world with complex background",
|
|
151
180
|
num_inference_steps=args.steps,
|
|
152
|
-
generator=torch.Generator(
|
|
181
|
+
generator=torch.Generator(args.gen_device).manual_seed(args.seed),
|
|
153
182
|
).images[0]
|
|
154
183
|
end = time.time()
|
|
155
184
|
all_times.append(end - start)
|
|
@@ -191,19 +220,27 @@ def main():
|
|
|
191
220
|
f"Actual Blocks: {actual_blocks}\n"
|
|
192
221
|
f"Pruned Blocks: {pruned_blocks}"
|
|
193
222
|
)
|
|
223
|
+
ulysses = 0 if args.ulysses is None else args.ulysses
|
|
194
224
|
if len(actual_blocks) > 0:
|
|
195
225
|
save_name = (
|
|
196
|
-
f"{
|
|
226
|
+
f"U{ulysses}_C{int(args.compile)}_{cache_type}_"
|
|
227
|
+
f"R{args.rdt}_P{pruned_ratio:.1f}_"
|
|
197
228
|
f"T{mean_time:.2f}s.png"
|
|
198
229
|
)
|
|
199
230
|
else:
|
|
200
231
|
save_name = (
|
|
201
|
-
f"{
|
|
232
|
+
f"U{ulysses}_C{int(args.compile)}_{cache_type}_"
|
|
233
|
+
f"R{args.rdt}_S{cached_stepes}_"
|
|
202
234
|
f"T{mean_time:.2f}s.png"
|
|
203
235
|
)
|
|
204
236
|
image.save(save_name)
|
|
205
237
|
logger.info(f"Image saved as {save_name}")
|
|
206
238
|
|
|
239
|
+
if args.ulysses is not None:
|
|
240
|
+
import torch.distributed as dist
|
|
241
|
+
dist.destroy_process_group()
|
|
242
|
+
logger.info("Distributed process group destroyed.")
|
|
243
|
+
|
|
207
244
|
|
|
208
245
|
if __name__ == "__main__":
|
|
209
246
|
main()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Example requirement, can be anything that pip knows
|
|
2
2
|
# install with `pip install -r requirements.txt`, and make sure that CI does the same
|
|
3
3
|
packaging
|
|
4
|
-
torch
|
|
5
|
-
transformers
|
|
6
|
-
diffusers
|
|
4
|
+
torch>=2.5.1 # torch 2.7.0 is preferred, but 2.5.1 is the minimum required version
|
|
5
|
+
transformers>=4.51.3
|
|
6
|
+
diffusers>=0.33.1
|
{cache_dit-0.1.5 → cache_dit-0.1.7}/src/cache_dit/cache_factory/dynamic_block_prune/prune_context.py
RENAMED
|
@@ -562,7 +562,7 @@ class DBPrunedTransformerBlocks(torch.nn.Module):
|
|
|
562
562
|
torch._dynamo.graph_break()
|
|
563
563
|
|
|
564
564
|
add_pruned_block(self.pruned_blocks_step)
|
|
565
|
-
add_actual_block(self.
|
|
565
|
+
add_actual_block(self.num_transformer_blocks)
|
|
566
566
|
patch_pruned_stats(self.transformer)
|
|
567
567
|
|
|
568
568
|
return (
|
|
@@ -577,7 +577,7 @@ class DBPrunedTransformerBlocks(torch.nn.Module):
|
|
|
577
577
|
|
|
578
578
|
@property
|
|
579
579
|
@torch.compiler.disable
|
|
580
|
-
def
|
|
580
|
+
def num_transformer_blocks(self):
|
|
581
581
|
# Total number of transformer blocks, including single transformer blocks.
|
|
582
582
|
num_blocks = len(self.transformer_blocks)
|
|
583
583
|
if self.single_transformer_blocks is not None:
|
|
@@ -597,7 +597,7 @@ class DBPrunedTransformerBlocks(torch.nn.Module):
|
|
|
597
597
|
@torch.compiler.disable
|
|
598
598
|
def _non_prune_blocks_ids(self):
|
|
599
599
|
# Never prune the first `Fn` and last `Bn` blocks.
|
|
600
|
-
num_blocks = self.
|
|
600
|
+
num_blocks = self.num_transformer_blocks
|
|
601
601
|
Fn_compute_blocks_ = (
|
|
602
602
|
Fn_compute_blocks()
|
|
603
603
|
if Fn_compute_blocks() < num_blocks
|
|
@@ -627,6 +627,10 @@ class DBPrunedTransformerBlocks(torch.nn.Module):
|
|
|
627
627
|
]
|
|
628
628
|
return sorted(non_prune_blocks_ids)
|
|
629
629
|
|
|
630
|
+
# @torch.compile(dynamic=True)
|
|
631
|
+
# mark this function as compile with dynamic=True will
|
|
632
|
+
# cause precision degradate, so, we choose to disable it
|
|
633
|
+
# now, until we find a better solution or fixed the bug.
|
|
630
634
|
@torch.compiler.disable
|
|
631
635
|
def _compute_single_hidden_states_residual(
|
|
632
636
|
self,
|
|
@@ -663,6 +667,10 @@ class DBPrunedTransformerBlocks(torch.nn.Module):
|
|
|
663
667
|
single_encoder_hidden_states_residual,
|
|
664
668
|
)
|
|
665
669
|
|
|
670
|
+
# @torch.compile(dynamic=True)
|
|
671
|
+
# mark this function as compile with dynamic=True will
|
|
672
|
+
# cause precision degradate, so, we choose to disable it
|
|
673
|
+
# now, until we find a better solution or fixed the bug.
|
|
666
674
|
@torch.compiler.disable
|
|
667
675
|
def _split_single_hidden_states(
|
|
668
676
|
self,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cache_dit
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.7
|
|
4
4
|
Summary: 🤗 CacheDiT: A Training-free and Easy-to-use Cache Acceleration Toolbox for Diffusion Transformers
|
|
5
5
|
Author: DefTruth, vipshop.com, etc.
|
|
6
6
|
Maintainer: DefTruth, vipshop.com, etc
|
|
@@ -10,9 +10,9 @@ Requires-Python: >=3.10
|
|
|
10
10
|
Description-Content-Type: text/markdown
|
|
11
11
|
License-File: LICENSE
|
|
12
12
|
Requires-Dist: packaging
|
|
13
|
-
Requires-Dist: torch
|
|
14
|
-
Requires-Dist: transformers
|
|
15
|
-
Requires-Dist: diffusers
|
|
13
|
+
Requires-Dist: torch>=2.5.1
|
|
14
|
+
Requires-Dist: transformers>=4.51.3
|
|
15
|
+
Requires-Dist: diffusers>=0.33.1
|
|
16
16
|
Provides-Extra: all
|
|
17
17
|
Provides-Extra: dev
|
|
18
18
|
Requires-Dist: pre-commit; extra == "dev"
|
|
@@ -44,10 +44,10 @@ Dynamic: requires-python
|
|
|
44
44
|
<img src=https://img.shields.io/badge/PyPI-pass-brightgreen.svg >
|
|
45
45
|
<img src=https://static.pepy.tech/badge/cache-dit >
|
|
46
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.
|
|
47
|
+
<img src=https://img.shields.io/badge/Release-v0.1.7-brightgreen.svg >
|
|
48
48
|
</div>
|
|
49
49
|
<p align="center">
|
|
50
|
-
DeepCache is for UNet not DiT. Most DiT cache speedups are complex and not training-free. CacheDiT
|
|
50
|
+
DeepCache is for UNet not DiT. Most DiT cache speedups are complex and not training-free. CacheDiT <br>offers a set of training-free cache accelerators for DiT: 🔥DBCache, DBPrune, FBCache, etc🔥
|
|
51
51
|
</p>
|
|
52
52
|
</div>
|
|
53
53
|
|
|
@@ -55,7 +55,7 @@ Dynamic: requires-python
|
|
|
55
55
|
|
|
56
56
|
<div align="center">
|
|
57
57
|
<p align="center">
|
|
58
|
-
<h3
|
|
58
|
+
<h3>🔥 DBCache: Dual Block Caching for Diffusion Transformers</h3>
|
|
59
59
|
</p>
|
|
60
60
|
</div>
|
|
61
61
|
|
|
@@ -77,7 +77,7 @@ Dynamic: requires-python
|
|
|
77
77
|
|
|
78
78
|
<div align="center">
|
|
79
79
|
<p align="center">
|
|
80
|
-
|
|
80
|
+
DBCache, <b> L20x4 </b>, Steps: 20, case to show the texture recovery ability of DBCache
|
|
81
81
|
</p>
|
|
82
82
|
</div>
|
|
83
83
|
|
|
@@ -85,7 +85,7 @@ These case studies demonstrate that even with relatively high thresholds (such a
|
|
|
85
85
|
|
|
86
86
|
<div align="center">
|
|
87
87
|
<p align="center">
|
|
88
|
-
<h3
|
|
88
|
+
<h3>🔥 DBPrune: Dynamic Block Prune with Residual Caching</h3>
|
|
89
89
|
</p>
|
|
90
90
|
</div>
|
|
91
91
|
|
|
@@ -102,10 +102,10 @@ These case studies demonstrate that even with relatively high thresholds (such a
|
|
|
102
102
|
</p>
|
|
103
103
|
</div>
|
|
104
104
|
|
|
105
|
-
Moreover,
|
|
105
|
+
Moreover, **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.
|
|
106
106
|
|
|
107
107
|
<p align="center">
|
|
108
|
-
|
|
108
|
+
♥️ Please consider to leave a ⭐️ Star to support us ~ ♥️
|
|
109
109
|
</p>
|
|
110
110
|
|
|
111
111
|
## ©️Citations
|
|
@@ -135,7 +135,7 @@ The **CacheDiT** codebase was adapted from FBCache's implementation at the [Para
|
|
|
135
135
|
- [🎉First Block Cache](#fbcache)
|
|
136
136
|
- [⚡️Dynamic Block Prune](#dbprune)
|
|
137
137
|
- [🎉Context Parallelism](#context-parallelism)
|
|
138
|
-
- [
|
|
138
|
+
- [🔥Torch Compile](#compile)
|
|
139
139
|
- [🎉Supported Models](#supported)
|
|
140
140
|
- [👋Contribute](#contribute)
|
|
141
141
|
- [©️License](#license)
|
|
@@ -210,6 +210,17 @@ cache_options = {
|
|
|
210
210
|
}
|
|
211
211
|
```
|
|
212
212
|
|
|
213
|
+
<div align="center">
|
|
214
|
+
<p align="center">
|
|
215
|
+
DBCache, <b> L20x1 </b>, Steps: 28, "A cat holding a sign that says hello world with complex background"
|
|
216
|
+
</p>
|
|
217
|
+
</div>
|
|
218
|
+
|
|
219
|
+
|Baseline(L20x1)|F1B0 (0.08)|F1B0 (0.20)|F8B8 (0.15)|F12B12 (0.20)|F16B16 (0.20)|
|
|
220
|
+
|:---:|:---:|:---:|:---:|:---:|:---:|
|
|
221
|
+
|24.85s|15.59s|8.58s|15.41s|15.11s|17.74s|
|
|
222
|
+
|<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>|
|
|
223
|
+
|
|
213
224
|
## 🎉FBCache: First Block Cache
|
|
214
225
|
|
|
215
226
|
<div id="fbcache"></div>
|
|
@@ -323,14 +334,19 @@ apply_cache_on_pipe(pipe, **cache_options)
|
|
|
323
334
|
pip3 install para-attn # or install `para-attn` from sources.
|
|
324
335
|
```
|
|
325
336
|
|
|
326
|
-
Then, you can run **DBCache** with **Context Parallelism** on 4 GPUs:
|
|
337
|
+
Then, you can run **DBCache** or **DBPrune** with **Context Parallelism** on 4 GPUs:
|
|
327
338
|
|
|
328
339
|
```python
|
|
340
|
+
import torch.distributed as dist
|
|
329
341
|
from diffusers import FluxPipeline
|
|
330
342
|
from para_attn.context_parallel import init_context_parallel_mesh
|
|
331
343
|
from para_attn.context_parallel.diffusers_adapters import parallelize_pipe
|
|
332
344
|
from cache_dit.cache_factory import apply_cache_on_pipe, CacheType
|
|
333
345
|
|
|
346
|
+
# Init distributed process group
|
|
347
|
+
dist.init_process_group()
|
|
348
|
+
torch.cuda.set_device(dist.get_rank())
|
|
349
|
+
|
|
334
350
|
pipe = FluxPipeline.from_pretrained(
|
|
335
351
|
"black-forest-labs/FLUX.1-dev",
|
|
336
352
|
torch_dtype=torch.bfloat16,
|
|
@@ -343,13 +359,31 @@ parallelize_pipe(
|
|
|
343
359
|
)
|
|
344
360
|
)
|
|
345
361
|
|
|
346
|
-
#
|
|
362
|
+
# DBPrune with default options from this library
|
|
347
363
|
apply_cache_on_pipe(
|
|
348
|
-
pipe, **CacheType.default_options(CacheType.
|
|
364
|
+
pipe, **CacheType.default_options(CacheType.DBPrune)
|
|
349
365
|
)
|
|
366
|
+
|
|
367
|
+
dist.destroy_process_group()
|
|
350
368
|
```
|
|
369
|
+
Then, run the python test script with `torchrun`:
|
|
370
|
+
```bash
|
|
371
|
+
torchrun --nproc_per_node=4 parallel_cache.py
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
<div align="center">
|
|
375
|
+
<p align="center">
|
|
376
|
+
DBPrune, <b> L20x4 </b>, Steps: 28, "A cat holding a sign that says hello world with complex background"
|
|
377
|
+
</p>
|
|
378
|
+
</div>
|
|
379
|
+
|
|
380
|
+
|Baseline(L20x1)|Pruned(24%)|Pruned(35%)|Pruned(38%)|Pruned(45%)|Pruned(60%)|
|
|
381
|
+
|:---:|:---:|:---:|:---:|:---:|:---:|
|
|
382
|
+
|24.85s|19.43s|16.82s|15.95s|14.24s|10.66s|
|
|
383
|
+
|8.54s (L20x4)|7.20s (L20x4)|6.61s (L20x4)|6.09s (L20x4)|5.54s (L20x4)|4.22s (L20x4)|
|
|
384
|
+
|<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>|
|
|
351
385
|
|
|
352
|
-
##
|
|
386
|
+
## 🔥Torch Compile
|
|
353
387
|
|
|
354
388
|
<div id="compile"></div>
|
|
355
389
|
|
|
@@ -357,7 +391,7 @@ apply_cache_on_pipe(
|
|
|
357
391
|
|
|
358
392
|
```python
|
|
359
393
|
apply_cache_on_pipe(
|
|
360
|
-
pipe, **CacheType.default_options(CacheType.
|
|
394
|
+
pipe, **CacheType.default_options(CacheType.DBPrune)
|
|
361
395
|
)
|
|
362
396
|
# Compile the Transformer module
|
|
363
397
|
pipe.transformer = torch.compile(pipe.transformer)
|
|
@@ -368,7 +402,7 @@ However, users intending to use **CacheDiT** for DiT with **dynamic input shapes
|
|
|
368
402
|
torch._dynamo.config.recompile_limit = 96 # default is 8
|
|
369
403
|
torch._dynamo.config.accumulated_recompile_limit = 2048 # default is 256
|
|
370
404
|
```
|
|
371
|
-
Otherwise, the recompile_limit error may be triggered, causing the module to fall back to eager mode.
|
|
405
|
+
Otherwise, the recompile_limit error may be triggered, causing the module to fall back to eager mode.
|
|
372
406
|
|
|
373
407
|
## 🎉Supported Models
|
|
374
408
|
|
|
@@ -381,7 +415,7 @@ Otherwise, the recompile_limit error may be triggered, causing the module to fal
|
|
|
381
415
|
## 👋Contribute
|
|
382
416
|
<div id="contribute"></div>
|
|
383
417
|
|
|
384
|
-
How to contribute? Star this repo or check [CONTRIBUTE.md](./CONTRIBUTE.md).
|
|
418
|
+
How to contribute? Star ⭐️ this repo to support us or check [CONTRIBUTE.md](./CONTRIBUTE.md).
|
|
385
419
|
|
|
386
420
|
## ©️License
|
|
387
421
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{cache_dit-0.1.5 → cache_dit-0.1.7}/src/cache_dit/cache_factory/dual_block_cache/__init__.py
RENAMED
|
File without changes
|
{cache_dit-0.1.5 → cache_dit-0.1.7}/src/cache_dit/cache_factory/dual_block_cache/cache_context.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{cache_dit-0.1.5 → cache_dit-0.1.7}/src/cache_dit/cache_factory/dynamic_block_prune/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{cache_dit-0.1.5 → cache_dit-0.1.7}/src/cache_dit/cache_factory/first_block_cache/__init__.py
RENAMED
|
File without changes
|
{cache_dit-0.1.5 → cache_dit-0.1.7}/src/cache_dit/cache_factory/first_block_cache/cache_context.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|