cache-dit 0.2.1__tar.gz → 0.2.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of cache-dit might be problematic. Click here for more details.
- {cache_dit-0.2.1 → cache_dit-0.2.3}/PKG-INFO +76 -39
- {cache_dit-0.2.1 → cache_dit-0.2.3}/README.md +75 -38
- cache_dit-0.2.3/assets/TEXTURE_DBCACHE_F1B0_R0.08.png +0 -0
- cache_dit-0.2.3/assets/TEXTURE_DBCACHE_F8B12_R0.12.png +0 -0
- cache_dit-0.2.3/assets/TEXTURE_DBCACHE_F8B16_R0.2.png +0 -0
- cache_dit-0.2.3/assets/TEXTURE_DBCACHE_F8B20_R0.2.png +0 -0
- cache_dit-0.2.3/assets/TEXTURE_DBCACHE_F8B8_R0.12.png +0 -0
- cache_dit-0.2.3/assets/TEXTURE_NONE_R0.08.png +0 -0
- cache_dit-0.2.3/assets/U0_C0_DBCACHE_F1B0S1W0T0ET0_R0.12_S14_T12.85s.png +0 -0
- cache_dit-0.2.3/assets/U0_C0_DBCACHE_F1B0S1W0T0ET0_R0.15_S17_T10.27s.png +0 -0
- cache_dit-0.2.3/assets/U0_C0_DBCACHE_F1B0S1W0T1ET1_R0.12_S14_T12.86s.png +0 -0
- cache_dit-0.2.3/assets/U0_C0_DBCACHE_F1B0S1W0T1ET1_R0.15_S17_T10.28s.png +0 -0
- cache_dit-0.2.3/assets/U0_C1_DBCACHE_F1B0S1W0T1ET1_R0.15_S17_T8.48s.png +0 -0
- cache_dit-0.2.3/assets/cache-dit-v1.png +0 -0
- cache_dit-0.2.3/assets/dbcache-fnbn-v1.png +0 -0
- cache_dit-0.2.3/assets/dbcache-v1.png +0 -0
- cache_dit-0.2.3/assets/dbprune-v1.png +0 -0
- cache_dit-0.2.3/assets/fbcache-v1.png +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/bench/bench.py +46 -8
- {cache_dit-0.2.1 → cache_dit-0.2.3}/src/cache_dit/_version.py +2 -2
- {cache_dit-0.2.1 → cache_dit-0.2.3}/src/cache_dit/cache_factory/dual_block_cache/cache_context.py +282 -57
- {cache_dit-0.2.1 → cache_dit-0.2.3}/src/cache_dit/cache_factory/dual_block_cache/diffusers_adapters/__init__.py +0 -2
- {cache_dit-0.2.1 → cache_dit-0.2.3}/src/cache_dit/cache_factory/dual_block_cache/diffusers_adapters/cogvideox.py +0 -2
- {cache_dit-0.2.1 → cache_dit-0.2.3}/src/cache_dit/cache_factory/dual_block_cache/diffusers_adapters/flux.py +0 -2
- {cache_dit-0.2.1 → cache_dit-0.2.3}/src/cache_dit/cache_factory/dual_block_cache/diffusers_adapters/hunyuan_video.py +0 -1
- {cache_dit-0.2.1 → cache_dit-0.2.3}/src/cache_dit/cache_factory/dual_block_cache/diffusers_adapters/mochi.py +0 -1
- {cache_dit-0.2.1 → cache_dit-0.2.3}/src/cache_dit/cache_factory/dual_block_cache/diffusers_adapters/wan.py +1 -3
- {cache_dit-0.2.1 → cache_dit-0.2.3}/src/cache_dit/cache_factory/dynamic_block_prune/diffusers_adapters/__init__.py +0 -2
- {cache_dit-0.2.1 → cache_dit-0.2.3}/src/cache_dit/cache_factory/dynamic_block_prune/diffusers_adapters/cogvideox.py +0 -2
- {cache_dit-0.2.1 → cache_dit-0.2.3}/src/cache_dit/cache_factory/dynamic_block_prune/diffusers_adapters/flux.py +0 -2
- {cache_dit-0.2.1 → cache_dit-0.2.3}/src/cache_dit/cache_factory/dynamic_block_prune/diffusers_adapters/hunyuan_video.py +0 -1
- {cache_dit-0.2.1 → cache_dit-0.2.3}/src/cache_dit/cache_factory/dynamic_block_prune/diffusers_adapters/mochi.py +0 -2
- {cache_dit-0.2.1 → cache_dit-0.2.3}/src/cache_dit/cache_factory/dynamic_block_prune/diffusers_adapters/wan.py +0 -2
- {cache_dit-0.2.1 → cache_dit-0.2.3}/src/cache_dit/cache_factory/dynamic_block_prune/prune_context.py +23 -23
- {cache_dit-0.2.1 → cache_dit-0.2.3}/src/cache_dit/cache_factory/first_block_cache/cache_context.py +3 -11
- {cache_dit-0.2.1 → cache_dit-0.2.3}/src/cache_dit/cache_factory/taylorseer.py +29 -0
- cache_dit-0.2.3/src/cache_dit/compile/__init__.py +1 -0
- cache_dit-0.2.3/src/cache_dit/compile/utils.py +94 -0
- cache_dit-0.2.3/src/cache_dit/custom_ops/__init__.py +0 -0
- cache_dit-0.2.3/src/cache_dit/custom_ops/triton_taylorseer.py +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/src/cache_dit/logger.py +28 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/src/cache_dit.egg-info/PKG-INFO +76 -39
- {cache_dit-0.2.1 → cache_dit-0.2.3}/src/cache_dit.egg-info/SOURCES.txt +27 -3
- cache_dit-0.2.3/tests/.gitignore +167 -0
- cache_dit-0.2.3/tests/README.md +9 -0
- cache_dit-0.2.3/tests/taylorseer_approximation_order_2.png +0 -0
- cache_dit-0.2.3/tests/taylorseer_approximation_order_4.png +0 -0
- cache_dit-0.2.3/tests/taylorseer_approximation_test.png +0 -0
- cache_dit-0.2.3/tests/test_taylorseer.py +81 -0
- cache_dit-0.2.1/assets/DBCache.png +0 -0
- cache_dit-0.2.1/assets/cache-dit.png +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/.github/workflows/issue.yml +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/.gitignore +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/.pre-commit-config.yaml +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/CONTRIBUTE.md +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/LICENSE +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/MANIFEST.in +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/assets/DBCACHE_F12B12S4_R0.2_S16.png +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/assets/DBCACHE_F12B16S4_R0.08_S6.png +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/assets/DBCACHE_F16B16S2_R0.2_S14.png +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/assets/DBCACHE_F16B16S4_R0.2_S13.png +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/assets/DBCACHE_F1B0S1_R0.08_S11.png +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/assets/DBCACHE_F1B0S1_R0.2_S19.png +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/assets/DBCACHE_F8B0S2_R0.12_S12.png +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/assets/DBCACHE_F8B16S1_R0.2_S18.png +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/assets/DBCACHE_F8B8S1_R0.08_S9.png +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/assets/DBCACHE_F8B8S1_R0.12_S12.png +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/assets/DBCACHE_F8B8S1_R0.15_S15.png +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/assets/DBPRUNE_F1B0_R0.03_P24.0_T19.43s.png +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/assets/DBPRUNE_F1B0_R0.04_P34.6_T16.82s.png +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/assets/DBPRUNE_F1B0_R0.05_P38.3_T15.95s.png +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/assets/DBPRUNE_F1B0_R0.06_P45.2_T14.24s.png +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/assets/DBPRUNE_F1B0_R0.07_P52.3_T12.53s.png +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/assets/DBPRUNE_F1B0_R0.08_P52.4_T12.52s.png +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/assets/DBPRUNE_F1B0_R0.09_P59.2_T10.81s.png +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/assets/DBPRUNE_F1B0_R0.12_P59.5_T10.76s.png +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/assets/DBPRUNE_F1B0_R0.12_P63.0_T9.90s.png +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/assets/DBPRUNE_F1B0_R0.1_P62.8_T9.95s.png +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/assets/DBPRUNE_F1B0_R0.2_P59.5_T10.66s.png +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/assets/DBPRUNE_F1B0_R0.3_P63.1_T9.79s.png +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/assets/NONE_R0.08_S0.png +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/assets/U0_C1_DBPRUNE_F1B0_R0.03_P24.0_T16.25s.png +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/assets/U0_C1_DBPRUNE_F1B0_R0.045_P38.2_T13.41s.png +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/assets/U0_C1_DBPRUNE_F1B0_R0.04_P34.6_T14.12s.png +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/assets/U0_C1_DBPRUNE_F1B0_R0.055_P45.1_T12.00s.png +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/assets/U0_C1_DBPRUNE_F1B0_R0.05_P41.6_T12.70s.png +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/assets/U0_C1_DBPRUNE_F1B0_R0.2_P59.5_T8.86s.png +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/assets/U0_C1_DBPRUNE_F8B8_R0.08_P23.1_T16.14s.png +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/assets/U0_C1_NONE_R0.08_S0_T20.43s.png +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/assets/U4_C1_DBPRUNE_F1B0_R0.03_P27.3_T6.62s.png +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/assets/U4_C1_DBPRUNE_F1B0_R0.03_P27.3_T6.63s.png +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/assets/U4_C1_DBPRUNE_F1B0_R0.045_P38.2_T5.81s.png +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/assets/U4_C1_DBPRUNE_F1B0_R0.045_P38.2_T5.82s.png +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/assets/U4_C1_DBPRUNE_F1B0_R0.04_P34.6_T6.06s.png +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/assets/U4_C1_DBPRUNE_F1B0_R0.04_P34.6_T6.07s.png +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/assets/U4_C1_DBPRUNE_F1B0_R0.04_P34.6_T6.08s.png +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/assets/U4_C1_DBPRUNE_F1B0_R0.055_P45.1_T5.27s.png +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/assets/U4_C1_DBPRUNE_F1B0_R0.055_P45.1_T5.28s.png +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/assets/U4_C1_DBPRUNE_F1B0_R0.2_P59.5_T3.95s.png +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/assets/U4_C1_DBPRUNE_F1B0_R0.2_P59.5_T3.96s.png +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/assets/U4_C1_NONE_R0.08_S0_T7.78s.png +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/assets/U4_C1_NONE_R0.08_S0_T7.79s.png +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/bench/.gitignore +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/docs/.gitignore +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/examples/.gitignore +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/examples/README.md +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/examples/data/cup.png +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/examples/data/cup_mask.png +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/examples/requirements.txt +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/examples/run_cogvideox.py +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/examples/run_flux.py +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/examples/run_flux_fill.py +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/examples/run_hunyuan_video.py +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/examples/run_mochi.py +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/examples/run_wan.py +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/pyproject.toml +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/pytest.ini +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/requirements.txt +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/setup.cfg +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/setup.py +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/src/cache_dit/__init__.py +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/src/cache_dit/cache_factory/__init__.py +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/src/cache_dit/cache_factory/dual_block_cache/__init__.py +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/src/cache_dit/cache_factory/dynamic_block_prune/__init__.py +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/src/cache_dit/cache_factory/first_block_cache/__init__.py +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/src/cache_dit/cache_factory/first_block_cache/diffusers_adapters/__init__.py +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/src/cache_dit/cache_factory/first_block_cache/diffusers_adapters/cogvideox.py +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/src/cache_dit/cache_factory/first_block_cache/diffusers_adapters/flux.py +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/src/cache_dit/cache_factory/first_block_cache/diffusers_adapters/hunyuan_video.py +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/src/cache_dit/cache_factory/first_block_cache/diffusers_adapters/mochi.py +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/src/cache_dit/cache_factory/first_block_cache/diffusers_adapters/wan.py +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/src/cache_dit/cache_factory/utils.py +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/src/cache_dit/primitives.py +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/src/cache_dit.egg-info/dependency_links.txt +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/src/cache_dit.egg-info/requires.txt +0 -0
- {cache_dit-0.2.1 → cache_dit-0.2.3}/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.2.
|
|
3
|
+
Version: 0.2.3
|
|
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
|
|
@@ -37,31 +37,31 @@ Dynamic: requires-python
|
|
|
37
37
|
<p align="center">
|
|
38
38
|
<h2>🤗 CacheDiT: A Training-free and Easy-to-use Cache Acceleration <br>Toolbox for Diffusion Transformers</h2>
|
|
39
39
|
</p>
|
|
40
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/cache-dit.png >
|
|
40
|
+
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/cache-dit-v1.png >
|
|
41
41
|
<div align='center'>
|
|
42
42
|
<img src=https://img.shields.io/badge/Language-Python-brightgreen.svg >
|
|
43
43
|
<img src=https://img.shields.io/badge/PRs-welcome-9cf.svg >
|
|
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.2.
|
|
47
|
+
<img src=https://img.shields.io/badge/Release-v0.2.2-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 <br>
|
|
50
|
+
DeepCache is for UNet not DiT. Most DiT cache speedups are complex and not training-free. CacheDiT offers <br>a set of training-free cache accelerators for DiT: <b>🔥<a href="#dbcache">DBCache</a>, <a href="#dbprune">DBPrune</a>, <a href="#taylorseer">TaylorSeer</a>, <a href="#fbcache">FBCache</a></b>, etc🔥
|
|
51
51
|
</p>
|
|
52
52
|
</div>
|
|
53
53
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
<
|
|
57
|
-
|
|
58
|
-
|
|
54
|
+
<div align="center">
|
|
55
|
+
<p align="center">
|
|
56
|
+
<b>♥️ Please consider to leave a ⭐️ Star to support us ~ ♥️</b>
|
|
57
|
+
</p>
|
|
58
|
+
</div>
|
|
59
59
|
|
|
60
60
|
## 🤗 Introduction
|
|
61
61
|
|
|
62
62
|
<div align="center">
|
|
63
63
|
<p align="center">
|
|
64
|
-
<h3>🔥
|
|
64
|
+
<h3>🔥DBCache: Dual Block Caching for Diffusion Transformers</h3>
|
|
65
65
|
</p>
|
|
66
66
|
</div>
|
|
67
67
|
|
|
@@ -77,9 +77,9 @@ The **CacheDiT** codebase is adapted from [FBCache](https://github.com/chengzeyi
|
|
|
77
77
|
|:---:|:---:|:---:|:---:|:---:|:---:|
|
|
78
78
|
|24.85s|15.59s|8.58s|15.41s|15.11s|17.74s|
|
|
79
79
|
|<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>|
|
|
80
|
-
|**Baseline(L20x1)**|**F1B0 (0.08)**|**F8B8 (0.12)**|**F8B12 (0.
|
|
80
|
+
|**Baseline(L20x1)**|**F1B0 (0.08)**|**F8B8 (0.12)**|**F8B12 (0.12)**|**F8B16 (0.20)**|**F8B20 (0.20)**|
|
|
81
81
|
|27.85s|6.04s|5.88s|5.77s|6.01s|6.20s|
|
|
82
|
-
|<img src=https://github.com/
|
|
82
|
+
|<img src=https://github.com/vipshop/cache-dit/raw/main/assets/TEXTURE_NONE_R0.08.png width=105px>|<img src=https://github.com/vipshop/cache-dit/raw/main/assets/TEXTURE_DBCACHE_F1B0_R0.08.png width=105px> |<img src=https://github.com/vipshop/cache-dit/raw/main/assets/TEXTURE_DBCACHE_F8B8_R0.12.png width=105px>|<img src=https://github.com/vipshop/cache-dit/raw/main/assets/TEXTURE_DBCACHE_F8B12_R0.12.png width=105px>|<img src=https://github.com/vipshop/cache-dit/raw/main/assets/TEXTURE_DBCACHE_F8B16_R0.2.png width=105px>|<img src=https://github.com/vipshop/cache-dit/raw/main/assets/TEXTURE_DBCACHE_F8B20_R0.2.png width=105px>|
|
|
83
83
|
|
|
84
84
|
<div align="center">
|
|
85
85
|
<p align="center">
|
|
@@ -91,7 +91,7 @@ These case studies demonstrate that even with relatively high thresholds (such a
|
|
|
91
91
|
|
|
92
92
|
<div align="center">
|
|
93
93
|
<p align="center">
|
|
94
|
-
<h3>🔥
|
|
94
|
+
<h3>🔥DBPrune: Dynamic Block Prune with Residual Caching</h3>
|
|
95
95
|
</p>
|
|
96
96
|
</div>
|
|
97
97
|
|
|
@@ -110,11 +110,11 @@ These case studies demonstrate that even with relatively high thresholds (such a
|
|
|
110
110
|
|
|
111
111
|
<div align="center">
|
|
112
112
|
<p align="center">
|
|
113
|
-
<h3>🔥
|
|
113
|
+
<h3>🔥Context Parallelism and Torch Compile</h3>
|
|
114
114
|
</p>
|
|
115
115
|
</div>
|
|
116
116
|
|
|
117
|
-
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.
|
|
117
|
+
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. CacheDiT is designed to work compatibly with **torch.compile.** You can easily use CacheDiT with torch.compile to further achieve a better performance.
|
|
118
118
|
|
|
119
119
|
<div align="center">
|
|
120
120
|
<p align="center">
|
|
@@ -128,12 +128,6 @@ Moreover, **CacheDiT** are **plug-and-play** solutions that works hand-in-hand w
|
|
|
128
128
|
|+L20x4:7.75s|6.62s|6.03s|5.81s|5.24s|3.93s|
|
|
129
129
|
|<img src=https://github.com/vipshop/cache-dit/raw/main/assets/U0_C1_NONE_R0.08_S0_T20.43s.png width=105px>|<img src=https://github.com/vipshop/cache-dit/raw/main/assets/U0_C1_DBPRUNE_F1B0_R0.03_P24.0_T16.25s.png width=105px> | <img src=https://github.com/vipshop/cache-dit/raw/main/assets/U0_C1_DBPRUNE_F1B0_R0.04_P34.6_T14.12s.png width=105px>|<img src=https://github.com/vipshop/cache-dit/raw/main/assets/U0_C1_DBPRUNE_F1B0_R0.045_P38.2_T13.41s.png width=105px>|<img src=https://github.com/vipshop/cache-dit/raw/main/assets/U0_C1_DBPRUNE_F1B0_R0.055_P45.1_T12.00s.png width=105px>|<img src=https://github.com/vipshop/cache-dit/raw/main/assets/U0_C1_DBPRUNE_F1B0_R0.2_P59.5_T8.86s.png width=105px>|
|
|
130
130
|
|
|
131
|
-
<div align="center">
|
|
132
|
-
<p align="center">
|
|
133
|
-
<b>♥️ Please consider to leave a ⭐️ Star to support us ~ ♥️</b>
|
|
134
|
-
</p>
|
|
135
|
-
</div>
|
|
136
|
-
|
|
137
131
|
## ©️Citations
|
|
138
132
|
|
|
139
133
|
```BibTeX
|
|
@@ -146,6 +140,12 @@ Moreover, **CacheDiT** are **plug-and-play** solutions that works hand-in-hand w
|
|
|
146
140
|
}
|
|
147
141
|
```
|
|
148
142
|
|
|
143
|
+
## 👋Reference
|
|
144
|
+
|
|
145
|
+
<div id="reference"></div>
|
|
146
|
+
|
|
147
|
+
The **CacheDiT** codebase is adapted from [FBCache](https://github.com/chengzeyi/ParaAttention/tree/main/src/para_attn/first_block_cache). Special thanks to their excellent work!
|
|
148
|
+
|
|
149
149
|
## 📖Contents
|
|
150
150
|
|
|
151
151
|
<div id="contents"></div>
|
|
@@ -153,6 +153,7 @@ Moreover, **CacheDiT** are **plug-and-play** solutions that works hand-in-hand w
|
|
|
153
153
|
- [⚙️Installation](#️installation)
|
|
154
154
|
- [🔥Supported Models](#supported)
|
|
155
155
|
- [⚡️Dual Block Cache](#dbcache)
|
|
156
|
+
- [🔥Hybrid TaylorSeer](#taylorseer)
|
|
156
157
|
- [🎉First Block Cache](#fbcache)
|
|
157
158
|
- [⚡️Dynamic Block Prune](#dbprune)
|
|
158
159
|
- [🎉Context Parallelism](#context-parallelism)
|
|
@@ -187,28 +188,19 @@ pip3 install git+https://github.com/vipshop/cache-dit.git
|
|
|
187
188
|
- [🚀HunyuanVideo](https://github.com/vipshop/cache-dit/raw/main/examples)
|
|
188
189
|
|
|
189
190
|
|
|
190
|
-
<!--
|
|
191
|
-
<p align="center">
|
|
192
|
-
<h4> 🔥Supported Models🔥</h4>
|
|
193
|
-
<a href=https://github.com/vipshop/cache-dit/raw/main/examples> <b>🚀FLUX.1</b>: ✔️DBCache, ✔️DBPrune, ✔️FBCache🔥</a> <br>
|
|
194
|
-
<a href=https://github.com/vipshop/cache-dit/raw/main/examples> <b>🚀Mochi</b>: ✔️DBCache, ✔️DBPrune, ✔️FBCache🔥</a> <br>
|
|
195
|
-
<a href=https://github.com/vipshop/cache-dit/raw/main/examples> <b>🚀CogVideoX</b>: ✔️DBCache, ✔️DBPrune, ✔️FBCache🔥</a> <br>
|
|
196
|
-
<a href=https://github.com/vipshop/cache-dit/raw/main/examples> <b>🚀CogVideoX1.5</b>: ✔️DBCache, ✔️DBPrune, ✔️FBCache🔥</a> <br>
|
|
197
|
-
<a href=https://github.com/vipshop/cache-dit/raw/main/examples> <b>🚀Wan2.1</b>: ✔️DBCache, ✔️DBPrune, ✔️FBCache🔥</a> <br>
|
|
198
|
-
<a href=https://github.com/vipshop/cache-dit/raw/main/examples> <b>🚀HunyuanVideo</b>: ✔️DBCache, ✔️DBPrune, ✔️FBCache🔥</a> <br>
|
|
199
|
-
</p>
|
|
200
|
-
-->
|
|
201
|
-
|
|
202
191
|
## ⚡️DBCache: Dual Block Cache
|
|
203
192
|
|
|
204
193
|
<div id="dbcache"></div>
|
|
205
194
|
|
|
206
|
-

|
|
207
196
|
|
|
208
197
|
**DBCache** provides configurable parameters for custom optimization, enabling a balanced trade-off between performance and precision:
|
|
209
198
|
|
|
210
199
|
- **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.
|
|
211
200
|
- **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.
|
|
201
|
+
|
|
202
|
+

|
|
203
|
+
|
|
212
204
|
- **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.
|
|
213
205
|
- **max_cached_steps**: (default: -1) DBCache disables the caching strategy when the previous cached steps exceed this value to prevent precision degradation.
|
|
214
206
|
- **residual_diff_threshold**: The value of residual diff threshold, a higher value leads to faster performance at the cost of lower precision.
|
|
@@ -264,11 +256,54 @@ cache_options = {
|
|
|
264
256
|
|24.85s|15.59s|8.58s|15.41s|15.11s|17.74s|
|
|
265
257
|
|<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>|
|
|
266
258
|
|
|
259
|
+
## 🔥Hybrid TaylorSeer
|
|
260
|
+
|
|
261
|
+
<div id="taylorseer"></div>
|
|
262
|
+
|
|
263
|
+
We have supported the [TaylorSeers: From Reusing to Forecasting: Accelerating Diffusion Models with TaylorSeers](https://arxiv.org/pdf/2503.06923) algorithm to further improve the precision of DBCache in cases where the cached steps are large, namely, **Hybrid TaylorSeer + DBCache**. At timesteps with significant intervals, the feature similarity in diffusion models decreases substantially, significantly harming the generation quality.
|
|
264
|
+
|
|
265
|
+
$$
|
|
266
|
+
\mathcal{F}\_{\text {pred }, m}\left(x_{t-k}^l\right)=\mathcal{F}\left(x_t^l\right)+\sum_{i=1}^m \frac{\Delta^i \mathcal{F}\left(x_t^l\right)}{i!\cdot N^i}(-k)^i
|
|
267
|
+
$$
|
|
268
|
+
|
|
269
|
+
**TaylorSeer** employs a differential method to approximate the higher-order derivatives of features and predict features in future timesteps with Taylor series expansion. The TaylorSeer implemented in CacheDiT supports both hidden states and residual cache types. That is $\mathcal{F}\_{\text {pred }, m}\left(x_{t-k}^l\right)$ can be a residual cache or a hidden-state cache.
|
|
270
|
+
|
|
271
|
+
```python
|
|
272
|
+
cache_options = {
|
|
273
|
+
# TaylorSeer options
|
|
274
|
+
"enable_taylorseer": True,
|
|
275
|
+
"enable_encoder_taylorseer": True,
|
|
276
|
+
# Taylorseer cache type cache be hidden_states or residual.
|
|
277
|
+
"taylorseer_cache_type": "residual",
|
|
278
|
+
# Higher values of n_derivatives will lead to longer
|
|
279
|
+
# computation time but may improve precision significantly.
|
|
280
|
+
"taylorseer_kwargs": {
|
|
281
|
+
"n_derivatives": 2, # default is 2.
|
|
282
|
+
},
|
|
283
|
+
"warmup_steps": 3, # n_derivatives + 1
|
|
284
|
+
"residual_diff_threshold": 0.12,
|
|
285
|
+
}
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
> [!Important]
|
|
289
|
+
> Please note that if you have used TaylorSeer as the calibrator for approximate hidden states, the **Bn** param of DBCache can be set to **0**. In essence, DBCache's Bn is also act as a calibrator, so you can choose either Bn > 0 or TaylorSeer. We recommend using the configuration scheme of **TaylorSeer** + **DBCache FnB0**.
|
|
290
|
+
|
|
291
|
+
<div align="center">
|
|
292
|
+
<p align="center">
|
|
293
|
+
<b>DBCache F1B0 + TaylorSeer</b>, L20x1, Steps: 28, <br>"A cat holding a sign that says hello world with complex background"
|
|
294
|
+
</p>
|
|
295
|
+
</div>
|
|
296
|
+
|
|
297
|
+
|Baseline(L20x1)|F1B0 (0.12)|+TaylorSeer|F1B0 (0.15)|+TaylorSeer|+compile|
|
|
298
|
+
|:---:|:---:|:---:|:---:|:---:|:---:|
|
|
299
|
+
|24.85s|12.85s|12.86s|10.27s|10.28s|8.48s|
|
|
300
|
+
|<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/U0_C0_DBCACHE_F1B0S1W0T0ET0_R0.12_S14_T12.85s.png width=105px>|<img src=https://github.com/vipshop/cache-dit/raw/main/assets/U0_C0_DBCACHE_F1B0S1W0T1ET1_R0.12_S14_T12.86s.png width=105px>|<img src=https://github.com/vipshop/cache-dit/raw/main/assets/U0_C0_DBCACHE_F1B0S1W0T0ET0_R0.15_S17_T10.27s.png width=105px>|<img src=https://github.com/vipshop/cache-dit/raw/main/assets/U0_C0_DBCACHE_F1B0S1W0T1ET1_R0.15_S17_T10.28s.png width=105px>|<img src=https://github.com/vipshop/cache-dit/raw/main/assets/U0_C1_DBCACHE_F1B0S1W0T1ET1_R0.15_S17_T8.48s.png width=105px>|
|
|
301
|
+
|
|
267
302
|
## 🎉FBCache: First Block Cache
|
|
268
303
|
|
|
269
304
|
<div id="fbcache"></div>
|
|
270
305
|
|
|
271
|
-

|
|
272
307
|
|
|
273
308
|
**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.
|
|
274
309
|
|
|
@@ -302,7 +337,7 @@ apply_cache_on_pipe(pipe, **cache_options)
|
|
|
302
337
|
|
|
303
338
|
<div id="dbprune"></div>
|
|
304
339
|
|
|
305
|
-

|
|
306
341
|
|
|
307
342
|
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.
|
|
308
343
|
|
|
@@ -389,7 +424,7 @@ from para_attn.context_parallel import init_context_parallel_mesh
|
|
|
389
424
|
from para_attn.context_parallel.diffusers_adapters import parallelize_pipe
|
|
390
425
|
from cache_dit.cache_factory import apply_cache_on_pipe, CacheType
|
|
391
426
|
|
|
392
|
-
|
|
427
|
+
# Init distributed process group
|
|
393
428
|
dist.init_process_group()
|
|
394
429
|
torch.cuda.set_device(dist.get_rank())
|
|
395
430
|
|
|
@@ -436,14 +471,16 @@ torch._dynamo.config.recompile_limit = 96 # default is 8
|
|
|
436
471
|
torch._dynamo.config.accumulated_recompile_limit = 2048 # default is 256
|
|
437
472
|
```
|
|
438
473
|
|
|
474
|
+
Please check [bench.py](./bench/bench.py) for more details.
|
|
475
|
+
|
|
439
476
|
## 👋Contribute
|
|
440
477
|
<div id="contribute"></div>
|
|
441
478
|
|
|
442
|
-
How to contribute? Star ⭐️ this repo to support us or check [CONTRIBUTE.md](
|
|
479
|
+
How to contribute? Star ⭐️ this repo to support us or check [CONTRIBUTE.md](https://github.com/vipshop/cache-dit/raw/main/CONTRIBUTE.md).
|
|
443
480
|
|
|
444
481
|
## ©️License
|
|
445
482
|
|
|
446
483
|
<div id="license"></div>
|
|
447
484
|
|
|
448
485
|
|
|
449
|
-
We have followed the original License from [ParaAttention](https://github.com/chengzeyi/ParaAttention), please check [LICENSE](
|
|
486
|
+
We have followed the original License from [ParaAttention](https://github.com/chengzeyi/ParaAttention), please check [LICENSE](https://github.com/vipshop/cache-dit/raw/main/LICENSE) for more details.
|
|
@@ -2,31 +2,31 @@
|
|
|
2
2
|
<p align="center">
|
|
3
3
|
<h2>🤗 CacheDiT: A Training-free and Easy-to-use Cache Acceleration <br>Toolbox for Diffusion Transformers</h2>
|
|
4
4
|
</p>
|
|
5
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/cache-dit.png >
|
|
5
|
+
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/cache-dit-v1.png >
|
|
6
6
|
<div align='center'>
|
|
7
7
|
<img src=https://img.shields.io/badge/Language-Python-brightgreen.svg >
|
|
8
8
|
<img src=https://img.shields.io/badge/PRs-welcome-9cf.svg >
|
|
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.2.
|
|
12
|
+
<img src=https://img.shields.io/badge/Release-v0.2.2-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 <br>
|
|
15
|
+
DeepCache is for UNet not DiT. Most DiT cache speedups are complex and not training-free. CacheDiT offers <br>a set of training-free cache accelerators for DiT: <b>🔥<a href="#dbcache">DBCache</a>, <a href="#dbprune">DBPrune</a>, <a href="#taylorseer">TaylorSeer</a>, <a href="#fbcache">FBCache</a></b>, etc🔥
|
|
16
16
|
</p>
|
|
17
17
|
</div>
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
<
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
<div align="center">
|
|
20
|
+
<p align="center">
|
|
21
|
+
<b>♥️ Please consider to leave a ⭐️ Star to support us ~ ♥️</b>
|
|
22
|
+
</p>
|
|
23
|
+
</div>
|
|
24
24
|
|
|
25
25
|
## 🤗 Introduction
|
|
26
26
|
|
|
27
27
|
<div align="center">
|
|
28
28
|
<p align="center">
|
|
29
|
-
<h3>🔥
|
|
29
|
+
<h3>🔥DBCache: Dual Block Caching for Diffusion Transformers</h3>
|
|
30
30
|
</p>
|
|
31
31
|
</div>
|
|
32
32
|
|
|
@@ -42,9 +42,9 @@ The **CacheDiT** codebase is adapted from [FBCache](https://github.com/chengzeyi
|
|
|
42
42
|
|:---:|:---:|:---:|:---:|:---:|:---:|
|
|
43
43
|
|24.85s|15.59s|8.58s|15.41s|15.11s|17.74s|
|
|
44
44
|
|<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>|
|
|
45
|
-
|**Baseline(L20x1)**|**F1B0 (0.08)**|**F8B8 (0.12)**|**F8B12 (0.
|
|
45
|
+
|**Baseline(L20x1)**|**F1B0 (0.08)**|**F8B8 (0.12)**|**F8B12 (0.12)**|**F8B16 (0.20)**|**F8B20 (0.20)**|
|
|
46
46
|
|27.85s|6.04s|5.88s|5.77s|6.01s|6.20s|
|
|
47
|
-
|<img src=https://github.com/
|
|
47
|
+
|<img src=https://github.com/vipshop/cache-dit/raw/main/assets/TEXTURE_NONE_R0.08.png width=105px>|<img src=https://github.com/vipshop/cache-dit/raw/main/assets/TEXTURE_DBCACHE_F1B0_R0.08.png width=105px> |<img src=https://github.com/vipshop/cache-dit/raw/main/assets/TEXTURE_DBCACHE_F8B8_R0.12.png width=105px>|<img src=https://github.com/vipshop/cache-dit/raw/main/assets/TEXTURE_DBCACHE_F8B12_R0.12.png width=105px>|<img src=https://github.com/vipshop/cache-dit/raw/main/assets/TEXTURE_DBCACHE_F8B16_R0.2.png width=105px>|<img src=https://github.com/vipshop/cache-dit/raw/main/assets/TEXTURE_DBCACHE_F8B20_R0.2.png width=105px>|
|
|
48
48
|
|
|
49
49
|
<div align="center">
|
|
50
50
|
<p align="center">
|
|
@@ -56,7 +56,7 @@ These case studies demonstrate that even with relatively high thresholds (such a
|
|
|
56
56
|
|
|
57
57
|
<div align="center">
|
|
58
58
|
<p align="center">
|
|
59
|
-
<h3>🔥
|
|
59
|
+
<h3>🔥DBPrune: Dynamic Block Prune with Residual Caching</h3>
|
|
60
60
|
</p>
|
|
61
61
|
</div>
|
|
62
62
|
|
|
@@ -75,11 +75,11 @@ These case studies demonstrate that even with relatively high thresholds (such a
|
|
|
75
75
|
|
|
76
76
|
<div align="center">
|
|
77
77
|
<p align="center">
|
|
78
|
-
<h3>🔥
|
|
78
|
+
<h3>🔥Context Parallelism and Torch Compile</h3>
|
|
79
79
|
</p>
|
|
80
80
|
</div>
|
|
81
81
|
|
|
82
|
-
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.
|
|
82
|
+
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. CacheDiT is designed to work compatibly with **torch.compile.** You can easily use CacheDiT with torch.compile to further achieve a better performance.
|
|
83
83
|
|
|
84
84
|
<div align="center">
|
|
85
85
|
<p align="center">
|
|
@@ -93,12 +93,6 @@ Moreover, **CacheDiT** are **plug-and-play** solutions that works hand-in-hand w
|
|
|
93
93
|
|+L20x4:7.75s|6.62s|6.03s|5.81s|5.24s|3.93s|
|
|
94
94
|
|<img src=https://github.com/vipshop/cache-dit/raw/main/assets/U0_C1_NONE_R0.08_S0_T20.43s.png width=105px>|<img src=https://github.com/vipshop/cache-dit/raw/main/assets/U0_C1_DBPRUNE_F1B0_R0.03_P24.0_T16.25s.png width=105px> | <img src=https://github.com/vipshop/cache-dit/raw/main/assets/U0_C1_DBPRUNE_F1B0_R0.04_P34.6_T14.12s.png width=105px>|<img src=https://github.com/vipshop/cache-dit/raw/main/assets/U0_C1_DBPRUNE_F1B0_R0.045_P38.2_T13.41s.png width=105px>|<img src=https://github.com/vipshop/cache-dit/raw/main/assets/U0_C1_DBPRUNE_F1B0_R0.055_P45.1_T12.00s.png width=105px>|<img src=https://github.com/vipshop/cache-dit/raw/main/assets/U0_C1_DBPRUNE_F1B0_R0.2_P59.5_T8.86s.png width=105px>|
|
|
95
95
|
|
|
96
|
-
<div align="center">
|
|
97
|
-
<p align="center">
|
|
98
|
-
<b>♥️ Please consider to leave a ⭐️ Star to support us ~ ♥️</b>
|
|
99
|
-
</p>
|
|
100
|
-
</div>
|
|
101
|
-
|
|
102
96
|
## ©️Citations
|
|
103
97
|
|
|
104
98
|
```BibTeX
|
|
@@ -111,6 +105,12 @@ Moreover, **CacheDiT** are **plug-and-play** solutions that works hand-in-hand w
|
|
|
111
105
|
}
|
|
112
106
|
```
|
|
113
107
|
|
|
108
|
+
## 👋Reference
|
|
109
|
+
|
|
110
|
+
<div id="reference"></div>
|
|
111
|
+
|
|
112
|
+
The **CacheDiT** codebase is adapted from [FBCache](https://github.com/chengzeyi/ParaAttention/tree/main/src/para_attn/first_block_cache). Special thanks to their excellent work!
|
|
113
|
+
|
|
114
114
|
## 📖Contents
|
|
115
115
|
|
|
116
116
|
<div id="contents"></div>
|
|
@@ -118,6 +118,7 @@ Moreover, **CacheDiT** are **plug-and-play** solutions that works hand-in-hand w
|
|
|
118
118
|
- [⚙️Installation](#️installation)
|
|
119
119
|
- [🔥Supported Models](#supported)
|
|
120
120
|
- [⚡️Dual Block Cache](#dbcache)
|
|
121
|
+
- [🔥Hybrid TaylorSeer](#taylorseer)
|
|
121
122
|
- [🎉First Block Cache](#fbcache)
|
|
122
123
|
- [⚡️Dynamic Block Prune](#dbprune)
|
|
123
124
|
- [🎉Context Parallelism](#context-parallelism)
|
|
@@ -152,28 +153,19 @@ pip3 install git+https://github.com/vipshop/cache-dit.git
|
|
|
152
153
|
- [🚀HunyuanVideo](https://github.com/vipshop/cache-dit/raw/main/examples)
|
|
153
154
|
|
|
154
155
|
|
|
155
|
-
<!--
|
|
156
|
-
<p align="center">
|
|
157
|
-
<h4> 🔥Supported Models🔥</h4>
|
|
158
|
-
<a href=https://github.com/vipshop/cache-dit/raw/main/examples> <b>🚀FLUX.1</b>: ✔️DBCache, ✔️DBPrune, ✔️FBCache🔥</a> <br>
|
|
159
|
-
<a href=https://github.com/vipshop/cache-dit/raw/main/examples> <b>🚀Mochi</b>: ✔️DBCache, ✔️DBPrune, ✔️FBCache🔥</a> <br>
|
|
160
|
-
<a href=https://github.com/vipshop/cache-dit/raw/main/examples> <b>🚀CogVideoX</b>: ✔️DBCache, ✔️DBPrune, ✔️FBCache🔥</a> <br>
|
|
161
|
-
<a href=https://github.com/vipshop/cache-dit/raw/main/examples> <b>🚀CogVideoX1.5</b>: ✔️DBCache, ✔️DBPrune, ✔️FBCache🔥</a> <br>
|
|
162
|
-
<a href=https://github.com/vipshop/cache-dit/raw/main/examples> <b>🚀Wan2.1</b>: ✔️DBCache, ✔️DBPrune, ✔️FBCache🔥</a> <br>
|
|
163
|
-
<a href=https://github.com/vipshop/cache-dit/raw/main/examples> <b>🚀HunyuanVideo</b>: ✔️DBCache, ✔️DBPrune, ✔️FBCache🔥</a> <br>
|
|
164
|
-
</p>
|
|
165
|
-
-->
|
|
166
|
-
|
|
167
156
|
## ⚡️DBCache: Dual Block Cache
|
|
168
157
|
|
|
169
158
|
<div id="dbcache"></div>
|
|
170
159
|
|
|
171
|
-

|
|
172
161
|
|
|
173
162
|
**DBCache** provides configurable parameters for custom optimization, enabling a balanced trade-off between performance and precision:
|
|
174
163
|
|
|
175
164
|
- **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.
|
|
176
165
|
- **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.
|
|
166
|
+
|
|
167
|
+

|
|
168
|
+
|
|
177
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.
|
|
178
170
|
- **max_cached_steps**: (default: -1) DBCache disables the caching strategy when the previous cached steps exceed this value to prevent precision degradation.
|
|
179
171
|
- **residual_diff_threshold**: The value of residual diff threshold, a higher value leads to faster performance at the cost of lower precision.
|
|
@@ -229,11 +221,54 @@ cache_options = {
|
|
|
229
221
|
|24.85s|15.59s|8.58s|15.41s|15.11s|17.74s|
|
|
230
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>|
|
|
231
223
|
|
|
224
|
+
## 🔥Hybrid TaylorSeer
|
|
225
|
+
|
|
226
|
+
<div id="taylorseer"></div>
|
|
227
|
+
|
|
228
|
+
We have supported the [TaylorSeers: From Reusing to Forecasting: Accelerating Diffusion Models with TaylorSeers](https://arxiv.org/pdf/2503.06923) algorithm to further improve the precision of DBCache in cases where the cached steps are large, namely, **Hybrid TaylorSeer + DBCache**. At timesteps with significant intervals, the feature similarity in diffusion models decreases substantially, significantly harming the generation quality.
|
|
229
|
+
|
|
230
|
+
$$
|
|
231
|
+
\mathcal{F}\_{\text {pred }, m}\left(x_{t-k}^l\right)=\mathcal{F}\left(x_t^l\right)+\sum_{i=1}^m \frac{\Delta^i \mathcal{F}\left(x_t^l\right)}{i!\cdot N^i}(-k)^i
|
|
232
|
+
$$
|
|
233
|
+
|
|
234
|
+
**TaylorSeer** employs a differential method to approximate the higher-order derivatives of features and predict features in future timesteps with Taylor series expansion. The TaylorSeer implemented in CacheDiT supports both hidden states and residual cache types. That is $\mathcal{F}\_{\text {pred }, m}\left(x_{t-k}^l\right)$ can be a residual cache or a hidden-state cache.
|
|
235
|
+
|
|
236
|
+
```python
|
|
237
|
+
cache_options = {
|
|
238
|
+
# TaylorSeer options
|
|
239
|
+
"enable_taylorseer": True,
|
|
240
|
+
"enable_encoder_taylorseer": True,
|
|
241
|
+
# Taylorseer cache type cache be hidden_states or residual.
|
|
242
|
+
"taylorseer_cache_type": "residual",
|
|
243
|
+
# Higher values of n_derivatives will lead to longer
|
|
244
|
+
# computation time but may improve precision significantly.
|
|
245
|
+
"taylorseer_kwargs": {
|
|
246
|
+
"n_derivatives": 2, # default is 2.
|
|
247
|
+
},
|
|
248
|
+
"warmup_steps": 3, # n_derivatives + 1
|
|
249
|
+
"residual_diff_threshold": 0.12,
|
|
250
|
+
}
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
> [!Important]
|
|
254
|
+
> Please note that if you have used TaylorSeer as the calibrator for approximate hidden states, the **Bn** param of DBCache can be set to **0**. In essence, DBCache's Bn is also act as a calibrator, so you can choose either Bn > 0 or TaylorSeer. We recommend using the configuration scheme of **TaylorSeer** + **DBCache FnB0**.
|
|
255
|
+
|
|
256
|
+
<div align="center">
|
|
257
|
+
<p align="center">
|
|
258
|
+
<b>DBCache F1B0 + TaylorSeer</b>, L20x1, Steps: 28, <br>"A cat holding a sign that says hello world with complex background"
|
|
259
|
+
</p>
|
|
260
|
+
</div>
|
|
261
|
+
|
|
262
|
+
|Baseline(L20x1)|F1B0 (0.12)|+TaylorSeer|F1B0 (0.15)|+TaylorSeer|+compile|
|
|
263
|
+
|:---:|:---:|:---:|:---:|:---:|:---:|
|
|
264
|
+
|24.85s|12.85s|12.86s|10.27s|10.28s|8.48s|
|
|
265
|
+
|<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/U0_C0_DBCACHE_F1B0S1W0T0ET0_R0.12_S14_T12.85s.png width=105px>|<img src=https://github.com/vipshop/cache-dit/raw/main/assets/U0_C0_DBCACHE_F1B0S1W0T1ET1_R0.12_S14_T12.86s.png width=105px>|<img src=https://github.com/vipshop/cache-dit/raw/main/assets/U0_C0_DBCACHE_F1B0S1W0T0ET0_R0.15_S17_T10.27s.png width=105px>|<img src=https://github.com/vipshop/cache-dit/raw/main/assets/U0_C0_DBCACHE_F1B0S1W0T1ET1_R0.15_S17_T10.28s.png width=105px>|<img src=https://github.com/vipshop/cache-dit/raw/main/assets/U0_C1_DBCACHE_F1B0S1W0T1ET1_R0.15_S17_T8.48s.png width=105px>|
|
|
266
|
+
|
|
232
267
|
## 🎉FBCache: First Block Cache
|
|
233
268
|
|
|
234
269
|
<div id="fbcache"></div>
|
|
235
270
|
|
|
236
|
-

|
|
237
272
|
|
|
238
273
|
**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.
|
|
239
274
|
|
|
@@ -267,7 +302,7 @@ apply_cache_on_pipe(pipe, **cache_options)
|
|
|
267
302
|
|
|
268
303
|
<div id="dbprune"></div>
|
|
269
304
|
|
|
270
|
-

|
|
271
306
|
|
|
272
307
|
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.
|
|
273
308
|
|
|
@@ -354,7 +389,7 @@ from para_attn.context_parallel import init_context_parallel_mesh
|
|
|
354
389
|
from para_attn.context_parallel.diffusers_adapters import parallelize_pipe
|
|
355
390
|
from cache_dit.cache_factory import apply_cache_on_pipe, CacheType
|
|
356
391
|
|
|
357
|
-
|
|
392
|
+
# Init distributed process group
|
|
358
393
|
dist.init_process_group()
|
|
359
394
|
torch.cuda.set_device(dist.get_rank())
|
|
360
395
|
|
|
@@ -401,14 +436,16 @@ torch._dynamo.config.recompile_limit = 96 # default is 8
|
|
|
401
436
|
torch._dynamo.config.accumulated_recompile_limit = 2048 # default is 256
|
|
402
437
|
```
|
|
403
438
|
|
|
439
|
+
Please check [bench.py](./bench/bench.py) for more details.
|
|
440
|
+
|
|
404
441
|
## 👋Contribute
|
|
405
442
|
<div id="contribute"></div>
|
|
406
443
|
|
|
407
|
-
How to contribute? Star ⭐️ this repo to support us or check [CONTRIBUTE.md](
|
|
444
|
+
How to contribute? Star ⭐️ this repo to support us or check [CONTRIBUTE.md](https://github.com/vipshop/cache-dit/raw/main/CONTRIBUTE.md).
|
|
408
445
|
|
|
409
446
|
## ©️License
|
|
410
447
|
|
|
411
448
|
<div id="license"></div>
|
|
412
449
|
|
|
413
450
|
|
|
414
|
-
We have followed the original License from [ParaAttention](https://github.com/chengzeyi/ParaAttention), please check [LICENSE](
|
|
451
|
+
We have followed the original License from [ParaAttention](https://github.com/chengzeyi/ParaAttention), please check [LICENSE](https://github.com/vipshop/cache-dit/raw/main/LICENSE) for more details.
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|