import{s as nt,n as it,o as ot}from"../chunks/scheduler.5c93273d.js";import{S as pt,i as rt,g as n,s as d,r as _,A as ct,h as i,f as a,c as s,j as lt,u as D,x as r,k,y as ht,a as l,v as G,d as j,t as v,w as J}from"../chunks/index.e43dd92b.js";import{C as dt}from"../chunks/CodeBlock.6896320e.js";import{H as st,E as ft}from"../chunks/getInferenceSnippets.d410b42d.js";function mt(A){let o,x,g,B,c,H,h,F='<a href="https://huggingface.co/papers/2312.00858" rel="nofollow">DeepCache</a> 通过策略性地缓存和重用高级特征，同时利用 U-Net 架构高效更新低级特征，来加速 <code>StableDiffusionPipeline</code> 和 <code>StableDiffusionXLPipeline</code>。',Z,f,N='首先安装 <a href="https://github.com/horseee/DeepCache" rel="nofollow">DeepCache</a>：',E,m,I,u,q='然后加载并启用 <a href="https://github.com/horseee/DeepCache#usage" rel="nofollow"><code>DeepCacheSDHelper</code></a>：',S,M,L,w,K=`<code>set_params</code> 方法接受两个参数：<code>cache_interval</code> 和 <code>cache_branch_id</code>。<code>cache_interval</code> 表示特征缓存的频率，指定为每次缓存操作之间的步数。<code>cache_branch_id</code> 标识网络的哪个分支（从最浅层到最深层排序）负责执行缓存过程。
选择较低的 <code>cache_branch_id</code> 或较大的 <code>cache_interval</code> 可以加快推理速度，但会降低图像质量（这些超参数的消融实验可以在<a href="https://huggingface.co/papers/2312.00858" rel="nofollow">论文</a>中找到）。一旦设置了这些参数，使用 <code>enable</code> 或 <code>disable</code> 方法来激活或停用 <code>DeepCacheSDHelper</code>。`,V,p,O='<img src="https://github.com/horseee/Diffusion_DeepCache/raw/master/static/images/example.png"/>',W,b,tt='您可以在 <a href="https://wandb.ai/horseee/DeepCache/runs/jwlsqqgt?workspace=user-horseee" rel="nofollow">WandB 报告</a> 中找到更多生成的样本（原始管道 vs DeepCache）和相应的推理延迟。提示是从 <a href="https://cocodataset.org/#home" rel="nofollow">MS-COCO 2017</a> 数据集中随机选择的。',Q,y,R,U,et='我们在 NVIDIA RTX A5000 上测试了 DeepCache 使用 50 个推理步骤加速 <a href="https://huggingface.co/stabilityai/stable-diffusion-2-1" rel="nofollow">Stable Diffusion v2.1</a> 的速度，使用不同的配置，包括分辨率、批处理大小、缓存间隔（I）和缓存分支(B)。',z,C,at="<thead><tr><th><strong>分辨率</strong></th> <th><strong>批次大小</strong></th> <th><strong>原始</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.32倍)</td> <td>5.03(3.18倍)</td> <td>7.27(2.20x)</td></tr> <tr><td></td> <td>4</td> <td>8.39</td> <td>3.60(2.33倍)</td> <td>2.62(3.21倍)</td> <td>3.75(2.24x)</td></tr> <tr><td></td> <td>1</td> <td>2.61</td> <td>1.12(2.33倍)</td> <td>0.81(3.24倍)</td> <td>1.11(2.35x)</td></tr> <tr><td>768</td> <td>8</td> <td>43.58</td> <td>18.99(2.29倍)</td> <td>13.96(3.12倍)</td> <td>21.27(2.05x)</td></tr> <tr><td></td> <td>4</td> <td>22.24</td> <td>9.67(2.30倍)</td> <td>7.10(3.13倍)</td> <td>10.74(2.07x)</td></tr> <tr><td></td> <td>1</td> <td>6.33</td> <td>2.72(2.33倍)</td> <td>1.97(3.21倍)</td> <td>2.98(2.12x)</td></tr> <tr><td>1024</td> <td>8</td> <td>101.95</td> <td>45.57(2.24倍)</td> <td>33.72(3.02倍)</td> <td>53.00(1.92x)</td></tr> <tr><td></td> <td>4</td> <td>49.25</td> <td>21.86(2.25倍)</td> <td>16.19(3.04倍)</td> <td>25.78(1.91x)</td></tr> <tr><td></td> <td>1</td> <td>13.83</td> <td>6.07(2.28倍)</td> <td>4.43(3.12倍)</td> <td>7.15(1.93x)</td></tr></tbody>",P,T,X,$,Y;return c=new st({props:{title:"DeepCache",local:"deepcache",headingTag:"h1"}}),m=new dt({props:{code:"cGlwJTIwaW5zdGFsbCUyMERlZXBDYWNoZQ==",highlighted:"pip install DeepCache",wrap:!1}}),M=new dt({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 st({props:{title:"基准测试",local:"基准测试",headingTag:"h2"}}),T=new ft({props:{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/zh/optimization/deepcache.md"}}),{c(){o=n("meta"),x=d(),g=n("p"),B=d(),_(c.$$.fragment),H=d(),h=n("p"),h.innerHTML=F,Z=d(),f=n("p"),f.innerHTML=N,E=d(),_(m.$$.fragment),I=d(),u=n("p"),u.innerHTML=q,S=d(),_(M.$$.fragment),L=d(),w=n("p"),w.innerHTML=K,V=d(),p=n("div"),p.innerHTML=O,W=d(),b=n("p"),b.innerHTML=tt,Q=d(),_(y.$$.fragment),R=d(),U=n("p"),U.innerHTML=et,z=d(),C=n("table"),C.innerHTML=at,P=d(),_(T.$$.fragment),X=d(),$=n("p"),this.h()},l(t){const e=ct("svelte-u9bgzb",document.head);o=i(e,"META",{name:!0,content:!0}),e.forEach(a),x=s(t),g=i(t,"P",{}),lt(g).forEach(a),B=s(t),D(c.$$.fragment,t),H=s(t),h=i(t,"P",{"data-svelte-h":!0}),r(h)!=="svelte-f6ph5f"&&(h.innerHTML=F),Z=s(t),f=i(t,"P",{"data-svelte-h":!0}),r(f)!=="svelte-12q1jl1"&&(f.innerHTML=N),E=s(t),D(m.$$.fragment,t),I=s(t),u=i(t,"P",{"data-svelte-h":!0}),r(u)!=="svelte-1yikv05"&&(u.innerHTML=q),S=s(t),D(M.$$.fragment,t),L=s(t),w=i(t,"P",{"data-svelte-h":!0}),r(w)!=="svelte-1koojx9"&&(w.innerHTML=K),V=s(t),p=i(t,"DIV",{class:!0,"data-svelte-h":!0}),r(p)!=="svelte-12c1pq6"&&(p.innerHTML=O),W=s(t),b=i(t,"P",{"data-svelte-h":!0}),r(b)!=="svelte-1uot2j0"&&(b.innerHTML=tt),Q=s(t),D(y.$$.fragment,t),R=s(t),U=i(t,"P",{"data-svelte-h":!0}),r(U)!=="svelte-s3ppmj"&&(U.innerHTML=et),z=s(t),C=i(t,"TABLE",{"data-svelte-h":!0}),r(C)!=="svelte-tieox5"&&(C.innerHTML=at),P=s(t),D(T.$$.fragment,t),X=s(t),$=i(t,"P",{}),lt($).forEach(a),this.h()},h(){k(o,"name","hf:doc:metadata"),k(o,"content",ut),k(p,"class","flex justify-center")},m(t,e){ht(document.head,o),l(t,x,e),l(t,g,e),l(t,B,e),G(c,t,e),l(t,H,e),l(t,h,e),l(t,Z,e),l(t,f,e),l(t,E,e),G(m,t,e),l(t,I,e),l(t,u,e),l(t,S,e),G(M,t,e),l(t,L,e),l(t,w,e),l(t,V,e),l(t,p,e),l(t,W,e),l(t,b,e),l(t,Q,e),G(y,t,e),l(t,R,e),l(t,U,e),l(t,z,e),l(t,C,e),l(t,P,e),G(T,t,e),l(t,X,e),l(t,$,e),Y=!0},p:it,i(t){Y||(j(c.$$.fragment,t),j(m.$$.fragment,t),j(M.$$.fragment,t),j(y.$$.fragment,t),j(T.$$.fragment,t),Y=!0)},o(t){v(c.$$.fragment,t),v(m.$$.fragment,t),v(M.$$.fragment,t),v(y.$$.fragment,t),v(T.$$.fragment,t),Y=!1},d(t){t&&(a(x),a(g),a(B),a(H),a(h),a(Z),a(f),a(E),a(I),a(u),a(S),a(L),a(w),a(V),a(p),a(W),a(b),a(Q),a(R),a(U),a(z),a(C),a(P),a(X),a($)),a(o),J(c,t),J(m,t),J(M,t),J(y,t),J(T,t)}}}const ut='{"title":"DeepCache","local":"deepcache","sections":[{"title":"基准测试","local":"基准测试","sections":[],"depth":2}],"depth":1}';function Mt(A){return ot(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Ct extends pt{constructor(o){super(),rt(this,o,Mt,mt,nt,{})}}export{Ct as component};
