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