Buckets:
| import"../chunks/DsnmJJEf.js";import{i as le,h as ce,C as de,H as d,D as s,E as pe,s as he,a as h}from"../chunks/BtE7mKSK.js";import{p as fe,o as me,s as e,f as p,a as l,b as ge,c as n,d as g,n as c,r as o}from"../chunks/jDjavuwI.js";import{E as f}from"../chunks/SrSJA0zO.js";const ue='{"title":"Caching methods","local":"caching-methods","sections":[{"title":"CacheMixin","local":"diffusers.CacheMixin","sections":[],"depth":2},{"title":"PyramidAttentionBroadcastConfig","local":"diffusers.PyramidAttentionBroadcastConfig","sections":[],"depth":2},{"title":"FasterCacheConfig","local":"diffusers.FasterCacheConfig","sections":[],"depth":2},{"title":"FirstBlockCacheConfig","local":"diffusers.FirstBlockCacheConfig","sections":[],"depth":2},{"title":"TaylorSeerCacheConfig","local":"diffusers.TaylorSeerCacheConfig","sections":[],"depth":2},{"title":"MagCacheConfig","local":"diffusers.MagCacheConfig","sections":[],"depth":2}],"depth":1}';var _e=g('<meta name="hf:doc:metadata"/>'),m=g("<p>Example:</p> <!>",1),be=g("<p>Example of inactive and active usage:</p> <!>",1),ye=g(`<p></p> <!> <!> <p>Cache methods speedup diffusion transformers by storing and reusing intermediate outputs of specific layers, such as attention and feedforward layers, instead of recalculating them at each inference step.</p> <!> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>A class for enable/disabling caching techniques on diffusion models.</p> <p>Supported caching techniques:</p> <ul><li><a href="https://huggingface.co/papers/2408.12588" rel="nofollow">Pyramid Attention Broadcast</a></li> <li><a href="https://huggingface.co/papers/2410.19355" rel="nofollow">FasterCache</a></li> <li><a href="https://github.com/chengzeyi/ParaAttention/blob/7a266123671b55e7e5a2fe9af3121f07a36afc78/README.md#first-block-cache-our-dynamic-caching" rel="nofollow">FirstBlockCache</a></li></ul> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Context manager that provides additional methods for cache management.</p></div> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Enable caching techniques on the model.</p> <!></div></div> <!> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Configuration for Pyramid Attention Broadcast.</p></div> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Apply <a href="https://huggingface.co/papers/2408.12588" rel="nofollow">Pyramid Attention Broadcast</a> to a given pipeline.</p> <p>PAB is an attention approximation method that leverages the similarity in attention states between timesteps to | |
| reduce the computational cost of attention computation. The key takeaway from the paper is that the attention | |
| similarity in the cross-attention layers between timesteps is high, followed by less similarity in the temporal and | |
| spatial layers. This allows for the skipping of attention computation in the cross-attention layers more frequently | |
| than in the temporal and spatial layers. Applying PAB will, therefore, speedup the inference process.</p> <!></div> <!> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Configuration for <a href="https://huggingface.co/papers/2410.19355" rel="nofollow">FasterCache</a>.</p></div> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Applies <a href="https://huggingface.co/papers/2410.19355" rel="nofollow">FasterCache</a> to a given pipeline.</p> <!></div> <!> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Configuration for <a href="https://github.com/chengzeyi/ParaAttention/blob/7a266123671b55e7e5a2fe9af3121f07a36afc78/README.md#first-block-cache-our-dynamic-caching" rel="nofollow">First Block | |
| Cache</a>.</p></div> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Applies <a href="https://github.com/chengzeyi/ParaAttention/blob/4de137c5b96416489f06e43e19f2c14a772e28fd/README.md#first-block-cache-our-dynamic-caching" rel="nofollow">First Block | |
| Cache</a> to a given module.</p> <p>First Block Cache builds on the ideas of <a href="https://huggingface.co/papers/2411.19108" rel="nofollow">TeaCache</a>. It is much simpler | |
| to implement generically for a wide range of models and has been integrated first for experimental purposes.</p> <!></div> <!> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Configuration for TaylorSeer cache. See: <a href="https://huggingface.co/papers/2503.06923" rel="nofollow">https://huggingface.co/papers/2503.06923</a></p> <p>Notes:</p> <ul><li>Patterns are matched using <code>re.fullmatch</code> on the module name.</li> <li>If <code>skip_predict_identifiers</code> or <code>cache_identifiers</code> are provided, only matching modules are hooked.</li> <li>If neither is provided, all attention-like modules are hooked by default.</li></ul> <!> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>A mock value for a dotted path (e.g. <code>torch.float32</code>): attribute access chains, | |
| calls behave as pass-through decorators, <code>repr</code> is the dotted path, and using it | |
| as a base class substitutes a plain-<code>type</code> base (PEP 560 <code>__mro_entries__</code>), so | |
| real subclasses keep a normal metaclass and <code>inspect.signature</code> reads their real <code>__init__</code> instead of a mock’s.</p></div></div> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Applies the TaylorSeer cache to a given pipeline (typically the transformer / UNet).</p> <p>This function hooks selected modules in the model to enable caching or skipping based on the provided | |
| configuration, reducing redundant computations in diffusion denoising loops.</p> <!></div> <!> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Configuration for <a href="https://github.com/Zehong-Ma/MagCache" rel="nofollow">MagCache</a>.</p></div> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><!> <p>Applies MagCache to a given module (typically a Transformer).</p></div> <!> <p></p>`,1);function Me(H,P){fe(P,!1),me(()=>{new URLSearchParams(window.location.search).get("fw")}),le();var U=ye();ce("1onvy6i",a=>{var r=_e();he(r,"content",ue),l(a,r)});var x=e(p(U),2);de(x,{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"});var Z=e(x,2);d(Z,{title:"Caching methods",local:"caching-methods",headingTag:"h1"});var B=e(Z,4);d(B,{title:"CacheMixin",local:"diffusers.CacheMixin",headingTag:"h2"});var u=e(B,2),F=n(u);s(F,{name:"class diffusers.CacheMixin",anchor:"diffusers.CacheMixin",source:"https://github.com/huggingface/diffusers/blob/vr_14246/src/diffusers/models/cache_utils.py#L23",parameters:[]});var _=e(F,8),z=n(_);s(z,{name:"cache_context",anchor:"diffusers.CacheMixin.cache_context",source:"https://github.com/huggingface/diffusers/blob/vr_14246/src/diffusers/models/cache_utils.py#L154",parameters:[{name:"name",val:": str"}]}),c(2),o(_);var N=e(_,2),G=n(N);s(G,{name:"enable_cache",anchor:"diffusers.CacheMixin.enable_cache",source:"https://github.com/huggingface/diffusers/blob/vr_14246/src/diffusers/models/cache_utils.py#L39",parameters:[{name:"config",val:""}],parametersDescription:[{anchor:"diffusers.CacheMixin.enable_cache.config",description:`<strong>config</strong> (<code>PyramidAttentionBroadcastConfig | FasterCacheConfig | FirstBlockCacheConfig | TextKVCacheConfig</code>) — | |
| The configuration for applying the caching technique. Currently supported caching techniques are: | |
| <ul> | |
| <li><a href="/docs/diffusers/pr_14246/en/api/cache#diffusers.PyramidAttentionBroadcastConfig">PyramidAttentionBroadcastConfig</a></li> | |
| <li><a href="/docs/diffusers/pr_14246/en/api/cache#diffusers.FasterCacheConfig">FasterCacheConfig</a></li> | |
| <li><a href="/docs/diffusers/pr_14246/en/api/cache#diffusers.FirstBlockCacheConfig">FirstBlockCacheConfig</a></li> | |
| <li><code>TextKVCacheConfig</code></li> | |
| </ul>`,name:"config"}]});var L=e(G,4);f(L,{anchor:"diffusers.CacheMixin.enable_cache.example",children:(a,r)=>{var t=m(),i=e(p(t),2);h(i,{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwQ29nVmlkZW9YUGlwZWxpbmUlMkMlMjBQeXJhbWlkQXR0ZW50aW9uQnJvYWRjYXN0Q29uZmlnJTBBJTBBcGlwZSUyMCUzRCUyMENvZ1ZpZGVvWFBpcGVsaW5lLmZyb21fcHJldHJhaW5lZCglMjJUSFVETSUyRkNvZ1ZpZGVvWC01YiUyMiUyQyUyMHRvcmNoX2R0eXBlJTNEdG9yY2guYmZsb2F0MTYpJTBBcGlwZS50byglMjJjdWRhJTIyKSUwQSUwQWNvbmZpZyUyMCUzRCUyMFB5cmFtaWRBdHRlbnRpb25Ccm9hZGNhc3RDb25maWcoJTBBJTIwJTIwJTIwJTIwc3BhdGlhbF9hdHRlbnRpb25fYmxvY2tfc2tpcF9yYW5nZSUzRDIlMkMlMEElMjAlMjAlMjAlMjBzcGF0aWFsX2F0dGVudGlvbl90aW1lc3RlcF9za2lwX3JhbmdlJTNEKDEwMCUyQyUyMDgwMCklMkMlMEElMjAlMjAlMjAlMjBjdXJyZW50X3RpbWVzdGVwX2NhbGxiYWNrJTNEbGFtYmRhJTNBJTIwcGlwZS5jdXJyZW50X3RpbWVzdGVwJTJDJTBBKSUwQXBpcGUudHJhbnNmb3JtZXIuZW5hYmxlX2NhY2hlKGNvbmZpZyk=",highlighted:`<span class="hljs-meta">>>> </span><span class="hljs-keyword">import</span> torch | |
| <span class="hljs-meta">>>> </span><span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> CogVideoXPipeline, PyramidAttentionBroadcastConfig | |
| <span class="hljs-meta">>>> </span>pipe = CogVideoXPipeline.from_pretrained(<span class="hljs-string">"THUDM/CogVideoX-5b"</span>, torch_dtype=torch.bfloat16) | |
| <span class="hljs-meta">>>> </span>pipe.to(<span class="hljs-string">"cuda"</span>) | |
| <span class="hljs-meta">>>> </span>config = PyramidAttentionBroadcastConfig( | |
| <span class="hljs-meta">... </span> spatial_attention_block_skip_range=<span class="hljs-number">2</span>, | |
| <span class="hljs-meta">... </span> spatial_attention_timestep_skip_range=(<span class="hljs-number">100</span>, <span class="hljs-number">800</span>), | |
| <span class="hljs-meta">... </span> current_timestep_callback=<span class="hljs-keyword">lambda</span>: pipe.current_timestep, | |
| <span class="hljs-meta">... </span>) | |
| <span class="hljs-meta">>>> </span>pipe.transformer.enable_cache(config)`,lang:"python",wrap:!1}),l(a,t)},$$slots:{default:!0}}),o(N),o(u);var W=e(u,2);d(W,{title:"PyramidAttentionBroadcastConfig",local:"diffusers.PyramidAttentionBroadcastConfig",headingTag:"h2"});var b=e(W,2),$=n(b);s($,{name:"class diffusers.PyramidAttentionBroadcastConfig",anchor:"diffusers.PyramidAttentionBroadcastConfig",source:"https://github.com/huggingface/diffusers/blob/vr_14246/src/diffusers/hooks/pyramid_attention_broadcast.py#L40",parameters:[{name:"spatial_attention_block_skip_range",val:": int | None = None"},{name:"temporal_attention_block_skip_range",val:": int | None = None"},{name:"cross_attention_block_skip_range",val:": int | None = None"},{name:"spatial_attention_timestep_skip_range",val:": tuple = (100, 800)"},{name:"temporal_attention_timestep_skip_range",val:": tuple = (100, 800)"},{name:"cross_attention_timestep_skip_range",val:": tuple = (100, 800)"},{name:"spatial_attention_block_identifiers",val:": tuple = ('blocks', 'transformer_blocks', 'single_transformer_blocks', 'layers', 'visual_transformer_blocks')"},{name:"temporal_attention_block_identifiers",val:": tuple = ('temporal_transformer_blocks',)"},{name:"cross_attention_block_identifiers",val:": tuple = ('blocks', 'transformer_blocks', 'layers')"},{name:"current_timestep_callback",val:": typing.Callable[[], int] = None"}],parametersDescription:[{anchor:"diffusers.PyramidAttentionBroadcastConfig.spatial_attention_block_skip_range",description:`<strong>spatial_attention_block_skip_range</strong> (<code>int</code>, <em>optional</em>, defaults to <code>None</code>) — | |
| The number of times a specific spatial attention broadcast is skipped before computing the attention states | |
| to re-use. If this is set to the value <code>N</code>, the attention computation will be skipped <code>N - 1</code> times (i.e., | |
| old attention states will be reused) before computing the new attention states again.`,name:"spatial_attention_block_skip_range"},{anchor:"diffusers.PyramidAttentionBroadcastConfig.temporal_attention_block_skip_range",description:`<strong>temporal_attention_block_skip_range</strong> (<code>int</code>, <em>optional</em>, defaults to <code>None</code>) — | |
| The number of times a specific temporal attention broadcast is skipped before computing the attention | |
| states to re-use. If this is set to the value <code>N</code>, the attention computation will be skipped <code>N - 1</code> times | |
| (i.e., old attention states will be reused) before computing the new attention states again.`,name:"temporal_attention_block_skip_range"},{anchor:"diffusers.PyramidAttentionBroadcastConfig.cross_attention_block_skip_range",description:`<strong>cross_attention_block_skip_range</strong> (<code>int</code>, <em>optional</em>, defaults to <code>None</code>) — | |
| The number of times a specific cross-attention broadcast is skipped before computing the attention states | |
| to re-use. If this is set to the value <code>N</code>, the attention computation will be skipped <code>N - 1</code> times (i.e., | |
| old attention states will be reused) before computing the new attention states again.`,name:"cross_attention_block_skip_range"},{anchor:"diffusers.PyramidAttentionBroadcastConfig.spatial_attention_timestep_skip_range",description:`<strong>spatial_attention_timestep_skip_range</strong> (<code>tuple[int, int]</code>, defaults to <code>(100, 800)</code>) — | |
| The range of timesteps to skip in the spatial attention layer. The attention computations will be | |
| conditionally skipped if the current timestep is within the specified range.`,name:"spatial_attention_timestep_skip_range"},{anchor:"diffusers.PyramidAttentionBroadcastConfig.temporal_attention_timestep_skip_range",description:`<strong>temporal_attention_timestep_skip_range</strong> (<code>tuple[int, int]</code>, defaults to <code>(100, 800)</code>) — | |
| The range of timesteps to skip in the temporal attention layer. The attention computations will be | |
| conditionally skipped if the current timestep is within the specified range.`,name:"temporal_attention_timestep_skip_range"},{anchor:"diffusers.PyramidAttentionBroadcastConfig.cross_attention_timestep_skip_range",description:`<strong>cross_attention_timestep_skip_range</strong> (<code>tuple[int, int]</code>, defaults to <code>(100, 800)</code>) — | |
| The range of timesteps to skip in the cross-attention layer. The attention computations will be | |
| conditionally skipped if the current timestep is within the specified range.`,name:"cross_attention_timestep_skip_range"},{anchor:"diffusers.PyramidAttentionBroadcastConfig.spatial_attention_block_identifiers",description:`<strong>spatial_attention_block_identifiers</strong> (<code>tuple[str, ...]</code>) — | |
| The identifiers to match against the layer names to determine if the layer is a spatial attention layer.`,name:"spatial_attention_block_identifiers"},{anchor:"diffusers.PyramidAttentionBroadcastConfig.temporal_attention_block_identifiers",description:`<strong>temporal_attention_block_identifiers</strong> (<code>tuple[str, ...]</code>) — | |
| The identifiers to match against the layer names to determine if the layer is a temporal attention layer.`,name:"temporal_attention_block_identifiers"},{anchor:"diffusers.PyramidAttentionBroadcastConfig.cross_attention_block_identifiers",description:`<strong>cross_attention_block_identifiers</strong> (<code>tuple[str, ...]</code>) — | |
| The identifiers to match against the layer names to determine if the layer is a cross-attention layer.`,name:"cross_attention_block_identifiers"}]}),c(2),o(b);var y=e(b,2),I=n(y);s(I,{name:"diffusers.apply_pyramid_attention_broadcast",anchor:"diffusers.apply_pyramid_attention_broadcast",source:"https://github.com/huggingface/diffusers/blob/vr_14246/src/diffusers/hooks/pyramid_attention_broadcast.py#L181",parameters:[{name:"module",val:": Module"},{name:"config",val:": PyramidAttentionBroadcastConfig"}],parametersDescription:[{anchor:"diffusers.apply_pyramid_attention_broadcast.module",description:`<strong>module</strong> (<code>torch.nn.Module</code>) — | |
| The module to apply Pyramid Attention Broadcast to.`,name:"module"},{anchor:"diffusers.apply_pyramid_attention_broadcast.config",description:`<strong>config</strong> (<code>PyramidAttentionBroadcastConfig | None</code>, <code>optional</code>, defaults to <code>None</code>) — | |
| The configuration to use for Pyramid Attention Broadcast.`,name:"config"}]});var K=e(I,6);f(K,{anchor:"diffusers.apply_pyramid_attention_broadcast.example",children:(a,r)=>{var t=m(),i=e(p(t),2);h(i,{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwQ29nVmlkZW9YUGlwZWxpbmUlMkMlMjBQeXJhbWlkQXR0ZW50aW9uQnJvYWRjYXN0Q29uZmlnJTJDJTIwYXBwbHlfcHlyYW1pZF9hdHRlbnRpb25fYnJvYWRjYXN0JTBBZnJvbSUyMGRpZmZ1c2Vycy51dGlscyUyMGltcG9ydCUyMGV4cG9ydF90b192aWRlbyUwQSUwQXBpcGUlMjAlM0QlMjBDb2dWaWRlb1hQaXBlbGluZS5mcm9tX3ByZXRyYWluZWQoJTIyVEhVRE0lMkZDb2dWaWRlb1gtNWIlMjIlMkMlMjB0b3JjaF9kdHlwZSUzRHRvcmNoLmJmbG9hdDE2KSUwQXBpcGUudG8oJTIyY3VkYSUyMiklMEElMEFjb25maWclMjAlM0QlMjBQeXJhbWlkQXR0ZW50aW9uQnJvYWRjYXN0Q29uZmlnKCUwQSUyMCUyMCUyMCUyMHNwYXRpYWxfYXR0ZW50aW9uX2Jsb2NrX3NraXBfcmFuZ2UlM0QyJTJDJTBBJTIwJTIwJTIwJTIwc3BhdGlhbF9hdHRlbnRpb25fdGltZXN0ZXBfc2tpcF9yYW5nZSUzRCgxMDAlMkMlMjA4MDApJTJDJTBBJTIwJTIwJTIwJTIwY3VycmVudF90aW1lc3RlcF9jYWxsYmFjayUzRGxhbWJkYSUzQSUyMHBpcGUuY3VycmVudF90aW1lc3RlcCUyQyUwQSklMEFhcHBseV9weXJhbWlkX2F0dGVudGlvbl9icm9hZGNhc3QocGlwZS50cmFuc2Zvcm1lciUyQyUyMGNvbmZpZyk=",highlighted:`<span class="hljs-meta">>>> </span><span class="hljs-keyword">import</span> torch | |
| <span class="hljs-meta">>>> </span><span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> CogVideoXPipeline, PyramidAttentionBroadcastConfig, apply_pyramid_attention_broadcast | |
| <span class="hljs-meta">>>> </span><span class="hljs-keyword">from</span> diffusers.utils <span class="hljs-keyword">import</span> export_to_video | |
| <span class="hljs-meta">>>> </span>pipe = CogVideoXPipeline.from_pretrained(<span class="hljs-string">"THUDM/CogVideoX-5b"</span>, torch_dtype=torch.bfloat16) | |
| <span class="hljs-meta">>>> </span>pipe.to(<span class="hljs-string">"cuda"</span>) | |
| <span class="hljs-meta">>>> </span>config = PyramidAttentionBroadcastConfig( | |
| <span class="hljs-meta">... </span> spatial_attention_block_skip_range=<span class="hljs-number">2</span>, | |
| <span class="hljs-meta">... </span> spatial_attention_timestep_skip_range=(<span class="hljs-number">100</span>, <span class="hljs-number">800</span>), | |
| <span class="hljs-meta">... </span> current_timestep_callback=<span class="hljs-keyword">lambda</span>: pipe.current_timestep, | |
| <span class="hljs-meta">... </span>) | |
| <span class="hljs-meta">>>> </span>apply_pyramid_attention_broadcast(pipe.transformer, config)`,lang:"python",wrap:!1}),l(a,t)},$$slots:{default:!0}}),o(y);var X=e(y,2);d(X,{title:"FasterCacheConfig",local:"diffusers.FasterCacheConfig",headingTag:"h2"});var w=e(X,2),O=n(w);s(O,{name:"class diffusers.FasterCacheConfig",anchor:"diffusers.FasterCacheConfig",source:"https://github.com/huggingface/diffusers/blob/vr_14246/src/diffusers/hooks/faster_cache.py#L50",parameters:[{name:"spatial_attention_block_skip_range",val:": int = 2"},{name:"temporal_attention_block_skip_range",val:": int | None = None"},{name:"spatial_attention_timestep_skip_range",val:": tuple = (-1, 681)"},{name:"temporal_attention_timestep_skip_range",val:": tuple = (-1, 681)"},{name:"low_frequency_weight_update_timestep_range",val:": tuple = (99, 901)"},{name:"high_frequency_weight_update_timestep_range",val:": tuple = (-1, 301)"},{name:"alpha_low_frequency",val:": float = 1.1"},{name:"alpha_high_frequency",val:": float = 1.1"},{name:"unconditional_batch_skip_range",val:": int = 5"},{name:"unconditional_batch_timestep_skip_range",val:": tuple = (-1, 641)"},{name:"spatial_attention_block_identifiers",val:": tuple = ('^blocks.*attn', '^transformer_blocks.*attn', '^single_transformer_blocks.*attn')"},{name:"temporal_attention_block_identifiers",val:": tuple = ('^temporal_transformer_blocks.*attn',)"},{name:"attention_weight_callback",val:": typing.Callable[[torch.nn.Module], float] = None"},{name:"low_frequency_weight_callback",val:": typing.Callable[[torch.nn.Module], float] = None"},{name:"high_frequency_weight_callback",val:": typing.Callable[[torch.nn.Module], float] = None"},{name:"tensor_format",val:": str = 'BCFHW'"},{name:"is_guidance_distilled",val:": bool = False"},{name:"current_timestep_callback",val:": typing.Callable[[], int] = None"},{name:"_unconditional_conditional_input_kwargs_identifiers",val:": list = ('hidden_states', 'encoder_hidden_states', 'timestep', 'attention_mask', 'encoder_attention_mask')"}],parametersDescription:[{anchor:"diffusers.FasterCacheConfig.spatial_attention_block_skip_range",description:`<strong>spatial_attention_block_skip_range</strong> (<code>int</code>, defaults to <code>2</code>) — | |
| Calculate the attention states every <code>N</code> iterations. If this is set to <code>N</code>, the attention computation will | |
| be skipped <code>N - 1</code> times (i.e., cached attention states will be reused) before computing the new attention | |
| states again.`,name:"spatial_attention_block_skip_range"},{anchor:"diffusers.FasterCacheConfig.temporal_attention_block_skip_range",description:`<strong>temporal_attention_block_skip_range</strong> (<code>int</code>, <em>optional</em>, defaults to <code>None</code>) — | |
| Calculate the attention states every <code>N</code> iterations. If this is set to <code>N</code>, the attention computation will | |
| be skipped <code>N - 1</code> times (i.e., cached attention states will be reused) before computing the new attention | |
| states again.`,name:"temporal_attention_block_skip_range"},{anchor:"diffusers.FasterCacheConfig.spatial_attention_timestep_skip_range",description:`<strong>spatial_attention_timestep_skip_range</strong> (<code>tuple[float, float]</code>, defaults to <code>(-1, 681)</code>) — | |
| The timestep range within which the spatial attention computation can be skipped without a significant loss | |
| in quality. This is to be determined by the user based on the underlying model. The first value in the | |
| tuple is the lower bound and the second value is the upper bound. Typically, diffusion timesteps for | |
| denoising are in the reversed range of 0 to 1000 (i.e. denoising starts at timestep 1000 and ends at | |
| timestep 0). For the default values, this would mean that the spatial attention computation skipping will | |
| be applicable only after denoising timestep 681 is reached, and continue until the end of the denoising | |
| process.`,name:"spatial_attention_timestep_skip_range"},{anchor:"diffusers.FasterCacheConfig.temporal_attention_timestep_skip_range",description:`<strong>temporal_attention_timestep_skip_range</strong> (<code>tuple[float, float]</code>, <em>optional</em>, defaults to <code>None</code>) — | |
| The timestep range within which the temporal attention computation can be skipped without a significant | |
| loss in quality. This is to be determined by the user based on the underlying model. The first value in the | |
| tuple is the lower bound and the second value is the upper bound. Typically, diffusion timesteps for | |
| denoising are in the reversed range of 0 to 1000 (i.e. denoising starts at timestep 1000 and ends at | |
| timestep 0).`,name:"temporal_attention_timestep_skip_range"},{anchor:"diffusers.FasterCacheConfig.low_frequency_weight_update_timestep_range",description:`<strong>low_frequency_weight_update_timestep_range</strong> (<code>tuple[int, int]</code>, defaults to <code>(99, 901)</code>) — | |
| The timestep range within which the low frequency weight scaling update is applied. The first value in the | |
| tuple is the lower bound and the second value is the upper bound of the timestep range. The callback | |
| function for the update is called only within this range.`,name:"low_frequency_weight_update_timestep_range"},{anchor:"diffusers.FasterCacheConfig.high_frequency_weight_update_timestep_range",description:`<strong>high_frequency_weight_update_timestep_range</strong> (<code>tuple[int, int]</code>, defaults to <code>(-1, 301)</code>) — | |
| The timestep range within which the high frequency weight scaling update is applied. The first value in the | |
| tuple is the lower bound and the second value is the upper bound of the timestep range. The callback | |
| function for the update is called only within this range.`,name:"high_frequency_weight_update_timestep_range"},{anchor:"diffusers.FasterCacheConfig.alpha_low_frequency",description:`<strong>alpha_low_frequency</strong> (<code>float</code>, defaults to <code>1.1</code>) — | |
| The weight to scale the low frequency updates by. This is used to approximate the unconditional branch from | |
| the conditional branch outputs.`,name:"alpha_low_frequency"},{anchor:"diffusers.FasterCacheConfig.alpha_high_frequency",description:`<strong>alpha_high_frequency</strong> (<code>float</code>, defaults to <code>1.1</code>) — | |
| The weight to scale the high frequency updates by. This is used to approximate the unconditional branch | |
| from the conditional branch outputs.`,name:"alpha_high_frequency"},{anchor:"diffusers.FasterCacheConfig.unconditional_batch_skip_range",description:`<strong>unconditional_batch_skip_range</strong> (<code>int</code>, defaults to <code>5</code>) — | |
| Process the unconditional branch every <code>N</code> iterations. If this is set to <code>N</code>, the unconditional branch | |
| computation will be skipped <code>N - 1</code> times (i.e., cached unconditional branch states will be reused) before | |
| computing the new unconditional branch states again.`,name:"unconditional_batch_skip_range"},{anchor:"diffusers.FasterCacheConfig.unconditional_batch_timestep_skip_range",description:`<strong>unconditional_batch_timestep_skip_range</strong> (<code>tuple[float, float]</code>, defaults to <code>(-1, 641)</code>) — | |
| The timestep range within which the unconditional branch computation can be skipped without a significant | |
| loss in quality. This is to be determined by the user based on the underlying model. The first value in the | |
| tuple is the lower bound and the second value is the upper bound.`,name:"unconditional_batch_timestep_skip_range"},{anchor:"diffusers.FasterCacheConfig.spatial_attention_block_identifiers",description:`<strong>spatial_attention_block_identifiers</strong> (<code>tuple[str, ...]</code>, defaults to <code>("blocks.*attn1", "transformer_blocks.*attn1", "single_transformer_blocks.*attn1")</code>) — | |
| The identifiers to match the spatial attention blocks in the model. If the name of the block contains any | |
| of these identifiers, FasterCache will be applied to that block. This can either be the full layer names, | |
| partial layer names, or regex patterns. Matching will always be done using a regex match.`,name:"spatial_attention_block_identifiers"},{anchor:"diffusers.FasterCacheConfig.temporal_attention_block_identifiers",description:`<strong>temporal_attention_block_identifiers</strong> (<code>tuple[str, ...]</code>, defaults to <code>("temporal_transformer_blocks.*attn1",)</code>) — | |
| The identifiers to match the temporal attention blocks in the model. If the name of the block contains any | |
| of these identifiers, FasterCache will be applied to that block. This can either be the full layer names, | |
| partial layer names, or regex patterns. Matching will always be done using a regex match.`,name:"temporal_attention_block_identifiers"},{anchor:"diffusers.FasterCacheConfig.attention_weight_callback",description:`<strong>attention_weight_callback</strong> (<code>Callable[[torch.nn.Module], float]</code>, defaults to <code>None</code>) — | |
| The callback function to determine the weight to scale the attention outputs by. This function should take | |
| the attention module as input and return a float value. This is used to approximate the unconditional | |
| branch from the conditional branch outputs. If not provided, the default weight is 0.5 for all timesteps. | |
| Typically, as described in the paper, this weight should gradually increase from 0 to 1 as the inference | |
| progresses. Users are encouraged to experiment and provide custom weight schedules that take into account | |
| the number of inference steps and underlying model behaviour as denoising progresses.`,name:"attention_weight_callback"},{anchor:"diffusers.FasterCacheConfig.low_frequency_weight_callback",description:`<strong>low_frequency_weight_callback</strong> (<code>Callable[[torch.nn.Module], float]</code>, defaults to <code>None</code>) — | |
| The callback function to determine the weight to scale the low frequency updates by. If not provided, the | |
| default weight is 1.1 for timesteps within the range specified (as described in the paper).`,name:"low_frequency_weight_callback"},{anchor:"diffusers.FasterCacheConfig.high_frequency_weight_callback",description:`<strong>high_frequency_weight_callback</strong> (<code>Callable[[torch.nn.Module], float]</code>, defaults to <code>None</code>) — | |
| The callback function to determine the weight to scale the high frequency updates by. If not provided, the | |
| default weight is 1.1 for timesteps within the range specified (as described in the paper).`,name:"high_frequency_weight_callback"},{anchor:"diffusers.FasterCacheConfig.tensor_format",description:`<strong>tensor_format</strong> (<code>str</code>, defaults to <code>"BCFHW"</code>) — | |
| The format of the input tensors. This should be one of <code>"BCFHW"</code>, <code>"BFCHW"</code>, or <code>"BCHW"</code>. The format is | |
| used to split individual latent frames in order for low and high frequency components to be computed.`,name:"tensor_format"},{anchor:"diffusers.FasterCacheConfig.is_guidance_distilled",description:`<strong>is_guidance_distilled</strong> (<code>bool</code>, defaults to <code>False</code>) — | |
| Whether the model is guidance distilled or not. If the model is guidance distilled, FasterCache will not be | |
| applied at the denoiser-level to skip the unconditional branch computation (as there is none).`,name:"is_guidance_distilled"},{anchor:"diffusers.FasterCacheConfig._unconditional_conditional_input_kwargs_identifiers",description:`<strong>_unconditional_conditional_input_kwargs_identifiers</strong> (<code>list[str]</code>, defaults to <code>("hidden_states", "encoder_hidden_states", "timestep", "attention_mask", "encoder_attention_mask")</code>) — | |
| The identifiers to match the input kwargs that contain the batchwise-concatenated unconditional and | |
| conditional inputs. If the name of the input kwargs contains any of these identifiers, FasterCache will | |
| split the inputs into unconditional and conditional branches. This must be a list of exact input kwargs | |
| names that contain the batchwise-concatenated unconditional and conditional inputs.`,name:"_unconditional_conditional_input_kwargs_identifiers"}]}),c(2),o(w);var k=e(w,2),q=n(k);s(q,{name:"diffusers.apply_faster_cache",anchor:"diffusers.apply_faster_cache",source:"https://github.com/huggingface/diffusers/blob/vr_14246/src/diffusers/hooks/faster_cache.py#L486",parameters:[{name:"module",val:": Module"},{name:"config",val:": FasterCacheConfig"}],parametersDescription:[{anchor:"diffusers.apply_faster_cache.module",description:`<strong>module</strong> (<code>torch.nn.Module</code>) — | |
| The pytorch module to apply FasterCache to. Typically, this should be a transformer architecture supported | |
| in Diffusers, such as <code>CogVideoXTransformer3DModel</code>, but external implementations may also work.`,name:"module"},{anchor:"diffusers.apply_faster_cache.config",description:`<strong>config</strong> (<code>FasterCacheConfig</code>) — | |
| The configuration to use for FasterCache.`,name:"config"}]});var ee=e(q,4);f(ee,{anchor:"diffusers.apply_faster_cache.example",children:(a,r)=>{var t=m(),i=e(p(t),2);h(i,{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwQ29nVmlkZW9YUGlwZWxpbmUlMkMlMjBGYXN0ZXJDYWNoZUNvbmZpZyUyQyUyMGFwcGx5X2Zhc3Rlcl9jYWNoZSUwQSUwQXBpcGUlMjAlM0QlMjBDb2dWaWRlb1hQaXBlbGluZS5mcm9tX3ByZXRyYWluZWQoJTIyVEhVRE0lMkZDb2dWaWRlb1gtNWIlMjIlMkMlMjB0b3JjaF9kdHlwZSUzRHRvcmNoLmJmbG9hdDE2KSUwQXBpcGUudG8oJTIyY3VkYSUyMiklMEElMEFjb25maWclMjAlM0QlMjBGYXN0ZXJDYWNoZUNvbmZpZyglMEElMjAlMjAlMjAlMjBzcGF0aWFsX2F0dGVudGlvbl9ibG9ja19za2lwX3JhbmdlJTNEMiUyQyUwQSUyMCUyMCUyMCUyMHNwYXRpYWxfYXR0ZW50aW9uX3RpbWVzdGVwX3NraXBfcmFuZ2UlM0QoLTElMkMlMjA2ODEpJTJDJTBBJTIwJTIwJTIwJTIwbG93X2ZyZXF1ZW5jeV93ZWlnaHRfdXBkYXRlX3RpbWVzdGVwX3JhbmdlJTNEKDk5JTJDJTIwNjQxKSUyQyUwQSUyMCUyMCUyMCUyMGhpZ2hfZnJlcXVlbmN5X3dlaWdodF91cGRhdGVfdGltZXN0ZXBfcmFuZ2UlM0QoLTElMkMlMjAzMDEpJTJDJTBBJTIwJTIwJTIwJTIwc3BhdGlhbF9hdHRlbnRpb25fYmxvY2tfaWRlbnRpZmllcnMlM0QlNUIlMjJ0cmFuc2Zvcm1lcl9ibG9ja3MlMjIlNUQlMkMlMEElMjAlMjAlMjAlMjBhdHRlbnRpb25fd2VpZ2h0X2NhbGxiYWNrJTNEbGFtYmRhJTIwXyUzQSUyMDAuMyUyQyUwQSUyMCUyMCUyMCUyMHRlbnNvcl9mb3JtYXQlM0QlMjJCRkNIVyUyMiUyQyUwQSklMEFhcHBseV9mYXN0ZXJfY2FjaGUocGlwZS50cmFuc2Zvcm1lciUyQyUyMGNvbmZpZyk=",highlighted:`<span class="hljs-meta">>>> </span><span class="hljs-keyword">import</span> torch | |
| <span class="hljs-meta">>>> </span><span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> CogVideoXPipeline, FasterCacheConfig, apply_faster_cache | |
| <span class="hljs-meta">>>> </span>pipe = CogVideoXPipeline.from_pretrained(<span class="hljs-string">"THUDM/CogVideoX-5b"</span>, torch_dtype=torch.bfloat16) | |
| <span class="hljs-meta">>>> </span>pipe.to(<span class="hljs-string">"cuda"</span>) | |
| <span class="hljs-meta">>>> </span>config = FasterCacheConfig( | |
| <span class="hljs-meta">... </span> spatial_attention_block_skip_range=<span class="hljs-number">2</span>, | |
| <span class="hljs-meta">... </span> spatial_attention_timestep_skip_range=(-<span class="hljs-number">1</span>, <span class="hljs-number">681</span>), | |
| <span class="hljs-meta">... </span> low_frequency_weight_update_timestep_range=(<span class="hljs-number">99</span>, <span class="hljs-number">641</span>), | |
| <span class="hljs-meta">... </span> high_frequency_weight_update_timestep_range=(-<span class="hljs-number">1</span>, <span class="hljs-number">301</span>), | |
| <span class="hljs-meta">... </span> spatial_attention_block_identifiers=[<span class="hljs-string">"transformer_blocks"</span>], | |
| <span class="hljs-meta">... </span> attention_weight_callback=<span class="hljs-keyword">lambda</span> _: <span class="hljs-number">0.3</span>, | |
| <span class="hljs-meta">... </span> tensor_format=<span class="hljs-string">"BFCHW"</span>, | |
| <span class="hljs-meta">... </span>) | |
| <span class="hljs-meta">>>> </span>apply_faster_cache(pipe.transformer, config)`,lang:"python",wrap:!1}),l(a,t)},$$slots:{default:!0}}),o(k);var Q=e(k,2);d(Q,{title:"FirstBlockCacheConfig",local:"diffusers.FirstBlockCacheConfig",headingTag:"h2"});var C=e(Q,2),te=n(C);s(te,{name:"class diffusers.FirstBlockCacheConfig",anchor:"diffusers.FirstBlockCacheConfig",source:"https://github.com/huggingface/diffusers/blob/vr_14246/src/diffusers/hooks/first_block_cache.py#L33",parameters:[{name:"threshold",val:": float = 0.05"}],parametersDescription:[{anchor:"diffusers.FirstBlockCacheConfig.threshold",description:`<strong>threshold</strong> (<code>float</code>, defaults to <code>0.05</code>) — | |
| The threshold to determine whether or not a forward pass through all layers of the model is required. A | |
| higher threshold usually results in a forward pass through a lower number of layers and faster inference, | |
| but might lead to poorer generation quality. A lower threshold may not result in significant generation | |
| speedup. The threshold is compared against the absmean difference of the residuals between the current and | |
| cached outputs from the first transformer block. If the difference is below the threshold, the forward pass | |
| is skipped.`,name:"threshold"}]}),c(2),o(C);var v=e(C,2),R=n(v);s(R,{name:"diffusers.apply_first_block_cache",anchor:"diffusers.apply_first_block_cache",source:"https://github.com/huggingface/diffusers/blob/vr_14246/src/diffusers/hooks/first_block_cache.py#L193",parameters:[{name:"module",val:": Module"},{name:"config",val:": FirstBlockCacheConfig"}],parametersDescription:[{anchor:"diffusers.apply_first_block_cache.module",description:`<strong>module</strong> (<code>torch.nn.Module</code>) — | |
| The pytorch module to apply FBCache to. Typically, this should be a transformer architecture supported in | |
| Diffusers, such as <code>CogVideoXTransformer3DModel</code>, but external implementations may also work.`,name:"module"},{anchor:"diffusers.apply_first_block_cache.config",description:`<strong>config</strong> (<code>FirstBlockCacheConfig</code>) — | |
| The configuration to use for applying the FBCache method.`,name:"config"}]});var ae=e(R,6);f(ae,{anchor:"diffusers.apply_first_block_cache.example",children:(a,r)=>{var t=m(),i=e(p(t),2);h(i,{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwQ29nVmlldzRQaXBlbGluZSUwQWZyb20lMjBkaWZmdXNlcnMuaG9va3MlMjBpbXBvcnQlMjBhcHBseV9maXJzdF9ibG9ja19jYWNoZSUyQyUyMEZpcnN0QmxvY2tDYWNoZUNvbmZpZyUwQSUwQXBpcGUlMjAlM0QlMjBDb2dWaWV3NFBpcGVsaW5lLmZyb21fcHJldHJhaW5lZCglMjJUSFVETSUyRkNvZ1ZpZXc0LTZCJTIyJTJDJTIwdG9yY2hfZHR5cGUlM0R0b3JjaC5iZmxvYXQxNiklMEFwaXBlLnRvKCUyMmN1ZGElMjIpJTBBJTBBYXBwbHlfZmlyc3RfYmxvY2tfY2FjaGUocGlwZS50cmFuc2Zvcm1lciUyQyUyMEZpcnN0QmxvY2tDYWNoZUNvbmZpZyh0aHJlc2hvbGQlM0QwLjIpKSUwQSUwQXByb21wdCUyMCUzRCUyMCUyMkElMjBwaG90byUyMG9mJTIwYW4lMjBhc3Ryb25hdXQlMjByaWRpbmclMjBhJTIwaG9yc2UlMjBvbiUyMG1hcnMlMjIlMEFpbWFnZSUyMCUzRCUyMHBpcGUocHJvbXB0JTJDJTIwZ2VuZXJhdG9yJTNEdG9yY2guR2VuZXJhdG9yKCkubWFudWFsX3NlZWQoNDIpKS5pbWFnZXMlNUIwJTVEJTBBaW1hZ2Uuc2F2ZSglMjJvdXRwdXQucG5nJTIyKQ==",highlighted:`<span class="hljs-meta">>>> </span><span class="hljs-keyword">import</span> torch | |
| <span class="hljs-meta">>>> </span><span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> CogView4Pipeline | |
| <span class="hljs-meta">>>> </span><span class="hljs-keyword">from</span> diffusers.hooks <span class="hljs-keyword">import</span> apply_first_block_cache, FirstBlockCacheConfig | |
| <span class="hljs-meta">>>> </span>pipe = CogView4Pipeline.from_pretrained(<span class="hljs-string">"THUDM/CogView4-6B"</span>, torch_dtype=torch.bfloat16) | |
| <span class="hljs-meta">>>> </span>pipe.to(<span class="hljs-string">"cuda"</span>) | |
| <span class="hljs-meta">>>> </span>apply_first_block_cache(pipe.transformer, FirstBlockCacheConfig(threshold=<span class="hljs-number">0.2</span>)) | |
| <span class="hljs-meta">>>> </span>prompt = <span class="hljs-string">"A photo of an astronaut riding a horse on mars"</span> | |
| <span class="hljs-meta">>>> </span>image = pipe(prompt, generator=torch.Generator().manual_seed(<span class="hljs-number">42</span>)).images[<span class="hljs-number">0</span>] | |
| <span class="hljs-meta">>>> </span>image.save(<span class="hljs-string">"output.png"</span>)`,lang:"python",wrap:!1}),l(a,t)},$$slots:{default:!0}}),o(v);var Y=e(v,2);d(Y,{title:"TaylorSeerCacheConfig",local:"diffusers.TaylorSeerCacheConfig",headingTag:"h2"});var M=e(Y,2),V=n(M);s(V,{name:"class diffusers.TaylorSeerCacheConfig",anchor:"diffusers.TaylorSeerCacheConfig",source:"https://github.com/huggingface/diffusers/blob/vr_14246/src/diffusers/hooks/taylorseer_cache.py#L26",parameters:[{name:"cache_interval",val:": int = 5"},{name:"disable_cache_before_step",val:": int = 3"},{name:"disable_cache_after_step",val:": int | None = None"},{name:"max_order",val:": int = 1"},{name:"taylor_factors_dtype",val:": typing.Optional[torch.dtype] = torch.bfloat16"},{name:"skip_predict_identifiers",val:": list[str] | None = None"},{name:"cache_identifiers",val:": list[str] | None = None"},{name:"use_lite_mode",val:": bool = False"}],parametersDescription:[{anchor:"diffusers.TaylorSeerCacheConfig.cache_interval",description:`<strong>cache_interval</strong> (<code>int</code>, defaults to <code>5</code>) — | |
| The interval between full computation steps. After a full computation, the cached (predicted) outputs are | |
| reused for this many subsequent denoising steps before refreshing with a new full forward pass.`,name:"cache_interval"},{anchor:"diffusers.TaylorSeerCacheConfig.disable_cache_before_step",description:`<strong>disable_cache_before_step</strong> (<code>int</code>, defaults to <code>3</code>) — | |
| The denoising step index before which caching is disabled, meaning full computation is performed for the | |
| initial steps (0 to disable_cache_before_step - 1) to gather data for Taylor series approximations. During | |
| these steps, Taylor factors are updated, but caching/predictions are not applied. Caching begins at this | |
| step.`,name:"disable_cache_before_step"},{anchor:"diffusers.TaylorSeerCacheConfig.disable_cache_after_step",description:`<strong>disable_cache_after_step</strong> (<code>int</code>, <em>optional</em>, defaults to <code>None</code>) — | |
| The denoising step index after which caching is disabled. If set, for steps >= this value, all modules run | |
| full computations without predictions or state updates, ensuring accuracy in later stages if needed.`,name:"disable_cache_after_step"},{anchor:"diffusers.TaylorSeerCacheConfig.max_order",description:`<strong>max_order</strong> (<code>int</code>, defaults to <code>1</code>) — | |
| The highest order in the Taylor series expansion for approximating module outputs. Higher orders provide | |
| better approximations but increase computation and memory usage.`,name:"max_order"},{anchor:"diffusers.TaylorSeerCacheConfig.taylor_factors_dtype",description:`<strong>taylor_factors_dtype</strong> (<code>torch.dtype</code>, defaults to <code>torch.bfloat16</code>) — | |
| Data type used for storing and computing Taylor series factors. Lower precision reduces memory but may | |
| affect stability; higher precision improves accuracy at the cost of more memory.`,name:"taylor_factors_dtype"},{anchor:"diffusers.TaylorSeerCacheConfig.skip_predict_identifiers",description:`<strong>skip_predict_identifiers</strong> (<code>list[str]</code>, <em>optional</em>, defaults to <code>None</code>) — | |
| Regex patterns (using <code>re.fullmatch</code>) for module names to place as “skip” in “cache” mode. In this mode, | |
| the module computes fully during initial or refresh steps but returns a zero tensor (matching recorded | |
| shape) during prediction steps to skip computation cheaply.`,name:"skip_predict_identifiers"},{anchor:"diffusers.TaylorSeerCacheConfig.cache_identifiers",description:`<strong>cache_identifiers</strong> (<code>list[str]</code>, <em>optional</em>, defaults to <code>None</code>) — | |
| Regex patterns (using <code>re.fullmatch</code>) for module names to place in Taylor-series caching mode, where | |
| outputs are approximated and cached for reuse.`,name:"cache_identifiers"},{anchor:"diffusers.TaylorSeerCacheConfig.use_lite_mode",description:`<strong>use_lite_mode</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>False</code>) — | |
| Enables a lightweight TaylorSeer variant that minimizes memory usage by applying predefined patterns for | |
| skipping and caching (e.g., skipping blocks and caching projections). This overrides any custom | |
| <code>inactive_identifiers</code> or <code>active_identifiers</code>.`,name:"use_lite_mode"}]});var S=e(V,8);f(S,{anchor:"diffusers.TaylorSeerCacheConfig.example",children:(a,r)=>{var t=be(),i=e(p(t),2);h(i,{code:"ZGVmJTIwZm9yd2FyZCh4KSUzQSUwQSUyMCUyMCUyMCUyMHglMjAlM0QlMjBzZWxmLm1vZHVsZTEoeCklMjAlMjAlMjMlMjBpbmFjdGl2ZSUyMG1vZHVsZSUzQSUyMHJldHVybnMlMjB6ZXJvcyUyMHRlbnNvciUyMGJhc2VkJTIwb24lMjBzaGFwZSUyMHJlY29yZGVkJTIwZHVyaW5nJTIwZnVsbCUyMGNvbXB1dGUlMEElMjAlMjAlMjAlMjB4JTIwJTNEJTIwc2VsZi5tb2R1bGUyKHgpJTIwJTIwJTIzJTIwYWN0aXZlJTIwbW9kdWxlJTNBJTIwY2FjaGVzJTIwb3V0cHV0JTIwaGVyZSUyQyUyMGF2b2lkaW5nJTIwcmVjb21wdXRhdGlvbiUyMG9mJTIwcHJpb3IlMjBzdGVwcyUwQSUyMCUyMCUyMCUyMHJldHVybiUyMHg=",highlighted:`<span class="hljs-keyword">def</span> <span class="hljs-title function_">forward</span>(<span class="hljs-params">x</span>): | |
| x = <span class="hljs-variable language_">self</span>.module1(x) <span class="hljs-comment"># inactive module: returns zeros tensor based on shape recorded during full compute</span> | |
| x = <span class="hljs-variable language_">self</span>.module2(x) <span class="hljs-comment"># active module: caches output here, avoiding recomputation of prior steps</span> | |
| <span class="hljs-keyword">return</span> x`,lang:"py",wrap:!1}),l(a,t)},$$slots:{default:!0}});var A=e(S,2),se=n(A);s(se,{name:"bfloat16",anchor:"diffusers.TaylorSeerCacheConfig.taylor_factors_dtype",parameters:[{name:"*args",val:""},{name:"**kwargs",val:""}]}),c(2),o(A),o(M);var T=e(M,2),E=n(T);s(E,{name:"diffusers.apply_taylorseer_cache",anchor:"diffusers.apply_taylorseer_cache",source:"https://github.com/huggingface/diffusers/blob/vr_14246/src/diffusers/hooks/taylorseer_cache.py#L258",parameters:[{name:"module",val:": Module"},{name:"config",val:": TaylorSeerCacheConfig"}],parametersDescription:[{anchor:"diffusers.apply_taylorseer_cache.module",description:"<strong>module</strong> (torch.nn.Module) — The model subtree to apply the hooks to.",name:"module"},{anchor:"diffusers.apply_taylorseer_cache.config",description:"<strong>config</strong> (TaylorSeerCacheConfig) — Configuration for the cache.",name:"config"}]});var ne=e(E,6);f(ne,{anchor:"diffusers.apply_taylorseer_cache.example",children:(a,r)=>{var t=m(),i=e(p(t),2);h(i,{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwRmx1eFBpcGVsaW5lJTJDJTIwVGF5bG9yU2VlckNhY2hlQ29uZmlnJTBBJTBBcGlwZSUyMCUzRCUyMEZsdXhQaXBlbGluZS5mcm9tX3ByZXRyYWluZWQoJTBBJTIwJTIwJTIwJTIwJTIyYmxhY2stZm9yZXN0LWxhYnMlMkZGTFVYLjEtZGV2JTIyJTJDJTBBJTIwJTIwJTIwJTIwdG9yY2hfZHR5cGUlM0R0b3JjaC5iZmxvYXQxNiUyQyUwQSklMEFwaXBlLnRvKCUyMmN1ZGElMjIpJTBBJTBBY29uZmlnJTIwJTNEJTIwVGF5bG9yU2VlckNhY2hlQ29uZmlnKCUwQSUyMCUyMCUyMCUyMGNhY2hlX2ludGVydmFsJTNENSUyQyUwQSUyMCUyMCUyMCUyMG1heF9vcmRlciUzRDElMkMlMEElMjAlMjAlMjAlMjBkaXNhYmxlX2NhY2hlX2JlZm9yZV9zdGVwJTNEMyUyQyUwQSUyMCUyMCUyMCUyMHRheWxvcl9mYWN0b3JzX2R0eXBlJTNEdG9yY2guZmxvYXQzMiUyQyUwQSklMEFwaXBlLnRyYW5zZm9ybWVyLmVuYWJsZV9jYWNoZShjb25maWcp",highlighted:`<span class="hljs-meta">>>> </span><span class="hljs-keyword">import</span> torch | |
| <span class="hljs-meta">>>> </span><span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> FluxPipeline, TaylorSeerCacheConfig | |
| <span class="hljs-meta">>>> </span>pipe = FluxPipeline.from_pretrained( | |
| <span class="hljs-meta">... </span> <span class="hljs-string">"black-forest-labs/FLUX.1-dev"</span>, | |
| <span class="hljs-meta">... </span> torch_dtype=torch.bfloat16, | |
| <span class="hljs-meta">... </span>) | |
| <span class="hljs-meta">>>> </span>pipe.to(<span class="hljs-string">"cuda"</span>) | |
| <span class="hljs-meta">>>> </span>config = TaylorSeerCacheConfig( | |
| <span class="hljs-meta">... </span> cache_interval=<span class="hljs-number">5</span>, | |
| <span class="hljs-meta">... </span> max_order=<span class="hljs-number">1</span>, | |
| <span class="hljs-meta">... </span> disable_cache_before_step=<span class="hljs-number">3</span>, | |
| <span class="hljs-meta">... </span> taylor_factors_dtype=torch.float32, | |
| <span class="hljs-meta">... </span>) | |
| <span class="hljs-meta">>>> </span>pipe.transformer.enable_cache(config)`,lang:"python",wrap:!1}),l(a,t)},$$slots:{default:!0}}),o(T);var D=e(T,2);d(D,{title:"MagCacheConfig",local:"diffusers.MagCacheConfig",headingTag:"h2"});var j=e(D,2),oe=n(j);s(oe,{name:"class diffusers.MagCacheConfig",anchor:"diffusers.MagCacheConfig",source:"https://github.com/huggingface/diffusers/blob/vr_14246/src/diffusers/hooks/mag_cache.py#L84",parameters:[{name:"threshold",val:": float = 0.06"},{name:"max_skip_steps",val:": int = 3"},{name:"retention_ratio",val:": float = 0.2"},{name:"num_inference_steps",val:": int = 28"},{name:"mag_ratios",val:": typing.Union[torch.Tensor, typing.List[float], NoneType] = None"},{name:"calibrate",val:": bool = False"}],parametersDescription:[{anchor:"diffusers.MagCacheConfig.threshold",description:`<strong>threshold</strong> (<code>float</code>, defaults to <code>0.06</code>) — | |
| The threshold for the accumulated error. If the accumulated error is below this threshold, the block | |
| computation is skipped. A higher threshold allows for more aggressive skipping (faster) but may degrade | |
| quality.`,name:"threshold"},{anchor:"diffusers.MagCacheConfig.max_skip_steps",description:`<strong>max_skip_steps</strong> (<code>int</code>, defaults to <code>3</code>) — | |
| The maximum number of consecutive steps that can be skipped (K in the paper).`,name:"max_skip_steps"},{anchor:"diffusers.MagCacheConfig.retention_ratio",description:`<strong>retention_ratio</strong> (<code>float</code>, defaults to <code>0.2</code>) — | |
| The fraction of initial steps during which skipping is disabled to ensure stability. For example, if | |
| <code>num_inference_steps</code> is 28 and <code>retention_ratio</code> is 0.2, the first 6 steps will never be skipped.`,name:"retention_ratio"},{anchor:"diffusers.MagCacheConfig.num_inference_steps",description:`<strong>num_inference_steps</strong> (<code>int</code>, defaults to <code>28</code>) — | |
| The number of inference steps used in the pipeline. This is required to interpolate <code>mag_ratios</code> correctly.`,name:"num_inference_steps"},{anchor:"diffusers.MagCacheConfig.mag_ratios",description:`<strong>mag_ratios</strong> (<code>torch.Tensor</code>, <em>optional</em>) — | |
| The pre-computed magnitude ratios for the model. These are checkpoint-dependent. If not provided, you must | |
| set <code>calibrate=True</code> to calculate them for your specific model. For Flux models, you can use | |
| <code>diffusers.hooks.mag_cache.FLUX_MAG_RATIOS</code>.`,name:"mag_ratios"},{anchor:"diffusers.MagCacheConfig.calibrate",description:`<strong>calibrate</strong> (<code>bool</code>, defaults to <code>False</code>) — | |
| If True, enables calibration mode. In this mode, no blocks are skipped. Instead, the hook calculates the | |
| magnitude ratios for the current run and logs them at the end. Use this to obtain <code>mag_ratios</code> for new | |
| models or schedulers.`,name:"calibrate"}]}),c(2),o(j);var J=e(j,2),ie=n(J);s(ie,{name:"diffusers.apply_mag_cache",anchor:"diffusers.apply_mag_cache",source:"https://github.com/huggingface/diffusers/blob/vr_14246/src/diffusers/hooks/mag_cache.py#L397",parameters:[{name:"module",val:": Module"},{name:"config",val:": MagCacheConfig"}],parametersDescription:[{anchor:"diffusers.apply_mag_cache.module",description:`<strong>module</strong> (<code>torch.nn.Module</code>) — | |
| The module to apply MagCache to.`,name:"module"},{anchor:"diffusers.apply_mag_cache.config",description:`<strong>config</strong> (<code>MagCacheConfig</code>) — | |
| The configuration for MagCache.`,name:"config"}]}),c(2),o(J);var re=e(J,2);pe(re,{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/en/api/cache.md"}),c(2),l(H,U),ge()}export{Me as component}; | |
Xet Storage Details
- Size:
- 51.7 kB
- Xet hash:
- 9f05d38ad6113a6d2da23e1f4b9ce5e7b49ebae3add83496450fe3372eca7e97
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.