import{s as cs,o as rs,n as x}from"../chunks/scheduler.5c93273d.js";import{S as Js,i as ms,g as u,s as c,r as B,A as us,h as y,f as e,c as r,j as Ms,u as _,x as j,k as Jl,y as ys,a as n,v as I,d as C,t as G,w as g}from"../chunks/index.e43dd92b.js";import{C as Q}from"../chunks/CodeBlock.6896320e.js";import{H as ul,E as ds}from"../chunks/getInferenceSnippets.7a494bf3.js";import{H as Hl,a as N}from"../chunks/HfOption.d50154c3.js";function Us(W){let t,m="要在 FLUX.1-dev 上应用第一块缓存，请调用 <code>apply_cache_on_pipe</code>，如下所示。0.08 是 FLUX 模型的默认残差差异值。",p,o,s,a,d='<thead><tr><th>优化</th> <th>原始</th> <th>FBCache rdt=0.06</th> <th>FBCache rdt=0.08</th> <th>FBCache rdt=0.10</th> <th>FBCache rdt=0.12</th></tr></thead> <tbody><tr><td>预览</td> <td><img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/para-attn/flux-original.png" alt="Original"/></td> <td><img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/para-attn/flux-fbc-0.06.png" alt="FBCache rdt=0.06"/></td> <td><img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/para-attn/flux-fbc-0.08.png" alt="FBCache rdt=0.08"/></td> <td><img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/para-attn/flux-fbc-0.10.png" alt="FBCache rdt=0.10"/></td> <td><img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/para-attn/flux-fbc-0.12.png" alt="FBCache rdt=0.12"/></td></tr> <tr><td>墙时间 (s)</td> <td>26.36</td> <td>21.83</td> <td>17.01</td> <td>16.00</td> <td>13.78</td></tr></tbody>',h,J,T="First Block Cache 将推理速度降低到 17.01 秒，与基线相比，或快 1.55 倍，同时保持几乎零质量损失。",b;return o=new Q({props:{code:"aW1wb3J0JTIwdGltZSUwQWltcG9ydCUyMHRvcmNoJTBBZnJvbSUyMGRpZmZ1c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ludCglMjJTYXZpbmclMjBpbWFnZSUyMHRvJTIwZmx1eC5wbmclMjIpJTBBaW1hZ2Uuc2F2ZSglMjJmbHV4LnBuZyUyMik=",highlighted:`<span class="hljs-keyword">import</span> time
<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> FluxPipeline

pipe = FluxPipeline.from_pretrained(
    <span class="hljs-string">&quot;black-forest-labs/FLUX.1-dev&quot;</span>,
    torch_dtype=torch.bfloat16,
).to(<span class="hljs-string">&quot;cuda&quot;</span>)

<span class="hljs-keyword">from</span> para_attn.first_block_cache.diffusers_adapters <span class="hljs-keyword">import</span> apply_cache_on_pipe

apply_cache_on_pipe(pipe, residual_diff_thre
shold=<span class="hljs-number">0.08</span>)

<span class="hljs-comment"># 启用内存节省</span>
<span class="hljs-comment"># pipe.enable_model_cpu_offload()</span>
<span class="hljs-comment"># pipe.enable_sequential_cpu_offload()</span>

begin = time.time()
image = pipe(
    <span class="hljs-string">&quot;A cat holding a sign that says hello world&quot;</span>,
    num_inference_steps=<span class="hljs-number">28</span>,
).images[<span class="hljs-number">0</span>]
end = time.time()
<span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Time: <span class="hljs-subst">{end - begin:<span class="hljs-number">.2</span>f}</span>s&quot;</span>)

<span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;Saving image to flux.png&quot;</span>)
image.save(<span class="hljs-string">&quot;flux.png&quot;</span>)`,wrap:!1}}),{c(){t=u("p"),t.innerHTML=m,p=c(),B(o.$$.fragment),s=c(),a=u("table"),a.innerHTML=d,h=c(),J=u("p"),J.textContent=T},l(U){t=y(U,"P",{"data-svelte-h":!0}),j(t)!=="svelte-13o107o"&&(t.innerHTML=m),p=r(U),_(o.$$.fragment,U),s=r(U),a=y(U,"TABLE",{"data-svelte-h":!0}),j(a)!=="svelte-9gupjq"&&(a.innerHTML=d),h=r(U),J=y(U,"P",{"data-svelte-h":!0}),j(J)!=="svelte-59xgrt"&&(J.textContent=T)},m(U,Z){n(U,t,Z),n(U,p,Z),I(o,U,Z),n(U,s,Z),n(U,a,Z),n(U,h,Z),n(U,J,Z),b=!0},p:x,i(U){b||(C(o.$$.fragment,U),b=!0)},o(U){G(o.$$.fragment,U),b=!1},d(U){U&&(e(t),e(p),e(s),e(a),e(h),e(J)),g(o,U)}}}function js(W){let t,m="要在 HunyuanVideo 上应用 First Block Cache，请使用 <code>apply_cache_on_pipe</code>，如下所示。0.06 是 HunyuanVideo 模型的默认残差差值。",p,o,s,a,d=`<source src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/para-attn/hunyuan-video-original.mp4" type="video/mp4"/>
  您的浏览器不支持视频标签。`,h,J,T="HunyuanVideo 无 FBCache",b,U,Z=`<source src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/para-attn/hunyuan-video-fbc.mp4" type="video/mp4"/>
  Your browser does not support the video tag.`,M,w,X="HunyuanVideo 与 FBCache",Y,k,v="First Block Cache 将推理速度降低至 2271.06 秒，相比基线快了 1.62 倍，同时保持了几乎为零的质量损失。",z;return o=new Q({props:{code:"aW1wb3J0JTIwdGltZSUwQWltcG9ydCUyMHRvcmNoJTBBZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMEh1bnl1YW5WaWRlb1BpcGVsaW5lJTJDJTIwSHVueXVhblZpZGVvVHJhbnNmb3JtZXIzRE1vZGVsJTBBZnJvbSUyMGRpZmZ1c2Vycy51dGlscyUyMGltcG9ydCUyMGV4cG9ydF90b192aWRlbyUwQSUwQW1vZGVsX2lkJTIwJTNEJTIwJTIydGVuY2VudCUyRkh1bnl1YW5WaWRlbyUyMiUwQXRyYW5zZm9ybWVyJTIwJTNEJTIwSHVueXVhblZpZGVvVHJhbnNmb3JtZXIzRE1vZGVsLmZyb21fcHJldHJhaW5lZCglMEElMjAlMjAlMjAlMjBtb2RlbF9pZCUyQyUwQSUyMCUyMCUyMCUyMHN1YmZvbGRlciUzRCUyMnRyYW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9zdGVwcyUzRDMwJTJDJTBBKS5mcmFtZXMlNUIwJTVEJTBBZW5kJTIwJTNEJTIwdGltZS50aW1lKCklMEFwcmludChmJTIyVGltZSUzQSUyMCU3QmVuZCUyMC0lMjBiZWdpbiUzQS4yZiU3RHMlMjIpJTBBJTBBcHJpbnQoJTIyU2F2aW5nJTIwdmlkZW8lMjB0byUyMGh1bnl1YW5fdmlkZW8ubXA0JTIyKSUwQWV4cG9ydF90b192aWRlbyhvdXRwdXQlMkMlMjAlMjJodW55dWFuX3ZpZGVvLm1wNCUyMiUyQyUyMGZwcyUzRDE1KQ==",highlighted:`<span class="hljs-keyword">import</span> time
<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> HunyuanVideoPipeline, HunyuanVideoTransformer3DModel
<span class="hljs-keyword">from</span> diffusers.utils <span class="hljs-keyword">import</span> export_to_video

model_id = <span class="hljs-string">&quot;tencent/HunyuanVideo&quot;</span>
transformer = HunyuanVideoTransformer3DModel.from_pretrained(
    model_id,
    subfolder=<span class="hljs-string">&quot;transformer&quot;</span>,
    torch_dtype=torch.bfloat16,
    revision=<span class="hljs-string">&quot;refs/pr/18&quot;</span>,
)
pipe = HunyuanVideoPipeline.from_pretrained(
    model_id,
    transformer=transformer,
    torch_dtype=torch.float16,
    revision=<span class="hljs-string">&quot;refs/pr/18&quot;</span>,
).to(<span class="hljs-string">&quot;cuda&quot;</span>)

<span class="hljs-keyword">from</span> para_attn.first_block_cache.diffusers_adapters <span class="hljs-keyword">import</span> apply_cache_on_pipe

apply_cache_on_pipe(pipe, residual_diff_threshold=<span class="hljs-number">0.6</span>)

pipe.vae.enable_tiling()

begin = time.time()
output = pipe(
    prompt=<span class="hljs-string">&quot;A cat walks on the grass, realistic&quot;</span>,
    height=<span class="hljs-number">720</span>,
    width=<span class="hljs-number">1280</span>,
    num_frames=<span class="hljs-number">129</span>,
    num_inference_steps=<span class="hljs-number">30</span>,
).frames[<span class="hljs-number">0</span>]
end = time.time()
<span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Time: <span class="hljs-subst">{end - begin:<span class="hljs-number">.2</span>f}</span>s&quot;</span>)

<span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;Saving video to hunyuan_video.mp4&quot;</span>)
export_to_video(output, <span class="hljs-string">&quot;hunyuan_video.mp4&quot;</span>, fps=<span class="hljs-number">15</span>)`,wrap:!1}}),{c(){t=u("p"),t.innerHTML=m,p=c(),B(o.$$.fragment),s=c(),a=u("video"),a.innerHTML=d,h=c(),J=u("small"),J.textContent=T,b=c(),U=u("video"),U.innerHTML=Z,M=c(),w=u("small"),w.textContent=X,Y=c(),k=u("p"),k.textContent=v,this.h()},l(f){t=y(f,"P",{"data-svelte-h":!0}),j(t)!=="svelte-1enthpa"&&(t.innerHTML=m),p=r(f),_(o.$$.fragment,f),s=r(f),a=y(f,"VIDEO",{"data-svelte-h":!0}),j(a)!=="svelte-7ylzx3"&&(a.innerHTML=d),h=r(f),J=y(f,"SMALL",{"data-svelte-h":!0}),j(J)!=="svelte-1xtgkhf"&&(J.textContent=T),b=r(f),U=y(f,"VIDEO",{"data-svelte-h":!0}),j(U)!=="svelte-1lwel73"&&(U.innerHTML=Z),M=r(f),w=y(f,"SMALL",{"data-svelte-h":!0}),j(w)!=="svelte-1omedp"&&(w.textContent=X),Y=r(f),k=y(f,"P",{"data-svelte-h":!0}),j(k)!=="svelte-b3qx2r"&&(k.textContent=v),this.h()},h(){a.controls="",U.controls=""},m(f,V){n(f,t,V),n(f,p,V),I(o,f,V),n(f,s,V),n(f,a,V),n(f,h,V),n(f,J,V),n(f,b,V),n(f,U,V),n(f,M,V),n(f,w,V),n(f,Y,V),n(f,k,V),z=!0},p:x,i(f){z||(C(o.$$.fragment,f),z=!0)},o(f){G(o.$$.fragment,f),z=!1},d(f){f&&(e(t),e(p),e(s),e(a),e(h),e(J),e(b),e(U),e(M),e(w),e(Y),e(k)),g(o,f)}}}function hs(W){let t,m,p,o;return t=new N({props:{id:"first-block-cache",option:"FLUX-1.dev",$$slots:{default:[Us]},$$scope:{ctx:W}}}),p=new N({props:{id:"first-block-cache",option:"HunyuanVideo",$$slots:{default:[js]},$$scope:{ctx:W}}}),{c(){B(t.$$.fragment),m=c(),B(p.$$.fragment)},l(s){_(t.$$.fragment,s),m=r(s),_(p.$$.fragment,s)},m(s,a){I(t,s,a),n(s,m,a),I(p,s,a),o=!0},p(s,a){const d={};a&2&&(d.$$scope={dirty:a,ctx:s}),t.$set(d);const h={};a&2&&(h.$$scope={dirty:a,ctx:s}),p.$set(h)},i(s){o||(C(t.$$.fragment,s),C(p.$$.fragment,s),o=!0)},o(s){G(t.$$.fragment,s),G(p.$$.fragment,s),o=!1},d(s){s&&e(m),g(t,s),g(p,s)}}}function fs(W){let t,m,p,o="fp8 动态量化和 torch.compile 将推理速度降低至 7.56 秒，相比基线快了 3.48 倍。",s;return t=new Q({props:{code:"aW1wb3J0JTIwdGltZSUwQWltcG9ydCUyMHRvcmNoJTBBZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMEZsdXhQaXBlbGluZSUwQSUwQXBpcGUlMjAlM0QlMjBGbHV4UGlwZWxpbmUuZnJvbV9wcmV0cmFpbmVkKCUwQSUyMCUyMCUyMCUyMCUyMmJsYWNrLWZvcmVzdC1sYWJzJTJGRkxVWC4xLWRldiUyMiUyQyUwQSUyMCUyMCUyMCUyMHRvcmNoX2R0eXBlJTNEdG9yY2guYmZsb2F0MTYlMkMlMEEpLnRvKCUyMmN1ZGElMjIpJTBBJTBBZnJvbSUyMHBhcmFfYXR0bi5maXJzdF9ibG9ja19jYWNoZS5kaWZmdXNlcnNfYWRhcHRlcnMlMjBpbXBvcnQlMjBhcHBseV9jYWNoZV9vbl9waXBlJTBBJTBBYXBwbHlfY2FjaGVfb25fcGlwZSglMEElMjAlMjAlMjAlMjBwaXBlJTJDJTBBJTIwJTIwJTIwJTIwcmVzaWR1YWxfZGlmZl90aHJlc2hvbGQlM0QwL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yMkElMjBjYXQlMjBob2xkaW5nJTIwYSUyMHNpZ24lMjB0aGF0JTIwc2F5cyUyMGhlbGxvJTIwd29ybGQlMjIlMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBudW1faW5mZXJlbmNlX3N0ZXBzJTNEMjglMkMlMEElMjAlMjAlMjAlMjApLmltYWdlcyU1QjAlNUQlMEElMjAlMjAlMjAlMjBlbmQlMjAlM0QlMjB0aW1lLnRpbWUoKSUwQSUyMCUyMCUyMCUyMGlmJTIwaSUyMCUzRCUzRCUyMDAlM0ElMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBwcmludChmJTIyJUU5JUEyJTg0JUU3JTgzJUFEJUU2JTk3JUI2JUU5JTk3JUI0JTNBJTIwJTdCZW5kJTIwLSUyMGJlZ2luJTNBLjJmJTdEcyUyMiklMEElMjAlMjAlMjAlMjBlbHNlJTNBJTBBJTIwJTIwJTIwJTIwJTIwJTIwJTIwJTIwcHJpbnQoZiUyMiVFNiU5NyVCNiVFOSU5NyVCNCUzQSUyMCU3QmVuZCUyMC0lMjBiZWdpbiUzQS4yZiU3RHMlMjIpJTBBJTBBcHJpbnQoJTIyJUU0JUJGJTlEJUU1JUFEJTk4JUU1JTlCJUJFJUU1JTgzJThGJUU1JTg4JUIwJTIwZmx1eC5wbmclMjIpJTBBaW1hZ2Uuc2F2ZSglMjJmbHV4LnBuZyUyMik=",highlighted:`<span class="hljs-keyword">import</span> time
<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> FluxPipeline

pipe = FluxPipeline.from_pretrained(
    <span class="hljs-string">&quot;black-forest-labs/FLUX.1-dev&quot;</span>,
    torch_dtype=torch.bfloat16,
).to(<span class="hljs-string">&quot;cuda&quot;</span>)

<span class="hljs-keyword">from</span> para_attn.first_block_cache.diffusers_adapters <span class="hljs-keyword">import</span> apply_cache_on_pipe

apply_cache_on_pipe(
    pipe,
    residual_diff_threshold=<span class="hljs-number">0.12</span>,  <span class="hljs-comment"># 使用更大的值以使缓存生效</span>
)

<span class="hljs-keyword">from</span> torchao.quantization <span class="hljs-keyword">import</span> quantize_, float8_dynamic_activation_float8_weight, float8_weight_only

quantize_(pipe.text_encoder, float8_weight_only())
quantize_(pipe.transformer, float8_dynamic_activation_float8_weight())
pipe.transformer = torch.<span class="hljs-built_in">compile</span>(
   pipe.transformer, mode=<span class="hljs-string">&quot;max-autotune-no-cudagraphs&quot;</span>,
)

<span class="hljs-comment"># 启用内存节省</span>
<span class="hljs-comment"># pipe.enable_model_cpu_offload()</span>
<span class="hljs-comment"># pipe.enable_sequential_cpu_offload()</span>

<span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">2</span>):
    begin = time.time()
    image = pipe(
        <span class="hljs-string">&quot;A cat holding a sign that says hello world&quot;</span>,
        num_inference_steps=<span class="hljs-number">28</span>,
    ).images[<span class="hljs-number">0</span>]
    end = time.time()
    <span class="hljs-keyword">if</span> i == <span class="hljs-number">0</span>:
        <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;预热时间: <span class="hljs-subst">{end - begin:<span class="hljs-number">.2</span>f}</span>s&quot;</span>)
    <span class="hljs-keyword">else</span>:
        <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;时间: <span class="hljs-subst">{end - begin:<span class="hljs-number">.2</span>f}</span>s&quot;</span>)

<span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;保存图像到 flux.png&quot;</span>)
image.save(<span class="hljs-string">&quot;flux.png&quot;</span>)`,wrap:!1}}),{c(){B(t.$$.fragment),m=c(),p=u("p"),p.textContent=o},l(a){_(t.$$.fragment,a),m=r(a),p=y(a,"P",{"data-svelte-h":!0}),j(p)!=="svelte-vnhv5y"&&(p.textContent=o)},m(a,d){I(t,a,d),n(a,m,d),n(a,p,d),s=!0},p:x,i(a){s||(C(t.$$.fragment,a),s=!0)},o(a){G(t.$$.fragment,a),s=!1},d(a){a&&(e(m),e(p)),g(t,a)}}}function ws(W){let t,m,p,o="NVIDIA L20 GPU 仅有 48GB 内存，在编译后且如果未调用 <code>enable_model_cpu_offload</code> 时，可能会遇到内存不足（OOM）错误，因为 HunyuanVideo 在高分辨率和大量帧数运行时具有非常大的激活张量。对于内存少于 80GB 的 GPU，可以尝试降低分辨率和帧数来避免 OOM 错误。",s,a,d="大型视频生成模型通常受注意力计算而非全连接层的瓶颈限制。这些模型不会从量化和 torch.compile 中显著受益。",h;return t=new Q({props:{code:"aW1wb3J0JTIwdGltZSUwQWltcG9ydCUyMHRvcmNoJTBBZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMEh1bnl1YW5WaWRlb1BpcGVsaW5lJTJDJTIwSHVueXVhblZpZGVvVHJhbnNmb3JtZXIzRE1vZGVsJTBBZnJvbSUyMGRpZmZ1c2Vycy51dGlscyUyMGltcG9ydCUyMGV4cG9ydF90b192aWRlbyUwQSUwQW1vZGVsX2lkJTIwJTNEJTIwJTIydGVuY2VudCUyRkh1bnl1YW5WaWRlbyUyMiUwQXRyYW5zZm9ybWVyJTIwJTNEJTIwSHVueXVhblZpZGVvVHJhbnNmb3JtZXIzRE1vZGVsLmZyb21fcHJldHJhaW5lZCglMEElMjAlMjAlMjAlMjBtb2RlbF9pZCUyQyUwQSUyMCUyMCUyMCUyMHN1YmZvbGRlciUzRCUyMnRyYW5zZm9ybWVyJTIyJTJDJTBBJTIwJTIwJTIwJTIwdG9yY2hfZHR5cGUlM0R0b3JjaC5iZmxvYXQxNiUyQyUwQSUyMCUyMCUyMCUyMHJldmlzaW9uJTNEJTIycmVmcyUyRnByJTJGMTglMjIlMkMlMEEpJTBBcGlwZSUyMCUzRCUyMEh1bnl1YW5WaWRlb1BpcGVsaW5lLmZyb21fcHJldHJhaW5lZCglMEElMjAlMjAlMjAlMjBtb2RlbF9pZCUyQyUwQSUyMCUyMCUyMCUyMHRyYW5zZm9ybWVyJTNEdHJhbnNmb3JtZXIlMkMlMEElM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yMiUyQyUyMGZwcyUzRDE1KQ==",highlighted:`<span class="hljs-keyword">import</span> time
<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> HunyuanVideoPipeline, HunyuanVideoTransformer3DModel
<span class="hljs-keyword">from</span> diffusers.utils <span class="hljs-keyword">import</span> export_to_video

model_id = <span class="hljs-string">&quot;tencent/HunyuanVideo&quot;</span>
transformer = HunyuanVideoTransformer3DModel.from_pretrained(
    model_id,
    subfolder=<span class="hljs-string">&quot;transformer&quot;</span>,
    torch_dtype=torch.bfloat16,
    revision=<span class="hljs-string">&quot;refs/pr/18&quot;</span>,
)
pipe = HunyuanVideoPipeline.from_pretrained(
    model_id,
    transformer=transformer,
    torch_dtype=torch.float16,
    revision=<span class="hljs-string">&quot;refs/pr/18&quot;</span>,
).to(<span class="hljs-string">&quot;cuda&quot;</span>)

<span class="hljs-keyword">from</span> para_attn.first_block_cache.diffusers_adapters <span class="hljs-keyword">import</span> apply_cache_on_pipe

apply_cache_on_pipe(pipe)

<span class="hljs-keyword">from</span> torchao.quantization <span class="hljs-keyword">import</span> quantize_, float8_dynamic_activation_float8_weight, float8_weight_only

quantize_(pipe.text_encoder, float8_weight_only())
quantize_(pipe.transformer, float8_dynamic_activation_float8_weight())
pipe.transformer = torch.<span class="hljs-built_in">compile</span>(
   pipe.transformer, mode=<span class="hljs-string">&quot;max-autotune-no-cudagraphs&quot;</span>,
)

<span class="hljs-comment"># Enable memory savings</span>
pipe.vae.enable_tiling()
<span class="hljs-comment"># pipe.enable_model_cpu_offload()</span>
<span class="hljs-comment"># pipe.enable_sequential_cpu_offload()</span>

<span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">2</span>):
    begin = time.time()
    output = pipe(
        prompt=<span class="hljs-string">&quot;A cat walks on the grass, realistic&quot;</span>,
        height=<span class="hljs-number">720</span>,
        width=<span class="hljs-number">1280</span>,
        num_frames=<span class="hljs-number">129</span>,
        num_inference_steps=<span class="hljs-number">1</span> <span class="hljs-keyword">if</span> i == <span class="hljs-number">0</span> <span class="hljs-keyword">else</span> <span class="hljs-number">30</span>,
    ).frames[<span class="hljs-number">0</span>]
    end = time.time()
    <span class="hljs-keyword">if</span> i == <span class="hljs-number">0</span>:
        <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Warm up time: <span class="hljs-subst">{end - begin:<span class="hljs-number">.2</span>f}</span>s&quot;</span>)
    <span class="hljs-keyword">else</span>:
        <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;Time: <span class="hljs-subst">{end - begin:<span class="hljs-number">.2</span>f}</span>s&quot;</span>)

<span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;Saving video to hunyuan_video.mp4&quot;</span>)
export_to_video(output, <span class="hljs-string">&quot;hunyuan_video.mp4&quot;</span>, fps=<span class="hljs-number">15</span>)`,wrap:!1}}),{c(){B(t.$$.fragment),m=c(),p=u("p"),p.innerHTML=o,s=c(),a=u("p"),a.textContent=d},l(J){_(t.$$.fragment,J),m=r(J),p=y(J,"P",{"data-svelte-h":!0}),j(p)!=="svelte-7u4mbb"&&(p.innerHTML=o),s=r(J),a=y(J,"P",{"data-svelte-h":!0}),j(a)!=="svelte-12a4nr6"&&(a.textContent=d)},m(J,T){I(t,J,T),n(J,m,T),n(J,p,T),n(J,s,T),n(J,a,T),h=!0},p:x,i(J){h||(C(t.$$.fragment,J),h=!0)},o(J){G(t.$$.fragment,J),h=!1},d(J){J&&(e(m),e(p),e(s),e(a)),g(t,J)}}}function Ts(W){let t,m,p,o;return t=new N({props:{id:"fp8-quantization",option:"FLUX-1.dev",$$slots:{default:[fs]},$$scope:{ctx:W}}}),p=new N({props:{id:"fp8-quantization",option:"HunyuanVideo",$$slots:{default:[ws]},$$scope:{ctx:W}}}),{c(){B(t.$$.fragment),m=c(),B(p.$$.fragment)},l(s){_(t.$$.fragment,s),m=r(s),_(p.$$.fragment,s)},m(s,a){I(t,s,a),n(s,m,a),I(p,s,a),o=!0},p(s,a){const d={};a&2&&(d.$$scope={dirty:a,ctx:s}),t.$set(d);const h={};a&2&&(h.$$scope={dirty:a,ctx:s}),p.$set(h)},i(s){o||(C(t.$$.fragment,s),C(p.$$.fragment,s),o=!0)},o(s){G(t.$$.fragment,s),G(p.$$.fragment,s),o=!1},d(s){s&&e(m),g(t,s),g(p,s)}}}function bs(W){let t,m="以下代码示例结合了第一块缓存、fp8动态量化、torch.compile和上下文并行，以实现最快的推理速度。",p,o,s,a,d='保存到<code>run_flux.py</code>并使用<a href="https://pytorch.org/docs/stable/elastic/run.html" rel="nofollow">torchrun</a>启动。',h,J,T,b,U="推理速度降至8.20秒，相比基线快了3.21倍，使用2个NVIDIA L20 GPU。在4个L20上，推理速度为3.90秒，快了6.75倍。",Z;return o=new Q({props:{code:"aW1wb3J0JTIwdGltZSUwQWltcG9ydCUyMHRvcmNoJTBBaW1wb3J0JTIwdG9yY2guZGlzdHJpYnV0ZWQlMjBhcyUyMGRpc3QlMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwRmx1eFBpcGVsaW5lJTBBJTBBZGlzdC5pbml0X3Byb2Nlc3NfZ3JvdXAoKSUwQSUwQXRvcmNoLmN1ZGEuc2V0X2RldmljZShkaXN0LmdldF9yYW5rKCkpJTBBJTBBcGlwZSUyMCUzRCUyMEZsdXhQaXBlbGluZS5mcm9tX3ByZXRyYWluZWQoJTBBJTIwJTIwJTIwJTIwJTIyYmxhY2stZm9yZXN0LWxhYnMlMkZGTFVYLjEtZGV2JTIyJTJDJTBBJTIwJTIwJTIwJTIwdG9yY2hfZHR5cGUlM0R0b3JjaC5iZmxvYXQxNiUyQyUwQSkudG8oJTIyY3VkYSUyMiklMEElMEFmcm9tJTIwcGFyYV9hdHRuLmNvbnRleHRfcGFyYWxsZWwlMjBpbXBvcnQlMjBpbml0X2NvbnRleHRfcGFyYWxsZWxfbWVzaCUwQWZyb20lMjBwYXJhX2F0dG4uY29udGV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keyword">import</span> time
<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">import</span> torch.distributed <span class="hljs-keyword">as</span> dist
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> FluxPipeline

dist.init_process_group()

torch.cuda.set_device(dist.get_rank())

pipe = FluxPipeline.from_pretrained(
    <span class="hljs-string">&quot;black-forest-labs/FLUX.1-dev&quot;</span>,
    torch_dtype=torch.bfloat16,
).to(<span class="hljs-string">&quot;cuda&quot;</span>)

<span class="hljs-keyword">from</span> para_attn.context_parallel <span class="hljs-keyword">import</span> init_context_parallel_mesh
<span class="hljs-keyword">from</span> para_attn.context_parallel.diffusers_adapters <span class="hljs-keyword">import</span> parallelize_pipe
<span class="hljs-keyword">from</span> para_attn.parallel_vae.diffusers_adapters <span class="hljs-keyword">import</span> parallelize_vae

mesh = init_context_parallel_mesh(
    pipe.device.<span class="hljs-built_in">type</span>,
    max_ring_dim_size=<span class="hljs-number">2</span>,
)
parallelize_pipe(
    pipe,
    mesh=mesh,
)
parallelize_vae(pipe.vae, mesh=mesh._flatten())

<span class="hljs-keyword">from</span> para_attn.first_block_cache.diffusers_adapters <span class="hljs-keyword">import</span> apply_cache_on_pipe

apply_cache_on_pipe(
    pipe,
    residual_diff_threshold=<span class="hljs-number">0.12</span>,  <span class="hljs-comment"># 使用较大的值以使缓存生效</span>
)

<span class="hljs-keyword">from</span> torchao.quantization <span class="hljs-keyword">import</span> quantize_, float8_dynamic_activation_float8_weight, float8_weight_only

quantize_(pipe.text_encoder, float8_weight_only())
quantize_(pipe.transformer, float8_dynamic_activation_float8_weight())
torch._inductor.config.reorder_for_compute_comm_overlap = <span class="hljs-literal">True</span>
pipe.transformer = torch.<span class="hljs-built_in">compile</span>(
   pipe.transformer, mode=<span class="hljs-string">&quot;max-autotune-no-cudagraphs&quot;</span>,
)

<span class="hljs-comment"># 启用内存节省</span>
<span class="hljs-comment"># pipe.enable_model_cpu_offload(gpu_id=dist.get_rank())</span>
<span class="hljs-comment"># pipe.enable_sequential_cpu_offload(gpu_id=dist.get_rank())</span>

<span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">2</span>):
    begin = time.time()
    image = pipe(
        <span class="hljs-string">&quot;A cat holding a sign that says hello world&quot;</span>,
        num_inference_steps=<span class="hljs-number">28</span>,
        output_type=<span class="hljs-string">&quot;pil&quot;</span> <span class="hljs-keyword">if</span> dist.get_rank() == <span class="hljs-number">0</span> <span class="hljs-keyword">else</span> <span class="hljs-string">&quot;pt&quot;</span>,
    ).images[<span class="hljs-number">0</span>]
    end = time.time()
    <span class="hljs-keyword">if</span> dist.get_rank() == <span class="hljs-number">0</span>:
        <span class="hljs-keyword">if</span> i == <span class="hljs-number">0</span>:
            <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;预热时间: <span class="hljs-subst">{end - begin:<span class="hljs-number">.2</span>f}</span>s&quot;</span>)
        <span class="hljs-keyword">else</span>:
            <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;时间: <span class="hljs-subst">{end - begin:<span class="hljs-number">.2</span>f}</span>s&quot;</span>)

<span class="hljs-keyword">if</span> dist.get_rank() == <span class="hljs-number">0</span>:
    <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;将图像保存到flux.png&quot;</span>)
    image.save(<span class="hljs-string">&quot;flux.png&quot;</span>)

dist.destroy_process_group()`,wrap:!1}}),J=new Q({props:{code:"JTIzJTIwJUU0JUJEJUJGJUU3JTk0JUE4LS1ucHJvY19wZXJfbm9kZSVFNiU4QyU4NyVFNSVBRSU5QUdQVSVFNiU5NSVCMCVFOSU4NyU4RiUwQXRvcmNocnVuJTIwLS1ucHJvY19wZXJfbm9kZSUzRDIlMjBydW5fZmx1eC5weQ==",highlighted:`<span class="hljs-comment"># 使用--nproc_per_node指定GPU数量</span>
torchrun --nproc_per_node=2 run_flux.py`,wrap:!1}}),{c(){t=u("p"),t.textContent=m,p=c(),B(o.$$.fragment),s=c(),a=u("p"),a.innerHTML=d,h=c(),B(J.$$.fragment),T=c(),b=u("p"),b.textContent=U},l(M){t=y(M,"P",{"data-svelte-h":!0}),j(t)!=="svelte-1wcnxcs"&&(t.textContent=m),p=r(M),_(o.$$.fragment,M),s=r(M),a=y(M,"P",{"data-svelte-h":!0}),j(a)!=="svelte-bdq9oz"&&(a.innerHTML=d),h=r(M),_(J.$$.fragment,M),T=r(M),b=y(M,"P",{"data-svelte-h":!0}),j(b)!=="svelte-19q14lf"&&(b.textContent=U)},m(M,w){n(M,t,w),n(M,p,w),I(o,M,w),n(M,s,w),n(M,a,w),n(M,h,w),I(J,M,w),n(M,T,w),n(M,b,w),Z=!0},p:x,i(M){Z||(C(o.$$.fragment,M),C(J.$$.fragment,M),Z=!0)},o(M){G(o.$$.fragment,M),G(J.$$.fragment,M),Z=!1},d(M){M&&(e(t),e(p),e(s),e(a),e(h),e(T),e(b)),g(o,M),g(J,M)}}}function Zs(W){let t,m="以下代码示例结合了第一块缓存和上下文并行，以实现最快的推理速度。",p,o,s,a,d='保存到 <code>run_hunyuan_video.py</code> 并使用 <a href="https://pytorch.org/docs/stable/elastic/run.html" rel="nofollow">torchrun</a> 启动。',h,J,T,b,U="推理速度降低到 649.23 秒，相比基线快 5.66 倍，使用 8 个 NVIDIA L20 GPU。",Z;return o=new Q({props:{code:" ",highlighted:`<span class="hljs-keyword">import</span> time
<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">import</span> torch.distributed <span class="hljs-keyword">as</span> dist
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> HunyuanVideoPipeline, HunyuanVideoTransformer3DModel
<span class="hljs-keyword">from</span> diffusers.utils <span class="hljs-keyword">import</span> export_to_video

dist.init_process_group()

torch.cuda.set_device(dist.get_rank())

model_id = <span class="hljs-string">&quot;tencent/HunyuanVideo&quot;</span>
transformer = HunyuanVideoTransformer3DModel.from_pretrained(
    model_id,
    subfolder=<span class="hljs-string">&quot;transformer&quot;</span>,
    torch_dtype=torch.bfloat16,
    revision=<span class="hljs-string">&quot;refs/pr/18&quot;</span>,
)
pipe = HunyuanVideoPipeline.from_pretrained(
    model_id,
    transformer=transformer,
    torch_dtype=torch.float16,
    revision=<span class="hljs-string">&quot;refs/pr/18&quot;</span>,
).to(<span class="hljs-string">&quot;cuda&quot;</span>)

<span class="hljs-keyword">from</span> para_attn.context_parallel <span class="hljs-keyword">import</span> init_context_parallel_mesh
<span class="hljs-keyword">from</span> para_attn.context_parallel.diffusers_adapters <span class="hljs-keyword">import</span> parallelize_pipe
<span class="hljs-keyword">from</span> para_attn.parallel_vae.diffusers_adapters <span class="hljs-keyword">import</span> parallelize_vae

mesh = init_context_parallel_mesh(
    pipe.device.<span class="hljs-built_in">type</span>,
)
parallelize_pipe(
    pipe,
    mesh=mesh,
)
parallelize_vae(pipe.vae, mesh=mesh._flatten())

<span class="hljs-keyword">from</span> para_attn.first_block_cache.diffusers_adapters <span class="hljs-keyword">import</span> apply_cache_on_pipe

apply_cache_on_pipe(pipe)

<span class="hljs-comment"># from torchao.quantization import quantize_, float8_dynamic_activation_float8_weight, float8_weight_only</span>
<span class="hljs-comment">#</span>
<span class="hljs-comment"># torch._inductor.config.reorder_for_compute_comm_overlap = True</span>
<span class="hljs-comment">#</span>
<span class="hljs-comment"># quantize_(pipe.text_encoder, float8_weight_only())</span>
<span class="hljs-comment"># quantize_(pipe.transformer, float8_dynamic_activation_float8_weight())</span>
<span class="hljs-comment"># pipe.transformer = torch.compile(</span>
<span class="hljs-comment">#    pipe.transformer, mode=&quot;max-autotune-no-cudagraphs&quot;,</span>
<span class="hljs-comment"># )</span>

<span class="hljs-comment"># 启用内存节省</span>
pipe.vae.enable_tiling()
<span class="hljs-comment"># pipe.enable_model_cpu_offload(gpu_id=dist.get_rank())</span>
<span class="hljs-comment"># pipe.enable_sequential_cpu_offload(gpu_id=dist.get_rank())</span>

<span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">2</span>):
    begin = time.time()
    output = pipe(
        prompt=<span class="hljs-string">&quot;A cat walks on the grass, realistic&quot;</span>,
        height=<span class="hljs-number">720</span>,
        width=<span class="hljs-number">1280</span>,
        num_frames=<span class="hljs-number">129</span>,
        num_inference_steps=<span class="hljs-number">1</span> <span class="hljs-keyword">if</span> i == <span class="hljs-number">0</span> <span class="hljs-keyword">else</span> <span class="hljs-number">30</span>,
        output_type=<span class="hljs-string">&quot;pil&quot;</span> <span class="hljs-keyword">if</span> dist.get_rank() == <span class="hljs-number">0</span> <span class="hljs-keyword">else</span> <span class="hljs-string">&quot;pt&quot;</span>,
    ).frames[<span class="hljs-number">0</span>]
    end = time.time()
    <span class="hljs-keyword">if</span> dist.get_rank() == <span class="hljs-number">0</span>:
        <span class="hljs-keyword">if</span> i == <span class="hljs-number">0</span>:
            <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;预热时间: <span class="hljs-subst">{end - begin:<span class="hljs-number">.2</span>f}</span>s&quot;</span>)
        <span class="hljs-keyword">else</span>:
            <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;时间: <span class="hljs-subst">{end - begin:<span class="hljs-number">.2</span>f}</span>s&quot;</span>)

