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wo,Z,$a,Ce,ka,Ea,vo,Bt,Pa,_o,D,Sa,Xs,ja,Da,Ue,qa,Aa,$o,He,ko,ee,Ma,Ys,Ia,Ta,Eo,We,Po,Vt,Qt,yp,So,Kt,Ga,jo,Xt,za,Do,Yt,La,qo,N,te,Js,Fe,Na,Zs,xa,Ao,Jt,Oa,Mo,Zt,Ca,Io,se,Ua,ei,Ha,Wa,To,E,Re,ti,Fa,Ra,Be,Ba,Va,Ve,si,Qa,Ka,Qe,Xa,Ya,Ke,ii,Ja,Za,Xe,en,tn,Ye,oi,sn,on,Je,rn,Go,_,ln,ri,an,nn,li,pn,fn,ai,un,mn,ni,hn,cn,zo,ie,dn,Ze,gn,bn,Lo,es,yn,No,oe,wn,et,vn,_n,xo,ts,$n,Oo,re,kn,tt,En,Pn,Co,le,Sn,st,jn,Dn,Uo,it,Ho,ss,qn,Wo,ot,Fo,is,An,Ro,rt,Bo,os,rs,wp,Vo,ae,Mn,pi,In,Tn,Qo,ls,Gn,Ko,as,zn,Xo,ne,Ln,fi,Nn,xn,Yo,pe,On,Cn,Un,Jo,fe,ui,Hn,Wn,mi,Fn,Zo,ns,Rn,er,lt,tr,ps,Bn,sr,at,ir,fs,Vn,or,nt,rr,us,ms,vp,lr,hs,Qn,ar,pt,nr,cs,ds,_p,pr,gs,Kn,fr,bs,Xn,ur,P,ys,ft,Yn,Jn,Zn,ws,ut,ep,tp,sp,vs,mt,ip,op,rp,_s,ht,lp,ap,mr;return de=new Ps({}),ge=new Ps({}),we=new Ps({}),_e=new w({props:{code:'model_id = "runwayml/stable-diffusion-v1-5"                                                                                                                                                                                                   ',highlighted:'model_id = <span class="hljs-string">&quot;runwayml/stable-diffusion-v1-5&quot;</span>                                                                                                                                                                                                   '}}),$e=new Ps({}),ke=new w({props:{code:`from diffusers import StableDiffusionPipeline                                                                                                                                                                                                 
                                                                                                                                                                                                                                              
pipe = StableDiffusionPipeline.from_pretrained(model_id)                                                                                                                                                                                      `,highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> StableDiffusionPipeline                                                                                                                                                                                                 
                                                                                                                                                                                                                                              
pipe = StableDiffusionPipeline.from_pretrained(model_id)                                                                                                                                                                                      `}}),Ee=new w({props:{code:'prompt = "portrait photo of a old warrior chief"                                                                                                                                                                                                                                                                                                                                                                                                                                            ',highlighted:'prompt = <span class="hljs-string">&quot;portrait photo of a old warrior chief&quot;</span>                                                                                                                                                                                                                                                                                                                                                                                                                                            '}}),Pe=new w({props:{code:'pipe = pipe.to("cuda")                                                                                                                                                                                                                                                                                                                                                                                                                                                                      ',highlighted:'pipe = pipe.to(<span class="hljs-string">&quot;cuda&quot;</span>)                                                                                                                                                                                                                                                                                                                                                                                                                                                                      '}}),Se=new w({props:{code:'generator = torch.Generator("cuda").manual_seed(0)                                                                                                                                                                                            ',highlighted:'generator = torch.Generator(<span class="hljs-string">&quot;cuda&quot;</span>).manual_seed(<span class="hljs-number">0</span>)                                                                                                                                                                                            '}}),je=new w({props:{code:`image = pipe(prompt, generator=generator).images[0]                                                                                                                                                                                           
image                                                                                                                                                                                                                                         `,highlighted:`image = pipe(prompt, generator=generator).images[<span class="hljs-number">0</span>]                                                                                                                                                                                           
image                                                                                                                                                                                                                                         `}}),De=new w({props:{code:`import torch                                                                                                                                                                                                                                  

pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)                                                                                                                                                           
pipe = pipe.to("cuda")                                                                                                                                                                                                                        `,highlighted:`<span class="hljs-keyword">import</span> torch                                                                                                                                                                                                                                  

pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)                                                                                                                                                           
pipe = pipe.to(<span class="hljs-string">&quot;cuda&quot;</span>)                                                                                                                                                                                                                        `}}),qe=new w({props:{code:`generator = torch.Generator("cuda").manual_seed(0)                                                                                                                                                                                            

image = pipe(prompt, generator=generator).images[0]                                                                                                                                                                                           
image                                                                                                                                                                                                                                         `,highlighted:`generator = torch.Generator(<span class="hljs-string">&quot;cuda&quot;</span>).manual_seed(<span class="hljs-number">0</span>)                                                                                                                                                                                            

image = pipe(prompt, generator=generator).images[<span class="hljs-number">0</span>]                                                                                                                                                                                           
image                                                                                                                                                                                                                                         `}}),Ae=new w({props:{code:"pipe.scheduler.compatibles                                                                                                                                                                                                                    ",highlighted:"pipe.scheduler.compatibles                                                                                                                                                                                                                    "}}),Me=new w({props:{code:`    [diffusers.schedulers.scheduling_dpmsolver_singlestep.DPMSolverSinglestepScheduler,                                                                                                                                                       
     diffusers.schedulers.scheduling_lms_discrete.LMSDiscreteScheduler,                                                                                                                                                                       
     diffusers.schedulers.scheduling_heun_discrete.HeunDiscreteScheduler,                                                                                                                                                                     
     diffusers.schedulers.scheduling_pndm.PNDMScheduler,                                                                                                                                                                                      
     diffusers.schedulers.scheduling_euler_discrete.EulerDiscreteScheduler,                                                                                                                                                                   
     diffusers.schedulers.scheduling_euler_ancestral_discrete.EulerAncestralDiscreteScheduler,                                                                                                                                                
     diffusers.schedulers.scheduling_dpmsolver_multistep.DPMSolverMultistepScheduler,                                                                                                                                                         
     diffusers.schedulers.scheduling_ddpm.DDPMScheduler,                                                                                                                                                                                      
     diffusers.schedulers.scheduling_ddim.DDIMScheduler]                                                                                                                                                                                      `,highlighted:`    [<span class="hljs-keyword">diffusers.schedulers.scheduling_dpmsolver_singlestep.DPMSolverSinglestepScheduler, </span>                                                                                                                                                      
     <span class="hljs-keyword">diffusers.schedulers.scheduling_lms_discrete.LMSDiscreteScheduler, </span>                                                                                                                                                                      
     <span class="hljs-keyword">diffusers.schedulers.scheduling_heun_discrete.HeunDiscreteScheduler, </span>                                                                                                                                                                    
     <span class="hljs-keyword">diffusers.schedulers.scheduling_pndm.PNDMScheduler, </span>                                                                                                                                                                                     
     <span class="hljs-keyword">diffusers.schedulers.scheduling_euler_discrete.EulerDiscreteScheduler, </span>                                                                                                                                                                  
     <span class="hljs-keyword">diffusers.schedulers.scheduling_euler_ancestral_discrete.EulerAncestralDiscreteScheduler, </span>                                                                                                                                               
     <span class="hljs-keyword">diffusers.schedulers.scheduling_dpmsolver_multistep.DPMSolverMultistepScheduler, </span>                                                                                                                                                        
     <span class="hljs-keyword">diffusers.schedulers.scheduling_ddpm.DDPMScheduler, </span>                                                                                                                                                                                     
     <span class="hljs-keyword">diffusers.schedulers.scheduling_ddim.DDIMScheduler] </span>                                                                                                                                                                                     `}}),Ge=new w({props:{code:`from diffusers import DPMSolverMultistepScheduler                                                                                                                                                                                             
                                                                                                                                                                                                                                              
pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)                                                                                                                                                               `,highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DPMSolverMultistepScheduler                                                                                                                                                                                             
                                                                                                                                                                                                                                              
pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)                                                                                                                                                               `}}),ze=new w({props:{code:`generator = torch.Generator("cuda").manual_seed(0)                                                                                                                                                                                            
                                                                                                                                                                                                                                              
image = pipe(prompt, generator=generator, num_inference_steps=20).images[0]                                                                                                                                                                   
image                                                                                                                                                                                                                                         `,highlighted:`generator = torch.Generator(<span class="hljs-string">&quot;cuda&quot;</span>).manual_seed(<span class="hljs-number">0</span>)                                                                                                                                                                                            
                                                                                                                                                                                                                                              
image = pipe(prompt, generator=generator, num_inference_steps=<span class="hljs-number">20</span>).images[<span class="hljs-number">0</span>]                                                                                                                                                                   
image                                                                                                                                                                                                                                         `}}),Le=new Ps({}),Ne=new w({props:{code:`def get_inputs(batch_size=1):                                                                                                                                                                                                                 
  generator = [torch.Generator("cuda").manual_seed(i) for i in range(batch_size)]                                                                                                                                                             
  prompts = batch_size * [prompt]                                                                                                                                                                                                             
  num_inference_steps = 20                                                                                                                                                                                                                    

  return {"prompt": prompts, "generator": generator, "num_inference_steps": num_inference_steps}                                                                                                                                              `,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}                                                                                                                                              `}}),xe=new w({props:{code:`from PIL import Image                                                                                                                                                                                                                         

def image_grid(imgs, rows=2, cols=2):                                                                                                                                                                                                         
    w, h = imgs[0].size                                                                                                                                                                                                                       
    grid = Image.new('RGB', size=(cols*w, rows*h))                                                                                                                                                                                            
                                                                                                                                                                                                                                              
    for i, img in enumerate(imgs):                                                                                                                                                                                                            
        grid.paste(img, box=(i%cols*w, i//cols*h))                                                                                                                                                                                            
    return grid                                                                                                                                                                                                                               `,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">&#x27;RGB&#x27;</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                                                                                                                                                                                                                               `}}),Oe=new w({props:{code:`images = pipe(**get_inputs(batch_size=4)).images                                                                                                                                                                                              
image_grid(images)                                                                                                                                                                                                                            `,highlighted:`images = pipe(**get_inputs(batch_size=<span class="hljs-number">4</span>)).images                                                                                                                                                                                              
image_grid(images)                                                                                                                                                                                                                            `}}),He=new w({props:{code:"pipe.enable_attention_slicing()                                                                                                                                                                                                               ",highlighted:"pipe.enable_attention_slicing()                                                                                                                                                                                                               "}}),We=new w({props:{code:`images = pipe(**get_inputs(batch_size=8)).images                                                                                                                                                                                              
image_grid(images, rows=2, cols=4)                                                                                                                                                                                                            `,highlighted:`images = pipe(**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>)                                                                                                                                                                                                            `}}),Fe=new Ps({}),it=new w({props:{code:`from diffusers import AutoencoderKL                                                                                                                                                                                                           

vae = AutoencoderKL.from_pretrained("stabilityai/sd-vae-ft-mse", torch_dtype=torch.float16).to("cuda")                                                                                                                                        `,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>)                                                                                                                                        `}}),ot=new w({props:{code:"pipe.vae = vae                                                                                                                                                                                                                                ",highlighted:"pipe.vae = vae                                                                                                                                                                                                                                "}}),rt=new w({props:{code:`images = pipe(**get_inputs(batch_size=8)).images                                                                                                                                                                                              
image_grid(images, rows=2, cols=4)                                                                                                                                                                                                            `,highlighted:`images = pipe(**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>)                                                                                                                                                                                                            `}}),lt=new w({props:{code:'prompt += ", tribal panther make up, blue on red, side profile, looking away, serious eyes"                                                                                                                                                   ',highlighted:'prompt += <span class="hljs-string">&quot;, tribal panther make up, blue on red, side profile, looking away, serious eyes&quot;</span>                                                                                                                                                   '}}),at=new w({props:{code:`prompt += " 50mm portrait photography, hard rim lighting photography--beta --ar 2:3  --beta --upbeta"                                                                                                                                         
prompt                                                                                                                                                                                                                                        `,highlighted:`prompt += <span class="hljs-string">&quot; 50mm portrait photography, hard rim lighting photography--beta --ar 2:3  --beta --upbeta&quot;</span>                                                                                                                                         
prompt                                                                                                                                                                                                                                        `}}),nt=new w({props:{code:`images = pipe(**get_inputs(batch_size=8)).images                                                                                                                                                                                              
image_grid(images, rows=2, cols=4)                                                                                                                                                                                                            `,highlighted:`images = pipe(**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>)                                                                                                                                                                                                            `}}),pt=new w({props:{code:`prompts = [                                                                                                                                                                                                                                   
    "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",                                                                                                                                                                                                                                                                   
    "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",                                                                                                                                                                                                                                                                        
    "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",                                                                                                                                                                                                                                                                            
    "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",                                                                                                                                                                                                                                                                      
]                                                                                                                                                                                                                                             

generator = [torch.Generator("cuda").manual_seed(1) for _ in range(len(prompts))]  # 1 because we want the 2nd image                                                                                                                          

images = pipe(prompt=prompts, generator=generator, num_inference_steps=25).images                                                                                                                                                             
image_grid(images)                                                                                                                                                                                                                            `,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))]  <span class="hljs-comment"># 1 because we want the 2nd image                                                                                                                          </span>

images = pipe(prompt=prompts, generator=generator, num_inference_steps=<span class="hljs-number">25</span>).images                                                                                                                                                             
image_grid(images)                                                                                                                                                                                                                            `}}),{c(){M=r("meta"),hi=f(),I=r("h1"),O=r("a"),Ss=r("span"),h(de.$$.fragment),Hr=f(),js=r("span"),Wr=a("The Stable Diffusion Guide \u{1F3A8}"),ci=f(),C=r("a"),ct=r("img"),di=f(),T=r("h2"),U=r("a"),Ds=r("span"),h(ge.$$.fragment),Fr=f(),qs=r("span"),Rr=a("Intro"),gi=f(),v=r("p"),Br=a("Stable Diffusion is a "),be=r("a"),Vr=a("Latent Diffusion model"),Qr=a(" developed by researchers from the Machine Vision and Learning group at LMU Munich, "),As=r("em"),Kr=a("a.k.a"),Xr=a(" CompVis."),Yr=r("br"),Jr=a(`
Model checkpoints were publicly released at the end of August 2022 by a collaboration of Stability AI, CompVis, and Runway with support from EleutherAI and LAION. For more information, you can check out `),ye=r("a"),Zr=a("the official blog post"),el=a("."),bi=f(),$=r("p"),tl=a("Since its public release the community has done an incredible job at working together to make the stable diffusion checkpoints "),Ms=r("strong"),sl=a("faster"),il=a(", "),Is=r("strong"),ol=a("more memory efficient"),rl=a(", and "),Ts=r("strong"),ll=a("more performant"),al=a("."),yi=f(),dt=r("p"),nl=a("\u{1F9E8} Diffusers offers a simple API to run stable diffusion with all memory, computing, and quality improvements."),wi=f(),S=r("p"),pl=a("This notebook walks you through the improvements one-by-one so you can best leverage "),gt=r("a"),fl=a("StableDiffusionPipeline"),ul=a(" for "),Gs=r("strong"),ml=a("inference"),hl=a("."),vi=f(),G=r("h2"),H=r("a"),zs=r("span"),h(we.$$.fragment),cl=f(),Ls=r("span"),dl=a("Prompt Engineering \u{1F3A8}"),_i=a(`

                                                                                                                                                                                                                                              
When running *Stable Diffusion* in inference, we usually want to generate a certain type, or style of image and then improve upon it. Improving upon a previously generated image means running inference over and over again with a different prompt and potentially a different seed until we are happy with our generation.
`),bt=r("p"),gl=a("So to begin with, it is most important to speed up stable diffusion as much as possible to generate as many pictures as possible in a given amount of time."),$i=f(),j=r("p"),bl=a("This can be done by both improving the "),Ns=r("strong"),yl=a("computational efficiency"),wl=a(" (speed) and the "),xs=r("strong"),vl=a("memory efficiency"),_l=a(" (GPU RAM)."),ki=f(),yt=r("p"),$l=a("Let\u2019s start by looking into computational efficiency first."),Ei=f(),W=r("p"),kl=a("Throughout the notebook, we will focus on "),ve=r("a"),El=a("runwayml/stable-diffusion-v1-5"),Pl=a(":"),Pi=f(),h(_e.$$.fragment),Si=f(),wt=r("p"),Sl=a("Let\u2019s load the pipeline."),ji=f(),z=r("h2"),F=r("a"),Os=r("span"),h($e.$$.fragment),jl=f(),Cs=r("span"),Dl=a("Speed Optimization"),Di=f(),h(ke.$$.fragment),qi=f(),R=r("p"),ql=a("We aim at generating a beautiful photograph of an "),Us=r("em"),Al=a("old warrior chief"),Ml=a(" and will later try to find the best prompt to generate such a photograph. For now, let\u2019s keep the prompt simple:"),Ai=f(),h(Ee.$$.fragment),Mi=f(),vt=r("p"),Il=a("To begin with, we should make sure we run inference on GPU, so let\u2019s move the pipeline to GPU, just like you would with any PyTorch module."),Ii=f(),h(Pe.$$.fragment),Ti=f(),B=r("p"),Tl=a("To generate an image, you should use the [~"),Hs=r("code"),Gl=a("StableDiffusionPipeline.__call__"),zl=a("] method."),Gi=f(),V=r("p"),Ll=a("To make sure we can reproduce more or less the same image in every call, let\u2019s make use of the generator. See the documentation on reproducibility "),_t=r("a"),Nl=a("here"),xl=a(" for more information."),zi=f(),h(Se.$$.fragment),Li=f(),$t=r("p"),Ol=a("Now, let\u2019s take a spin on it."),Ni=f(),h(je.$$.fragment),xi=f(),kt=r("p"),Et=r("img"),Oi=f(),Pt=r("p"),Cl=a("Cool, this now took roughly 30 seconds on a T4 GPU (you might see faster inference if your allocated GPU is better than a T4)."),Ci=f(),St=r("p"),Ul=a("The default run we did above used full float32 precision and ran the default number of inference steps (50). The easiest speed-ups come from switching to float16 (or half) precision and simply running fewer inference steps. Let\u2019s load the model now in float16 instead."),Ui=f(),h(De.$$.fragment),Hi=f(),jt=r("p"),Hl=a("And we can again call the pipeline to generate an image."),Wi=f(),h(qe.$$.fragment),Fi=f(),Dt=r("p"),qt=r("img"),Ri=f(),At=r("p"),Wl=a("Cool, this is almost three times as fast for arguably the same image quality."),Bi=f(),Mt=r("p"),Fl=a("We strongly suggest always running your pipelines in float16 as so far we have very rarely seen degradations in quality because of it."),Vi=f(),It=r("p"),Rl=a("Next, let\u2019s see if we need to use 50 inference steps or whether we could use significantly fewer. The number of inference steps is associated with the denoising scheduler we use. Choosing a more efficient scheduler could help us decrease the number of steps."),Qi=f(),Tt=r("p"),Bl=a("Let\u2019s have a look at all the schedulers the stable diffusion pipeline is compatible with."),Ki=f(),h(Ae.$$.fragment),Xi=f(),h(Me.$$.fragment),Yi=f(),Gt=r("p"),Vl=a("Cool, that\u2019s a lot of schedulers."),Ji=f(),Q=r("p"),Ql=a("\u{1F9E8} Diffusers is constantly adding a bunch of novel schedulers/samplers that can be used with Stable Diffusion. For more information, we recommend taking a look at the official documentation "),Ie=r("a"),Kl=a("here"),Xl=a("."),Zi=f(),k=r("p"),Yl=a("Alright, right now Stable Diffusion is using the "),Ws=r("code"),Jl=a("PNDMScheduler"),Zl=a(" which usually requires around 50 inference steps. However, other schedulers such as "),Fs=r("code"),ea=a("DPMSolverMultistepScheduler"),ta=a(" or "),Rs=r("code"),sa=a("DPMSolverSinglestepScheduler"),ia=a(" seem to get away with just 20 to 25 inference steps. Let\u2019s try them out."),eo=f(),K=r("p"),oa=a("You can set a new scheduler by making use of the "),Te=r("a"),ra=a("from_config"),la=a(" function."),to=f(),h(Ge.$$.fragment),so=f(),zt=r("p"),aa=a("Now, let\u2019s try to reduce the number of inference steps to just 20."),io=f(),h(ze.$$.fragment),oo=f(),Lt=r("p"),Nt=r("img"),ro=f(),xt=r("p"),na=a("The image now does look a little different, but it\u2019s arguably still of equally high quality. We now cut inference time to just 4 seconds though \u{1F60D}."),lo=f(),L=r("h2"),X=r("a"),Bs=r("span"),h(Le.$$.fragment),pa=f(),Vs=r("span"),fa=a("Memory Optimization"),ao=f(),Ot=r("p"),ua=a("Less memory used in generation indirectly implies more speed, since we\u2019re often trying to maximize how many images we can generate per second. Usually, the more images per inference run, the more images per second too."),no=f(),Y=r("p"),ma=a("The easiest way to see how many images we can generate at once is to simply try it out, and see when we get a "),Qs=r("em"),ha=a("\u201COut-of-memory (OOM)\u201D"),ca=a(" error."),po=f(),Ct=r("p"),da=a("We can run batched inference by simply passing a list of prompts and generators. Let\u2019s define a quick function that generates a batch for us."),fo=f(),h(Ne.$$.fragment),uo=f(),Ut=r("p"),ga=a("This function returns a list of prompts and a list of generators, so we can reuse the generator that produced a result we like."),mo=f(),Ht=r("p"),ba=a("We also need a method that allows us to easily display a batch of images."),ho=f(),h(xe.$$.fragment),co=f(),J=r("p"),ya=a("Cool, let\u2019s see how much memory we can use starting with "),Ks=r("code"),wa=a("batch_size=4"),va=a("."),go=f(),h(Oe.$$.fragment),bo=f(),Wt=r("p"),Ft=r("img"),yo=f(),Rt=r("p"),_a=a("Going over a batch_size of 4 will error out in this notebook (assuming we are running it on a T4 GPU). Also, we can see we only generate slightly more images per second (3.75s/image) compared to 4s/image previously."),wo=f(),Z=r("p"),$a=a("However, the community has found some nice tricks to improve the memory constraints further. After stable diffusion was released, the community found improvements within days and shared them freely over GitHub - open-source at its finest! I believe the original idea came from "),Ce=r("a"),ka=a("this"),Ea=a(" GitHub thread."),vo=f(),Bt=r("p"),Pa=a("By far most of the memory is taken up by the cross-attention layers. Instead of running this operation in batch, one can run it sequentially to save a significant amount of memory."),_o=f(),D=r("p"),Sa=a("It can easily be enabled by calling "),Xs=r("code"),ja=a("enable_attention_slicing"),Da=a(" as is documented "),Ue=r("a"),qa=a("here"),Aa=a("."),$o=f(),h(He.$$.fragment),ko=f(),ee=r("p"),Ma=a("Great, now that attention slicing is enabled, let\u2019s try to double the batch size again, going for "),Ys=r("code"),Ia=a("batch_size=8"),Ta=a("."),Eo=f(),h(We.$$.fragment),Po=f(),Vt=r("p"),Qt=r("img"),So=f(),Kt=r("p"),Ga=a("Nice, it works. However, the speed gain is again not very big (it might however be much more significant on other GPUs)."),jo=f(),Xt=r("p"),za=a("We\u2019re at roughly 3.5 seconds per image \u{1F525} which is probably the fastest we can be with a simple T4 without sacrificing quality."),Do=f(),Yt=r("p"),La=a("Next, let\u2019s look into how to improve the quality!"),qo=f(),N=r("h2"),te=r("a"),Js=r("span"),h(Fe.$$.fragment),Na=f(),Zs=r("span"),xa=a("Quality Improvements"),Ao=f(),Jt=r("p"),Oa=a("Now that our image generation pipeline is blazing fast, let\u2019s try to get maximum image quality."),Mo=f(),Zt=r("p"),Ca=a("First of all, image quality is extremely subjective, so it\u2019s difficult to make general claims here."),Io=f(),se=r("p"),Ua=a("The most obvious step to take to improve quality is to use "),ei=r("em"),Ha=a("better checkpoints"),Wa=a(". Since the release of Stable Diffusion, many improved versions have been released, which are summarized here:"),To=f(),E=r("ul"),Re=r("li"),ti=r("em"),Fa=a("Official Release - 22 Aug 2022"),Ra=a(": "),Be=r("a"),Ba=a("Stable-Diffusion 1.4"),Va=f(),Ve=r("li"),si=r("em"),Qa=a("20 October 2022"),Ka=a(": "),Qe=r("a"),Xa=a("Stable-Diffusion 1.5"),Ya=f(),Ke=r("li"),ii=r("em"),Ja=a("24 Nov 2022"),Za=a(": "),Xe=r("a"),en=a("Stable-Diffusion 2.0"),tn=f(),Ye=r("li"),oi=r("em"),sn=a("7 Dec 2022"),on=a(": "),Je=r("a"),rn=a("Stable-Diffusion 2.1"),Go=f(),_=r("p"),ln=a("Newer versions don\u2019t necessarily mean better image quality with the same parameters. People mentioned that "),ri=r("em"),an=a("2.0"),nn=a(" is slightly worse than "),li=r("em"),pn=a("1.5"),fn=a(" for certain prompts, but given the right prompt engineering "),ai=r("em"),un=a("2.0"),mn=a(" and "),ni=r("em"),hn=a("2.1"),cn=a(" seem to be better."),zo=f(),ie=r("p"),dn=a("Overall, we strongly recommend just trying the models out and reading up on advice online (e.g. it has been shown that using negative prompts is very important for 2.0 and 2.1 to get the highest possible quality. See for example "),Ze=r("a"),gn=a("this nice blog post"),bn=a("."),Lo=f(),es=r("p"),yn=a("Additionally, the community has started fine-tuning many of the above versions on certain styles with some of them having an extremely high quality and gaining a lot of traction."),No=f(),oe=r("p"),wn=a("We recommend having a look at all "),et=r("a"),vn=a("diffusers checkpoints sorted by downloads and trying out the different checkpoints"),_n=a("."),xo=f(),ts=r("p"),$n=a("For the following, we will stick to v1.5 for simplicity."),Oo=f(),re=r("p"),kn=a("Next, we can also try to optimize single components of the pipeline, e.g. switching out the latent decoder. For more details on how the whole Stable Diffusion pipeline works, please have a look at "),tt=r("a"),En=a("this blog post"),Pn=a("."),Co=f(),le=r("p"),Sn=a("Let\u2019s load "),st=r("a"),jn=a("stabilityai\u2019s newest auto-decoder"),Dn=a("."),Uo=f(),h(it.$$.fragment),Ho=f(),ss=r("p"),qn=a("Now we can set it to the vae of the pipeline to use it."),Wo=f(),h(ot.$$.fragment),Fo=f(),is=r("p"),An=a("Let\u2019s run the same prompt as before to compare quality."),Ro=f(),h(rt.$$.fragment),Bo=f(),os=r("p"),rs=r("img"),Vo=f(),ae=r("p"),Mn=a("Seems like the difference is only very minor, but the new generations are arguably a bit "),pi=r("em"),In=a("sharper"),Tn=a("."),Qo=f(),ls=r("p"),Gn=a("Cool, finally, let\u2019s look a bit into prompt engineering."),Ko=f(),as=r("p"),zn=a("Our goal was to generate a photo of an old warrior chief. Let\u2019s now try to bring a bit more color into the photos and make the look more impressive."),Xo=f(),ne=r("p"),Ln=a("Originally our prompt was \u201D"),fi=r("em"),Nn=a("portrait photo of an old warrior chief"),xn=a("\u201C."),Yo=f(),pe=r("p"),On=a("To improve the prompt, it often helps to add cues that could have been used online to save high-quality photos, as well as add more details."),Cn=r("br"),Un=a(`
Essentially, when doing prompt engineering, one has to think:`),Jo=f(),fe=r("ul"),ui=r("li"),Hn=a("How was the photo or similar photos of the one I want probably stored on the internet?"),Wn=f(),mi=r("li"),Fn=a("What additional detail can I give that steers the models into the style that I want?"),Zo=f(),ns=r("p"),Rn=a("Cool, let\u2019s add more details."),er=f(),h(lt.$$.fragment),tr=f(),ps=r("p"),Bn=a("and let\u2019s also add some cues that usually help to generate higher quality images."),sr=f(),h(at.$$.fragment),ir=f(),fs=r("p"),Vn=a("Cool, let\u2019s now try this prompt."),or=f(),h(nt.$$.fragment),rr=f(),us=r("p"),ms=r("img"),lr=f(),hs=r("p"),Qn=a('Pretty impressive! We got some very high-quality image generations there. The 2nd image is my personal favorite, so I\u2019ll re-use this seed and see whether I can tweak the prompts slightly by using \u201Coldest warrior\u201D, \u201Cold\u201D, "", and \u201Cyoung\u201D instead of \u201Cold\u201D.'),ar=f(),h(pt.$$.fragment),nr=f(),cs=r("p"),ds=r("img"),pr=f(),gs=r("p"),Kn=a("The first picture looks nice! The eye movement slightly changed and looks nice. This finished up our 101-guide on how to use Stable Diffusion \u{1F917}."),fr=f(),bs=r("p"),Xn=a("For more information on optimization or other guides, I recommend taking a look at the following:"),ur=f(),P=r("ul"),ys=r("li"),ft=r("a"),Yn=a("Blog post about Stable Diffusion"),Jn=a(": In-detail blog post explaining Stable Diffusion."),Zn=f(),ws=r("li"),ut=r("a"),ep=a("FlashAttention"),tp=a(": XFormers flash attention can optimize your model even further with more speed and memory improvements."),sp=f(),vs=r("li"),mt=r("a"),ip=a("Dreambooth"),op=a(" - Quickly customize the model by fine-tuning it."),rp=f(),_s=r("li"),ht=r("a"),lp=a("General info on Stable Diffusion"),ap=a(" - Info on other tasks that are powered by Stable Diffusion."),this.h()},l(e){const i=Gu('[data-svelte="svelte-1phssyn"]',document.head);M=l(i,"META",{name:!0,content:!0}),i.forEach(t),hi=u(e),I=l(e,"H1",{class:!0});var hr=p(I);O=l(hr,"A",{id:!0,class:!0,href:!0});var $p=p(O);Ss=l($p,"SPAN",{});var kp=p(Ss);c(de.$$.fragment,kp),kp.forEach(t),$p.forEach(t),Hr=u(hr),js=l(hr,"SPAN",{});var Ep=p(js);Wr=n(Ep,"The Stable Diffusion Guide \u{1F3A8}"),Ep.forEach(t),hr.forEach(t),ci=u(e),C=l(e,"A",{target:!0,href:!0});var Pp=p(C);ct=l(Pp,"IMG",{src:!0,alt:!0}),Pp.forEach(t),di=u(e),T=l(e,"H2",{class:!0});var cr=p(T);U=l(cr,"A",{id:!0,class:!0,href:!0});var Sp=p(U);Ds=l(Sp,"SPAN",{});var jp=p(Ds);c(ge.$$.fragment,jp),jp.forEach(t),Sp.forEach(t),Fr=u(cr),qs=l(cr,"SPAN",{});var Dp=p(qs);Rr=n(Dp,"Intro"),Dp.forEach(t),cr.forEach(t),gi=u(e),v=l(e,"P",{});var q=p(v);Br=n(q,"Stable Diffusion is a "),be=l(q,"A",{href:!0,rel:!0});var qp=p(be);Vr=n(qp,"Latent Diffusion model"),qp.forEach(t),Qr=n(q," developed by researchers from the Machine Vision and Learning group at LMU Munich, "),As=l(q,"EM",{});var Ap=p(As);Kr=n(Ap,"a.k.a"),Ap.forEach(t),Xr=n(q," CompVis."),Yr=l(q,"BR",{}),Jr=n(q,`
Model checkpoints were publicly released at the end of August 2022 by a collaboration of Stability AI, CompVis, and Runway with support from EleutherAI and LAION. For more information, you can check out `),ye=l(q,"A",{href:!0,rel:!0});var Mp=p(ye);Zr=n(Mp,"the official blog post"),Mp.forEach(t),el=n(q,"."),q.forEach(t),bi=u(e),$=l(e,"P",{});var ue=p($);tl=n(ue,"Since its public release the community has done an incredible job at working together to make the stable diffusion checkpoints "),Ms=l(ue,"STRONG",{});var Ip=p(Ms);sl=n(Ip,"faster"),Ip.forEach(t),il=n(ue,", "),Is=l(ue,"STRONG",{});var Tp=p(Is);ol=n(Tp,"more memory efficient"),Tp.forEach(t),rl=n(ue,", and "),Ts=l(ue,"STRONG",{});var Gp=p(Ts);ll=n(Gp,"more performant"),Gp.forEach(t),al=n(ue,"."),ue.forEach(t),yi=u(e),dt=l(e,"P",{});var zp=p(dt);nl=n(zp,"\u{1F9E8} Diffusers offers a simple API to run stable diffusion with all memory, computing, and quality improvements."),zp.forEach(t),wi=u(e),S=l(e,"P",{});var $s=p(S);pl=n($s,"This notebook walks you through the improvements one-by-one so you can best leverage "),gt=l($s,"A",{href:!0});var Lp=p(gt);fl=n(Lp,"StableDiffusionPipeline"),Lp.forEach(t),ul=n($s," for "),Gs=l($s,"STRONG",{});var Np=p(Gs);ml=n(Np,"inference"),Np.forEach(t),hl=n($s,"."),$s.forEach(t),vi=u(e),G=l(e,"H2",{class:!0});var dr=p(G);H=l(dr,"A",{id:!0,class:!0,href:!0});var xp=p(H);zs=l(xp,"SPAN",{});var Op=p(zs);c(we.$$.fragment,Op),Op.forEach(t),xp.forEach(t),cl=u(dr),Ls=l(dr,"SPAN",{});var Cp=p(Ls);dl=n(Cp,"Prompt Engineering \u{1F3A8}"),Cp.forEach(t),dr.forEach(t),_i=n(e,`

                                                                                                                                                                                                                                              
When running *Stable Diffusion* in inference, we usually want to generate a certain type, or style of image and then improve upon it. Improving upon a previously generated image means running inference over and over again with a different prompt and potentially a different seed until we are happy with our generation.
`),bt=l(e,"P",{});var Up=p(bt);gl=n(Up,"So to begin with, it is most important to speed up stable diffusion as much as possible to generate as many pictures as possible in a given amount of time."),Up.forEach(t),$i=u(e),j=l(e,"P",{});var ks=p(j);bl=n(ks,"This can be done by both improving the "),Ns=l(ks,"STRONG",{});var Hp=p(Ns);yl=n(Hp,"computational efficiency"),Hp.forEach(t),wl=n(ks," (speed) and the "),xs=l(ks,"STRONG",{});var Wp=p(xs);vl=n(Wp,"memory efficiency"),Wp.forEach(t),_l=n(ks," (GPU RAM)."),ks.forEach(t),ki=u(e),yt=l(e,"P",{});var Fp=p(yt);$l=n(Fp,"Let\u2019s start by looking into computational efficiency first."),Fp.forEach(t),Ei=u(e),W=l(e,"P",{});var gr=p(W);kl=n(gr,"Throughout the notebook, we will focus on "),ve=l(gr,"A",{href:!0,rel:!0});var Rp=p(ve);El=n(Rp,"runwayml/stable-diffusion-v1-5"),Rp.forEach(t),Pl=n(gr,":"),gr.forEach(t),Pi=u(e),c(_e.$$.fragment,e),Si=u(e),wt=l(e,"P",{});var Bp=p(wt);Sl=n(Bp,"Let\u2019s load the pipeline."),Bp.forEach(t),ji=u(e),z=l(e,"H2",{class:!0});var br=p(z);F=l(br,"A",{id:!0,class:!0,href:!0});var Vp=p(F);Os=l(Vp,"SPAN",{});var Qp=p(Os);c($e.$$.fragment,Qp),Qp.forEach(t),Vp.forEach(t),jl=u(br),Cs=l(br,"SPAN",{});var Kp=p(Cs);Dl=n(Kp,"Speed Optimization"),Kp.forEach(t),br.forEach(t),Di=u(e),c(ke.$$.fragment,e),qi=u(e),R=l(e,"P",{});var yr=p(R);ql=n(yr,"We aim at generating a beautiful photograph of an "),Us=l(yr,"EM",{});var Xp=p(Us);Al=n(Xp,"old warrior chief"),Xp.forEach(t),Ml=n(yr," and will later try to find the best prompt to generate such a photograph. For now, let\u2019s keep the prompt simple:"),yr.forEach(t),Ai=u(e),c(Ee.$$.fragment,e),Mi=u(e),vt=l(e,"P",{});var Yp=p(vt);Il=n(Yp,"To begin with, we should make sure we run inference on GPU, so let\u2019s move the pipeline to GPU, just like you would with any PyTorch module."),Yp.forEach(t),Ii=u(e),c(Pe.$$.fragment,e),Ti=u(e),B=l(e,"P",{});var wr=p(B);Tl=n(wr,"To generate an image, you should use the [~"),Hs=l(wr,"CODE",{});var Jp=p(Hs);Gl=n(Jp,"StableDiffusionPipeline.__call__"),Jp.forEach(t),zl=n(wr,"] method."),wr.forEach(t),Gi=u(e),V=l(e,"P",{});var vr=p(V);Ll=n(vr,"To make sure we can reproduce more or less the same image in every call, let\u2019s make use of the generator. See the documentation on reproducibility "),_t=l(vr,"A",{href:!0});var Zp=p(_t);Nl=n(Zp,"here"),Zp.forEach(t),xl=n(vr," for more information."),vr.forEach(t),zi=u(e),c(Se.$$.fragment,e),Li=u(e),$t=l(e,"P",{});var ef=p($t);Ol=n(ef,"Now, let\u2019s take a spin on it."),ef.forEach(t),Ni=u(e),c(je.$$.fragment,e),xi=u(e),kt=l(e,"P",{});var tf=p(kt);Et=l(tf,"IMG",{src:!0,alt:!0}),tf.forEach(t),Oi=u(e),Pt=l(e,"P",{});var sf=p(Pt);Cl=n(sf,"Cool, this now took roughly 30 seconds on a T4 GPU (you might see faster inference if your allocated GPU is better than a T4)."),sf.forEach(t),Ci=u(e),St=l(e,"P",{});var of=p(St);Ul=n(of,"The default run we did above used full float32 precision and ran the default number of inference steps (50). The easiest speed-ups come from switching to float16 (or half) precision and simply running fewer inference steps. Let\u2019s load the model now in float16 instead."),of.forEach(t),Ui=u(e),c(De.$$.fragment,e),Hi=u(e),jt=l(e,"P",{});var rf=p(jt);Hl=n(rf,"And we can again call the pipeline to generate an image."),rf.forEach(t),Wi=u(e),c(qe.$$.fragment,e),Fi=u(e),Dt=l(e,"P",{});var lf=p(Dt);qt=l(lf,"IMG",{src:!0,alt:!0}),lf.forEach(t),Ri=u(e),At=l(e,"P",{});var af=p(At);Wl=n(af,"Cool, this is almost three times as fast for arguably the same image quality."),af.forEach(t),Bi=u(e),Mt=l(e,"P",{});var nf=p(Mt);Fl=n(nf,"We strongly suggest always running your pipelines in float16 as so far we have very rarely seen degradations in quality because of it."),nf.forEach(t),Vi=u(e),It=l(e,"P",{});var pf=p(It);Rl=n(pf,"Next, let\u2019s see if we need to use 50 inference steps or whether we could use significantly fewer. The number of inference steps is associated with the denoising scheduler we use. Choosing a more efficient scheduler could help us decrease the number of steps."),pf.forEach(t),Qi=u(e),Tt=l(e,"P",{});var ff=p(Tt);Bl=n(ff,"Let\u2019s have a look at all the schedulers the stable diffusion pipeline is compatible with."),ff.forEach(t),Ki=u(e),c(Ae.$$.fragment,e),Xi=u(e),c(Me.$$.fragment,e),Yi=u(e),Gt=l(e,"P",{});var uf=p(Gt);Vl=n(uf,"Cool, that\u2019s a lot of schedulers."),uf.forEach(t),Ji=u(e),Q=l(e,"P",{});var _r=p(Q);Ql=n(_r,"\u{1F9E8} Diffusers is constantly adding a bunch of novel schedulers/samplers that can be used with Stable Diffusion. For more information, we recommend taking a look at the official documentation "),Ie=l(_r,"A",{href:!0,rel:!0});var mf=p(Ie);Kl=n(mf,"here"),mf.forEach(t),Xl=n(_r,"."),_r.forEach(t),Zi=u(e),k=l(e,"P",{});var me=p(k);Yl=n(me,"Alright, right now Stable Diffusion is using the "),Ws=l(me,"CODE",{});var hf=p(Ws);Jl=n(hf,"PNDMScheduler"),hf.forEach(t),Zl=n(me," which usually requires around 50 inference steps. However, other schedulers such as "),Fs=l(me,"CODE",{});var cf=p(Fs);ea=n(cf,"DPMSolverMultistepScheduler"),cf.forEach(t),ta=n(me," or "),Rs=l(me,"CODE",{});var df=p(Rs);sa=n(df,"DPMSolverSinglestepScheduler"),df.forEach(t),ia=n(me," seem to get away with just 20 to 25 inference steps. Let\u2019s try them out."),me.forEach(t),eo=u(e),K=l(e,"P",{});var $r=p(K);oa=n($r,"You can set a new scheduler by making use of the "),Te=l($r,"A",{href:!0,rel:!0});var gf=p(Te);ra=n(gf,"from_config"),gf.forEach(t),la=n($r," function."),$r.forEach(t),to=u(e),c(Ge.$$.fragment,e),so=u(e),zt=l(e,"P",{});var bf=p(zt);aa=n(bf,"Now, let\u2019s try to reduce the number of inference steps to just 20."),bf.forEach(t),io=u(e),c(ze.$$.fragment,e),oo=u(e),Lt=l(e,"P",{});var yf=p(Lt);Nt=l(yf,"IMG",{src:!0,alt:!0}),yf.forEach(t),ro=u(e),xt=l(e,"P",{});var wf=p(xt);na=n(wf,"The image now does look a little different, but it\u2019s arguably still of equally high quality. We now cut inference time to just 4 seconds though \u{1F60D}."),wf.forEach(t),lo=u(e),L=l(e,"H2",{class:!0});var kr=p(L);X=l(kr,"A",{id:!0,class:!0,href:!0});var vf=p(X);Bs=l(vf,"SPAN",{});var _f=p(Bs);c(Le.$$.fragment,_f),_f.forEach(t),vf.forEach(t),pa=u(kr),Vs=l(kr,"SPAN",{});var $f=p(Vs);fa=n($f,"Memory Optimization"),$f.forEach(t),kr.forEach(t),ao=u(e),Ot=l(e,"P",{});var kf=p(Ot);ua=n(kf,"Less memory used in generation indirectly implies more speed, since we\u2019re often trying to maximize how many images we can generate per second. Usually, the more images per inference run, the more images per second too."),kf.forEach(t),no=u(e),Y=l(e,"P",{});var Er=p(Y);ma=n(Er,"The easiest way to see how many images we can generate at once is to simply try it out, and see when we get a "),Qs=l(Er,"EM",{});var Ef=p(Qs);ha=n(Ef,"\u201COut-of-memory (OOM)\u201D"),Ef.forEach(t),ca=n(Er," error."),Er.forEach(t),po=u(e),Ct=l(e,"P",{});var Pf=p(Ct);da=n(Pf,"We can run batched inference by simply passing a list of prompts and generators. Let\u2019s define a quick function that generates a batch for us."),Pf.forEach(t),fo=u(e),c(Ne.$$.fragment,e),uo=u(e),Ut=l(e,"P",{});var Sf=p(Ut);ga=n(Sf,"This function returns a list of prompts and a list of generators, so we can reuse the generator that produced a result we like."),Sf.forEach(t),mo=u(e),Ht=l(e,"P",{});var jf=p(Ht);ba=n(jf,"We also need a method that allows us to easily display a batch of images."),jf.forEach(t),ho=u(e),c(xe.$$.fragment,e),co=u(e),J=l(e,"P",{});var Pr=p(J);ya=n(Pr,"Cool, let\u2019s see how much memory we can use starting with "),Ks=l(Pr,"CODE",{});var Df=p(Ks);wa=n(Df,"batch_size=4"),Df.forEach(t),va=n(Pr,"."),Pr.forEach(t),go=u(e),c(Oe.$$.fragment,e),bo=u(e),Wt=l(e,"P",{});var qf=p(Wt);Ft=l(qf,"IMG",{src:!0,alt:!0}),qf.forEach(t),yo=u(e),Rt=l(e,"P",{});var Af=p(Rt);_a=n(Af,"Going over a batch_size of 4 will error out in this notebook (assuming we are running it on a T4 GPU). Also, we can see we only generate slightly more images per second (3.75s/image) compared to 4s/image previously."),Af.forEach(t),wo=u(e),Z=l(e,"P",{});var Sr=p(Z);$a=n(Sr,"However, the community has found some nice tricks to improve the memory constraints further. After stable diffusion was released, the community found improvements within days and shared them freely over GitHub - open-source at its finest! I believe the original idea came from "),Ce=l(Sr,"A",{href:!0,rel:!0});var Mf=p(Ce);ka=n(Mf,"this"),Mf.forEach(t),Ea=n(Sr," GitHub thread."),Sr.forEach(t),vo=u(e),Bt=l(e,"P",{});var If=p(Bt);Pa=n(If,"By far most of the memory is taken up by the cross-attention layers. Instead of running this operation in batch, one can run it sequentially to save a significant amount of memory."),If.forEach(t),_o=u(e),D=l(e,"P",{});var Es=p(D);Sa=n(Es,"It can easily be enabled by calling "),Xs=l(Es,"CODE",{});var Tf=p(Xs);ja=n(Tf,"enable_attention_slicing"),Tf.forEach(t),Da=n(Es," as is documented "),Ue=l(Es,"A",{href:!0,rel:!0});var Gf=p(Ue);qa=n(Gf,"here"),Gf.forEach(t),Aa=n(Es,"."),Es.forEach(t),$o=u(e),c(He.$$.fragment,e),ko=u(e),ee=l(e,"P",{});var jr=p(ee);Ma=n(jr,"Great, now that attention slicing is enabled, let\u2019s try to double the batch size again, going for "),Ys=l(jr,"CODE",{});var zf=p(Ys);Ia=n(zf,"batch_size=8"),zf.forEach(t),Ta=n(jr,"."),jr.forEach(t),Eo=u(e),c(We.$$.fragment,e),Po=u(e),Vt=l(e,"P",{});var Lf=p(Vt);Qt=l(Lf,"IMG",{src:!0,alt:!0}),Lf.forEach(t),So=u(e),Kt=l(e,"P",{});var Nf=p(Kt);Ga=n(Nf,"Nice, it works. However, the speed gain is again not very big (it might however be much more significant on other GPUs)."),Nf.forEach(t),jo=u(e),Xt=l(e,"P",{});var xf=p(Xt);za=n(xf,"We\u2019re at roughly 3.5 seconds per image \u{1F525} which is probably the fastest we can be with a simple T4 without sacrificing quality."),xf.forEach(t),Do=u(e),Yt=l(e,"P",{});var Of=p(Yt);La=n(Of,"Next, let\u2019s look into how to improve the quality!"),Of.forEach(t),qo=u(e),N=l(e,"H2",{class:!0});var Dr=p(N);te=l(Dr,"A",{id:!0,class:!0,href:!0});var Cf=p(te);Js=l(Cf,"SPAN",{});var Uf=p(Js);c(Fe.$$.fragment,Uf),Uf.forEach(t),Cf.forEach(t),Na=u(Dr),Zs=l(Dr,"SPAN",{});var Hf=p(Zs);xa=n(Hf,"Quality Improvements"),Hf.forEach(t),Dr.forEach(t),Ao=u(e),Jt=l(e,"P",{});var Wf=p(Jt);Oa=n(Wf,"Now that our image generation pipeline is blazing fast, let\u2019s try to get maximum image quality."),Wf.forEach(t),Mo=u(e),Zt=l(e,"P",{});var Ff=p(Zt);Ca=n(Ff,"First of all, image quality is extremely subjective, so it\u2019s difficult to make general claims here."),Ff.forEach(t),Io=u(e),se=l(e,"P",{});var qr=p(se);Ua=n(qr,"The most obvious step to take to improve quality is to use "),ei=l(qr,"EM",{});var Rf=p(ei);Ha=n(Rf,"better checkpoints"),Rf.forEach(t),Wa=n(qr,". Since the release of Stable Diffusion, many improved versions have been released, which are summarized here:"),qr.forEach(t),To=u(e),E=l(e,"UL",{});var he=p(E);Re=l(he,"LI",{});var Ar=p(Re);ti=l(Ar,"EM",{});var Bf=p(ti);Fa=n(Bf,"Official Release - 22 Aug 2022"),Bf.forEach(t),Ra=n(Ar,": "),Be=l(Ar,"A",{href:!0,rel:!0});var Vf=p(Be);Ba=n(Vf,"Stable-Diffusion 1.4"),Vf.forEach(t),Ar.forEach(t),Va=u(he),Ve=l(he,"LI",{});var Mr=p(Ve);si=l(Mr,"EM",{});var Qf=p(si);Qa=n(Qf,"20 October 2022"),Qf.forEach(t),Ka=n(Mr,": "),Qe=l(Mr,"A",{href:!0,rel:!0});var Kf=p(Qe);Xa=n(Kf,"Stable-Diffusion 1.5"),Kf.forEach(t),Mr.forEach(t),Ya=u(he),Ke=l(he,"LI",{});var Ir=p(Ke);ii=l(Ir,"EM",{});var Xf=p(ii);Ja=n(Xf,"24 Nov 2022"),Xf.forEach(t),Za=n(Ir,": "),Xe=l(Ir,"A",{href:!0,rel:!0});var Yf=p(Xe);en=n(Yf,"Stable-Diffusion 2.0"),Yf.forEach(t),Ir.forEach(t),tn=u(he),Ye=l(he,"LI",{});var Tr=p(Ye);oi=l(Tr,"EM",{});var Jf=p(oi);sn=n(Jf,"7 Dec 2022"),Jf.forEach(t),on=n(Tr,": "),Je=l(Tr,"A",{href:!0,rel:!0});var Zf=p(Je);rn=n(Zf,"Stable-Diffusion 2.1"),Zf.forEach(t),Tr.forEach(t),he.forEach(t),Go=u(e),_=l(e,"P",{});var A=p(_);ln=n(A,"Newer versions don\u2019t necessarily mean better image quality with the same parameters. People mentioned that "),ri=l(A,"EM",{});var eu=p(ri);an=n(eu,"2.0"),eu.forEach(t),nn=n(A," is slightly worse than "),li=l(A,"EM",{});var tu=p(li);pn=n(tu,"1.5"),tu.forEach(t),fn=n(A," for certain prompts, but given the right prompt engineering "),ai=l(A,"EM",{});var su=p(ai);un=n(su,"2.0"),su.forEach(t),mn=n(A," and "),ni=l(A,"EM",{});var iu=p(ni);hn=n(iu,"2.1"),iu.forEach(t),cn=n(A," seem to be better."),A.forEach(t),zo=u(e),ie=l(e,"P",{});var Gr=p(ie);dn=n(Gr,"Overall, we strongly recommend just trying the models out and reading up on advice online (e.g. it has been shown that using negative prompts is very important for 2.0 and 2.1 to get the highest possible quality. See for example "),Ze=l(Gr,"A",{href:!0,rel:!0});var ou=p(Ze);gn=n(ou,"this nice blog post"),ou.forEach(t),bn=n(Gr,"."),Gr.forEach(t),Lo=u(e),es=l(e,"P",{});var ru=p(es);yn=n(ru,"Additionally, the community has started fine-tuning many of the above versions on certain styles with some of them having an extremely high quality and gaining a lot of traction."),ru.forEach(t),No=u(e),oe=l(e,"P",{});var zr=p(oe);wn=n(zr,"We recommend having a look at all "),et=l(zr,"A",{href:!0,rel:!0});var lu=p(et);vn=n(lu,"diffusers checkpoints sorted by downloads and trying out the different checkpoints"),lu.forEach(t),_n=n(zr,"."),zr.forEach(t),xo=u(e),ts=l(e,"P",{});var au=p(ts);$n=n(au,"For the following, we will stick to v1.5 for simplicity."),au.forEach(t),Oo=u(e),re=l(e,"P",{});var Lr=p(re);kn=n(Lr,"Next, we can also try to optimize single components of the pipeline, e.g. switching out the latent decoder. For more details on how the whole Stable Diffusion pipeline works, please have a look at "),tt=l(Lr,"A",{href:!0,rel:!0});var nu=p(tt);En=n(nu,"this blog post"),nu.forEach(t),Pn=n(Lr,"."),Lr.forEach(t),Co=u(e),le=l(e,"P",{});var Nr=p(le);Sn=n(Nr,"Let\u2019s load "),st=l(Nr,"A",{href:!0,rel:!0});var pu=p(st);jn=n(pu,"stabilityai\u2019s newest auto-decoder"),pu.forEach(t),Dn=n(Nr,"."),Nr.forEach(t),Uo=u(e),c(it.$$.fragment,e),Ho=u(e),ss=l(e,"P",{});var fu=p(ss);qn=n(fu,"Now we can set it to the vae of the pipeline to use it."),fu.forEach(t),Wo=u(e),c(ot.$$.fragment,e),Fo=u(e),is=l(e,"P",{});var uu=p(is);An=n(uu,"Let\u2019s run the same prompt as before to compare quality."),uu.forEach(t),Ro=u(e),c(rt.$$.fragment,e),Bo=u(e),os=l(e,"P",{});var mu=p(os);rs=l(mu,"IMG",{src:!0,alt:!0}),mu.forEach(t),Vo=u(e),ae=l(e,"P",{});var xr=p(ae);Mn=n(xr,"Seems like the difference is only very minor, but the new generations are arguably a bit "),pi=l(xr,"EM",{});var hu=p(pi);In=n(hu,"sharper"),hu.forEach(t),Tn=n(xr,"."),xr.forEach(t),Qo=u(e),ls=l(e,"P",{});var cu=p(ls);Gn=n(cu,"Cool, finally, let\u2019s look a bit into prompt engineering."),cu.forEach(t),Ko=u(e),as=l(e,"P",{});var du=p(as);zn=n(du,"Our goal was to generate a photo of an old warrior chief. Let\u2019s now try to bring a bit more color into the photos and make the look more impressive."),du.forEach(t),Xo=u(e),ne=l(e,"P",{});var Or=p(ne);Ln=n(Or,"Originally our prompt was \u201D"),fi=l(Or,"EM",{});var gu=p(fi);Nn=n(gu,"portrait photo of an old warrior chief"),gu.forEach(t),xn=n(Or,"\u201C."),Or.forEach(t),Yo=u(e),pe=l(e,"P",{});var Cr=p(pe);On=n(Cr,"To improve the prompt, it often helps to add cues that could have been used online to save high-quality photos, as well as add more details."),Cn=l(Cr,"BR",{}),Un=n(Cr,`
Essentially, when doing prompt engineering, one has to think:`),Cr.forEach(t),Jo=u(e),fe=l(e,"UL",{});var Ur=p(fe);ui=l(Ur,"LI",{});var bu=p(ui);Hn=n(bu,"How was the photo or similar photos of the one I want probably stored on the internet?"),bu.forEach(t),Wn=u(Ur),mi=l(Ur,"LI",{});var yu=p(mi);Fn=n(yu,"What additional detail can I give that steers the models into the style that I want?"),yu.forEach(t),Ur.forEach(t),Zo=u(e),ns=l(e,"P",{});var wu=p(ns);Rn=n(wu,"Cool, let\u2019s add more details."),wu.forEach(t),er=u(e),c(lt.$$.fragment,e),tr=u(e),ps=l(e,"P",{});var vu=p(ps);Bn=n(vu,"and let\u2019s also add some cues that usually help to generate higher quality images."),vu.forEach(t),sr=u(e),c(at.$$.fragment,e),ir=u(e),fs=l(e,"P",{});var _u=p(fs);Vn=n(_u,"Cool, let\u2019s now try this prompt."),_u.forEach(t),or=u(e),c(nt.$$.fragment,e),rr=u(e),us=l(e,"P",{});var $u=p(us);ms=l($u,"IMG",{src:!0,alt:!0}),$u.forEach(t),lr=u(e),hs=l(e,"P",{});var ku=p(hs);Qn=n(ku,'Pretty impressive! We got some very high-quality image generations there. The 2nd image is my personal favorite, so I\u2019ll re-use this seed and see whether I can tweak the prompts slightly by using \u201Coldest warrior\u201D, \u201Cold\u201D, "", and \u201Cyoung\u201D instead of \u201Cold\u201D.'),ku.forEach(t),ar=u(e),c(pt.$$.fragment,e),nr=u(e),cs=l(e,"P",{});var Eu=p(cs);ds=l(Eu,"IMG",{src:!0,alt:!0}),Eu.forEach(t),pr=u(e),gs=l(e,"P",{});var Pu=p(gs);Kn=n(Pu,"The first picture looks nice! The eye movement slightly changed and looks nice. This finished up our 101-guide on how to use Stable Diffusion \u{1F917}."),Pu.forEach(t),fr=u(e),bs=l(e,"P",{});var Su=p(bs);Xn=n(Su,"For more information on optimization or other guides, I recommend taking a look at the following:"),Su.forEach(t),ur=u(e),P=l(e,"UL",{});var ce=p(P);ys=l(ce,"LI",{});var np=p(ys);ft=l(np,"A",{href:!0,rel:!0});var ju=p(ft);Yn=n(ju,"Blog post about Stable Diffusion"),ju.forEach(t),Jn=n(np,": In-detail blog post explaining Stable Diffusion."),np.forEach(t),Zn=u(ce),ws=l(ce,"LI",{});var pp=p(ws);ut=l(pp,"A",{href:!0,rel:!0});var Du=p(ut);ep=n(Du,"FlashAttention"),Du.forEach(t),tp=n(pp,": XFormers flash attention can optimize your model even further with more speed and memory improvements."),pp.forEach(t),sp=u(ce),vs=l(ce,"LI",{});var fp=p(vs);mt=l(fp,"A",{href:!0,rel:!0});var qu=p(mt);ip=n(qu,"Dreambooth"),qu.forEach(t),op=n(fp," - Quickly customize the model by fine-tuning it."),fp.forEach(t),rp=u(ce),_s=l(ce,"LI",{});var up=p(_s);ht=l(up,"A",{href:!0,rel:!0});var Au=p(ht);lp=n(Au,"General info on Stable Diffusion"),Au.forEach(t),ap=n(up," - Info on other tasks that are powered by Stable Diffusion."),up.forEach(t),ce.forEach(t),this.h()},h(){m(M,"name","hf:doc:metadata"),m(M,"content",JSON.stringify(xu)),m(O,"id","the-stable-diffusion-guide"),m(O,"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"),m(O,"href","#the-stable-diffusion-guide"),m(I,"class","relative group"),x(ct.src,hp="https://colab.research.google.com/assets/colab-badge.svg")||m(ct,"src",hp),m(ct,"alt","Open In Colab"),m(C,"target","_blank"),m(C,"href","https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers/sd_101_guide.ipynb"),m(U,"id","intro"),m(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"),m(U,"href","#intro"),m(T,"class","relative group"),m(be,"href","https://github.com/CompVis/latent-diffusion"),m(be,"rel","nofollow"),m(ye,"href","https://stability.ai/blog/stable-diffusion-public-release"),m(ye,"rel","nofollow"),m(gt,"href","/docs/diffusers/main/en/api/pipelines/stable_diffusion/text2img#diffusers.StableDiffusionPipeline"),m(H,"id","prompt-engineering"),m(H,"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"),m(H,"href","#prompt-engineering"),m(G,"class","relative group"),m(ve,"href","https://huggingface.co/runwayml/stable-diffusion-v1-5"),m(ve,"rel","nofollow"),m(F,"id","speed-optimization"),m(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"),m(F,"href","#speed-optimization"),m(z,"class","relative group"),m(_t,"href","./conceptual/reproducibility"),x(Et.src,cp="https://huggingface.co/datasets/diffusers/docs-images/resolve/main/stable_diffusion_101/sd_101_1.png")||m(Et,"src",cp),m(Et,"alt","img"),x(qt.src,dp="https://huggingface.co/datasets/diffusers/docs-images/resolve/main/stable_diffusion_101/sd_101_2.png")||m(qt,"src",dp),m(qt,"alt","img"),m(Ie,"href","https://huggingface.co/docs/diffusers/main/en/api/schedulers/overview"),m(Ie,"rel","nofollow"),m(Te,"href","https://huggingface.co/docs/diffusers/main/en/api/configuration#diffusers.ConfigMixin.from_config"),m(Te,"rel","nofollow"),x(Nt.src,gp="https://huggingface.co/datasets/diffusers/docs-images/resolve/main/stable_diffusion_101/sd_101_3.png")||m(Nt,"src",gp),m(Nt,"alt","img"),m(X,"id","memory-optimization"),m(X,"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"),m(X,"href","#memory-optimization"),m(L,"class","relative group"),x(Ft.src,bp="https://huggingface.co/datasets/diffusers/docs-images/resolve/main/stable_diffusion_101/sd_101_4.png")||m(Ft,"src",bp),m(Ft,"alt","img"),m(Ce,"href","https://github.com/basujindal/stable-diffusion/pull/117"),m(Ce,"rel","nofollow"),m(Ue,"href","https://huggingface.co/docs/diffusers/main/en/api/pipelines/stable_diffusion/text2img#diffusers.StableDiffusionPipeline.enable_attention_slicing"),m(Ue,"rel","nofollow"),x(Qt.src,yp="https://huggingface.co/datasets/diffusers/docs-images/resolve/main/stable_diffusion_101/sd_101_5.png")||m(Qt,"src",yp),m(Qt,"alt","img"),m(te,"id","quality-improvements"),m(te,"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"),m(te,"href","#quality-improvements"),m(N,"class","relative group"),m(Be,"href","https://huggingface.co/CompVis/stable-diffusion-v1-4"),m(Be,"rel","nofollow"),m(Qe,"href","https://huggingface.co/runwayml/stable-diffusion-v1-5"),m(Qe,"rel","nofollow"),m(Xe,"href","https://huggingface.co/stabilityai/stable-diffusion-2-0"),m(Xe,"rel","nofollow"),m(Je,"href","https://huggingface.co/stabilityai/stable-diffusion-2-1"),m(Je,"rel","nofollow"),m(Ze,"href","https://minimaxir.com/2022/11/stable-diffusion-negative-prompt/"),m(Ze,"rel","nofollow"),m(et,"href","https://huggingface.co/models?library=diffusers"),m(et,"rel","nofollow"),m(tt,"href","https://huggingface.co/blog/stable_diffusion"),m(tt,"rel","nofollow"),m(st,"href","https://huggingface.co/stabilityai/stable-diffusion-2-1"),m(st,"rel","nofollow"),x(rs.src,wp="https://huggingface.co/datasets/diffusers/docs-images/resolve/main/stable_diffusion_101/sd_101_6.png")||m(rs,"src",wp),m(rs,"alt","img"),x(ms.src,vp="https://huggingface.co/datasets/diffusers/docs-images/resolve/main/stable_diffusion_101/sd_101_7.png")||m(ms,"src",vp),m(ms,"alt","img"),x(ds.src,_p="https://huggingface.co/datasets/diffusers/docs-images/resolve/main/stable_diffusion_101/sd_101_8.png")||m(ds,"src",_p),m(ds,"alt","img"),m(ft,"href","https://huggingface.co/blog/stable_diffusion"),m(ft,"rel","nofollow"),m(ut,"href","https://huggingface.co/docs/diffusers/optimization/xformers"),m(ut,"rel","nofollow"),m(mt,"href","https://huggingface.co/docs/diffusers/training/dreambooth"),m(mt,"rel","nofollow"),m(ht,"href","https://huggingface.co/docs/diffusers/main/en/api/pipelines/stable_diffusion/overview"),m(ht,"rel","nofollow")},m(e,i){s(document.head,M),o(e,hi,i),o(e,I,i),s(I,O),s(O,Ss),d(de,Ss,null),s(I,Hr),s(I,js),s(js,Wr),o(e,ci,i),o(e,C,i),s(C,ct),o(e,di,i),o(e,T,i),s(T,U),s(U,Ds),d(ge,Ds,null),s(T,Fr),s(T,qs),s(qs,Rr),o(e,gi,i),o(e,v,i),s(v,Br),s(v,be),s(be,Vr),s(v,Qr),s(v,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,i),o(e,Ho,i),o(e,ss,i),s(ss,qn),o(e,Wo,i),d(ot,e,i),o(e,Fo,i),o(e,is,i),s(is,An),o(e,Ro,i),d(rt,e,i),o(e,Bo,i),o(e,os,i),s(os,rs),o(e,Vo,i),o(e,ae,i),s(ae,Mn),s(ae,pi),s(pi,In),s(ae,Tn),o(e,Qo,i),o(e,ls,i),s(ls,Gn),o(e,Ko,i),o(e,as,i),s(as,zn),o(e,Xo,i),o(e,ne,i),s(ne,Ln),s(ne,fi),s(fi,Nn),s(ne,xn),o(e,Yo,i),o(e,pe,i),s(pe,On),s(pe,Cn),s(pe,Un),o(e,Jo,i),o(e,fe,i),s(fe,ui),s(ui,Hn),s(fe,Wn),s(fe,mi),s(mi,Fn),o(e,Zo,i),o(e,ns,i),s(ns,Rn),o(e,er,i),d(lt,e,i),o(e,tr,i),o(e,ps,i),s(ps,Bn),o(e,sr,i),d(at,e,i),o(e,ir,i),o(e,fs,i),s(fs,Vn),o(e,or,i),d(nt,e,i),o(e,rr,i),o(e,us,i),s(us,ms),o(e,lr,i),o(e,hs,i),s(hs,Qn),o(e,ar,i),d(pt,e,i),o(e,nr,i),o(e,cs,i),s(cs,ds),o(e,pr,i),o(e,gs,i),s(gs,Kn),o(e,fr,i),o(e,bs,i),s(bs,Xn),o(e,ur,i),o(e,P,i),s(P,ys),s(ys,ft),s(ft,Yn),s(ys,Jn),s(P,Zn),s(P,ws),s(ws,ut),s(ut,ep),s(ws,tp),s(P,sp),s(P,vs),s(vs,mt),s(mt,ip),s(vs,op),s(P,rp),s(P,_s),s(_s,ht),s(ht,lp),s(_s,ap),mr=!0},p:zu,i(e){mr||(g(de.$$.fragment,e),g(ge.$$.fragment,e),g(we.$$.fragment,e),g(_e.$$.fragment,e),g($e.$$.fragment,e),g(ke.$$.fragment,e),g(Ee.$$.fragment,e),g(Pe.$$.fragment,e),g(Se.$$.fragment,e),g(je.$$.fragment,e),g(De.$$.fragment,e),g(qe.$$.fragment,e),g(Ae.$$.fragment,e),g(Me.$$.fragment,e),g(Ge.$$.fragment,e),g(ze.$$.fragment,e),g(Le.$$.fragment,e),g(Ne.$$.fragment,e),g(xe.$$.fragment,e),g(Oe.$$.fragment,e),g(He.$$.fragment,e),g(We.$$.fragment,e),g(Fe.$$.fragment,e),g(it.$$.fragment,e),g(ot.$$.fragment,e),g(rt.$$.fragment,e),g(lt.$$.fragment,e),g(at.$$.fragment,e),g(nt.$$.fragment,e),g(pt.$$.fragment,e),mr=!0)},o(e){b(de.$$.fragment,e),b(ge.$$.fragment,e),b(we.$$.fragment,e),b(_e.$$.fragment,e),b($e.$$.fragment,e),b(ke.$$.fragment,e),b(Ee.$$.fragment,e),b(Pe.$$.fragment,e),b(Se.$$.fragment,e),b(je.$$.fragment,e),b(De.$$.fragment,e),b(qe.$$.fragment,e),b(Ae.$$.fragment,e),b(Me.$$.fragment,e),b(Ge.$$.fragment,e),b(ze.$$.fragment,e),b(Le.$$.fragment,e),b(Ne.$$.fragment,e),b(xe.$$.fragment,e),b(Oe.$$.fragment,e),b(He.$$.fragment,e),b(We.$$.fragment,e),b(Fe.$$.fragment,e),b(it.$$.fragment,e),b(ot.$$.fragment,e),b(rt.$$.fragment,e),b(lt.$$.fragment,e),b(at.$$.fragment,e),b(nt.$$.fragment,e),b(pt.$$.fragment,e),mr=!1},d(e){t(M),e&&t(hi),e&&t(I),y(de),e&&t(ci),e&&t(C),e&&t(di),e&&t(T),y(ge),e&&t(gi),e&&t(v),e&&t(bi),e&&t($),e&&t(yi),e&&t(dt),e&&t(wi),e&&t(S),e&&t(vi),e&&t(G),y(we),e&&t(_i),e&&t(bt),e&&t($i),e&&t(j),e&&t(ki),e&&t(yt),e&&t(Ei),e&&t(W),e&&t(Pi),y(_e,e),e&&t(Si),e&&t(wt),e&&t(ji),e&&t(z),y($e),e&&t(Di),y(ke,e),e&&t(qi),e&&t(R),e&&t(Ai),y(Ee,e),e&&t(Mi),e&&t(vt),e&&t(Ii),y(Pe,e),e&&t(Ti),e&&t(B),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Fo),e&&t(is),e&&t(Ro),y(rt,e),e&&t(Bo),e&&t(os),e&&t(Vo),e&&t(ae),e&&t(Qo),e&&t(ls),e&&t(Ko),e&&t(as),e&&t(Xo),e&&t(ne),e&&t(Yo),e&&t(pe),e&&t(Jo),e&&t(fe),e&&t(Zo),e&&t(ns),e&&t(er),y(lt,e),e&&t(tr),e&&t(ps),e&&t(sr),y(at,e),e&&t(ir),e&&t(fs),e&&t(or),y(nt,e),e&&t(rr),e&&t(us),e&&t(lr),e&&t(hs),e&&t(ar),y(pt,e),e&&t(nr),e&&t(cs),e&&t(pr),e&&t(gs),e&&t(fr),e&&t(bs),e&&t(ur),e&&t(P)}}}const xu={local:"the-stable-diffusion-guide",sections:[{local:"intro",title:"Intro                                                                                                                                                                                                                                                                                                                                                                                                                                                                                "},{local:"prompt-engineering",title:"Prompt Engineering \u{1F3A8}                                                                                                                                                                                                                      "},{local:"speed-optimization",title:"Speed Optimization                                                                                                                                                                                                                                                                                                                                                                                                                                                                       "},{local:"memory-optimization",title:"Memory Optimization                                                                                                                                                                                                                        "},{local:"quality-improvements",title:"Quality Improvements                                                                                                                                                                                                                       "}],title:"The Stable Diffusion Guide \u{1F3A8}                                                                                                                                                                                                           "};function Ou(mp){return Lu(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Wu extends Mu{constructor(M){super();Iu(this,M,Ou,Nu,Tu,{})}}export{Wu as default,xu as metadata};
