import{s as zt,o as Kt,n as Xe}from"../chunks/scheduler.53228c21.js";import{S as Ot,i as ea,e as p,s as i,c as u,h as ta,a as d,d as a,b as r,f as U,g,j as k,k as Z,l,m as c,n as _,t as b,o as y,p as w}from"../chunks/index.100fac89.js";import{C as aa}from"../chunks/CopyLLMTxtMenu.20a72e0e.js";import{D as G}from"../chunks/Docstring.49101787.js";import{C as qe}from"../chunks/CodeBlock.d30a6509.js";import{E as Ne}from"../chunks/ExampleCodeBlock.4a9effb9.js";import{H as We,E as na}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.4d82655d.js";function sa(v){let n,C="Example:",f,o,h;return o=new qe({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwQ29nVmlkZW9YUGlwZWxpbmUlMkMlMjBQeXJhbWlkQXR0ZW50aW9uQnJvYWRjYXN0Q29uZmlnJTBBJTBBcGlwZSUyMCUzRCUyMENvZ1ZpZGVvWFBpcGVsaW5lLmZyb21fcHJldHJhaW5lZCglMjJUSFVETSUyRkNvZ1ZpZGVvWC01YiUyMiUyQyUyMHRvcmNoX2R0eXBlJTNEdG9yY2guYmZsb2F0MTYpJTBBcGlwZS50byglMjJjdWRhJTIyKSUwQSUwQWNvbmZpZyUyMCUzRCUyMFB5cmFtaWRBdHRlbnRpb25Ccm9hZGNhc3RDb25maWcoJTBBJTIwJTIwJTIwJTIwc3BhdGlhbF9hdHRlbnRpb25fYmxvY2tfc2tpcF9yYW5nZSUzRDIlMkMlMEElMjAlMjAlMjAlMjBzcGF0aWFsX2F0dGVudGlvbl90aW1lc3RlcF9za2lwX3JhbmdlJTNEKDEwMCUyQyUyMDgwMCklMkMlMEElMjAlMjAlMjAlMjBjdXJyZW50X3RpbWVzdGVwX2NhbGxiYWNrJTNEbGFtYmRhJTNBJTIwcGlwZS5jdXJyZW50X3RpbWVzdGVwJTJDJTBBKSUwQXBpcGUudHJhbnNmb3JtZXIuZW5hYmxlX2NhY2hlKGNvbmZpZyk=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> torch
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> CogVideoXPipeline, PyramidAttentionBroadcastConfig

