cache-dit 0.2.14__py3-none-any.whl → 0.2.15__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.
Potentially problematic release.
This version of cache-dit might be problematic. Click here for more details.
- cache_dit/_version.py +2 -2
- cache_dit/cache_factory/dual_block_cache/diffusers_adapters/__init__.py +4 -0
- cache_dit/cache_factory/dual_block_cache/diffusers_adapters/qwen_image.py +88 -0
- cache_dit/cache_factory/dual_block_cache/diffusers_adapters/wan.py +2 -2
- {cache_dit-0.2.14.dist-info → cache_dit-0.2.15.dist-info}/METADATA +9 -13
- {cache_dit-0.2.14.dist-info → cache_dit-0.2.15.dist-info}/RECORD +10 -9
- {cache_dit-0.2.14.dist-info → cache_dit-0.2.15.dist-info}/WHEEL +0 -0
- {cache_dit-0.2.14.dist-info → cache_dit-0.2.15.dist-info}/entry_points.txt +0 -0
- {cache_dit-0.2.14.dist-info → cache_dit-0.2.15.dist-info}/licenses/LICENSE +0 -0
- {cache_dit-0.2.14.dist-info → cache_dit-0.2.15.dist-info}/top_level.txt +0 -0
cache_dit/_version.py
CHANGED
|
@@ -15,6 +15,8 @@ def apply_db_cache_on_transformer(transformer, *args, **kwargs):
|
|
|
15
15
|
adapter_name = "wan"
|
|
16
16
|
elif transformer_cls_name.startswith("HunyuanVideo"):
|
|
17
17
|
adapter_name = "hunyuan_video"
|
|
18
|
+
elif transformer_cls_name.startswith("QwenImage"):
|
|
19
|
+
adapter_name = "qwen_image"
|
|
18
20
|
else:
|
|
19
21
|
raise ValueError(
|
|
20
22
|
f"Unknown transformer class name: {transformer_cls_name}"
|
|
@@ -41,6 +43,8 @@ def apply_db_cache_on_pipe(pipe: DiffusionPipeline, *args, **kwargs):
|
|
|
41
43
|
adapter_name = "wan"
|
|
42
44
|
elif pipe_cls_name.startswith("HunyuanVideo"):
|
|
43
45
|
adapter_name = "hunyuan_video"
|
|
46
|
+
elif pipe_cls_name.startswith("QwenImage"):
|
|
47
|
+
adapter_name = "qwen_image"
|
|
44
48
|
else:
|
|
45
49
|
raise ValueError(f"Unknown pipeline class name: {pipe_cls_name}")
|
|
46
50
|
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import functools
|
|
2
|
+
import unittest
|
|
3
|
+
|
|
4
|
+
import torch
|
|
5
|
+
from diffusers import QwenImagePipeline, QwenImageTransformer2DModel
|
|
6
|
+
|
|
7
|
+
from cache_dit.cache_factory.dual_block_cache import cache_context
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def apply_db_cache_on_transformer(
|
|
11
|
+
transformer: QwenImageTransformer2DModel,
|
|
12
|
+
):
|
|
13
|
+
if getattr(transformer, "_is_cached", False):
|
|
14
|
+
return transformer
|
|
15
|
+
|
|
16
|
+
transformer_blocks = torch.nn.ModuleList(
|
|
17
|
+
[
|
|
18
|
+
cache_context.DBCachedTransformerBlocks(
|
|
19
|
+
transformer.transformer_blocks,
|
|
20
|
+
transformer=transformer,
|
|
21
|
+
return_hidden_states_first=False,
|
|
22
|
+
)
|
|
23
|
+
]
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
original_forward = transformer.forward
|
|
27
|
+
|
|
28
|
+
@functools.wraps(transformer.__class__.forward)
|
|
29
|
+
def new_forward(
|
|
30
|
+
self,
|
|
31
|
+
*args,
|
|
32
|
+
**kwargs,
|
|
33
|
+
):
|
|
34
|
+
with unittest.mock.patch.object(
|
|
35
|
+
self,
|
|
36
|
+
"transformer_blocks",
|
|
37
|
+
transformer_blocks,
|
|
38
|
+
):
|
|
39
|
+
return original_forward(
|
|
40
|
+
*args,
|
|
41
|
+
**kwargs,
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
transformer.forward = new_forward.__get__(transformer)
|
|
45
|
+
|
|
46
|
+
transformer._is_cached = True
|
|
47
|
+
|
|
48
|
+
return transformer
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def apply_db_cache_on_pipe(
|
|
52
|
+
pipe: QwenImagePipeline,
|
|
53
|
+
*,
|
|
54
|
+
shallow_patch: bool = False,
|
|
55
|
+
residual_diff_threshold=0.06,
|
|
56
|
+
downsample_factor=1,
|
|
57
|
+
warmup_steps=0,
|
|
58
|
+
max_cached_steps=-1,
|
|
59
|
+
**kwargs,
|
|
60
|
+
):
|
|
61
|
+
cache_kwargs, kwargs = cache_context.collect_cache_kwargs(
|
|
62
|
+
default_attrs={
|
|
63
|
+
"residual_diff_threshold": residual_diff_threshold,
|
|
64
|
+
"downsample_factor": downsample_factor,
|
|
65
|
+
"warmup_steps": warmup_steps,
|
|
66
|
+
"max_cached_steps": max_cached_steps,
|
|
67
|
+
},
|
|
68
|
+
**kwargs,
|
|
69
|
+
)
|
|
70
|
+
if not getattr(pipe, "_is_cached", False):
|
|
71
|
+
original_call = pipe.__class__.__call__
|
|
72
|
+
|
|
73
|
+
@functools.wraps(original_call)
|
|
74
|
+
def new_call(self, *args, **kwargs):
|
|
75
|
+
with cache_context.cache_context(
|
|
76
|
+
cache_context.create_cache_context(
|
|
77
|
+
**cache_kwargs,
|
|
78
|
+
)
|
|
79
|
+
):
|
|
80
|
+
return original_call(self, *args, **kwargs)
|
|
81
|
+
|
|
82
|
+
pipe.__class__.__call__ = new_call
|
|
83
|
+
pipe.__class__._is_cached = True
|
|
84
|
+
|
|
85
|
+
if not shallow_patch:
|
|
86
|
+
apply_db_cache_on_transformer(pipe.transformer)
|
|
87
|
+
|
|
88
|
+
return pipe
|
|
@@ -2,7 +2,7 @@ import functools
|
|
|
2
2
|
import unittest
|
|
3
3
|
|
|
4
4
|
import torch
|
|
5
|
-
from diffusers import
|
|
5
|
+
from diffusers import WanPipeline, WanTransformer3DModel
|
|
6
6
|
|
|
7
7
|
from cache_dit.cache_factory.dual_block_cache import cache_context
|
|
8
8
|
|
|
@@ -49,7 +49,7 @@ def apply_db_cache_on_transformer(
|
|
|
49
49
|
|
|
50
50
|
|
|
51
51
|
def apply_db_cache_on_pipe(
|
|
52
|
-
pipe:
|
|
52
|
+
pipe: WanPipeline,
|
|
53
53
|
*,
|
|
54
54
|
shallow_patch: bool = False,
|
|
55
55
|
residual_diff_threshold=0.03,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cache_dit
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.15
|
|
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
|
|
@@ -52,20 +52,14 @@ Dynamic: requires-python
|
|
|
52
52
|
<img src=https://img.shields.io/badge/Python-3.10|3.11|3.12-9cf.svg >
|
|
53
53
|
<img src=https://img.shields.io/badge/Release-v0.2-brightgreen.svg >
|
|
54
54
|
</div>
|
|
55
|
-
|
|
56
|
-
DeepCache is for UNet not DiT. Most DiT cache speedups are complex and not training-free. <br> CacheDiT offers a set of training-free cache accelerators for Diffusion Transformers: <br> <b>🔥<a href="#dbcache">DBCache</a>, <a href="#dbprune">DBPrune</a>, <a href="#taylorseer">Hybrid TaylorSeer</a>, <a href="#cfg">Hybrid Cache CFG</a>, <a href="#fbcache">FBCache</a></b>, etc🔥
|
|
57
|
-
</p>
|
|
55
|
+
<b>🔥<a href="#dbcache">DBCache</a> | <a href="#dbprune">DBPrune</a> | <a href="#taylorseer">Hybrid TaylorSeer</a> | <a href="#cfg">Hybrid Cache CFG</a> | <a href="#fbcache">FBCache</a></b>🔥
|
|
58
56
|
</div>
|
|
59
57
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
## 🔥News🔥
|
|
67
|
-
- [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)**, also check the **[PR](https://github.com/huggingface/flux-fast/pull/13)**.
|
|
68
|
-
- [2025-07-13] **[🤗flux-faster](https://github.com/xlite-dev/flux-faster)** is released! A forked version of **[🤗huggingface/flux-fast](https://github.com/huggingface/flux-fast)** that **makes flux-fast even faster** with **[cache-dit](https://github.com/vipshop/cache-dit)**, **3.3x** speedup on NVIDIA L20.
|
|
58
|
+
## 🔥News
|
|
59
|
+
- [2025-08-11] 🔥[Qwen-Image](./examples/run_qwen_image.py) is supported! Please check [run_qwen_image.py](./examples/run_qwen_image.py) as an example.
|
|
60
|
+
- [2025-08-10] 🔥[FLUX.1-Kontext-dev](./examples/run_flux_kontext.py) is supported! Please check [run_flux_kontext.py](./examples/run_flux_kontext.py) as an example.
|
|
61
|
+
- [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)**, also check the [PR](https://github.com/huggingface/flux-fast/pull/13).
|
|
62
|
+
- [2025-07-13] **[🤗flux-faster](https://github.com/xlite-dev/flux-faster)** is released! **3.3x** speedup for FLUX.1 on NVIDIA L20 with `cache-dit`.
|
|
69
63
|
|
|
70
64
|
## 📖Contents
|
|
71
65
|
|
|
@@ -104,8 +98,10 @@ pip3 install git+https://github.com/vipshop/cache-dit.git
|
|
|
104
98
|
|
|
105
99
|
<div id="supported"></div>
|
|
106
100
|
|
|
101
|
+
- [🚀Qwen-Image](https://github.com/vipshop/cache-dit/raw/main/examples)
|
|
107
102
|
- [🚀FLUX.1-dev](https://github.com/vipshop/cache-dit/raw/main/examples)
|
|
108
103
|
- [🚀FLUX.1-Fill-dev](https://github.com/vipshop/cache-dit/raw/main/examples)
|
|
104
|
+
- [🚀FLUX.1-Kontext-dev](https://github.com/vipshop/cache-dit/raw/main/examples)
|
|
109
105
|
- [🚀mochi-1-preview](https://github.com/vipshop/cache-dit/raw/main/examples)
|
|
110
106
|
- [🚀CogVideoX](https://github.com/vipshop/cache-dit/raw/main/examples)
|
|
111
107
|
- [🚀CogVideoX1.5](https://github.com/vipshop/cache-dit/raw/main/examples)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
cache_dit/__init__.py,sha256=0-B173-fLi3IA8nJXoS71zK0zD33Xplysd9skmLfEOY,171
|
|
2
|
-
cache_dit/_version.py,sha256=
|
|
2
|
+
cache_dit/_version.py,sha256=TspyaLI34cMH7HNr-lrUKFnY4CF39yGfG_421vC3fhg,513
|
|
3
3
|
cache_dit/logger.py,sha256=0zsu42hN-3-rgGC_C29ms1IvVpV4_b4_SwJCKSenxBE,4304
|
|
4
4
|
cache_dit/primitives.py,sha256=A2iG9YLot3gOsZSPp-_gyjqjLgJvWQRx8aitD4JQ23Y,3877
|
|
5
5
|
cache_dit/utils.py,sha256=4cFNh0asch6Zgsixq0bS1ElfwBu_6BG5ZSmaa1khjyg,144
|
|
@@ -9,12 +9,13 @@ cache_dit/cache_factory/taylorseer.py,sha256=LKSNo2ode69EVo9xrxjxAMEjz0yDGiGADeD
|
|
|
9
9
|
cache_dit/cache_factory/utils.py,sha256=V-Mb5Jn07geEUUWo4QAfh6pmSzkL-2OGDn0VAXbG6hQ,1799
|
|
10
10
|
cache_dit/cache_factory/dual_block_cache/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
11
11
|
cache_dit/cache_factory/dual_block_cache/cache_context.py,sha256=sJ9yxQlcrX4qkPln94FrL0WDe2WIn3_UD2-Mk8YtjSw,73301
|
|
12
|
-
cache_dit/cache_factory/dual_block_cache/diffusers_adapters/__init__.py,sha256=
|
|
12
|
+
cache_dit/cache_factory/dual_block_cache/diffusers_adapters/__init__.py,sha256=uSqF5aD2-feHB25vEbx1STBQVjWVAOn_wYTdAEmS4NU,2045
|
|
13
13
|
cache_dit/cache_factory/dual_block_cache/diffusers_adapters/cogvideox.py,sha256=3xUjvDzor9AkBkDUc0N7kZqM86MIdajuigesnicNzXE,2260
|
|
14
14
|
cache_dit/cache_factory/dual_block_cache/diffusers_adapters/flux.py,sha256=cIsov6Pf0dRyddqkzTA2CU-jSDotof8LQr-HIoY9T9M,2615
|
|
15
15
|
cache_dit/cache_factory/dual_block_cache/diffusers_adapters/hunyuan_video.py,sha256=SO4q39PQuQ5QVHy5Z-ubiKdstzvQPedONN2J5oiGUh0,9955
|
|
16
16
|
cache_dit/cache_factory/dual_block_cache/diffusers_adapters/mochi.py,sha256=8W9m-WeEVE2ytYi9udKEA8Wtb0EnvP3eT2A1Tu-d29k,2252
|
|
17
|
-
cache_dit/cache_factory/dual_block_cache/diffusers_adapters/
|
|
17
|
+
cache_dit/cache_factory/dual_block_cache/diffusers_adapters/qwen_image.py,sha256=ZIjB4GFIL0_xY8FkXdOJJ9-Xcft54rnBCrz43VWZLi0,2296
|
|
18
|
+
cache_dit/cache_factory/dual_block_cache/diffusers_adapters/wan.py,sha256=EH2PpYFJ76KQLb35za6T-nM8Q10owLNatv6cd480ydE,2584
|
|
18
19
|
cache_dit/cache_factory/dynamic_block_prune/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
19
20
|
cache_dit/cache_factory/dynamic_block_prune/prune_context.py,sha256=1qarKAsEFiaaN2_ghko2dqGz_R7BTQSOyGtb_eQq38Y,35716
|
|
20
21
|
cache_dit/cache_factory/dynamic_block_prune/diffusers_adapters/__init__.py,sha256=hVBTXj9MMGFGVezT3j8MntFRBiphSaUL4YhSOd8JtuY,1870
|
|
@@ -41,9 +42,9 @@ cache_dit/metrics/fid.py,sha256=9Ivtazl6mW0Bon2VXa-Ia5Xj2ewxRD3V1Qkd69zYM3Y,1706
|
|
|
41
42
|
cache_dit/metrics/inception.py,sha256=pBVe2X6ylLPIXTG4-GWDM9DWnCviMJbJ45R3ulhktR0,12759
|
|
42
43
|
cache_dit/metrics/lpips.py,sha256=I2qCNi6qJh5TRsaIsdxO0WoRX1DN7U_H3zS0oCSahYM,1032
|
|
43
44
|
cache_dit/metrics/metrics.py,sha256=8jvM1sF-nDxUuwCRy44QEoo4dYVLCQVh1QyAMs4eaQY,27840
|
|
44
|
-
cache_dit-0.2.
|
|
45
|
-
cache_dit-0.2.
|
|
46
|
-
cache_dit-0.2.
|
|
47
|
-
cache_dit-0.2.
|
|
48
|
-
cache_dit-0.2.
|
|
49
|
-
cache_dit-0.2.
|
|
45
|
+
cache_dit-0.2.15.dist-info/licenses/LICENSE,sha256=Dqb07Ik2dV41s9nIdMUbiRWEfDqo7-dQeRiY7kPO8PE,3769
|
|
46
|
+
cache_dit-0.2.15.dist-info/METADATA,sha256=7cxw9ZaYpCFbtA1iDt-CWhk07mDXuRPECxfuO-wB0IE,25153
|
|
47
|
+
cache_dit-0.2.15.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
48
|
+
cache_dit-0.2.15.dist-info/entry_points.txt,sha256=FX2gysXaZx6NeK1iCLMcIdP8Q4_qikkIHtEmi3oWn8o,65
|
|
49
|
+
cache_dit-0.2.15.dist-info/top_level.txt,sha256=ZJDydonLEhujzz0FOkVbO-BqfzO9d_VqRHmZU-3MOZo,10
|
|
50
|
+
cache_dit-0.2.15.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|