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

generator = torch.Generator(<span class="hljs-string">&quot;cuda&quot;</span>).manual_seed(<span class="hljs-number">0</span>)`}}),Ze=new J({props:{code:"aW1hZ2UlMjAlM0QlMjBwaXBlbGluZShwcm9tcHQlMkMlMjBnZW5lcmF0b3IlM0RnZW5lcmF0b3IpLmltYWdlcyU1QjAlNUQlMEFpbWFnZQ==",highlighted:`image = pipeline(prompt, generator=generator).images[<span class="hljs-number">0</span>]
image`}}),je=new J({props:{code:"aW1wb3J0JTIwdG9yY2glMEElMEFwaXBlbGluZSUyMCUzRCUyMERpZmZ1c2lvblBpcGVsaW5lLmZyb21fcHJldHJhaW5lZChtb2RlbF9pZCUyQyUyMHRvcmNoX2R0eXBlJTNEdG9yY2guZmxvYXQxNiUyQyUyMHVzZV9zYWZldGVuc29ycyUzRFRydWUpJTBBcGlwZWxpbmUlMjAlM0QlMjBwaXBlbGluZS50byglMjJjdWRhJTIyKSUwQWdlbmVyYXRvciUyMCUzRCUyMHRvcmNoLkdlbmVyYXRvciglMjJjdWRhJTIyKS5tYW51YWxfc2VlZCgwKSUwQWltYWdlJTIwJTNEJTIwcGlwZWxpbmUocHJvbXB0JTJDJTIwZ2VuZXJhdG9yJTNEZ2VuZXJhdG9yKS5pbWFnZXMlNUIwJTVEJTBBaW1hZ2U=",highlighted:`<span class="hljs-keyword">import</span> torch