<span class="hljs-keyword">if</span> dist.get_rank() == <span class="hljs-number">0</span>:
    <span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;保存视频到 hunyuan_video.mp4&quot;</span>)
    export_to_video(output, <span class="hljs-string">&quot;hunyuan_video.mp4&quot;</span>, fps=<span class="hljs-number">15</span>)

dist.destroy_process_group()`,wrap:!1}}),J=new Q({props:{code:"JTIzJTIwJUU0JUJEJUJGJUU3JTk0JUE4JTIwLS1ucHJvY19wZXJfbm9kZSUyMCVFNiU4QyU4NyVFNSVBRSU5QSUyMEdQVSUyMCVFNiU5NSVCMCVFOSU4NyU4RiUwQXRvcmNocnVuJTIwLS1ucHJvY19wZXJfbm9kZSUzRDglMjBydW5faHVueXVhbl92aWRlby5weQ==",highlighted:`<span class="hljs-comment"># 使用 --nproc_per_node 指定 GPU 数量</span>
torchrun --nproc_per_node=8 run_hunyuan_video.py`,wrap:!1}}),{c(){t=u("p"),t.textContent=m,p=c(),B(o.$$.fragment),s=c(),a=u("p"),a.innerHTML=d,h=c(),B(J.$$.fragment),T=c(),b=u("p"),b.textContent=U},l(M){t=y(M,"P",{"data-svelte-h":!0}),j(t)!=="svelte-58tdmv"&&(t.textContent=m),p=r(M),_(o.$$.fragment,M),s=r(M),a=y(M,"P",{"data-svelte-h":!0}),j(a)!=="svelte-pk6cu0"&&(a.innerHTML=d),h=r(M),_(J.$$.fragment,M),T=r(M),b=y(M,"P",{"data-svelte-h":!0}),j(b)!=="svelte-nfook2"&&(b.textContent=U)},m(M,w){n(M,t,w),n(M,p,w),I(o,M,w),n(M,s,w),n(M,a,w),n(M,h,w),I(J,M,w),n(M,T,w),n(M,b,w),Z=!0},p:x,i(M){Z||(C(o.$$.fragment,M),C(J.$$.fragment,M),Z=!0)},o(M){G(o.$$.fragment,M),G(J.$$.fragment,M),Z=!1},d(M){M&&(e(t),e(p),e(s),e(a),e(h),e(T),e(b)),g(o,M),g(J,M)}}}function Bs(W){let t,m,p,o;return t=new N({props:{id:"context-parallelism",option:"FLUX-1.dev",$$slots:{default:[bs]},$$scope:{ctx:W}}}),p=new N({props:{id:"context-parallelism",option:"HunyuanVideo",$$slots:{default:[Zs]},$$scope:{ctx:W}}}),{c(){B(t.$$.fragment),m=c(),B(p.$$.fragment)},l(s){_(t.$$.fragment,s),m=r(s),_(p.$$.fragment,s)},m(s,a){I(t,s,a),n(s,m,a),I(p,s,a),o=!0},p(s,a){const d={};a&2&&(d.$$scope={dirty:a,ctx:s}),t.$set(d);const h={};a&2&&(h.$$scope={dirty:a,ctx:s}),p.$set(h)},i(s){o||(C(t.$$.fragment,s),C(p.$$.fragment,s),o=!0)},o(s){G(t.$$.fragment,s),G(p.$$.fragment,s),o=!1},d(s){s&&e(m),g(t,s),g(p,s)}}}function _s(W){let t,m="<thead><tr><th>GPU 类型</th> <th>GPU 数量</th> <th>优化</th> <th>墙钟时间 (s)</th> <th>加速比</th></tr></thead> <tbody><tr><td>NVIDIA L20</td> <td>1</td> <td>基线</td> <td>26.36</td> <td>1.00x</td></tr> <tr><td>NVIDIA L20</td> <td>1</td> <td>FBCache (rdt=0.08)</td> <td>17.01</td> <td>1.55x</td></tr> <tr><td>NVIDIA L20</td> <td>1</td> <td>FP8 DQ</td> <td>13.40</td> <td>1.96x</td></tr> <tr><td>NVIDIA L20</td> <td>1</td> <td>FBCache (rdt=0.12) + FP8 DQ</td> <td>7.56</td> <td>3.48x</td></tr> <tr><td>NVIDIA L20</td> <td>2</td> <td>FBCache (rdt=0.12) + FP8 DQ + CP</td> <td>4.92</td> <td>5.35x</td></tr> <tr><td>NVIDIA L20</td> <td>4</td> <td>FBCache (rdt=0.12) + FP8 DQ + CP</td> <td>3.90</td> <td>6.75x</td></tr></tbody>";return{c(){t=u("table"),t.innerHTML=m},l(p){t=y(p,"TABLE",{"data-svelte-h":!0}),j(t)!=="svelte-qm3hdc"&&(t.innerHTML=m)},m(p,o){n(p,t,o)},p:x,d(p){p&&e(t)}}}function Is(W){let t,m="<thead><tr><th>GPU 类型</th> <th>GPU 数量</th> <th>优化</th> <th>墙钟时间 (s)</th> <th>加速比</th></tr></thead> <tbody><tr><td>NVIDIA L20</td> <td>1</td> <td>基线</td> <td>3675.71</td> <td>1.00x</td></tr></tbody>",p,o,s=`| NVIDIA
L20 | 1 | FBCache | 2271.06 | 1.62x |
| NVIDIA L20 | 2 | FBCache + CP | 1132.90 | 3.24x |
| NVIDIA L20 | 4 | FBCache + CP | 718.15 | 5.12x |
| NVIDIA L20 | 8 | FBCache + CP | 649.23 | 5.66x |`;return{c(){t=u("table"),t.innerHTML=m,p=c(),o=u("p"),o.textContent=s},l(a){t=y(a,"TABLE",{"data-svelte-h":!0}),j(t)!=="svelte-g64hnd"&&(t.innerHTML=m),p=r(a),o=y(a,"P",{"data-svelte-h":!0}),j(o)!=="svelte-138nu2o"&&(o.textContent=s)},m(a,d){n(a,t,d),n(a,p,d),n(a,o,d)},p:x,d(a){a&&(e(t),e(p),e(o))}}}function Cs(W){let t,m,p,o;return t=new N({props:{id:"conclusion",option:"FLUX-1.dev",$$slots:{default:[_s]},$$scope:{ctx:W}}}),p=new N({props:{id:"conclusion",option:"HunyuanVideo",$$slots:{default:[Is]},$$scope:{ctx:W}}}),{c(){B(t.$$.fragment),m=c(),B(p.$$.fragment)},l(s){_(t.$$.fragment,s),m=r(s),_(p.$$.fragment,s)},m(s,a){I(t,s,a),n(s,m,a),I(p,s,a),o=!0},p(s,a){const d={};a&2&&(d.$$scope={dirty:a,ctx:s}),t.$set(d);const h={};a&2&&(h.$$scope={dirty:a,ctx:s}),p.$set(h)},i(s){o||(C(t.$$.fragment,s),C(p.$$.fragment,s),o=!0)},o(s){G(t.$$.fragment,s),G(p.$$.fragment,s),o=!1},d(s){s&&e(m),g(t,s),g(p,s)}}}function Gs(W){let t,m,p,o,s,a,d,h='<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/para-attn/flux-performance.png"/>',J,T,b='<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/para-attn/hunyuan-video-performance.png"/>',U,Z,M='大型图像和视频生成模型，如 <a href="https://huggingface.co/black-forest-labs/FLUX.1-dev" rel="nofollow">FLUX.1-dev</a> 和 <a href="https://huggingface.co/tencent/HunyuanVideo" rel="nofollow">HunyuanVideo</a>，由于其规模，可能对实时应用和部署构成推理挑战。',w,X,Y='<a href="https://github.com/chengzeyi/ParaAttention" rel="nofollow">ParaAttention</a> 是一个实现了<strong>上下文并行</strong>和<strong>第一块缓存</strong>的库，可以与其他技术（如 torch.compile、fp8 动态量化）结合使用，以加速推理。',k,v,z=`本指南将展示如何在 NVIDIA L20 GPU 上对 FLUX.1-dev 和 HunyuanVideo 应用 ParaAttention。
在我们的基线基准测试中，除了 HunyuanVideo 为避免内存不足错误外，未应用任何优化。`,f,V,Sl="我们的基线基准测试显示，FLUX.1-dev 能够在 28 步中生成 1024x1024 分辨率图像，耗时 26.36 秒；HunyuanVideo 能够在 30 步中生成 129 帧 720p 分辨率视频，耗时 3675.71 秒。",yl,A,Nl="<p>对于更快的上下文并行推理，请尝试使用支持 NVLink 的 NVIDIA A100 或 H100 GPU（如果可用），尤其是在 GPU 数量较多时。</p>",dl,L,Ul,q,xl="缓存模型中 transformer 块的输出并在后续推理步骤中重用它们，可以降低计算成本并加速推理。",jl,D,Yl="然而，很难决定何时重用缓存以确保生成图像或视频的质量。ParaAttention 直接使用<strong>第一个 transformer 块输出的残差差异</strong>来近似模型输出之间的差异。当差异足够小时，重用先前推理步骤的残差差异。换句话说，跳过去噪步骤。",hl,K,zl="这在 FLUX.1-dev 和 HunyuanVideo 推理上实现了 2 倍加速，且质量非常好。",fl,P,Ll='<img src="https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/para-attn/ada-cache.png" alt="Cache in Diffusion Transformer"/> <figcaption>AdaCache 的工作原理，第一块缓存是其变体</figcaption>',wl,$,Tl,O,bl,ll,ql='fp8 动态量化进一步加速推理并减少内存使用。为了使用 8 位 <a href="https://www.nvidia.com/en-us/data-center/tensor-cores/" rel="nofollow">NVIDIA Tensor Cores</a>，必须对激活和权重进行量化。',Zl,sl,Dl="使用 <code>float8_weight_only</code> 和 <code>float8_dynamic_activation_float8_weight</code> 来量化文本编码器和变换器模型。",Bl,tl,Kl="默认量化方法是逐张量量化，但如果您的 GPU 支持逐行量化，您也可以尝试它以获得更好的准确性。",_l,el,Pl='使用以下命令安装 <a href="https://github.com/pytorch/ao/tree/main" rel="nofollow">torchao</a>。',Il,al,Cl,nl,Ol='<a href="https://pytorch.org/tutorials/intermediate/torch_compile_tutorial.html" rel="nofollow">torch.compile</a> 使用 <code>mode=&quot;max-autotune-no-cudagraphs&quot;</code> 或 <code>mode=&quot;max-autotune&quot;</code> 选择最佳内核以获得性能。如果是第一次调用模型，编译可能会花费很长时间，但一旦模型编译完成，这是值得的。',Gl,pl,ls="此示例仅量化变换器模型，但您也可以量化文本编码器以进一步减少内存使用。",gl,E,ss="<p>动态量化可能会显著改变模型输出的分布，因此您需要将 <code>residual_diff_threshold</code> 设置为更大的值以使其生效。</p>",Wl,F,Vl,il,kl,ol,ts="上下文并行性并行化推理并随多个 GPU 扩展。ParaAttention 组合设计允许您将上下文并行性与第一块缓存和动态量化结合使用。",Xl,R,es='<p>请参考 <a href="https://github.com/chengzeyi/ParaAttention/tree/main" rel="nofollow">ParaAttention</a> 仓库获取详细说明和如何使用多个 GPU 扩展推理的示例。</p>',vl,Ml,as='如果推理过程需要持久化和可服务，建议使用 <a href="https://pytorch.org/docs/stable/multiprocessing.html" rel="nofollow">torch.multiprocessing</a> 编写您自己的推理处理器。这可以消除启动进程以及加载和重新编译模型的开销。',Ql,H,Al,cl,$l,S,El,rl,Fl,ml,Rl;return s=new ul({props:{title:"ParaAttention",local:"paraattention",headingTag:"h1"}}),L=new ul({props:{title:"第一块缓存",local:"第一块缓存",headingTag:"h2"}}),$=new Hl({props:{id:"first-block-cache",options:["FLUX-1.dev","HunyuanVideo"],$$slots:{default:[hs]},$$scope:{ctx:W}}}),O=new ul({props:{title:"fp8 量化",local:"fp8-量化",headingTag:"h2"}}),al=new Q({props:{code:"cGlwMyUyMGluc3RhbGwlMjAtVSUyMHRvcmNoJTIwdG9yY2hhbw==",highlighted:"pip3 install -U torch torchao",wrap:!1}}),F=new Hl({props:{id:"fp8-quantization",options:["FLUX-1.dev","HunyuanVideo"],$$slots:{default:[Ts]},$$scope:{ctx:W}}}),il=new ul({props:{title:"上下文并行性",local:"上下文并行性",headingTag:"h2"}}),H=new Hl({props:{id:"context-parallelism",options:["FLUX-1.dev","HunyuanVideo"],$$slots:{default:[Bs]},$$scope:{ctx:W}}}),cl=new ul({props:{title:"基准测试",local:"基准测试",headingTag:"h2"}}),S=new Hl({props:{id:"conclusion",options:["FLUX-1.dev","HunyuanVideo"],$$slots:{default:[Cs]},$$scope:{ctx:W}}}),rl=new ds({props:{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/zh/optimization/para_attn.md"}}),{c(){t=u("meta"),m=c(),p=u("p"),o=c(),B(s.$$.fragment),a=c(),d=u("div"),d.innerHTML=h,J=c(),T=u("div"),T.innerHTML=b,U=c(),Z=u("p"),Z.innerHTML=M,w=c(),X=u("p"),X.innerHTML=Y,k=c(),v=u("p"),v.textContent=z,f=c(),V=u("p"),V.textContent=Sl,yl=c(),A=u("blockquote"),A.innerHTML=Nl,dl=c(),B(L.$$.fragment),Ul=c(),q=u("p"),q.textContent=xl,jl=c(),D=u("p"),D.innerHTML=Yl,hl=c(),K=u("p"),K.textContent=zl,fl=c(),P=u("figure"),P.innerHTML=Ll,wl=c(),B($.$$.fragment),Tl=c(),B(O.$$.fragment),bl=c(),ll=u("p"),ll.innerHTML=ql,Zl=c(),sl=u("p"),sl.innerHTML=Dl,Bl=c(),tl=u("p"),tl.textContent=Kl,_l=c(),el=u("p"),el.innerHTML=Pl,Il=c(),B(al.$$.fragment),Cl=c(),nl=u("p"),nl.innerHTML=Ol,Gl=c(),pl=u("p"),pl.textContent=ls,gl=c(),E=u("blockquote"),E.innerHTML=ss,Wl=c(),B(F.$$.fragment),Vl=c(),B(il.$$.fragment),kl=c(),ol=u("p"),ol.textContent=ts,Xl=c(),R=u("blockquote"),R.innerHTML=es,vl=c(),Ml=u("p"),Ml.innerHTML=as,Ql=c(),B(H.$$.fragment),Al=c(),B(cl.$$.fragment),$l=c(),B(S.$$.fragment),El=c(),B(rl.$$.fragment),Fl=c(),ml=u("p"),this.h()},l(l){const i=us("svelte-u9bgzb",document.head);t=y(i,"META",{name:!0,content:!0}),i.forEach(e),m=r(l),p=y(l,"P",{}),Ms(p).forEach(e),o=r(l),_(s.$$.fragment,l),a=r(l),d=y(l,"DIV",{class:!0,"data-svelte-h":!0}),j(d)!=="svelte-1p4slnk"&&(d.innerHTML=h),J=r(l),T=y(l,"DIV",{class:!0,"data-svelte-h":!0}),j(T)!=="svelte-1kqq4mt"&&(T.innerHTML=b),U=r(l),Z=y(l,"P",{"data-svelte-h":!0}),j(Z)!=="svelte-1aznnck"&&(Z.innerHTML=M),w=r(l),X=y(l,"P",{"data-svelte-h":!0}),j(X)!=="svelte-nxzfeq"&&(X.innerHTML=Y),k=r(l),v=y(l,"P",{"data-svelte-h":!0}),j(v)!=="svelte-ckrkoc"&&(v.textContent=z),f=r(l),V=y(l,"P",{"data-svelte-h":!0}),j(V)!=="svelte-wz0gnx"&&(V.textContent=Sl),yl=r(l),A=y(l,"BLOCKQUOTE",{class:!0,"data-svelte-h":!0}),j(A)!=="svelte-m6tkds"&&(A.innerHTML=Nl),dl=r(l),_(L.$$.fragment,l),Ul=r(l),q=y(l,"P",{"data-svelte-h":!0}),j(q)!=="svelte-17ussag"&&(q.textContent=xl),jl=r(l),D=y(l,"P",{"data-svelte-h":!0}),j(D)!=="svelte-1dduett"&&(D.innerHTML=Yl),hl=r(l),K=y(l,"P",{"data-svelte-h":!0}),j(K)!=="svelte-1y9k7c"&&(K.textContent=zl),fl=r(l),P=y(l,"FIGURE",{"data-svelte-h":!0}),j(P)!=="svelte-1cjjxth"&&(P.innerHTML=Ll),wl=r(l),_($.$$.fragment,l),Tl=r(l),_(O.$$.fragment,l),bl=r(l),ll=y(l,"P",{"data-svelte-h":!0}),j(ll)!=="svelte-iz99fc"&&(ll.innerHTML=ql),Zl=r(l),sl=y(l,"P",{"data-svelte-h":!0}),j(sl)!=="svelte-3fzx9w"&&(sl.innerHTML=Dl),Bl=r(l),tl=y(l,"P",{"data-svelte-h":!0}),j(tl)!=="svelte-f45i0k"&&(tl.textContent=Kl),_l=r(l),el=y(l,"P",{"data-svelte-h":!0}),j(el)!=="svelte-1s76vee"&&(el.innerHTML=Pl),Il=r(l),_(al.$$.fragment,l),Cl=r(l),nl=y(l,"P",{"data-svelte-h":!0}),j(nl)!=="svelte-ubr0pd"&&(nl.innerHTML=Ol),Gl=r(l),pl=y(l,"P",{"data-svelte-h":!0}),j(pl)!=="svelte-1w4d2au"&&(pl.textContent=ls),gl=r(l),E=y(l,"BLOCKQUOTE",{class:!0,"data-svelte-h":!0}),j(E)!=="svelte-5igzue"&&(E.innerHTML=ss),Wl=r(l),_(F.$$.fragment,l),Vl=r(l),_(il.$$.fragment,l),kl=r(l),ol=y(l,"P",{"data-svelte-h":!0}),j(ol)!=="svelte-125hian"&&(ol.textContent=ts),Xl=r(l),R=y(l,"BLOCKQUOTE",{class:!0,"data-svelte-h":!0}),j(R)!=="svelte-zcqlrq"&&(R.innerHTML=es),vl=r(l),Ml=y(l,"P",{"data-svelte-h":!0}),j(Ml)!=="svelte-gwlw48"&&(Ml.innerHTML=as),Ql=r(l),_(H.$$.fragment,l),Al=r(l),_(cl.$$.fragment,l),$l=r(l),_(S.$$.fragment,l),El=r(l),_(rl.$$.fragment,l),Fl=r(l),ml=y(l,"P",{}),Ms(ml).forEach(e),this.h()},h(){Jl(t,"name","hf:doc:metadata"),Jl(t,"content",gs),Jl(d,"class","flex justify-center"),Jl(T,"class","flex justify-center"),Jl(A,"class","tip"),Jl(E,"class","tip"),Jl(R,"class","tip")},m(l,i){ys(document.head,t),n(l,m,i),n(l,p,i),n(l,o,i),I(s,l,i),n(l,a,i),n(l,d,i),n(l,J,i),n(l,T,i),n(l,U,i),n(l,Z,i),n(l,w,i),n(l,X,i),n(l,k,i),n(l,v,i),n(l,f,i),n(l,V,i),n(l,yl,i),n(l,A,i),n(l,dl,i),I(L,l,i),n(l,Ul,i),n(l,q,i),n(l,jl,i),n(l,D,i),n(l,hl,i),n(l,K,i),n(l,fl,i),n(l,P,i),n(l,wl,i),I($,l,i),n(l,Tl,i),I(O,l,i),n(l,bl,i),n(l,ll,i),n(l,Zl,i),n(l,sl,i),n(l,Bl,i),n(l,tl,i),n(l,_l,i),n(l,el,i),n(l,Il,i),I(al,l,i),n(l,Cl,i),n(l,nl,i),n(l,Gl,i),n(l,pl,i),n(l,gl,i),n(l,E,i),n(l,Wl,i),I(F,l,i),n(l,Vl,i),I(il,l,i),n(l,kl,i),n(l,ol,i),n(l,Xl,i),n(l,R,i),n(l,vl,i),n(l,Ml,i),n(l,Ql,i),I(H,l,i),n(l,Al,i),I(cl,l,i),n(l,$l,i),I(S,l,i),n(l,El,i),I(rl,l,i),n(l,Fl,i),n(l,ml,i),Rl=!0},p(l,[i]){const ns={};i&2&&(ns.$$scope={dirty:i,ctx:l}),$.$set(ns);const ps={};i&2&&(ps.$$scope={dirty:i,ctx:l}),F.$set(ps);const is={};i&2&&(is.$$scope={dirty:i,ctx:l}),H.$set(is);const os={};i&2&&(os.$$scope={dirty:i,ctx:l}),S.$set(os)},i(l){Rl||(C(s.$$.fragment,l),C(L.$$.fragment,l),C($.$$.fragment,l),C(O.$$.fragment,l),C(al.$$.fragment,l),C(F.$$.fragment,l),C(il.$$.fragment,l),C(H.$$.fragment,l),C(cl.$$.fragment,l),C(S.$$.fragment,l),C(rl.$$.fragment,l),Rl=!0)},o(l){G(s.$$.fragment,l),G(L.$$.fragment,l),G($.$$.fragment,l),G(O.$$.fragment,l),G(al.$$.fragment,l),G(F.$$.fragment,l),G(il.$$.fragment,l),G(H.$$.fragment,l),G(cl.$$.fragment,l),G(S.$$.fragment,l),G(rl.$$.fragment,l),Rl=!1},d(l){l&&(e(m),e(p),e(o),e(a),e(d),e(J),e(T),e(U),e(Z),e(w),e(X),e(k),e(v),e(f),e(V),e(yl),e(A),e(dl),e(Ul),e(q),e(jl),e(D),e(hl),e(K),e(fl),e(P),e(wl),e(Tl),e(bl),e(ll),e(Zl),e(sl),e(Bl),e(tl),e(_l),e(el),e(Il),e(Cl),e(nl),e(Gl),e(pl),e(gl),e(E),e(Wl),e(Vl),e(kl),e(ol),e(Xl),e(R),e(vl),e(Ml),e(Ql),e(Al),e($l),e(El),e(Fl),e(ml)),e(t),g(s,l),g(L,l),g($,l),g(O,l),g(al,l),g(F,l),g(il,l),g(H,l),g(cl,l),g(S,l),g(rl,l)}}}const gs='{"title":"ParaAttention","local":"paraattention","sections":[{"title":"第一块缓存","local":"第一块缓存","sections":[],"depth":2},{"title":"fp8 量化","local":"fp8-量化","sections":[],"depth":2},{"title":"上下文并行性","local":"上下文并行性","sections":[],"depth":2},{"title":"基准测试","local":"基准测试","sections":[],"depth":2}],"depth":1}';function Ws(W){return rs(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class As extends Js{constructor(t){super(),ms(this,t,Ws,Gs,cs,{})}}export{As as component};
