cache-dit 0.3.2__py3-none-any.whl → 1.0.14__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/__init__.py +37 -19
- cache_dit/_version.py +2 -2
- cache_dit/caching/__init__.py +36 -0
- cache_dit/{cache_factory → caching}/block_adapters/__init__.py +149 -18
- cache_dit/{cache_factory → caching}/block_adapters/block_adapters.py +91 -7
- cache_dit/caching/block_adapters/block_registers.py +118 -0
- cache_dit/caching/cache_adapters/__init__.py +1 -0
- cache_dit/{cache_factory → caching}/cache_adapters/cache_adapter.py +262 -123
- cache_dit/caching/cache_blocks/__init__.py +226 -0
- cache_dit/caching/cache_blocks/offload_utils.py +115 -0
- cache_dit/caching/cache_blocks/pattern_0_1_2.py +26 -0
- cache_dit/caching/cache_blocks/pattern_3_4_5.py +543 -0
- cache_dit/caching/cache_blocks/pattern_base.py +748 -0
- cache_dit/caching/cache_blocks/pattern_utils.py +86 -0
- cache_dit/caching/cache_contexts/__init__.py +28 -0
- cache_dit/caching/cache_contexts/cache_config.py +120 -0
- cache_dit/{cache_factory → caching}/cache_contexts/cache_context.py +29 -90
- cache_dit/{cache_factory → caching}/cache_contexts/cache_manager.py +138 -10
- cache_dit/{cache_factory → caching}/cache_contexts/calibrators/__init__.py +25 -3
- cache_dit/{cache_factory → caching}/cache_contexts/calibrators/foca.py +1 -1
- cache_dit/{cache_factory → caching}/cache_contexts/calibrators/taylorseer.py +81 -9
- cache_dit/caching/cache_contexts/context_manager.py +36 -0
- cache_dit/caching/cache_contexts/prune_config.py +63 -0
- cache_dit/caching/cache_contexts/prune_context.py +155 -0
- cache_dit/caching/cache_contexts/prune_manager.py +167 -0
- cache_dit/caching/cache_interface.py +358 -0
- cache_dit/{cache_factory → caching}/cache_types.py +19 -2
- cache_dit/{cache_factory → caching}/forward_pattern.py +14 -14
- cache_dit/{cache_factory → caching}/params_modifier.py +10 -10
- cache_dit/caching/patch_functors/__init__.py +15 -0
- cache_dit/{cache_factory → caching}/patch_functors/functor_chroma.py +1 -1
- cache_dit/{cache_factory → caching}/patch_functors/functor_dit.py +1 -1
- cache_dit/{cache_factory → caching}/patch_functors/functor_flux.py +1 -1
- cache_dit/{cache_factory → caching}/patch_functors/functor_hidream.py +2 -4
- cache_dit/{cache_factory → caching}/patch_functors/functor_hunyuan_dit.py +1 -1
- cache_dit/caching/patch_functors/functor_qwen_image_controlnet.py +263 -0
- cache_dit/caching/utils.py +68 -0
- cache_dit/metrics/__init__.py +11 -0
- cache_dit/metrics/metrics.py +3 -0
- cache_dit/parallelism/__init__.py +3 -0
- cache_dit/parallelism/backends/native_diffusers/__init__.py +6 -0
- cache_dit/parallelism/backends/native_diffusers/context_parallelism/__init__.py +164 -0
- cache_dit/parallelism/backends/native_diffusers/context_parallelism/attention/__init__.py +4 -0
- cache_dit/parallelism/backends/native_diffusers/context_parallelism/attention/_attention_dispatch.py +304 -0
- cache_dit/parallelism/backends/native_diffusers/context_parallelism/cp_plan_chroma.py +95 -0
- cache_dit/parallelism/backends/native_diffusers/context_parallelism/cp_plan_cogvideox.py +202 -0
- cache_dit/parallelism/backends/native_diffusers/context_parallelism/cp_plan_cogview.py +299 -0
- cache_dit/parallelism/backends/native_diffusers/context_parallelism/cp_plan_cosisid.py +123 -0
- cache_dit/parallelism/backends/native_diffusers/context_parallelism/cp_plan_dit.py +94 -0
- cache_dit/parallelism/backends/native_diffusers/context_parallelism/cp_plan_flux.py +88 -0
- cache_dit/parallelism/backends/native_diffusers/context_parallelism/cp_plan_hunyuan.py +729 -0
- cache_dit/parallelism/backends/native_diffusers/context_parallelism/cp_plan_ltxvideo.py +264 -0
- cache_dit/parallelism/backends/native_diffusers/context_parallelism/cp_plan_nunchaku.py +407 -0
- cache_dit/parallelism/backends/native_diffusers/context_parallelism/cp_plan_pixart.py +285 -0
- cache_dit/parallelism/backends/native_diffusers/context_parallelism/cp_plan_qwen_image.py +104 -0
- cache_dit/parallelism/backends/native_diffusers/context_parallelism/cp_plan_registers.py +84 -0
- cache_dit/parallelism/backends/native_diffusers/context_parallelism/cp_plan_wan.py +101 -0
- cache_dit/parallelism/backends/native_diffusers/context_parallelism/cp_planners.py +117 -0
- cache_dit/parallelism/backends/native_diffusers/parallel_difffusers.py +49 -0
- cache_dit/parallelism/backends/native_diffusers/utils.py +11 -0
- cache_dit/parallelism/backends/native_pytorch/__init__.py +6 -0
- cache_dit/parallelism/backends/native_pytorch/parallel_torch.py +62 -0
- cache_dit/parallelism/backends/native_pytorch/tensor_parallelism/__init__.py +48 -0
- cache_dit/parallelism/backends/native_pytorch/tensor_parallelism/tp_plan_flux.py +171 -0
- cache_dit/parallelism/backends/native_pytorch/tensor_parallelism/tp_plan_kandinsky5.py +79 -0
- cache_dit/parallelism/backends/native_pytorch/tensor_parallelism/tp_plan_qwen_image.py +78 -0
- cache_dit/parallelism/backends/native_pytorch/tensor_parallelism/tp_plan_registers.py +65 -0
- cache_dit/parallelism/backends/native_pytorch/tensor_parallelism/tp_plan_wan.py +153 -0
- cache_dit/parallelism/backends/native_pytorch/tensor_parallelism/tp_planners.py +14 -0
- cache_dit/parallelism/parallel_backend.py +26 -0
- cache_dit/parallelism/parallel_config.py +88 -0
- cache_dit/parallelism/parallel_interface.py +77 -0
- cache_dit/quantize/__init__.py +7 -0
- cache_dit/quantize/backends/__init__.py +1 -0
- cache_dit/quantize/backends/bitsandbytes/__init__.py +0 -0
- cache_dit/quantize/backends/torchao/__init__.py +1 -0
- cache_dit/quantize/{quantize_ao.py → backends/torchao/quantize_ao.py} +44 -30
- cache_dit/quantize/quantize_backend.py +0 -0
- cache_dit/quantize/quantize_config.py +0 -0
- cache_dit/quantize/quantize_interface.py +3 -16
- cache_dit/summary.py +593 -0
- cache_dit/utils.py +46 -290
- cache_dit-1.0.14.dist-info/METADATA +301 -0
- cache_dit-1.0.14.dist-info/RECORD +102 -0
- cache_dit-1.0.14.dist-info/licenses/LICENSE +203 -0
- cache_dit/cache_factory/__init__.py +0 -28
- cache_dit/cache_factory/block_adapters/block_registers.py +0 -90
- cache_dit/cache_factory/cache_adapters/__init__.py +0 -1
- cache_dit/cache_factory/cache_blocks/__init__.py +0 -72
- cache_dit/cache_factory/cache_blocks/pattern_0_1_2.py +0 -16
- cache_dit/cache_factory/cache_blocks/pattern_3_4_5.py +0 -238
- cache_dit/cache_factory/cache_blocks/pattern_base.py +0 -404
- cache_dit/cache_factory/cache_blocks/utils.py +0 -41
- cache_dit/cache_factory/cache_contexts/__init__.py +0 -14
- cache_dit/cache_factory/cache_interface.py +0 -217
- cache_dit/cache_factory/patch_functors/__init__.py +0 -12
- cache_dit/cache_factory/utils.py +0 -57
- cache_dit-0.3.2.dist-info/METADATA +0 -753
- cache_dit-0.3.2.dist-info/RECORD +0 -56
- cache_dit-0.3.2.dist-info/licenses/LICENSE +0 -53
- /cache_dit/{cache_factory → caching}/.gitignore +0 -0
- /cache_dit/{cache_factory → caching}/cache_contexts/calibrators/base.py +0 -0
- /cache_dit/{cache_factory → caching}/patch_functors/functor_base.py +0 -0
- /cache_dit/{custom_ops → kernels}/__init__.py +0 -0
- /cache_dit/{custom_ops → kernels}/triton_taylorseer.py +0 -0
- {cache_dit-0.3.2.dist-info → cache_dit-1.0.14.dist-info}/WHEEL +0 -0
- {cache_dit-0.3.2.dist-info → cache_dit-1.0.14.dist-info}/entry_points.txt +0 -0
- {cache_dit-0.3.2.dist-info → cache_dit-1.0.14.dist-info}/top_level.txt +0 -0
|
@@ -1,753 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: cache_dit
|
|
3
|
-
Version: 0.3.2
|
|
4
|
-
Summary: A Unified, Flexible and Training-free Cache Acceleration Framework for 🤗Diffusers.
|
|
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: pyyaml
|
|
14
|
-
Requires-Dist: torch>=2.7.1
|
|
15
|
-
Requires-Dist: transformers>=4.55.2
|
|
16
|
-
Requires-Dist: diffusers>=0.35.1
|
|
17
|
-
Requires-Dist: scikit-image
|
|
18
|
-
Requires-Dist: scipy
|
|
19
|
-
Requires-Dist: lpips==0.1.4
|
|
20
|
-
Requires-Dist: torchao>=0.12.0
|
|
21
|
-
Requires-Dist: image-reward
|
|
22
|
-
Provides-Extra: all
|
|
23
|
-
Provides-Extra: metrics
|
|
24
|
-
Requires-Dist: image-reward; extra == "metrics"
|
|
25
|
-
Requires-Dist: pytorch-fid; extra == "metrics"
|
|
26
|
-
Requires-Dist: lpips==0.1.4; extra == "metrics"
|
|
27
|
-
Provides-Extra: dev
|
|
28
|
-
Requires-Dist: pre-commit; extra == "dev"
|
|
29
|
-
Requires-Dist: pytest<8.0.0,>=7.0.0; extra == "dev"
|
|
30
|
-
Requires-Dist: pytest-html; extra == "dev"
|
|
31
|
-
Requires-Dist: expecttest; extra == "dev"
|
|
32
|
-
Requires-Dist: hypothesis; extra == "dev"
|
|
33
|
-
Requires-Dist: transformers; extra == "dev"
|
|
34
|
-
Requires-Dist: diffusers; extra == "dev"
|
|
35
|
-
Requires-Dist: accelerate; extra == "dev"
|
|
36
|
-
Requires-Dist: peft; extra == "dev"
|
|
37
|
-
Requires-Dist: protobuf; extra == "dev"
|
|
38
|
-
Requires-Dist: sentencepiece; extra == "dev"
|
|
39
|
-
Requires-Dist: opencv-python-headless; extra == "dev"
|
|
40
|
-
Requires-Dist: ftfy; extra == "dev"
|
|
41
|
-
Requires-Dist: scikit-image; extra == "dev"
|
|
42
|
-
Requires-Dist: pytorch-fid; extra == "dev"
|
|
43
|
-
Dynamic: license-file
|
|
44
|
-
Dynamic: provides-extra
|
|
45
|
-
Dynamic: requires-dist
|
|
46
|
-
Dynamic: requires-python
|
|
47
|
-
|
|
48
|
-
<div align="center">
|
|
49
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/cache-dit-logo.png height="120">
|
|
50
|
-
|
|
51
|
-
<p align="center">
|
|
52
|
-
A <b>Unified</b>, Flexible and Training-free <b>Cache Acceleration</b> Framework for <b>🤗Diffusers</b> <br>
|
|
53
|
-
♥️ Cache Acceleration with <b>One-line</b> Code ~ ♥️
|
|
54
|
-
</p>
|
|
55
|
-
<div align='center'>
|
|
56
|
-
<img src=https://img.shields.io/badge/Language-Python-brightgreen.svg >
|
|
57
|
-
<img src=https://img.shields.io/badge/PRs-welcome-9cf.svg >
|
|
58
|
-
<img src=https://img.shields.io/badge/PyPI-pass-brightgreen.svg >
|
|
59
|
-
<img src=https://static.pepy.tech/badge/cache-dit >
|
|
60
|
-
<img src=https://img.shields.io/badge/Python-3.10|3.11|3.12-9cf.svg >
|
|
61
|
-
<img src=https://img.shields.io/badge/Release-v0.3-brightgreen.svg >
|
|
62
|
-
</div>
|
|
63
|
-
<p align="center">
|
|
64
|
-
<b><a href="#unified">📚Unified Cache APIs</a></b> | <a href="#forward-pattern-matching">📚Forward Pattern Matching</a> | <a href="#automatic-block-adapter">📚Automatic Block Adapter</a><br>
|
|
65
|
-
<a href="#hybird-forward-pattern">📚Hybrid Forward Pattern</a> | <a href="#dbcache">📚DBCache</a> | <a href="#taylorseer">📚TaylorSeer Calibrator</a> | <a href="#cfg">📚Cache CFG</a><br>
|
|
66
|
-
<a href="#benchmarks">📚Text2Image DrawBench</a> | <a href="#benchmarks">📚Text2Image Distillation DrawBench</a>
|
|
67
|
-
</p>
|
|
68
|
-
<p align="center">
|
|
69
|
-
🎉Now, <b>cache-dit</b> covers almost <b>All</b> Diffusers' <b>DiT</b> Pipelines🎉<br>
|
|
70
|
-
🔥<a href="#supported">Qwen-Image</a> | <a href="#supported">FLUX.1</a> | <a href="#supported">Qwen-Image-Lightning</a> | <a href="#supported"> Wan 2.1 </a> | <a href="#supported"> Wan 2.2 </a>🔥<br>
|
|
71
|
-
🔥<a href="#supported">HunyuanImage-2.1</a> | <a href="#supported">HunyuanVideo</a> | <a href="#supported">HunyuanDiT</a> | <a href="#supported">HiDream</a> | <a href="#supported">AuraFlow</a>🔥<br>
|
|
72
|
-
🔥<a href="#supported">CogView3Plus</a> | <a href="#supported">CogView4</a> | <a href="#supported">LTXVideo</a> | <a href="#supported">CogVideoX</a> | <a href="#supported">CogVideoX 1.5</a> | <a href="#supported">ConsisID</a>🔥<br>
|
|
73
|
-
🔥<a href="#supported">Cosmos</a> | <a href="#supported">SkyReelsV2</a> | <a href="#supported">VisualCloze</a> | <a href="#supported">OmniGen 1/2</a> | <a href="#supported">Lumina 1/2</a> | <a href="#supported">PixArt</a>🔥<br>
|
|
74
|
-
🔥<a href="#supported">Chroma</a> | <a href="#supported">Sana</a> | <a href="#supported">Allegro</a> | <a href="#supported">Mochi</a> | <a href="#supported">SD 3/3.5</a> | <a href="#supported">Amused</a> | <a href="#supported"> ... </a> | <a href="#supported">DiT-XL</a>🔥
|
|
75
|
-
</p>
|
|
76
|
-
</div>
|
|
77
|
-
<div align='center'>
|
|
78
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/gifs/wan2.2.C0_Q0_NONE.gif width=124px>
|
|
79
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/gifs/wan2.2.C1_Q0_DBCACHE_F1B0_W2M8MC2_T1O2_R0.08.gif width=124px>
|
|
80
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/gifs/hunyuan_video.C0_L0_Q0_NONE.gif width=126px>
|
|
81
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/gifs/hunyuan_video.C0_L0_Q0_DBCACHE_F1B0_W8M0MC2_T0O2_R0.12_S27.gif width=126px>
|
|
82
|
-
<p><b>🔥Wan2.2 MoE</b> | <a href="https://github.com/vipshop/cache-dit">+cache-dit</a>:2.0x↑🎉 | <b>HunyuanVideo</b> | <a href="https://github.com/vipshop/cache-dit">+cache-dit</a>:2.1x↑🎉</p>
|
|
83
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/qwen-image.C0_Q0_NONE.png width=160px>
|
|
84
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/qwen-image.C1_Q0_DBCACHE_F8B0_W8M0MC0_T1O4_R0.12_S23.png width=160px>
|
|
85
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/flux.C0_Q0_NONE_T23.69s.png width=90px>
|
|
86
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/flux.C0_Q0_DBCACHE_F1B0_W4M0MC0_T1O2_R0.15_S16_T11.39s.png width=90px>
|
|
87
|
-
<p><b>🔥Qwen-Image</b> | <a href="https://github.com/vipshop/cache-dit">+cache-dit</a>:1.8x↑🎉 | <b>FLUX.1-dev</b> | <a href="https://github.com/vipshop/cache-dit">+cache-dit</a>:2.1x↑🎉</p>
|
|
88
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/flux-kontext-cat.C0_L0_Q0_NONE.png width=100px>
|
|
89
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/flux-kontext.C0_L0_Q0_NONE.png width=100px>
|
|
90
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/flux-kontext.C0_L0_Q0_DBCACHE_F8B0_W8M0MC0_T0O2_R0.08_S10.png width=100px>
|
|
91
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/flux-kontext.C0_L0_Q0_DBCACHE_F1B0_W8M0MC2_T0O2_R0.12_S12.png width=100px>
|
|
92
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/flux-kontext.C0_L0_Q0_DBCACHE_F1B0_W2M0MC2_T0O2_R0.15_S15.png width=100px>
|
|
93
|
-
<p><b>🔥FLUX-Kontext-dev</b> | Baseline | <a href="https://github.com/vipshop/cache-dit">+cache-dit</a>:1.3x↑🎉 | 1.7x↑🎉 | 2.0x↑ 🎉</p>
|
|
94
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/qwen-image-lightning.4steps.C0_L1_Q0_NONE.png width=160px>
|
|
95
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/qwen-image-lightning.4steps.C0_L1_Q0_DBCACHE_F16B16_W2M1MC1_T0O2_R0.9_S1.png width=160px>
|
|
96
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/hunyuan-image-2.1.C0_L0_Q1_fp8_w8a16_wo_NONE.png width=90px>
|
|
97
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/hunyuan-image-2.1.C0_L0_Q1_fp8_w8a16_wo_DBCACHE_F8B0_W8M0MC2_T1O2_R0.12_S25.png width=90px>
|
|
98
|
-
<p><b>🔥Qwen...Lightning</b> | <a href="https://github.com/vipshop/cache-dit">+cache-dit</a>:1.14x↑🎉 | <b>HunyuanImage</b> | <a href="https://github.com/vipshop/cache-dit">+cache-dit</a>:1.7x↑🎉</p>
|
|
99
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/examples/data/bear.png width=125px>
|
|
100
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/qwen-image-edit.C0_L0_Q0_NONE.png width=125px>
|
|
101
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/qwen-image-edit.C0_L0_Q0_DBCACHE_F8B0_W8M0MC0_T0O2_R0.08_S18.png width=125px>
|
|
102
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/qwen-image-edit.C0_L0_Q0_DBCACHE_F1B0_W8M0MC2_T0O2_R0.12_S24.png width=125px>
|
|
103
|
-
<p><b>🔥Qwen-Image-Edit</b> | Input w/o Edit | Baseline | <a href="https://github.com/vipshop/cache-dit">+cache-dit</a>:1.6x↑🎉 | 1.9x↑🎉 </p>
|
|
104
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/hidream.C0_L0_Q0_NONE.png width=100px>
|
|
105
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/hidream.C0_L0_Q0_DBCACHE_F1B0_W8M0MC0_T0O2_R0.08_S24.png width=100px>
|
|
106
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/cogview4.C0_L0_Q0_NONE.png width=100px>
|
|
107
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/cogview4.C0_L0_Q0_DBCACHE_F8B0_W8M0MC0_T0O2_R0.08_S15.png width=100px>
|
|
108
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/cogview4.C0_L0_Q0_DBCACHE_F1B0_W4M0MC4_T0O2_R0.2_S22.png width=100px>
|
|
109
|
-
<p><b>🔥HiDream-I1</b> | <a href="https://github.com/vipshop/cache-dit">+cache-dit</a>:1.9x↑🎉 | <b>CogView4</b> | <a href="https://github.com/vipshop/cache-dit">+cache-dit</a>:1.4x↑🎉 | 1.7x↑🎉</p>
|
|
110
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/cogview3_plus.C0_L0_Q0_NONE.png width=100px>
|
|
111
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/cogview3_plus.C0_L0_Q0_DBCACHE_F8B0_W8M0MC0_T0O2_R0.08_S15.png width=100px>
|
|
112
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/cogview3_plus.C0_L0_Q0_DBCACHE_F1B0_W8M0MC2_T0O2_R0.08_S25.png width=100px>
|
|
113
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/chroma1-hd.C0_L0_Q0_NONE.png width=100px>
|
|
114
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/chroma1-hd.C0_L0_Q0_DBCACHE_F1B0_W8M0MC0_T0O2_R0.08_S20.png width=100px>
|
|
115
|
-
<p><b>🔥CogView3</b> | <a href="https://github.com/vipshop/cache-dit">+cache-dit</a>:1.5x↑🎉 | 2.0x↑🎉| <b>Chroma1-HD</b> | <a href="https://github.com/vipshop/cache-dit">+cache-dit</a>:1.9x↑🎉</p>
|
|
116
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/gifs/mochi.C0_L0_Q0_NONE.gif width=125px>
|
|
117
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/gifs/mochi.C0_L0_Q0_DBCACHE_F8B0_W8M0MC0_T0O2_R0.08_S34.gif width=125px>
|
|
118
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/gifs/skyreels_v2.C0_L0_Q0_NONE.gif width=125px>
|
|
119
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/gifs/skyreels_v2.C0_L0_Q0_DBCACHE_F8B0_W8M0MC0_T0O2_R0.12_S17.gif width=125px>
|
|
120
|
-
<p><b>🔥Mochi-1-preview</b> | <a href="https://github.com/vipshop/cache-dit">+cache-dit</a>:1.8x↑🎉 | <b>SkyReelsV2</b> | <a href="https://github.com/vipshop/cache-dit">+cache-dit</a>:1.6x↑🎉</p>
|
|
121
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/examples/data/visualcloze/00555_00.jpg width=100px>
|
|
122
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/examples/data/visualcloze/12265_00.jpg width=100px>
|
|
123
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/visualcloze-512.C0_L0_Q0_NONE.png width=100px>
|
|
124
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/visualcloze-512.C0_L0_Q0_DBCACHE_F8B0_W8M0MC0_T0O2_R0.08_S15.png width=100px>
|
|
125
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/visualcloze-512.C0_L0_Q0_DBCACHE_F1B0_W8M0MC0_T0O2_R0.08_S18.png width=100px>
|
|
126
|
-
<p><b>🔥VisualCloze-512</b> | Model | Cloth | Baseline | <a href="https://github.com/vipshop/cache-dit">+cache-dit</a>:1.4x↑🎉 | 1.7x↑🎉 </p>
|
|
127
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/gifs/ltx-video.C0_L0_Q0_NONE.gif width=144px>
|
|
128
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/gifs/ltx-video.C0_L0_Q0_DBCACHE_F1B0_W8M0MC0_T0O2_R0.15_S13.gif width=144px>
|
|
129
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/gifs/cogvideox1.5.C0_L0_Q0_NONE.gif width=105px>
|
|
130
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/gifs/cogvideox1.5.C0_L0_Q0_DBCACHE_F1B0_W8M0MC0_T0O2_R0.12_S22.gif width=105px>
|
|
131
|
-
<p><b>🔥LTX-Video-0.9.7</b> | <a href="https://github.com/vipshop/cache-dit">+cache-dit</a>:1.7x↑🎉 | <b>CogVideoX1.5</b> | <a href="https://github.com/vipshop/cache-dit">+cache-dit</a>:2.0x↑🎉</p>
|
|
132
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/omingen-v1.C0_L0_Q0_NONE.png width=100px>
|
|
133
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/omingen-v1.C0_L0_Q0_DBCACHE_F8B0_W8M0MC0_T0O2_R0.08_S24.png width=100px>
|
|
134
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/omingen-v1.C0_L0_Q0_DBCACHE_F1B0_W8M0MC0_T1O2_R0.08_S38.png width=100px>
|
|
135
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/lumina2.C0_L0_Q0_NONE.png width=100px>
|
|
136
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/lumina2.C0_L0_Q0_DBCACHE_F1B0_W2M0MC2_T0O2_R0.12_S14.png width=100px>
|
|
137
|
-
<p><b>🔥OmniGen-v1</b> | <a href="https://github.com/vipshop/cache-dit">+cache-dit</a>:1.5x↑🎉 | 3.3x↑🎉 | <b>Lumina2</b> | <a href="https://github.com/vipshop/cache-dit">+cache-dit</a>:1.9x↑🎉</p>
|
|
138
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/gifs/allegro.C0_L0_Q0_NONE.gif width=117px>
|
|
139
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/gifs/allegro.C0_L0_Q0_DBCACHE_F8B0_W8M0MC0_T0O2_R0.26_S27.gif width=117px>
|
|
140
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/auraflow.C0_L0_Q0_NONE.png width=133px>
|
|
141
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/auraflow.C0_L0_Q0_DBCACHE_F1B0_W8M0MC2_T0O2_R0.08_S28.png width=133px>
|
|
142
|
-
<p><b>🔥Allegro</b> | <a href="https://github.com/vipshop/cache-dit">+cache-dit</a>:1.36x↑🎉 | <b>AuraFlow-v0.3</b> | <a href="https://github.com/vipshop/cache-dit">+cache-dit</a>:2.27x↑🎉 </p>
|
|
143
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/sana.C0_L0_Q0_NONE.png width=100px>
|
|
144
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/sana.C0_L0_Q0_DBCACHE_F8B0_W8M0MC2_T0O2_R0.25_S6.png width=100px>
|
|
145
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/sana.C0_L0_Q0_DBCACHE_F1B0_W8M0MC2_T0O2_R0.3_S8.png width=100px>
|
|
146
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/pixart-sigma.C0_L0_Q0_NONE.png width=100px>
|
|
147
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/pixart-sigma.C0_L0_Q0_DBCACHE_F8B0_W8M0MC0_T0O2_R0.08_S28.png width=100px>
|
|
148
|
-
<p><b>🔥Sana</b> | <a href="https://github.com/vipshop/cache-dit">+cache-dit</a>:1.3x↑🎉 | 1.6x↑🎉| <b>PixArt-Sigma</b> | <a href="https://github.com/vipshop/cache-dit">+cache-dit</a>:2.3x↑🎉</p>
|
|
149
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/pixart-alpha.C0_L0_Q0_NONE.png width=100px>
|
|
150
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/pixart-alpha.C0_L0_Q0_DBCACHE_F8B0_W8M0MC0_T0O2_R0.05_S27.png width=100px>
|
|
151
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/pixart-alpha.C0_L0_Q0_DBCACHE_F8B0_W8M0MC0_T0O2_R0.08_S32.png width=100px>
|
|
152
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/sd_3_5.C0_L0_Q0_NONE.png width=100px>
|
|
153
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/sd_3_5.C0_L0_Q0_DBCACHE_F1B0_W8M0MC3_T0O2_R0.12_S30.png width=100px>
|
|
154
|
-
<p><b>🔥PixArt-Alpha</b> | <a href="https://github.com/vipshop/cache-dit">+cache-dit</a>:1.6x↑🎉 | 1.8x↑🎉| <b>SD 3.5</b> | <a href="https://github.com/vipshop/cache-dit">+cache-dit</a>:2.5x↑🎉</p>
|
|
155
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/amused.C0_L0_Q0_NONE.png width=100px>
|
|
156
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/amused.C0_L0_Q0_DBCACHE_F8B0_W8M0MC0_T0O2_R0.34_S1.png width=100px>
|
|
157
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/amused.C0_L0_Q0_DBCACHE_F8B0_W8M0MC0_T0O2_R0.38_S2.png width=100px>
|
|
158
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/dit-xl.C0_L0_Q0_NONE.png width=100px>
|
|
159
|
-
<img src=https://github.com/vipshop/cache-dit/raw/main/assets/dit-xl.C0_L0_Q0_DBCACHE_F1B0_W8M0MC2_T0O2_R0.15_S11.png width=100px>
|
|
160
|
-
<p><b>🔥Asumed</b> | <a href="https://github.com/vipshop/cache-dit">+cache-dit</a>:1.1x↑🎉 | 1.2x↑🎉 | <b>DiT-XL-256</b> | <a href="https://github.com/vipshop/cache-dit">+cache-dit</a>:1.8x↑🎉
|
|
161
|
-
<br>♥️ Please consider to leave a <b>⭐️ Star</b> to support us ~ ♥️</p>
|
|
162
|
-
</div>
|
|
163
|
-
|
|
164
|
-
## 🔥News
|
|
165
|
-
|
|
166
|
-
- [2025-09-10] 🎉Day 1 support [**HunyuanImage-2.1**](https://github.com/Tencent-Hunyuan/HunyuanImage-2.1) with **1.7x↑🎉** speedup! Check this [example](https://github.com/vipshop/cache-dit/raw/main/examples/pipeline/run_hunyuan_image_2.1.py).
|
|
167
|
-
- [2025-09-08] 🔥[**Qwen-Image-Lightning**](https://github.com/vipshop/cache-dit/raw/main/examples/pipeline/run_qwen_image_lightning.py) **7.1/3.5 steps🎉** inference with **[DBCache: F16B16](https://github.com/vipshop/cache-dit)**.
|
|
168
|
-
- [2025-09-03] 🎉[**Wan2.2-MoE**](https://github.com/Wan-Video) **2.4x↑🎉** speedup! Please refer to [run_wan_2.2.py](https://github.com/vipshop/cache-dit/raw/main/examples/pipeline/run_wan_2.2.py) as an example.
|
|
169
|
-
- [2025-08-19] 🔥[**Qwen-Image-Edit**](https://github.com/QwenLM/Qwen-Image) **2x↑🎉** speedup! Check the example: [run_qwen_image_edit.py](https://github.com/vipshop/cache-dit/raw/main/examples/pipeline/run_qwen_image_edit.py).
|
|
170
|
-
- [2025-08-11] 🔥[**Qwen-Image**](https://github.com/QwenLM/Qwen-Image) **1.8x↑🎉** speedup! Please refer to [run_qwen_image.py](https://github.com/vipshop/cache-dit/raw/main/examples/pipeline/run_qwen_image.py) as an example.
|
|
171
|
-
- [2025-07-13] 🎉[**FLUX.1-dev**](https://github.com/xlite-dev/flux-faster) **3.3x↑🎉** speedup! NVIDIA L20 with **[cache-dit](https://github.com/vipshop/cache-dit)** + **compile + FP8 DQ**.
|
|
172
|
-
|
|
173
|
-
<details>
|
|
174
|
-
<summary> Previous News </summary>
|
|
175
|
-
|
|
176
|
-
- [2025-09-08] 🎉First caching mechanism in [Qwen-Image-Lightning](https://github.com/ModelTC/Qwen-Image-Lightning) with **[cache-dit](https://github.com/vipshop/cache-dit)**, check this [PR](https://github.com/ModelTC/Qwen-Image-Lightning/pull/35).
|
|
177
|
-
- [2025-09-08] 🎉First caching mechanism in [Wan2.2](https://github.com/Wan-Video/Wan2.2) with **[cache-dit](https://github.com/vipshop/cache-dit)**, check this [PR](https://github.com/Wan-Video/Wan2.2/pull/127) for more details.
|
|
178
|
-
- [2025-08-12] 🎉First caching mechanism in [QwenLM/Qwen-Image](https://github.com/QwenLM/Qwen-Image) with **[cache-dit](https://github.com/vipshop/cache-dit)**, check this [PR](https://github.com/QwenLM/Qwen-Image/pull/61).
|
|
179
|
-
- [2025-09-01] 📚[**Hybird Forward Pattern**](#unified) is supported! Please check [FLUX.1-dev](https://github.com/vipshop/cache-dit/raw/main/examples/run_flux_adapter.py) as an example.
|
|
180
|
-
- [2025-08-10] 🔥[**FLUX.1-Kontext-dev**](https://huggingface.co/black-forest-labs/FLUX.1-Kontext-dev) is supported! Please refer [run_flux_kontext.py](https://github.com/vipshop/cache-dit/raw/main/examples/pipeline/run_flux_kontext.py) as an example.
|
|
181
|
-
- [2025-07-18] 🎉First caching mechanism in [🤗huggingface/flux-fast](https://github.com/huggingface/flux-fast) with **[cache-dit](https://github.com/vipshop/cache-dit)**, check the [PR](https://github.com/huggingface/flux-fast/pull/13).
|
|
182
|
-
|
|
183
|
-
</details>
|
|
184
|
-
|
|
185
|
-
## 📖Contents
|
|
186
|
-
|
|
187
|
-
<div id="contents"></div>
|
|
188
|
-
|
|
189
|
-
- [⚙️Installation](#️installation)
|
|
190
|
-
- [🔥Benchmarks](#benchmarks)
|
|
191
|
-
- [🔥Supported Pipelines](#supported)
|
|
192
|
-
- [🎉Unified Cache APIs](#unified)
|
|
193
|
-
- [📚Forward Pattern Matching](#forward-pattern-matching)
|
|
194
|
-
- [♥️Cache with One-line Code](#%EF%B8%8Fcache-acceleration-with-one-line-code)
|
|
195
|
-
- [🔥Automatic Block Adapter](#automatic-block-adapter)
|
|
196
|
-
- [📚Hybird Forward Pattern](#automatic-block-adapter)
|
|
197
|
-
- [📚Implement Patch Functor](#implement-patch-functor)
|
|
198
|
-
- [🤖Cache Acceleration Stats](#cache-acceleration-stats-summary)
|
|
199
|
-
- [⚡️Dual Block Cache](#dbcache)
|
|
200
|
-
- [🔥TaylorSeer Calibrator](#taylorseer)
|
|
201
|
-
- [⚡️Hybrid Cache CFG](#cfg)
|
|
202
|
-
- [⚙️Torch Compile](#compile)
|
|
203
|
-
- [🛠Metrics CLI](#metrics)
|
|
204
|
-
|
|
205
|
-
## ⚙️Installation
|
|
206
|
-
|
|
207
|
-
<div id="installation"></div>
|
|
208
|
-
|
|
209
|
-
You can install the stable release of `cache-dit` from PyPI:
|
|
210
|
-
|
|
211
|
-
```bash
|
|
212
|
-
pip3 install -U cache-dit
|
|
213
|
-
```
|
|
214
|
-
Or you can install the latest develop version from GitHub:
|
|
215
|
-
|
|
216
|
-
```bash
|
|
217
|
-
pip3 install git+https://github.com/vipshop/cache-dit.git
|
|
218
|
-
```
|
|
219
|
-
|
|
220
|
-
## 🔥Supported Pipelines
|
|
221
|
-
|
|
222
|
-
<div id="supported"></div>
|
|
223
|
-
|
|
224
|
-
Currently, **cache-dit** library supports almost **Any** Diffusion Transformers (with **Transformer Blocks** that match the specific Input and Output **patterns**). Please check [🎉Examples](https://github.com/vipshop/cache-dit/raw/main/examples/pipeline) for more details. Here are just some of the tested models listed.
|
|
225
|
-
|
|
226
|
-
```python
|
|
227
|
-
>>> import cache_dit
|
|
228
|
-
>>> cache_dit.supported_pipelines()
|
|
229
|
-
(30, ['Flux*', 'Mochi*', 'CogVideoX*', 'Wan*', 'HunyuanVideo*', 'QwenImage*', 'LTX*', 'Allegro*',
|
|
230
|
-
'CogView3Plus*', 'CogView4*', 'Cosmos*', 'EasyAnimate*', 'SkyReelsV2*', 'StableDiffusion3*',
|
|
231
|
-
'ConsisID*', 'DiT*', 'Amused*', 'Bria*', 'Lumina*', 'OmniGen*', 'PixArt*', 'Sana*', 'StableAudio*',
|
|
232
|
-
'VisualCloze*', 'AuraFlow*', 'Chroma*', 'ShapE*', 'HiDream*', 'HunyuanDiT*', 'HunyuanDiTPAG*'])
|
|
233
|
-
```
|
|
234
|
-
|
|
235
|
-
<details>
|
|
236
|
-
<summary> Show all pipelines </summary>
|
|
237
|
-
|
|
238
|
-
- [🚀HunyuanImage-2.1](https://github.com/vipshop/cache-dit/raw/main/examples)
|
|
239
|
-
- [🚀Qwen-Image-Lightning](https://github.com/vipshop/cache-dit/raw/main/examples)
|
|
240
|
-
- [🚀Qwen-Image-Edit](https://github.com/vipshop/cache-dit/raw/main/examples)
|
|
241
|
-
- [🚀Qwen-Image](https://github.com/vipshop/cache-dit/raw/main/examples)
|
|
242
|
-
- [🚀FLUX.1-dev](https://github.com/vipshop/cache-dit/raw/main/examples)
|
|
243
|
-
- [🚀FLUX.1-Fill-dev](https://github.com/vipshop/cache-dit/raw/main/examples)
|
|
244
|
-
- [🚀FLUX.1-Kontext-dev](https://github.com/vipshop/cache-dit/raw/main/examples)
|
|
245
|
-
- [🚀CogView4](https://github.com/vipshop/cache-dit/raw/main/examples)
|
|
246
|
-
- [🚀Wan2.2-T2V](https://github.com/vipshop/cache-dit/raw/main/examples)
|
|
247
|
-
- [🚀HunyuanVideo](https://github.com/vipshop/cache-dit/raw/main/examples)
|
|
248
|
-
- [🚀HiDream-I1-Full](https://github.com/vipshop/cache-dit/raw/main/examples)
|
|
249
|
-
- [🚀HunyuanDiT](https://github.com/vipshop/cache-dit/raw/main/examples)
|
|
250
|
-
- [🚀Wan2.1-T2V](https://github.com/vipshop/cache-dit/raw/main/examples)
|
|
251
|
-
- [🚀Wan2.1-FLF2V](https://github.com/vipshop/cache-dit/raw/main/examples)
|
|
252
|
-
- [🚀SkyReelsV2](https://github.com/vipshop/cache-dit/raw/main/examples)
|
|
253
|
-
- [🚀Chroma1-HD](https://github.com/vipshop/cache-dit/raw/main/examples)
|
|
254
|
-
- [🚀CogVideoX1.5](https://github.com/vipshop/cache-dit/raw/main/examples)
|
|
255
|
-
- [🚀CogView3-Plus](https://github.com/vipshop/cache-dit/raw/main/examples)
|
|
256
|
-
- [🚀CogVideoX](https://github.com/vipshop/cache-dit/raw/main/examples)
|
|
257
|
-
- [🚀VisualCloze](https://github.com/vipshop/cache-dit/raw/main/examples)
|
|
258
|
-
- [🚀LTXVideo](https://github.com/vipshop/cache-dit/raw/main/examples)
|
|
259
|
-
- [🚀OmniGen](https://github.com/vipshop/cache-dit/raw/main/examples)
|
|
260
|
-
- [🚀Lumina2](https://github.com/vipshop/cache-dit/raw/main/examples)
|
|
261
|
-
- [🚀mochi-1-preview](https://github.com/vipshop/cache-dit/raw/main/examples)
|
|
262
|
-
- [🚀AuraFlow-v0.3](https://github.com/vipshop/cache-dit/raw/main/examples)
|
|
263
|
-
- [🚀PixArt-Alpha](https://github.com/vipshop/cache-dit/raw/main/examples)
|
|
264
|
-
- [🚀PixArt-Sigma](https://github.com/vipshop/cache-dit/raw/main/examples)
|
|
265
|
-
- [🚀NVIDIA Sana](https://github.com/vipshop/cache-dit/raw/main/examples)
|
|
266
|
-
- [🚀SD-3/3.5](https://github.com/vipshop/cache-dit/raw/main/examples)
|
|
267
|
-
- [🚀ConsisID](https://github.com/vipshop/cache-dit/raw/main/examples)
|
|
268
|
-
- [🚀Allegro](https://github.com/vipshop/cache-dit/raw/main/examples)
|
|
269
|
-
- [🚀Amused](https://github.com/vipshop/cache-dit/raw/main/examples)
|
|
270
|
-
- [🚀DiT-XL](https://github.com/vipshop/cache-dit/raw/main/examples)
|
|
271
|
-
- ...
|
|
272
|
-
|
|
273
|
-
</details>
|
|
274
|
-
|
|
275
|
-
## 🔥Benchmarks
|
|
276
|
-
|
|
277
|
-
<div id="benchmarks"></div>
|
|
278
|
-
|
|
279
|
-
cache-dit will support more mainstream Cache acceleration algorithms in the future. More benchmarks will be released, please stay tuned for update. Here, only the results of some precision and performance benchmarks are presented. The test dataset is **DrawBench**. For a complete benchmark, please refer to [📚Benchmarks](https://github.com/vipshop/cache-dit/raw/main/bench/).
|
|
280
|
-
|
|
281
|
-
### 📚Text2Image DrawBench: FLUX.1-dev
|
|
282
|
-
|
|
283
|
-
Comparisons between different FnBn compute block configurations show that **more compute blocks result in higher precision**. For example, the F8B0_W8MC0 configuration achieves the best Clip Score (33.007) and ImageReward (1.0333). **Device**: NVIDIA L20. **F**: Fn_compute_blocks, **B**: Bn_compute_blocks, 50 steps.
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
| Config | Clip Score(↑) | ImageReward(↑) | PSNR(↑) | TFLOPs(↓) | SpeedUp(↑) |
|
|
287
|
-
| --- | --- | --- | --- | --- | --- |
|
|
288
|
-
| [**FLUX.1**-dev]: 50 steps | 32.9217 | 1.0412 | INF | 3726.87 | 1.00x |
|
|
289
|
-
| F8B0_W4MC0_R0.08 | 32.9871 | 1.0370 | 33.8317 | 2064.81 | 1.80x |
|
|
290
|
-
| F8B0_W4MC2_R0.12 | 32.9535 | 1.0185 | 32.7346 | 1935.73 | 1.93x |
|
|
291
|
-
| F8B0_W4MC3_R0.12 | 32.9234 | 1.0085 | 32.5385 | 1816.58 | 2.05x |
|
|
292
|
-
| F4B0_W4MC3_R0.12 | 32.8981 | 1.0130 | 31.8031 | 1507.83 | 2.47x |
|
|
293
|
-
| F4B0_W4MC4_R0.12 | 32.8384 | 1.0065 | 31.5292 | 1400.08 | 2.66x |
|
|
294
|
-
|
|
295
|
-
The comparison between **cache-dit: DBCache** and algorithms such as Δ-DiT, Chipmunk, FORA, DuCa, TaylorSeer and FoCa is as follows. Now, in the comparison with a speedup ratio less than **3x**, cache-dit achieved the best accuracy. Please check [📚How to Reproduce?](https://github.com/vipshop/cache-dit/raw/main/bench/) for more details.
|
|
296
|
-
|
|
297
|
-
| Method | TFLOPs(↓) | SpeedUp(↑) | ImageReward(↑) | Clip Score(↑) |
|
|
298
|
-
| --- | --- | --- | --- | --- |
|
|
299
|
-
| [**FLUX.1**-dev]: 50 steps | 3726.87 | 1.00× | 0.9898 | 32.404 |
|
|
300
|
-
| [**FLUX.1**-dev]: 60% steps | 2231.70 | 1.67× | 0.9663 | 32.312 |
|
|
301
|
-
| Δ-DiT(N=2) | 2480.01 | 1.50× | 0.9444 | 32.273 |
|
|
302
|
-
| Δ-DiT(N=3) | 1686.76 | 2.21× | 0.8721 | 32.102 |
|
|
303
|
-
| [**FLUX.1**-dev]: 34% steps | 1264.63 | 3.13× | 0.9453 | 32.114 |
|
|
304
|
-
| Chipmunk | 1505.87 | 2.47× | 0.9936 | 32.776 |
|
|
305
|
-
| FORA(N=3) | 1320.07 | 2.82× | 0.9776 | 32.266 |
|
|
306
|
-
| **[DBCache(F=4,B=0,W=4,MC=4)](https://github.com/vipshop/cache-dit)** | 1400.08 | **2.66×** | **1.0065** | 32.838 |
|
|
307
|
-
| **[DBCache+TaylorSeer(F=1,B=0,O=1)](https://github.com/vipshop/cache-dit)** | 1153.05 | **3.23×** | **1.0221** | 32.819 |
|
|
308
|
-
| DuCa(N=5) | 978.76 | 3.80× | 0.9955 | 32.241 |
|
|
309
|
-
| TaylorSeer(N=4,O=2) | 1042.27 | 3.57× | 0.9857 | 32.413 |
|
|
310
|
-
| **[DBCache(F=1,B=0,W=4,MC=6)](https://github.com/vipshop/cache-dit)** | 944.75 | **3.94×** | 0.9997 | 32.849 |
|
|
311
|
-
| **[DBCache+TaylorSeer(F=1,B=0,O=1)](https://github.com/vipshop/cache-dit)** | 944.75 | **3.94×** | **1.0107** | 32.865 |
|
|
312
|
-
| **[FoCa(N=5): arxiv.2508.16211](https://arxiv.org/pdf/2508.16211)** | 893.54 | **4.16×** | **1.0029** | **32.948** |
|
|
313
|
-
|
|
314
|
-
<details>
|
|
315
|
-
<summary> Show all comparison </summary>
|
|
316
|
-
|
|
317
|
-
| Method | TFLOPs(↓) | SpeedUp(↑) | ImageReward(↑) | Clip Score(↑) |
|
|
318
|
-
| --- | --- | --- | --- | --- |
|
|
319
|
-
| [**FLUX.1**-dev]: 50 steps | 3726.87 | 1.00× | 0.9898 | 32.404 |
|
|
320
|
-
| [**FLUX.1**-dev]: 60% steps | 2231.70 | 1.67× | 0.9663 | 32.312 |
|
|
321
|
-
| Δ-DiT(N=2) | 2480.01 | 1.50× | 0.9444 | 32.273 |
|
|
322
|
-
| Δ-DiT(N=3) | 1686.76 | 2.21× | 0.8721 | 32.102 |
|
|
323
|
-
| [**FLUX.1**-dev]: 34% steps | 1264.63 | 3.13× | 0.9453 | 32.114 |
|
|
324
|
-
| Chipmunk | 1505.87 | 2.47× | 0.9936 | 32.776 |
|
|
325
|
-
| FORA(N=3) | 1320.07 | 2.82× | 0.9776 | 32.266 |
|
|
326
|
-
| **[DBCache(F=4,B=0,W=4,MC=4)](https://github.com/vipshop/cache-dit)** | 1400.08 | **2.66×** | **1.0065** | 32.838 |
|
|
327
|
-
| DuCa(N=5) | 978.76 | 3.80× | 0.9955 | 32.241 |
|
|
328
|
-
| TaylorSeer(N=4,O=2) | 1042.27 | 3.57× | 0.9857 | 32.413 |
|
|
329
|
-
| **[DBCache+TaylorSeer(F=1,B=0,O=1)](https://github.com/vipshop/cache-dit)** | 1153.05 | **3.23×** | **1.0221** | 32.819 |
|
|
330
|
-
| **[DBCache(F=1,B=0,W=4,MC=6)](https://github.com/vipshop/cache-dit)** | 944.75 | **3.94×** | 0.9997 | 32.849 |
|
|
331
|
-
| **[DBCache+TaylorSeer(F=1,B=0,O=1)](https://github.com/vipshop/cache-dit)** | 944.75 | **3.94×** | **1.0107** | 32.865 |
|
|
332
|
-
| **[FoCa(N=5): arxiv.2508.16211](https://arxiv.org/pdf/2508.16211)** | 893.54 | **4.16×** | **1.0029** | **32.948** |
|
|
333
|
-
| [**FLUX.1**-dev]: 22% steps | 818.29 | 4.55× | 0.8183 | 31.772 |
|
|
334
|
-
| FORA(N=4) | 967.91 | 3.84× | 0.9730 | 32.142 |
|
|
335
|
-
| ToCa(N=8) | 784.54 | 4.74× | 0.9451 | 31.993 |
|
|
336
|
-
| DuCa(N=7) | 760.14 | 4.89× | 0.9757 | 32.066 |
|
|
337
|
-
| TeaCache(l=0.8) | 892.35 | 4.17× | 0.8683 | 31.704 |
|
|
338
|
-
| **[DBCache(F=4,B=0,W=4,MC=10)](https://github.com/vipshop/cache-dit)** | 816.65 | 4.56x | 0.8245 | 32.191 |
|
|
339
|
-
| TaylorSeer(N=5,O=2) | 893.54 | 4.16× | 0.9768 | 32.467 |
|
|
340
|
-
| **[FoCa(N=7): arxiv.2508.16211](https://arxiv.org/pdf/2508.16211)** | 670.44 | **5.54×** | **0.9891** | **32.920** |
|
|
341
|
-
| FORA(N=7) | 670.14 | 5.55× | 0.7418 | 31.519 |
|
|
342
|
-
| ToCa(N=12) | 644.70 | 5.77× | 0.7155 | 31.808 |
|
|
343
|
-
| DuCa(N=10) | 606.91 | 6.13× | 0.8382 | 31.759 |
|
|
344
|
-
| TeaCache(l=1.2) | 669.27 | 5.56× | 0.7394 | 31.704 |
|
|
345
|
-
| **[DBCache(F=1,B=0,W=4,MC=10)](https://github.com/vipshop/cache-dit)** | 651.90 | **5.72x** | 0.8796 | **32.318** |
|
|
346
|
-
| TaylorSeer(N=7,O=2) | 670.44 | 5.54× | 0.9128 | 32.128 |
|
|
347
|
-
| **[FoCa(N=8): arxiv.2508.16211](https://arxiv.org/pdf/2508.16211)** | 596.07 | **6.24×** | **0.9502** | **32.706** |
|
|
348
|
-
|
|
349
|
-
NOTE: Except for DBCache, other performance data are referenced from the paper [FoCa, arxiv.2508.16211](https://arxiv.org/pdf/2508.16211).
|
|
350
|
-
|
|
351
|
-
</details>
|
|
352
|
-
|
|
353
|
-
### 📚Text2Image Distillation DrawBench: Qwen-Image-Lightning
|
|
354
|
-
|
|
355
|
-
Surprisingly, cache-dit: DBCache still works in the extremely few-step distill model. For example, **Qwen-Image-Lightning w/ 4 steps**, with the F16B16 configuration, the PSNR is 34.8163, the Clip Score is 35.6109, and the ImageReward is 1.2614. It maintained a relatively high precision.
|
|
356
|
-
|
|
357
|
-
| Config | PSNR(↑) | Clip Score(↑) | ImageReward(↑) | TFLOPs(↓) | SpeedUp(↑) |
|
|
358
|
-
|----------------------------|-----------|------------|--------------|----------|------------|
|
|
359
|
-
| [**Lightning**]: 4 steps | INF | 35.5797 | 1.2630 | 274.33 | 1.00x |
|
|
360
|
-
| F24B24_W2MC1_R0.8 | 36.3242 | 35.6224 | 1.2630 | 264.74 | 1.04x |
|
|
361
|
-
| F16B16_W2MC1_R0.8 | 34.8163 | 35.6109 | 1.2614 | 244.25 | 1.12x |
|
|
362
|
-
| F12B12_W2MC1_R0.8 | 33.8953 | 35.6535 | 1.2549 | 234.63 | 1.17x |
|
|
363
|
-
| F8B8_W2MC1_R0.8 | 33.1374 | 35.7284 | 1.2517 | 224.29 | 1.22x |
|
|
364
|
-
| F1B0_W2MC1_R0.8 | 31.8317 | 35.6651 | 1.2397 | 206.90 | 1.33x |
|
|
365
|
-
|
|
366
|
-
## 🎉Unified Cache APIs
|
|
367
|
-
|
|
368
|
-
<div id="unified"></div>
|
|
369
|
-
|
|
370
|
-
### 📚Forward Pattern Matching
|
|
371
|
-
|
|
372
|
-
Currently, for any **Diffusion** models with **Transformer Blocks** that match the specific **Input/Output patterns**, we can use the **Unified Cache APIs** from **cache-dit**, namely, the `cache_dit.enable_cache(...)` API. The **Unified Cache APIs** are currently in the experimental phase; please stay tuned for updates. The supported patterns are listed as follows:
|
|
373
|
-
|
|
374
|
-

|
|
375
|
-
|
|
376
|
-
### ♥️Cache Acceleration with One-line Code
|
|
377
|
-
|
|
378
|
-
In most cases, you only need to call **one-line** of code, that is `cache_dit.enable_cache(...)`. After this API is called, you just need to call the pipe as normal. The `pipe` param can be **any** Diffusion Pipeline. Please refer to [Qwen-Image](https://github.com/vipshop/cache-dit/raw/main/examples/pipeline/run_qwen_image.py) as an example.
|
|
379
|
-
|
|
380
|
-
```python
|
|
381
|
-
import cache_dit
|
|
382
|
-
from diffusers import DiffusionPipeline
|
|
383
|
-
|
|
384
|
-
# Can be any diffusion pipeline
|
|
385
|
-
pipe = DiffusionPipeline.from_pretrained("Qwen/Qwen-Image")
|
|
386
|
-
|
|
387
|
-
# One-line code with default cache options.
|
|
388
|
-
cache_dit.enable_cache(pipe)
|
|
389
|
-
|
|
390
|
-
# Just call the pipe as normal.
|
|
391
|
-
output = pipe(...)
|
|
392
|
-
|
|
393
|
-
# Disable cache and run original pipe.
|
|
394
|
-
cache_dit.disable_cache(pipe)
|
|
395
|
-
```
|
|
396
|
-
|
|
397
|
-
### 🔥Automatic Block Adapter
|
|
398
|
-
|
|
399
|
-
But in some cases, you may have a **modified** Diffusion Pipeline or Transformer that is not located in the diffusers library or not officially supported by **cache-dit** at this time. The **BlockAdapter** can help you solve this problems. Please refer to [🔥Qwen-Image w/ BlockAdapter](https://github.com/vipshop/cache-dit/raw/main/examples/adapter/run_qwen_image_adapter.py) as an example.
|
|
400
|
-
|
|
401
|
-
```python
|
|
402
|
-
from cache_dit import ForwardPattern, BlockAdapter
|
|
403
|
-
|
|
404
|
-
# Use 🔥BlockAdapter with `auto` mode.
|
|
405
|
-
cache_dit.enable_cache(
|
|
406
|
-
BlockAdapter(
|
|
407
|
-
# Any DiffusionPipeline, Qwen-Image, etc.
|
|
408
|
-
pipe=pipe, auto=True,
|
|
409
|
-
# Check `📚Forward Pattern Matching` documentation and hack the code of
|
|
410
|
-
# of Qwen-Image, you will find that it has satisfied `FORWARD_PATTERN_1`.
|
|
411
|
-
forward_pattern=ForwardPattern.Pattern_1,
|
|
412
|
-
),
|
|
413
|
-
)
|
|
414
|
-
|
|
415
|
-
# Or, manually setup transformer configurations.
|
|
416
|
-
cache_dit.enable_cache(
|
|
417
|
-
BlockAdapter(
|
|
418
|
-
pipe=pipe, # Qwen-Image, etc.
|
|
419
|
-
transformer=pipe.transformer,
|
|
420
|
-
blocks=pipe.transformer.transformer_blocks,
|
|
421
|
-
forward_pattern=ForwardPattern.Pattern_1,
|
|
422
|
-
),
|
|
423
|
-
)
|
|
424
|
-
```
|
|
425
|
-
For such situations, **BlockAdapter** can help you quickly apply various cache acceleration features to your own Diffusion Pipelines and Transformers. Please check the [📚BlockAdapter.md](https://github.com/vipshop/cache-dit/raw/main/docs/BlockAdapter.md) for more details.
|
|
426
|
-
|
|
427
|
-
### 📚Hybird Forward Pattern
|
|
428
|
-
|
|
429
|
-
Sometimes, a Transformer class will contain more than one transformer `blocks`. For example, **FLUX.1** (HiDream, Chroma, etc) contains transformer_blocks and single_transformer_blocks (with different forward patterns). The **BlockAdapter** can also help you solve this problem. Please refer to [📚FLUX.1](https://github.com/vipshop/cache-dit/raw/main/examples/adapter/run_flux_adapter.py) as an example.
|
|
430
|
-
|
|
431
|
-
```python
|
|
432
|
-
# For diffusers <= 0.34.0, FLUX.1 transformer_blocks and
|
|
433
|
-
# single_transformer_blocks have different forward patterns.
|
|
434
|
-
cache_dit.enable_cache(
|
|
435
|
-
BlockAdapter(
|
|
436
|
-
pipe=pipe, # FLUX.1, etc.
|
|
437
|
-
transformer=pipe.transformer,
|
|
438
|
-
blocks=[
|
|
439
|
-
pipe.transformer.transformer_blocks,
|
|
440
|
-
pipe.transformer.single_transformer_blocks,
|
|
441
|
-
],
|
|
442
|
-
forward_pattern=[
|
|
443
|
-
ForwardPattern.Pattern_1,
|
|
444
|
-
ForwardPattern.Pattern_3,
|
|
445
|
-
],
|
|
446
|
-
),
|
|
447
|
-
)
|
|
448
|
-
```
|
|
449
|
-
|
|
450
|
-
Even sometimes you have more complex cases, such as **Wan 2.2 MoE**, which has more than one Transformer (namely `transformer` and `transformer_2`) in its structure. Fortunately, **cache-dit** can also handle this situation very well. Please refer to [📚Wan 2.2 MoE](https://github.com/vipshop/cache-dit/raw/main/examples/pipeline/run_wan_2.2.py) as an example.
|
|
451
|
-
|
|
452
|
-
```python
|
|
453
|
-
from cache_dit import ForwardPattern, BlockAdapter, ParamsModifier, BasicCacheConfig
|
|
454
|
-
|
|
455
|
-
cache_dit.enable_cache(
|
|
456
|
-
BlockAdapter(
|
|
457
|
-
pipe=pipe,
|
|
458
|
-
transformer=[
|
|
459
|
-
pipe.transformer,
|
|
460
|
-
pipe.transformer_2,
|
|
461
|
-
],
|
|
462
|
-
blocks=[
|
|
463
|
-
pipe.transformer.blocks,
|
|
464
|
-
pipe.transformer_2.blocks,
|
|
465
|
-
],
|
|
466
|
-
forward_pattern=[
|
|
467
|
-
ForwardPattern.Pattern_2,
|
|
468
|
-
ForwardPattern.Pattern_2,
|
|
469
|
-
],
|
|
470
|
-
# Setup different cache params for each 'blocks'. You can
|
|
471
|
-
# pass any specific cache params to ParamModifier, the old
|
|
472
|
-
# value will be overwrite by the new one.
|
|
473
|
-
params_modifiers=[
|
|
474
|
-
ParamsModifier(
|
|
475
|
-
cache_config=BasicCacheConfig(
|
|
476
|
-
max_warmup_steps=4,
|
|
477
|
-
max_cached_steps=8,
|
|
478
|
-
),
|
|
479
|
-
),
|
|
480
|
-
ParamsModifier(
|
|
481
|
-
cache_config=BasicCacheConfig(
|
|
482
|
-
max_warmup_steps=2,
|
|
483
|
-
max_cached_steps=20,
|
|
484
|
-
),
|
|
485
|
-
),
|
|
486
|
-
],
|
|
487
|
-
has_separate_cfg=True,
|
|
488
|
-
),
|
|
489
|
-
)
|
|
490
|
-
```
|
|
491
|
-
### 📚Implement Patch Functor
|
|
492
|
-
|
|
493
|
-
For any PATTERN not in {0...5}, we introduced the simple abstract concept of **Patch Functor**. Users can implement a subclass of Patch Functor to convert an unknown Pattern into a known PATTERN, and for some models, users may also need to fuse the operations within the blocks for loop into block forward.
|
|
494
|
-
|
|
495
|
-

|
|
496
|
-
|
|
497
|
-
Some Patch functors have already been provided in cache-dit: [📚HiDreamPatchFunctor](https://github.com/vipshop/cache-dit/raw/main/src/cache_dit/cache_factory/patch_functors/functor_hidream.py), [📚ChromaPatchFunctor](https://github.com/vipshop/cache-dit/raw/main/src/cache_dit/cache_factory/patch_functors/functor_chroma.py), etc. After implementing Patch Functor, users need to set the `patch_functor` property of **BlockAdapter**.
|
|
498
|
-
|
|
499
|
-
```python
|
|
500
|
-
@BlockAdapterRegistry.register("HiDream")
|
|
501
|
-
def hidream_adapter(pipe, **kwargs) -> BlockAdapter:
|
|
502
|
-
from diffusers import HiDreamImageTransformer2DModel
|
|
503
|
-
from cache_dit.cache_factory.patch_functors import HiDreamPatchFunctor
|
|
504
|
-
|
|
505
|
-
assert isinstance(pipe.transformer, HiDreamImageTransformer2DModel)
|
|
506
|
-
return BlockAdapter(
|
|
507
|
-
pipe=pipe,
|
|
508
|
-
transformer=pipe.transformer,
|
|
509
|
-
blocks=[
|
|
510
|
-
pipe.transformer.double_stream_blocks,
|
|
511
|
-
pipe.transformer.single_stream_blocks,
|
|
512
|
-
],
|
|
513
|
-
forward_pattern=[
|
|
514
|
-
ForwardPattern.Pattern_0,
|
|
515
|
-
ForwardPattern.Pattern_3,
|
|
516
|
-
],
|
|
517
|
-
# NOTE: Setup your custom patch functor here.
|
|
518
|
-
patch_functor=HiDreamPatchFunctor(),
|
|
519
|
-
**kwargs,
|
|
520
|
-
)
|
|
521
|
-
```
|
|
522
|
-
|
|
523
|
-
### 🤖Cache Acceleration Stats Summary
|
|
524
|
-
|
|
525
|
-
After finishing each inference of `pipe(...)`, you can call the `cache_dit.summary()` API on pipe to get the details of the **Cache Acceleration Stats** for the current inference.
|
|
526
|
-
```python
|
|
527
|
-
stats = cache_dit.summary(pipe)
|
|
528
|
-
```
|
|
529
|
-
|
|
530
|
-
You can set `details` param as `True` to show more details of cache stats. (markdown table format) Sometimes, this may help you analyze what values of the residual diff threshold would be better.
|
|
531
|
-
|
|
532
|
-
```python
|
|
533
|
-
⚡️Cache Steps and Residual Diffs Statistics: QwenImagePipeline
|
|
534
|
-
|
|
535
|
-
| Cache Steps | Diffs Min | Diffs P25 | Diffs P50 | Diffs P75 | Diffs P95 | Diffs Max |
|
|
536
|
-
|-------------|-----------|-----------|-----------|-----------|-----------|-----------|
|
|
537
|
-
| 23 | 0.045 | 0.084 | 0.114 | 0.147 | 0.241 | 0.297 |
|
|
538
|
-
```
|
|
539
|
-
|
|
540
|
-
## ⚡️DBCache: Dual Block Cache
|
|
541
|
-
|
|
542
|
-
<div id="dbcache"></div>
|
|
543
|
-
|
|
544
|
-

|
|
545
|
-
|
|
546
|
-
**DBCache**: **Dual Block Caching** for Diffusion Transformers. Different configurations of compute blocks (**F8B12**, etc.) can be customized in DBCache, enabling a balanced trade-off between performance and precision. Moreover, it can be entirely **training**-**free**. Please check [DBCache.md](https://github.com/vipshop/cache-dit/raw/main/docs/DBCache.md) docs for more design details.
|
|
547
|
-
|
|
548
|
-
- **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.
|
|
549
|
-
- **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.
|
|
550
|
-
|
|
551
|
-
```python
|
|
552
|
-
import cache_dit
|
|
553
|
-
from diffusers import FluxPipeline
|
|
554
|
-
|
|
555
|
-
pipe_or_adapter = FluxPipeline.from_pretrained(
|
|
556
|
-
"black-forest-labs/FLUX.1-dev",
|
|
557
|
-
torch_dtype=torch.bfloat16,
|
|
558
|
-
).to("cuda")
|
|
559
|
-
|
|
560
|
-
# Default options, F8B0, 8 warmup steps, and unlimited cached
|
|
561
|
-
# steps for good balance between performance and precision
|
|
562
|
-
cache_dit.enable_cache(pipe_or_adapter)
|
|
563
|
-
|
|
564
|
-
# Custom options, F8B8, higher precision
|
|
565
|
-
from cache_dit import BasicCacheConfig
|
|
566
|
-
|
|
567
|
-
cache_dit.enable_cache(
|
|
568
|
-
pipe_or_adapter,
|
|
569
|
-
cache_config=BasicCacheConfig(
|
|
570
|
-
max_warmup_steps=8, # steps do not cache
|
|
571
|
-
max_cached_steps=-1, # -1 means no limit
|
|
572
|
-
Fn_compute_blocks=8, # Fn, F8, etc.
|
|
573
|
-
Bn_compute_blocks=8, # Bn, B8, etc.
|
|
574
|
-
residual_diff_threshold=0.12,
|
|
575
|
-
),
|
|
576
|
-
)
|
|
577
|
-
```
|
|
578
|
-
|
|
579
|
-
<div align="center">
|
|
580
|
-
<p align="center">
|
|
581
|
-
DBCache, <b> L20x1 </b>, Steps: 28, "A cat holding a sign that says hello world with complex background"
|
|
582
|
-
</p>
|
|
583
|
-
</div>
|
|
584
|
-
|
|
585
|
-
|Baseline(L20x1)|F1B0 (0.08)|F1B0 (0.20)|F8B8 (0.15)|F12B12 (0.20)|F16B16 (0.20)|
|
|
586
|
-
|:---:|:---:|:---:|:---:|:---:|:---:|
|
|
587
|
-
|24.85s|15.59s|8.58s|15.41s|15.11s|17.74s|
|
|
588
|
-
|<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>|
|
|
589
|
-
|
|
590
|
-
## 🔥TaylorSeer Calibrator
|
|
591
|
-
|
|
592
|
-
<div id="taylorseer"></div>
|
|
593
|
-
|
|
594
|
-
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.
|
|
595
|
-
|
|
596
|
-
$$
|
|
597
|
-
\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
|
|
598
|
-
$$
|
|
599
|
-
|
|
600
|
-
**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 cache-dit 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.
|
|
601
|
-
|
|
602
|
-
```python
|
|
603
|
-
from cache_dit import BasicCacheConfig, TaylorSeerCalibratorConfig
|
|
604
|
-
|
|
605
|
-
cache_dit.enable_cache(
|
|
606
|
-
pipe_or_adapter,
|
|
607
|
-
# Basic DBCache w/ FnBn configurations
|
|
608
|
-
cache_config=BasicCacheConfig(
|
|
609
|
-
max_warmup_steps=8, # steps do not cache
|
|
610
|
-
max_cached_steps=-1, # -1 means no limit
|
|
611
|
-
Fn_compute_blocks=8, # Fn, F8, etc.
|
|
612
|
-
Bn_compute_blocks=8, # Bn, B8, etc.
|
|
613
|
-
residual_diff_threshold=0.12,
|
|
614
|
-
),
|
|
615
|
-
# Then, you can use the TaylorSeer Calibrator to approximate
|
|
616
|
-
# the values in cached steps, taylorseer_order default is 1.
|
|
617
|
-
calibrator_config=TaylorSeerCalibratorConfig(
|
|
618
|
-
taylorseer_order=1,
|
|
619
|
-
),
|
|
620
|
-
)
|
|
621
|
-
```
|
|
622
|
-
|
|
623
|
-
> [!Important]
|
|
624
|
-
> 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**.
|
|
625
|
-
|
|
626
|
-
<div align="center">
|
|
627
|
-
<p align="center">
|
|
628
|
-
<b>DBCache F1B0 + TaylorSeer</b>, L20x1, Steps: 28, <br>"A cat holding a sign that says hello world with complex background"
|
|
629
|
-
</p>
|
|
630
|
-
</div>
|
|
631
|
-
|
|
632
|
-
|Baseline(L20x1)|F1B0 (0.12)|+TaylorSeer|F1B0 (0.15)|+TaylorSeer|+compile|
|
|
633
|
-
|:---:|:---:|:---:|:---:|:---:|:---:|
|
|
634
|
-
|24.85s|12.85s|12.86s|10.27s|10.28s|8.48s|
|
|
635
|
-
|<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>|
|
|
636
|
-
|
|
637
|
-
## ⚡️Hybrid Cache CFG
|
|
638
|
-
|
|
639
|
-
<div id="cfg"></div>
|
|
640
|
-
|
|
641
|
-
cache-dit supports caching for **CFG (classifier-free guidance)**. For models that fuse CFG and non-CFG into a single forward step, or models that do not include CFG (classifier-free guidance) in the forward step, please set `enable_separate_cfg` param to **False (default, None)**. Otherwise, set it to True. For examples:
|
|
642
|
-
|
|
643
|
-
```python
|
|
644
|
-
from cache_dit import BasicCacheConfig
|
|
645
|
-
|
|
646
|
-
cache_dit.enable_cache(
|
|
647
|
-
pipe_or_adapter,
|
|
648
|
-
cache_config=BasicCacheConfig(
|
|
649
|
-
...,
|
|
650
|
-
# CFG: classifier free guidance or not
|
|
651
|
-
# For model that fused CFG and non-CFG into single forward step,
|
|
652
|
-
# should set enable_separate_cfg as False. For example, set it as True
|
|
653
|
-
# for Wan 2.1/Qwen-Image and set it as False for FLUX.1, HunyuanVideo,
|
|
654
|
-
# CogVideoX, Mochi, LTXVideo, Allegro, CogView3Plus, EasyAnimate, SD3, etc.
|
|
655
|
-
enable_separate_cfg=True, # Wan 2.1, Qwen-Image, CogView4, Cosmos, SkyReelsV2, etc.
|
|
656
|
-
# Compute cfg forward first or not, default False, namely,
|
|
657
|
-
# 0, 2, 4, ..., -> non-CFG step; 1, 3, 5, ... -> CFG step.
|
|
658
|
-
cfg_compute_first=False,
|
|
659
|
-
# Compute separate diff values for CFG and non-CFG step,
|
|
660
|
-
# default True. If False, we will use the computed diff from
|
|
661
|
-
# current non-CFG transformer step for current CFG step.
|
|
662
|
-
cfg_diff_compute_separate=True,
|
|
663
|
-
),
|
|
664
|
-
)
|
|
665
|
-
```
|
|
666
|
-
|
|
667
|
-
## ⚙️Torch Compile
|
|
668
|
-
|
|
669
|
-
<div id="compile"></div>
|
|
670
|
-
|
|
671
|
-
By the way, **cache-dit** is designed to work compatibly with **torch.compile.** You can easily use cache-dit with torch.compile to further achieve a better performance. For example:
|
|
672
|
-
|
|
673
|
-
```python
|
|
674
|
-
cache_dit.enable_cache(pipe)
|
|
675
|
-
|
|
676
|
-
# Compile the Transformer module
|
|
677
|
-
pipe.transformer = torch.compile(pipe.transformer)
|
|
678
|
-
```
|
|
679
|
-
However, users intending to use **cache-dit** for DiT with **dynamic input shapes** should consider increasing the **recompile** **limit** of `torch._dynamo`. Otherwise, the recompile_limit error may be triggered, causing the module to fall back to eager mode.
|
|
680
|
-
```python
|
|
681
|
-
torch._dynamo.config.recompile_limit = 96 # default is 8
|
|
682
|
-
torch._dynamo.config.accumulated_recompile_limit = 2048 # default is 256
|
|
683
|
-
```
|
|
684
|
-
|
|
685
|
-
Please check [perf.py](https://github.com/vipshop/cache-dit/raw/main/bench/perf.py) for more details.
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
## 🛠Metrics CLI
|
|
689
|
-
|
|
690
|
-
<div id="metrics"></div>
|
|
691
|
-
|
|
692
|
-
You can utilize the APIs provided by cache-dit to quickly evaluate the accuracy losses caused by different cache configurations. For example:
|
|
693
|
-
|
|
694
|
-
```python
|
|
695
|
-
from cache_dit.metrics import compute_psnr
|
|
696
|
-
from cache_dit.metrics import compute_ssim
|
|
697
|
-
from cache_dit.metrics import compute_fid
|
|
698
|
-
from cache_dit.metrics import compute_lpips
|
|
699
|
-
from cache_dit.metrics import compute_clip_score
|
|
700
|
-
from cache_dit.metrics import compute_image_reward
|
|
701
|
-
|
|
702
|
-
psnr, n = compute_psnr("true.png", "test.png") # Num: n
|
|
703
|
-
psnr, n = compute_psnr("true_dir", "test_dir")
|
|
704
|
-
ssim, n = compute_ssim("true_dir", "test_dir")
|
|
705
|
-
fid, n = compute_fid("true_dir", "test_dir")
|
|
706
|
-
lpips, n = compute_lpips("true_dir", "test_dir")
|
|
707
|
-
clip, n = compute_clip_score("DrawBench200.txt", "test_dir")
|
|
708
|
-
reward, n = compute_image_reward("DrawBench200.txt", "test_dir")
|
|
709
|
-
```
|
|
710
|
-
|
|
711
|
-
Or, you can use `cache-dit-metrics-cli` tool. For examples:
|
|
712
|
-
|
|
713
|
-
```bash
|
|
714
|
-
cache-dit-metrics-cli -h # show usage
|
|
715
|
-
# all: PSNR, FID, SSIM, MSE, ..., etc.
|
|
716
|
-
cache-dit-metrics-cli all -i1 true.png -i2 test.png # image
|
|
717
|
-
cache-dit-metrics-cli all -i1 true_dir -i2 test_dir # image dir
|
|
718
|
-
```
|
|
719
|
-
|
|
720
|
-
## 👋Contribute
|
|
721
|
-
<div id="contribute"></div>
|
|
722
|
-
|
|
723
|
-
How to contribute? Star ⭐️ this repo to support us or check [CONTRIBUTE.md](https://github.com/vipshop/cache-dit/raw/main/CONTRIBUTE.md).
|
|
724
|
-
|
|
725
|
-
<div align='center'>
|
|
726
|
-
<a href="https://star-history.com/#vipshop/cache-dit&Date">
|
|
727
|
-
<picture align='center'>
|
|
728
|
-
<source media="(prefers-color-scheme: dark)" srcset="https://api.star-history.com/svg?repos=vipshop/cache-dit&type=Date&theme=dark" />
|
|
729
|
-
<source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/svg?repos=vipshop/cache-dit&type=Date" />
|
|
730
|
-
<img alt="Star History Chart" src="https://api.star-history.com/svg?repos=vipshop/cache-dit&type=Date" width=400px />
|
|
731
|
-
</picture>
|
|
732
|
-
</a>
|
|
733
|
-
</div>
|
|
734
|
-
|
|
735
|
-
## ©️Acknowledgements
|
|
736
|
-
|
|
737
|
-
<div id="Acknowledgements"></div>
|
|
738
|
-
|
|
739
|
-
The **cache-dit** codebase is adapted from FBCache. Over time its codebase diverged a lot, and **cache-dit** API is no longer compatible with FBCache.
|
|
740
|
-
|
|
741
|
-
## ©️Citations
|
|
742
|
-
|
|
743
|
-
<div id="citations"></div>
|
|
744
|
-
|
|
745
|
-
```BibTeX
|
|
746
|
-
@misc{cache-dit@2025,
|
|
747
|
-
title={cache-dit: A Unified, Flexible and Training-free Cache Acceleration Framework for 🤗Diffusers.},
|
|
748
|
-
url={https://github.com/vipshop/cache-dit.git},
|
|
749
|
-
note={Open-source software available at https://github.com/vipshop/cache-dit.git},
|
|
750
|
-
author={vipshop.com},
|
|
751
|
-
year={2025}
|
|
752
|
-
}
|
|
753
|
-
```
|