import{s as se,n as de,o as re}from"../chunks/scheduler.8c3d61f6.js";import{S as oe,i as ce,g as s,s as i,r as _,A as pe,h as d,f as a,c as l,j as ne,u as v,x as c,k as Y,y as he,a as n,v as $,d as D,t as B,w as G}from"../chunks/index.da70eac4.js";import{C as ie}from"../chunks/CodeBlock.00a903b3.js";import{H as le,E as fe}from"../chunks/EditOnGithub.1e64e623.js";function me(q){let r,J,U,j,p,S,h,A='<a href="https://huggingface.co/papers/2312.00858" rel="nofollow">DeepCache</a> accelerates <a href="/docs/diffusers/pr_10065/en/api/pipelines/stable_diffusion/text2img#diffusers.StableDiffusionPipeline">StableDiffusionPipeline</a> and <a href="/docs/diffusers/pr_10065/en/api/pipelines/stable_diffusion/stable_diffusion_xl#diffusers.StableDiffusionXLPipeline">StableDiffusionXLPipeline</a> by strategically caching and reusing high-level features while efficiently updating low-level features by taking advantage of the U-Net architecture.',H,f,F='Start by installing <a href="https://github.com/horseee/DeepCache" rel="nofollow">DeepCache</a>:',Z,m,E,u,N='Then load and enable the <a href="https://github.com/horseee/DeepCache#usage" rel="nofollow"><code>DeepCacheSDHelper</code></a>:',I,b,L,w,K=`The <code>set_params</code> method accepts two arguments: <code>cache_interval</code> and <code>cache_branch_id</code>. <code>cache_interval</code> means the frequency of feature caching, specified as the number of steps between each cache operation. <code>cache_branch_id</code> identifies which branch of the network (ordered from the shallowest to the deepest layer) is responsible for executing the caching processes.
Opting for a lower <code>cache_branch_id</code> or a larger <code>cache_interval</code> can lead to faster inference speed at the expense of reduced image quality (ablation experiments of these two hyperparameters can be found in the <a href="https://arxiv.org/abs/2312.00858" rel="nofollow">paper</a>). Once those arguments are set, use the <code>enable</code> or <code>disable</code> methods to activate or deactivate the <code>DeepCacheSDHelper</code>.`,W,o,O='<img src="https://github.com/horseee/Diffusion_DeepCache/raw/master/static/images/example.png"/>',V,g,ee='You can find more generated samples (original pipeline vs DeepCache) and the corresponding inference latency in the <a href="https://wandb.ai/horseee/DeepCache/runs/jwlsqqgt?workspace=user-horseee" rel="nofollow">WandB report</a>. The prompts are randomly selected from the <a href="https://cocodataset.org/#home" rel="nofollow">MS-COCO 2017</a> dataset.',z,M,P,y,te='We tested how much faster DeepCache accelerates <a href="https://huggingface.co/stabilityai/stable-diffusion-2-1" rel="nofollow">Stable Diffusion v2.1</a> with 50 inference steps on an NVIDIA RTX A5000, using different configurations for resolution, batch size, cache interval (I), and cache branch (B).',Q,x,ae="<thead><tr><th><strong>Resolution</strong></th> <th><strong>Batch size</strong></th> <th><strong>Original</strong></th> <th><strong>DeepCache(I=3, B=0)</strong></th> <th><strong>DeepCache(I=5, B=0)</strong></th> <th><strong>DeepCache(I=5, B=1)</strong></th></tr></thead> <tbody><tr><td>512</td> <td>8</td> <td>15.96</td> <td>6.88(2.32x)</td> <td>5.03(3.18x)</td> <td>7.27(2.20x)</td></tr> <tr><td></td> <td>4</td> <td>8.39</td> <td>3.60(2.33x)</td> <td>2.62(3.21x)</td> <td>3.75(2.24x)</td></tr> <tr><td></td> <td>1</td> <td>2.61</td> <td>1.12(2.33x)</td> <td>0.81(3.24x)</td> <td>1.11(2.35x)</td></tr> <tr><td>768</td> <td>8</td> <td>43.58</td> <td>18.99(2.29x)</td> <td>13.96(3.12x)</td> <td>21.27(2.05x)</td></tr> <tr><td></td> <td>4</td> <td>22.24</td> <td>9.67(2.30x)</td> <td>7.10(3.13x)</td> <td>10.74(2.07x)</td></tr> <tr><td></td> <td>1</td> <td>6.33</td> <td>2.72(2.33x)</td> <td>1.97(3.21x)</td> <td>2.98(2.12x)</td></tr> <tr><td>1024</td> <td>8</td> <td>101.95</td> <td>45.57(2.24x)</td> <td>33.72(3.02x)</td> <td>53.00(1.92x)</td></tr> <tr><td></td> <td>4</td> <td>49.25</td> <td>21.86(2.25x)</td> <td>16.19(3.04x)</td> <td>25.78(1.91x)</td></tr> <tr><td></td> <td>1</td> <td>13.83</td> <td>6.07(2.28x)</td> <td>4.43(3.12x)</td> <td>7.15(1.93x)</td></tr></tbody>",R,T,k,C,X;return p=new le({props:{title:"DeepCache",local:"deepcache",headingTag:"h1"}}),m=new ie({props:{code:"cGlwJTIwaW5zdGFsbCUyMERlZXBDYWNoZQ==",highlighted:"pip install DeepCache",wrap:!1}}),b=new ie({props:{code:"JTIwJTIwaW1wb3J0JTIwdG9yY2glMEElMjAlMjBmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwU3RhYmxlRGlmZnVzaW9uUGlwZWxpbmUlMEElMjAlMjBwaXBlJTIwJTNEJTIwU3RhYmxlRGlmZnVzaW9uUGlwZWxpbmUuZnJvbV9wcmV0cmFpbmVkKCdzdGFibGUtZGlmZnVzaW9uLXYxLTUlMkZzdGFibGUtZGlmZnVzaW9uLXYxLTUnJTJDJTIwdG9yY2hfZHR5cGUlM0R0b3JjaC5mbG9hdDE2KS50byglMjJjdWRhJTIyKSUwQSUwQSUyQiUyMGZyb20lMjBEZWVwQ2FjaGUlMjBpbXBvcnQlMjBEZWVwQ2FjaGVTREhlbHBlciUwQSUyQiUyMGhlbHBlciUyMCUzRCUyMERlZXBDYWNoZVNESGVscGVyKHBpcGUlM0RwaXBlKSUwQSUyQiUyMGhlbHBlci5zZXRfcGFyYW1zKCUwQSUyQiUyMCUyMCUyMCUyMCUyMGNhY2hlX2ludGVydmFsJTNEMyUyQyUwQSUyQiUyMCUyMCUyMCUyMCUyMGNhY2hlX2JyYW5jaF9pZCUzRDAlMkMlMEElMkIlMjApJTBBJTJCJTIwaGVscGVyLmVuYWJsZSgpJTBBJTBBJTIwJTIwaW1hZ2UlMjAlM0QlMjBwaXBlKCUyMmElMjBwaG90byUyMG9mJTIwYW4lMjBhc3Ryb25hdXQlMjBvbiUyMGElMjBtb29uJTIyKS5pbWFnZXMlNUIwJTVE",highlighted:`  import torch
  from diffusers import StableDiffusionPipeline
  pipe = StableDiffusionPipeline.from_pretrained(&#x27;stable-diffusion-v1-5/stable-diffusion-v1-5&#x27;, torch_dtype=torch.float16).to(&quot;cuda&quot;)

<span class="hljs-addition">+ from DeepCache import DeepCacheSDHelper</span>
<span class="hljs-addition">+ helper = DeepCacheSDHelper(pipe=pipe)</span>
<span class="hljs-addition">+ helper.set_params(</span>
<span class="hljs-addition">+     cache_interval=3,</span>
<span class="hljs-addition">+     cache_branch_id=0,</span>
<span class="hljs-addition">+ )</span>
<span class="hljs-addition">+ helper.enable()</span>

  image = pipe(&quot;a photo of an astronaut on a moon&quot;).images[0]`,wrap:!1}}),M=new le({props:{title:"Benchmark",local:"benchmark",headingTag:"h2"}}),T=new fe({props:{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/en/optimization/deepcache.md"}}),{c(){r=s("meta"),J=i(),U=s("p"),j=i(),_(p.$$.fragment),S=i(),h=s("p"),h.innerHTML=A,H=i(),f=s("p"),f.innerHTML=F,Z=i(),_(m.$$.fragment),E=i(),u=s("p"),u.innerHTML=N,I=i(),_(b.$$.fragment),L=i(),w=s("p"),w.innerHTML=K,W=i(),o=s("div"),o.innerHTML=O,V=i(),g=s("p"),g.innerHTML=ee,z=i(),_(M.$$.fragment),P=i(),y=s("p"),y.innerHTML=te,Q=i(),x=s("table"),x.innerHTML=ae,R=i(),_(T.$$.fragment),k=i(),C=s("p"),this.h()},l(e){const t=pe("svelte-u9bgzb",document.head);r=d(t,"META",{name:!0,content:!0}),t.forEach(a),J=l(e),U=d(e,"P",{}),ne(U).forEach(a),j=l(e),v(p.$$.fragment,e),S=l(e),h=d(e,"P",{"data-svelte-h":!0}),c(h)!=="svelte-1rqkqpg"&&(h.innerHTML=A),H=l(e),f=d(e,"P",{"data-svelte-h":!0}),c(f)!=="svelte-yv0ij"&&(f.innerHTML=F),Z=l(e),v(m.$$.fragment,e),E=l(e),u=d(e,"P",{"data-svelte-h":!0}),c(u)!=="svelte-sy0xvd"&&(u.innerHTML=N),I=l(e),v(b.$$.fragment,e),L=l(e),w=d(e,"P",{"data-svelte-h":!0}),c(w)!=="svelte-1k27afg"&&(w.innerHTML=K),W=l(e),o=d(e,"DIV",{class:!0,"data-svelte-h":!0}),c(o)!=="svelte-12c1pq6"&&(o.innerHTML=O),V=l(e),g=d(e,"P",{"data-svelte-h":!0}),c(g)!=="svelte-a518zi"&&(g.innerHTML=ee),z=l(e),v(M.$$.fragment,e),P=l(e),y=d(e,"P",{"data-svelte-h":!0}),c(y)!=="svelte-18sczus"&&(y.innerHTML=te),Q=l(e),x=d(e,"TABLE",{"data-svelte-h":!0}),c(x)!=="svelte-whx3f0"&&(x.innerHTML=ae),R=l(e),v(T.$$.fragment,e),k=l(e),C=d(e,"P",{}),ne(C).forEach(a),this.h()},h(){Y(r,"name","hf:doc:metadata"),Y(r,"content",ue),Y(o,"class","flex justify-center")},m(e,t){he(document.head,r),n(e,J,t),n(e,U,t),n(e,j,t),$(p,e,t),n(e,S,t),n(e,h,t),n(e,H,t),n(e,f,t),n(e,Z,t),$(m,e,t),n(e,E,t),n(e,u,t),n(e,I,t),$(b,e,t),n(e,L,t),n(e,w,t),n(e,W,t),n(e,o,t),n(e,V,t),n(e,g,t),n(e,z,t),$(M,e,t),n(e,P,t),n(e,y,t),n(e,Q,t),n(e,x,t),n(e,R,t),$(T,e,t),n(e,k,t),n(e,C,t),X=!0},p:de,i(e){X||(D(p.$$.fragment,e),D(m.$$.fragment,e),D(b.$$.fragment,e),D(M.$$.fragment,e),D(T.$$.fragment,e),X=!0)},o(e){B(p.$$.fragment,e),B(m.$$.fragment,e),B(b.$$.fragment,e),B(M.$$.fragment,e),B(T.$$.fragment,e),X=!1},d(e){e&&(a(J),a(U),a(j),a(S),a(h),a(H),a(f),a(Z),a(E),a(u),a(I),a(L),a(w),a(W),a(o),a(V),a(g),a(z),a(P),a(y),a(Q),a(x),a(R),a(k),a(C)),a(r),G(p,e),G(m,e),G(b,e),G(M,e),G(T,e)}}}const ue='{"title":"DeepCache","local":"deepcache","sections":[{"title":"Benchmark","local":"benchmark","sections":[],"depth":2}],"depth":1}';function be(q){return re(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class xe extends oe{constructor(r){super(),ce(this,r,be,me,se,{})}}export{xe as component};