pipeline = DiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16, use_safetensors=<span class="hljs-literal">True</span>)
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`}}),Se=new J({props:{code:"aW1hZ2VzJTIwJTNEJTIwcGlwZWxpbmUoKipnZXRfaW5wdXRzKGJhdGNoX3NpemUlM0Q0KSkuaW1hZ2VzJTBBaW1hZ2VfZ3JpZChpbWFnZXMp",highlighted:`images = pipeline(**get_inputs(batch_size=<span class="hljs-number">4</span>)).images
image_grid(images)`}}),Ce=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({}),Ye=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(){M=i("meta"),Z=f(),g=i("h1"),_=i("a"),T=i("span"),h(v.$$.fragment),U=f(),$=i("span"),di=a("Effective and efficient diffusion"),Il=f(),h(we.$$.fragment),Wl=f(),E=i("p"),yi=a("Getting the "),pt=i("a"),bi=a("DiffusionPipeline"),wi=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"),Mi=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"),Ui=a(" (speed) and "),Pt=i("em"),_i=a("memory"),Ti=a(" (GPU RAM) efficiency from the pipeline to reduce the time between inference cycles so you can iterate faster."),Vl=f(),Q=i("p"),Zi=a("This tutorial walks you through how to generate faster and better with the "),ct=i("a"),Gi=a("DiffusionPipeline"),ji=a("."),Nl=f(),Y=i("p"),$i=a("Begin by loading the "),Me=i("a"),Dt=i("code"),Ei=a("runwayml/stable-diffusion-v1-5"),ki=a(" model:"),Sl=f(),h(ge.$$.fragment),Cl=f(),ut=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"),F=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(Ue.$$.fragment),Dl=f(),I=i("p"),Ni=a("To make sure you can use the same image and improve on it, use a "),_e=i("a"),Qt=i("code"),Si=a("Generator"),Ci=a(" and set a seed for "),mt=i("a"),Ri=a("reproducibility"),Xi=a(":"),xl=f(),h(Te.$$.fragment),Hl=f(),dt=i("p"),Ai=a("Now you can generate an image:"),Ql=f(),h(Ze.$$.fragment),Yl=f(),Ge=i("div"),Yt=i("img"),Fl=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 "),Ft=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"),Yi=a(" or running fewer inference steps."),ql=f(),L=i("p"),Fi=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 "),wt=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 "),Mt=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"),co=a("Now set the "),el=i("code"),uo=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"),wo=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"),Mo=a("OutOfMemoryError"),go=a(" (OOM)."),cs=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"),Uo=a(". Make sure to assign each "),al=i("code"),_o=a("Generator"),To=a(" a seed so you can reuse it if it produces a good result."),us=f(),h(Ve.$$.fragment),hs=f(),Ut=i("p"),Zo=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(Se.$$.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 "),_t=i("a"),Wo=a("enable_attention_slicing()"),Bo=a(" function:"),ws=f(),h(Ce.$$.fragment),Ms=f(),se=i("p"),Vo=a("Now try increasing the "),pl=i("code"),No=a("batch_size"),So=a(" to 8!"),gs=f(),h(Re.$$.fragment),vs=f(),Xe=i("div"),fl=i("img"),Js=f(),Tt=i("p"),Co=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."),Us=f(),A=i("h2"),ie=i("a"),cl=i("span"),h(Ae.$$.fragment),Ro=f(),ul=i("span"),Xo=a("Quality"),_s=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."),Ts=f(),z=i("h3"),ae=i("a"),ml=i("span"),h(ze.$$.fragment),Do=f(),dl=i("span"),xo=a("Better checkpoints"),Zs=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"),Yo=a(") to get the best results."),Gs=f(),N=i("p"),Fo=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(Ye.$$.fragment),ks=f(),Fe=i("div"),wl=i("img"),Is=f(),D=i("h3"),fe=i("a"),Ml=i("span"),h(qe.$$.fragment),oa=f(),gl=i("span"),aa=a("Better prompt engineering"),Ws=f(),ce=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(),ue=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?"),ca=f(),Ul=i("li"),ua=a("What additional detail can I give that steers the model towards the style I want?"),Vs=f(),Zt=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),Ss=f(),Gt=i("p"),ma=a("Generate a batch of images with the new prompt:"),Cs=f(),h(Ke.$$.fragment),Rs=f(),Oe=i("div"),_l=i("img"),Xs=f(),S=i("p"),da=a("Pretty impressive! Let\u2019s tweak the second image - corresponding to the "),Tl=i("code"),ya=a("Generator"),ba=a(" with a seed of "),Zl=i("code"),wa=a("1"),Ma=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"),Ua=a("DiffusionPipeline"),_a=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(),C=i("ul"),H=i("li"),Ta=a("Learn how "),$t=i("a"),Za=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"),Sa=a("."),this.h()},l(e){const s=_n('[data-svelte="svelte-1phssyn"]',document.head);M=o(s,"META",{name:!0,content:!0}),s.forEach(t),Z=c(e),g=o(e,"H1",{class:!0});var at=n(g);_=o(at,"A",{id:!0,class:!0,href:!0});var kl=n(_);T=o(kl,"SPAN",{});var xa=n(T);m(v.$$.fragment,xa),xa.forEach(t),kl.forEach(t),U=c(at),$=o(at,"SPAN",{});var Ha=n($);di=r(Ha,"Effective and efficient diffusion"),Ha.forEach(t),at.forEach(t),Il=c(e),m(we.$$.fragment,e),Wl=c(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),wi=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 Ya=n(ft);Mi=r(Ya,"DiffusionPipeline"),Ya.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=c(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 Fa=n(zt);Ji=r(Fa,"computational"),Fa.forEach(t),Ui=r(Wt," (speed) and "),Pt=o(Wt,"EM",{});var qa=n(Pt);_i=r(qa,"memory"),qa.forEach(t),Ti=r(Wt," (GPU RAM) efficiency from the pipeline to reduce the time between inference cycles so you can iterate faster."),Wt.forEach(t),Vl=c(e),Q=o(e,"P",{});var Qs=n(Q);Zi=r(Qs,"This tutorial walks you through how to generate faster and better with the "),ct=o(Qs,"A",{href:!0});var La=n(ct);Gi=r(La,"DiffusionPipeline"),La.forEach(t),ji=r(Qs,"."),Qs.forEach(t),Nl=c(e),Y=o(e,"P",{});var Ys=n(Y);$i=r(Ys,"Begin by loading the "),Me=o(Ys,"A",{href:!0,rel:!0});var Ka=n(Me);Dt=o(Ka,"CODE",{});var Oa=n(Dt);Ei=r(Oa,"runwayml/stable-diffusion-v1-5"),Oa.forEach(t),Ka.forEach(t),ki=r(Ys," model:"),Ys.forEach(t),Sl=c(e),m(ge.$$.fragment,e),Cl=c(e),ut=o(e,"P",{});var er=n(ut);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=c(e),m(ve.$$.fragment,e),Xl=c(e),R=o(e,"H2",{class:!0});var Fs=n(R);F=o(Fs,"A",{id:!0,class:!0,href:!0});var tr=n(F);xt=o(tr,"SPAN",{});var lr=n(xt);m(Je.$$.fragment,lr),lr.forEach(t),tr.forEach(t),Wi=c(Fs),Ht=o(Fs,"SPAN",{});var sr=n(Ht);Bi=r(sr,"Speed"),sr.forEach(t),Fs.forEach(t),Al=c(e),m(q.$$.fragment,e),zl=c(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=c(e),m(Ue.$$.fragment,e),Dl=c(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 "),_e=o(Bt,"A",{href:!0,rel:!0});var or=n(_e);Qt=o(or,"CODE",{});var ar=n(Qt);Si=r(ar,"Generator"),ar.forEach(t),or.forEach(t),Ci=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=c(e),m(Te.$$.fragment,e),Hl=c(e),dt=o(e,"P",{});var nr=n(dt);Ai=r(nr,"Now you can generate an image:"),nr.forEach(t),Ql=c(e),m(Ze.$$.fragment,e),Yl=c(e),Ge=o(e,"DIV",{class:!0});var pr=n(Ge);Yt=o(pr,"IMG",{src:!0}),pr.forEach(t),Fl=c(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 "),Ft=o(de,"CODE",{});var cr=n(Ft);xi=r(cr,"float32"),cr.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 ur=n(qt);Qi=r(ur,"float16"),ur.forEach(t),Yi=r(de," or running fewer inference steps."),de.forEach(t),ql=c(e),L=o(e,"P",{});var qs=n(L);Fi=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=c(e),m(je.$$.fragment,e),Kl=c(e),$e=o(e,"DIV",{class:!0});var mr=n($e);Kt=o(mr,"IMG",{src:!0}),mr.forEach(t),Ol=c(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=c(e),m(K.$$.fragment,e),ts=c(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 "),wt=o(Vt,"A",{href:!0});var yr=n(wt);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=c(e),m(Ee.$$.fragment,e),ss=c(e),j=o(e,"P",{});var ye=n(j);io=r(ye,"The Stable Diffusion model uses the "),Mt=o(ye,"A",{href:!0});var wr=n(Mt);oo=r(wr,"PNDMScheduler"),wr.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 Mr=n(gt);ro=r(Mr,"DPMSolverMultistepScheduler"),Mr.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=c(e),m(ke.$$.fragment,e),os=c(e),O=o(e,"P",{});var Ls=n(O);co=r(Ls,"Now set the "),el=o(Ls,"CODE",{});var vr=n(el);uo=r(vr,"num_inference_steps"),vr.forEach(t),ho=r(Ls," to 20:"),Ls.forEach(t),as=c(e),m(Ie.$$.fragment,e),rs=c(e),We=o(e,"DIV",{class:!0});var Jr=n(We);tl=o(Jr,"IMG",{src:!0}),Jr.forEach(t),ns=c(e),Jt=o(e,"P",{});var Ur=n(Jt);mo=r(Ur,"Great, you\u2019ve managed to cut the inference time to just 4 seconds! \u26A1\uFE0F"),Ur.forEach(t),ps=c(e),X=o(e,"H2",{class:!0});var Ks=n(X);ee=o(Ks,"A",{id:!0,class:!0,href:!0});var _r=n(ee);ll=o(_r,"SPAN",{});var Tr=n(ll);m(Be.$$.fragment,Tr),Tr.forEach(t),_r.forEach(t),yo=c(Ks),sl=o(Ks,"SPAN",{});var Zr=n(sl);bo=r(Zr,"Memory"),Zr.forEach(t),Ks.forEach(t),fs=c(e),te=o(e,"P",{});var Os=n(te);wo=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);Mo=r(Gr,"OutOfMemoryError"),Gr.forEach(t),go=r(Os," (OOM)."),Os.forEach(t),cs=c(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),Uo=r(Nt,". Make sure to assign each "),al=o(Nt,"CODE",{});var $r=n(al);_o=r($r,"Generator"),$r.forEach(t),To=r(Nt," a seed so you can reuse it if it produces a good result."),Nt.forEach(t),us=c(e),m(Ve.$$.fragment,e),hs=c(e),Ut=o(e,"P",{});var Er=n(Ut);Zo=r(Er,"You\u2019ll also need a function that\u2019ll display each batch of images:"),Er.forEach(t),ms=c(e),m(Ne.$$.fragment,e),ds=c(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=c(e),m(Se.$$.fragment,e),bs=c(e),V=o(e,"P",{});var St=n(V);Eo=r(St,"Unless you have a GPU with more RAM, the code above probably returned an "),nl=o(St,"CODE",{});var Ir=n(nl);ko=r(Ir,"OOM"),Ir.forEach(t),Io=r(St," 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 "),_t=o(St,"A",{href:!0});var Wr=n(_t);Wo=r(Wr,"enable_attention_slicing()"),Wr.forEach(t),Bo=r(St," function:"),St.forEach(t),ws=c(e),m(Ce.$$.fragment,e),Ms=c(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),So=r(ti," to 8!"),ti.forEach(t),gs=c(e),m(Re.$$.fragment,e),vs=c(e),Xe=o(e,"DIV",{class:!0});var Vr=n(Xe);fl=o(Vr,"IMG",{src:!0}),Vr.forEach(t),Js=c(e),Tt=o(e,"P",{});var Nr=n(Tt);Co=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),Us=c(e),A=o(e,"H2",{class:!0});var li=n(A);ie=o(li,"A",{id:!0,class:!0,href:!0});var Sr=n(ie);cl=o(Sr,"SPAN",{});var Cr=n(cl);m(Ae.$$.fragment,Cr),Cr.forEach(t),Sr.forEach(t),Ro=c(li),ul=o(li,"SPAN",{});var Rr=n(ul);Xo=r(Rr,"Quality"),Rr.forEach(t),li.forEach(t),_s=c(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),Ts=c(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=c(ii),dl=o(ii,"SPAN",{});var Pr=n(dl);xo=r(Pr,"Better checkpoints"),Pr.forEach(t),ii.forEach(t),Zs=c(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),Yo=r(oi,") to get the best results."),oi.forEach(t),Gs=c(e),N=o(e,"P",{});var Ct=n(N);Fo=r(Ct,"As the field grows, there are more and more high-quality checkpoints finetuned to produce certain styles. Try exploring the "),De=o(Ct,"A",{href:!0,rel:!0});var xr=n(De);qo=r(xr,"Hub"),xr.forEach(t),Lo=r(Ct," and "),xe=o(Ct,"A",{href:!0,rel:!0});var Hr=n(xe);Ko=r(Hr,"Diffusers Gallery"),Hr.forEach(t),Oo=r(Ct," to find one you\u2019re interested in!"),Ct.forEach(t),js=c(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 Yr=n(yl);m(He.$$.fragment,Yr),Yr.forEach(t),Qr.forEach(t),ea=c(ai),bl=o(ai,"SPAN",{});var Fr=n(bl);ta=r(Fr,"Better pipeline components"),Fr.forEach(t),ai.forEach(t),$s=c(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=c(e),m(Ye.$$.fragment,e),ks=c(e),Fe=o(e,"DIV",{class:!0});var Lr=n(Fe);wl=o(Lr,"IMG",{src:!0}),Lr.forEach(t),Is=c(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);Ml=o(Kr,"SPAN",{});var Or=n(Ml);m(qe.$$.fragment,Or),Or.forEach(t),Kr.forEach(t),oa=c(ni),gl=o(ni,"SPAN",{});var en=n(gl);aa=r(en,"Better prompt engineering"),en.forEach(t),ni.forEach(t),Ws=c(e),ce=o(e,"P",{});var pi=n(ce);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=c(e),ue=o(e,"UL",{});var fi=n(ue);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),ca=c(fi),Ul=o(fi,"LI",{});var sn=n(Ul);ua=r(sn,"What additional detail can I give that steers the model towards the style I want?"),sn.forEach(t),fi.forEach(t),Vs=c(e),Zt=o(e,"P",{});var on=n(Zt);ha=r(on,"With this in mind, let\u2019s improve the prompt to include color and higher quality details:"),on.forEach(t),Ns=c(e),m(Le.$$.fragment,e),Ss=c(e),Gt=o(e,"P",{});var an=n(Gt);ma=r(an,"Generate a batch of images with the new prompt:"),an.forEach(t),Cs=c(e),m(Ke.$$.fragment,e),Rs=c(e),Oe=o(e,"DIV",{class:!0});var rn=n(Oe);_l=o(rn,"IMG",{src:!0}),rn.forEach(t),Xs=c(e),S=o(e,"P",{});var Rt=n(S);da=r(Rt,"Pretty impressive! Let\u2019s tweak the second image - corresponding to the "),Tl=o(Rt,"CODE",{});var nn=n(Tl);ya=r(nn,"Generator"),nn.forEach(t),ba=r(Rt," with a seed of "),Zl=o(Rt,"CODE",{});var pn=n(Zl);wa=r(pn,"1"),pn.forEach(t),Ma=r(Rt," - a bit more by adding some text about the age of the subject:"),Rt.forEach(t),As=c(e),m(et.$$.fragment,e),zs=c(e),tt=o(e,"DIV",{class:!0});var fn=n(tt);Gl=o(fn,"IMG",{src:!0}),fn.forEach(t),Ps=c(e),x=o(e,"H2",{class:!0});var ci=n(x);he=o(ci,"A",{id:!0,class:!0,href:!0});var cn=n(he);jl=o(cn,"SPAN",{});var un=n(jl);m(lt.$$.fragment,un),un.forEach(t),cn.forEach(t),ga=c(ci),$l=o(ci,"SPAN",{});var hn=n($l);va=r(hn,"Next steps"),hn.forEach(t),ci.forEach(t),Ds=c(e),me=o(e,"P",{});var ui=n(me);Ja=r(ui,"In this tutorial, you learned how to optimize a "),jt=o(ui,"A",{href:!0});var mn=n(jt);Ua=r(mn,"DiffusionPipeline"),mn.forEach(t),_a=r(ui," 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:"),ui.forEach(t),xs=c(e),C=o(e,"UL",{});var Xt=n(C);H=o(Xt,"LI",{});var At=n(H);Ta=r(At,"Learn how "),$t=o(At,"A",{href:!0});var dn=n($t);Za=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=c(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 wn=n(Et);Ia=r(wn,"xFormers"),wn.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=c(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 Mn=n(kt);Na=r(Mn,"this guide"),Mn.forEach(t),Sa=r(mi,"."),mi.forEach(t),Xt.forEach(t),this.h()},h(){u(M,"name","hf:doc:metadata"),u(M,"content",JSON.stringify(En)),u(_,"id","effective-and-efficient-diffusion"),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"),u(_,"href","#effective-and-efficient-diffusion"),u(g,"class","relative group"),u(pt,"href","/docs/diffusers/main/en/api/pipelines/overview#diffusers.DiffusionPipeline"),u(ft,"href","/docs/diffusers/main/en/api/pipelines/overview#diffusers.DiffusionPipeline"),u(ct,"href","/docs/diffusers/main/en/api/pipelines/overview#diffusers.DiffusionPipeline"),u(Me,"href","https://huggingface.co/runwayml/stable-diffusion-v1-5"),u(Me,"rel","nofollow"),u(F,"id","speed"),u(F,"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"),u(F,"href","#speed"),u(R,"class","relative group"),u(_e,"href","https://pytorch.org/docs/stable/generated/torch.Generator.html"),u(_e,"rel","nofollow"),u(mt,"href","./using-diffusers/reproducibility"),rt(Yt.src,Ca="https://huggingface.co/datasets/diffusers/docs-images/resolve/main/stable_diffusion_101/sd_101_1.png")||u(Yt,"src",Ca),u(Ge,"class","flex justify-center"),u(yt,"href","/docs/diffusers/main/en/api/pipelines/overview#diffusers.DiffusionPipeline"),rt(Kt.src,Ra="https://huggingface.co/datasets/diffusers/docs-images/resolve/main/stable_diffusion_101/sd_101_2.png")||u(Kt,"src",Ra),u($e,"class","flex justify-center"),u(wt,"href","/docs/diffusers/main/en/api/pipelines/overview#diffusers.DiffusionPipeline"),u(Mt,"href","/docs/diffusers/main/en/api/schedulers/pndm#diffusers.PNDMScheduler"),u(gt,"href","/docs/diffusers/main/en/api/schedulers/multistep_dpm_solver#diffusers.DPMSolverMultistepScheduler"),u(vt,"href","/docs/diffusers/main/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")||u(tl,"src",Xa),u(We,"class","flex justify-center"),u(ee,"id","memory"),u(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"),u(ee,"href","#memory"),u(X,"class","relative group"),u(_t,"href","/docs/diffusers/main/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")||u(fl,"src",Aa),u(Xe,"class","flex justify-center"),u(ie,"id","quality"),u(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"),u(ie,"href","#quality"),u(A,"class","relative group"),u(ae,"id","better-checkpoints"),u(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"),u(ae,"href","#better-checkpoints"),u(z,"class","relative group"),u(Pe,"href","https://minimaxir.com/2022/11/stable-diffusion-negative-prompt/"),u(Pe,"rel","nofollow"),u(De,"href","https://huggingface.co/models?library=diffusers&sort=downloads"),u(De,"rel","nofollow"),u(xe,"href","https://huggingface.co/spaces/huggingface-projects/diffusers-gallery"),u(xe,"rel","nofollow"),u(ne,"id","better-pipeline-components"),u(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"),u(ne,"href","#better-pipeline-components"),u(P,"class","relative group"),u(Qe,"href","https://huggingface.co/stabilityai/stable-diffusion-2-1/tree/main/vae"),u(Qe,"rel","nofollow"),rt(wl.src,za="https://huggingface.co/datasets/diffusers/docs-images/resolve/main/stable_diffusion_101/sd_101_6.png")||u(wl,"src",za),u(Fe,"class","flex justify-center"),u(fe,"id","better-prompt-engineering"),u(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"),u(fe,"href","#better-prompt-engineering"),u(D,"class","relative group"),rt(_l.src,Pa="https://huggingface.co/datasets/diffusers/docs-images/resolve/main/stable_diffusion_101/sd_101_7.png")||u(_l,"src",Pa),u(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")||u(Gl,"src",Da),u(tt,"class","flex justify-center"),u(he,"id","next-steps"),u(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"),u(he,"href","#next-steps"),u(x,"class","relative group"),u(jt,"href","/docs/diffusers/main/en/api/pipelines/overview#diffusers.DiffusionPipeline"),u($t,"href","./optimization/torch2.0"),u(st,"href","https://pytorch.org/docs/stable/generated/torch.compile.html"),u(st,"rel","nofollow"),u(Et,"href","./optimization/xformers"),u(kt,"href","./optimization/fp16")},m(e,s){l(document.head,M),p(e,Z,s),p(e,g,s),l(g,_),l(_,T),d(v,T,null),l(g,U),l(g,$),l($,di),p(e,Il,s),d(we,e,s),p(e,Wl,s),p(e,E,s),l(E,yi),l(E,pt),l(pt,bi),l(E,wi),l(E,ft),l(ft,Mi),l(E,gi),p(e,Bl,s),p(e,k,s),l(k,vi),l(k,zt),l(zt,Ji),l(k,Ui),l(k,Pt),l(Pt,_i),l(k,Ti),p(e,Vl,s),p(e,Q,s),l(Q,Zi),l(Q,ct),l(ct,Gi),l(Q,ji),p(e,Nl,s),p(e,Y,s),l(Y,$i),l(Y,Me),l(Me,Dt),l(Dt,Ei),l(Y,ki),p(e,Sl,s),d(ge,e,s),p(e,Cl,s),p(e,ut,s),l(ut,Ii),p(e,Rl,s),d(ve,e,s),p(e,Xl,s),p(e,R,s),l(R,F),l(F,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(Ue,e,s),p(e,Dl,s),p(e,I,s),l(I,Ni),l(I,_e),l(_e,Qt),l(Qt,Si),l(I,Ci),l(I,mt),l(mt,Ri),l(I,Xi),p(e,xl,s),d(Te,e,s),p(e,Hl,s),p(e,dt,s),l(dt,Ai),p(e,Ql,s),d(Ze,e,s),p(e,Yl,s),p(e,Ge,s),l(Ge,Yt),p(e,Fl,s),p(e,G,s),l(G,zi),l(G,yt),l(yt,Pi),l(G,Di),l(G,Ft),l(Ft,xi),l(G,Hi),l(G,qt),l(qt,Qi),l(G,Yi),p(e,ql,s),p(e,L,s),l(L,Fi),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,wt),l(wt,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,Mt),l(Mt,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,co),l(O,el),l(el,uo),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,wo),l(te,il),l(il,Mo),l(te,go),p(e,cs,s),p(e,B,s),l(B,vo),l(B,ol),l(ol,Jo),l(B,Uo),l(B,al),l(al,_o),l(B,To),p(e,us,s),d(Ve,e,s),p(e,hs,s),p(e,Ut,s),l(Ut,Zo),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(Se,e,s),p(e,bs,s),p(e,V,s),l(V,Eo),l(V,nl),l(nl,ko),l(V,Io),l(V,_t),l(_t,Wo),l(V,Bo),p(e,ws,s),d(Ce,e,s),p(e,Ms,s),p(e,se,s),l(se,Vo),l(se,pl),l(pl,No),l(se,So),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,Tt,s),l(Tt,Co),p(e,Us,s),p(e,A,s),l(A,ie),l(ie,cl),d(Ae,cl,null),l(A,Ro),l(A,ul),l(ul,Xo),p(e,_s,s),p(e,oe,s),l(oe,Ao),l(oe,hl),l(hl,zo),l(oe,Po),p(e,Ts,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,Zs,s),p(e,re,s),l(re,Ho),l(re,Pe),l(Pe,Qo),l(re,Yo),p(e,Gs,s),p(e,N,s),l(N,Fo),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(Ye,e,s),p(e,ks,s),p(e,Fe,s),l(Fe,wl),p(e,Is,s),p(e,D,s),l(D,fe),l(fe,Ml),d(qe,Ml,null),l(D,oa),l(D,gl),l(gl,aa),p(e,Ws,s),p(e,ce,s),l(ce,ra),l(ce,vl),l(vl,na),l(ce,pa),p(e,Bs,s),p(e,ue,s),l(ue,Jl),l(Jl,fa),l(ue,ca),l(ue,Ul),l(Ul,ua),p(e,Vs,s),p(e,Zt,s),l(Zt,ha),p(e,Ns,s),d(Le,e,s),p(e,Ss,s),p(e,Gt,s),l(Gt,ma),p(e,Cs,s),d(Ke,e,s),p(e,Rs,s),p(e,Oe,s),l(Oe,_l),p(e,Xs,s),p(e,S,s),l(S,da),l(S,Tl),l(Tl,ya),l(S,ba),l(S,Zl),l(Zl,wa),l(S,Ma),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,Ua),l(me,_a),p(e,xs,s),p(e,C,s),l(C,H),l(H,Ta),l(H,$t),l($t,Za),l(H,Ga),l(H,st),l(st,El),l(El,ja),l(H,$a),l(C,Ea),l(C,it),l(it,ka),l(it,Et),l(Et,Ia),l(it,Wa),l(C,Ba),l(C,ot),l(ot,Va),l(ot,kt),l(kt,Na),l(ot,Sa),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(we.$$.fragment,e),y(ge.$$.fragment,e),y(ve.$$.fragment,e),y(Je.$$.fragment,e),y(q.$$.fragment,e),y(Ue.$$.fragment,e),y(Te.$$.fragment,e),y(Ze.$$.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(Se.$$.fragment,e),y(Ce.$$.fragment,e),y(Re.$$.fragment,e),y(Ae.$$.fragment,e),y(ze.$$.fragment,e),y(He.$$.fragment,e),y(Ye.$$.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(we.$$.fragment,e),b(ge.$$.fragment,e),b(ve.$$.fragment,e),b(Je.$$.fragment,e),b(q.$$.fragment,e),b(Ue.$$.fragment,e),b(Te.$$.fragment,e),b(Ze.$$.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(Se.$$.fragment,e),b(Ce.$$.fragment,e),b(Re.$$.fragment,e),b(Ae.$$.fragment,e),b(ze.$$.fragment,e),b(He.$$.fragment,e),b(Ye.$$.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(M),e&&t(Z),e&&t(g),w(v),e&&t(Il),w(we,e),e&&t(Wl),e&&t(E),e&&t(Bl),e&&t(k),e&&t(Vl),e&&t(Q),e&&t(Nl),e&&t(Y),e&&t(Sl),w(ge,e),e&&t(Cl),e&&t(ut),e&&t(Rl),w(ve,e),e&&t(Xl),e&&t(R),w(Je),e&&t(Al),w(q,e),e&&t(zl),e&&t(ht),e&&t(Pl),w(Ue,e),e&&t(Dl),e&&t(I),e&&t(xl),w(Te,e),e&&t(Hl),e&&t(dt),e&&t(Ql),w(Ze,e),e&&t(Yl),e&&t(Ge),e&&t(Fl),e&&t(G),e&&t(ql),e&&t(L),e&&t(Ll),w(je,e),e&&t(Kl),e&&t($e),e&&t(Ol),e&&t(bt),e&&t(es),w(K,e),e&&t(ts),e&&t(W),e&&t(ls),w(Ee,e),e&&t(ss),e&&t(j),e&&t(is),w(ke,e),e&&t(os),e&&t(O),e&&t(as),w(Ie,e),e&&t(rs),e&&t(We),e&&t(ns),e&&t(Jt),e&&t(ps),e&&t(X),w(Be),e&&t(fs),e&&t(te),e&&t(cs),e&&t(B),e&&t(us),w(Ve,e),e&&t(hs),e&&t(Ut),e&&t(ms),w(Ne,e),e&&t(ds),e&&t(le),e&&t(ys),w(Se,e),e&&t(bs),e&&t(V),e&&t(ws),w(Ce,e),e&&t(Ms),e&&t(se),e&&t(gs),w(Re,e),e&&t(vs),e&&t(Xe),e&&t(Js),e&&t(Tt),e&&t(Us),e&&t(A),w(Ae),e&&t(_s),e&&t(oe),e&&t(Ts),e&&t(z),w(ze),e&&t(Zs),e&&t(re),e&&t(Gs),e&&t(N),e&&t(js),e&&t(P),w(He),e&&t($s),e&&t(pe),e&&t(Es),w(Ye,e),e&&t(ks),e&&t(Fe),e&&t(Is),e&&t(D),w(qe),e&&t(Ws),e&&t(ce),e&&t(Bs),e&&t(ue),e&&t(Vs),e&&t(Zt),e&&t(Ns),w(Le,e),e&&t(Ss),e&&t(Gt),e&&t(Cs),w(Ke,e),e&&t(Rs),e&&t(Oe),e&&t(Xs),e&&t(S),e&&t(As),w(et,e),e&&t(zs),e&&t(tt),e&&t(Ps),e&&t(x),w(lt),e&&t(Ds),e&&t(me),e&&t(xs),e&&t(C)}}}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 Tn(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Sn extends vn{constructor(M){super();Jn(this,M,kn,$n,Un,{})}}export{Sn as default,En as metadata};
