import{s as pt,n as ot,o as rt}from"../chunks/scheduler.e4ff9b64.js";import{S as ct,i as ht,e as i,s as d,c as g,h as ft,a as s,d as a,b as n,f as nt,g as _,j as r,k as N,l as mt,m as l,n as x,t as D,o as G,p as j}from"../chunks/index.09f1bca0.js";import{C as ut,H as it,E as Mt}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.b71282d6.js";import{C as st}from"../chunks/CodeBlock.c52051fd.js";function bt(q){let p,B,v,H,c,L,h,S,f,A='<a href="https://huggingface.co/papers/2312.00858" rel="nofollow">DeepCache</a> 通过策略性地缓存和重用高级特征，同时利用 U-Net 架构高效更新低级特征，来加速 <code>StableDiffusionPipeline</code> 和 <code>StableDiffusionXLPipeline</code>。',Z,m,K='首先安装 <a href="https://github.com/horseee/DeepCache" rel="nofollow">DeepCache</a>：',E,u,I,M,O='然后加载并启用 <a href="https://github.com/horseee/DeepCache#usage" rel="nofollow"><code>DeepCacheSDHelper</code></a>：',V,b,W,w,tt=`<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>。`,Q,o,et='<img src="https://github.com/horseee/Diffusion_DeepCache/raw/master/static/images/example.png"/>',z,y,at='您可以在 <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> 数据集中随机选择的。',R,C,P,U,lt='我们在 NVIDIA RTX A5000 上测试了 DeepCache 使用 50 个推理步骤加速 <a href="https://huggingface.co/stabilityai/stable-diffusion-2-1" rel="nofollow">Stable Diffusion v2.1</a> 的速度，使用不同的配置，包括分辨率、批处理大小、缓存间隔（I）和缓存分支(B)。',X,$,dt="<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>",Y,T,k,J,F;return c=new ut({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),h=new it({props:{title:"DeepCache",local:"deepcache",headingTag:"h1"}}),u=new st({props:{code:"cGlwJTIwaW5zdGFsbCUyMERlZXBDYWNoZQ==",highlighted:"pip install DeepCache",wrap:!1}}),b=new st({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}}),C=new it({props:{title:"基准测试",local:"基准测试",headingTag:"h2"}}),T=new Mt({props:{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/zh/optimization/deepcache.md"}}),{c(){p=i("meta"),B=d(),v=i("p"),H=d(),g(c.$$.fragment),L=d(),g(h.$$.fragment),S=d(),f=i("p"),f.innerHTML=A,Z=d(),m=i("p"),m.innerHTML=K,E=d(),g(u.$$.fragment),I=d(),M=i("p"),M.innerHTML=O,V=d(),g(b.$$.fragment),W=d(),w=i("p"),w.innerHTML=tt,Q=d(),o=i("div"),o.innerHTML=et,z=d(),y=i("p"),y.innerHTML=at,R=d(),g(C.$$.fragment),P=d(),U=i("p"),U.innerHTML=lt,X=d(),$=i("table"),$.innerHTML=dt,Y=d(),g(T.$$.fragment),k=d(),J=i("p"),this.h()},l(t){const e=ft("svelte-u9bgzb",document.head);p=s(e,"META",{name:!0,content:!0}),e.forEach(a),B=n(t),v=s(t,"P",{}),nt(v).forEach(a),H=n(t),_(c.$$.fragment,t),L=n(t),_(h.$$.fragment,t),S=n(t),f=s(t,"P",{"data-svelte-h":!0}),r(f)!=="svelte-f6ph5f"&&(f.innerHTML=A),Z=n(t),m=s(t,"P",{"data-svelte-h":!0}),r(m)!=="svelte-12q1jl1"&&(m.innerHTML=K),E=n(t),_(u.$$.fragment,t),I=n(t),M=s(t,"P",{"data-svelte-h":!0}),r(M)!=="svelte-1yikv05"&&(M.innerHTML=O),V=n(t),_(b.$$.fragment,t),W=n(t),w=s(t,"P",{"data-svelte-h":!0}),r(w)!=="svelte-1koojx9"&&(w.innerHTML=tt),Q=n(t),o=s(t,"DIV",{class:!0,"data-svelte-h":!0}),r(o)!=="svelte-12c1pq6"&&(o.innerHTML=et),z=n(t),y=s(t,"P",{"data-svelte-h":!0}),r(y)!=="svelte-1uot2j0"&&(y.innerHTML=at),R=n(t),_(C.$$.fragment,t),P=n(t),U=s(t,"P",{"data-svelte-h":!0}),r(U)!=="svelte-s3ppmj"&&(U.innerHTML=lt),X=n(t),$=s(t,"TABLE",{"data-svelte-h":!0}),r($)!=="svelte-tieox5"&&($.innerHTML=dt),Y=n(t),_(T.$$.fragment,t),k=n(t),J=s(t,"P",{}),nt(J).forEach(a),this.h()},h(){N(p,"name","hf:doc:metadata"),N(p,"content",wt),N(o,"class","flex justify-center")},m(t,e){mt(document.head,p),l(t,B,e),l(t,v,e),l(t,H,e),x(c,t,e),l(t,L,e),x(h,t,e),l(t,S,e),l(t,f,e),l(t,Z,e),l(t,m,e),l(t,E,e),x(u,t,e),l(t,I,e),l(t,M,e),l(t,V,e),x(b,t,e),l(t,W,e),l(t,w,e),l(t,Q,e),l(t,o,e),l(t,z,e),l(t,y,e),l(t,R,e),x(C,t,e),l(t,P,e),l(t,U,e),l(t,X,e),l(t,$,e),l(t,Y,e),x(T,t,e),l(t,k,e),l(t,J,e),F=!0},p:ot,i(t){F||(D(c.$$.fragment,t),D(h.$$.fragment,t),D(u.$$.fragment,t),D(b.$$.fragment,t),D(C.$$.fragment,t),D(T.$$.fragment,t),F=!0)},o(t){G(c.$$.fragment,t),G(h.$$.fragment,t),G(u.$$.fragment,t),G(b.$$.fragment,t),G(C.$$.fragment,t),G(T.$$.fragment,t),F=!1},d(t){t&&(a(B),a(v),a(H),a(L),a(S),a(f),a(Z),a(m),a(E),a(I),a(M),a(V),a(W),a(w),a(Q),a(o),a(z),a(y),a(R),a(P),a(U),a(X),a($),a(Y),a(k),a(J)),a(p),j(c,t),j(h,t),j(u,t),j(b,t),j(C,t),j(T,t)}}}const wt='{"title":"DeepCache","local":"deepcache","sections":[{"title":"基准测试","local":"基准测试","sections":[],"depth":2}],"depth":1}';function yt(q){return rt(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class gt extends ct{constructor(p){super(),ht(this,p,yt,bt,pt,{})}}export{gt as component};