<span class="hljs-meta">&gt;&gt;&gt; </span>pipe = CogVideoXPipeline.from_pretrained(<span class="hljs-string">&quot;THUDM/CogVideoX-5b&quot;</span>, torch_dtype=torch.bfloat16)
<span class="hljs-meta">&gt;&gt;&gt; </span>pipe.to(<span class="hljs-string">&quot;cuda&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </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">&gt;&gt;&gt; </span>pipe.transformer.enable_cache(config)`,wrap:!1}}),{c(){n=p("p"),n.textContent=C,f=i(),u(o.$$.fragment)},l(t){n=d(t,"P",{"data-svelte-h":!0}),k(n)!=="svelte-11lpom8"&&(n.textContent=C),f=r(t),g(o.$$.fragment,t)},m(t,m){c(t,n,m),c(t,f,m),_(o,t,m),h=!0},p:Xe,i(t){h||(b(o.$$.fragment,t),h=!0)},o(t){y(o.$$.fragment,t),h=!1},d(t){t&&(a(n),a(f)),w(o,t)}}}function oa(v){let n,C="Example:",f,o,h;return o=new qe({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwQ29nVmlkZW9YUGlwZWxpbmUlMkMlMjBQeXJhbWlkQXR0ZW50aW9uQnJvYWRjYXN0Q29uZmlnJTJDJTIwYXBwbHlfcHlyYW1pZF9hdHRlbnRpb25fYnJvYWRjYXN0JTBBZnJvbSUyMGRpZmZ1c2Vycy51dGlscyUyMGltcG9ydCUyMGV4cG9ydF90b192aWRlbyUwQSUwQXBpcGUlMjAlM0QlMjBDb2dWaWRlb1hQaXBlbGluZS5mcm9tX3ByZXRyYWluZWQoJTIyVEhVRE0lMkZDb2dWaWRlb1gtNWIlMjIlMkMlMjB0b3JjaF9kdHlwZSUzRHRvcmNoLmJmbG9hdDE2KSUwQXBpcGUudG8oJTIyY3VkYSUyMiklMEElMEFjb25maWclMjAlM0QlMjBQeXJhbWlkQXR0ZW50aW9uQnJvYWRjYXN0Q29uZmlnKCUwQSUyMCUyMCUyMCUyMHNwYXRpYWxfYXR0ZW50aW9uX2Jsb2NrX3NraXBfcmFuZ2UlM0QyJTJDJTBBJTIwJTIwJTIwJTIwc3BhdGlhbF9hdHRlbnRpb25fdGltZXN0ZXBfc2tpcF9yYW5nZSUzRCgxMDAlMkMlMjA4MDApJTJDJTBBJTIwJTIwJTIwJTIwY3VycmVudF90aW1lc3RlcF9jYWxsYmFjayUzRGxhbWJkYSUzQSUyMHBpcGUuY3VycmVudF90aW1lc3RlcCUyQyUwQSklMEFhcHBseV9weXJhbWlkX2F0dGVudGlvbl9icm9hZGNhc3QocGlwZS50cmFuc2Zvcm1lciUyQyUyMGNvbmZpZyk=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> torch
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> CogVideoXPipeline, PyramidAttentionBroadcastConfig, apply_pyramid_attention_broadcast
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> diffusers.utils <span class="hljs-keyword">import</span> export_to_video

<span class="hljs-meta">&gt;&gt;&gt; </span>pipe = CogVideoXPipeline.from_pretrained(<span class="hljs-string">&quot;THUDM/CogVideoX-5b&quot;</span>, torch_dtype=torch.bfloat16)
<span class="hljs-meta">&gt;&gt;&gt; </span>pipe.to(<span class="hljs-string">&quot;cuda&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </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">&gt;&gt;&gt; </span>apply_pyramid_attention_broadcast(pipe.transformer, config)`,wrap:!1}}),{c(){n=p("p"),n.textContent=C,f=i(),u(o.$$.fragment)},l(t){n=d(t,"P",{"data-svelte-h":!0}),k(n)!=="svelte-11lpom8"&&(n.textContent=C),f=r(t),g(o.$$.fragment,t)},m(t,m){c(t,n,m),c(t,f,m),_(o,t,m),h=!0},p:Xe,i(t){h||(b(o.$$.fragment,t),h=!0)},o(t){y(o.$$.fragment,t),h=!1},d(t){t&&(a(n),a(f)),w(o,t)}}}function ia(v){let n,C="Example:",f,o,h;return o=new qe({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwQ29nVmlkZW9YUGlwZWxpbmUlMkMlMjBGYXN0ZXJDYWNoZUNvbmZpZyUyQyUyMGFwcGx5X2Zhc3Rlcl9jYWNoZSUwQSUwQXBpcGUlMjAlM0QlMjBDb2dWaWRlb1hQaXBlbGluZS5mcm9tX3ByZXRyYWluZWQoJTIyVEhVRE0lMkZDb2dWaWRlb1gtNWIlMjIlMkMlMjB0b3JjaF9kdHlwZSUzRHRvcmNoLmJmbG9hdDE2KSUwQXBpcGUudG8oJTIyY3VkYSUyMiklMEElMEFjb25maWclMjAlM0QlMjBGYXN0ZXJDYWNoZUNvbmZpZyglMEElMjAlMjAlMjAlMjBzcGF0aWFsX2F0dGVudGlvbl9ibG9ja19za2lwX3JhbmdlJTNEMiUyQyUwQSUyMCUyMCUyMCUyMHNwYXRpYWxfYXR0ZW50aW9uX3RpbWVzdGVwX3NraXBfcmFuZ2UlM0QoLTElMkMlMjA2ODEpJTJDJTBBJTIwJTIwJTIwJTIwbG93X2ZyZXF1ZW5jeV93ZWlnaHRfdXBkYXRlX3RpbWVzdGVwX3JhbmdlJTNEKDk5JTJDJTIwNjQxKSUyQyUwQSUyMCUyMCUyMCUyMGhpZ2hfZnJlcXVlbmN5X3dlaWdodF91cGRhdGVfdGltZXN0ZXBfcmFuZ2UlM0QoLTElMkMlMjAzMDEpJTJDJTBBJTIwJTIwJTIwJTIwc3BhdGlhbF9hdHRlbnRpb25fYmxvY2tfaWRlbnRpZmllcnMlM0QlNUIlMjJ0cmFuc2Zvcm1lcl9ibG9ja3MlMjIlNUQlMkMlMEElMjAlMjAlMjAlMjBhdHRlbnRpb25fd2VpZ2h0X2NhbGxiYWNrJTNEbGFtYmRhJTIwXyUzQSUyMDAuMyUyQyUwQSUyMCUyMCUyMCUyMHRlbnNvcl9mb3JtYXQlM0QlMjJCRkNIVyUyMiUyQyUwQSklMEFhcHBseV9mYXN0ZXJfY2FjaGUocGlwZS50cmFuc2Zvcm1lciUyQyUyMGNvbmZpZyk=",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> torch
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> CogVideoXPipeline, FasterCacheConfig, apply_faster_cache

<span class="hljs-meta">&gt;&gt;&gt; </span>pipe = CogVideoXPipeline.from_pretrained(<span class="hljs-string">&quot;THUDM/CogVideoX-5b&quot;</span>, torch_dtype=torch.bfloat16)
<span class="hljs-meta">&gt;&gt;&gt; </span>pipe.to(<span class="hljs-string">&quot;cuda&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </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">&quot;transformer_blocks&quot;</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">&quot;BFCHW&quot;</span>,
<span class="hljs-meta">... </span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>apply_faster_cache(pipe.transformer, config)`,wrap:!1}}),{c(){n=p("p"),n.textContent=C,f=i(),u(o.$$.fragment)},l(t){n=d(t,"P",{"data-svelte-h":!0}),k(n)!=="svelte-11lpom8"&&(n.textContent=C),f=r(t),g(o.$$.fragment,t)},m(t,m){c(t,n,m),c(t,f,m),_(o,t,m),h=!0},p:Xe,i(t){h||(b(o.$$.fragment,t),h=!0)},o(t){y(o.$$.fragment,t),h=!1},d(t){t&&(a(n),a(f)),w(o,t)}}}function ra(v){let n,C="Example:",f,o,h;return o=new qe({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwQ29nVmlldzRQaXBlbGluZSUwQWZyb20lMjBkaWZmdXNlcnMuaG9va3MlMjBpbXBvcnQlMjBhcHBseV9maXJzdF9ibG9ja19jYWNoZSUyQyUyMEZpcnN0QmxvY2tDYWNoZUNvbmZpZyUwQSUwQXBpcGUlMjAlM0QlMjBDb2dWaWV3NFBpcGVsaW5lLmZyb21fcHJldHJhaW5lZCglMjJUSFVETSUyRkNvZ1ZpZXc0LTZCJTIyJTJDJTIwdG9yY2hfZHR5cGUlM0R0b3JjaC5iZmxvYXQxNiklMEFwaXBlLnRvKCUyMmN1ZGElMjIpJTBBJTBBYXBwbHlfZmlyc3RfYmxvY2tfY2FjaGUocGlwZS50cmFuc2Zvcm1lciUyQyUyMEZpcnN0QmxvY2tDYWNoZUNvbmZpZyh0aHJlc2hvbGQlM0QwLjIpKSUwQSUwQXByb21wdCUyMCUzRCUyMCUyMkElMjBwaG90byUyMG9mJTIwYW4lMjBhc3Ryb25hdXQlMjByaWRpbmclMjBhJTIwaG9yc2UlMjBvbiUyMG1hcnMlMjIlMEFpbWFnZSUyMCUzRCUyMHBpcGUocHJvbXB0JTJDJTIwZ2VuZXJhdG9yJTNEdG9yY2guR2VuZXJhdG9yKCkubWFudWFsX3NlZWQoNDIpKS5pbWFnZXMlNUIwJTVEJTBBaW1hZ2Uuc2F2ZSglMjJvdXRwdXQucG5nJTIyKQ==",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> torch
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> CogView4Pipeline
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> diffusers.hooks <span class="hljs-keyword">import</span> apply_first_block_cache, FirstBlockCacheConfig

<span class="hljs-meta">&gt;&gt;&gt; </span>pipe = CogView4Pipeline.from_pretrained(<span class="hljs-string">&quot;THUDM/CogView4-6B&quot;</span>, torch_dtype=torch.bfloat16)
<span class="hljs-meta">&gt;&gt;&gt; </span>pipe.to(<span class="hljs-string">&quot;cuda&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </span>apply_first_block_cache(pipe.transformer, FirstBlockCacheConfig(threshold=<span class="hljs-number">0.2</span>))

<span class="hljs-meta">&gt;&gt;&gt; </span>prompt = <span class="hljs-string">&quot;A photo of an astronaut riding a horse on mars&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </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">&gt;&gt;&gt; </span>image.save(<span class="hljs-string">&quot;output.png&quot;</span>)`,wrap:!1}}),{c(){n=p("p"),n.textContent=C,f=i(),u(o.$$.fragment)},l(t){n=d(t,"P",{"data-svelte-h":!0}),k(n)!=="svelte-11lpom8"&&(n.textContent=C),f=r(t),g(o.$$.fragment,t)},m(t,m){c(t,n,m),c(t,f,m),_(o,t,m),h=!0},p:Xe,i(t){h||(b(o.$$.fragment,t),h=!0)},o(t){y(o.$$.fragment,t),h=!1},d(t){t&&(a(n),a(f)),w(o,t)}}}function la(v){let n,C="Example of inactive and active usage:",f,o,h;return o=new qe({props:{code:"ZGVmJTIwZm9yd2FyZCh4KSUzQSUwQSUyMCUyMCUyMCUyMHglMjAlM0QlMjBzZWxmLm1vZHVsZTEoeCklMjAlMjAlMjMlMjBpbmFjdGl2ZSUyMG1vZHVsZSUzQSUyMHJldHVybnMlMjB6ZXJvcyUyMHRlbnNvciUyMGJhc2VkJTIwb24lMjBzaGFwZSUyMHJlY29yZGVkJTIwZHVyaW5nJTIwZnVsbCUyMGNvbXB1dGUlMEElMjAlMjAlMjAlMjB4JTIwJTNEJTIwc2VsZi5tb2R1bGUyKHgpJTIwJTIwJTIzJTIwYWN0aXZlJTIwbW9kdWxlJTNBJTIwY2FjaGVzJTIwb3V0cHV0JTIwaGVyZSUyQyUyMGF2b2lkaW5nJTIwcmVjb21wdXRhdGlvbiUyMG9mJTIwcHJpb3IlMjBzdGVwcyUwQSUyMCUyMCUyMCUyMHJldHVybiUyMHg=",highlighted:`<span class="hljs-keyword">def</span> <span class="hljs-title function_">forward</span>(<span class="hljs-params">x</span>):
    x = self.module1(x)  <span class="hljs-comment"># inactive module: returns zeros tensor based on shape recorded during full compute</span>
    x = self.module2(x)  <span class="hljs-comment"># active module: caches output here, avoiding recomputation of prior steps</span>
    <span class="hljs-keyword">return</span> x`,wrap:!1}}),{c(){n=p("p"),n.textContent=C,f=i(),u(o.$$.fragment)},l(t){n=d(t,"P",{"data-svelte-h":!0}),k(n)!=="svelte-ld79go"&&(n.textContent=C),f=r(t),g(o.$$.fragment,t)},m(t,m){c(t,n,m),c(t,f,m),_(o,t,m),h=!0},p:Xe,i(t){h||(b(o.$$.fragment,t),h=!0)},o(t){y(o.$$.fragment,t),h=!1},d(t){t&&(a(n),a(f)),w(o,t)}}}function ca(v){let n,C="Example:",f,o,h;return o=new qe({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwRmx1eFBpcGVsaW5lJTJDJTIwVGF5bG9yU2VlckNhY2hlQ29uZmlnJTBBJTBBcGlwZSUyMCUzRCUyMEZsdXhQaXBlbGluZS5mcm9tX3ByZXRyYWluZWQoJTBBJTIwJTIwJTIwJTIwJTIyYmxhY2stZm9yZXN0LWxhYnMlMkZGTFVYLjEtZGV2JTIyJTJDJTBBJTIwJTIwJTIwJTIwdG9yY2hfZHR5cGUlM0R0b3JjaC5iZmxvYXQxNiUyQyUwQSklMEFwaXBlLnRvKCUyMmN1ZGElMjIpJTBBJTBBY29uZmlnJTIwJTNEJTIwVGF5bG9yU2VlckNhY2hlQ29uZmlnKCUwQSUyMCUyMCUyMCUyMGNhY2hlX2ludGVydmFsJTNENSUyQyUwQSUyMCUyMCUyMCUyMG1heF9vcmRlciUzRDElMkMlMEElMjAlMjAlMjAlMjBkaXNhYmxlX2NhY2hlX2JlZm9yZV9zdGVwJTNEMyUyQyUwQSUyMCUyMCUyMCUyMHRheWxvcl9mYWN0b3JzX2R0eXBlJTNEdG9yY2guZmxvYXQzMiUyQyUwQSklMEFwaXBlLnRyYW5zZm9ybWVyLmVuYWJsZV9jYWNoZShjb25maWcp",highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> torch
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> FluxPipeline, TaylorSeerCacheConfig

<span class="hljs-meta">&gt;&gt;&gt; </span>pipe = FluxPipeline.from_pretrained(
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;black-forest-labs/FLUX.1-dev&quot;</span>,
<span class="hljs-meta">... </span>    torch_dtype=torch.bfloat16,
<span class="hljs-meta">... </span>)
<span class="hljs-meta">&gt;&gt;&gt; </span>pipe.to(<span class="hljs-string">&quot;cuda&quot;</span>)

<span class="hljs-meta">&gt;&gt;&gt; </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">&gt;&gt;&gt; </span>pipe.transformer.enable_cache(config)`,wrap:!1}}),{c(){n=p("p"),n.textContent=C,f=i(),u(o.$$.fragment)},l(t){n=d(t,"P",{"data-svelte-h":!0}),k(n)!=="svelte-11lpom8"&&(n.textContent=C),f=r(t),g(o.$$.fragment,t)},m(t,m){c(t,n,m),c(t,f,m),_(o,t,m),h=!0},p:Xe,i(t){h||(b(o.$$.fragment,t),h=!0)},o(t){y(o.$$.fragment,t),h=!1},d(t){t&&(a(n),a(f)),w(o,t)}}}function pa(v){let n,C,f,o,h,t,m,Qe,L,Bt="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.",Ee,z,Re,$,K,it,_e,Ft="A class for enable/disabling caching techniques on diffusion models.",rt,be,Gt="Supported caching techniques:",lt,ye,It='<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>',ct,Q,O,pt,we,Nt="Context manager that provides additional methods for cache management.",dt,I,ee,ht,ke,Wt="Enable caching techniques on the model.",ft,E,Ye,te,Se,W,ae,mt,Ce,Xt="Configuration for Pyramid Attention Broadcast.",Ae,j,ne,ut,$e,qt='Apply <a href="https://huggingface.co/papers/2408.12588" rel="nofollow">Pyramid Attention Broadcast</a> to a given pipeline.',gt,Te,Vt=`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.`,_t,R,He,se,Pe,X,oe,bt,Me,Qt='Configuration for <a href="https://huggingface.co/papers/2410.19355" rel="nofollow">FasterCache</a>.',De,B,ie,yt,ve,Et='Applies <a href="https://huggingface.co/papers/2410.19355" rel="nofollow">FasterCache</a> to a given pipeline.',wt,Y,Le,re,ze,q,le,kt,je,Rt=`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>.`,Ke,x,ce,Ct,xe,Yt=`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.`,$t,Je,St=`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.`,Tt,S,Oe,pe,et,T,de,Mt,Ue,At='Configuration for TaylorSeer cache. See: <a href="https://huggingface.co/papers/2503.06923" rel="nofollow">https://huggingface.co/papers/2503.06923</a>',vt,Ze,Ht="Notes:",jt,Be,Pt="<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>",xt,A,tt,J,he,Jt,Fe,Dt="Applies the TaylorSeer cache to a given pipeline (typically the transformer / UNet).",Ut,Ge,Lt=`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.`,Zt,H,at,fe,nt,Ve,st;return h=new aa({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),m=new We({props:{title:"Caching methods",local:"caching-methods",headingTag:"h1"}}),z=new We({props:{title:"CacheMixin",local:"diffusers.CacheMixin",headingTag:"h2"}}),K=new G({props:{name:"class diffusers.CacheMixin",anchor:"diffusers.CacheMixin",parameters:[],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/cache_utils.py#L23"}}),O=new G({props:{name:"cache_context",anchor:"diffusers.CacheMixin.cache_context",parameters:[{name:"name",val:": str"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/cache_utils.py#L133"}}),ee=new G({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>) &#x2014;
The configuration for applying the caching technique. Currently supported caching techniques are:
<ul>
<li><a href="/docs/diffusers/main/en/api/cache#diffusers.PyramidAttentionBroadcastConfig">PyramidAttentionBroadcastConfig</a></li>
</ul>`,name:"config"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/cache_utils.py#L39"}}),E=new Ne({props:{anchor:"diffusers.CacheMixin.enable_cache.example",$$slots:{default:[sa]},$$scope:{ctx:v}}}),te=new We({props:{title:"PyramidAttentionBroadcastConfig",local:"diffusers.PyramidAttentionBroadcastConfig",headingTag:"h2"}}),ae=new G({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', 'layers')"},{name:"temporal_attention_block_identifiers",val:": typing.Tuple[str, ...] = ('temporal_transformer_blocks',)"},{name:"cross_attention_block_identifiers",val:": typing.Tuple[str, ...] = ('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>) &#x2014;
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>) &#x2014;
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>) &#x2014;
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>) &#x2014;
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>) &#x2014;
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>) &#x2014;
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>) &#x2014;
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>) &#x2014;
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>) &#x2014;
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/main/src/diffusers/hooks/pyramid_attention_broadcast.py#L40"}}),ne=new G({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>) &#x2014;
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>) &#x2014;
The configuration to use for Pyramid Attention Broadcast.`,name:"config"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/hooks/pyramid_attention_broadcast.py#L181"}}),R=new Ne({props:{anchor:"diffusers.apply_pyramid_attention_broadcast.example",$$slots:{default:[oa]},$$scope:{ctx:v}}}),se=new We({props:{title:"FasterCacheConfig",local:"diffusers.FasterCacheConfig",headingTag:"h2"}}),oe=new G({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>) &#x2014;
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>) &#x2014;
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>) &#x2014;
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>) &#x2014;
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>) &#x2014;
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>) &#x2014;
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>) &#x2014;
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>) &#x2014;
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>) &#x2014;
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>) &#x2014;
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>(&quot;blocks.*attn1&quot;, &quot;transformer_blocks.*attn1&quot;, &quot;single_transformer_blocks.*attn1&quot;)</code>) &#x2014;
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>(&quot;temporal_transformer_blocks.*attn1&quot;,)</code>) &#x2014;
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>) &#x2014;
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>) &#x2014;
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>) &#x2014;
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>&quot;BCFHW&quot;</code>) &#x2014;
The format of the input tensors. This should be one of <code>&quot;BCFHW&quot;</code>, <code>&quot;BFCHW&quot;</code>, or <code>&quot;BCHW&quot;</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>) &#x2014;
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>(&quot;hidden_states&quot;, &quot;encoder_hidden_states&quot;, &quot;timestep&quot;, &quot;attention_mask&quot;, &quot;encoder_attention_mask&quot;)</code>) &#x2014;
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/main/src/diffusers/hooks/faster_cache.py#L50"}}),ie=new G({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.module",description:`<strong>module</strong> (<code>torch.nn.Module</code>) &#x2014;
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>) &#x2014;
The configuration to use for FasterCache.`,name:"config"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/hooks/faster_cache.py#L486"}}),Y=new Ne({props:{anchor:"diffusers.apply_faster_cache.example",$$slots:{default:[ia]},$$scope:{ctx:v}}}),re=new We({props:{title:"FirstBlockCacheConfig",local:"diffusers.FirstBlockCacheConfig",headingTag:"h3"}}),le=new G({props:{name:"class diffusers.FirstBlockCacheConfig",anchor:"diffusers.FirstBlockCacheConfig",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>) &#x2014;
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"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/hooks/first_block_cache.py#L34"}}),ce=new G({props:{name:"diffusers.apply_first_block_cache",anchor:"diffusers.apply_first_block_cache",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>) &#x2014;
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>) &#x2014;
The configuration to use for applying the FBCache method.`,name:"config"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/hooks/first_block_cache.py#L194"}}),S=new Ne({props:{anchor:"diffusers.apply_first_block_cache.example",$$slots:{default:[ra]},$$scope:{ctx:v}}}),pe=new We({props:{title:"TaylorSeerCacheConfig",local:"diffusers.TaylorSeerCacheConfig",headingTag:"h3"}}),de=new G({props:{name:"class diffusers.TaylorSeerCacheConfig",anchor:"diffusers.TaylorSeerCacheConfig",parameters:[{name:"cache_interval",val:": int = 5"},{name:"disable_cache_before_step",val:": int = 3"},{name:"disable_cache_after_step",val:": typing.Optional[int] = None"},{name:"max_order",val:": int = 1"},{name:"taylor_factors_dtype",val:": typing.Optional[torch.dtype] = torch.bfloat16"},{name:"skip_predict_identifiers",val:": typing.Optional[typing.List[str]] = None"},{name:"cache_identifiers",val:": typing.Optional[typing.List[str]] = 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>) &#x2014;
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>) &#x2014;
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>) &#x2014;
The denoising step index after which caching is disabled. If set, for steps &gt;= 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>) &#x2014;
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>) &#x2014;
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>) &#x2014;
Regex patterns (using <code>re.fullmatch</code>) for module names to place as &#x201C;skip&#x201D; in &#x201C;cache&#x201D; 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>) &#x2014;
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>) &#x2014;
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"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/hooks/taylorseer_cache.py#L27"}}),A=new Ne({props:{anchor:"diffusers.TaylorSeerCacheConfig.example",$$slots:{default:[la]},$$scope:{ctx:v}}}),he=new G({props:{name:"diffusers.apply_taylorseer_cache",anchor:"diffusers.apply_taylorseer_cache",parameters:[{name:"module",val:": Module"},{name:"config",val:": TaylorSeerCacheConfig"}],parametersDescription:[{anchor:"diffusers.apply_taylorseer_cache.module",description:"<strong>module</strong> (torch.nn.Module) &#x2014; The model subtree to apply the hooks to.",name:"module"},{anchor:"diffusers.apply_taylorseer_cache.config",description:"<strong>config</strong> (TaylorSeerCacheConfig) &#x2014; Configuration for the cache.",name:"config"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/hooks/taylorseer_cache.py#L259"}}),H=new Ne({props:{anchor:"diffusers.apply_taylorseer_cache.example",$$slots:{default:[ca]},$$scope:{ctx:v}}}),fe=new na({props:{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/en/api/cache.md"}}),{c(){n=p("meta"),C=i(),f=p("p"),o=i(),u(h.$$.fragment),t=i(),u(m.$$.fragment),Qe=i(),L=p("p"),L.textContent=Bt,Ee=i(),u(z.$$.fragment),Re=i(),$=p("div"),u(K.$$.fragment),it=i(),_e=p("p"),_e.textContent=Ft,rt=i(),be=p("p"),be.textContent=Gt,lt=i(),ye=p("ul"),ye.innerHTML=It,ct=i(),Q=p("div"),u(O.$$.fragment),pt=i(),we=p("p"),we.textContent=Nt,dt=i(),I=p("div"),u(ee.$$.fragment),ht=i(),ke=p("p"),ke.textContent=Wt,ft=i(),u(E.$$.fragment),Ye=i(),u(te.$$.fragment),Se=i(),W=p("div"),u(ae.$$.fragment),mt=i(),Ce=p("p"),Ce.textContent=Xt,Ae=i(),j=p("div"),u(ne.$$.fragment),ut=i(),$e=p("p"),$e.innerHTML=qt,gt=i(),Te=p("p"),Te.textContent=Vt,_t=i(),u(R.$$.fragment),He=i(),u(se.$$.fragment),Pe=i(),X=p("div"),u(oe.$$.fragment),bt=i(),Me=p("p"),Me.innerHTML=Qt,De=i(),B=p("div"),u(ie.$$.fragment),yt=i(),ve=p("p"),ve.innerHTML=Et,wt=i(),u(Y.$$.fragment),Le=i(),u(re.$$.fragment),ze=i(),q=p("div"),u(le.$$.fragment),kt=i(),je=p("p"),je.innerHTML=Rt,Ke=i(),x=p("div"),u(ce.$$.fragment),Ct=i(),xe=p("p"),xe.innerHTML=Yt,$t=i(),Je=p("p"),Je.innerHTML=St,Tt=i(),u(S.$$.fragment),Oe=i(),u(pe.$$.fragment),et=i(),T=p("div"),u(de.$$.fragment),Mt=i(),Ue=p("p"),Ue.innerHTML=At,vt=i(),Ze=p("p"),Ze.textContent=Ht,jt=i(),Be=p("ul"),Be.innerHTML=Pt,xt=i(),u(A.$$.fragment),tt=i(),J=p("div"),u(he.$$.fragment),Jt=i(),Fe=p("p"),Fe.textContent=Dt,Ut=i(),Ge=p("p"),Ge.textContent=Lt,Zt=i(),u(H.$$.fragment),at=i(),u(fe.$$.fragment),nt=i(),Ve=p("p"),this.h()},l(e){const s=ta("svelte-u9bgzb",document.head);n=d(s,"META",{name:!0,content:!0}),s.forEach(a),C=r(e),f=d(e,"P",{}),U(f).forEach(a),o=r(e),g(h.$$.fragment,e),t=r(e),g(m.$$.fragment,e),Qe=r(e),L=d(e,"P",{"data-svelte-h":!0}),k(L)!=="svelte-1oer4hj"&&(L.textContent=Bt),Ee=r(e),g(z.$$.fragment,e),Re=r(e),$=d(e,"DIV",{class:!0});var M=U($);g(K.$$.fragment,M),it=r(M),_e=d(M,"P",{"data-svelte-h":!0}),k(_e)!=="svelte-1jkm0k7"&&(_e.textContent=Ft),rt=r(M),be=d(M,"P",{"data-svelte-h":!0}),k(be)!=="svelte-x25y7s"&&(be.textContent=Gt),lt=r(M),ye=d(M,"UL",{"data-svelte-h":!0}),k(ye)!=="svelte-ub5q43"&&(ye.innerHTML=It),ct=r(M),Q=d(M,"DIV",{class:!0});var me=U(Q);g(O.$$.fragment,me),pt=r(me),we=d(me,"P",{"data-svelte-h":!0}),k(we)!=="svelte-121bmd6"&&(we.textContent=Nt),me.forEach(a),dt=r(M),I=d(M,"DIV",{class:!0});var V=U(I);g(ee.$$.fragment,V),ht=r(V),ke=d(V,"P",{"data-svelte-h":!0}),k(ke)!=="svelte-1jqtd9a"&&(ke.textContent=Wt),ft=r(V),g(E.$$.fragment,V),V.forEach(a),M.forEach(a),Ye=r(e),g(te.$$.fragment,e),Se=r(e),W=d(e,"DIV",{class:!0});var ue=U(W);g(ae.$$.fragment,ue),mt=r(ue),Ce=d(ue,"P",{"data-svelte-h":!0}),k(Ce)!=="svelte-g9nrp2"&&(Ce.textContent=Xt),ue.forEach(a),Ae=r(e),j=d(e,"DIV",{class:!0});var F=U(j);g(ne.$$.fragment,F),ut=r(F),$e=d(F,"P",{"data-svelte-h":!0}),k($e)!=="svelte-1k6n7qf"&&($e.innerHTML=qt),gt=r(F),Te=d(F,"P",{"data-svelte-h":!0}),k(Te)!=="svelte-1n2zwuf"&&(Te.textContent=Vt),_t=r(F),g(R.$$.fragment,F),F.forEach(a),He=r(e),g(se.$$.fragment,e),Pe=r(e),X=d(e,"DIV",{class:!0});var ge=U(X);g(oe.$$.fragment,ge),bt=r(ge),Me=d(ge,"P",{"data-svelte-h":!0}),k(Me)!=="svelte-38u0u9"&&(Me.innerHTML=Qt),ge.forEach(a),De=r(e),B=d(e,"DIV",{class:!0});var Ie=U(B);g(ie.$$.fragment,Ie),yt=r(Ie),ve=d(Ie,"P",{"data-svelte-h":!0}),k(ve)!=="svelte-1v5ielx"&&(ve.innerHTML=Et),wt=r(Ie),g(Y.$$.fragment,Ie),Ie.forEach(a),Le=r(e),g(re.$$.fragment,e),ze=r(e),q=d(e,"DIV",{class:!0});var ot=U(q);g(le.$$.fragment,ot),kt=r(ot),je=d(ot,"P",{"data-svelte-h":!0}),k(je)!=="svelte-360v39"&&(je.innerHTML=Rt),ot.forEach(a),Ke=r(e),x=d(e,"DIV",{class:!0});var P=U(x);g(ce.$$.fragment,P),Ct=r(P),xe=d(P,"P",{"data-svelte-h":!0}),k(xe)!=="svelte-1p02a6y"&&(xe.innerHTML=Yt),$t=r(P),Je=d(P,"P",{"data-svelte-h":!0}),k(Je)!=="svelte-1xnxpcr"&&(Je.innerHTML=St),Tt=r(P),g(S.$$.fragment,P),P.forEach(a),Oe=r(e),g(pe.$$.fragment,e),et=r(e),T=d(e,"DIV",{class:!0});var N=U(T);g(de.$$.fragment,N),Mt=r(N),Ue=d(N,"P",{"data-svelte-h":!0}),k(Ue)!=="svelte-jvr5il"&&(Ue.innerHTML=At),vt=r(N),Ze=d(N,"P",{"data-svelte-h":!0}),k(Ze)!=="svelte-1biq3pv"&&(Ze.textContent=Ht),jt=r(N),Be=d(N,"UL",{"data-svelte-h":!0}),k(Be)!=="svelte-fshky8"&&(Be.innerHTML=Pt),xt=r(N),g(A.$$.fragment,N),N.forEach(a),tt=r(e),J=d(e,"DIV",{class:!0});var D=U(J);g(he.$$.fragment,D),Jt=r(D),Fe=d(D,"P",{"data-svelte-h":!0}),k(Fe)!=="svelte-1mz0d6l"&&(Fe.textContent=Dt),Ut=r(D),Ge=d(D,"P",{"data-svelte-h":!0}),k(Ge)!=="svelte-wvy9tn"&&(Ge.textContent=Lt),Zt=r(D),g(H.$$.fragment,D),D.forEach(a),at=r(e),g(fe.$$.fragment,e),nt=r(e),Ve=d(e,"P",{}),U(Ve).forEach(a),this.h()},h(){Z(n,"name","hf:doc:metadata"),Z(n,"content",da),Z(Q,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),Z(I,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),Z($,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),Z(W,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),Z(j,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),Z(X,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),Z(B,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),Z(q,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),Z(x,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),Z(T,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),Z(J,"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,s){l(document.head,n),c(e,C,s),c(e,f,s),c(e,o,s),_(h,e,s),c(e,t,s),_(m,e,s),c(e,Qe,s),c(e,L,s),c(e,Ee,s),_(z,e,s),c(e,Re,s),c(e,$,s),_(K,$,null),l($,it),l($,_e),l($,rt),l($,be),l($,lt),l($,ye),l($,ct),l($,Q),_(O,Q,null),l(Q,pt),l(Q,we),l($,dt),l($,I),_(ee,I,null),l(I,ht),l(I,ke),l(I,ft),_(E,I,null),c(e,Ye,s),_(te,e,s),c(e,Se,s),c(e,W,s),_(ae,W,null),l(W,mt),l(W,Ce),c(e,Ae,s),c(e,j,s),_(ne,j,null),l(j,ut),l(j,$e),l(j,gt),l(j,Te),l(j,_t),_(R,j,null),c(e,He,s),_(se,e,s),c(e,Pe,s),c(e,X,s),_(oe,X,null),l(X,bt),l(X,Me),c(e,De,s),c(e,B,s),_(ie,B,null),l(B,yt),l(B,ve),l(B,wt),_(Y,B,null),c(e,Le,s),_(re,e,s),c(e,ze,s),c(e,q,s),_(le,q,null),l(q,kt),l(q,je),c(e,Ke,s),c(e,x,s),_(ce,x,null),l(x,Ct),l(x,xe),l(x,$t),l(x,Je),l(x,Tt),_(S,x,null),c(e,Oe,s),_(pe,e,s),c(e,et,s),c(e,T,s),_(de,T,null),l(T,Mt),l(T,Ue),l(T,vt),l(T,Ze),l(T,jt),l(T,Be),l(T,xt),_(A,T,null),c(e,tt,s),c(e,J,s),_(he,J,null),l(J,Jt),l(J,Fe),l(J,Ut),l(J,Ge),l(J,Zt),_(H,J,null),c(e,at,s),_(fe,e,s),c(e,nt,s),c(e,Ve,s),st=!0},p(e,[s]){const M={};s&2&&(M.$$scope={dirty:s,ctx:e}),E.$set(M);const me={};s&2&&(me.$$scope={dirty:s,ctx:e}),R.$set(me);const V={};s&2&&(V.$$scope={dirty:s,ctx:e}),Y.$set(V);const ue={};s&2&&(ue.$$scope={dirty:s,ctx:e}),S.$set(ue);const F={};s&2&&(F.$$scope={dirty:s,ctx:e}),A.$set(F);const ge={};s&2&&(ge.$$scope={dirty:s,ctx:e}),H.$set(ge)},i(e){st||(b(h.$$.fragment,e),b(m.$$.fragment,e),b(z.$$.fragment,e),b(K.$$.fragment,e),b(O.$$.fragment,e),b(ee.$$.fragment,e),b(E.$$.fragment,e),b(te.$$.fragment,e),b(ae.$$.fragment,e),b(ne.$$.fragment,e),b(R.$$.fragment,e),b(se.$$.fragment,e),b(oe.$$.fragment,e),b(ie.$$.fragment,e),b(Y.$$.fragment,e),b(re.$$.fragment,e),b(le.$$.fragment,e),b(ce.$$.fragment,e),b(S.$$.fragment,e),b(pe.$$.fragment,e),b(de.$$.fragment,e),b(A.$$.fragment,e),b(he.$$.fragment,e),b(H.$$.fragment,e),b(fe.$$.fragment,e),st=!0)},o(e){y(h.$$.fragment,e),y(m.$$.fragment,e),y(z.$$.fragment,e),y(K.$$.fragment,e),y(O.$$.fragment,e),y(ee.$$.fragment,e),y(E.$$.fragment,e),y(te.$$.fragment,e),y(ae.$$.fragment,e),y(ne.$$.fragment,e),y(R.$$.fragment,e),y(se.$$.fragment,e),y(oe.$$.fragment,e),y(ie.$$.fragment,e),y(Y.$$.fragment,e),y(re.$$.fragment,e),y(le.$$.fragment,e),y(ce.$$.fragment,e),y(S.$$.fragment,e),y(pe.$$.fragment,e),y(de.$$.fragment,e),y(A.$$.fragment,e),y(he.$$.fragment,e),y(H.$$.fragment,e),y(fe.$$.fragment,e),st=!1},d(e){e&&(a(C),a(f),a(o),a(t),a(Qe),a(L),a(Ee),a(Re),a($),a(Ye),a(Se),a(W),a(Ae),a(j),a(He),a(Pe),a(X),a(De),a(B),a(Le),a(ze),a(q),a(Ke),a(x),a(Oe),a(et),a(T),a(tt),a(J),a(at),a(nt),a(Ve)),a(n),w(h,e),w(m,e),w(z,e),w(K),w(O),w(ee),w(E),w(te,e),w(ae),w(ne),w(R),w(se,e),w(oe),w(ie),w(Y),w(re,e),w(le),w(ce),w(S),w(pe,e),w(de),w(A),w(he),w(H),w(fe,e)}}}const da='{"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":[{"title":"FirstBlockCacheConfig","local":"diffusers.FirstBlockCacheConfig","sections":[],"depth":3},{"title":"TaylorSeerCacheConfig","local":"diffusers.TaylorSeerCacheConfig","sections":[],"depth":3}],"depth":2}],"depth":1}';function ha(v){return Kt(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class wa extends Ot{constructor(n){super(),ea(this,n,ha,pa,zt,{})}}export{wa as component};
