import{s as Ut,o as Zt,n as ue}from"../chunks/scheduler.8c3d61f6.js";import{S as Gt,i as _t,g as c,s as o,r as y,A as Wt,h as f,f as l,c as p,j as gt,u as w,x as h,k as jt,y as vt,a as n,v as M,d as $,t as T,w as J}from"../chunks/index.da70eac4.js";import{T as Oe}from"../chunks/Tip.1d9b8c37.js";import{C as W}from"../chunks/CodeBlock.a9c4becf.js";import{H as C,E as xt}from"../chunks/index.ef90fe87.js";import{H as Xt,a as et}from"../chunks/HfOption.6ab18950.js";function kt(j){let a,u="bfloat16 is similar to float16 but it is more robust to numerical errors. Hardware support for bfloat16 varies, but most modern GPUs are capable of supporting bfloat16.",s,m,d;return m=new W({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwU3RhYmxlRGlmZnVzaW9uWExQaXBlbGluZSUwQSUwQXBpcGVsaW5lJTIwJTNEJTIwU3RhYmxlRGlmZnVzaW9uWExQaXBlbGluZS5mcm9tX3ByZXRyYWluZWQoJTBBJTIwJTIwJTIwJTIwJTIyc3RhYmlsaXR5YWklMkZzdGFibGUtZGlmZnVzaW9uLXhsLWJhc2UtMS4wJTIyJTJDJTIwdG9yY2hfZHR5cGUlM0R0b3JjaC5iZmxvYXQxNiUwQSkudG8oJTIyY3VkYSUyMiklMEElMEFwcm9tcHQlMjAlM0QlMjAlMjJBc3Ryb25hdXQlMjBpbiUyMGElMjBqdW5nbGUlMkMlMjBjb2xkJTIwY29sb3IlMjBwYWxldHRlJTJDJTIwbXV0ZWQlMjBjb2xvcnMlMkMlMjBkZXRhaWxlZCUyQyUyMDhrJTIyJTBBcGlwZWxpbmUocHJvbXB0JTJDJTIwbnVtX2luZmVyZW5jZV9zdGVwcyUzRDMwKS5pbWFnZXMlNUIwJTVE",highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> StableDiffusionXLPipeline

pipeline = StableDiffusionXLPipeline.from_pretrained(
    <span class="hljs-string">&quot;stabilityai/stable-diffusion-xl-base-1.0&quot;</span>, torch_dtype=torch.bfloat16
).to(<span class="hljs-string">&quot;cuda&quot;</span>)

prompt = <span class="hljs-string">&quot;Astronaut in a jungle, cold color palette, muted colors, detailed, 8k&quot;</span>
pipeline(prompt, num_inference_steps=<span class="hljs-number">30</span>).images[<span class="hljs-number">0</span>]`,wrap:!1}}),{c(){a=c("p"),a.textContent=u,s=o(),y(m.$$.fragment)},l(r){a=f(r,"P",{"data-svelte-h":!0}),h(a)!=="svelte-kz0em0"&&(a.textContent=u),s=p(r),w(m.$$.fragment,r)},m(r,i){n(r,a,i),n(r,s,i),M(m,r,i),d=!0},p:ue,i(r){d||($(m.$$.fragment,r),d=!0)},o(r){T(m.$$.fragment,r),d=!1},d(r){r&&(l(a),l(s)),J(m,r)}}}function Bt(j){let a,u="float16 is similar to bfloat16 but may be more prone to numerical errors.",s,m,d;return m=new W({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwU3RhYmxlRGlmZnVzaW9uWExQaXBlbGluZSUwQSUwQXBpcGVsaW5lJTIwJTNEJTIwU3RhYmxlRGlmZnVzaW9uWExQaXBlbGluZS5mcm9tX3ByZXRyYWluZWQoJTBBJTIwJTIwJTIwJTIwJTIyc3RhYmlsaXR5YWklMkZzdGFibGUtZGlmZnVzaW9uLXhsLWJhc2UtMS4wJTIyJTJDJTIwdG9yY2hfZHR5cGUlM0R0b3JjaC5mbG9hdDE2JTBBKS50byglMjJjdWRhJTIyKSUwQSUwQXByb21wdCUyMCUzRCUyMCUyMkFzdHJvbmF1dCUyMGluJTIwYSUyMGp1bmdsZSUyQyUyMGNvbGQlMjBjb2xvciUyMHBhbGV0dGUlMkMlMjBtdXRlZCUyMGNvbG9ycyUyQyUyMGRldGFpbGVkJTJDJTIwOGslMjIlMEFwaXBlbGluZShwcm9tcHQlMkMlMjBudW1faW5mZXJlbmNlX3N0ZXBzJTNEMzApLmltYWdlcyU1QjAlNUQ=",highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> StableDiffusionXLPipeline

pipeline = StableDiffusionXLPipeline.from_pretrained(
    <span class="hljs-string">&quot;stabilityai/stable-diffusion-xl-base-1.0&quot;</span>, torch_dtype=torch.float16
).to(<span class="hljs-string">&quot;cuda&quot;</span>)

prompt = <span class="hljs-string">&quot;Astronaut in a jungle, cold color palette, muted colors, detailed, 8k&quot;</span>
pipeline(prompt, num_inference_steps=<span class="hljs-number">30</span>).images[<span class="hljs-number">0</span>]`,wrap:!1}}),{c(){a=c("p"),a.textContent=u,s=o(),y(m.$$.fragment)},l(r){a=f(r,"P",{"data-svelte-h":!0}),h(a)!=="svelte-nzm7ns"&&(a.textContent=u),s=p(r),w(m.$$.fragment,r)},m(r,i){n(r,a,i),n(r,s,i),M(m,r,i),d=!0},p:ue,i(r){d||($(m.$$.fragment,r),d=!0)},o(r){T(m.$$.fragment,r),d=!1},d(r){r&&(l(a),l(s)),J(m,r)}}}function Ct(j){let a,u='<a href="https://blogs.nvidia.com/blog/2020/05/14/tensorfloat-32-precision-format/" rel="nofollow">TensorFloat-32 (tf32)</a> mode is supported on NVIDIA Ampere GPUs and it computes the convolution and matrix multiplication operations in tf32. Storage and other operations are kept in float32. This enables significantly faster computations when combined with bfloat16 or float16.',s,m,d="PyTorch only enables tf32 mode for convolutions by default and you’ll need to explicitly enable it for matrix multiplications.",r,i,g,U,G='Refer to the <a href="https://huggingface.co/docs/transformers/en/perf_train_gpu_one#mixed-precision" rel="nofollow">mixed precision training</a> docs for more details.',_;return i=new W({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwU3RhYmxlRGlmZnVzaW9uWExQaXBlbGluZSUwQSUwQXRvcmNoLmJhY2tlbmRzLmN1ZGEubWF0bXVsLmFsbG93X3RmMzIlMjAlM0QlMjBUcnVlJTBBJTBBcGlwZWxpbmUlMjAlM0QlMjBTdGFibGVEaWZmdXNpb25YTFBpcGVsaW5lLmZyb21fcHJldHJhaW5lZCglMEElMjAlMjAlMjAlMjAlMjJzdGFiaWxpdHlhaSUyRnN0YWJsZS1kaWZmdXNpb24teGwtYmFzZS0xLjAlMjIlMkMlMjB0b3JjaF9kdHlwZSUzRHRvcmNoLmJmbG9hdDE2JTBBKS50byglMjJjdWRhJTIyKSUwQSUwQXByb21wdCUyMCUzRCUyMCUyMkFzdHJvbmF1dCUyMGluJTIwYSUyMGp1bmdsZSUyQyUyMGNvbGQlMjBjb2xvciUyMHBhbGV0dGUlMkMlMjBtdXRlZCUyMGNvbG9ycyUyQyUyMGRldGFpbGVkJTJDJTIwOGslMjIlMEFwaXBlbGluZShwcm9tcHQlMkMlMjBudW1faW5mZXJlbmNlX3N0ZXBzJTNEMzApLmltYWdlcyU1QjAlNUQ=",highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> StableDiffusionXLPipeline

torch.backends.cuda.matmul.allow_tf32 = <span class="hljs-literal">True</span>

pipeline = StableDiffusionXLPipeline.from_pretrained(
    <span class="hljs-string">&quot;stabilityai/stable-diffusion-xl-base-1.0&quot;</span>, torch_dtype=torch.bfloat16
).to(<span class="hljs-string">&quot;cuda&quot;</span>)

prompt = <span class="hljs-string">&quot;Astronaut in a jungle, cold color palette, muted colors, detailed, 8k&quot;</span>
pipeline(prompt, num_inference_steps=<span class="hljs-number">30</span>).images[<span class="hljs-number">0</span>]`,wrap:!1}}),{c(){a=c("p"),a.innerHTML=u,s=o(),m=c("p"),m.textContent=d,r=o(),y(i.$$.fragment),g=o(),U=c("p"),U.innerHTML=G},l(b){a=f(b,"P",{"data-svelte-h":!0}),h(a)!=="svelte-1sdg1x4"&&(a.innerHTML=u),s=p(b),m=f(b,"P",{"data-svelte-h":!0}),h(m)!=="svelte-13cgegp"&&(m.textContent=d),r=p(b),w(i.$$.fragment,b),g=p(b),U=f(b,"P",{"data-svelte-h":!0}),h(U)!=="svelte-uy7wpj"&&(U.innerHTML=G)},m(b,Z){n(b,a,Z),n(b,s,Z),n(b,m,Z),n(b,r,Z),M(i,b,Z),n(b,g,Z),n(b,U,Z),_=!0},p:ue,i(b){_||($(i.$$.fragment,b),_=!0)},o(b){T(i.$$.fragment,b),_=!1},d(b){b&&(l(a),l(s),l(m),l(r),l(g),l(U)),J(i,b)}}}function Rt(j){let a,u,s,m,d,r;return a=new et({props:{id:"dtypes",option:"bfloat16",$$slots:{default:[kt]},$$scope:{ctx:j}}}),s=new et({props:{id:"dtypes",option:"float16",$$slots:{default:[Bt]},$$scope:{ctx:j}}}),d=new et({props:{id:"dtypes",option:"TensorFloat-32",$$slots:{default:[Ct]},$$scope:{ctx:j}}}),{c(){y(a.$$.fragment),u=o(),y(s.$$.fragment),m=o(),y(d.$$.fragment)},l(i){w(a.$$.fragment,i),u=p(i),w(s.$$.fragment,i),m=p(i),w(d.$$.fragment,i)},m(i,g){M(a,i,g),n(i,u,g),M(s,i,g),n(i,m,g),M(d,i,g),r=!0},p(i,g){const U={};g&2&&(U.$$scope={dirty:g,ctx:i}),a.$set(U);const G={};g&2&&(G.$$scope={dirty:g,ctx:i}),s.$set(G);const _={};g&2&&(_.$$scope={dirty:g,ctx:i}),d.$set(_)},i(i){r||($(a.$$.fragment,i),$(s.$$.fragment,i),$(d.$$.fragment,i),r=!0)},o(i){T(a.$$.fragment,i),T(s.$$.fragment,i),T(d.$$.fragment,i),r=!1},d(i){i&&(l(u),l(m)),J(a,i),J(s,i),J(d,i)}}}function It(j){let a,u='Memory-efficient attention optimizes for inference speed <em>and</em> <a href="./memory#memory-efficient-attention">memory usage</a>!';return{c(){a=c("p"),a.innerHTML=u},l(s){a=f(s,"P",{"data-svelte-h":!0}),h(a)!=="svelte-nfsjqr"&&(a.innerHTML=u)},m(s,m){n(s,a,m)},p:ue,d(s){s&&l(a)}}}function Vt(j){let a,u='With PyTorch 2.3.1, you can control the caching behavior of torch.compile. This is particularly beneficial for compilation modes like <code>&quot;max-autotune&quot;</code> which performs a grid-search over several compilation flags to find the optimal configuration. Learn more in the <a href="https://pytorch.org/tutorials/recipes/torch_compile_caching_tutorial.html" rel="nofollow">Compile Time Caching in torch.compile</a> tutorial.';return{c(){a=c("p"),a.innerHTML=u},l(s){a=f(s,"P",{"data-svelte-h":!0}),h(a)!=="svelte-1a730av"&&(a.innerHTML=u)},m(s,m){n(s,a,m)},p:ue,d(s){s&&l(a)}}}function Nt(j){let a,u='Refer to our <a href="../quantization/torchao">torchao</a> docs to learn more about how to use the Diffusers torchao integration.';return{c(){a=c("p"),a.innerHTML=u},l(s){a=f(s,"P",{"data-svelte-h":!0}),h(a)!=="svelte-1h2qhs5"&&(a.innerHTML=u)},m(s,m){n(s,a,m)},p:ue,d(s){s&&l(a)}}}function Ht(j){let a,u='The <a href="https://github.com/huggingface/diffusers/blob/58431f102cf39c3c8a569f32d71b2ea8caa461e1/src/diffusers/pipelines/pipeline_utils.py#L2034" rel="nofollow">fuse_qkv_projections</a> method is experimental and support is limited to mostly Stable Diffusion pipelines. Take a look at this <a href="https://github.com/huggingface/diffusers/pull/6179" rel="nofollow">PR</a> to learn more about how to enable it for other pipelines';return{c(){a=c("p"),a.innerHTML=u},l(s){a=f(s,"P",{"data-svelte-h":!0}),h(a)!=="svelte-o2jj7j"&&(a.innerHTML=u)},m(s,m){n(s,a,m)},p:ue,d(s){s&&l(a)}}}function Lt(j){let a,u,s,m,d,r,i,g='Diffusion models are slow at inference because generation is an iterative process where noise is gradually refined into an image or video over a certain number of “steps”. To speedup this process, you can try experimenting with different <a href="../api/schedulers/overview">schedulers</a>, reduce the precision of the model weights for faster computations, use more memory-efficient attention mechanisms, and more.',U,G,_="Combine and use these techniques together to make inference faster than using any single technique on its own.",b,Z,tt="This guide will go over how to accelerate inference.",he,R,be,I,lt="The precision and data type of the model weights affect inference speed because a higher precision requires more memory to load and more time to perform the computations. PyTorch loads model weights in float32 or full precision by default, so changing the data type is a simple way to quickly get faster inference.",ye,v,we,V,Me,x,$e,N,nt='<a href="https://pytorch.org/docs/stable/generated/torch.nn.functional.scaled_dot_product_attention.html" rel="nofollow">Scaled dot product attention (SDPA)</a> implements several attention backends, <a href="https://github.com/Dao-AILab/flash-attention" rel="nofollow">FlashAttention</a>, <a href="https://github.com/facebookresearch/xformers" rel="nofollow">xFormers</a>, and a native C++ implementation. It automatically selects the most optimal backend for your hardware.',Te,H,at='SDPA is enabled by default if you’re using PyTorch &gt;= 2.0 and no additional changes are required to your code. You could try experimenting with other attention backends though if you’d like to choose your own. The example below uses the <a href="https://pytorch.org/docs/stable/generated/torch.nn.attention.sdpa_kernel.html" rel="nofollow">torch.nn.attention.sdpa_kernel</a> context manager to enable efficient attention.',Je,L,ge,z,je,Y,st='<a href="https://pytorch.org/tutorials/intermediate/torch_compile_tutorial.html" rel="nofollow">torch.compile</a> accelerates inference by compiling PyTorch code and operations into optimized kernels. Diffusers typically compiles the more compute-intensive models like the UNet, transformer, or VAE.',Ue,E,it='Enable the following compiler settings for maximum speed (refer to the <a href="https://github.com/pytorch/pytorch/blob/main/torch/_inductor/config.py" rel="nofollow">full list</a> for more options).',Ze,Q,Ge,F,ot="Load and compile the UNet and VAE. There are several different modes you can choose from, but <code>&quot;max-autotune&quot;</code> optimizes for the fastest speed by compiling to a CUDA graph. CUDA graphs effectively reduces the overhead by launching multiple GPU operations through a single CPU operation.",_e,X,We,S,pt='Changing the memory layout to <a href="./memory#torchchannels_last">channels_last</a> also optimizes memory and inference speed.',ve,q,xe,A,rt="Compilation is slow the first time, but once compiled, it is significantly faster. Try to only use the compiled pipeline on the same type of inference operations. Calling the compiled pipeline on a different image size retriggers compilation which is slow and inefficient.",Xe,P,ke,D,mt="It is important to specify <code>fullgraph=True</code> in torch.compile to ensure there are no graph breaks in the underlying model. This allows you to take advantage of torch.compile without any performance degradation. For the UNet and VAE, this changes how you access the return variables.",Be,K,Ce,O,Re,ee,ct='The <code>step()</code> function is <a href="https://github.com/huggingface/diffusers/blob/1d686bac8146037e97f3fd8c56e4063230f71751/src/diffusers/pipelines/stable_diffusion_xl/pipeline_stable_diffusion_xl.py#L1228" rel="nofollow">called</a> on the scheduler each time after the denoiser makes a prediction, and the <code>sigmas</code> variable is <a href="https://github.com/huggingface/diffusers/blob/1d686bac8146037e97f3fd8c56e4063230f71751/src/diffusers/schedulers/scheduling_euler_discrete.py#L476" rel="nofollow">indexed</a>. When placed on the GPU, it introduces latency because of the communication sync between the CPU and GPU. It becomes more evident when the denoiser has already been compiled.',Ie,te,ft='In general, the <code>sigmas</code> should <a href="https://github.com/huggingface/diffusers/blob/35a969d297cba69110d175ee79c59312b9f49e1e/src/diffusers/schedulers/scheduling_euler_discrete.py#L240" rel="nofollow">stay on the CPU</a> to avoid the communication sync and latency.',Ve,le,Ne,ne,ut='<a href="https://pytorch.org/tutorials/recipes/recipes/dynamic_quantization.html" rel="nofollow">Dynamic quantization</a> improves inference speed by reducing precision to enable faster math operations. This particular type of quantization determines how to scale the activations based on the data at runtime rather than using a fixed scaling factor. As a result, the scaling factor is more accurately aligned with the data.',He,ae,dt='The example below applies <a href="https://pytorch.org/tutorials/recipes/recipes/dynamic_quantization.html" rel="nofollow">dynamic int8 quantization</a> to the UNet and VAE with the <a href="../quantization/torchao">torchao</a> library.',Le,k,ze,se,ht="Configure the compiler tags for maximum speed.",Ye,ie,Ee,oe,bt='Filter out some linear layers in the UNet and VAE which don’t benefit from dynamic quantization with the <a href="https://github.com/huggingface/diffusion-fast/blob/0f169640b1db106fe6a479f78c1ed3bfaeba3386/utils/pipeline_utils.py#L16" rel="nofollow">dynamic_quant_filter_fn</a>.',Qe,pe,Fe,re,Se,B,qe,me,yt="An input is projected into three subspaces, represented by the projection matrices Q, K, and V, in an attention block. These projections are typically calculated separately, but you can horizontally combine these into a single matrix and perform the projection in a single step. It increases the size of the matrix multiplications of the input projections and also improves the impact of quantization.",Ae,ce,Pe,fe,De,de,Ke;return d=new C({props:{title:"Accelerate inference",local:"accelerate-inference",headingTag:"h1"}}),R=new C({props:{title:"Model data type",local:"model-data-type",headingTag:"h2"}}),v=new Xt({props:{id:"dtypes",options:["bfloat16","float16","TensorFloat-32"],$$slots:{default:[Rt]},$$scope:{ctx:j}}}),V=new C({props:{title:"Scaled dot product attention",local:"scaled-dot-product-attention",headingTag:"h2"}}),x=new Oe({props:{warning:!1,$$slots:{default:[It]},$$scope:{ctx:j}}}),L=new W({props:{code:"ZnJvbSUyMHRvcmNoLm5uLmF0dGVudGlvbiUyMGltcG9ydCUyMFNEUEJhY2tlbmQlMkMlMjBzZHBhX2tlcm5lbCUwQWltcG9ydCUyMHRvcmNoJTBBZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMFN0YWJsZURpZmZ1c2lvblhMUGlwZWxpbmUlMEElMEFwaXBlbGluZSUyMCUzRCUyMFN0YWJsZURpZmZ1c2lvblhMUGlwZWxpbmUuZnJvbV9wcmV0cmFpbmVkKCUwQSUyMCUyMCUyMCUyMCUyMnN0YWJpbGl0eWFpJTJGc3RhYmxlLWRpZmZ1c2lvbi14bC1iYXNlLTEuMCUyMiUyQyUyMHRvcmNoX2R0eXBlJTNEdG9yY2guYmZsb2F0MTYlMEEpLnRvKCUyMmN1ZGElMjIpJTBBJTBBcHJvbXB0JTIwJTNEJTIwJTIyQXN0cm9uYXV0JTIwaW4lMjBhJTIwanVuZ2xlJTJDJTIwY29sZCUyMGNvbG9yJTIwcGFsZXR0ZSUyQyUyMG11dGVkJTIwY29sb3JzJTJDJTIwZGV0YWlsZWQlMkMlMjA4ayUyMiUwQSUwQXdpdGglMjBzZHBhX2tlcm5lbChTRFBCYWNrZW5kLkVGRklDSUVOVF9BVFRFTlRJT04pJTNBJTBBJTIwJTIwaW1hZ2UlMjAlM0QlMjBwaXBlbGluZShwcm9tcHQlMkMlMjBudW1faW5mZXJlbmNlX3N0ZXBzJTNEMzApLmltYWdlcyU1QjAlNUQ=",highlighted:`<span class="hljs-keyword">from</span> torch.nn.attention <span class="hljs-keyword">import</span> SDPBackend, sdpa_kernel
<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> StableDiffusionXLPipeline

pipeline = StableDiffusionXLPipeline.from_pretrained(
    <span class="hljs-string">&quot;stabilityai/stable-diffusion-xl-base-1.0&quot;</span>, torch_dtype=torch.bfloat16
).to(<span class="hljs-string">&quot;cuda&quot;</span>)

prompt = <span class="hljs-string">&quot;Astronaut in a jungle, cold color palette, muted colors, detailed, 8k&quot;</span>

<span class="hljs-keyword">with</span> sdpa_kernel(SDPBackend.EFFICIENT_ATTENTION):
  image = pipeline(prompt, num_inference_steps=<span class="hljs-number">30</span>).images[<span class="hljs-number">0</span>]`,wrap:!1}}),z=new C({props:{title:"torch.compile",local:"torchcompile",headingTag:"h2"}}),Q=new W({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwU3RhYmxlRGlmZnVzaW9uWExQaXBlbGluZSUwQSUwQXRvcmNoLl9pbmR1Y3Rvci5jb25maWcuY29udl8xeDFfYXNfbW0lMjAlM0QlMjBUcnVlJTBBdG9yY2guX2luZHVjdG9yLmNvbmZpZy5jb29yZGluYXRlX2Rlc2NlbnRfdHVuaW5nJTIwJTNEJTIwVHJ1ZSUwQXRvcmNoLl9pbmR1Y3Rvci5jb25maWcuZXBpbG9ndWVfZnVzaW9uJTIwJTNEJTIwRmFsc2UlMEF0b3JjaC5faW5kdWN0b3IuY29uZmlnLmNvb3JkaW5hdGVfZGVzY2VudF9jaGVja19hbGxfZGlyZWN0aW9ucyUyMCUzRCUyMFRydWU=",highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> StableDiffusionXLPipeline

torch._inductor.config.conv_1x1_as_mm = <span class="hljs-literal">True</span>
torch._inductor.config.coordinate_descent_tuning = <span class="hljs-literal">True</span>
torch._inductor.config.epilogue_fusion = <span class="hljs-literal">False</span>
torch._inductor.config.coordinate_descent_check_all_directions = <span class="hljs-literal">True</span>`,wrap:!1}}),X=new Oe({props:{warning:!1,$$slots:{default:[Vt]},$$scope:{ctx:j}}}),q=new W({props:{code:"cGlwZWxpbmUlMjAlM0QlMjBTdGFibGVEaWZmdXNpb25YTFBpcGVsaW5lLmZyb21fcHJldHJhaW5lZCglMEElMjAlMjAlMjAlMjAlMjJzdGFiaWxpdHlhaSUyRnN0YWJsZS1kaWZmdXNpb24teGwtYmFzZS0xLjAlMjIlMkMlMjB0b3JjaF9kdHlwZSUzRHRvcmNoLmZsb2F0MTYlMEEpLnRvKCUyMmN1ZGElMjIpJTBBcGlwZWxpbmUudW5ldC50byhtZW1vcnlfZm9ybWF0JTNEdG9yY2guY2hhbm5lbHNfbGFzdCklMEFwaXBlbGluZS52YWUudG8obWVtb3J5X2Zvcm1hdCUzRHRvcmNoLmNoYW5uZWxzX2xhc3QpJTBBcGlwZWxpbmUudW5ldCUyMCUzRCUyMHRvcmNoLmNvbXBpbGUoJTBBJTIwJTIwJTIwJTIwcGlwZWxpbmUudW5ldCUyQyUyMG1vZGUlM0QlMjJtYXgtYXV0b3R1bmUlMjIlMkMlMjBmdWxsZ3JhcGglM0RUcnVlJTBBKSUwQXBpcGVsaW5lLnZhZS5kZWNvZGUlMjAlM0QlMjB0b3JjaC5jb21waWxlKCUwQSUyMCUyMCUyMCUyMHBpcGVsaW5lLnZhZS5kZWNvZGUlMkMlMEElMjAlMjAlMjAlMjBtb2RlJTNEJTIybWF4LWF1dG90dW5lJTIyJTJDJTBBJTIwJTIwJTIwJTIwZnVsbGdyYXBoJTNEVHJ1ZSUwQSklMEElMEFwcm9tcHQlMjAlM0QlMjAlMjJBc3Ryb25hdXQlMjBpbiUyMGElMjBqdW5nbGUlMkMlMjBjb2xkJTIwY29sb3IlMjBwYWxldHRlJTJDJTIwbXV0ZWQlMjBjb2xvcnMlMkMlMjBkZXRhaWxlZCUyQyUyMDhrJTIyJTBBcGlwZWxpbmUocHJvbXB0JTJDJTIwbnVtX2luZmVyZW5jZV9zdGVwcyUzRDMwKS5pbWFnZXMlNUIwJTVE",highlighted:`pipeline = StableDiffusionXLPipeline.from_pretrained(
    <span class="hljs-string">&quot;stabilityai/stable-diffusion-xl-base-1.0&quot;</span>, torch_dtype=torch.float16
).to(<span class="hljs-string">&quot;cuda&quot;</span>)
pipeline.unet.to(memory_format=torch.channels_last)
pipeline.vae.to(memory_format=torch.channels_last)
pipeline.unet = torch.<span class="hljs-built_in">compile</span>(
    pipeline.unet, mode=<span class="hljs-string">&quot;max-autotune&quot;</span>, fullgraph=<span class="hljs-literal">True</span>
)
pipeline.vae.decode = torch.<span class="hljs-built_in">compile</span>(
    pipeline.vae.decode,
    mode=<span class="hljs-string">&quot;max-autotune&quot;</span>,
    fullgraph=<span class="hljs-literal">True</span>
)

prompt = <span class="hljs-string">&quot;Astronaut in a jungle, cold color palette, muted colors, detailed, 8k&quot;</span>
pipeline(prompt, num_inference_steps=<span class="hljs-number">30</span>).images[<span class="hljs-number">0</span>]`,wrap:!1}}),P=new C({props:{title:"Graph breaks",local:"graph-breaks",headingTag:"h3"}}),K=new W({props:{code:"LSUyMGxhdGVudHMlMjAlM0QlMjB1bmV0KCUwQS0lMjAlMjAlMjBsYXRlbnRzJTJDJTIwdGltZXN0ZXAlM0R0aW1lc3RlcCUyQyUyMGVuY29kZXJfaGlkZGVuX3N0YXRlcyUzRHByb21wdF9lbWJlZHMlMEEtKS5zYW1wbGUlMEElMEElMkIlMjBsYXRlbnRzJTIwJTNEJTIwdW5ldCglMEElMkIlMjAlMjAlMjBsYXRlbnRzJTJDJTIwdGltZXN0ZXAlM0R0aW1lc3RlcCUyQyUyMGVuY29kZXJfaGlkZGVuX3N0YXRlcyUzRHByb21wdF9lbWJlZHMlMkMlMjByZXR1cm5fZGljdCUzREZhbHNlJTBBJTJCKSU1QjAlNUQ=",highlighted:`<span class="hljs-deletion">- latents = unet(</span>
<span class="hljs-deletion">-   latents, timestep=timestep, encoder_hidden_states=prompt_embeds</span>
<span class="hljs-deletion">-).sample</span>

<span class="hljs-addition">+ latents = unet(</span>
<span class="hljs-addition">+   latents, timestep=timestep, encoder_hidden_states=prompt_embeds, return_dict=False</span>
<span class="hljs-addition">+)[0]</span>`,wrap:!1}}),O=new C({props:{title:"GPU sync",local:"gpu-sync",headingTag:"h3"}}),le=new C({props:{title:"Dynamic quantization",local:"dynamic-quantization",headingTag:"h2"}}),k=new Oe({props:{warning:!1,$$slots:{default:[Nt]},$$scope:{ctx:j}}}),ie=new W({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwdG9yY2hhbyUyMGltcG9ydCUyMGFwcGx5X2R5bmFtaWNfcXVhbnQlMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwU3RhYmxlRGlmZnVzaW9uWExQaXBlbGluZSUwQSUwQXRvcmNoLl9pbmR1Y3Rvci5jb25maWcuY29udl8xeDFfYXNfbW0lMjAlM0QlMjBUcnVlJTBBdG9yY2guX2luZHVjdG9yLmNvbmZpZy5jb29yZGluYXRlX2Rlc2NlbnRfdHVuaW5nJTIwJTNEJTIwVHJ1ZSUwQXRvcmNoLl9pbmR1Y3Rvci5jb25maWcuZXBpbG9ndWVfZnVzaW9uJTIwJTNEJTIwRmFsc2UlMEF0b3JjaC5faW5kdWN0b3IuY29uZmlnLmNvb3JkaW5hdGVfZGVzY2VudF9jaGVja19hbGxfZGlyZWN0aW9ucyUyMCUzRCUyMFRydWUlMEF0b3JjaC5faW5kdWN0b3IuY29uZmlnLmZvcmNlX2Z1c2VfaW50X21tX3dpdGhfbXVsJTIwJTNEJTIwVHJ1ZSUwQXRvcmNoLl9pbmR1Y3Rvci5jb25maWcudXNlX21peGVkX21tJTIwJTNEJTIwVHJ1ZQ==",highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> torchao <span class="hljs-keyword">import</span> apply_dynamic_quant
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> StableDiffusionXLPipeline

torch._inductor.config.conv_1x1_as_mm = <span class="hljs-literal">True</span>
torch._inductor.config.coordinate_descent_tuning = <span class="hljs-literal">True</span>
torch._inductor.config.epilogue_fusion = <span class="hljs-literal">False</span>
torch._inductor.config.coordinate_descent_check_all_directions = <span class="hljs-literal">True</span>
torch._inductor.config.force_fuse_int_mm_with_mul = <span class="hljs-literal">True</span>
torch._inductor.config.use_mixed_mm = <span class="hljs-literal">True</span>`,wrap:!1}}),pe=new W({props:{code:"cGlwZWxpbmUlMjAlM0QlMjBTdGFibGVEaWZmdXNpb25YTFBpcGVsaW5lLmZyb21fcHJldHJhaW5lZCglMEElMjAlMjAlMjAlMjAlMjJzdGFiaWxpdHlhaSUyRnN0YWJsZS1kaWZmdXNpb24teGwtYmFzZS0xLjAlMjIlMkMlMjB0b3JjaF9kdHlwZSUzRHRvcmNoLmJmbG9hdDE2JTBBKS50byglMjJjdWRhJTIyKSUwQSUwQWFwcGx5X2R5bmFtaWNfcXVhbnQocGlwZWxpbmUudW5ldCUyQyUyMGR5bmFtaWNfcXVhbnRfZmlsdGVyX2ZuKSUwQWFwcGx5X2R5bmFtaWNfcXVhbnQocGlwZWxpbmUudmFlJTJDJTIwZHluYW1pY19xdWFudF9maWx0ZXJfZm4pJTBBJTBBcHJvbXB0JTIwJTNEJTIwJTIyQXN0cm9uYXV0JTIwaW4lMjBhJTIwanVuZ2xlJTJDJTIwY29sZCUyMGNvbG9yJTIwcGFsZXR0ZSUyQyUyMG11dGVkJTIwY29sb3JzJTJDJTIwZGV0YWlsZWQlMkMlMjA4ayUyMiUwQXBpcGVsaW5lKHByb21wdCUyQyUyMG51bV9pbmZlcmVuY2Vfc3RlcHMlM0QzMCkuaW1hZ2VzJTVCMCU1RA==",highlighted:`pipeline = StableDiffusionXLPipeline.from_pretrained(
    <span class="hljs-string">&quot;stabilityai/stable-diffusion-xl-base-1.0&quot;</span>, torch_dtype=torch.bfloat16
).to(<span class="hljs-string">&quot;cuda&quot;</span>)

apply_dynamic_quant(pipeline.unet, dynamic_quant_filter_fn)
apply_dynamic_quant(pipeline.vae, dynamic_quant_filter_fn)

prompt = <span class="hljs-string">&quot;Astronaut in a jungle, cold color palette, muted colors, detailed, 8k&quot;</span>
pipeline(prompt, num_inference_steps=<span class="hljs-number">30</span>).images[<span class="hljs-number">0</span>]`,wrap:!1}}),re=new C({props:{title:"Fused projection matrices",local:"fused-projection-matrices",headingTag:"h2"}}),B=new Oe({props:{warning:!0,$$slots:{default:[Ht]},$$scope:{ctx:j}}}),ce=new W({props:{code:"cGlwZWxpbmUuZnVzZV9xa3ZfcHJvamVjdGlvbnMoKQ==",highlighted:"pipeline.fuse_qkv_projections()",wrap:!1}}),fe=new xt({props:{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/en/optimization/fp16.md"}}),{c(){a=c("meta"),u=o(),s=c("p"),m=o(),y(d.$$.fragment),r=o(),i=c("p"),i.innerHTML=g,U=o(),G=c("p"),G.textContent=_,b=o(),Z=c("p"),Z.textContent=tt,he=o(),y(R.$$.fragment),be=o(),I=c("p"),I.textContent=lt,ye=o(),y(v.$$.fragment),we=o(),y(V.$$.fragment),Me=o(),y(x.$$.fragment),$e=o(),N=c("p"),N.innerHTML=nt,Te=o(),H=c("p"),H.innerHTML=at,Je=o(),y(L.$$.fragment),ge=o(),y(z.$$.fragment),je=o(),Y=c("p"),Y.innerHTML=st,Ue=o(),E=c("p"),E.innerHTML=it,Ze=o(),y(Q.$$.fragment),Ge=o(),F=c("p"),F.innerHTML=ot,_e=o(),y(X.$$.fragment),We=o(),S=c("p"),S.innerHTML=pt,ve=o(),y(q.$$.fragment),xe=o(),A=c("p"),A.textContent=rt,Xe=o(),y(P.$$.fragment),ke=o(),D=c("p"),D.innerHTML=mt,Be=o(),y(K.$$.fragment),Ce=o(),y(O.$$.fragment),Re=o(),ee=c("p"),ee.innerHTML=ct,Ie=o(),te=c("p"),te.innerHTML=ft,Ve=o(),y(le.$$.fragment),Ne=o(),ne=c("p"),ne.innerHTML=ut,He=o(),ae=c("p"),ae.innerHTML=dt,Le=o(),y(k.$$.fragment),ze=o(),se=c("p"),se.textContent=ht,Ye=o(),y(ie.$$.fragment),Ee=o(),oe=c("p"),oe.innerHTML=bt,Qe=o(),y(pe.$$.fragment),Fe=o(),y(re.$$.fragment),Se=o(),y(B.$$.fragment),qe=o(),me=c("p"),me.textContent=yt,Ae=o(),y(ce.$$.fragment),Pe=o(),y(fe.$$.fragment),De=o(),de=c("p"),this.h()},l(e){const t=Wt("svelte-u9bgzb",document.head);a=f(t,"META",{name:!0,content:!0}),t.forEach(l),u=p(e),s=f(e,"P",{}),gt(s).forEach(l),m=p(e),w(d.$$.fragment,e),r=p(e),i=f(e,"P",{"data-svelte-h":!0}),h(i)!=="svelte-1m782be"&&(i.innerHTML=g),U=p(e),G=f(e,"P",{"data-svelte-h":!0}),h(G)!=="svelte-wa2eaw"&&(G.textContent=_),b=p(e),Z=f(e,"P",{"data-svelte-h":!0}),h(Z)!=="svelte-1cgitz1"&&(Z.textContent=tt),he=p(e),w(R.$$.fragment,e),be=p(e),I=f(e,"P",{"data-svelte-h":!0}),h(I)!=="svelte-18445ux"&&(I.textContent=lt),ye=p(e),w(v.$$.fragment,e),we=p(e),w(V.$$.fragment,e),Me=p(e),w(x.$$.fragment,e),$e=p(e),N=f(e,"P",{"data-svelte-h":!0}),h(N)!=="svelte-zmbjuq"&&(N.innerHTML=nt),Te=p(e),H=f(e,"P",{"data-svelte-h":!0}),h(H)!=="svelte-5i9w75"&&(H.innerHTML=at),Je=p(e),w(L.$$.fragment,e),ge=p(e),w(z.$$.fragment,e),je=p(e),Y=f(e,"P",{"data-svelte-h":!0}),h(Y)!=="svelte-nqxvwk"&&(Y.innerHTML=st),Ue=p(e),E=f(e,"P",{"data-svelte-h":!0}),h(E)!=="svelte-17o6ivw"&&(E.innerHTML=it),Ze=p(e),w(Q.$$.fragment,e),Ge=p(e),F=f(e,"P",{"data-svelte-h":!0}),h(F)!=="svelte-dwk3fl"&&(F.innerHTML=ot),_e=p(e),w(X.$$.fragment,e),We=p(e),S=f(e,"P",{"data-svelte-h":!0}),h(S)!=="svelte-lm2asr"&&(S.innerHTML=pt),ve=p(e),w(q.$$.fragment,e),xe=p(e),A=f(e,"P",{"data-svelte-h":!0}),h(A)!=="svelte-1jdqgot"&&(A.textContent=rt),Xe=p(e),w(P.$$.fragment,e),ke=p(e),D=f(e,"P",{"data-svelte-h":!0}),h(D)!=="svelte-12tqltr"&&(D.innerHTML=mt),Be=p(e),w(K.$$.fragment,e),Ce=p(e),w(O.$$.fragment,e),Re=p(e),ee=f(e,"P",{"data-svelte-h":!0}),h(ee)!=="svelte-1gyzgx0"&&(ee.innerHTML=ct),Ie=p(e),te=f(e,"P",{"data-svelte-h":!0}),h(te)!=="svelte-13ty8ou"&&(te.innerHTML=ft),Ve=p(e),w(le.$$.fragment,e),Ne=p(e),ne=f(e,"P",{"data-svelte-h":!0}),h(ne)!=="svelte-13773d2"&&(ne.innerHTML=ut),He=p(e),ae=f(e,"P",{"data-svelte-h":!0}),h(ae)!=="svelte-1wm8cfw"&&(ae.innerHTML=dt),Le=p(e),w(k.$$.fragment,e),ze=p(e),se=f(e,"P",{"data-svelte-h":!0}),h(se)!=="svelte-1rguzol"&&(se.textContent=ht),Ye=p(e),w(ie.$$.fragment,e),Ee=p(e),oe=f(e,"P",{"data-svelte-h":!0}),h(oe)!=="svelte-applj5"&&(oe.innerHTML=bt),Qe=p(e),w(pe.$$.fragment,e),Fe=p(e),w(re.$$.fragment,e),Se=p(e),w(B.$$.fragment,e),qe=p(e),me=f(e,"P",{"data-svelte-h":!0}),h(me)!=="svelte-1h88cib"&&(me.textContent=yt),Ae=p(e),w(ce.$$.fragment,e),Pe=p(e),w(fe.$$.fragment,e),De=p(e),de=f(e,"P",{}),gt(de).forEach(l),this.h()},h(){jt(a,"name","hf:doc:metadata"),jt(a,"content",zt)},m(e,t){vt(document.head,a),n(e,u,t),n(e,s,t),n(e,m,t),M(d,e,t),n(e,r,t),n(e,i,t),n(e,U,t),n(e,G,t),n(e,b,t),n(e,Z,t),n(e,he,t),M(R,e,t),n(e,be,t),n(e,I,t),n(e,ye,t),M(v,e,t),n(e,we,t),M(V,e,t),n(e,Me,t),M(x,e,t),n(e,$e,t),n(e,N,t),n(e,Te,t),n(e,H,t),n(e,Je,t),M(L,e,t),n(e,ge,t),M(z,e,t),n(e,je,t),n(e,Y,t),n(e,Ue,t),n(e,E,t),n(e,Ze,t),M(Q,e,t),n(e,Ge,t),n(e,F,t),n(e,_e,t),M(X,e,t),n(e,We,t),n(e,S,t),n(e,ve,t),M(q,e,t),n(e,xe,t),n(e,A,t),n(e,Xe,t),M(P,e,t),n(e,ke,t),n(e,D,t),n(e,Be,t),M(K,e,t),n(e,Ce,t),M(O,e,t),n(e,Re,t),n(e,ee,t),n(e,Ie,t),n(e,te,t),n(e,Ve,t),M(le,e,t),n(e,Ne,t),n(e,ne,t),n(e,He,t),n(e,ae,t),n(e,Le,t),M(k,e,t),n(e,ze,t),n(e,se,t),n(e,Ye,t),M(ie,e,t),n(e,Ee,t),n(e,oe,t),n(e,Qe,t),M(pe,e,t),n(e,Fe,t),M(re,e,t),n(e,Se,t),M(B,e,t),n(e,qe,t),n(e,me,t),n(e,Ae,t),M(ce,e,t),n(e,Pe,t),M(fe,e,t),n(e,De,t),n(e,de,t),Ke=!0},p(e,[t]){const wt={};t&2&&(wt.$$scope={dirty:t,ctx:e}),v.$set(wt);const Mt={};t&2&&(Mt.$$scope={dirty:t,ctx:e}),x.$set(Mt);const $t={};t&2&&($t.$$scope={dirty:t,ctx:e}),X.$set($t);const Tt={};t&2&&(Tt.$$scope={dirty:t,ctx:e}),k.$set(Tt);const Jt={};t&2&&(Jt.$$scope={dirty:t,ctx:e}),B.$set(Jt)},i(e){Ke||($(d.$$.fragment,e),$(R.$$.fragment,e),$(v.$$.fragment,e),$(V.$$.fragment,e),$(x.$$.fragment,e),$(L.$$.fragment,e),$(z.$$.fragment,e),$(Q.$$.fragment,e),$(X.$$.fragment,e),$(q.$$.fragment,e),$(P.$$.fragment,e),$(K.$$.fragment,e),$(O.$$.fragment,e),$(le.$$.fragment,e),$(k.$$.fragment,e),$(ie.$$.fragment,e),$(pe.$$.fragment,e),$(re.$$.fragment,e),$(B.$$.fragment,e),$(ce.$$.fragment,e),$(fe.$$.fragment,e),Ke=!0)},o(e){T(d.$$.fragment,e),T(R.$$.fragment,e),T(v.$$.fragment,e),T(V.$$.fragment,e),T(x.$$.fragment,e),T(L.$$.fragment,e),T(z.$$.fragment,e),T(Q.$$.fragment,e),T(X.$$.fragment,e),T(q.$$.fragment,e),T(P.$$.fragment,e),T(K.$$.fragment,e),T(O.$$.fragment,e),T(le.$$.fragment,e),T(k.$$.fragment,e),T(ie.$$.fragment,e),T(pe.$$.fragment,e),T(re.$$.fragment,e),T(B.$$.fragment,e),T(ce.$$.fragment,e),T(fe.$$.fragment,e),Ke=!1},d(e){e&&(l(u),l(s),l(m),l(r),l(i),l(U),l(G),l(b),l(Z),l(he),l(be),l(I),l(ye),l(we),l(Me),l($e),l(N),l(Te),l(H),l(Je),l(ge),l(je),l(Y),l(Ue),l(E),l(Ze),l(Ge),l(F),l(_e),l(We),l(S),l(ve),l(xe),l(A),l(Xe),l(ke),l(D),l(Be),l(Ce),l(Re),l(ee),l(Ie),l(te),l(Ve),l(Ne),l(ne),l(He),l(ae),l(Le),l(ze),l(se),l(Ye),l(Ee),l(oe),l(Qe),l(Fe),l(Se),l(qe),l(me),l(Ae),l(Pe),l(De),l(de)),l(a),J(d,e),J(R,e),J(v,e),J(V,e),J(x,e),J(L,e),J(z,e),J(Q,e),J(X,e),J(q,e),J(P,e),J(K,e),J(O,e),J(le,e),J(k,e),J(ie,e),J(pe,e),J(re,e),J(B,e),J(ce,e),J(fe,e)}}}const zt='{"title":"Accelerate inference","local":"accelerate-inference","sections":[{"title":"Model data type","local":"model-data-type","sections":[],"depth":2},{"title":"Scaled dot product attention","local":"scaled-dot-product-attention","sections":[],"depth":2},{"title":"torch.compile","local":"torchcompile","sections":[{"title":"Graph breaks","local":"graph-breaks","sections":[],"depth":3},{"title":"GPU sync","local":"gpu-sync","sections":[],"depth":3}],"depth":2},{"title":"Dynamic quantization","local":"dynamic-quantization","sections":[],"depth":2},{"title":"Fused projection matrices","local":"fused-projection-matrices","sections":[],"depth":2}],"depth":1}';function Yt(j){return Zt(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Pt extends Gt{constructor(a){super(),_t(this,a,Yt,Lt,Ut,{})}}export{Pt as component};
