Buckets:
| import{s as Ve,o as De,n as Fe}from"../chunks/scheduler.8c3d61f6.js";import{S as He,i as Se,g as d,s as i,r as u,A as ze,h,f as n,c as o,j as N,u as g,x as $,k as X,y as c,a as r,v as _,d as b,t as y,w as k}from"../chunks/index.da70eac4.js";import{D as ie}from"../chunks/Docstring.9419aa1d.js";import{C as We}from"../chunks/CodeBlock.a9c4becf.js";import{E as Ze}from"../chunks/ExampleCodeBlock.1b2603c3.js";import{H as ye,E as Le}from"../chunks/getInferenceSnippets.39110341.js";function Ke(q){let s,C="Example:",f,l,p;return l=new We({props:{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)`,wrap:!1}}),{c(){s=d("p"),s.textContent=C,f=i(),u(l.$$.fragment)},l(t){s=h(t,"P",{"data-svelte-h":!0}),$(s)!=="svelte-11lpom8"&&(s.textContent=C),f=o(t),g(l.$$.fragment,t)},m(t,m){r(t,s,m),r(t,f,m),_(l,t,m),p=!0},p:Fe,i(t){p||(b(l.$$.fragment,t),p=!0)},o(t){y(l.$$.fragment,t),p=!1},d(t){t&&(n(s),n(f)),k(l,t)}}}function Oe(q){let s,C="Example:",f,l,p;return l=new We({props:{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)`,wrap:!1}}),{c(){s=d("p"),s.textContent=C,f=i(),u(l.$$.fragment)},l(t){s=h(t,"P",{"data-svelte-h":!0}),$(s)!=="svelte-11lpom8"&&(s.textContent=C),f=o(t),g(l.$$.fragment,t)},m(t,m){r(t,s,m),r(t,f,m),_(l,t,m),p=!0},p:Fe,i(t){p||(b(l.$$.fragment,t),p=!0)},o(t){y(l.$$.fragment,t),p=!1},d(t){t&&(n(s),n(f)),k(l,t)}}}function et(q){let s,C="Example:",f,l,p;return l=new We({props:{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)`,wrap:!1}}),{c(){s=d("p"),s.textContent=C,f=i(),u(l.$$.fragment)},l(t){s=h(t,"P",{"data-svelte-h":!0}),$(s)!=="svelte-11lpom8"&&(s.textContent=C),f=o(t),g(l.$$.fragment,t)},m(t,m){r(t,s,m),r(t,f,m),_(l,t,m),p=!0},p:Fe,i(t){p||(b(l.$$.fragment,t),p=!0)},o(t){y(l.$$.fragment,t),p=!1},d(t){t&&(n(s),n(f)),k(l,t)}}}function tt(q){let s,C,f,l,p,t,m,Ne="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.",le,G,re,w,I,ke,S,Xe="A class for enable/disabling caching techniques on diffusion models.",we,z,Ge="Supported caching techniques:",Ce,L,Ie='<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>',Te,j,R,Me,K,Re="Enable caching techniques on the model.",$e,U,ce,A,pe,x,Q,ve,O,Ae="Configuration for Pyramid Attention Broadcast.",de,T,Y,je,ee,Qe='Apply <a href="https://huggingface.co/papers/2408.12588" rel="nofollow">Pyramid Attention Broadcast</a> to a given pipeline.',xe,te,Ye=`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.`,Je,Z,he,P,fe,J,E,Be,ne,Pe='Configuration for <a href="https://huggingface.co/papers/2410.19355" rel="nofollow">FasterCache</a>.',me,v,V,qe,ae,Ee='Applies <a href="https://huggingface.co/papers/2410.19355" rel="nofollow">FasterCache</a> to a given pipeline.',Ue,F,ue,D,ge,oe,_e;return p=new ye({props:{title:"Caching methods",local:"caching-methods",headingTag:"h1"}}),G=new ye({props:{title:"CacheMixin",local:"diffusers.CacheMixin",headingTag:"h2"}}),I=new ie({props:{name:"class diffusers.CacheMixin",anchor:"diffusers.CacheMixin",parameters:[],source:"https://github.com/huggingface/diffusers/blob/vr_11340/src/diffusers/models/cache_utils.py#L21"}}),R=new ie({props:{name:"enable_cache",anchor:"diffusers.CacheMixin.enable_cache",parameters:[{name:"config",val:""}],parametersDescription:[{anchor:"diffusers.CacheMixin.enable_cache.config",description:`<strong>config</strong> (<code>Union[PyramidAttentionBroadcastConfig]</code>) — | |
| The configuration for applying the caching technique. Currently supported caching techniques are:<ul> | |
| <li><a href="/docs/diffusers/pr_11340/en/api/cache#diffusers.PyramidAttentionBroadcastConfig">PyramidAttentionBroadcastConfig</a></li> | |
| </ul>`,name:"config"}],source:"https://github.com/huggingface/diffusers/blob/vr_11340/src/diffusers/models/cache_utils.py#L36"}}),U=new Ze({props:{anchor:"diffusers.CacheMixin.enable_cache.example",$$slots:{default:[Ke]},$$scope:{ctx:q}}}),A=new ye({props:{title:"PyramidAttentionBroadcastConfig",local:"diffusers.PyramidAttentionBroadcastConfig",headingTag:"h2"}}),Q=new ie({props:{name:"class diffusers.PyramidAttentionBroadcastConfig",anchor:"diffusers.PyramidAttentionBroadcastConfig",parameters:[{name:"spatial_attention_block_skip_range",val:": typing.Optional[int] = None"},{name:"temporal_attention_block_skip_range",val:": typing.Optional[int] = None"},{name:"cross_attention_block_skip_range",val:": typing.Optional[int] = None"},{name:"spatial_attention_timestep_skip_range",val:": typing.Tuple[int, int] = (100, 800)"},{name:"temporal_attention_timestep_skip_range",val:": typing.Tuple[int, int] = (100, 800)"},{name:"cross_attention_timestep_skip_range",val:": typing.Tuple[int, int] = (100, 800)"},{name:"spatial_attention_block_identifiers",val:": typing.Tuple[str, ...] = ('blocks', 'transformer_blocks', 'single_transformer_blocks')"},{name:"temporal_attention_block_identifiers",val:": typing.Tuple[str, ...] = ('temporal_transformer_blocks',)"},{name:"cross_attention_block_identifiers",val:": typing.Tuple[str, ...] = ('blocks', 'transformer_blocks')"},{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 re-used) 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 re-used) 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 re-used) 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>, defaults to <code>("blocks", "transformer_blocks")</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>, defaults to <code>("temporal_transformer_blocks",)</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>, defaults to <code>("blocks", "transformer_blocks")</code>) — | |
| The identifiers to match against the layer names to determine if the layer is a cross-attention layer.`,name:"cross_attention_block_identifiers"}],source:"https://github.com/huggingface/diffusers/blob/vr_11340/src/diffusers/hooks/pyramid_attention_broadcast.py#L36"}}),Y=new ie({props:{name:"diffusers.apply_pyramid_attention_broadcast",anchor:"diffusers.apply_pyramid_attention_broadcast",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>Optional[PyramidAttentionBroadcastConfig]</code>, <code>optional</code>, defaults to <code>None</code>) — | |
| The configuration to use for Pyramid Attention Broadcast.`,name:"config"}],source:"https://github.com/huggingface/diffusers/blob/vr_11340/src/diffusers/hooks/pyramid_attention_broadcast.py#L178"}}),Z=new Ze({props:{anchor:"diffusers.apply_pyramid_attention_broadcast.example",$$slots:{default:[Oe]},$$scope:{ctx:q}}}),P=new ye({props:{title:"FasterCacheConfig",local:"diffusers.FasterCacheConfig",headingTag:"h2"}}),E=new ie({props:{name:"class diffusers.FasterCacheConfig",anchor:"diffusers.FasterCacheConfig",parameters:[{name:"spatial_attention_block_skip_range",val:": int = 2"},{name:"temporal_attention_block_skip_range",val:": typing.Optional[int] = None"},{name:"spatial_attention_timestep_skip_range",val:": typing.Tuple[int, int] = (-1, 681)"},{name:"temporal_attention_timestep_skip_range",val:": typing.Tuple[int, int] = (-1, 681)"},{name:"low_frequency_weight_update_timestep_range",val:": typing.Tuple[int, int] = (99, 901)"},{name:"high_frequency_weight_update_timestep_range",val:": typing.Tuple[int, int] = (-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:": typing.Tuple[int, int] = (-1, 641)"},{name:"spatial_attention_block_identifiers",val:": typing.Tuple[str, ...] = ('^blocks.*attn', '^transformer_blocks.*attn', '^single_transformer_blocks.*attn')"},{name:"temporal_attention_block_identifiers",val:": typing.Tuple[str, ...] = ('^temporal_transformer_blocks.*attn',)"},{name:"attention_weight_callback",val:": typing.Callable[[torch.nn.modules.module.Module], float] = None"},{name:"low_frequency_weight_callback",val:": typing.Callable[[torch.nn.modules.module.Module], float] = None"},{name:"high_frequency_weight_callback",val:": typing.Callable[[torch.nn.modules.module.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:": typing.List[str] = ('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 re-used) 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 re-used) 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 re-used) 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"}],source:"https://github.com/huggingface/diffusers/blob/vr_11340/src/diffusers/hooks/faster_cache.py#L49"}}),V=new ie({props:{name:"diffusers.apply_faster_cache",anchor:"diffusers.apply_faster_cache",parameters:[{name:"module",val:": Module"},{name:"config",val:": FasterCacheConfig"}],parametersDescription:[{anchor:"diffusers.apply_faster_cache.pipeline",description:`<strong>pipeline</strong> (<code>DiffusionPipeline</code>) — | |
| The diffusion pipeline to apply FasterCache to.`,name:"pipeline"},{anchor:"diffusers.apply_faster_cache.config",description:`<strong>config</strong> (<code>Optional[FasterCacheConfig]</code>, <code>optional</code>, defaults to <code>None</code>) — | |
| The configuration to use for FasterCache.`,name:"config"}],source:"https://github.com/huggingface/diffusers/blob/vr_11340/src/diffusers/hooks/faster_cache.py#L486"}}),F=new Ze({props:{anchor:"diffusers.apply_faster_cache.example",$$slots:{default:[et]},$$scope:{ctx:q}}}),D=new Le({props:{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/en/api/cache.md"}}),{c(){s=d("meta"),C=i(),f=d("p"),l=i(),u(p.$$.fragment),t=i(),m=d("p"),m.textContent=Ne,le=i(),u(G.$$.fragment),re=i(),w=d("div"),u(I.$$.fragment),ke=i(),S=d("p"),S.textContent=Xe,we=i(),z=d("p"),z.textContent=Ge,Ce=i(),L=d("ul"),L.innerHTML=Ie,Te=i(),j=d("div"),u(R.$$.fragment),Me=i(),K=d("p"),K.textContent=Re,$e=i(),u(U.$$.fragment),ce=i(),u(A.$$.fragment),pe=i(),x=d("div"),u(Q.$$.fragment),ve=i(),O=d("p"),O.textContent=Ae,de=i(),T=d("div"),u(Y.$$.fragment),je=i(),ee=d("p"),ee.innerHTML=Qe,xe=i(),te=d("p"),te.textContent=Ye,Je=i(),u(Z.$$.fragment),he=i(),u(P.$$.fragment),fe=i(),J=d("div"),u(E.$$.fragment),Be=i(),ne=d("p"),ne.innerHTML=Pe,me=i(),v=d("div"),u(V.$$.fragment),qe=i(),ae=d("p"),ae.innerHTML=Ee,Ue=i(),u(F.$$.fragment),ue=i(),u(D.$$.fragment),ge=i(),oe=d("p"),this.h()},l(e){const a=ze("svelte-u9bgzb",document.head);s=h(a,"META",{name:!0,content:!0}),a.forEach(n),C=o(e),f=h(e,"P",{}),N(f).forEach(n),l=o(e),g(p.$$.fragment,e),t=o(e),m=h(e,"P",{"data-svelte-h":!0}),$(m)!=="svelte-1oer4hj"&&(m.textContent=Ne),le=o(e),g(G.$$.fragment,e),re=o(e),w=h(e,"DIV",{class:!0});var M=N(w);g(I.$$.fragment,M),ke=o(M),S=h(M,"P",{"data-svelte-h":!0}),$(S)!=="svelte-1jkm0k7"&&(S.textContent=Xe),we=o(M),z=h(M,"P",{"data-svelte-h":!0}),$(z)!=="svelte-x25y7s"&&(z.textContent=Ge),Ce=o(M),L=h(M,"UL",{"data-svelte-h":!0}),$(L)!=="svelte-n3yfbs"&&(L.innerHTML=Ie),Te=o(M),j=h(M,"DIV",{class:!0});var B=N(j);g(R.$$.fragment,B),Me=o(B),K=h(B,"P",{"data-svelte-h":!0}),$(K)!=="svelte-1jqtd9a"&&(K.textContent=Re),$e=o(B),g(U.$$.fragment,B),B.forEach(n),M.forEach(n),ce=o(e),g(A.$$.fragment,e),pe=o(e),x=h(e,"DIV",{class:!0});var H=N(x);g(Q.$$.fragment,H),ve=o(H),O=h(H,"P",{"data-svelte-h":!0}),$(O)!=="svelte-g9nrp2"&&(O.textContent=Ae),H.forEach(n),de=o(e),T=h(e,"DIV",{class:!0});var W=N(T);g(Y.$$.fragment,W),je=o(W),ee=h(W,"P",{"data-svelte-h":!0}),$(ee)!=="svelte-1k6n7qf"&&(ee.innerHTML=Qe),xe=o(W),te=h(W,"P",{"data-svelte-h":!0}),$(te)!=="svelte-1n2zwuf"&&(te.textContent=Ye),Je=o(W),g(Z.$$.fragment,W),W.forEach(n),he=o(e),g(P.$$.fragment,e),fe=o(e),J=h(e,"DIV",{class:!0});var be=N(J);g(E.$$.fragment,be),Be=o(be),ne=h(be,"P",{"data-svelte-h":!0}),$(ne)!=="svelte-38u0u9"&&(ne.innerHTML=Pe),be.forEach(n),me=o(e),v=h(e,"DIV",{class:!0});var se=N(v);g(V.$$.fragment,se),qe=o(se),ae=h(se,"P",{"data-svelte-h":!0}),$(ae)!=="svelte-1v5ielx"&&(ae.innerHTML=Ee),Ue=o(se),g(F.$$.fragment,se),se.forEach(n),ue=o(e),g(D.$$.fragment,e),ge=o(e),oe=h(e,"P",{}),N(oe).forEach(n),this.h()},h(){X(s,"name","hf:doc:metadata"),X(s,"content",nt),X(j,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),X(w,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),X(x,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),X(T,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),X(J,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),X(v,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8")},m(e,a){c(document.head,s),r(e,C,a),r(e,f,a),r(e,l,a),_(p,e,a),r(e,t,a),r(e,m,a),r(e,le,a),_(G,e,a),r(e,re,a),r(e,w,a),_(I,w,null),c(w,ke),c(w,S),c(w,we),c(w,z),c(w,Ce),c(w,L),c(w,Te),c(w,j),_(R,j,null),c(j,Me),c(j,K),c(j,$e),_(U,j,null),r(e,ce,a),_(A,e,a),r(e,pe,a),r(e,x,a),_(Q,x,null),c(x,ve),c(x,O),r(e,de,a),r(e,T,a),_(Y,T,null),c(T,je),c(T,ee),c(T,xe),c(T,te),c(T,Je),_(Z,T,null),r(e,he,a),_(P,e,a),r(e,fe,a),r(e,J,a),_(E,J,null),c(J,Be),c(J,ne),r(e,me,a),r(e,v,a),_(V,v,null),c(v,qe),c(v,ae),c(v,Ue),_(F,v,null),r(e,ue,a),_(D,e,a),r(e,ge,a),r(e,oe,a),_e=!0},p(e,[a]){const M={};a&2&&(M.$$scope={dirty:a,ctx:e}),U.$set(M);const B={};a&2&&(B.$$scope={dirty:a,ctx:e}),Z.$set(B);const H={};a&2&&(H.$$scope={dirty:a,ctx:e}),F.$set(H)},i(e){_e||(b(p.$$.fragment,e),b(G.$$.fragment,e),b(I.$$.fragment,e),b(R.$$.fragment,e),b(U.$$.fragment,e),b(A.$$.fragment,e),b(Q.$$.fragment,e),b(Y.$$.fragment,e),b(Z.$$.fragment,e),b(P.$$.fragment,e),b(E.$$.fragment,e),b(V.$$.fragment,e),b(F.$$.fragment,e),b(D.$$.fragment,e),_e=!0)},o(e){y(p.$$.fragment,e),y(G.$$.fragment,e),y(I.$$.fragment,e),y(R.$$.fragment,e),y(U.$$.fragment,e),y(A.$$.fragment,e),y(Q.$$.fragment,e),y(Y.$$.fragment,e),y(Z.$$.fragment,e),y(P.$$.fragment,e),y(E.$$.fragment,e),y(V.$$.fragment,e),y(F.$$.fragment,e),y(D.$$.fragment,e),_e=!1},d(e){e&&(n(C),n(f),n(l),n(t),n(m),n(le),n(re),n(w),n(ce),n(pe),n(x),n(de),n(T),n(he),n(fe),n(J),n(me),n(v),n(ue),n(ge),n(oe)),n(s),k(p,e),k(G,e),k(I),k(R),k(U),k(A,e),k(Q),k(Y),k(Z),k(P,e),k(E),k(V),k(F),k(D,e)}}}const nt='{"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}],"depth":1}';function at(q){return De(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class pt extends He{constructor(s){super(),Se(this,s,at,tt,Ve,{})}}export{pt as component}; | |
Xet Storage Details
- Size:
- 36.7 kB
- Xet hash:
- 27033243fa2c0c60f96332b081cc8b00d49dc5ee95c1467b154afbd81f5e1c0e
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.