import{S as rf,i as lf,s as pf,e as a,k as p,w as u,t as r,M as ff,c as n,d as s,m as f,a as o,x as m,h as i,b as h,G as t,g as c,y as d,q as _,o as v,B as y,v as cf}from"../../chunks/vendor-hf-doc-builder.js";import{T as of}from"../../chunks/Tip-hf-doc-builder.js";import{I as q}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{C as A}from"../../chunks/CodeBlock-hf-doc-builder.js";function hf(st){let b;return{c(){b=r("It is strongly discouraged to make use of [`torch.autocast`](https://pytorch.org/docs/stable/amp.html#torch.autocast) in any of the pipelines as it can lead to black images and is always slower than using pure \n  float16 precision.")},l(g){b=i(g,"It is strongly discouraged to make use of [`torch.autocast`](https://pytorch.org/docs/stable/amp.html#torch.autocast) in any of the pipelines as it can lead to black images and is always slower than using pure \n  float16 precision.")},m(g,j){c(g,b,j)},d(g){g&&s(b)}}}function uf(st){let b;return{c(){b=r(`Attention slicing is useful even if a batch size of just 1 is used - as long
  as the model uses more than one attention head. If there is more than one
  attention head the *QK^T* attention matrix can be computed sequentially for
  each head which can save a significant amount of memory.`)},l(g){b=i(g,`Attention slicing is useful even if a batch size of just 1 is used - as long
  as the model uses more than one attention head. If there is more than one
  attention head the *QK^T* attention matrix can be computed sequentially for
  each head which can save a significant amount of memory.`)},m(g,j){c(g,b,j)},d(g){g&&s(b)}}}function mf(st){let b,g,j,oe,Bt,De,qn,Ot,In,ma,T,Un,Lt,Cn,Rn,Ae,Fn,zn,at,Vn,Gn,da,nt,Hn,_a,re,Xt,I,va,Mn,Yt,Bn,On,Wt,Ln,Xn,$,U,Kt,Yn,Wn,Qt,Kn,Qn,Jt,Jn,Zn,C,Zt,eo,to,es,so,ao,ts,no,oo,R,ss,ro,io,as,lo,po,ns,fo,co,F,os,ho,uo,rs,mo,_o,is,vo,yo,z,ls,bo,wo,ps,go,$o,fs,Eo,jo,V,cs,ko,To,hs,Do,Ao,us,Po,ya,ot,So,ba,G,ie,ms,Pe,xo,ds,No,wa,Se,xe,qo,Io,ga,le,Uo,_s,Co,Ro,$a,Ne,Ea,H,pe,vs,qe,Fo,ys,zo,ja,fe,Vo,Ie,Go,Ho,ka,Ue,Ta,M,ce,bs,Ce,Mo,ws,Bo,Da,P,Oo,gs,Lo,Xo,$s,Yo,Wo,Aa,Re,Pa,he,Sa,B,ue,Es,Fe,Ko,js,Qo,xa,rt,Jo,Na,me,qa,de,Zo,it,er,tr,Ia,ze,Ua,lt,sr,Ca,O,_e,ks,Ve,ar,Ts,nr,Ra,pt,or,Fa,S,rr,ft,ir,lr,ct,pr,fr,za,ve,cr,ht,hr,ur,Va,Ge,Ga,ut,mr,Ha,L,ye,Ds,He,dr,As,_r,Ma,mt,vr,Ba,be,yr,dt,br,wr,Oa,Me,La,_t,gr,Xa,vt,$r,Ya,Be,Wa,k,Ps,Er,jr,Ss,kr,Tr,xs,Dr,Ar,Oe,Pr,Sr,Ka,X,we,Ns,Le,xr,qs,Nr,Qa,yt,qr,Ja,bt,Ir,Za,Xe,en,Y,ge,Is,Ye,Ur,Us,Cr,tn,$e,Rr,Cs,Fr,zr,sn,wt,Vr,an,We,nn,Ee,Gr,Rs,Hr,Mr,on,Ke,rn,W,je,Fs,Qe,Br,zs,Or,ln,x,Lr,Je,Xr,Yr,Ze,Wr,Kr,pn,gt,Qr,fn,ke,Vs,K,Gs,Jr,Zr,Hs,ei,ti,Ms,si,ai,w,Q,Bs,ni,oi,Os,ri,ii,Ls,li,pi,J,Xs,fi,ci,Ys,hi,ui,Ws,mi,di,Z,Ks,_i,vi,Qs,yi,bi,Js,wi,gi,ee,Zs,$i,Ei,ea,ji,ki,ta,Ti,Di,te,sa,Ai,Pi,aa,Si,xi,na,Ni,qi,se,oa,Ii,Ui,ra,Ci,Ri,ia,Fi,zi,ae,la,Vi,Gi,pa,Hi,Mi,fa,Bi,cn,$t,Oi,hn,N,ca,Li,Xi,ha,Yi,Wi,Et,jt,Ki,Qi,un,et,mn;return De=new q({}),Pe=new q({}),Ne=new A({props:{code:`import torch

torch.backends.cudnn.benchmark = True`,highlighted:`<span class="hljs-keyword">import</span> torch

torch.backends.cudnn.benchmark = <span class="hljs-literal">True</span>`}}),qe=new q({}),Ue=new A({props:{code:`import torch

torch.backends.cuda.matmul.allow_tf32 = True`,highlighted:`<span class="hljs-keyword">import</span> torch

torch.backends.cuda.matmul.allow_tf32 = <span class="hljs-literal">True</span>`}}),Ce=new q({}),Re=new A({props:{code:`pipe = StableDiffusionPipeline.from_pretrained(
    "runwayml/stable-diffusion-v1-5",
    
    torch_dtype=torch.float16,
)
pipe = pipe.to("cuda")

prompt = "a photo of an astronaut riding a horse on mars"
image = pipe(prompt).images[0]`,highlighted:`pipe = StableDiffusionPipeline.from_pretrained(
    <span class="hljs-string">&quot;runwayml/stable-diffusion-v1-5&quot;</span>,
    
    torch_dtype=torch.float16,
)
pipe = pipe.to(<span class="hljs-string">&quot;cuda&quot;</span>)

prompt = <span class="hljs-string">&quot;a photo of an astronaut riding a horse on mars&quot;</span>
image = pipe(prompt).images[<span class="hljs-number">0</span>]`}}),he=new of({props:{warning:!0,$$slots:{default:[hf]},$$scope:{ctx:st}}}),Fe=new q({}),me=new of({props:{$$slots:{default:[uf]},$$scope:{ctx:st}}}),ze=new A({props:{code:`import torch
from diffusers import StableDiffusionPipeline

pipe = StableDiffusionPipeline.from_pretrained(
    "runwayml/stable-diffusion-v1-5",
    
    torch_dtype=torch.float16,
)
pipe = pipe.to("cuda")

prompt = "a photo of an astronaut riding a horse on mars"
pipe.enable_attention_slicing()
image = pipe(prompt).images[0]`,highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> StableDiffusionPipeline

pipe = StableDiffusionPipeline.from_pretrained(
    <span class="hljs-string">&quot;runwayml/stable-diffusion-v1-5&quot;</span>,
    
    torch_dtype=torch.float16,
)
pipe = pipe.to(<span class="hljs-string">&quot;cuda&quot;</span>)

prompt = <span class="hljs-string">&quot;a photo of an astronaut riding a horse on mars&quot;</span>
pipe.enable_attention_slicing()
image = pipe(prompt).images[<span class="hljs-number">0</span>]`}}),Ve=new q({}),Ge=new A({props:{code:`import torch
from diffusers import StableDiffusionPipeline

pipe = StableDiffusionPipeline.from_pretrained(
    "runwayml/stable-diffusion-v1-5",
    
    torch_dtype=torch.float16,
)
pipe = pipe.to("cuda")

prompt = "a photo of an astronaut riding a horse on mars"
pipe.enable_vae_slicing()
images = pipe([prompt] * 32).images`,highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> StableDiffusionPipeline

pipe = StableDiffusionPipeline.from_pretrained(
    <span class="hljs-string">&quot;runwayml/stable-diffusion-v1-5&quot;</span>,
    
    torch_dtype=torch.float16,
)
pipe = pipe.to(<span class="hljs-string">&quot;cuda&quot;</span>)

prompt = <span class="hljs-string">&quot;a photo of an astronaut riding a horse on mars&quot;</span>
pipe.enable_vae_slicing()
images = pipe([prompt] * <span class="hljs-number">32</span>).images`}}),He=new q({}),Me=new A({props:{code:`import torch
from diffusers import StableDiffusionPipeline

pipe = StableDiffusionPipeline.from_pretrained(
    "runwayml/stable-diffusion-v1-5",
    
    torch_dtype=torch.float16,
)

prompt = "a photo of an astronaut riding a horse on mars"
pipe.enable_sequential_cpu_offload()
image = pipe(prompt).images[0]`,highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> StableDiffusionPipeline

pipe = StableDiffusionPipeline.from_pretrained(
    <span class="hljs-string">&quot;runwayml/stable-diffusion-v1-5&quot;</span>,
    
    torch_dtype=torch.float16,
)

prompt = <span class="hljs-string">&quot;a photo of an astronaut riding a horse on mars&quot;</span>
pipe.enable_sequential_cpu_offload()
image = pipe(prompt).images[<span class="hljs-number">0</span>]`}}),Be=new A({props:{code:`import torch
from diffusers import StableDiffusionPipeline

pipe = StableDiffusionPipeline.from_pretrained(
    "runwayml/stable-diffusion-v1-5",
    
    torch_dtype=torch.float16,
)

prompt = "a photo of an astronaut riding a horse on mars"
pipe.enable_sequential_cpu_offload()
pipe.enable_attention_slicing(1)

image = pipe(prompt).images[0]`,highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> StableDiffusionPipeline

pipe = StableDiffusionPipeline.from_pretrained(
    <span class="hljs-string">&quot;runwayml/stable-diffusion-v1-5&quot;</span>,
    
    torch_dtype=torch.float16,
)

prompt = <span class="hljs-string">&quot;a photo of an astronaut riding a horse on mars&quot;</span>
pipe.enable_sequential_cpu_offload()
pipe.enable_attention_slicing(<span class="hljs-number">1</span>)

image = pipe(prompt).images[<span class="hljs-number">0</span>]`}}),Le=new q({}),Xe=new A({props:{code:`print(pipe.unet.conv_out.state_dict()["weight"].stride())  # (2880, 9, 3, 1)
pipe.unet.to(memory_format=torch.channels_last)  # in-place operation
print(
    pipe.unet.conv_out.state_dict()["weight"].stride()
)  # (2880, 1, 960, 320) having a stride of 1 for the 2nd dimension proves that it works`,highlighted:`<span class="hljs-built_in">print</span>(pipe.unet.conv_out.state_dict()[<span class="hljs-string">&quot;weight&quot;</span>].stride())  <span class="hljs-comment"># (2880, 9, 3, 1)</span>
pipe.unet.to(memory_format=torch.channels_last)  <span class="hljs-comment"># in-place operation</span>
<span class="hljs-built_in">print</span>(
    pipe.unet.conv_out.state_dict()[<span class="hljs-string">&quot;weight&quot;</span>].stride()
)  <span class="hljs-comment"># (2880, 1, 960, 320) having a stride of 1 for the 2nd dimension proves that it works</span>`}}),Ye=new q({}),We=new A({props:{code:`import time
import torch
from diffusers import StableDiffusionPipeline
import functools

# torch disable grad
torch.set_grad_enabled(False)

# set variables
n_experiments = 2
unet_runs_per_experiment = 50

# load inputs
def generate_inputs():
    sample = torch.randn(2, 4, 64, 64).half().cuda()
    timestep = torch.rand(1).half().cuda() * 999
    encoder_hidden_states = torch.randn(2, 77, 768).half().cuda()
    return sample, timestep, encoder_hidden_states


pipe = StableDiffusionPipeline.from_pretrained(
    "runwayml/stable-diffusion-v1-5",
    torch_dtype=torch.float16,
).to("cuda")
unet = pipe.unet
unet.eval()
unet.to(memory_format=torch.channels_last)  # use channels_last memory format
unet.forward = functools.partial(unet.forward, return_dict=False)  # set return_dict=False as default

# warmup
for _ in range(3):
    with torch.inference_mode():
        inputs = generate_inputs()
        orig_output = unet(*inputs)

# trace
print("tracing..")
unet_traced = torch.jit.trace(unet, inputs)
unet_traced.eval()
print("done tracing")


# warmup and optimize graph
for _ in range(5):
    with torch.inference_mode():
        inputs = generate_inputs()
        orig_output = unet_traced(*inputs)


# benchmarking
with torch.inference_mode():
    for _ in range(n_experiments):
        torch.cuda.synchronize()
        start_time = time.time()
        for _ in range(unet_runs_per_experiment):
            orig_output = unet_traced(*inputs)
        torch.cuda.synchronize()
        print(f"unet traced inference took {time.time() - start_time:.2f} seconds")
    for _ in range(n_experiments):
        torch.cuda.synchronize()
        start_time = time.time()
        for _ in range(unet_runs_per_experiment):
            orig_output = unet(*inputs)
        torch.cuda.synchronize()
        print(f"unet inference took {time.time() - start_time:.2f} seconds")

# save the model
unet_traced.save("unet_traced.pt")`,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> StableDiffusionPipeline
<span class="hljs-keyword">import</span> functools

<span class="hljs-comment"># torch disable grad</span>
torch.set_grad_enabled(<span class="hljs-literal">False</span>)

<span class="hljs-comment"># set variables</span>
n_experiments = <span class="hljs-number">2</span>
unet_runs_per_experiment = <span class="hljs-number">50</span>

<span class="hljs-comment"># load inputs</span>
<span class="hljs-keyword">def</span> <span class="hljs-title function_">generate_inputs</span>():
    sample = torch.randn(<span class="hljs-number">2</span>, <span class="hljs-number">4</span>, <span class="hljs-number">64</span>, <span class="hljs-number">64</span>).half().cuda()
    timestep = torch.rand(<span class="hljs-number">1</span>).half().cuda() * <span class="hljs-number">999</span>
    encoder_hidden_states = torch.randn(<span class="hljs-number">2</span>, <span class="hljs-number">77</span>, <span class="hljs-number">768</span>).half().cuda()
    <span class="hljs-keyword">return</span> sample, timestep, encoder_hidden_states


pipe = StableDiffusionPipeline.from_pretrained(
    <span class="hljs-string">&quot;runwayml/stable-diffusion-v1-5&quot;</span>,
    torch_dtype=torch.float16,
).to(<span class="hljs-string">&quot;cuda&quot;</span>)
unet = pipe.unet
unet.<span class="hljs-built_in">eval</span>()
unet.to(memory_format=torch.channels_last)  <span class="hljs-comment"># use channels_last memory format</span>
unet.forward = functools.partial(unet.forward, return_dict=<span class="hljs-literal">False</span>)  <span class="hljs-comment"># set return_dict=False as default</span>

<span class="hljs-comment"># warmup</span>
<span class="hljs-keyword">for</span> _ <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">3</span>):
    <span class="hljs-keyword">with</span> torch.inference_mode():
        inputs = generate_inputs()
        orig_output = unet(*inputs)

<span class="hljs-comment"># trace</span>
<span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;tracing..&quot;</span>)
unet_traced = torch.jit.trace(unet, inputs)
unet_traced.<span class="hljs-built_in">eval</span>()
<span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;done tracing&quot;</span>)


<span class="hljs-comment"># warmup and optimize graph</span>
<span class="hljs-keyword">for</span> _ <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-number">5</span>):
    <span class="hljs-keyword">with</span> torch.inference_mode():
        inputs = generate_inputs()
        orig_output = unet_traced(*inputs)


<span class="hljs-comment"># benchmarking</span>
<span class="hljs-keyword">with</span> torch.inference_mode():
    <span class="hljs-keyword">for</span> _ <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(n_experiments):
        torch.cuda.synchronize()
        start_time = time.time()
        <span class="hljs-keyword">for</span> _ <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(unet_runs_per_experiment):
            orig_output = unet_traced(*inputs)
        torch.cuda.synchronize()
        <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;unet traced inference took <span class="hljs-subst">{time.time() - start_time:<span class="hljs-number">.2</span>f}</span> seconds&quot;</span>)
    <span class="hljs-keyword">for</span> _ <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(n_experiments):
        torch.cuda.synchronize()
        start_time = time.time()
        <span class="hljs-keyword">for</span> _ <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(unet_runs_per_experiment):
            orig_output = unet(*inputs)
        torch.cuda.synchronize()
        <span class="hljs-built_in">print</span>(<span class="hljs-string">f&quot;unet inference took <span class="hljs-subst">{time.time() - start_time:<span class="hljs-number">.2</span>f}</span> seconds&quot;</span>)

<span class="hljs-comment"># save the model</span>
unet_traced.save(<span class="hljs-string">&quot;unet_traced.pt&quot;</span>)`}}),Ke=new A({props:{code:`from diffusers import StableDiffusionPipeline
import torch
from dataclasses import dataclass


@dataclass
class UNet2DConditionOutput:
    sample: torch.FloatTensor


pipe = StableDiffusionPipeline.from_pretrained(
    "runwayml/stable-diffusion-v1-5",
    torch_dtype=torch.float16,
).to("cuda")

# use jitted unet
unet_traced = torch.jit.load("unet_traced.pt")
# del pipe.unet
class TracedUNet(torch.nn.Module):
    def __init__(self):
        super().__init__()
        self.in_channels = pipe.unet.in_channels
        self.device = pipe.unet.device

    def forward(self, latent_model_input, t, encoder_hidden_states):
        sample = unet_traced(latent_model_input, t, encoder_hidden_states)[0]
        return UNet2DConditionOutput(sample=sample)


pipe.unet = TracedUNet()

with torch.inference_mode():
    image = pipe([prompt] * 1, num_inference_steps=50).images[0]`,highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> StableDiffusionPipeline
<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> dataclasses <span class="hljs-keyword">import</span> dataclass


<span class="hljs-meta">@dataclass</span>
<span class="hljs-keyword">class</span> <span class="hljs-title class_">UNet2DConditionOutput</span>:
    sample: torch.FloatTensor


pipe = StableDiffusionPipeline.from_pretrained(
    <span class="hljs-string">&quot;runwayml/stable-diffusion-v1-5&quot;</span>,
    torch_dtype=torch.float16,
).to(<span class="hljs-string">&quot;cuda&quot;</span>)

<span class="hljs-comment"># use jitted unet</span>
unet_traced = torch.jit.load(<span class="hljs-string">&quot;unet_traced.pt&quot;</span>)
<span class="hljs-comment"># del pipe.unet</span>
<span class="hljs-keyword">class</span> <span class="hljs-title class_">TracedUNet</span>(torch.nn.Module):
    <span class="hljs-keyword">def</span> <span class="hljs-title function_">__init__</span>(<span class="hljs-params">self</span>):
        <span class="hljs-built_in">super</span>().__init__()
        self.in_channels = pipe.unet.in_channels
        self.device = pipe.unet.device

    <span class="hljs-keyword">def</span> <span class="hljs-title function_">forward</span>(<span class="hljs-params">self, latent_model_input, t, encoder_hidden_states</span>):
        sample = unet_traced(latent_model_input, t, encoder_hidden_states)[<span class="hljs-number">0</span>]
        <span class="hljs-keyword">return</span> UNet2DConditionOutput(sample=sample)


pipe.unet = TracedUNet()

<span class="hljs-keyword">with</span> torch.inference_mode():
    image = pipe([prompt] * <span class="hljs-number">1</span>, num_inference_steps=<span class="hljs-number">50</span>).images[<span class="hljs-number">0</span>]`}}),Qe=new q({}),et=new A({props:{code:`from diffusers import StableDiffusionPipeline
import torch

pipe = StableDiffusionPipeline.from_pretrained(
    "runwayml/stable-diffusion-v1-5",
    torch_dtype=torch.float16,
).to("cuda")

pipe.enable_xformers_memory_efficient_attention()

with torch.inference_mode():
    sample = pipe("a small cat")

# optional: You can disable it via
# pipe.disable_xformers_memory_efficient_attention()`,highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> StableDiffusionPipeline
<span class="hljs-keyword">import</span> torch

pipe = StableDiffusionPipeline.from_pretrained(
    <span class="hljs-string">&quot;runwayml/stable-diffusion-v1-5&quot;</span>,
    torch_dtype=torch.float16,
).to(<span class="hljs-string">&quot;cuda&quot;</span>)

pipe.enable_xformers_memory_efficient_attention()

<span class="hljs-keyword">with</span> torch.inference_mode():
    sample = pipe(<span class="hljs-string">&quot;a small cat&quot;</span>)

<span class="hljs-comment"># optional: You can disable it via</span>
<span class="hljs-comment"># pipe.disable_xformers_memory_efficient_attention()</span>`}}),{c(){b=a("meta"),g=p(),j=a("h1"),oe=a("a"),Bt=a("span"),u(De.$$.fragment),qn=p(),Ot=a("span"),In=r("Memory and speed"),ma=p(),T=a("p"),Un=r("We present some techniques and ideas to optimize \u{1F917} Diffusers "),Lt=a("em"),Cn=r("inference"),Rn=r(" for memory or speed. As a general rule, we recommend the use of "),Ae=a("a"),Fn=r("xFormers"),zn=r(" for memory efficient attention, please see the recommended "),at=a("a"),Vn=r("installation instructions"),Gn=r("."),da=p(),nt=a("p"),Hn=r("We\u2019ll discuss how the following settings impact performance and memory."),_a=p(),re=a("table"),Xt=a("thead"),I=a("tr"),va=a("th"),Mn=p(),Yt=a("th"),Bn=r("Latency"),On=p(),Wt=a("th"),Ln=r("Speedup"),Xn=p(),$=a("tbody"),U=a("tr"),Kt=a("td"),Yn=r("original"),Wn=p(),Qt=a("td"),Kn=r("9.50s"),Qn=p(),Jt=a("td"),Jn=r("x1"),Zn=p(),C=a("tr"),Zt=a("td"),eo=r("cuDNN auto-tuner"),to=p(),es=a("td"),so=r("9.37s"),ao=p(),ts=a("td"),no=r("x1.01"),oo=p(),R=a("tr"),ss=a("td"),ro=r("fp16"),io=p(),as=a("td"),lo=r("3.61s"),po=p(),ns=a("td"),fo=r("x2.63"),co=p(),F=a("tr"),os=a("td"),ho=r("channels last"),uo=p(),rs=a("td"),mo=r("3.30s"),_o=p(),is=a("td"),vo=r("x2.88"),yo=p(),z=a("tr"),ls=a("td"),bo=r("traced UNet"),wo=p(),ps=a("td"),go=r("3.21s"),$o=p(),fs=a("td"),Eo=r("x2.96"),jo=p(),V=a("tr"),cs=a("td"),ko=r("memory efficient attention"),To=p(),hs=a("td"),Do=r("2.63s"),Ao=p(),us=a("td"),Po=r("x3.61"),ya=p(),ot=a("em"),So=r(`obtained on NVIDIA TITAN RTX by generating a single image of size 512x512 from
  the prompt "a photo of an astronaut riding a horse on mars" with 50 DDIM
  steps.`),ba=p(),G=a("h2"),ie=a("a"),ms=a("span"),u(Pe.$$.fragment),xo=p(),ds=a("span"),No=r("Enable cuDNN auto-tuner"),wa=p(),Se=a("p"),xe=a("a"),qo=r("NVIDIA cuDNN"),Io=r("\xA0supports many algorithms to compute a convolution. Autotuner runs a short benchmark and selects the kernel with the best performance on a given hardware for a given input size."),ga=p(),le=a("p"),Uo=r("Since we\u2019re using "),_s=a("strong"),Co=r("convolutional networks"),Ro=r(" (other types currently not supported), we can enable cuDNN autotuner before launching the inference by setting:"),$a=p(),u(Ne.$$.fragment),Ea=p(),H=a("h3"),pe=a("a"),vs=a("span"),u(qe.$$.fragment),Fo=p(),ys=a("span"),zo=r("Use tf32 instead of fp32 (on Ampere and later CUDA devices)"),ja=p(),fe=a("p"),Vo=r("On Ampere and later CUDA devices matrix multiplications and convolutions can use the TensorFloat32 (TF32) mode for faster but slightly less accurate computations. By default PyTorch enables TF32 mode for convolutions but not matrix multiplications, and unless a network requires full float32 precision we recommend enabling this setting for matrix multiplications, too. It can significantly speed up computations with typically negligible loss of numerical accuracy. You can read more about it "),Ie=a("a"),Go=r("here"),Ho=r(". All you need to do is to add this before your inference:"),ka=p(),u(Ue.$$.fragment),Ta=p(),M=a("h2"),ce=a("a"),bs=a("span"),u(Ce.$$.fragment),Mo=p(),ws=a("span"),Bo=r("Half precision weights"),Da=p(),P=a("p"),Oo=r("To save more GPU memory and get more speed, you can load and run the model weights directly in half precision. This involves loading the float16 version of the weights, which was saved to a branch named "),gs=a("code"),Lo=r("fp16"),Xo=r(", and telling PyTorch to use the "),$s=a("code"),Yo=r("float16"),Wo=r(" type when loading them:"),Aa=p(),u(Re.$$.fragment),Pa=p(),u(he.$$.fragment),Sa=p(),B=a("h2"),ue=a("a"),Es=a("span"),u(Fe.$$.fragment),Ko=p(),js=a("span"),Qo=r("Sliced attention for additional memory savings"),xa=p(),rt=a("p"),Jo=r("For even additional memory savings, you can use a sliced version of attention that performs the computation in steps instead of all at once."),Na=p(),u(me.$$.fragment),qa=p(),de=a("p"),Zo=r("To perform the attention computation sequentially over each head, you only need to invoke "),it=a("a"),er=r("enable_attention_slicing()"),tr=r(" in your pipeline before inference, like here:"),Ia=p(),u(ze.$$.fragment),Ua=p(),lt=a("p"),sr=r("There\u2019s a small performance penalty of about 10% slower inference times, but this method allows you to use Stable Diffusion in as little as 3.2 GB of VRAM!"),Ca=p(),O=a("h2"),_e=a("a"),ks=a("span"),u(Ve.$$.fragment),ar=p(),Ts=a("span"),nr=r("Sliced VAE decode for larger batches"),Ra=p(),pt=a("p"),or=r("To decode large batches of images with limited VRAM, or to enable batches with 32 images or more, you can use sliced VAE decode that decodes the batch latents one image at a time."),Fa=p(),S=a("p"),rr=r("You likely want to couple this with "),ft=a("a"),ir=r("enable_attention_slicing()"),lr=r(" or "),ct=a("a"),pr=r("enable_xformers_memory_efficient_attention()"),fr=r(" to further minimize memory use."),za=p(),ve=a("p"),cr=r("To perform the VAE decode one image at a time, invoke "),ht=a("a"),hr=r("enable_vae_slicing()"),ur=r(" in your pipeline before inference. For example:"),Va=p(),u(Ge.$$.fragment),Ga=p(),ut=a("p"),mr=r("You may see a small performance boost in VAE decode on multi-image batches. There should be no performance impact on single-image batches."),Ha=p(),L=a("h2"),ye=a("a"),Ds=a("span"),u(He.$$.fragment),dr=p(),As=a("span"),_r=r("Offloading to CPU with accelerate for memory savings"),Ma=p(),mt=a("p"),vr=r("For additional memory savings, you can offload the weights to CPU and only load them to GPU when performing the forward pass."),Ba=p(),be=a("p"),yr=r("To perform CPU offloading, all you have to do is invoke "),dt=a("a"),br=r("enable_sequential_cpu_offload()"),wr=r(":"),Oa=p(),u(Me.$$.fragment),La=p(),_t=a("p"),gr=r("And you can get the memory consumption to < 3GB."),Xa=p(),vt=a("p"),$r=r("If is also possible to chain it with attention slicing for minimal memory consumption (< 2GB)."),Ya=p(),u(Be.$$.fragment),Wa=p(),k=a("p"),Ps=a("strong"),Er=r("Note"),jr=r(": When using "),Ss=a("code"),kr=r("enable_sequential_cpu_offload()"),Tr=r(", it is important to "),xs=a("strong"),Dr=r("not"),Ar=r(" move the pipeline to CUDA beforehand or else the gain in memory consumption will only be minimal. See "),Oe=a("a"),Pr=r("this issue"),Sr=r(" for more information."),Ka=p(),X=a("h2"),we=a("a"),Ns=a("span"),u(Le.$$.fragment),xr=p(),qs=a("span"),Nr=r("Using Channels Last memory format"),Qa=p(),yt=a("p"),qr=r("Channels last memory format is an alternative way of ordering NCHW tensors in memory preserving dimensions ordering. Channels last tensors ordered in such a way that channels become the densest dimension (aka storing images pixel-per-pixel). Since not all operators currently support channels last format it may result in a worst performance, so it\u2019s better to try it and see if it works for your model."),Ja=p(),bt=a("p"),Ir=r("For example, in order to set the UNet model in our pipeline to use channels last format, we can use the following:"),Za=p(),u(Xe.$$.fragment),en=p(),Y=a("h2"),ge=a("a"),Is=a("span"),u(Ye.$$.fragment),Ur=p(),Us=a("span"),Cr=r("Tracing"),tn=p(),$e=a("p"),Rr=r("Tracing runs an example input tensor through your model, and captures the operations that are invoked as that input makes its way through the model\u2019s layers so that an executable or "),Cs=a("code"),Fr=r("ScriptFunction"),zr=r(" is returned that will be optimized using just-in-time compilation."),sn=p(),wt=a("p"),Vr=r("To trace our UNet model, we can use the following:"),an=p(),u(We.$$.fragment),nn=p(),Ee=a("p"),Gr=r("Then we can replace the "),Rs=a("code"),Hr=r("unet"),Mr=r(" attribute of the pipeline with the traced model like the following"),on=p(),u(Ke.$$.fragment),rn=p(),W=a("h2"),je=a("a"),Fs=a("span"),u(Qe.$$.fragment),Br=p(),zs=a("span"),Or=r("Memory Efficient Attention"),ln=p(),x=a("p"),Lr=r("Recent work on optimizing the bandwitdh in the attention block has generated huge speed ups and gains in GPU memory usage. The most recent being Flash Attention from @tridao: "),Je=a("a"),Xr=r("code"),Yr=r(", "),Ze=a("a"),Wr=r("paper"),Kr=r("."),pn=p(),gt=a("p"),Qr=r("Here are the speedups we obtain on a few Nvidia GPUs when running the inference at 512x512 with a batch size of 1 (one prompt):"),fn=p(),ke=a("table"),Vs=a("thead"),K=a("tr"),Gs=a("th"),Jr=r("GPU"),Zr=p(),Hs=a("th"),ei=r("Base Attention FP16"),ti=p(),Ms=a("th"),si=r("Memory Efficient Attention FP16"),ai=p(),w=a("tbody"),Q=a("tr"),Bs=a("td"),ni=r("NVIDIA Tesla T4"),oi=p(),Os=a("td"),ri=r("3.5it/s"),ii=p(),Ls=a("td"),li=r("5.5it/s"),pi=p(),J=a("tr"),Xs=a("td"),fi=r("NVIDIA 3060 RTX"),ci=p(),Ys=a("td"),hi=r("4.6it/s"),ui=p(),Ws=a("td"),mi=r("7.8it/s"),di=p(),Z=a("tr"),Ks=a("td"),_i=r("NVIDIA A10G"),vi=p(),Qs=a("td"),yi=r("8.88it/s"),bi=p(),Js=a("td"),wi=r("15.6it/s"),gi=p(),ee=a("tr"),Zs=a("td"),$i=r("NVIDIA RTX A6000"),Ei=p(),ea=a("td"),ji=r("11.7it/s"),ki=p(),ta=a("td"),Ti=r("21.09it/s"),Di=p(),te=a("tr"),sa=a("td"),Ai=r("NVIDIA TITAN RTX"),Pi=p(),aa=a("td"),Si=r("12.51it/s"),xi=p(),na=a("td"),Ni=r("18.22it/s"),qi=p(),se=a("tr"),oa=a("td"),Ii=r("A100-SXM4-40GB"),Ui=p(),ra=a("td"),Ci=r("18.6it/s"),Ri=p(),ia=a("td"),Fi=r("29.it/s"),zi=p(),ae=a("tr"),la=a("td"),Vi=r("A100-SXM-80GB"),Gi=p(),pa=a("td"),Hi=r("18.7it/s"),Mi=p(),fa=a("td"),Bi=r("29.5it/s"),cn=p(),$t=a("p"),Oi=r("To leverage it just make sure you have:"),hn=p(),N=a("ul"),ca=a("li"),Li=r("PyTorch > 1.12"),Xi=p(),ha=a("li"),Yi=r("Cuda available"),Wi=p(),Et=a("li"),jt=a("a"),Ki=r("Installed the xformers library"),Qi=r("."),un=p(),u(et.$$.fragment),this.h()},l(e){const l=ff('[data-svelte="svelte-1phssyn"]',document.head);b=n(l,"META",{name:!0,content:!0}),l.forEach(s),g=f(e),j=n(e,"H1",{class:!0});var tt=o(j);oe=n(tt,"A",{id:!0,class:!0,href:!0});var ua=o(oe);Bt=n(ua,"SPAN",{});var el=o(Bt);m(De.$$.fragment,el),el.forEach(s),ua.forEach(s),qn=f(tt),Ot=n(tt,"SPAN",{});var tl=o(Ot);In=i(tl,"Memory and speed"),tl.forEach(s),tt.forEach(s),ma=f(e),T=n(e,"P",{});var Te=o(T);Un=i(Te,"We present some techniques and ideas to optimize \u{1F917} Diffusers "),Lt=n(Te,"EM",{});var sl=o(Lt);Cn=i(sl,"inference"),sl.forEach(s),Rn=i(Te," for memory or speed. As a general rule, we recommend the use of "),Ae=n(Te,"A",{href:!0,rel:!0});var al=o(Ae);Fn=i(al,"xFormers"),al.forEach(s),zn=i(Te," for memory efficient attention, please see the recommended "),at=n(Te,"A",{href:!0});var nl=o(at);Vn=i(nl,"installation instructions"),nl.forEach(s),Gn=i(Te,"."),Te.forEach(s),da=f(e),nt=n(e,"P",{});var ol=o(nt);Hn=i(ol,"We\u2019ll discuss how the following settings impact performance and memory."),ol.forEach(s),_a=f(e),re=n(e,"TABLE",{});var dn=o(re);Xt=n(dn,"THEAD",{});var rl=o(Xt);I=n(rl,"TR",{});var kt=o(I);va=n(kt,"TH",{}),o(va).forEach(s),Mn=f(kt),Yt=n(kt,"TH",{});var il=o(Yt);Bn=i(il,"Latency"),il.forEach(s),On=f(kt),Wt=n(kt,"TH",{});var ll=o(Wt);Ln=i(ll,"Speedup"),ll.forEach(s),kt.forEach(s),rl.forEach(s),Xn=f(dn),$=n(dn,"TBODY",{});var D=o($);U=n(D,"TR",{});var Tt=o(U);Kt=n(Tt,"TD",{});var pl=o(Kt);Yn=i(pl,"original"),pl.forEach(s),Wn=f(Tt),Qt=n(Tt,"TD",{});var fl=o(Qt);Kn=i(fl,"9.50s"),fl.forEach(s),Qn=f(Tt),Jt=n(Tt,"TD",{});var cl=o(Jt);Jn=i(cl,"x1"),cl.forEach(s),Tt.forEach(s),Zn=f(D),C=n(D,"TR",{});var Dt=o(C);Zt=n(Dt,"TD",{});var hl=o(Zt);eo=i(hl,"cuDNN auto-tuner"),hl.forEach(s),to=f(Dt),es=n(Dt,"TD",{});var ul=o(es);so=i(ul,"9.37s"),ul.forEach(s),ao=f(Dt),ts=n(Dt,"TD",{});var ml=o(ts);no=i(ml,"x1.01"),ml.forEach(s),Dt.forEach(s),oo=f(D),R=n(D,"TR",{});var At=o(R);ss=n(At,"TD",{});var dl=o(ss);ro=i(dl,"fp16"),dl.forEach(s),io=f(At),as=n(At,"TD",{});var _l=o(as);lo=i(_l,"3.61s"),_l.forEach(s),po=f(At),ns=n(At,"TD",{});var vl=o(ns);fo=i(vl,"x2.63"),vl.forEach(s),At.forEach(s),co=f(D),F=n(D,"TR",{});var Pt=o(F);os=n(Pt,"TD",{});var yl=o(os);ho=i(yl,"channels last"),yl.forEach(s),uo=f(Pt),rs=n(Pt,"TD",{});var bl=o(rs);mo=i(bl,"3.30s"),bl.forEach(s),_o=f(Pt),is=n(Pt,"TD",{});var wl=o(is);vo=i(wl,"x2.88"),wl.forEach(s),Pt.forEach(s),yo=f(D),z=n(D,"TR",{});var St=o(z);ls=n(St,"TD",{});var gl=o(ls);bo=i(gl,"traced UNet"),gl.forEach(s),wo=f(St),ps=n(St,"TD",{});var $l=o(ps);go=i($l,"3.21s"),$l.forEach(s),$o=f(St),fs=n(St,"TD",{});var El=o(fs);Eo=i(El,"x2.96"),El.forEach(s),St.forEach(s),jo=f(D),V=n(D,"TR",{});var xt=o(V);cs=n(xt,"TD",{});var jl=o(cs);ko=i(jl,"memory efficient attention"),jl.forEach(s),To=f(xt),hs=n(xt,"TD",{});var kl=o(hs);Do=i(kl,"2.63s"),kl.forEach(s),Ao=f(xt),us=n(xt,"TD",{});var Tl=o(us);Po=i(Tl,"x3.61"),Tl.forEach(s),xt.forEach(s),D.forEach(s),dn.forEach(s),ya=f(e),ot=n(e,"EM",{});var Dl=o(ot);So=i(Dl,`obtained on NVIDIA TITAN RTX by generating a single image of size 512x512 from
  the prompt "a photo of an astronaut riding a horse on mars" with 50 DDIM
  steps.`),Dl.forEach(s),ba=f(e),G=n(e,"H2",{class:!0});var _n=o(G);ie=n(_n,"A",{id:!0,class:!0,href:!0});var Al=o(ie);ms=n(Al,"SPAN",{});var Pl=o(ms);m(Pe.$$.fragment,Pl),Pl.forEach(s),Al.forEach(s),xo=f(_n),ds=n(_n,"SPAN",{});var Sl=o(ds);No=i(Sl,"Enable cuDNN auto-tuner"),Sl.forEach(s),_n.forEach(s),wa=f(e),Se=n(e,"P",{});var Ji=o(Se);xe=n(Ji,"A",{href:!0,rel:!0});var xl=o(xe);qo=i(xl,"NVIDIA cuDNN"),xl.forEach(s),Io=i(Ji,"\xA0supports many algorithms to compute a convolution. Autotuner runs a short benchmark and selects the kernel with the best performance on a given hardware for a given input size."),Ji.forEach(s),ga=f(e),le=n(e,"P",{});var vn=o(le);Uo=i(vn,"Since we\u2019re using "),_s=n(vn,"STRONG",{});var Nl=o(_s);Co=i(Nl,"convolutional networks"),Nl.forEach(s),Ro=i(vn," (other types currently not supported), we can enable cuDNN autotuner before launching the inference by setting:"),vn.forEach(s),$a=f(e),m(Ne.$$.fragment,e),Ea=f(e),H=n(e,"H3",{class:!0});var yn=o(H);pe=n(yn,"A",{id:!0,class:!0,href:!0});var ql=o(pe);vs=n(ql,"SPAN",{});var Il=o(vs);m(qe.$$.fragment,Il),Il.forEach(s),ql.forEach(s),Fo=f(yn),ys=n(yn,"SPAN",{});var Ul=o(ys);zo=i(Ul,"Use tf32 instead of fp32 (on Ampere and later CUDA devices)"),Ul.forEach(s),yn.forEach(s),ja=f(e),fe=n(e,"P",{});var bn=o(fe);Vo=i(bn,"On Ampere and later CUDA devices matrix multiplications and convolutions can use the TensorFloat32 (TF32) mode for faster but slightly less accurate computations. By default PyTorch enables TF32 mode for convolutions but not matrix multiplications, and unless a network requires full float32 precision we recommend enabling this setting for matrix multiplications, too. It can significantly speed up computations with typically negligible loss of numerical accuracy. You can read more about it "),Ie=n(bn,"A",{href:!0,rel:!0});var Cl=o(Ie);Go=i(Cl,"here"),Cl.forEach(s),Ho=i(bn,". All you need to do is to add this before your inference:"),bn.forEach(s),ka=f(e),m(Ue.$$.fragment,e),Ta=f(e),M=n(e,"H2",{class:!0});var wn=o(M);ce=n(wn,"A",{id:!0,class:!0,href:!0});var Rl=o(ce);bs=n(Rl,"SPAN",{});var Fl=o(bs);m(Ce.$$.fragment,Fl),Fl.forEach(s),Rl.forEach(s),Mo=f(wn),ws=n(wn,"SPAN",{});var zl=o(ws);Bo=i(zl,"Half precision weights"),zl.forEach(s),wn.forEach(s),Da=f(e),P=n(e,"P",{});var Nt=o(P);Oo=i(Nt,"To save more GPU memory and get more speed, you can load and run the model weights directly in half precision. This involves loading the float16 version of the weights, which was saved to a branch named "),gs=n(Nt,"CODE",{});var Vl=o(gs);Lo=i(Vl,"fp16"),Vl.forEach(s),Xo=i(Nt,", and telling PyTorch to use the "),$s=n(Nt,"CODE",{});var Gl=o($s);Yo=i(Gl,"float16"),Gl.forEach(s),Wo=i(Nt," type when loading them:"),Nt.forEach(s),Aa=f(e),m(Re.$$.fragment,e),Pa=f(e),m(he.$$.fragment,e),Sa=f(e),B=n(e,"H2",{class:!0});var gn=o(B);ue=n(gn,"A",{id:!0,class:!0,href:!0});var Hl=o(ue);Es=n(Hl,"SPAN",{});var Ml=o(Es);m(Fe.$$.fragment,Ml),Ml.forEach(s),Hl.forEach(s),Ko=f(gn),js=n(gn,"SPAN",{});var Bl=o(js);Qo=i(Bl,"Sliced attention for additional memory savings"),Bl.forEach(s),gn.forEach(s),xa=f(e),rt=n(e,"P",{});var Ol=o(rt);Jo=i(Ol,"For even additional memory savings, you can use a sliced version of attention that performs the computation in steps instead of all at once."),Ol.forEach(s),Na=f(e),m(me.$$.fragment,e),qa=f(e),de=n(e,"P",{});var $n=o(de);Zo=i($n,"To perform the attention computation sequentially over each head, you only need to invoke "),it=n($n,"A",{href:!0});var Ll=o(it);er=i(Ll,"enable_attention_slicing()"),Ll.forEach(s),tr=i($n," in your pipeline before inference, like here:"),$n.forEach(s),Ia=f(e),m(ze.$$.fragment,e),Ua=f(e),lt=n(e,"P",{});var Xl=o(lt);sr=i(Xl,"There\u2019s a small performance penalty of about 10% slower inference times, but this method allows you to use Stable Diffusion in as little as 3.2 GB of VRAM!"),Xl.forEach(s),Ca=f(e),O=n(e,"H2",{class:!0});var En=o(O);_e=n(En,"A",{id:!0,class:!0,href:!0});var Yl=o(_e);ks=n(Yl,"SPAN",{});var Wl=o(ks);m(Ve.$$.fragment,Wl),Wl.forEach(s),Yl.forEach(s),ar=f(En),Ts=n(En,"SPAN",{});var Kl=o(Ts);nr=i(Kl,"Sliced VAE decode for larger batches"),Kl.forEach(s),En.forEach(s),Ra=f(e),pt=n(e,"P",{});var Ql=o(pt);or=i(Ql,"To decode large batches of images with limited VRAM, or to enable batches with 32 images or more, you can use sliced VAE decode that decodes the batch latents one image at a time."),Ql.forEach(s),Fa=f(e),S=n(e,"P",{});var qt=o(S);rr=i(qt,"You likely want to couple this with "),ft=n(qt,"A",{href:!0});var Jl=o(ft);ir=i(Jl,"enable_attention_slicing()"),Jl.forEach(s),lr=i(qt," or "),ct=n(qt,"A",{href:!0});var Zl=o(ct);pr=i(Zl,"enable_xformers_memory_efficient_attention()"),Zl.forEach(s),fr=i(qt," to further minimize memory use."),qt.forEach(s),za=f(e),ve=n(e,"P",{});var jn=o(ve);cr=i(jn,"To perform the VAE decode one image at a time, invoke "),ht=n(jn,"A",{href:!0});var ep=o(ht);hr=i(ep,"enable_vae_slicing()"),ep.forEach(s),ur=i(jn," in your pipeline before inference. For example:"),jn.forEach(s),Va=f(e),m(Ge.$$.fragment,e),Ga=f(e),ut=n(e,"P",{});var tp=o(ut);mr=i(tp,"You may see a small performance boost in VAE decode on multi-image batches. There should be no performance impact on single-image batches."),tp.forEach(s),Ha=f(e),L=n(e,"H2",{class:!0});var kn=o(L);ye=n(kn,"A",{id:!0,class:!0,href:!0});var sp=o(ye);Ds=n(sp,"SPAN",{});var ap=o(Ds);m(He.$$.fragment,ap),ap.forEach(s),sp.forEach(s),dr=f(kn),As=n(kn,"SPAN",{});var np=o(As);_r=i(np,"Offloading to CPU with accelerate for memory savings"),np.forEach(s),kn.forEach(s),Ma=f(e),mt=n(e,"P",{});var op=o(mt);vr=i(op,"For additional memory savings, you can offload the weights to CPU and only load them to GPU when performing the forward pass."),op.forEach(s),Ba=f(e),be=n(e,"P",{});var Tn=o(be);yr=i(Tn,"To perform CPU offloading, all you have to do is invoke "),dt=n(Tn,"A",{href:!0});var rp=o(dt);br=i(rp,"enable_sequential_cpu_offload()"),rp.forEach(s),wr=i(Tn,":"),Tn.forEach(s),Oa=f(e),m(Me.$$.fragment,e),La=f(e),_t=n(e,"P",{});var ip=o(_t);gr=i(ip,"And you can get the memory consumption to < 3GB."),ip.forEach(s),Xa=f(e),vt=n(e,"P",{});var lp=o(vt);$r=i(lp,"If is also possible to chain it with attention slicing for minimal memory consumption (< 2GB)."),lp.forEach(s),Ya=f(e),m(Be.$$.fragment,e),Wa=f(e),k=n(e,"P",{});var ne=o(k);Ps=n(ne,"STRONG",{});var pp=o(Ps);Er=i(pp,"Note"),pp.forEach(s),jr=i(ne,": When using "),Ss=n(ne,"CODE",{});var fp=o(Ss);kr=i(fp,"enable_sequential_cpu_offload()"),fp.forEach(s),Tr=i(ne,", it is important to "),xs=n(ne,"STRONG",{});var cp=o(xs);Dr=i(cp,"not"),cp.forEach(s),Ar=i(ne," move the pipeline to CUDA beforehand or else the gain in memory consumption will only be minimal. See "),Oe=n(ne,"A",{href:!0,rel:!0});var hp=o(Oe);Pr=i(hp,"this issue"),hp.forEach(s),Sr=i(ne," for more information."),ne.forEach(s),Ka=f(e),X=n(e,"H2",{class:!0});var Dn=o(X);we=n(Dn,"A",{id:!0,class:!0,href:!0});var up=o(we);Ns=n(up,"SPAN",{});var mp=o(Ns);m(Le.$$.fragment,mp),mp.forEach(s),up.forEach(s),xr=f(Dn),qs=n(Dn,"SPAN",{});var dp=o(qs);Nr=i(dp,"Using Channels Last memory format"),dp.forEach(s),Dn.forEach(s),Qa=f(e),yt=n(e,"P",{});var _p=o(yt);qr=i(_p,"Channels last memory format is an alternative way of ordering NCHW tensors in memory preserving dimensions ordering. Channels last tensors ordered in such a way that channels become the densest dimension (aka storing images pixel-per-pixel). Since not all operators currently support channels last format it may result in a worst performance, so it\u2019s better to try it and see if it works for your model."),_p.forEach(s),Ja=f(e),bt=n(e,"P",{});var vp=o(bt);Ir=i(vp,"For example, in order to set the UNet model in our pipeline to use channels last format, we can use the following:"),vp.forEach(s),Za=f(e),m(Xe.$$.fragment,e),en=f(e),Y=n(e,"H2",{class:!0});var An=o(Y);ge=n(An,"A",{id:!0,class:!0,href:!0});var yp=o(ge);Is=n(yp,"SPAN",{});var bp=o(Is);m(Ye.$$.fragment,bp),bp.forEach(s),yp.forEach(s),Ur=f(An),Us=n(An,"SPAN",{});var wp=o(Us);Cr=i(wp,"Tracing"),wp.forEach(s),An.forEach(s),tn=f(e),$e=n(e,"P",{});var Pn=o($e);Rr=i(Pn,"Tracing runs an example input tensor through your model, and captures the operations that are invoked as that input makes its way through the model\u2019s layers so that an executable or "),Cs=n(Pn,"CODE",{});var gp=o(Cs);Fr=i(gp,"ScriptFunction"),gp.forEach(s),zr=i(Pn," is returned that will be optimized using just-in-time compilation."),Pn.forEach(s),sn=f(e),wt=n(e,"P",{});var $p=o(wt);Vr=i($p,"To trace our UNet model, we can use the following:"),$p.forEach(s),an=f(e),m(We.$$.fragment,e),nn=f(e),Ee=n(e,"P",{});var Sn=o(Ee);Gr=i(Sn,"Then we can replace the "),Rs=n(Sn,"CODE",{});var Ep=o(Rs);Hr=i(Ep,"unet"),Ep.forEach(s),Mr=i(Sn," attribute of the pipeline with the traced model like the following"),Sn.forEach(s),on=f(e),m(Ke.$$.fragment,e),rn=f(e),W=n(e,"H2",{class:!0});var xn=o(W);je=n(xn,"A",{id:!0,class:!0,href:!0});var jp=o(je);Fs=n(jp,"SPAN",{});var kp=o(Fs);m(Qe.$$.fragment,kp),kp.forEach(s),jp.forEach(s),Br=f(xn),zs=n(xn,"SPAN",{});var Tp=o(zs);Or=i(Tp,"Memory Efficient Attention"),Tp.forEach(s),xn.forEach(s),ln=f(e),x=n(e,"P",{});var It=o(x);Lr=i(It,"Recent work on optimizing the bandwitdh in the attention block has generated huge speed ups and gains in GPU memory usage. The most recent being Flash Attention from @tridao: "),Je=n(It,"A",{href:!0,rel:!0});var Dp=o(Je);Xr=i(Dp,"code"),Dp.forEach(s),Yr=i(It,", "),Ze=n(It,"A",{href:!0,rel:!0});var Ap=o(Ze);Wr=i(Ap,"paper"),Ap.forEach(s),Kr=i(It,"."),It.forEach(s),pn=f(e),gt=n(e,"P",{});var Pp=o(gt);Qr=i(Pp,"Here are the speedups we obtain on a few Nvidia GPUs when running the inference at 512x512 with a batch size of 1 (one prompt):"),Pp.forEach(s),fn=f(e),ke=n(e,"TABLE",{});var Nn=o(ke);Vs=n(Nn,"THEAD",{});var Sp=o(Vs);K=n(Sp,"TR",{});var Ut=o(K);Gs=n(Ut,"TH",{});var xp=o(Gs);Jr=i(xp,"GPU"),xp.forEach(s),Zr=f(Ut),Hs=n(Ut,"TH",{});var Np=o(Hs);ei=i(Np,"Base Attention FP16"),Np.forEach(s),ti=f(Ut),Ms=n(Ut,"TH",{});var qp=o(Ms);si=i(qp,"Memory Efficient Attention FP16"),qp.forEach(s),Ut.forEach(s),Sp.forEach(s),ai=f(Nn),w=n(Nn,"TBODY",{});var E=o(w);Q=n(E,"TR",{});var Ct=o(Q);Bs=n(Ct,"TD",{});var Ip=o(Bs);ni=i(Ip,"NVIDIA Tesla T4"),Ip.forEach(s),oi=f(Ct),Os=n(Ct,"TD",{});var Up=o(Os);ri=i(Up,"3.5it/s"),Up.forEach(s),ii=f(Ct),Ls=n(Ct,"TD",{});var Cp=o(Ls);li=i(Cp,"5.5it/s"),Cp.forEach(s),Ct.forEach(s),pi=f(E),J=n(E,"TR",{});var Rt=o(J);Xs=n(Rt,"TD",{});var Rp=o(Xs);fi=i(Rp,"NVIDIA 3060 RTX"),Rp.forEach(s),ci=f(Rt),Ys=n(Rt,"TD",{});var Fp=o(Ys);hi=i(Fp,"4.6it/s"),Fp.forEach(s),ui=f(Rt),Ws=n(Rt,"TD",{});var zp=o(Ws);mi=i(zp,"7.8it/s"),zp.forEach(s),Rt.forEach(s),di=f(E),Z=n(E,"TR",{});var Ft=o(Z);Ks=n(Ft,"TD",{});var Vp=o(Ks);_i=i(Vp,"NVIDIA A10G"),Vp.forEach(s),vi=f(Ft),Qs=n(Ft,"TD",{});var Gp=o(Qs);yi=i(Gp,"8.88it/s"),Gp.forEach(s),bi=f(Ft),Js=n(Ft,"TD",{});var Hp=o(Js);wi=i(Hp,"15.6it/s"),Hp.forEach(s),Ft.forEach(s),gi=f(E),ee=n(E,"TR",{});var zt=o(ee);Zs=n(zt,"TD",{});var Mp=o(Zs);$i=i(Mp,"NVIDIA RTX A6000"),Mp.forEach(s),Ei=f(zt),ea=n(zt,"TD",{});var Bp=o(ea);ji=i(Bp,"11.7it/s"),Bp.forEach(s),ki=f(zt),ta=n(zt,"TD",{});var Op=o(ta);Ti=i(Op,"21.09it/s"),Op.forEach(s),zt.forEach(s),Di=f(E),te=n(E,"TR",{});var Vt=o(te);sa=n(Vt,"TD",{});var Lp=o(sa);Ai=i(Lp,"NVIDIA TITAN RTX"),Lp.forEach(s),Pi=f(Vt),aa=n(Vt,"TD",{});var Xp=o(aa);Si=i(Xp,"12.51it/s"),Xp.forEach(s),xi=f(Vt),na=n(Vt,"TD",{});var Yp=o(na);Ni=i(Yp,"18.22it/s"),Yp.forEach(s),Vt.forEach(s),qi=f(E),se=n(E,"TR",{});var Gt=o(se);oa=n(Gt,"TD",{});var Wp=o(oa);Ii=i(Wp,"A100-SXM4-40GB"),Wp.forEach(s),Ui=f(Gt),ra=n(Gt,"TD",{});var Kp=o(ra);Ci=i(Kp,"18.6it/s"),Kp.forEach(s),Ri=f(Gt),ia=n(Gt,"TD",{});var Qp=o(ia);Fi=i(Qp,"29.it/s"),Qp.forEach(s),Gt.forEach(s),zi=f(E),ae=n(E,"TR",{});var Ht=o(ae);la=n(Ht,"TD",{});var Jp=o(la);Vi=i(Jp,"A100-SXM-80GB"),Jp.forEach(s),Gi=f(Ht),pa=n(Ht,"TD",{});var Zp=o(pa);Hi=i(Zp,"18.7it/s"),Zp.forEach(s),Mi=f(Ht),fa=n(Ht,"TD",{});var ef=o(fa);Bi=i(ef,"29.5it/s"),ef.forEach(s),Ht.forEach(s),E.forEach(s),Nn.forEach(s),cn=f(e),$t=n(e,"P",{});var tf=o($t);Oi=i(tf,"To leverage it just make sure you have:"),tf.forEach(s),hn=f(e),N=n(e,"UL",{});var Mt=o(N);ca=n(Mt,"LI",{});var sf=o(ca);Li=i(sf,"PyTorch > 1.12"),sf.forEach(s),Xi=f(Mt),ha=n(Mt,"LI",{});var af=o(ha);Yi=i(af,"Cuda available"),af.forEach(s),Wi=f(Mt),Et=n(Mt,"LI",{});var Zi=o(Et);jt=n(Zi,"A",{href:!0});var nf=o(jt);Ki=i(nf,"Installed the xformers library"),nf.forEach(s),Qi=i(Zi,"."),Zi.forEach(s),Mt.forEach(s),un=f(e),m(et.$$.fragment,e),this.h()},h(){h(b,"name","hf:doc:metadata"),h(b,"content",JSON.stringify(df)),h(oe,"id","memory-and-speed"),h(oe,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),h(oe,"href","#memory-and-speed"),h(j,"class","relative group"),h(Ae,"href","https://github.com/facebookresearch/xformers"),h(Ae,"rel","nofollow"),h(at,"href","xformers"),h(ie,"id","enable-cudnn-autotuner"),h(ie,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),h(ie,"href","#enable-cudnn-autotuner"),h(G,"class","relative group"),h(xe,"href","https://developer.nvidia.com/cudnn"),h(xe,"rel","nofollow"),h(pe,"id","use-tf32-instead-of-fp32-on-ampere-and-later-cuda-devices"),h(pe,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),h(pe,"href","#use-tf32-instead-of-fp32-on-ampere-and-later-cuda-devices"),h(H,"class","relative group"),h(Ie,"href","https://huggingface.co/docs/transformers/v4.18.0/en/performance#tf32"),h(Ie,"rel","nofollow"),h(ce,"id","half-precision-weights"),h(ce,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),h(ce,"href","#half-precision-weights"),h(M,"class","relative group"),h(ue,"id","sliced-attention-for-additional-memory-savings"),h(ue,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),h(ue,"href","#sliced-attention-for-additional-memory-savings"),h(B,"class","relative group"),h(it,"href","/docs/diffusers/v0.12.0/en/api/pipelines/stable_diffusion/inpaint#diffusers.StableDiffusionInpaintPipeline.enable_attention_slicing"),h(_e,"id","sliced-vae-decode-for-larger-batches"),h(_e,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),h(_e,"href","#sliced-vae-decode-for-larger-batches"),h(O,"class","relative group"),h(ft,"href","/docs/diffusers/v0.12.0/en/api/pipelines/stable_diffusion/inpaint#diffusers.StableDiffusionInpaintPipeline.enable_attention_slicing"),h(ct,"href","/docs/diffusers/v0.12.0/en/api/pipelines/stable_diffusion/inpaint#diffusers.StableDiffusionInpaintPipeline.enable_xformers_memory_efficient_attention"),h(ht,"href","/docs/diffusers/v0.12.0/en/api/pipelines/stable_diffusion/text2img#diffusers.StableDiffusionPipeline.enable_vae_slicing"),h(ye,"id","offloading-to-cpu-with-accelerate-for-memory-savings"),h(ye,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),h(ye,"href","#offloading-to-cpu-with-accelerate-for-memory-savings"),h(L,"class","relative group"),h(dt,"href","/docs/diffusers/v0.12.0/en/api/pipelines/stable_diffusion/text2img#diffusers.StableDiffusionPipeline.enable_sequential_cpu_offload"),h(Oe,"href","https://github.com/huggingface/diffusers/issues/1934"),h(Oe,"rel","nofollow"),h(we,"id","using-channels-last-memory-format"),h(we,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),h(we,"href","#using-channels-last-memory-format"),h(X,"class","relative group"),h(ge,"id","tracing"),h(ge,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),h(ge,"href","#tracing"),h(Y,"class","relative group"),h(je,"id","memory-efficient-attention"),h(je,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),h(je,"href","#memory-efficient-attention"),h(W,"class","relative group"),h(Je,"href","https://github.com/HazyResearch/flash-attention"),h(Je,"rel","nofollow"),h(Ze,"href","https://arxiv.org/pdf/2205.14135.pdf"),h(Ze,"rel","nofollow"),h(jt,"href","xformers")},m(e,l){t(document.head,b),c(e,g,l),c(e,j,l),t(j,oe),t(oe,Bt),d(De,Bt,null),t(j,qn),t(j,Ot),t(Ot,In),c(e,ma,l),c(e,T,l),t(T,Un),t(T,Lt),t(Lt,Cn),t(T,Rn),t(T,Ae),t(Ae,Fn),t(T,zn),t(T,at),t(at,Vn),t(T,Gn),c(e,da,l),c(e,nt,l),t(nt,Hn),c(e,_a,l),c(e,re,l),t(re,Xt),t(Xt,I),t(I,va),t(I,Mn),t(I,Yt),t(Yt,Bn),t(I,On),t(I,Wt),t(Wt,Ln),t(re,Xn),t(re,$),t($,U),t(U,Kt),t(Kt,Yn),t(U,Wn),t(U,Qt),t(Qt,Kn),t(U,Qn),t(U,Jt),t(Jt,Jn),t($,Zn),t($,C),t(C,Zt),t(Zt,eo),t(C,to),t(C,es),t(es,so),t(C,ao),t(C,ts),t(ts,no),t($,oo),t($,R),t(R,ss),t(ss,ro),t(R,io),t(R,as),t(as,lo),t(R,po),t(R,ns),t(ns,fo),t($,co),t($,F),t(F,os),t(os,ho),t(F,uo),t(F,rs),t(rs,mo),t(F,_o),t(F,is),t(is,vo),t($,yo),t($,z),t(z,ls),t(ls,bo),t(z,wo),t(z,ps),t(ps,go),t(z,$o),t(z,fs),t(fs,Eo),t($,jo),t($,V),t(V,cs),t(cs,ko),t(V,To),t(V,hs),t(hs,Do),t(V,Ao),t(V,us),t(us,Po),c(e,ya,l),c(e,ot,l),t(ot,So),c(e,ba,l),c(e,G,l),t(G,ie),t(ie,ms),d(Pe,ms,null),t(G,xo),t(G,ds),t(ds,No),c(e,wa,l),c(e,Se,l),t(Se,xe),t(xe,qo),t(Se,Io),c(e,ga,l),c(e,le,l),t(le,Uo),t(le,_s),t(_s,Co),t(le,Ro),c(e,$a,l),d(Ne,e,l),c(e,Ea,l),c(e,H,l),t(H,pe),t(pe,vs),d(qe,vs,null),t(H,Fo),t(H,ys),t(ys,zo),c(e,ja,l),c(e,fe,l),t(fe,Vo),t(fe,Ie),t(Ie,Go),t(fe,Ho),c(e,ka,l),d(Ue,e,l),c(e,Ta,l),c(e,M,l),t(M,ce),t(ce,bs),d(Ce,bs,null),t(M,Mo),t(M,ws),t(ws,Bo),c(e,Da,l),c(e,P,l),t(P,Oo),t(P,gs),t(gs,Lo),t(P,Xo),t(P,$s),t($s,Yo),t(P,Wo),c(e,Aa,l),d(Re,e,l),c(e,Pa,l),d(he,e,l),c(e,Sa,l),c(e,B,l),t(B,ue),t(ue,Es),d(Fe,Es,null),t(B,Ko),t(B,js),t(js,Qo),c(e,xa,l),c(e,rt,l),t(rt,Jo),c(e,Na,l),d(me,e,l),c(e,qa,l),c(e,de,l),t(de,Zo),t(de,it),t(it,er),t(de,tr),c(e,Ia,l),d(ze,e,l),c(e,Ua,l),c(e,lt,l),t(lt,sr),c(e,Ca,l),c(e,O,l),t(O,_e),t(_e,ks),d(Ve,ks,null),t(O,ar),t(O,Ts),t(Ts,nr),c(e,Ra,l),c(e,pt,l),t(pt,or),c(e,Fa,l),c(e,S,l),t(S,rr),t(S,ft),t(ft,ir),t(S,lr),t(S,ct),t(ct,pr),t(S,fr),c(e,za,l),c(e,ve,l),t(ve,cr),t(ve,ht),t(ht,hr),t(ve,ur),c(e,Va,l),d(Ge,e,l),c(e,Ga,l),c(e,ut,l),t(ut,mr),c(e,Ha,l),c(e,L,l),t(L,ye),t(ye,Ds),d(He,Ds,null),t(L,dr),t(L,As),t(As,_r),c(e,Ma,l),c(e,mt,l),t(mt,vr),c(e,Ba,l),c(e,be,l),t(be,yr),t(be,dt),t(dt,br),t(be,wr),c(e,Oa,l),d(Me,e,l),c(e,La,l),c(e,_t,l),t(_t,gr),c(e,Xa,l),c(e,vt,l),t(vt,$r),c(e,Ya,l),d(Be,e,l),c(e,Wa,l),c(e,k,l),t(k,Ps),t(Ps,Er),t(k,jr),t(k,Ss),t(Ss,kr),t(k,Tr),t(k,xs),t(xs,Dr),t(k,Ar),t(k,Oe),t(Oe,Pr),t(k,Sr),c(e,Ka,l),c(e,X,l),t(X,we),t(we,Ns),d(Le,Ns,null),t(X,xr),t(X,qs),t(qs,Nr),c(e,Qa,l),c(e,yt,l),t(yt,qr),c(e,Ja,l),c(e,bt,l),t(bt,Ir),c(e,Za,l),d(Xe,e,l),c(e,en,l),c(e,Y,l),t(Y,ge),t(ge,Is),d(Ye,Is,null),t(Y,Ur),t(Y,Us),t(Us,Cr),c(e,tn,l),c(e,$e,l),t($e,Rr),t($e,Cs),t(Cs,Fr),t($e,zr),c(e,sn,l),c(e,wt,l),t(wt,Vr),c(e,an,l),d(We,e,l),c(e,nn,l),c(e,Ee,l),t(Ee,Gr),t(Ee,Rs),t(Rs,Hr),t(Ee,Mr),c(e,on,l),d(Ke,e,l),c(e,rn,l),c(e,W,l),t(W,je),t(je,Fs),d(Qe,Fs,null),t(W,Br),t(W,zs),t(zs,Or),c(e,ln,l),c(e,x,l),t(x,Lr),t(x,Je),t(Je,Xr),t(x,Yr),t(x,Ze),t(Ze,Wr),t(x,Kr),c(e,pn,l),c(e,gt,l),t(gt,Qr),c(e,fn,l),c(e,ke,l),t(ke,Vs),t(Vs,K),t(K,Gs),t(Gs,Jr),t(K,Zr),t(K,Hs),t(Hs,ei),t(K,ti),t(K,Ms),t(Ms,si),t(ke,ai),t(ke,w),t(w,Q),t(Q,Bs),t(Bs,ni),t(Q,oi),t(Q,Os),t(Os,ri),t(Q,ii),t(Q,Ls),t(Ls,li),t(w,pi),t(w,J),t(J,Xs),t(Xs,fi),t(J,ci),t(J,Ys),t(Ys,hi),t(J,ui),t(J,Ws),t(Ws,mi),t(w,di),t(w,Z),t(Z,Ks),t(Ks,_i),t(Z,vi),t(Z,Qs),t(Qs,yi),t(Z,bi),t(Z,Js),t(Js,wi),t(w,gi),t(w,ee),t(ee,Zs),t(Zs,$i),t(ee,Ei),t(ee,ea),t(ea,ji),t(ee,ki),t(ee,ta),t(ta,Ti),t(w,Di),t(w,te),t(te,sa),t(sa,Ai),t(te,Pi),t(te,aa),t(aa,Si),t(te,xi),t(te,na),t(na,Ni),t(w,qi),t(w,se),t(se,oa),t(oa,Ii),t(se,Ui),t(se,ra),t(ra,Ci),t(se,Ri),t(se,ia),t(ia,Fi),t(w,zi),t(w,ae),t(ae,la),t(la,Vi),t(ae,Gi),t(ae,pa),t(pa,Hi),t(ae,Mi),t(ae,fa),t(fa,Bi),c(e,cn,l),c(e,$t,l),t($t,Oi),c(e,hn,l),c(e,N,l),t(N,ca),t(ca,Li),t(N,Xi),t(N,ha),t(ha,Yi),t(N,Wi),t(N,Et),t(Et,jt),t(jt,Ki),t(Et,Qi),c(e,un,l),d(et,e,l),mn=!0},p(e,[l]){const tt={};l&2&&(tt.$$scope={dirty:l,ctx:e}),he.$set(tt);const ua={};l&2&&(ua.$$scope={dirty:l,ctx:e}),me.$set(ua)},i(e){mn||(_(De.$$.fragment,e),_(Pe.$$.fragment,e),_(Ne.$$.fragment,e),_(qe.$$.fragment,e),_(Ue.$$.fragment,e),_(Ce.$$.fragment,e),_(Re.$$.fragment,e),_(he.$$.fragment,e),_(Fe.$$.fragment,e),_(me.$$.fragment,e),_(ze.$$.fragment,e),_(Ve.$$.fragment,e),_(Ge.$$.fragment,e),_(He.$$.fragment,e),_(Me.$$.fragment,e),_(Be.$$.fragment,e),_(Le.$$.fragment,e),_(Xe.$$.fragment,e),_(Ye.$$.fragment,e),_(We.$$.fragment,e),_(Ke.$$.fragment,e),_(Qe.$$.fragment,e),_(et.$$.fragment,e),mn=!0)},o(e){v(De.$$.fragment,e),v(Pe.$$.fragment,e),v(Ne.$$.fragment,e),v(qe.$$.fragment,e),v(Ue.$$.fragment,e),v(Ce.$$.fragment,e),v(Re.$$.fragment,e),v(he.$$.fragment,e),v(Fe.$$.fragment,e),v(me.$$.fragment,e),v(ze.$$.fragment,e),v(Ve.$$.fragment,e),v(Ge.$$.fragment,e),v(He.$$.fragment,e),v(Me.$$.fragment,e),v(Be.$$.fragment,e),v(Le.$$.fragment,e),v(Xe.$$.fragment,e),v(Ye.$$.fragment,e),v(We.$$.fragment,e),v(Ke.$$.fragment,e),v(Qe.$$.fragment,e),v(et.$$.fragment,e),mn=!1},d(e){s(b),e&&s(g),e&&s(j),y(De),e&&s(ma),e&&s(T),e&&s(da),e&&s(nt),e&&s(_a),e&&s(re),e&&s(ya),e&&s(ot),e&&s(ba),e&&s(G),y(Pe),e&&s(wa),e&&s(Se),e&&s(ga),e&&s(le),e&&s($a),y(Ne,e),e&&s(Ea),e&&s(H),y(qe),e&&s(ja),e&&s(fe),e&&s(ka),y(Ue,e),e&&s(Ta),e&&s(M),y(Ce),e&&s(Da),e&&s(P),e&&s(Aa),y(Re,e),e&&s(Pa),y(he,e),e&&s(Sa),e&&s(B),y(Fe),e&&s(xa),e&&s(rt),e&&s(Na),y(me,e),e&&s(qa),e&&s(de),e&&s(Ia),y(ze,e),e&&s(Ua),e&&s(lt),e&&s(Ca),e&&s(O),y(Ve),e&&s(Ra),e&&s(pt),e&&s(Fa),e&&s(S),e&&s(za),e&&s(ve),e&&s(Va),y(Ge,e),e&&s(Ga),e&&s(ut),e&&s(Ha),e&&s(L),y(He),e&&s(Ma),e&&s(mt),e&&s(Ba),e&&s(be),e&&s(Oa),y(Me,e),e&&s(La),e&&s(_t),e&&s(Xa),e&&s(vt),e&&s(Ya),y(Be,e),e&&s(Wa),e&&s(k),e&&s(Ka),e&&s(X),y(Le),e&&s(Qa),e&&s(yt),e&&s(Ja),e&&s(bt),e&&s(Za),y(Xe,e),e&&s(en),e&&s(Y),y(Ye),e&&s(tn),e&&s($e),e&&s(sn),e&&s(wt),e&&s(an),y(We,e),e&&s(nn),e&&s(Ee),e&&s(on),y(Ke,e),e&&s(rn),e&&s(W),y(Qe),e&&s(ln),e&&s(x),e&&s(pn),e&&s(gt),e&&s(fn),e&&s(ke),e&&s(cn),e&&s($t),e&&s(hn),e&&s(N),e&&s(un),y(et,e)}}}const df={local:"memory-and-speed",sections:[{local:"enable-cudnn-autotuner",sections:[{local:"use-tf32-instead-of-fp32-on-ampere-and-later-cuda-devices",title:"Use tf32 instead of fp32 (on Ampere and later CUDA devices)"}],title:"Enable cuDNN auto-tuner"},{local:"half-precision-weights",title:"Half precision weights"},{local:"sliced-attention-for-additional-memory-savings",title:"Sliced attention for additional memory savings"},{local:"sliced-vae-decode-for-larger-batches",title:"Sliced VAE decode for larger batches"},{local:"offloading-to-cpu-with-accelerate-for-memory-savings",title:"Offloading to CPU with accelerate for memory savings"},{local:"using-channels-last-memory-format",title:"Using Channels Last memory format"},{local:"tracing",title:"Tracing"},{local:"memory-efficient-attention",title:"Memory Efficient Attention"}],title:"Memory and speed"};function _f(st){return cf(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class gf extends rf{constructor(b){super();lf(this,b,_f,mf,pf,{})}}export{gf as default,df as metadata};
