import{S as ao,i as so,s as ro,e as n,k as f,w,t as s,M as lo,c as o,d as t,m as d,a,x as $,h as r,b as l,G as e,g as h,y as x,q as D,o as E,B as P,v as fo,L as co}from"../../../../chunks/vendor-hf-doc-builder.js";import{D as q}from"../../../../chunks/Docstring-hf-doc-builder.js";import{C as po}from"../../../../chunks/CodeBlock-hf-doc-builder.js";import{I as oo}from"../../../../chunks/IconCopyLink-hf-doc-builder.js";import{E as uo}from"../../../../chunks/ExampleCodeBlock-hf-doc-builder.js";function mo(ot){let g,N,y,b,C;return b=new po({props:{code:`import torch
from diffusers import StableDiffusionPipeline

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

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

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

<span class="hljs-meta">&gt;&gt;&gt; </span>prompt = <span class="hljs-string">&quot;a photo of an astronaut riding a horse on mars&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>image = pipe(prompt).images[<span class="hljs-number">0</span>]`}}),{c(){g=n("p"),N=s("Examples:"),y=f(),w(b.$$.fragment)},l(p){g=o(p,"P",{});var T=a(g);N=r(T,"Examples:"),T.forEach(t),y=d(p),$(b.$$.fragment,p)},m(p,T){h(p,g,T),e(g,N),h(p,y,T),x(b,p,T),C=!0},p:co,i(p){C||(D(b.$$.fragment,p),C=!0)},o(p){E(b.$$.fragment,p),C=!1},d(p){p&&t(g),p&&t(y),P(b,p)}}}function ho(ot){let g,N,y,b,C,p,T,Me,Tt,at,V,O,Ve,K,At,qe,Lt,st,_,Mt,H,Vt,qt,J,Nt,Ot,R,zt,Ut,Q,Gt,Wt,Se,jt,Ft,rt,ke,Bt,lt,z,X,Ne,Kt,Ht,Y,Jt,Rt,Z,Oe,Qt,Xt,ee,Yt,ft,Ie,Zt,dt,v,te,ze,ei,ti,ie,ii,ni,ne,Ue,oi,ai,oe,si,ri,ae,Ge,li,fi,se,di,ci,re,We,pi,ui,le,mi,hi,fe,je,gi,bi,de,_i,vi,ce,Fe,yi,wi,pe,$i,ct,c,ue,xi,Be,Di,Ei,me,Pi,Ce,Si,ki,Ii,A,he,Ci,Ke,Ti,Ai,U,Li,L,ge,Mi,He,Vi,qi,Je,Ni,Oi,G,be,zi,_e,Ui,Re,Gi,Wi,ji,M,ve,Fi,Qe,Bi,Ki,Xe,Hi,Ji,W,ye,Ri,we,Qi,Ye,Xi,Yi,Zi,S,$e,en,Ze,tn,nn,et,on,an,tt,sn,rn,j,xe,ln,it,fn,dn,F,De,cn,Ee,pn,nt,un,mn,pt;return p=new oo({}),K=new oo({}),ue=new q({props:{name:"class diffusers.StableDiffusionPipeline",anchor:"diffusers.StableDiffusionPipeline",parameters:[{name:"vae",val:": AutoencoderKL"},{name:"text_encoder",val:": CLIPTextModel"},{name:"tokenizer",val:": CLIPTokenizer"},{name:"unet",val:": UNet2DConditionModel"},{name:"scheduler",val:": KarrasDiffusionSchedulers"},{name:"safety_checker",val:": StableDiffusionSafetyChecker"},{name:"feature_extractor",val:": CLIPFeatureExtractor"},{name:"requires_safety_checker",val:": bool = True"}],parametersDescription:[{anchor:"diffusers.StableDiffusionPipeline.vae",description:`<strong>vae</strong> (<a href="/docs/diffusers/main/en/api/models#diffusers.AutoencoderKL">AutoencoderKL</a>) &#x2014;
Variational Auto-Encoder (VAE) Model to encode and decode images to and from latent representations.`,name:"vae"},{anchor:"diffusers.StableDiffusionPipeline.text_encoder",description:`<strong>text_encoder</strong> (<code>CLIPTextModel</code>) &#x2014;
Frozen text-encoder. Stable Diffusion uses the text portion of
<a href="https://huggingface.co/docs/transformers/model_doc/clip#transformers.CLIPTextModel" rel="nofollow">CLIP</a>, specifically
the <a href="https://huggingface.co/openai/clip-vit-large-patch14" rel="nofollow">clip-vit-large-patch14</a> variant.`,name:"text_encoder"},{anchor:"diffusers.StableDiffusionPipeline.tokenizer",description:`<strong>tokenizer</strong> (<code>CLIPTokenizer</code>) &#x2014;
Tokenizer of class
<a href="https://huggingface.co/docs/transformers/v4.21.0/en/model_doc/clip#transformers.CLIPTokenizer" rel="nofollow">CLIPTokenizer</a>.`,name:"tokenizer"},{anchor:"diffusers.StableDiffusionPipeline.unet",description:'<strong>unet</strong> (<a href="/docs/diffusers/main/en/api/models#diffusers.UNet2DConditionModel">UNet2DConditionModel</a>) &#x2014; Conditional U-Net architecture to denoise the encoded image latents.',name:"unet"},{anchor:"diffusers.StableDiffusionPipeline.scheduler",description:`<strong>scheduler</strong> (<a href="/docs/diffusers/main/en/api/schedulers/overview#diffusers.SchedulerMixin">SchedulerMixin</a>) &#x2014;
A scheduler to be used in combination with <code>unet</code> to denoise the encoded image latents. Can be one of
<a href="/docs/diffusers/main/en/api/schedulers/ddim#diffusers.DDIMScheduler">DDIMScheduler</a>, <a href="/docs/diffusers/main/en/api/schedulers/lms_discrete#diffusers.LMSDiscreteScheduler">LMSDiscreteScheduler</a>, or <a href="/docs/diffusers/main/en/api/schedulers/pndm#diffusers.PNDMScheduler">PNDMScheduler</a>.`,name:"scheduler"},{anchor:"diffusers.StableDiffusionPipeline.safety_checker",description:`<strong>safety_checker</strong> (<code>StableDiffusionSafetyChecker</code>) &#x2014;
Classification module that estimates whether generated images could be considered offensive or harmful.
Please, refer to the <a href="https://huggingface.co/runwayml/stable-diffusion-v1-5" rel="nofollow">model card</a> for details.`,name:"safety_checker"},{anchor:"diffusers.StableDiffusionPipeline.feature_extractor",description:`<strong>feature_extractor</strong> (<code>CLIPFeatureExtractor</code>) &#x2014;
Model that extracts features from generated images to be used as inputs for the <code>safety_checker</code>.`,name:"feature_extractor"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py#L49"}}),he=new q({props:{name:"__call__",anchor:"diffusers.StableDiffusionPipeline.__call__",parameters:[{name:"prompt",val:": typing.Union[str, typing.List[str]]"},{name:"height",val:": typing.Optional[int] = None"},{name:"width",val:": typing.Optional[int] = None"},{name:"num_inference_steps",val:": int = 50"},{name:"guidance_scale",val:": float = 7.5"},{name:"negative_prompt",val:": typing.Union[str, typing.List[str], NoneType] = None"},{name:"num_images_per_prompt",val:": typing.Optional[int] = 1"},{name:"eta",val:": float = 0.0"},{name:"generator",val:": typing.Union[torch._C.Generator, typing.List[torch._C.Generator], NoneType] = None"},{name:"latents",val:": typing.Optional[torch.FloatTensor] = None"},{name:"output_type",val:": typing.Optional[str] = 'pil'"},{name:"return_dict",val:": bool = True"},{name:"callback",val:": typing.Union[typing.Callable[[int, int, torch.FloatTensor], NoneType], NoneType] = None"},{name:"callback_steps",val:": typing.Optional[int] = 1"}],parametersDescription:[{anchor:"diffusers.StableDiffusionPipeline.__call__.prompt",description:`<strong>prompt</strong> (<code>str</code> or <code>List[str]</code>) &#x2014;
The prompt or prompts to guide the image generation.`,name:"prompt"},{anchor:"diffusers.StableDiffusionPipeline.__call__.height",description:`<strong>height</strong> (<code>int</code>, <em>optional</em>, defaults to self.unet.config.sample_size * self.vae_scale_factor) &#x2014;
The height in pixels of the generated image.`,name:"height"},{anchor:"diffusers.StableDiffusionPipeline.__call__.width",description:`<strong>width</strong> (<code>int</code>, <em>optional</em>, defaults to self.unet.config.sample_size * self.vae_scale_factor) &#x2014;
The width in pixels of the generated image.`,name:"width"},{anchor:"diffusers.StableDiffusionPipeline.__call__.num_inference_steps",description:`<strong>num_inference_steps</strong> (<code>int</code>, <em>optional</em>, defaults to 50) &#x2014;
The number of denoising steps. More denoising steps usually lead to a higher quality image at the
expense of slower inference.`,name:"num_inference_steps"},{anchor:"diffusers.StableDiffusionPipeline.__call__.guidance_scale",description:`<strong>guidance_scale</strong> (<code>float</code>, <em>optional</em>, defaults to 7.5) &#x2014;
Guidance scale as defined in <a href="https://arxiv.org/abs/2207.12598" rel="nofollow">Classifier-Free Diffusion Guidance</a>.
<code>guidance_scale</code> is defined as <code>w</code> of equation 2. of <a href="https://arxiv.org/pdf/2205.11487.pdf" rel="nofollow">Imagen
Paper</a>. Guidance scale is enabled by setting <code>guidance_scale &gt; 1</code>. Higher guidance scale encourages to generate images that are closely linked to the text <code>prompt</code>,
usually at the expense of lower image quality.`,name:"guidance_scale"},{anchor:"diffusers.StableDiffusionPipeline.__call__.negative_prompt",description:`<strong>negative_prompt</strong> (<code>str</code> or <code>List[str]</code>, <em>optional</em>) &#x2014;
The prompt or prompts not to guide the image generation. Ignored when not using guidance (i.e., ignored
if <code>guidance_scale</code> is less than <code>1</code>).`,name:"negative_prompt"},{anchor:"diffusers.StableDiffusionPipeline.__call__.num_images_per_prompt",description:`<strong>num_images_per_prompt</strong> (<code>int</code>, <em>optional</em>, defaults to 1) &#x2014;
The number of images to generate per prompt.`,name:"num_images_per_prompt"},{anchor:"diffusers.StableDiffusionPipeline.__call__.eta",description:`<strong>eta</strong> (<code>float</code>, <em>optional</em>, defaults to 0.0) &#x2014;
Corresponds to parameter eta (&#x3B7;) in the DDIM paper: <a href="https://arxiv.org/abs/2010.02502" rel="nofollow">https://arxiv.org/abs/2010.02502</a>. Only applies to
<a href="/docs/diffusers/main/en/api/schedulers/ddim#diffusers.DDIMScheduler">schedulers.DDIMScheduler</a>, will be ignored for others.`,name:"eta"},{anchor:"diffusers.StableDiffusionPipeline.__call__.generator",description:`<strong>generator</strong> (<code>torch.Generator</code> or <code>List[torch.Generator]</code>, <em>optional</em>) &#x2014;
One or a list of <a href="https://pytorch.org/docs/stable/generated/torch.Generator.html" rel="nofollow">torch generator(s)</a>
to make generation deterministic.`,name:"generator"},{anchor:"diffusers.StableDiffusionPipeline.__call__.latents",description:`<strong>latents</strong> (<code>torch.FloatTensor</code>, <em>optional</em>) &#x2014;
Pre-generated noisy latents, sampled from a Gaussian distribution, to be used as inputs for image
generation. Can be used to tweak the same generation with different prompts. If not provided, a latents
tensor will ge generated by sampling using the supplied random <code>generator</code>.`,name:"latents"},{anchor:"diffusers.StableDiffusionPipeline.__call__.output_type",description:`<strong>output_type</strong> (<code>str</code>, <em>optional</em>, defaults to <code>&quot;pil&quot;</code>) &#x2014;
The output format of the generate image. Choose between
<a href="https://pillow.readthedocs.io/en/stable/" rel="nofollow">PIL</a>: <code>PIL.Image.Image</code> or <code>np.array</code>.`,name:"output_type"},{anchor:"diffusers.StableDiffusionPipeline.__call__.return_dict",description:`<strong>return_dict</strong> (<code>bool</code>, <em>optional</em>, defaults to <code>True</code>) &#x2014;
Whether or not to return a <a href="/docs/diffusers/main/en/api/pipelines/stable_diffusion/overview#diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput">StableDiffusionPipelineOutput</a> instead of a
plain tuple.`,name:"return_dict"},{anchor:"diffusers.StableDiffusionPipeline.__call__.callback",description:`<strong>callback</strong> (<code>Callable</code>, <em>optional</em>) &#x2014;
A function that will be called every <code>callback_steps</code> steps during inference. The function will be
called with the following arguments: <code>callback(step: int, timestep: int, latents: torch.FloatTensor)</code>.`,name:"callback"},{anchor:"diffusers.StableDiffusionPipeline.__call__.callback_steps",description:`<strong>callback_steps</strong> (<code>int</code>, <em>optional</em>, defaults to 1) &#x2014;
The frequency at which the <code>callback</code> function will be called. If not specified, the callback will be
called at every step.`,name:"callback_steps"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py#L392",returnDescription:`
<p><a
  href="/docs/diffusers/main/en/api/pipelines/stable_diffusion/overview#diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput"
>StableDiffusionPipelineOutput</a> if <code>return_dict</code> is True, otherwise a <code>tuple. When returning a tuple, the first element is a list with the generated images, and the second element is a list of </code>bool<code>s denoting whether the corresponding generated image likely represents "not-safe-for-work" (nsfw) content, according to the </code>safety_checker\`.</p>
`,returnType:`
<p><a
  href="/docs/diffusers/main/en/api/pipelines/stable_diffusion/overview#diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput"
>StableDiffusionPipelineOutput</a> or <code>tuple</code></p>
`}}),U=new uo({props:{anchor:"diffusers.StableDiffusionPipeline.__call__.example",$$slots:{default:[mo]},$$scope:{ctx:ot}}}),ge=new q({props:{name:"enable_attention_slicing",anchor:"diffusers.StableDiffusionPipeline.enable_attention_slicing",parameters:[{name:"slice_size",val:": typing.Union[str, int, NoneType] = 'auto'"}],parametersDescription:[{anchor:"diffusers.StableDiffusionPipeline.enable_attention_slicing.slice_size",description:`<strong>slice_size</strong> (<code>str</code> or <code>int</code>, <em>optional</em>, defaults to <code>&quot;auto&quot;</code>) &#x2014;
When <code>&quot;auto&quot;</code>, halves the input to the attention heads, so attention will be computed in two steps. If
<code>&quot;max&quot;</code>, maxium amount of memory will be saved by running only one slice at a time. If a number is
provided, uses as many slices as <code>attention_head_dim // slice_size</code>. In this case, <code>attention_head_dim</code>
must be a multiple of <code>slice_size</code>.`,name:"slice_size"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/pipeline_utils.py#L876"}}),be=new q({props:{name:"disable_attention_slicing",anchor:"diffusers.StableDiffusionPipeline.disable_attention_slicing",parameters:[],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/pipeline_utils.py#L892"}}),ve=new q({props:{name:"enable_vae_slicing",anchor:"diffusers.StableDiffusionPipeline.enable_vae_slicing",parameters:[],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py#L167"}}),ye=new q({props:{name:"disable_vae_slicing",anchor:"diffusers.StableDiffusionPipeline.disable_vae_slicing",parameters:[],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py#L176"}}),$e=new q({props:{name:"enable_xformers_memory_efficient_attention",anchor:"diffusers.StableDiffusionPipeline.enable_xformers_memory_efficient_attention",parameters:[],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/pipeline_utils.py#L841"}}),xe=new q({props:{name:"disable_xformers_memory_efficient_attention",anchor:"diffusers.StableDiffusionPipeline.disable_xformers_memory_efficient_attention",parameters:[],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/pipeline_utils.py#L853"}}),De=new q({props:{name:"enable_sequential_cpu_offload",anchor:"diffusers.StableDiffusionPipeline.enable_sequential_cpu_offload",parameters:[{name:"gpu_id",val:" = 0"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py#L183"}}),{c(){g=n("meta"),N=f(),y=n("h1"),b=n("a"),C=n("span"),w(p.$$.fragment),T=f(),Me=n("span"),Tt=s("Text-to-Image Generation"),at=f(),V=n("h2"),O=n("a"),Ve=n("span"),w(K.$$.fragment),At=f(),qe=n("span"),Lt=s("StableDiffusionPipeline"),st=f(),_=n("p"),Mt=s("The Stable Diffusion model was created by the researchers and engineers from "),H=n("a"),Vt=s("CompVis"),qt=s(", "),J=n("a"),Nt=s("Stability AI"),Ot=s(", "),R=n("a"),zt=s("runway"),Ut=s(", and "),Q=n("a"),Gt=s("LAION"),Wt=s(". The "),Se=n("a"),jt=s("StableDiffusionPipeline"),Ft=s(" is capable of generating photo-realistic images given any text input using Stable Diffusion."),rt=f(),ke=n("p"),Bt=s("The original codebase can be found here:"),lt=f(),z=n("ul"),X=n("li"),Ne=n("em"),Kt=s("Stable Diffusion V1"),Ht=s(": "),Y=n("a"),Jt=s("CampVis/stable-diffusion"),Rt=f(),Z=n("li"),Oe=n("em"),Qt=s("Stable Diffusion v2"),Xt=s(": "),ee=n("a"),Yt=s("Stability-AI/stablediffusion"),ft=f(),Ie=n("p"),Zt=s("Available Checkpoints are:"),dt=f(),v=n("ul"),te=n("li"),ze=n("em"),ei=s("stable-diffusion-v1-4 (512x512 resolution)"),ti=f(),ie=n("a"),ii=s("CompVis/stable-diffusion-v1-4"),ni=f(),ne=n("li"),Ue=n("em"),oi=s("stable-diffusion-v1-5 (512x512 resolution)"),ai=f(),oe=n("a"),si=s("runwayml/stable-diffusion-v1-5"),ri=f(),ae=n("li"),Ge=n("em"),li=s("stable-diffusion-2-base (512x512 resolution)"),fi=s(": "),se=n("a"),di=s("stabilityai/stable-diffusion-2-base"),ci=f(),re=n("li"),We=n("em"),pi=s("stable-diffusion-2 (768x768 resolution)"),ui=s(": "),le=n("a"),mi=s("stabilityai/stable-diffusion-2"),hi=f(),fe=n("li"),je=n("em"),gi=s("stable-diffusion-2-1-base (512x512 resolution)"),bi=f(),de=n("a"),_i=s("stabilityai/stable-diffusion-2-1-base"),vi=f(),ce=n("li"),Fe=n("em"),yi=s("stable-diffusion-2-1 (768x768 resolution)"),wi=s(": "),pe=n("a"),$i=s("stabilityai/stable-diffusion-2-1"),ct=f(),c=n("div"),w(ue.$$.fragment),xi=f(),Be=n("p"),Di=s("Pipeline for text-to-image generation using Stable Diffusion."),Ei=f(),me=n("p"),Pi=s("This model inherits from "),Ce=n("a"),Si=s("DiffusionPipeline"),ki=s(`. Check the superclass documentation for the generic methods the
library implements for all the pipelines (such as downloading or saving, running on a particular device, etc.)`),Ii=f(),A=n("div"),w(he.$$.fragment),Ci=f(),Ke=n("p"),Ti=s("Function invoked when calling the pipeline for generation."),Ai=f(),w(U.$$.fragment),Li=f(),L=n("div"),w(ge.$$.fragment),Mi=f(),He=n("p"),Vi=s("Enable sliced attention computation."),qi=f(),Je=n("p"),Ni=s(`When this option is enabled, the attention module will split the input tensor in slices, to compute attention
in several steps. This is useful to save some memory in exchange for a small speed decrease.`),Oi=f(),G=n("div"),w(be.$$.fragment),zi=f(),_e=n("p"),Ui=s("Disable sliced attention computation. If "),Re=n("code"),Gi=s("enable_attention_slicing"),Wi=s(` was previously invoked, this method will go
back to computing attention in one step.`),ji=f(),M=n("div"),w(ve.$$.fragment),Fi=f(),Qe=n("p"),Bi=s("Enable sliced VAE decoding."),Ki=f(),Xe=n("p"),Hi=s(`When this option is enabled, the VAE will split the input tensor in slices to compute decoding in several
steps. This is useful to save some memory and allow larger batch sizes.`),Ji=f(),W=n("div"),w(ye.$$.fragment),Ri=f(),we=n("p"),Qi=s("Disable sliced VAE decoding. If "),Ye=n("code"),Xi=s("enable_vae_slicing"),Yi=s(` was previously invoked, this method will go back to
computing decoding in one step.`),Zi=f(),S=n("div"),w($e.$$.fragment),en=f(),Ze=n("p"),tn=s("Enable memory efficient attention as implemented in xformers."),nn=f(),et=n("p"),on=s(`When this option is enabled, you should observe lower GPU memory usage and a potential speed up at inference
time. Speed up at training time is not guaranteed.`),an=f(),tt=n("p"),sn=s(`Warning: When Memory Efficient Attention and Sliced attention are both enabled, the Memory Efficient Attention
is used.`),rn=f(),j=n("div"),w(xe.$$.fragment),ln=f(),it=n("p"),fn=s("Disable memory efficient attention as implemented in xformers."),dn=f(),F=n("div"),w(De.$$.fragment),cn=f(),Ee=n("p"),pn=s(`Offloads all models to CPU using accelerate, significantly reducing memory usage. When called, unet,
text_encoder, vae and safety checker have their state dicts saved to CPU and then are moved to a
`),nt=n("code"),un=s("torch.device('meta') and loaded to GPU only when their specific submodule has its "),mn=s("forward` method called."),this.h()},l(i){const u=lo('[data-svelte="svelte-1phssyn"]',document.head);g=o(u,"META",{name:!0,content:!0}),u.forEach(t),N=d(i),y=o(i,"H1",{class:!0});var Pe=a(y);b=o(Pe,"A",{id:!0,class:!0,href:!0});var hn=a(b);C=o(hn,"SPAN",{});var gn=a(C);$(p.$$.fragment,gn),gn.forEach(t),hn.forEach(t),T=d(Pe),Me=o(Pe,"SPAN",{});var bn=a(Me);Tt=r(bn,"Text-to-Image Generation"),bn.forEach(t),Pe.forEach(t),at=d(i),V=o(i,"H2",{class:!0});var ut=a(V);O=o(ut,"A",{id:!0,class:!0,href:!0});var _n=a(O);Ve=o(_n,"SPAN",{});var vn=a(Ve);$(K.$$.fragment,vn),vn.forEach(t),_n.forEach(t),At=d(ut),qe=o(ut,"SPAN",{});var yn=a(qe);Lt=r(yn,"StableDiffusionPipeline"),yn.forEach(t),ut.forEach(t),st=d(i),_=o(i,"P",{});var k=a(_);Mt=r(k,"The Stable Diffusion model was created by the researchers and engineers from "),H=o(k,"A",{href:!0,rel:!0});var wn=a(H);Vt=r(wn,"CompVis"),wn.forEach(t),qt=r(k,", "),J=o(k,"A",{href:!0,rel:!0});var $n=a(J);Nt=r($n,"Stability AI"),$n.forEach(t),Ot=r(k,", "),R=o(k,"A",{href:!0,rel:!0});var xn=a(R);zt=r(xn,"runway"),xn.forEach(t),Ut=r(k,", and "),Q=o(k,"A",{href:!0,rel:!0});var Dn=a(Q);Gt=r(Dn,"LAION"),Dn.forEach(t),Wt=r(k,". The "),Se=o(k,"A",{href:!0});var En=a(Se);jt=r(En,"StableDiffusionPipeline"),En.forEach(t),Ft=r(k," is capable of generating photo-realistic images given any text input using Stable Diffusion."),k.forEach(t),rt=d(i),ke=o(i,"P",{});var Pn=a(ke);Bt=r(Pn,"The original codebase can be found here:"),Pn.forEach(t),lt=d(i),z=o(i,"UL",{});var mt=a(z);X=o(mt,"LI",{});var ht=a(X);Ne=o(ht,"EM",{});var Sn=a(Ne);Kt=r(Sn,"Stable Diffusion V1"),Sn.forEach(t),Ht=r(ht,": "),Y=o(ht,"A",{href:!0,rel:!0});var kn=a(Y);Jt=r(kn,"CampVis/stable-diffusion"),kn.forEach(t),ht.forEach(t),Rt=d(mt),Z=o(mt,"LI",{});var gt=a(Z);Oe=o(gt,"EM",{});var In=a(Oe);Qt=r(In,"Stable Diffusion v2"),In.forEach(t),Xt=r(gt,": "),ee=o(gt,"A",{href:!0,rel:!0});var Cn=a(ee);Yt=r(Cn,"Stability-AI/stablediffusion"),Cn.forEach(t),gt.forEach(t),mt.forEach(t),ft=d(i),Ie=o(i,"P",{});var Tn=a(Ie);Zt=r(Tn,"Available Checkpoints are:"),Tn.forEach(t),dt=d(i),v=o(i,"UL",{});var I=a(v);te=o(I,"LI",{});var bt=a(te);ze=o(bt,"EM",{});var An=a(ze);ei=r(An,"stable-diffusion-v1-4 (512x512 resolution)"),An.forEach(t),ti=d(bt),ie=o(bt,"A",{href:!0,rel:!0});var Ln=a(ie);ii=r(Ln,"CompVis/stable-diffusion-v1-4"),Ln.forEach(t),bt.forEach(t),ni=d(I),ne=o(I,"LI",{});var _t=a(ne);Ue=o(_t,"EM",{});var Mn=a(Ue);oi=r(Mn,"stable-diffusion-v1-5 (512x512 resolution)"),Mn.forEach(t),ai=d(_t),oe=o(_t,"A",{href:!0,rel:!0});var Vn=a(oe);si=r(Vn,"runwayml/stable-diffusion-v1-5"),Vn.forEach(t),_t.forEach(t),ri=d(I),ae=o(I,"LI",{});var vt=a(ae);Ge=o(vt,"EM",{});var qn=a(Ge);li=r(qn,"stable-diffusion-2-base (512x512 resolution)"),qn.forEach(t),fi=r(vt,": "),se=o(vt,"A",{href:!0,rel:!0});var Nn=a(se);di=r(Nn,"stabilityai/stable-diffusion-2-base"),Nn.forEach(t),vt.forEach(t),ci=d(I),re=o(I,"LI",{});var yt=a(re);We=o(yt,"EM",{});var On=a(We);pi=r(On,"stable-diffusion-2 (768x768 resolution)"),On.forEach(t),ui=r(yt,": "),le=o(yt,"A",{href:!0,rel:!0});var zn=a(le);mi=r(zn,"stabilityai/stable-diffusion-2"),zn.forEach(t),yt.forEach(t),hi=d(I),fe=o(I,"LI",{});var wt=a(fe);je=o(wt,"EM",{});var Un=a(je);gi=r(Un,"stable-diffusion-2-1-base (512x512 resolution)"),Un.forEach(t),bi=d(wt),de=o(wt,"A",{href:!0,rel:!0});var Gn=a(de);_i=r(Gn,"stabilityai/stable-diffusion-2-1-base"),Gn.forEach(t),wt.forEach(t),vi=d(I),ce=o(I,"LI",{});var $t=a(ce);Fe=o($t,"EM",{});var Wn=a(Fe);yi=r(Wn,"stable-diffusion-2-1 (768x768 resolution)"),Wn.forEach(t),wi=r($t,": "),pe=o($t,"A",{href:!0,rel:!0});var jn=a(pe);$i=r(jn,"stabilityai/stable-diffusion-2-1"),jn.forEach(t),$t.forEach(t),I.forEach(t),ct=d(i),c=o(i,"DIV",{class:!0});var m=a(c);$(ue.$$.fragment,m),xi=d(m),Be=o(m,"P",{});var Fn=a(Be);Di=r(Fn,"Pipeline for text-to-image generation using Stable Diffusion."),Fn.forEach(t),Ei=d(m),me=o(m,"P",{});var xt=a(me);Pi=r(xt,"This model inherits from "),Ce=o(xt,"A",{href:!0});var Bn=a(Ce);Si=r(Bn,"DiffusionPipeline"),Bn.forEach(t),ki=r(xt,`. Check the superclass documentation for the generic methods the
library implements for all the pipelines (such as downloading or saving, running on a particular device, etc.)`),xt.forEach(t),Ii=d(m),A=o(m,"DIV",{class:!0});var Te=a(A);$(he.$$.fragment,Te),Ci=d(Te),Ke=o(Te,"P",{});var Kn=a(Ke);Ti=r(Kn,"Function invoked when calling the pipeline for generation."),Kn.forEach(t),Ai=d(Te),$(U.$$.fragment,Te),Te.forEach(t),Li=d(m),L=o(m,"DIV",{class:!0});var Ae=a(L);$(ge.$$.fragment,Ae),Mi=d(Ae),He=o(Ae,"P",{});var Hn=a(He);Vi=r(Hn,"Enable sliced attention computation."),Hn.forEach(t),qi=d(Ae),Je=o(Ae,"P",{});var Jn=a(Je);Ni=r(Jn,`When this option is enabled, the attention module will split the input tensor in slices, to compute attention
in several steps. This is useful to save some memory in exchange for a small speed decrease.`),Jn.forEach(t),Ae.forEach(t),Oi=d(m),G=o(m,"DIV",{class:!0});var Dt=a(G);$(be.$$.fragment,Dt),zi=d(Dt),_e=o(Dt,"P",{});var Et=a(_e);Ui=r(Et,"Disable sliced attention computation. If "),Re=o(Et,"CODE",{});var Rn=a(Re);Gi=r(Rn,"enable_attention_slicing"),Rn.forEach(t),Wi=r(Et,` was previously invoked, this method will go
back to computing attention in one step.`),Et.forEach(t),Dt.forEach(t),ji=d(m),M=o(m,"DIV",{class:!0});var Le=a(M);$(ve.$$.fragment,Le),Fi=d(Le),Qe=o(Le,"P",{});var Qn=a(Qe);Bi=r(Qn,"Enable sliced VAE decoding."),Qn.forEach(t),Ki=d(Le),Xe=o(Le,"P",{});var Xn=a(Xe);Hi=r(Xn,`When this option is enabled, the VAE will split the input tensor in slices to compute decoding in several
steps. This is useful to save some memory and allow larger batch sizes.`),Xn.forEach(t),Le.forEach(t),Ji=d(m),W=o(m,"DIV",{class:!0});var Pt=a(W);$(ye.$$.fragment,Pt),Ri=d(Pt),we=o(Pt,"P",{});var St=a(we);Qi=r(St,"Disable sliced VAE decoding. If "),Ye=o(St,"CODE",{});var Yn=a(Ye);Xi=r(Yn,"enable_vae_slicing"),Yn.forEach(t),Yi=r(St,` was previously invoked, this method will go back to
computing decoding in one step.`),St.forEach(t),Pt.forEach(t),Zi=d(m),S=o(m,"DIV",{class:!0});var B=a(S);$($e.$$.fragment,B),en=d(B),Ze=o(B,"P",{});var Zn=a(Ze);tn=r(Zn,"Enable memory efficient attention as implemented in xformers."),Zn.forEach(t),nn=d(B),et=o(B,"P",{});var eo=a(et);on=r(eo,`When this option is enabled, you should observe lower GPU memory usage and a potential speed up at inference
time. Speed up at training time is not guaranteed.`),eo.forEach(t),an=d(B),tt=o(B,"P",{});var to=a(tt);sn=r(to,`Warning: When Memory Efficient Attention and Sliced attention are both enabled, the Memory Efficient Attention
is used.`),to.forEach(t),B.forEach(t),rn=d(m),j=o(m,"DIV",{class:!0});var kt=a(j);$(xe.$$.fragment,kt),ln=d(kt),it=o(kt,"P",{});var io=a(it);fn=r(io,"Disable memory efficient attention as implemented in xformers."),io.forEach(t),kt.forEach(t),dn=d(m),F=o(m,"DIV",{class:!0});var It=a(F);$(De.$$.fragment,It),cn=d(It),Ee=o(It,"P",{});var Ct=a(Ee);pn=r(Ct,`Offloads all models to CPU using accelerate, significantly reducing memory usage. When called, unet,
text_encoder, vae and safety checker have their state dicts saved to CPU and then are moved to a
`),nt=o(Ct,"CODE",{});var no=a(nt);un=r(no,"torch.device('meta') and loaded to GPU only when their specific submodule has its "),no.forEach(t),mn=r(Ct,"forward` method called."),Ct.forEach(t),It.forEach(t),m.forEach(t),this.h()},h(){l(g,"name","hf:doc:metadata"),l(g,"content",JSON.stringify(go)),l(b,"id","texttoimage-generation"),l(b,"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"),l(b,"href","#texttoimage-generation"),l(y,"class","relative group"),l(O,"id","diffusers.StableDiffusionPipeline"),l(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"),l(O,"href","#diffusers.StableDiffusionPipeline"),l(V,"class","relative group"),l(H,"href","https://github.com/CompVis"),l(H,"rel","nofollow"),l(J,"href","https://stability.ai/"),l(J,"rel","nofollow"),l(R,"href","https://github.com/runwayml"),l(R,"rel","nofollow"),l(Q,"href","https://laion.ai/"),l(Q,"rel","nofollow"),l(Se,"href","/docs/diffusers/main/en/api/pipelines/stable_diffusion/text2img#diffusers.StableDiffusionPipeline"),l(Y,"href","https://github.com/CompVis/stable-diffusion"),l(Y,"rel","nofollow"),l(ee,"href","https://github.com/Stability-AI/stablediffusion"),l(ee,"rel","nofollow"),l(ie,"href","https://huggingface.co/CompVis/stable-diffusion-v1-4"),l(ie,"rel","nofollow"),l(oe,"href","https://huggingface.co/runwayml/stable-diffusion-v1-5"),l(oe,"rel","nofollow"),l(se,"href","https://huggingface.co/stabilityai/stable-diffusion-2-base"),l(se,"rel","nofollow"),l(le,"href","https://huggingface.co/stabilityai/stable-diffusion-2"),l(le,"rel","nofollow"),l(de,"href","https://huggingface.co/stabilityai/stable-diffusion-2-1-base"),l(de,"rel","nofollow"),l(pe,"href","https://huggingface.co/stabilityai/stable-diffusion-2-1"),l(pe,"rel","nofollow"),l(Ce,"href","/docs/diffusers/main/en/api/diffusion_pipeline#diffusers.DiffusionPipeline"),l(A,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(L,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(G,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(M,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(W,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(S,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(j,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(F,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(c,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8")},m(i,u){e(document.head,g),h(i,N,u),h(i,y,u),e(y,b),e(b,C),x(p,C,null),e(y,T),e(y,Me),e(Me,Tt),h(i,at,u),h(i,V,u),e(V,O),e(O,Ve),x(K,Ve,null),e(V,At),e(V,qe),e(qe,Lt),h(i,st,u),h(i,_,u),e(_,Mt),e(_,H),e(H,Vt),e(_,qt),e(_,J),e(J,Nt),e(_,Ot),e(_,R),e(R,zt),e(_,Ut),e(_,Q),e(Q,Gt),e(_,Wt),e(_,Se),e(Se,jt),e(_,Ft),h(i,rt,u),h(i,ke,u),e(ke,Bt),h(i,lt,u),h(i,z,u),e(z,X),e(X,Ne),e(Ne,Kt),e(X,Ht),e(X,Y),e(Y,Jt),e(z,Rt),e(z,Z),e(Z,Oe),e(Oe,Qt),e(Z,Xt),e(Z,ee),e(ee,Yt),h(i,ft,u),h(i,Ie,u),e(Ie,Zt),h(i,dt,u),h(i,v,u),e(v,te),e(te,ze),e(ze,ei),e(te,ti),e(te,ie),e(ie,ii),e(v,ni),e(v,ne),e(ne,Ue),e(Ue,oi),e(ne,ai),e(ne,oe),e(oe,si),e(v,ri),e(v,ae),e(ae,Ge),e(Ge,li),e(ae,fi),e(ae,se),e(se,di),e(v,ci),e(v,re),e(re,We),e(We,pi),e(re,ui),e(re,le),e(le,mi),e(v,hi),e(v,fe),e(fe,je),e(je,gi),e(fe,bi),e(fe,de),e(de,_i),e(v,vi),e(v,ce),e(ce,Fe),e(Fe,yi),e(ce,wi),e(ce,pe),e(pe,$i),h(i,ct,u),h(i,c,u),x(ue,c,null),e(c,xi),e(c,Be),e(Be,Di),e(c,Ei),e(c,me),e(me,Pi),e(me,Ce),e(Ce,Si),e(me,ki),e(c,Ii),e(c,A),x(he,A,null),e(A,Ci),e(A,Ke),e(Ke,Ti),e(A,Ai),x(U,A,null),e(c,Li),e(c,L),x(ge,L,null),e(L,Mi),e(L,He),e(He,Vi),e(L,qi),e(L,Je),e(Je,Ni),e(c,Oi),e(c,G),x(be,G,null),e(G,zi),e(G,_e),e(_e,Ui),e(_e,Re),e(Re,Gi),e(_e,Wi),e(c,ji),e(c,M),x(ve,M,null),e(M,Fi),e(M,Qe),e(Qe,Bi),e(M,Ki),e(M,Xe),e(Xe,Hi),e(c,Ji),e(c,W),x(ye,W,null),e(W,Ri),e(W,we),e(we,Qi),e(we,Ye),e(Ye,Xi),e(we,Yi),e(c,Zi),e(c,S),x($e,S,null),e(S,en),e(S,Ze),e(Ze,tn),e(S,nn),e(S,et),e(et,on),e(S,an),e(S,tt),e(tt,sn),e(c,rn),e(c,j),x(xe,j,null),e(j,ln),e(j,it),e(it,fn),e(c,dn),e(c,F),x(De,F,null),e(F,cn),e(F,Ee),e(Ee,pn),e(Ee,nt),e(nt,un),e(Ee,mn),pt=!0},p(i,[u]){const Pe={};u&2&&(Pe.$$scope={dirty:u,ctx:i}),U.$set(Pe)},i(i){pt||(D(p.$$.fragment,i),D(K.$$.fragment,i),D(ue.$$.fragment,i),D(he.$$.fragment,i),D(U.$$.fragment,i),D(ge.$$.fragment,i),D(be.$$.fragment,i),D(ve.$$.fragment,i),D(ye.$$.fragment,i),D($e.$$.fragment,i),D(xe.$$.fragment,i),D(De.$$.fragment,i),pt=!0)},o(i){E(p.$$.fragment,i),E(K.$$.fragment,i),E(ue.$$.fragment,i),E(he.$$.fragment,i),E(U.$$.fragment,i),E(ge.$$.fragment,i),E(be.$$.fragment,i),E(ve.$$.fragment,i),E(ye.$$.fragment,i),E($e.$$.fragment,i),E(xe.$$.fragment,i),E(De.$$.fragment,i),pt=!1},d(i){t(g),i&&t(N),i&&t(y),P(p),i&&t(at),i&&t(V),P(K),i&&t(st),i&&t(_),i&&t(rt),i&&t(ke),i&&t(lt),i&&t(z),i&&t(ft),i&&t(Ie),i&&t(dt),i&&t(v),i&&t(ct),i&&t(c),P(ue),P(he),P(U),P(ge),P(be),P(ve),P(ye),P($e),P(xe),P(De)}}}const go={local:"texttoimage-generation",sections:[{local:"diffusers.StableDiffusionPipeline",title:"StableDiffusionPipeline"}],title:"Text-to-Image Generation"};function bo(ot){return fo(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class xo extends ao{constructor(g){super();so(this,g,bo,ho,ro,{})}}export{xo as default,go as metadata};
