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