import{S as vn,i as Jn,s as _n,e as i,k as f,w as h,t as a,M as Un,c as o,d as t,m as u,a as n,x as m,h as r,b as c,N as rt,G as l,g as p,y as d,q as y,o as b,B as M,v as Zn}from"../chunks/vendor-hf-doc-builder.js";import{T as gn}from"../chunks/Tip-hf-doc-builder.js";import{I as be}from"../chunks/IconCopyLink-hf-doc-builder.js";import{C as J}from"../chunks/CodeBlock-hf-doc-builder.js";import{D as Tn}from"../chunks/DocNotebookDropdown-hf-doc-builder.js";function Gn(nt){let w,T,g,U,Z;return{c(){w=i("p"),T=a("\u{1F4A1} If you don\u2019t have access to a GPU, you can use one for free from a GPU provider like "),g=i("a"),U=a("Colab"),Z=a("!"),this.h()},l(v){w=o(v,"P",{});var _=n(w);T=r(_,"\u{1F4A1} If you don\u2019t have access to a GPU, you can use one for free from a GPU provider like "),g=o(_,"A",{href:!0,rel:!0});var $=n(g);U=r($,"Colab"),$.forEach(t),Z=r(_,"!"),_.forEach(t),this.h()},h(){c(g,"href","https://colab.research.google.com/"),c(g,"rel","nofollow")},m(v,_){p(v,w,_),l(w,T),l(w,g),l(g,U),l(w,Z)},d(v){v&&t(w)}}}function jn(nt){let w,T,g,U,Z;return{c(){w=i("p"),T=a("\u{1F4A1} We strongly suggest always running your pipelines in "),g=i("code"),U=a("float16"),Z=a(", and so far, we\u2019ve rarely seen any degradation in output quality.")},l(v){w=o(v,"P",{});var _=n(w);T=r(_,"\u{1F4A1} We strongly suggest always running your pipelines in "),g=o(_,"CODE",{});var $=n(g);U=r($,"float16"),$.forEach(t),Z=r(_,", and so far, we\u2019ve rarely seen any degradation in output quality."),_.forEach(t)},m(v,_){p(v,w,_),l(w,T),l(w,g),l(g,U),l(w,Z)},d(v){v&&t(w)}}}function $n(nt){let w,T,g,U,Z,v,_,$,di,Il,Me,Wl,E,yi,pt,bi,Mi,ft,wi,gi,Bl,k,vi,zt,Ji,_i,Pt,Ui,Zi,Vl,Q,Ti,ut,Gi,ji,Nl,F,$i,we,Dt,Ei,ki,Cl,ge,Sl,ct,Ii,Rl,ve,Xl,R,Y,xt,Je,Wi,Ht,Bi,Al,q,zl,ht,Vi,Pl,_e,Dl,I,Ni,Ue,Qt,Ci,Si,mt,Ri,Xi,xl,Ze,Hl,dt,Ai,Ql,Te,Fl,Ge,Ft,Sa,Yl,G,zi,yt,Pi,Di,Yt,xi,Hi,qt,Qi,Fi,ql,L,Yi,Lt,qi,Li,Ll,je,Kl,$e,Kt,Ra,Ol,bt,Ki,es,K,ts,W,Oi,Mt,eo,to,Ot,lo,so,ls,Ee,ss,j,io,wt,oo,ao,gt,ro,no,vt,po,fo,is,ke,os,O,uo,el,co,ho,as,Ie,rs,We,tl,Xa,ns,Jt,mo,ps,X,ee,ll,Be,yo,sl,bo,fs,te,Mo,il,wo,go,us,B,vo,ol,Jo,_o,al,Uo,Zo,cs,Ve,hs,_t,To,ms,Ne,ds,le,Go,rl,jo,$o,ys,Ce,bs,V,Eo,nl,ko,Io,Ut,Wo,Bo,Ms,Se,ws,se,Vo,pl,No,Co,gs,Re,vs,Xe,fl,Aa,Js,Zt,So,_s,A,ie,ul,Ae,Ro,cl,Xo,Us,oe,Ao,hl,zo,Po,Zs,z,ae,ml,ze,Do,dl,xo,Ts,re,Ho,Pe,Qo,Fo,Gs,N,Yo,De,qo,Lo,xe,Ko,Oo,js,P,ne,yl,He,ea,bl,ta,$s,pe,la,Qe,sa,ia,Es,Fe,ks,Ye,Ml,za,Is,D,fe,wl,qe,oa,gl,aa,Ws,ue,ra,vl,na,pa,Bs,ce,Jl,fa,ua,_l,ca,Vs,Tt,ha,Ns,Le,Cs,Gt,ma,Ss,Ke,Rs,Oe,Ul,Pa,Xs,C,da,Zl,ya,ba,Tl,Ma,wa,As,et,zs,tt,Gl,Da,Ps,x,he,jl,lt,ga,$l,va,Ds,me,Ja,jt,_a,Ua,xs,S,H,Za,$t,Ta,Ga,st,El,ja,$a,Ea,it,ka,Et,Ia,Wa,Ba,ot,Va,kt,Na,Ca,Hs;return v=new be({}),Me=new Tn({props:{classNames:"absolute z-10 right-0 top-0",options:[{label:"Mixed",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers_doc/en/stable_diffusion.ipynb"},{label:"PyTorch",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers_doc/en/pytorch/stable_diffusion.ipynb"},{label:"TensorFlow",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers_doc/en/tensorflow/stable_diffusion.ipynb"},{label:"Mixed",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/diffusers_doc/en/stable_diffusion.ipynb"},{label:"PyTorch",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/diffusers_doc/en/pytorch/stable_diffusion.ipynb"},{label:"TensorFlow",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/diffusers_doc/en/tensorflow/stable_diffusion.ipynb"}]}}),ge=new J({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMERpZmZ1c2lvblBpcGVsaW5lJTBBJTBBbW9kZWxfaWQlMjAlM0QlMjAlMjJydW53YXltbCUyRnN0YWJsZS1kaWZmdXNpb24tdjEtNSUyMiUwQXBpcGVsaW5lJTIwJTNEJTIwRGlmZnVzaW9uUGlwZWxpbmUuZnJvbV9wcmV0cmFpbmVkKG1vZGVsX2lkKQ==",highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DiffusionPipeline

model_id = <span class="hljs-string">&quot;runwayml/stable-diffusion-v1-5&quot;</span>
pipeline = DiffusionPipeline.from_pretrained(model_id)`}}),ve=new J({props:{code:"cHJvbXB0JTIwJTNEJTIwJTIycG9ydHJhaXQlMjBwaG90byUyMG9mJTIwYSUyMG9sZCUyMHdhcnJpb3IlMjBjaGllZiUyMg==",highlighted:'prompt = <span class="hljs-string">&quot;portrait photo of a old warrior chief&quot;</span>'}}),Je=new be({}),q=new gn({props:{$$slots:{default:[Gn]},$$scope:{ctx:nt}}}),_e=new J({props:{code:"cGlwZWxpbmUlMjAlM0QlMjBwaXBlbGluZS50byglMjJjdWRhJTIyKQ==",highlighted:'pipeline = pipeline.to(<span class="hljs-string">&quot;cuda&quot;</span>)'}}),Ze=new J({props:{code:"Z2VuZXJhdG9yJTIwJTNEJTIwdG9yY2guR2VuZXJhdG9yKCUyMmN1ZGElMjIpLm1hbnVhbF9zZWVkKDAp",highlighted:'generator = torch.Generator(<span class="hljs-string">&quot;cuda&quot;</span>).manual_seed(<span class="hljs-number">0</span>)'}}),Te=new J({props:{code:"aW1hZ2UlMjAlM0QlMjBwaXBlbGluZShwcm9tcHQlMkMlMjBnZW5lcmF0b3IlM0RnZW5lcmF0b3IpLmltYWdlcyU1QjAlNUQlMEFpbWFnZQ==",highlighted:`image = pipeline(prompt, generator=generator).images[<span class="hljs-number">0</span>]
image`}}),je=new J({props:{code:"aW1wb3J0JTIwdG9yY2glMEElMEFwaXBlbGluZSUyMCUzRCUyMERpZmZ1c2lvblBpcGVsaW5lLmZyb21fcHJldHJhaW5lZChtb2RlbF9pZCUyQyUyMHRvcmNoX2R0eXBlJTNEdG9yY2guZmxvYXQxNiklMEFwaXBlbGluZSUyMCUzRCUyMHBpcGVsaW5lLnRvKCUyMmN1ZGElMjIpJTBBZ2VuZXJhdG9yJTIwJTNEJTIwdG9yY2guR2VuZXJhdG9yKCUyMmN1ZGElMjIpLm1hbnVhbF9zZWVkKDApJTBBaW1hZ2UlMjAlM0QlMjBwaXBlbGluZShwcm9tcHQlMkMlMjBnZW5lcmF0b3IlM0RnZW5lcmF0b3IpLmltYWdlcyU1QjAlNUQlMEFpbWFnZQ==",highlighted:`<span class="hljs-keyword">import</span> torch

pipeline = DiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
pipeline = pipeline.to(<span class="hljs-string">&quot;cuda&quot;</span>)
generator = torch.Generator(<span class="hljs-string">&quot;cuda&quot;</span>).manual_seed(<span class="hljs-number">0</span>)
image = pipeline(prompt, generator=generator).images[<span class="hljs-number">0</span>]
image`}}),K=new gn({props:{$$slots:{default:[jn]},$$scope:{ctx:nt}}}),Ee=new J({props:{code:"cGlwZWxpbmUuc2NoZWR1bGVyLmNvbXBhdGlibGVzJTBBJTVCJTBBJTIwJTIwJTIwJTIwZGlmZnVzZXJzLnNjaGVkdWxlcnMuc2NoZWR1bGluZ19sbXNfZGlzY3JldGUuTE1TRGlzY3JldGVTY2hlZHVsZXIlMkMlMEElMjAlMjAlMjAlMjBkaWZmdXNlcnMuc2NoZWR1bGVycy5zY2hlZHVsaW5nX3VuaXBjX211bHRpc3RlcC5VbmlQQ011bHRpc3RlcFNjaGVkdWxlciUyQyUwQSUyMCUyMCUyMCUyMGRpZmZ1c2Vycy5zY2hlZHVsZXJzLnNjaGVkdWxpbmdfa19kcG1fMl9kaXNjcmV0ZS5LRFBNMkRpc2NyZXRlU2NoZWR1bGVyJTJDJTBBJTIwJTIwJTIwJTIwZGlmZnVzZXJzLnNjaGVkdWxlcnMuc2NoZWR1bGluZ19kZWlzX211bHRpc3RlcC5ERUlTTXVsdGlzdGVwU2NoZWR1bGVyJTJDJTBBJTIwJTIwJTIwJTIwZGlmZnVzZXJzLnNjaGVkdWxlcnMuc2NoZWR1bGluZ19ldWxlcl9kaXNjcmV0ZS5FdWxlckRpc2NyZXRlU2NoZWR1bGVyJTJDJTBBJTIwJTIwJTIwJTIwZGlmZnVzZXJzLnNjaGVkdWxlcnMuc2NoZWR1bGluZ19kcG1zb2x2ZXJfbXVsdGlzdGVwLkRQTVNvbHZlck11bHRpc3RlcFNjaGVkdWxlciUyQyUwQSUyMCUyMCUyMCUyMGRpZmZ1c2Vycy5zY2hlZHVsZXJzLnNjaGVkdWxpbmdfZGRwbS5ERFBNU2NoZWR1bGVyJTJDJTBBJTIwJTIwJTIwJTIwZGlmZnVzZXJzLnNjaGVkdWxlcnMuc2NoZWR1bGluZ19kcG1zb2x2ZXJfc2luZ2xlc3RlcC5EUE1Tb2x2ZXJTaW5nbGVzdGVwU2NoZWR1bGVyJTJDJTBBJTIwJTIwJTIwJTIwZGlmZnVzZXJzLnNjaGVkdWxlcnMuc2NoZWR1bGluZ19rX2RwbV8yX2FuY2VzdHJhbF9kaXNjcmV0ZS5LRFBNMkFuY2VzdHJhbERpc2NyZXRlU2NoZWR1bGVyJTJDJTBBJTIwJTIwJTIwJTIwZGlmZnVzZXJzLnNjaGVkdWxlcnMuc2NoZWR1bGluZ19oZXVuX2Rpc2NyZXRlLkhldW5EaXNjcmV0ZVNjaGVkdWxlciUyQyUwQSUyMCUyMCUyMCUyMGRpZmZ1c2Vycy5zY2hlZHVsZXJzLnNjaGVkdWxpbmdfcG5kbS5QTkRNU2NoZWR1bGVyJTJDJTBBJTIwJTIwJTIwJTIwZGlmZnVzZXJzLnNjaGVkdWxlcnMuc2NoZWR1bGluZ19ldWxlcl9hbmNlc3RyYWxfZGlzY3JldGUuRXVsZXJBbmNlc3RyYWxEaXNjcmV0ZVNjaGVkdWxlciUyQyUwQSUyMCUyMCUyMCUyMGRpZmZ1c2Vycy5zY2hlZHVsZXJzLnNjaGVkdWxpbmdfZGRpbS5ERElNU2NoZWR1bGVyJTJDJTBBJTVE",highlighted:`pipeline.scheduler.compatibles
[
    diffusers.schedulers.scheduling_lms_discrete.LMSDiscreteScheduler,
    diffusers.schedulers.scheduling_unipc_multistep.UniPCMultistepScheduler,
    diffusers.schedulers.scheduling_k_dpm_2_discrete.KDPM2DiscreteScheduler,
    diffusers.schedulers.scheduling_deis_multistep.DEISMultistepScheduler,
    diffusers.schedulers.scheduling_euler_discrete.EulerDiscreteScheduler,
    diffusers.schedulers.scheduling_dpmsolver_multistep.DPMSolverMultistepScheduler,
    diffusers.schedulers.scheduling_ddpm.DDPMScheduler,
    diffusers.schedulers.scheduling_dpmsolver_singlestep.DPMSolverSinglestepScheduler,
    diffusers.schedulers.scheduling_k_dpm_2_ancestral_discrete.KDPM2AncestralDiscreteScheduler,
    diffusers.schedulers.scheduling_heun_discrete.HeunDiscreteScheduler,
    diffusers.schedulers.scheduling_pndm.PNDMScheduler,
    diffusers.schedulers.scheduling_euler_ancestral_discrete.EulerAncestralDiscreteScheduler,
    diffusers.schedulers.scheduling_ddim.DDIMScheduler,
]`}}),ke=new J({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMERQTVNvbHZlck11bHRpc3RlcFNjaGVkdWxlciUwQSUwQXBpcGVsaW5lLnNjaGVkdWxlciUyMCUzRCUyMERQTVNvbHZlck11bHRpc3RlcFNjaGVkdWxlci5mcm9tX2NvbmZpZyhwaXBlbGluZS5zY2hlZHVsZXIuY29uZmlnKQ==",highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DPMSolverMultistepScheduler

pipeline.scheduler = DPMSolverMultistepScheduler.from_config(pipeline.scheduler.config)`}}),Ie=new J({props:{code:"Z2VuZXJhdG9yJTIwJTNEJTIwdG9yY2guR2VuZXJhdG9yKCUyMmN1ZGElMjIpLm1hbnVhbF9zZWVkKDApJTBBaW1hZ2UlMjAlM0QlMjBwaXBlbGluZShwcm9tcHQlMkMlMjBnZW5lcmF0b3IlM0RnZW5lcmF0b3IlMkMlMjBudW1faW5mZXJlbmNlX3N0ZXBzJTNEMjApLmltYWdlcyU1QjAlNUQlMEFpbWFnZQ==",highlighted:`generator = torch.Generator(<span class="hljs-string">&quot;cuda&quot;</span>).manual_seed(<span class="hljs-number">0</span>)
image = pipeline(prompt, generator=generator, num_inference_steps=<span class="hljs-number">20</span>).images[<span class="hljs-number">0</span>]
image`}}),Be=new be({}),Ve=new J({props:{code:"ZGVmJTIwZ2V0X2lucHV0cyhiYXRjaF9zaXplJTNEMSklM0ElMEElMjAlMjAlMjAlMjBnZW5lcmF0b3IlMjAlM0QlMjAlNUJ0b3JjaC5HZW5lcmF0b3IoJTIyY3VkYSUyMikubWFudWFsX3NlZWQoaSklMjBmb3IlMjBpJTIwaW4lMjByYW5nZShiYXRjaF9zaXplKSU1RCUwQSUyMCUyMCUyMCUyMHByb21wdHMlMjAlM0QlMjBiYXRjaF9zaXplJTIwKiUyMCU1QnByb21wdCU1RCUwQSUyMCUyMCUyMCUyMG51bV9pbmZlcmVuY2Vfc3RlcHMlMjAlM0QlMjAyMCUwQSUwQSUyMCUyMCUyMCUyMHJldHVybiUyMCU3QiUyMnByb21wdCUyMiUzQSUyMHByb21wdHMlMkMlMjAlMjJnZW5lcmF0b3IlMjIlM0ElMjBnZW5lcmF0b3IlMkMlMjAlMjJudW1faW5mZXJlbmNlX3N0ZXBzJTIyJTNBJTIwbnVtX2luZmVyZW5jZV9zdGVwcyU3RA==",highlighted:`<span class="hljs-keyword">def</span> <span class="hljs-title function_">get_inputs</span>(<span class="hljs-params">batch_size=<span class="hljs-number">1</span></span>):
    generator = [torch.Generator(<span class="hljs-string">&quot;cuda&quot;</span>).manual_seed(i) <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(batch_size)]
    prompts = batch_size * [prompt]
    num_inference_steps = <span class="hljs-number">20</span>

    <span class="hljs-keyword">return</span> {<span class="hljs-string">&quot;prompt&quot;</span>: prompts, <span class="hljs-string">&quot;generator&quot;</span>: generator, <span class="hljs-string">&quot;num_inference_steps&quot;</span>: num_inference_steps}`}}),Ne=new J({props:{code:"ZnJvbSUyMFBJTCUyMGltcG9ydCUyMEltYWdlJTBBJTBBJTBBZGVmJTIwaW1hZ2VfZ3JpZChpbWdzJTJDJTIwcm93cyUzRDIlMkMlMjBjb2xzJTNEMiklM0ElMEElMjAlMjAlMjAlMjB3JTJDJTIwaCUyMCUzRCUyMGltZ3MlNUIwJTVELnNpemUlMEElMjAlMjAlMjAlMjBncmlkJTIwJTNEJTIwSW1hZ2UubmV3KCUyMlJHQiUyMiUyQyUyMHNpemUlM0QoY29scyUyMColMjB3JTJDJTIwcm93cyUyMColMjBoKSklMEElMEElMjAlMjAlMjAlMjBmb3IlMjBpJTJDJTIwaW1nJTIwaW4lMjBlbnVtZXJhdGUoaW1ncyklM0ElMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjBncmlkLnBhc3RlKGltZyUyQyUyMGJveCUzRChpJTIwJTI1JTIwY29scyUyMColMjB3JTJDJTIwaSUyMCUyRiUyRiUyMGNvbHMlMjAqJTIwaCkpJTBBJTIwJTIwJTIwJTIwcmV0dXJuJTIwZ3JpZA==",highlighted:`<span class="hljs-keyword">from</span> PIL <span class="hljs-keyword">import</span> Image


<span class="hljs-keyword">def</span> <span class="hljs-title function_">image_grid</span>(<span class="hljs-params">imgs, rows=<span class="hljs-number">2</span>, cols=<span class="hljs-number">2</span></span>):
    w, h = imgs[<span class="hljs-number">0</span>].size
    grid = Image.new(<span class="hljs-string">&quot;RGB&quot;</span>, size=(cols * w, rows * h))

    <span class="hljs-keyword">for</span> i, img <span class="hljs-keyword">in</span> <span class="hljs-built_in">enumerate</span>(imgs):
        grid.paste(img, box=(i % cols * w, i // cols * h))
    <span class="hljs-keyword">return</span> grid`}}),Ce=new J({props:{code:"aW1hZ2VzJTIwJTNEJTIwcGlwZWxpbmUoKipnZXRfaW5wdXRzKGJhdGNoX3NpemUlM0Q0KSkuaW1hZ2VzJTBBaW1hZ2VfZ3JpZChpbWFnZXMp",highlighted:`images = pipeline(**get_inputs(batch_size=<span class="hljs-number">4</span>)).images
image_grid(images)`}}),Se=new J({props:{code:"cGlwZWxpbmUuZW5hYmxlX2F0dGVudGlvbl9zbGljaW5nKCk=",highlighted:"pipeline.enable_attention_slicing()"}}),Re=new J({props:{code:"aW1hZ2VzJTIwJTNEJTIwcGlwZWxpbmUoKipnZXRfaW5wdXRzKGJhdGNoX3NpemUlM0Q4KSkuaW1hZ2VzJTBBaW1hZ2VfZ3JpZChpbWFnZXMlMkMlMjByb3dzJTNEMiUyQyUyMGNvbHMlM0Q0KQ==",highlighted:`images = pipeline(**get_inputs(batch_size=<span class="hljs-number">8</span>)).images
image_grid(images, rows=<span class="hljs-number">2</span>, cols=<span class="hljs-number">4</span>)`}}),Ae=new be({}),ze=new be({}),He=new be({}),Fe=new J({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMEF1dG9lbmNvZGVyS0wlMEElMEF2YWUlMjAlM0QlMjBBdXRvZW5jb2RlcktMLmZyb21fcHJldHJhaW5lZCglMjJzdGFiaWxpdHlhaSUyRnNkLXZhZS1mdC1tc2UlMjIlMkMlMjB0b3JjaF9kdHlwZSUzRHRvcmNoLmZsb2F0MTYpLnRvKCUyMmN1ZGElMjIpJTBBcGlwZWxpbmUudmFlJTIwJTNEJTIwdmFlJTBBaW1hZ2VzJTIwJTNEJTIwcGlwZWxpbmUoKipnZXRfaW5wdXRzKGJhdGNoX3NpemUlM0Q4KSkuaW1hZ2VzJTBBaW1hZ2VfZ3JpZChpbWFnZXMlMkMlMjByb3dzJTNEMiUyQyUyMGNvbHMlM0Q0KQ==",highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> AutoencoderKL

vae = AutoencoderKL.from_pretrained(<span class="hljs-string">&quot;stabilityai/sd-vae-ft-mse&quot;</span>, torch_dtype=torch.float16).to(<span class="hljs-string">&quot;cuda&quot;</span>)
pipeline.vae = vae
images = pipeline(**get_inputs(batch_size=<span class="hljs-number">8</span>)).images
image_grid(images, rows=<span class="hljs-number">2</span>, cols=<span class="hljs-number">4</span>)`}}),qe=new be({}),Le=new J({props:{code:"cHJvbXB0JTIwJTJCJTNEJTIwJTIyJTJDJTIwdHJpYmFsJTIwcGFudGhlciUyMG1ha2UlMjB1cCUyQyUyMGJsdWUlMjBvbiUyMHJlZCUyQyUyMHNpZGUlMjBwcm9maWxlJTJDJTIwbG9va2luZyUyMGF3YXklMkMlMjBzZXJpb3VzJTIwZXllcyUyMiUwQXByb21wdCUyMCUyQiUzRCUyMCUyMiUyMDUwbW0lMjBwb3J0cmFpdCUyMHBob3RvZ3JhcGh5JTJDJTIwaGFyZCUyMHJpbSUyMGxpZ2h0aW5nJTIwcGhvdG9ncmFwaHktLWJldGElMjAtLWFyJTIwMiUzQTMlMjAlMjAtLWJldGElMjAtLXVwYmV0YSUyMg==",highlighted:`prompt += <span class="hljs-string">&quot;, tribal panther make up, blue on red, side profile, looking away, serious eyes&quot;</span>
prompt += <span class="hljs-string">&quot; 50mm portrait photography, hard rim lighting photography--beta --ar 2:3  --beta --upbeta&quot;</span>`}}),Ke=new J({props:{code:"aW1hZ2VzJTIwJTNEJTIwcGlwZWxpbmUoKipnZXRfaW5wdXRzKGJhdGNoX3NpemUlM0Q4KSkuaW1hZ2VzJTBBaW1hZ2VfZ3JpZChpbWFnZXMlMkMlMjByb3dzJTNEMiUyQyUyMGNvbHMlM0Q0KQ==",highlighted:`images = pipeline(**get_inputs(batch_size=<span class="hljs-number">8</span>)).images
image_grid(images, rows=<span class="hljs-number">2</span>, cols=<span class="hljs-number">4</span>)`}}),et=new J({props:{code:"cHJvbXB0cyUyMCUzRCUyMCU1QiUwQSUyMCUyMCUyMCUyMCUyMnBvcnRyYWl0JTIwcGhvdG8lMjBvZiUyMHRoZSUyMG9sZGVzdCUyMHdhcnJpb3IlMjBjaGllZiUyQyUyMHRyaWJhbCUyMHBhbnRoZXIlMjBtYWtlJTIwdXAlMkMlMjBibHVlJTIwb24lMjByZWQlMkMlMjBzaWRlJTIwcHJvZmlsZSUyQyUyMGxvb2tpbmclMjBhd2F5JTJDJTIwc2VyaW91cyUyMGV5ZXMlMjA1MG1tJTIwcG9ydHJhaXQlMjBwaG90b2dyYXBoeSUyQyUyMGhhcmQlMjByaW0lMjBsaWdodGluZyUyMHBob3RvZ3JhcGh5LS1iZXRhJTIwLS1hciUyMDIlM0EzJTIwJTIwLS1iZXRhJTIwLS11cGJldGElMjIlMkMlMEElMjAlMjAlMjAlMjAlMjJwb3J0cmFpdCUyMHBob3RvJTIwb2YlMjBhJTIwb2xkJTIwd2FycmlvciUyMGNoaWVmJTJDJTIwdHJpYmFsJTIwcGFudGhlciUyMG1ha2UlMjB1cCUyQyUyMGJsdWUlMjBvbiUyMHJlZCUyQyUyMHNpZGUlMjBwcm9maWxlJTJDJTIwbG9va2luZyUyMGF3YXklMkMlMjBzZXJpb3VzJTIwZXllcyUyMDUwbW0lMjBwb3J0cmFpdCUyMHBob3RvZ3JhcGh5JTJDJTIwaGFyZCUyMHJpbSUyMGxpZ2h0aW5nJTIwcGhvdG9ncmFwaHktLWJldGElMjAtLWFyJTIwMiUzQTMlMjAlMjAtLWJldGElMjAtLXVwYmV0YSUyMiUyQyUwQSUyMCUyMCUyMCUyMCUyMnBvcnRyYWl0JTIwcGhvdG8lMjBvZiUyMGElMjB3YXJyaW9yJTIwY2hpZWYlMkMlMjB0cmliYWwlMjBwYW50aGVyJTIwbWFrZSUyMHVwJTJDJTIwYmx1ZSUyMG9uJTIwcmVkJTJDJTIwc2lkZSUyMHByb2ZpbGUlMkMlMjBsb29raW5nJTIwYXdheSUyQyUyMHNlcmlvdXMlMjBleWVzJTIwNTBtbSUyMHBvcnRyYWl0JTIwcGhvdG9ncmFwaHklMkMlMjBoYXJkJTIwcmltJTIwbGlnaHRpbmclMjBwaG90b2dyYXBoeS0tYmV0YSUyMC0tYXIlMjAyJTNBMyUyMCUyMC0tYmV0YSUyMC0tdXBiZXRhJTIyJTJDJTBBJTIwJTIwJTIwJTIwJTIycG9ydHJhaXQlMjBwaG90byUyMG9mJTIwYSUyMHlvdW5nJTIwd2FycmlvciUyMGNoaWVmJTJDJTIwdHJpYmFsJTIwcGFudGhlciUyMG1ha2UlMjB1cCUyQyUyMGJsdWUlMjBvbiUyMHJlZCUyQyUyMHNpZGUlMjBwcm9maWxlJTJDJTIwbG9va2luZyUyMGF3YXklMkMlMjBzZXJpb3VzJTIwZXllcyUyMDUwbW0lMjBwb3J0cmFpdCUyMHBob3RvZ3JhcGh5JTJDJTIwaGFyZCUyMHJpbSUyMGxpZ2h0aW5nJTIwcGhvdG9ncmFwaHktLWJldGElMjAtLWFyJTIwMiUzQTMlMjAlMjAtLWJldGElMjAtLXVwYmV0YSUyMiUyQyUwQSU1RCUwQSUwQWdlbmVyYXRvciUyMCUzRCUyMCU1QnRvcmNoLkdlbmVyYXRvciglMjJjdWRhJTIyKS5tYW51YWxfc2VlZCgxKSUyMGZvciUyMF8lMjBpbiUyMHJhbmdlKGxlbihwcm9tcHRzKSklNUQlMEFpbWFnZXMlMjAlM0QlMjBwaXBlbGluZShwcm9tcHQlM0Rwcm9tcHRzJTJDJTIwZ2VuZXJhdG9yJTNEZ2VuZXJhdG9yJTJDJTIwbnVtX2luZmVyZW5jZV9zdGVwcyUzRDI1KS5pbWFnZXMlMEFpbWFnZV9ncmlkKGltYWdlcyk=",highlighted:`prompts = [
    <span class="hljs-string">&quot;portrait photo of the oldest warrior chief, tribal panther make up, blue on red, side profile, looking away, serious eyes 50mm portrait photography, hard rim lighting photography--beta --ar 2:3  --beta --upbeta&quot;</span>,
    <span class="hljs-string">&quot;portrait photo of a old warrior chief, tribal panther make up, blue on red, side profile, looking away, serious eyes 50mm portrait photography, hard rim lighting photography--beta --ar 2:3  --beta --upbeta&quot;</span>,
    <span class="hljs-string">&quot;portrait photo of a warrior chief, tribal panther make up, blue on red, side profile, looking away, serious eyes 50mm portrait photography, hard rim lighting photography--beta --ar 2:3  --beta --upbeta&quot;</span>,
    <span class="hljs-string">&quot;portrait photo of a young warrior chief, tribal panther make up, blue on red, side profile, looking away, serious eyes 50mm portrait photography, hard rim lighting photography--beta --ar 2:3  --beta --upbeta&quot;</span>,
]

generator = [torch.Generator(<span class="hljs-string">&quot;cuda&quot;</span>).manual_seed(<span class="hljs-number">1</span>) <span class="hljs-keyword">for</span> _ <span class="hljs-keyword">in</span> <span class="hljs-built_in">range</span>(<span class="hljs-built_in">len</span>(prompts))]
images = pipeline(prompt=prompts, generator=generator, num_inference_steps=<span class="hljs-number">25</span>).images
image_grid(images)`}}),lt=new be({}),{c(){w=i("meta"),T=f(),g=i("h1"),U=i("a"),Z=i("span"),h(v.$$.fragment),_=f(),$=i("span"),di=a("Effective and efficient diffusion"),Il=f(),h(Me.$$.fragment),Wl=f(),E=i("p"),yi=a("Getting the "),pt=i("a"),bi=a("DiffusionPipeline"),Mi=a(" to generate images in a certain style or include what you want can be tricky. Often times, you have to run the "),ft=i("a"),wi=a("DiffusionPipeline"),gi=a(" several times before you end up with an image you\u2019re happy with. But generating something out of nothing is a computationally intensive process, especially if you\u2019re running inference over and over again."),Bl=f(),k=i("p"),vi=a("This is why it\u2019s important to get the most "),zt=i("em"),Ji=a("computational"),_i=a(" (speed) and "),Pt=i("em"),Ui=a("memory"),Zi=a(" (GPU RAM) efficiency from the pipeline to reduce the time between inference cycles so you can iterate faster."),Vl=f(),Q=i("p"),Ti=a("This tutorial walks you through how to generate faster and better with the "),ut=i("a"),Gi=a("DiffusionPipeline"),ji=a("."),Nl=f(),F=i("p"),$i=a("Begin by loading the "),we=i("a"),Dt=i("code"),Ei=a("runwayml/stable-diffusion-v1-5"),ki=a(" model:"),Cl=f(),h(ge.$$.fragment),Sl=f(),ct=i("p"),Ii=a("The example prompt you\u2019ll use is a portrait of an old warrior chief, but feel free to use your own prompt:"),Rl=f(),h(ve.$$.fragment),Xl=f(),R=i("h2"),Y=i("a"),xt=i("span"),h(Je.$$.fragment),Wi=f(),Ht=i("span"),Bi=a("Speed"),Al=f(),h(q.$$.fragment),zl=f(),ht=i("p"),Vi=a("One of the simplest ways to speed up inference is to place the pipeline on a GPU the same way you would with any PyTorch module:"),Pl=f(),h(_e.$$.fragment),Dl=f(),I=i("p"),Ni=a("To make sure you can use the same image and improve on it, use a "),Ue=i("a"),Qt=i("code"),Ci=a("Generator"),Si=a(" and set a seed for "),mt=i("a"),Ri=a("reproducibility"),Xi=a(":"),xl=f(),h(Ze.$$.fragment),Hl=f(),dt=i("p"),Ai=a("Now you can generate an image:"),Ql=f(),h(Te.$$.fragment),Fl=f(),Ge=i("div"),Ft=i("img"),Yl=f(),G=i("p"),zi=a("This process took ~30 seconds on a T4 GPU (it might be faster if your allocated GPU is better than a T4). By default, the "),yt=i("a"),Pi=a("DiffusionPipeline"),Di=a(" runs inference with full "),Yt=i("code"),xi=a("float32"),Hi=a(" precision for 50 inference steps. You can speed this up by switching to a lower precision like "),qt=i("code"),Qi=a("float16"),Fi=a(" or running fewer inference steps."),ql=f(),L=i("p"),Yi=a("Let\u2019s start by loading the model in "),Lt=i("code"),qi=a("float16"),Li=a(" and generate an image:"),Ll=f(),h(je.$$.fragment),Kl=f(),$e=i("div"),Kt=i("img"),Ol=f(),bt=i("p"),Ki=a("This time, it only took ~11 seconds to generate the image, which is almost 3x faster than before!"),es=f(),h(K.$$.fragment),ts=f(),W=i("p"),Oi=a("Another option is to reduce the number of inference steps. Choosing a more efficient scheduler could help decrease the number of steps without sacrificing output quality. You can find which schedulers are compatible with the current model in the "),Mt=i("a"),eo=a("DiffusionPipeline"),to=a(" by calling the "),Ot=i("code"),lo=a("compatibles"),so=a(" method:"),ls=f(),h(Ee.$$.fragment),ss=f(),j=i("p"),io=a("The Stable Diffusion model uses the "),wt=i("a"),oo=a("PNDMScheduler"),ao=a(" by default which usually requires ~50 inference steps, but more performant schedulers like "),gt=i("a"),ro=a("DPMSolverMultistepScheduler"),no=a(", require only ~20 or 25 inference steps. Use the "),vt=i("a"),po=a("ConfigMixin.from_config()"),fo=a(" method to load a new scheduler:"),is=f(),h(ke.$$.fragment),os=f(),O=i("p"),uo=a("Now set the "),el=i("code"),co=a("num_inference_steps"),ho=a(" to 20:"),as=f(),h(Ie.$$.fragment),rs=f(),We=i("div"),tl=i("img"),ns=f(),Jt=i("p"),mo=a("Great, you\u2019ve managed to cut the inference time to just 4 seconds! \u26A1\uFE0F"),ps=f(),X=i("h2"),ee=i("a"),ll=i("span"),h(Be.$$.fragment),yo=f(),sl=i("span"),bo=a("Memory"),fs=f(),te=i("p"),Mo=a("The other key to improving pipeline performance is consuming less memory, which indirectly implies more speed, since you\u2019re often trying to maximize the number of images generated per second. The easiest way to see how many images you can generate at once is to try out different batch sizes until you get an "),il=i("code"),wo=a("OutOfMemoryError"),go=a(" (OOM)."),us=f(),B=i("p"),vo=a("Create a function that\u2019ll generate a batch of images from a list of prompts and "),ol=i("code"),Jo=a("Generators"),_o=a(". Make sure to assign each "),al=i("code"),Uo=a("Generator"),Zo=a(" a seed so you can reuse it if it produces a good result."),cs=f(),h(Ve.$$.fragment),hs=f(),_t=i("p"),To=a("You\u2019ll also need a function that\u2019ll display each batch of images:"),ms=f(),h(Ne.$$.fragment),ds=f(),le=i("p"),Go=a("Start with "),rl=i("code"),jo=a("batch_size=4"),$o=a(" and see how much memory you\u2019ve consumed:"),ys=f(),h(Ce.$$.fragment),bs=f(),V=i("p"),Eo=a("Unless you have a GPU with more RAM, the code above probably returned an "),nl=i("code"),ko=a("OOM"),Io=a(" error! Most of the memory is taken up by the cross-attention layers. Instead of running this operation in a batch, you can run it sequentially to save a significant amount of memory. All you have to do is configure the pipeline to use the "),Ut=i("a"),Wo=a("enable_attention_slicing()"),Bo=a(" function:"),Ms=f(),h(Se.$$.fragment),ws=f(),se=i("p"),Vo=a("Now try increasing the "),pl=i("code"),No=a("batch_size"),Co=a(" to 8!"),gs=f(),h(Re.$$.fragment),vs=f(),Xe=i("div"),fl=i("img"),Js=f(),Zt=i("p"),So=a("Whereas before you couldn\u2019t even generate a batch of 4 images, now you can generate a batch of 8 images at ~3.5 seconds per image! This is probably the fastest you can go on a T4 GPU without sacrificing quality."),_s=f(),A=i("h2"),ie=i("a"),ul=i("span"),h(Ae.$$.fragment),Ro=f(),cl=i("span"),Xo=a("Quality"),Us=f(),oe=i("p"),Ao=a("In the last two sections, you learned how to optimize the speed of your pipeline by using "),hl=i("code"),zo=a("fp16"),Po=a(", reducing the number of inference steps by using a more performant scheduler, and enabling attention slicing to reduce memory consumption. Now you\u2019re going to focus on how to improve the quality of generated images."),Zs=f(),z=i("h3"),ae=i("a"),ml=i("span"),h(ze.$$.fragment),Do=f(),dl=i("span"),xo=a("Better checkpoints"),Ts=f(),re=i("p"),Ho=a("The most obvious step is to use better checkpoints. The Stable Diffusion model is a good starting point, and since its official launch, several improved versions have also been released. However, using a newer version doesn\u2019t automatically mean you\u2019ll get better results. You\u2019ll still have to experiment with different checkpoints yourself, and do a little research (such as using "),Pe=i("a"),Qo=a("negative prompts"),Fo=a(") to get the best results."),Gs=f(),N=i("p"),Yo=a("As the field grows, there are more and more high-quality checkpoints finetuned to produce certain styles. Try exploring the "),De=i("a"),qo=a("Hub"),Lo=a(" and "),xe=i("a"),Ko=a("Diffusers Gallery"),Oo=a(" to find one you\u2019re interested in!"),js=f(),P=i("h3"),ne=i("a"),yl=i("span"),h(He.$$.fragment),ea=f(),bl=i("span"),ta=a("Better pipeline components"),$s=f(),pe=i("p"),la=a("You can also try replacing the current pipeline components with a newer version. Let\u2019s try loading the latest "),Qe=i("a"),sa=a("autodecoder"),ia=a(" from Stability AI into the pipeline, and generate some images:"),Es=f(),h(Fe.$$.fragment),ks=f(),Ye=i("div"),Ml=i("img"),Is=f(),D=i("h3"),fe=i("a"),wl=i("span"),h(qe.$$.fragment),oa=f(),gl=i("span"),aa=a("Better prompt engineering"),Ws=f(),ue=i("p"),ra=a("The text prompt you use to generate an image is super important, so much so that it is called "),vl=i("em"),na=a("prompt engineering"),pa=a(". Some considerations to keep during prompt engineering are:"),Bs=f(),ce=i("ul"),Jl=i("li"),fa=a("How is the image or similar images of the one I want to generate stored on the internet?"),ua=f(),_l=i("li"),ca=a("What additional detail can I give that steers the model towards the style I want?"),Vs=f(),Tt=i("p"),ha=a("With this in mind, let\u2019s improve the prompt to include color and higher quality details:"),Ns=f(),h(Le.$$.fragment),Cs=f(),Gt=i("p"),ma=a("Generate a batch of images with the new prompt:"),Ss=f(),h(Ke.$$.fragment),Rs=f(),Oe=i("div"),Ul=i("img"),Xs=f(),C=i("p"),da=a("Pretty impressive! Let\u2019s tweak the second image - corresponding to the "),Zl=i("code"),ya=a("Generator"),ba=a(" with a seed of "),Tl=i("code"),Ma=a("1"),wa=a(" - a bit more by adding some text about the age of the subject:"),As=f(),h(et.$$.fragment),zs=f(),tt=i("div"),Gl=i("img"),Ps=f(),x=i("h2"),he=i("a"),jl=i("span"),h(lt.$$.fragment),ga=f(),$l=i("span"),va=a("Next steps"),Ds=f(),me=i("p"),Ja=a("In this tutorial, you learned how to optimize a "),jt=i("a"),_a=a("DiffusionPipeline"),Ua=a(" for computational and memory efficiency as well as improving the quality of generated outputs. If you\u2019re interested in making your pipeline even faster, take a look at the following resources:"),xs=f(),S=i("ul"),H=i("li"),Za=a("Learn how "),$t=i("a"),Ta=a("PyTorch 2.0"),Ga=a(" and "),st=i("a"),El=i("code"),ja=a("torch.compile"),$a=a(" can yield 5 - 300% faster inference speed. On an A100 GPU, inference can be up to 50% faster!"),Ea=f(),it=i("li"),ka=a("If you can\u2019t use PyTorch 2, we recommend you install "),Et=i("a"),Ia=a("xFormers"),Wa=a(". Its memory-efficient attention mechanism works great with PyTorch 1.13.1 for faster speed and reduced memory consumption."),Ba=f(),ot=i("li"),Va=a("Other optimization techniques, such as model offloading, are covered in "),kt=i("a"),Na=a("this guide"),Ca=a("."),this.h()},l(e){const s=Un('[data-svelte="svelte-1phssyn"]',document.head);w=o(s,"META",{name:!0,content:!0}),s.forEach(t),T=u(e),g=o(e,"H1",{class:!0});var at=n(g);U=o(at,"A",{id:!0,class:!0,href:!0});var kl=n(U);Z=o(kl,"SPAN",{});var xa=n(Z);m(v.$$.fragment,xa),xa.forEach(t),kl.forEach(t),_=u(at),$=o(at,"SPAN",{});var Ha=n($);di=r(Ha,"Effective and efficient diffusion"),Ha.forEach(t),at.forEach(t),Il=u(e),m(Me.$$.fragment,e),Wl=u(e),E=o(e,"P",{});var It=n(E);yi=r(It,"Getting the "),pt=o(It,"A",{href:!0});var Qa=n(pt);bi=r(Qa,"DiffusionPipeline"),Qa.forEach(t),Mi=r(It," to generate images in a certain style or include what you want can be tricky. Often times, you have to run the "),ft=o(It,"A",{href:!0});var Fa=n(ft);wi=r(Fa,"DiffusionPipeline"),Fa.forEach(t),gi=r(It," several times before you end up with an image you\u2019re happy with. But generating something out of nothing is a computationally intensive process, especially if you\u2019re running inference over and over again."),It.forEach(t),Bl=u(e),k=o(e,"P",{});var Wt=n(k);vi=r(Wt,"This is why it\u2019s important to get the most "),zt=o(Wt,"EM",{});var Ya=n(zt);Ji=r(Ya,"computational"),Ya.forEach(t),_i=r(Wt," (speed) and "),Pt=o(Wt,"EM",{});var qa=n(Pt);Ui=r(qa,"memory"),qa.forEach(t),Zi=r(Wt," (GPU RAM) efficiency from the pipeline to reduce the time between inference cycles so you can iterate faster."),Wt.forEach(t),Vl=u(e),Q=o(e,"P",{});var Qs=n(Q);Ti=r(Qs,"This tutorial walks you through how to generate faster and better with the "),ut=o(Qs,"A",{href:!0});var La=n(ut);Gi=r(La,"DiffusionPipeline"),La.forEach(t),ji=r(Qs,"."),Qs.forEach(t),Nl=u(e),F=o(e,"P",{});var Fs=n(F);$i=r(Fs,"Begin by loading the "),we=o(Fs,"A",{href:!0,rel:!0});var Ka=n(we);Dt=o(Ka,"CODE",{});var Oa=n(Dt);Ei=r(Oa,"runwayml/stable-diffusion-v1-5"),Oa.forEach(t),Ka.forEach(t),ki=r(Fs," model:"),Fs.forEach(t),Cl=u(e),m(ge.$$.fragment,e),Sl=u(e),ct=o(e,"P",{});var er=n(ct);Ii=r(er,"The example prompt you\u2019ll use is a portrait of an old warrior chief, but feel free to use your own prompt:"),er.forEach(t),Rl=u(e),m(ve.$$.fragment,e),Xl=u(e),R=o(e,"H2",{class:!0});var Ys=n(R);Y=o(Ys,"A",{id:!0,class:!0,href:!0});var tr=n(Y);xt=o(tr,"SPAN",{});var lr=n(xt);m(Je.$$.fragment,lr),lr.forEach(t),tr.forEach(t),Wi=u(Ys),Ht=o(Ys,"SPAN",{});var sr=n(Ht);Bi=r(sr,"Speed"),sr.forEach(t),Ys.forEach(t),Al=u(e),m(q.$$.fragment,e),zl=u(e),ht=o(e,"P",{});var ir=n(ht);Vi=r(ir,"One of the simplest ways to speed up inference is to place the pipeline on a GPU the same way you would with any PyTorch module:"),ir.forEach(t),Pl=u(e),m(_e.$$.fragment,e),Dl=u(e),I=o(e,"P",{});var Bt=n(I);Ni=r(Bt,"To make sure you can use the same image and improve on it, use a "),Ue=o(Bt,"A",{href:!0,rel:!0});var or=n(Ue);Qt=o(or,"CODE",{});var ar=n(Qt);Ci=r(ar,"Generator"),ar.forEach(t),or.forEach(t),Si=r(Bt," and set a seed for "),mt=o(Bt,"A",{href:!0});var rr=n(mt);Ri=r(rr,"reproducibility"),rr.forEach(t),Xi=r(Bt,":"),Bt.forEach(t),xl=u(e),m(Ze.$$.fragment,e),Hl=u(e),dt=o(e,"P",{});var nr=n(dt);Ai=r(nr,"Now you can generate an image:"),nr.forEach(t),Ql=u(e),m(Te.$$.fragment,e),Fl=u(e),Ge=o(e,"DIV",{class:!0});var pr=n(Ge);Ft=o(pr,"IMG",{src:!0}),pr.forEach(t),Yl=u(e),G=o(e,"P",{});var de=n(G);zi=r(de,"This process took ~30 seconds on a T4 GPU (it might be faster if your allocated GPU is better than a T4). By default, the "),yt=o(de,"A",{href:!0});var fr=n(yt);Pi=r(fr,"DiffusionPipeline"),fr.forEach(t),Di=r(de," runs inference with full "),Yt=o(de,"CODE",{});var ur=n(Yt);xi=r(ur,"float32"),ur.forEach(t),Hi=r(de," precision for 50 inference steps. You can speed this up by switching to a lower precision like "),qt=o(de,"CODE",{});var cr=n(qt);Qi=r(cr,"float16"),cr.forEach(t),Fi=r(de," or running fewer inference steps."),de.forEach(t),ql=u(e),L=o(e,"P",{});var qs=n(L);Yi=r(qs,"Let\u2019s start by loading the model in "),Lt=o(qs,"CODE",{});var hr=n(Lt);qi=r(hr,"float16"),hr.forEach(t),Li=r(qs," and generate an image:"),qs.forEach(t),Ll=u(e),m(je.$$.fragment,e),Kl=u(e),$e=o(e,"DIV",{class:!0});var mr=n($e);Kt=o(mr,"IMG",{src:!0}),mr.forEach(t),Ol=u(e),bt=o(e,"P",{});var dr=n(bt);Ki=r(dr,"This time, it only took ~11 seconds to generate the image, which is almost 3x faster than before!"),dr.forEach(t),es=u(e),m(K.$$.fragment,e),ts=u(e),W=o(e,"P",{});var Vt=n(W);Oi=r(Vt,"Another option is to reduce the number of inference steps. Choosing a more efficient scheduler could help decrease the number of steps without sacrificing output quality. You can find which schedulers are compatible with the current model in the "),Mt=o(Vt,"A",{href:!0});var yr=n(Mt);eo=r(yr,"DiffusionPipeline"),yr.forEach(t),to=r(Vt," by calling the "),Ot=o(Vt,"CODE",{});var br=n(Ot);lo=r(br,"compatibles"),br.forEach(t),so=r(Vt," method:"),Vt.forEach(t),ls=u(e),m(Ee.$$.fragment,e),ss=u(e),j=o(e,"P",{});var ye=n(j);io=r(ye,"The Stable Diffusion model uses the "),wt=o(ye,"A",{href:!0});var Mr=n(wt);oo=r(Mr,"PNDMScheduler"),Mr.forEach(t),ao=r(ye," by default which usually requires ~50 inference steps, but more performant schedulers like "),gt=o(ye,"A",{href:!0});var wr=n(gt);ro=r(wr,"DPMSolverMultistepScheduler"),wr.forEach(t),no=r(ye,", require only ~20 or 25 inference steps. Use the "),vt=o(ye,"A",{href:!0});var gr=n(vt);po=r(gr,"ConfigMixin.from_config()"),gr.forEach(t),fo=r(ye," method to load a new scheduler:"),ye.forEach(t),is=u(e),m(ke.$$.fragment,e),os=u(e),O=o(e,"P",{});var Ls=n(O);uo=r(Ls,"Now set the "),el=o(Ls,"CODE",{});var vr=n(el);co=r(vr,"num_inference_steps"),vr.forEach(t),ho=r(Ls," to 20:"),Ls.forEach(t),as=u(e),m(Ie.$$.fragment,e),rs=u(e),We=o(e,"DIV",{class:!0});var Jr=n(We);tl=o(Jr,"IMG",{src:!0}),Jr.forEach(t),ns=u(e),Jt=o(e,"P",{});var _r=n(Jt);mo=r(_r,"Great, you\u2019ve managed to cut the inference time to just 4 seconds! \u26A1\uFE0F"),_r.forEach(t),ps=u(e),X=o(e,"H2",{class:!0});var Ks=n(X);ee=o(Ks,"A",{id:!0,class:!0,href:!0});var Ur=n(ee);ll=o(Ur,"SPAN",{});var Zr=n(ll);m(Be.$$.fragment,Zr),Zr.forEach(t),Ur.forEach(t),yo=u(Ks),sl=o(Ks,"SPAN",{});var Tr=n(sl);bo=r(Tr,"Memory"),Tr.forEach(t),Ks.forEach(t),fs=u(e),te=o(e,"P",{});var Os=n(te);Mo=r(Os,"The other key to improving pipeline performance is consuming less memory, which indirectly implies more speed, since you\u2019re often trying to maximize the number of images generated per second. The easiest way to see how many images you can generate at once is to try out different batch sizes until you get an "),il=o(Os,"CODE",{});var Gr=n(il);wo=r(Gr,"OutOfMemoryError"),Gr.forEach(t),go=r(Os," (OOM)."),Os.forEach(t),us=u(e),B=o(e,"P",{});var Nt=n(B);vo=r(Nt,"Create a function that\u2019ll generate a batch of images from a list of prompts and "),ol=o(Nt,"CODE",{});var jr=n(ol);Jo=r(jr,"Generators"),jr.forEach(t),_o=r(Nt,". Make sure to assign each "),al=o(Nt,"CODE",{});var $r=n(al);Uo=r($r,"Generator"),$r.forEach(t),Zo=r(Nt," a seed so you can reuse it if it produces a good result."),Nt.forEach(t),cs=u(e),m(Ve.$$.fragment,e),hs=u(e),_t=o(e,"P",{});var Er=n(_t);To=r(Er,"You\u2019ll also need a function that\u2019ll display each batch of images:"),Er.forEach(t),ms=u(e),m(Ne.$$.fragment,e),ds=u(e),le=o(e,"P",{});var ei=n(le);Go=r(ei,"Start with "),rl=o(ei,"CODE",{});var kr=n(rl);jo=r(kr,"batch_size=4"),kr.forEach(t),$o=r(ei," and see how much memory you\u2019ve consumed:"),ei.forEach(t),ys=u(e),m(Ce.$$.fragment,e),bs=u(e),V=o(e,"P",{});var Ct=n(V);Eo=r(Ct,"Unless you have a GPU with more RAM, the code above probably returned an "),nl=o(Ct,"CODE",{});var Ir=n(nl);ko=r(Ir,"OOM"),Ir.forEach(t),Io=r(Ct," error! Most of the memory is taken up by the cross-attention layers. Instead of running this operation in a batch, you can run it sequentially to save a significant amount of memory. All you have to do is configure the pipeline to use the "),Ut=o(Ct,"A",{href:!0});var Wr=n(Ut);Wo=r(Wr,"enable_attention_slicing()"),Wr.forEach(t),Bo=r(Ct," function:"),Ct.forEach(t),Ms=u(e),m(Se.$$.fragment,e),ws=u(e),se=o(e,"P",{});var ti=n(se);Vo=r(ti,"Now try increasing the "),pl=o(ti,"CODE",{});var Br=n(pl);No=r(Br,"batch_size"),Br.forEach(t),Co=r(ti," to 8!"),ti.forEach(t),gs=u(e),m(Re.$$.fragment,e),vs=u(e),Xe=o(e,"DIV",{class:!0});var Vr=n(Xe);fl=o(Vr,"IMG",{src:!0}),Vr.forEach(t),Js=u(e),Zt=o(e,"P",{});var Nr=n(Zt);So=r(Nr,"Whereas before you couldn\u2019t even generate a batch of 4 images, now you can generate a batch of 8 images at ~3.5 seconds per image! This is probably the fastest you can go on a T4 GPU without sacrificing quality."),Nr.forEach(t),_s=u(e),A=o(e,"H2",{class:!0});var li=n(A);ie=o(li,"A",{id:!0,class:!0,href:!0});var Cr=n(ie);ul=o(Cr,"SPAN",{});var Sr=n(ul);m(Ae.$$.fragment,Sr),Sr.forEach(t),Cr.forEach(t),Ro=u(li),cl=o(li,"SPAN",{});var Rr=n(cl);Xo=r(Rr,"Quality"),Rr.forEach(t),li.forEach(t),Us=u(e),oe=o(e,"P",{});var si=n(oe);Ao=r(si,"In the last two sections, you learned how to optimize the speed of your pipeline by using "),hl=o(si,"CODE",{});var Xr=n(hl);zo=r(Xr,"fp16"),Xr.forEach(t),Po=r(si,", reducing the number of inference steps by using a more performant scheduler, and enabling attention slicing to reduce memory consumption. Now you\u2019re going to focus on how to improve the quality of generated images."),si.forEach(t),Zs=u(e),z=o(e,"H3",{class:!0});var ii=n(z);ae=o(ii,"A",{id:!0,class:!0,href:!0});var Ar=n(ae);ml=o(Ar,"SPAN",{});var zr=n(ml);m(ze.$$.fragment,zr),zr.forEach(t),Ar.forEach(t),Do=u(ii),dl=o(ii,"SPAN",{});var Pr=n(dl);xo=r(Pr,"Better checkpoints"),Pr.forEach(t),ii.forEach(t),Ts=u(e),re=o(e,"P",{});var oi=n(re);Ho=r(oi,"The most obvious step is to use better checkpoints. The Stable Diffusion model is a good starting point, and since its official launch, several improved versions have also been released. However, using a newer version doesn\u2019t automatically mean you\u2019ll get better results. You\u2019ll still have to experiment with different checkpoints yourself, and do a little research (such as using "),Pe=o(oi,"A",{href:!0,rel:!0});var Dr=n(Pe);Qo=r(Dr,"negative prompts"),Dr.forEach(t),Fo=r(oi,") to get the best results."),oi.forEach(t),Gs=u(e),N=o(e,"P",{});var St=n(N);Yo=r(St,"As the field grows, there are more and more high-quality checkpoints finetuned to produce certain styles. Try exploring the "),De=o(St,"A",{href:!0,rel:!0});var xr=n(De);qo=r(xr,"Hub"),xr.forEach(t),Lo=r(St," and "),xe=o(St,"A",{href:!0,rel:!0});var Hr=n(xe);Ko=r(Hr,"Diffusers Gallery"),Hr.forEach(t),Oo=r(St," to find one you\u2019re interested in!"),St.forEach(t),js=u(e),P=o(e,"H3",{class:!0});var ai=n(P);ne=o(ai,"A",{id:!0,class:!0,href:!0});var Qr=n(ne);yl=o(Qr,"SPAN",{});var Fr=n(yl);m(He.$$.fragment,Fr),Fr.forEach(t),Qr.forEach(t),ea=u(ai),bl=o(ai,"SPAN",{});var Yr=n(bl);ta=r(Yr,"Better pipeline components"),Yr.forEach(t),ai.forEach(t),$s=u(e),pe=o(e,"P",{});var ri=n(pe);la=r(ri,"You can also try replacing the current pipeline components with a newer version. Let\u2019s try loading the latest "),Qe=o(ri,"A",{href:!0,rel:!0});var qr=n(Qe);sa=r(qr,"autodecoder"),qr.forEach(t),ia=r(ri," from Stability AI into the pipeline, and generate some images:"),ri.forEach(t),Es=u(e),m(Fe.$$.fragment,e),ks=u(e),Ye=o(e,"DIV",{class:!0});var Lr=n(Ye);Ml=o(Lr,"IMG",{src:!0}),Lr.forEach(t),Is=u(e),D=o(e,"H3",{class:!0});var ni=n(D);fe=o(ni,"A",{id:!0,class:!0,href:!0});var Kr=n(fe);wl=o(Kr,"SPAN",{});var Or=n(wl);m(qe.$$.fragment,Or),Or.forEach(t),Kr.forEach(t),oa=u(ni),gl=o(ni,"SPAN",{});var en=n(gl);aa=r(en,"Better prompt engineering"),en.forEach(t),ni.forEach(t),Ws=u(e),ue=o(e,"P",{});var pi=n(ue);ra=r(pi,"The text prompt you use to generate an image is super important, so much so that it is called "),vl=o(pi,"EM",{});var tn=n(vl);na=r(tn,"prompt engineering"),tn.forEach(t),pa=r(pi,". Some considerations to keep during prompt engineering are:"),pi.forEach(t),Bs=u(e),ce=o(e,"UL",{});var fi=n(ce);Jl=o(fi,"LI",{});var ln=n(Jl);fa=r(ln,"How is the image or similar images of the one I want to generate stored on the internet?"),ln.forEach(t),ua=u(fi),_l=o(fi,"LI",{});var sn=n(_l);ca=r(sn,"What additional detail can I give that steers the model towards the style I want?"),sn.forEach(t),fi.forEach(t),Vs=u(e),Tt=o(e,"P",{});var on=n(Tt);ha=r(on,"With this in mind, let\u2019s improve the prompt to include color and higher quality details:"),on.forEach(t),Ns=u(e),m(Le.$$.fragment,e),Cs=u(e),Gt=o(e,"P",{});var an=n(Gt);ma=r(an,"Generate a batch of images with the new prompt:"),an.forEach(t),Ss=u(e),m(Ke.$$.fragment,e),Rs=u(e),Oe=o(e,"DIV",{class:!0});var rn=n(Oe);Ul=o(rn,"IMG",{src:!0}),rn.forEach(t),Xs=u(e),C=o(e,"P",{});var Rt=n(C);da=r(Rt,"Pretty impressive! Let\u2019s tweak the second image - corresponding to the "),Zl=o(Rt,"CODE",{});var nn=n(Zl);ya=r(nn,"Generator"),nn.forEach(t),ba=r(Rt," with a seed of "),Tl=o(Rt,"CODE",{});var pn=n(Tl);Ma=r(pn,"1"),pn.forEach(t),wa=r(Rt," - a bit more by adding some text about the age of the subject:"),Rt.forEach(t),As=u(e),m(et.$$.fragment,e),zs=u(e),tt=o(e,"DIV",{class:!0});var fn=n(tt);Gl=o(fn,"IMG",{src:!0}),fn.forEach(t),Ps=u(e),x=o(e,"H2",{class:!0});var ui=n(x);he=o(ui,"A",{id:!0,class:!0,href:!0});var un=n(he);jl=o(un,"SPAN",{});var cn=n(jl);m(lt.$$.fragment,cn),cn.forEach(t),un.forEach(t),ga=u(ui),$l=o(ui,"SPAN",{});var hn=n($l);va=r(hn,"Next steps"),hn.forEach(t),ui.forEach(t),Ds=u(e),me=o(e,"P",{});var ci=n(me);Ja=r(ci,"In this tutorial, you learned how to optimize a "),jt=o(ci,"A",{href:!0});var mn=n(jt);_a=r(mn,"DiffusionPipeline"),mn.forEach(t),Ua=r(ci," for computational and memory efficiency as well as improving the quality of generated outputs. If you\u2019re interested in making your pipeline even faster, take a look at the following resources:"),ci.forEach(t),xs=u(e),S=o(e,"UL",{});var Xt=n(S);H=o(Xt,"LI",{});var At=n(H);Za=r(At,"Learn how "),$t=o(At,"A",{href:!0});var dn=n($t);Ta=r(dn,"PyTorch 2.0"),dn.forEach(t),Ga=r(At," and "),st=o(At,"A",{href:!0,rel:!0});var yn=n(st);El=o(yn,"CODE",{});var bn=n(El);ja=r(bn,"torch.compile"),bn.forEach(t),yn.forEach(t),$a=r(At," can yield 5 - 300% faster inference speed. On an A100 GPU, inference can be up to 50% faster!"),At.forEach(t),Ea=u(Xt),it=o(Xt,"LI",{});var hi=n(it);ka=r(hi,"If you can\u2019t use PyTorch 2, we recommend you install "),Et=o(hi,"A",{href:!0});var Mn=n(Et);Ia=r(Mn,"xFormers"),Mn.forEach(t),Wa=r(hi,". Its memory-efficient attention mechanism works great with PyTorch 1.13.1 for faster speed and reduced memory consumption."),hi.forEach(t),Ba=u(Xt),ot=o(Xt,"LI",{});var mi=n(ot);Va=r(mi,"Other optimization techniques, such as model offloading, are covered in "),kt=o(mi,"A",{href:!0});var wn=n(kt);Na=r(wn,"this guide"),wn.forEach(t),Ca=r(mi,"."),mi.forEach(t),Xt.forEach(t),this.h()},h(){c(w,"name","hf:doc:metadata"),c(w,"content",JSON.stringify(En)),c(U,"id","effective-and-efficient-diffusion"),c(U,"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"),c(U,"href","#effective-and-efficient-diffusion"),c(g,"class","relative group"),c(pt,"href","/docs/diffusers/v0.17.1/en/api/diffusion_pipeline#diffusers.DiffusionPipeline"),c(ft,"href","/docs/diffusers/v0.17.1/en/api/diffusion_pipeline#diffusers.DiffusionPipeline"),c(ut,"href","/docs/diffusers/v0.17.1/en/api/diffusion_pipeline#diffusers.DiffusionPipeline"),c(we,"href","https://huggingface.co/runwayml/stable-diffusion-v1-5"),c(we,"rel","nofollow"),c(Y,"id","speed"),c(Y,"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"),c(Y,"href","#speed"),c(R,"class","relative group"),c(Ue,"href","https://pytorch.org/docs/stable/generated/torch.Generator.html"),c(Ue,"rel","nofollow"),c(mt,"href","./using-diffusers/reproducibility"),rt(Ft.src,Sa="https://huggingface.co/datasets/diffusers/docs-images/resolve/main/stable_diffusion_101/sd_101_1.png")||c(Ft,"src",Sa),c(Ge,"class","flex justify-center"),c(yt,"href","/docs/diffusers/v0.17.1/en/api/diffusion_pipeline#diffusers.DiffusionPipeline"),rt(Kt.src,Ra="https://huggingface.co/datasets/diffusers/docs-images/resolve/main/stable_diffusion_101/sd_101_2.png")||c(Kt,"src",Ra),c($e,"class","flex justify-center"),c(Mt,"href","/docs/diffusers/v0.17.1/en/api/diffusion_pipeline#diffusers.DiffusionPipeline"),c(wt,"href","/docs/diffusers/v0.17.1/en/api/schedulers/pndm#diffusers.PNDMScheduler"),c(gt,"href","/docs/diffusers/v0.17.1/en/api/schedulers/multistep_dpm_solver#diffusers.DPMSolverMultistepScheduler"),c(vt,"href","/docs/diffusers/v0.17.1/en/api/configuration#diffusers.ConfigMixin.from_config"),rt(tl.src,Xa="https://huggingface.co/datasets/diffusers/docs-images/resolve/main/stable_diffusion_101/sd_101_3.png")||c(tl,"src",Xa),c(We,"class","flex justify-center"),c(ee,"id","memory"),c(ee,"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"),c(ee,"href","#memory"),c(X,"class","relative group"),c(Ut,"href","/docs/diffusers/v0.17.1/en/api/pipelines/stable_diffusion/upscale#diffusers.StableDiffusionUpscalePipeline.enable_attention_slicing"),rt(fl.src,Aa="https://huggingface.co/datasets/diffusers/docs-images/resolve/main/stable_diffusion_101/sd_101_5.png")||c(fl,"src",Aa),c(Xe,"class","flex justify-center"),c(ie,"id","quality"),c(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"),c(ie,"href","#quality"),c(A,"class","relative group"),c(ae,"id","better-checkpoints"),c(ae,"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"),c(ae,"href","#better-checkpoints"),c(z,"class","relative group"),c(Pe,"href","https://minimaxir.com/2022/11/stable-diffusion-negative-prompt/"),c(Pe,"rel","nofollow"),c(De,"href","https://huggingface.co/models?library=diffusers&sort=downloads"),c(De,"rel","nofollow"),c(xe,"href","https://huggingface.co/spaces/huggingface-projects/diffusers-gallery"),c(xe,"rel","nofollow"),c(ne,"id","better-pipeline-components"),c(ne,"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"),c(ne,"href","#better-pipeline-components"),c(P,"class","relative group"),c(Qe,"href","https://huggingface.co/stabilityai/stable-diffusion-2-1/tree/main/vae"),c(Qe,"rel","nofollow"),rt(Ml.src,za="https://huggingface.co/datasets/diffusers/docs-images/resolve/main/stable_diffusion_101/sd_101_6.png")||c(Ml,"src",za),c(Ye,"class","flex justify-center"),c(fe,"id","better-prompt-engineering"),c(fe,"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"),c(fe,"href","#better-prompt-engineering"),c(D,"class","relative group"),rt(Ul.src,Pa="https://huggingface.co/datasets/diffusers/docs-images/resolve/main/stable_diffusion_101/sd_101_7.png")||c(Ul,"src",Pa),c(Oe,"class","flex justify-center"),rt(Gl.src,Da="https://huggingface.co/datasets/diffusers/docs-images/resolve/main/stable_diffusion_101/sd_101_8.png")||c(Gl,"src",Da),c(tt,"class","flex justify-center"),c(he,"id","next-steps"),c(he,"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"),c(he,"href","#next-steps"),c(x,"class","relative group"),c(jt,"href","/docs/diffusers/v0.17.1/en/api/diffusion_pipeline#diffusers.DiffusionPipeline"),c($t,"href","./optimization/torch2.0"),c(st,"href","https://pytorch.org/docs/stable/generated/torch.compile.html"),c(st,"rel","nofollow"),c(Et,"href","./optimization/xformers"),c(kt,"href","./optimization/fp16")},m(e,s){l(document.head,w),p(e,T,s),p(e,g,s),l(g,U),l(U,Z),d(v,Z,null),l(g,_),l(g,$),l($,di),p(e,Il,s),d(Me,e,s),p(e,Wl,s),p(e,E,s),l(E,yi),l(E,pt),l(pt,bi),l(E,Mi),l(E,ft),l(ft,wi),l(E,gi),p(e,Bl,s),p(e,k,s),l(k,vi),l(k,zt),l(zt,Ji),l(k,_i),l(k,Pt),l(Pt,Ui),l(k,Zi),p(e,Vl,s),p(e,Q,s),l(Q,Ti),l(Q,ut),l(ut,Gi),l(Q,ji),p(e,Nl,s),p(e,F,s),l(F,$i),l(F,we),l(we,Dt),l(Dt,Ei),l(F,ki),p(e,Cl,s),d(ge,e,s),p(e,Sl,s),p(e,ct,s),l(ct,Ii),p(e,Rl,s),d(ve,e,s),p(e,Xl,s),p(e,R,s),l(R,Y),l(Y,xt),d(Je,xt,null),l(R,Wi),l(R,Ht),l(Ht,Bi),p(e,Al,s),d(q,e,s),p(e,zl,s),p(e,ht,s),l(ht,Vi),p(e,Pl,s),d(_e,e,s),p(e,Dl,s),p(e,I,s),l(I,Ni),l(I,Ue),l(Ue,Qt),l(Qt,Ci),l(I,Si),l(I,mt),l(mt,Ri),l(I,Xi),p(e,xl,s),d(Ze,e,s),p(e,Hl,s),p(e,dt,s),l(dt,Ai),p(e,Ql,s),d(Te,e,s),p(e,Fl,s),p(e,Ge,s),l(Ge,Ft),p(e,Yl,s),p(e,G,s),l(G,zi),l(G,yt),l(yt,Pi),l(G,Di),l(G,Yt),l(Yt,xi),l(G,Hi),l(G,qt),l(qt,Qi),l(G,Fi),p(e,ql,s),p(e,L,s),l(L,Yi),l(L,Lt),l(Lt,qi),l(L,Li),p(e,Ll,s),d(je,e,s),p(e,Kl,s),p(e,$e,s),l($e,Kt),p(e,Ol,s),p(e,bt,s),l(bt,Ki),p(e,es,s),d(K,e,s),p(e,ts,s),p(e,W,s),l(W,Oi),l(W,Mt),l(Mt,eo),l(W,to),l(W,Ot),l(Ot,lo),l(W,so),p(e,ls,s),d(Ee,e,s),p(e,ss,s),p(e,j,s),l(j,io),l(j,wt),l(wt,oo),l(j,ao),l(j,gt),l(gt,ro),l(j,no),l(j,vt),l(vt,po),l(j,fo),p(e,is,s),d(ke,e,s),p(e,os,s),p(e,O,s),l(O,uo),l(O,el),l(el,co),l(O,ho),p(e,as,s),d(Ie,e,s),p(e,rs,s),p(e,We,s),l(We,tl),p(e,ns,s),p(e,Jt,s),l(Jt,mo),p(e,ps,s),p(e,X,s),l(X,ee),l(ee,ll),d(Be,ll,null),l(X,yo),l(X,sl),l(sl,bo),p(e,fs,s),p(e,te,s),l(te,Mo),l(te,il),l(il,wo),l(te,go),p(e,us,s),p(e,B,s),l(B,vo),l(B,ol),l(ol,Jo),l(B,_o),l(B,al),l(al,Uo),l(B,Zo),p(e,cs,s),d(Ve,e,s),p(e,hs,s),p(e,_t,s),l(_t,To),p(e,ms,s),d(Ne,e,s),p(e,ds,s),p(e,le,s),l(le,Go),l(le,rl),l(rl,jo),l(le,$o),p(e,ys,s),d(Ce,e,s),p(e,bs,s),p(e,V,s),l(V,Eo),l(V,nl),l(nl,ko),l(V,Io),l(V,Ut),l(Ut,Wo),l(V,Bo),p(e,Ms,s),d(Se,e,s),p(e,ws,s),p(e,se,s),l(se,Vo),l(se,pl),l(pl,No),l(se,Co),p(e,gs,s),d(Re,e,s),p(e,vs,s),p(e,Xe,s),l(Xe,fl),p(e,Js,s),p(e,Zt,s),l(Zt,So),p(e,_s,s),p(e,A,s),l(A,ie),l(ie,ul),d(Ae,ul,null),l(A,Ro),l(A,cl),l(cl,Xo),p(e,Us,s),p(e,oe,s),l(oe,Ao),l(oe,hl),l(hl,zo),l(oe,Po),p(e,Zs,s),p(e,z,s),l(z,ae),l(ae,ml),d(ze,ml,null),l(z,Do),l(z,dl),l(dl,xo),p(e,Ts,s),p(e,re,s),l(re,Ho),l(re,Pe),l(Pe,Qo),l(re,Fo),p(e,Gs,s),p(e,N,s),l(N,Yo),l(N,De),l(De,qo),l(N,Lo),l(N,xe),l(xe,Ko),l(N,Oo),p(e,js,s),p(e,P,s),l(P,ne),l(ne,yl),d(He,yl,null),l(P,ea),l(P,bl),l(bl,ta),p(e,$s,s),p(e,pe,s),l(pe,la),l(pe,Qe),l(Qe,sa),l(pe,ia),p(e,Es,s),d(Fe,e,s),p(e,ks,s),p(e,Ye,s),l(Ye,Ml),p(e,Is,s),p(e,D,s),l(D,fe),l(fe,wl),d(qe,wl,null),l(D,oa),l(D,gl),l(gl,aa),p(e,Ws,s),p(e,ue,s),l(ue,ra),l(ue,vl),l(vl,na),l(ue,pa),p(e,Bs,s),p(e,ce,s),l(ce,Jl),l(Jl,fa),l(ce,ua),l(ce,_l),l(_l,ca),p(e,Vs,s),p(e,Tt,s),l(Tt,ha),p(e,Ns,s),d(Le,e,s),p(e,Cs,s),p(e,Gt,s),l(Gt,ma),p(e,Ss,s),d(Ke,e,s),p(e,Rs,s),p(e,Oe,s),l(Oe,Ul),p(e,Xs,s),p(e,C,s),l(C,da),l(C,Zl),l(Zl,ya),l(C,ba),l(C,Tl),l(Tl,Ma),l(C,wa),p(e,As,s),d(et,e,s),p(e,zs,s),p(e,tt,s),l(tt,Gl),p(e,Ps,s),p(e,x,s),l(x,he),l(he,jl),d(lt,jl,null),l(x,ga),l(x,$l),l($l,va),p(e,Ds,s),p(e,me,s),l(me,Ja),l(me,jt),l(jt,_a),l(me,Ua),p(e,xs,s),p(e,S,s),l(S,H),l(H,Za),l(H,$t),l($t,Ta),l(H,Ga),l(H,st),l(st,El),l(El,ja),l(H,$a),l(S,Ea),l(S,it),l(it,ka),l(it,Et),l(Et,Ia),l(it,Wa),l(S,Ba),l(S,ot),l(ot,Va),l(ot,kt),l(kt,Na),l(ot,Ca),Hs=!0},p(e,[s]){const at={};s&2&&(at.$$scope={dirty:s,ctx:e}),q.$set(at);const kl={};s&2&&(kl.$$scope={dirty:s,ctx:e}),K.$set(kl)},i(e){Hs||(y(v.$$.fragment,e),y(Me.$$.fragment,e),y(ge.$$.fragment,e),y(ve.$$.fragment,e),y(Je.$$.fragment,e),y(q.$$.fragment,e),y(_e.$$.fragment,e),y(Ze.$$.fragment,e),y(Te.$$.fragment,e),y(je.$$.fragment,e),y(K.$$.fragment,e),y(Ee.$$.fragment,e),y(ke.$$.fragment,e),y(Ie.$$.fragment,e),y(Be.$$.fragment,e),y(Ve.$$.fragment,e),y(Ne.$$.fragment,e),y(Ce.$$.fragment,e),y(Se.$$.fragment,e),y(Re.$$.fragment,e),y(Ae.$$.fragment,e),y(ze.$$.fragment,e),y(He.$$.fragment,e),y(Fe.$$.fragment,e),y(qe.$$.fragment,e),y(Le.$$.fragment,e),y(Ke.$$.fragment,e),y(et.$$.fragment,e),y(lt.$$.fragment,e),Hs=!0)},o(e){b(v.$$.fragment,e),b(Me.$$.fragment,e),b(ge.$$.fragment,e),b(ve.$$.fragment,e),b(Je.$$.fragment,e),b(q.$$.fragment,e),b(_e.$$.fragment,e),b(Ze.$$.fragment,e),b(Te.$$.fragment,e),b(je.$$.fragment,e),b(K.$$.fragment,e),b(Ee.$$.fragment,e),b(ke.$$.fragment,e),b(Ie.$$.fragment,e),b(Be.$$.fragment,e),b(Ve.$$.fragment,e),b(Ne.$$.fragment,e),b(Ce.$$.fragment,e),b(Se.$$.fragment,e),b(Re.$$.fragment,e),b(Ae.$$.fragment,e),b(ze.$$.fragment,e),b(He.$$.fragment,e),b(Fe.$$.fragment,e),b(qe.$$.fragment,e),b(Le.$$.fragment,e),b(Ke.$$.fragment,e),b(et.$$.fragment,e),b(lt.$$.fragment,e),Hs=!1},d(e){t(w),e&&t(T),e&&t(g),M(v),e&&t(Il),M(Me,e),e&&t(Wl),e&&t(E),e&&t(Bl),e&&t(k),e&&t(Vl),e&&t(Q),e&&t(Nl),e&&t(F),e&&t(Cl),M(ge,e),e&&t(Sl),e&&t(ct),e&&t(Rl),M(ve,e),e&&t(Xl),e&&t(R),M(Je),e&&t(Al),M(q,e),e&&t(zl),e&&t(ht),e&&t(Pl),M(_e,e),e&&t(Dl),e&&t(I),e&&t(xl),M(Ze,e),e&&t(Hl),e&&t(dt),e&&t(Ql),M(Te,e),e&&t(Fl),e&&t(Ge),e&&t(Yl),e&&t(G),e&&t(ql),e&&t(L),e&&t(Ll),M(je,e),e&&t(Kl),e&&t($e),e&&t(Ol),e&&t(bt),e&&t(es),M(K,e),e&&t(ts),e&&t(W),e&&t(ls),M(Ee,e),e&&t(ss),e&&t(j),e&&t(is),M(ke,e),e&&t(os),e&&t(O),e&&t(as),M(Ie,e),e&&t(rs),e&&t(We),e&&t(ns),e&&t(Jt),e&&t(ps),e&&t(X),M(Be),e&&t(fs),e&&t(te),e&&t(us),e&&t(B),e&&t(cs),M(Ve,e),e&&t(hs),e&&t(_t),e&&t(ms),M(Ne,e),e&&t(ds),e&&t(le),e&&t(ys),M(Ce,e),e&&t(bs),e&&t(V),e&&t(Ms),M(Se,e),e&&t(ws),e&&t(se),e&&t(gs),M(Re,e),e&&t(vs),e&&t(Xe),e&&t(Js),e&&t(Zt),e&&t(_s),e&&t(A),M(Ae),e&&t(Us),e&&t(oe),e&&t(Zs),e&&t(z),M(ze),e&&t(Ts),e&&t(re),e&&t(Gs),e&&t(N),e&&t(js),e&&t(P),M(He),e&&t($s),e&&t(pe),e&&t(Es),M(Fe,e),e&&t(ks),e&&t(Ye),e&&t(Is),e&&t(D),M(qe),e&&t(Ws),e&&t(ue),e&&t(Bs),e&&t(ce),e&&t(Vs),e&&t(Tt),e&&t(Ns),M(Le,e),e&&t(Cs),e&&t(Gt),e&&t(Ss),M(Ke,e),e&&t(Rs),e&&t(Oe),e&&t(Xs),e&&t(C),e&&t(As),M(et,e),e&&t(zs),e&&t(tt),e&&t(Ps),e&&t(x),M(lt),e&&t(Ds),e&&t(me),e&&t(xs),e&&t(S)}}}const En={local:"effective-and-efficient-diffusion",sections:[{local:"speed",title:"Speed"},{local:"memory",title:"Memory"},{local:"quality",sections:[{local:"better-checkpoints",title:"Better checkpoints"},{local:"better-pipeline-components",title:"Better pipeline components"},{local:"better-prompt-engineering",title:"Better prompt engineering"}],title:"Quality"},{local:"next-steps",title:"Next steps"}],title:"Effective and efficient diffusion"};function kn(nt){return Zn(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Cn extends vn{constructor(w){super();Jn(this,w,kn,$n,_n,{})}}export{Cn as default,En as metadata};
