import{s as ie,n as de,o as re}from"../chunks/scheduler.8c3d61f6.js";import{S as oe,i as ce,g as i,s,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 X,y as he,a as n,v as $,d as I,t as D,w as B}from"../chunks/index.589a98e8.js";import{C as se}from"../chunks/CodeBlock.36627b28.js";import{H as le,E as fe}from"../chunks/EditOnGithub.e5a8d9cb.js";function me(q){let r,U,C,H,p,Z,h,F='<a href="https://huggingface.co/papers/2312.00858" rel="nofollow">DeepCache</a> accelerates <a href="/docs/diffusers/pr_8408/en/api/pipelines/stable_diffusion/text2img#diffusers.StableDiffusionPipeline">StableDiffusionPipeline</a> and <a href="/docs/diffusers/pr_8408/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.',j,f,A='Start by installing <a href="https://github.com/horseee/DeepCache" rel="nofollow">DeepCache</a>:',E,m,G,u,Q='Then load and enable the <a href="https://github.com/horseee/DeepCache#usage" rel="nofollow"><code>DeepCacheSDHelper</code></a>:',S,w,L,b,O=`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,K='<img src="https://github.com/horseee/Diffusion_DeepCache/raw/master/static/images/example.png"/>',Y,T,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.',k,g,R,J,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).',N,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>",P,M,V,y,z;return p=new le({props:{title:"DeepCache",local:"deepcache",headingTag:"h1"}}),m=new se({props:{code:"cGlwJTIwaW5zdGFsbCUyMERlZXBDYWNoZQ==",highlighted:"pip install DeepCache",wrap:!1}}),w=new se({props:{code:"JTIwJTIwaW1wb3J0JTIwdG9yY2glMEElMjAlMjBmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwU3RhYmxlRGlmZnVzaW9uUGlwZWxpbmUlMEElMjAlMjBwaXBlJTIwJTNEJTIwU3RhYmxlRGlmZnVzaW9uUGlwZWxpbmUuZnJvbV9wcmV0cmFpbmVkKCdydW53YXltbCUyRnN0YWJsZS1kaWZmdXNpb24tdjEtNSclMkMlMjB0b3JjaF9kdHlwZSUzRHRvcmNoLmZsb2F0MTYpLnRvKCUyMmN1ZGElMjIpJTBBJTBBJTJCJTIwZnJvbSUyMERlZXBDYWNoZSUyMGltcG9ydCUyMERlZXBDYWNoZVNESGVscGVyJTBBJTJCJTIwaGVscGVyJTIwJTNEJTIwRGVlcENhY2hlU0RIZWxwZXIocGlwZSUzRHBpcGUpJTBBJTJCJTIwaGVscGVyLnNldF9wYXJhbXMoJTBBJTJCJTIwJTIwJTIwJTIwJTIwY2FjaGVfaW50ZXJ2YWwlM0QzJTJDJTBBJTJCJTIwJTIwJTIwJTIwJTIwY2FjaGVfYnJhbmNoX2lkJTNEMCUyQyUwQSUyQiUyMCklMEElMkIlMjBoZWxwZXIuZW5hYmxlKCklMEElMEElMjAlMjBpbWFnZSUyMCUzRCUyMHBpcGUoJTIyYSUyMHBob3RvJTIwb2YlMjBhbiUyMGFzdHJvbmF1dCUyMG9uJTIwYSUyMG1vb24lMjIpLmltYWdlcyU1QjAlNUQ=",highlighted:`  import torch
  from diffusers import StableDiffusionPipeline
  pipe = StableDiffusionPipeline.from_pretrained(&#x27;runwayml/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}}),g=new le({props:{title:"Benchmark",local:"benchmark",headingTag:"h2"}}),M=new fe({props:{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/en/optimization/deepcache.md"}}),{c(){r=i("meta"),U=s(),C=i("p"),H=s(),_(p.$$.fragment),Z=s(),h=i("p"),h.innerHTML=F,j=s(),f=i("p"),f.innerHTML=A,E=s(),_(m.$$.fragment),G=s(),u=i("p"),u.innerHTML=Q,S=s(),_(w.$$.fragment),L=s(),b=i("p"),b.innerHTML=O,W=s(),o=i("div"),o.innerHTML=K,Y=s(),T=i("p"),T.innerHTML=ee,k=s(),_(g.$$.fragment),R=s(),J=i("p"),J.innerHTML=te,N=s(),x=i("table"),x.innerHTML=ae,P=s(),_(M.$$.fragment),V=s(),y=i("p"),this.h()},l(e){const t=pe("svelte-u9bgzb",document.head);r=d(t,"META",{name:!0,content:!0}),t.forEach(a),U=l(e),C=d(e,"P",{}),ne(C).forEach(a),H=l(e),v(p.$$.fragment,e),Z=l(e),h=d(e,"P",{"data-svelte-h":!0}),c(h)!=="svelte-1b58uu4"&&(h.innerHTML=F),j=l(e),f=d(e,"P",{"data-svelte-h":!0}),c(f)!=="svelte-yv0ij"&&(f.innerHTML=A),E=l(e),v(m.$$.fragment,e),G=l(e),u=d(e,"P",{"data-svelte-h":!0}),c(u)!=="svelte-sy0xvd"&&(u.innerHTML=Q),S=l(e),v(w.$$.fragment,e),L=l(e),b=d(e,"P",{"data-svelte-h":!0}),c(b)!=="svelte-1k27afg"&&(b.innerHTML=O),W=l(e),o=d(e,"DIV",{class:!0,"data-svelte-h":!0}),c(o)!=="svelte-12c1pq6"&&(o.innerHTML=K),Y=l(e),T=d(e,"P",{"data-svelte-h":!0}),c(T)!=="svelte-a518zi"&&(T.innerHTML=ee),k=l(e),v(g.$$.fragment,e),R=l(e),J=d(e,"P",{"data-svelte-h":!0}),c(J)!=="svelte-18sczus"&&(J.innerHTML=te),N=l(e),x=d(e,"TABLE",{"data-svelte-h":!0}),c(x)!=="svelte-whx3f0"&&(x.innerHTML=ae),P=l(e),v(M.$$.fragment,e),V=l(e),y=d(e,"P",{}),ne(y).forEach(a),this.h()},h(){X(r,"name","hf:doc:metadata"),X(r,"content",ue),X(o,"class","flex justify-center")},m(e,t){he(document.head,r),n(e,U,t),n(e,C,t),n(e,H,t),$(p,e,t),n(e,Z,t),n(e,h,t),n(e,j,t),n(e,f,t),n(e,E,t),$(m,e,t),n(e,G,t),n(e,u,t),n(e,S,t),$(w,e,t),n(e,L,t),n(e,b,t),n(e,W,t),n(e,o,t),n(e,Y,t),n(e,T,t),n(e,k,t),$(g,e,t),n(e,R,t),n(e,J,t),n(e,N,t),n(e,x,t),n(e,P,t),$(M,e,t),n(e,V,t),n(e,y,t),z=!0},p:de,i(e){z||(I(p.$$.fragment,e),I(m.$$.fragment,e),I(w.$$.fragment,e),I(g.$$.fragment,e),I(M.$$.fragment,e),z=!0)},o(e){D(p.$$.fragment,e),D(m.$$.fragment,e),D(w.$$.fragment,e),D(g.$$.fragment,e),D(M.$$.fragment,e),z=!1},d(e){e&&(a(U),a(C),a(H),a(Z),a(h),a(j),a(f),a(E),a(G),a(u),a(S),a(L),a(b),a(W),a(o),a(Y),a(T),a(k),a(R),a(J),a(N),a(x),a(P),a(V),a(y)),a(r),B(p,e),B(m,e),B(w,e),B(g,e),B(M,e)}}}const ue='{"title":"DeepCache","local":"deepcache","sections":[{"title":"Benchmark","local":"benchmark","sections":[],"depth":2}],"depth":1}';function we(q){return re(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class xe extends oe{constructor(r){super(),ce(this,r,we,me,ie,{})}}export{xe as component};
