MCPcopy Index your code
hub / github.com/huggingface/diffusers / disable_cache

Method disable_cache

src/diffusers/models/cache_utils.py:106–147  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

104 self._cache_config = config
105
106 def disable_cache(self) -> None:
107 from ..hooks import (
108 FasterCacheConfig,
109 FirstBlockCacheConfig,
110 HookRegistry,
111 MagCacheConfig,
112 PyramidAttentionBroadcastConfig,
113 TaylorSeerCacheConfig,
114 TextKVCacheConfig,
115 )
116 from ..hooks.faster_cache import _FASTER_CACHE_BLOCK_HOOK, _FASTER_CACHE_DENOISER_HOOK
117 from ..hooks.first_block_cache import _FBC_BLOCK_HOOK, _FBC_LEADER_BLOCK_HOOK
118 from ..hooks.mag_cache import _MAG_CACHE_BLOCK_HOOK, _MAG_CACHE_LEADER_BLOCK_HOOK
119 from ..hooks.pyramid_attention_broadcast import _PYRAMID_ATTENTION_BROADCAST_HOOK
120 from ..hooks.taylorseer_cache import _TAYLORSEER_CACHE_HOOK
121 from ..hooks.text_kv_cache import _TEXT_KV_CACHE_BLOCK_HOOK, _TEXT_KV_CACHE_TRANSFORMER_HOOK
122
123 if self._cache_config is None:
124 logger.warning("Caching techniques have not been enabled, so there's nothing to disable.")
125 return
126
127 registry = HookRegistry.check_if_exists_or_initialize(self)
128 if isinstance(self._cache_config, FasterCacheConfig):
129 registry.remove_hook(_FASTER_CACHE_DENOISER_HOOK, recurse=True)
130 registry.remove_hook(_FASTER_CACHE_BLOCK_HOOK, recurse=True)
131 elif isinstance(self._cache_config, FirstBlockCacheConfig):
132 registry.remove_hook(_FBC_LEADER_BLOCK_HOOK, recurse=True)
133 registry.remove_hook(_FBC_BLOCK_HOOK, recurse=True)
134 elif isinstance(self._cache_config, MagCacheConfig):
135 registry.remove_hook(_MAG_CACHE_LEADER_BLOCK_HOOK, recurse=True)
136 registry.remove_hook(_MAG_CACHE_BLOCK_HOOK, recurse=True)
137 elif isinstance(self._cache_config, PyramidAttentionBroadcastConfig):
138 registry.remove_hook(_PYRAMID_ATTENTION_BROADCAST_HOOK, recurse=True)
139 elif isinstance(self._cache_config, TextKVCacheConfig):
140 registry.remove_hook(_TEXT_KV_CACHE_TRANSFORMER_HOOK, recurse=True)
141 registry.remove_hook(_TEXT_KV_CACHE_BLOCK_HOOK, recurse=True)
142 elif isinstance(self._cache_config, TaylorSeerCacheConfig):
143 registry.remove_hook(_TAYLORSEER_CACHE_HOOK, recurse=True)
144 else:
145 raise ValueError(f"Cache config {type(self._cache_config)} is not supported.")
146
147 self._cache_config = None
148
149 def _reset_stateful_cache(self, recurse: bool = True) -> None:
150 from ..hooks import HookRegistry

Calls 2

remove_hookMethod · 0.80