import{S as po,i as co,s as uo,e as i,k as f,w as x,t as s,M as mo,c as o,d as t,m as d,a,x as D,h as r,b as l,G as e,g as _,y as P,q as E,o as S,B as k,v as ho,L as lo}from"../../../../chunks/vendor-hf-doc-builder.js";import{D as V}from"../../../../chunks/Docstring-hf-doc-builder.js";import{C as fo}from"../../../../chunks/CodeBlock-hf-doc-builder.js";import{I as so}from"../../../../chunks/IconCopyLink-hf-doc-builder.js";import{E as ro}from"../../../../chunks/ExampleCodeBlock-hf-doc-builder.js";function go(ke){let h,A,b,u,$;return u=new fo({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(){h=i("p"),A=s("Examples:"),b=f(),x(u.$$.fragment)},l(p){h=o(p,"P",{});var v=a(h);A=r(v,"Examples:"),v.forEach(t),b=d(p),D(u.$$.fragment,p)},m(p,v){_(p,h,v),e(h,A),_(p,b,v),P(u,p,v),$=!0},p:lo,i(p){$||(E(u.$$.fragment,p),$=!0)},o(p){S(u.$$.fragment,p),$=!1},d(p){p&&t(h),p&&t(b),k(u,p)}}}function _o(ke){let h,A,b,u,$;return u=new fo({props:{code:`import torch
from diffusers import DiffusionPipeline
from xformers.ops import MemoryEfficientAttentionFlashAttentionOp

pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-2-1", torch_dtype=torch.float16)
pipe = pipe.to("cuda")
pipe.enable_xformers_memory_efficient_attention(attention_op=MemoryEfficientAttentionFlashAttentionOp)
# Workaround for not accepting attention shape using VAE for Flash Attention
pipe.vae.enable_xformers_memory_efficient_attention(attention_op=None)`,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> DiffusionPipeline
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> xformers.ops <span class="hljs-keyword">import</span> MemoryEfficientAttentionFlashAttentionOp

<span class="hljs-meta">&gt;&gt;&gt; </span>pipe = DiffusionPipeline.from_pretrained(<span class="hljs-string">&quot;stabilityai/stable-diffusion-2-1&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>pipe.enable_xformers_memory_efficient_attention(attention_op=MemoryEfficientAttentionFlashAttentionOp)
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-comment"># Workaround for not accepting attention shape using VAE for Flash Attention</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>pipe.vae.enable_xformers_memory_efficient_attention(attention_op=<span class="hljs-literal">None</span>)`}}),{c(){h=i("p"),A=s("Examples:"),b=f(),x(u.$$.fragment)},l(p){h=o(p,"P",{});var v=a(h);A=r(v,"Examples:"),v.forEach(t),b=d(p),D(u.$$.fragment,p)},m(p,v){_(p,h,v),e(h,A),_(p,b,v),P(u,p,v),$=!0},p:lo,i(p){$||(E(u.$$.fragment,p),$=!0)},o(p){S(u.$$.fragment,p),$=!1},d(p){p&&t(h),p&&t(b),k(u,p)}}}function bo(ke){let h,A,b,u,$,p,v,je,Lt,rt,O,q,Oe,H,Mt,Ve,Nt,lt,y,jt,J,Ot,Vt,R,qt,Ft,Q,zt,Ut,X,Gt,Wt,Ie,Bt,Kt,ft,Ae,Ht,dt,F,Y,qe,Jt,Rt,Z,Qt,Xt,ee,Fe,Yt,Zt,te,en,pt,Ce,tn,ct,w,ne,ze,nn,on,ie,an,sn,oe,Ue,rn,ln,ae,fn,dn,se,Ge,pn,cn,re,un,mn,le,We,hn,gn,fe,_n,bn,de,Be,vn,yn,pe,wn,$n,ce,Ke,xn,Dn,ue,Pn,ut,c,me,En,He,Sn,kn,he,In,Te,An,Cn,Tn,L,ge,Ln,Je,Mn,Nn,z,jn,M,_e,On,Re,Vn,qn,Qe,Fn,zn,U,be,Un,ve,Gn,Xe,Wn,Bn,Kn,N,ye,Hn,Ye,Jn,Rn,Ze,Qn,Xn,G,we,Yn,$e,Zn,et,ei,ti,ni,I,xe,ii,tt,oi,ai,nt,si,ri,it,li,fi,W,di,B,De,pi,ot,ci,ui,K,Pe,mi,Ee,hi,at,gi,_i,mt;return p=new so({}),H=new so({}),me=new V({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/v0.12.0/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/v0.12.0/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/v0.12.0/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/v0.12.0/en/api/schedulers/ddim#diffusers.DDIMScheduler">DDIMScheduler</a>, <a href="/docs/diffusers/v0.12.0/en/api/schedulers/lms_discrete#diffusers.LMSDiscreteScheduler">LMSDiscreteScheduler</a>, or <a href="/docs/diffusers/v0.12.0/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/v0.12.0/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py#L49"}}),ge=new V({props:{name:"__call__",anchor:"diffusers.StableDiffusionPipeline.__call__",parameters:[{name:"prompt",val:": typing.Union[str, typing.List[str]] = None"},{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:"prompt_embeds",val:": typing.Optional[torch.FloatTensor] = None"},{name:"negative_prompt_embeds",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>, <em>optional</em>) &#x2014;
The prompt or prompts to guide the image generation. If not defined, one has to pass <code>prompt_embeds</code>.
instead.`,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. If not defined, one has to pass
<code>negative_prompt_embeds</code>. instead. If not defined, one has to pass <code>negative_prompt_embeds</code>. instead.
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/v0.12.0/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__.prompt_embeds",description:`<strong>prompt_embeds</strong> (<code>torch.FloatTensor</code>, <em>optional</em>) &#x2014;
Pre-generated text embeddings. Can be used to easily tweak text inputs, <em>e.g.</em> prompt weighting. If not
provided, text embeddings will be generated from <code>prompt</code> input argument.`,name:"prompt_embeds"},{anchor:"diffusers.StableDiffusionPipeline.__call__.negative_prompt_embeds",description:`<strong>negative_prompt_embeds</strong> (<code>torch.FloatTensor</code>, <em>optional</em>) &#x2014;
Pre-generated negative text embeddings. Can be used to easily tweak text inputs, <em>e.g.</em> prompt
weighting. If not provided, negative_prompt_embeds will be generated from <code>negative_prompt</code> input
argument.`,name:"negative_prompt_embeds"},{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/v0.12.0/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/v0.12.0/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py#L457",returnDescription:`
<p><a
  href="/docs/diffusers/v0.12.0/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/v0.12.0/en/api/pipelines/stable_diffusion/overview#diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput"
>StableDiffusionPipelineOutput</a> or <code>tuple</code></p>
`}}),z=new ro({props:{anchor:"diffusers.StableDiffusionPipeline.__call__.example",$$slots:{default:[go]},$$scope:{ctx:ke}}}),_e=new V({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/v0.12.0/src/diffusers/pipelines/pipeline_utils.py#L902"}}),be=new V({props:{name:"disable_attention_slicing",anchor:"diffusers.StableDiffusionPipeline.disable_attention_slicing",parameters:[],source:"https://github.com/huggingface/diffusers/blob/v0.12.0/src/diffusers/pipelines/pipeline_utils.py#L918"}}),ye=new V({props:{name:"enable_vae_slicing",anchor:"diffusers.StableDiffusionPipeline.enable_vae_slicing",parameters:[],source:"https://github.com/huggingface/diffusers/blob/v0.12.0/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py#L167"}}),we=new V({props:{name:"disable_vae_slicing",anchor:"diffusers.StableDiffusionPipeline.disable_vae_slicing",parameters:[],source:"https://github.com/huggingface/diffusers/blob/v0.12.0/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py#L176"}}),xe=new V({props:{name:"enable_xformers_memory_efficient_attention",anchor:"diffusers.StableDiffusionPipeline.enable_xformers_memory_efficient_attention",parameters:[{name:"attention_op",val:": typing.Optional[typing.Callable] = None"}],parametersDescription:[{anchor:"diffusers.StableDiffusionPipeline.enable_xformers_memory_efficient_attention.attention_op",description:`<strong>attention_op</strong> (<code>Callable</code>, <em>optional</em>) &#x2014;
Override the default <code>None</code> operator for use as <code>op</code> argument to the
<a href="https://facebookresearch.github.io/xformers/components/ops.html#xformers.ops.memory_efficient_attention" rel="nofollow"><code>memory_efficient_attention()</code></a>
function of xFormers.`,name:"attention_op"}],source:"https://github.com/huggingface/diffusers/blob/v0.12.0/src/diffusers/pipelines/pipeline_utils.py#L845"}}),W=new ro({props:{anchor:"diffusers.StableDiffusionPipeline.enable_xformers_memory_efficient_attention.example",$$slots:{default:[_o]},$$scope:{ctx:ke}}}),De=new V({props:{name:"disable_xformers_memory_efficient_attention",anchor:"diffusers.StableDiffusionPipeline.disable_xformers_memory_efficient_attention",parameters:[],source:"https://github.com/huggingface/diffusers/blob/v0.12.0/src/diffusers/pipelines/pipeline_utils.py#L877"}}),Pe=new V({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/v0.12.0/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py#L183"}}),{c(){h=i("meta"),A=f(),b=i("h1"),u=i("a"),$=i("span"),x(p.$$.fragment),v=f(),je=i("span"),Lt=s("Text-to-Image Generation"),rt=f(),O=i("h2"),q=i("a"),Oe=i("span"),x(H.$$.fragment),Mt=f(),Ve=i("span"),Nt=s("StableDiffusionPipeline"),lt=f(),y=i("p"),jt=s("The Stable Diffusion model was created by the researchers and engineers from "),J=i("a"),Ot=s("CompVis"),Vt=s(", "),R=i("a"),qt=s("Stability AI"),Ft=s(", "),Q=i("a"),zt=s("runway"),Ut=s(", and "),X=i("a"),Gt=s("LAION"),Wt=s(". The "),Ie=i("a"),Bt=s("StableDiffusionPipeline"),Kt=s(" is capable of generating photo-realistic images given any text input using Stable Diffusion."),ft=f(),Ae=i("p"),Ht=s("The original codebase can be found here:"),dt=f(),F=i("ul"),Y=i("li"),qe=i("em"),Jt=s("Stable Diffusion V1"),Rt=s(": "),Z=i("a"),Qt=s("CampVis/stable-diffusion"),Xt=f(),ee=i("li"),Fe=i("em"),Yt=s("Stable Diffusion v2"),Zt=s(": "),te=i("a"),en=s("Stability-AI/stablediffusion"),pt=f(),Ce=i("p"),tn=s("Available Checkpoints are:"),ct=f(),w=i("ul"),ne=i("li"),ze=i("em"),nn=s("stable-diffusion-v1-4 (512x512 resolution)"),on=f(),ie=i("a"),an=s("CompVis/stable-diffusion-v1-4"),sn=f(),oe=i("li"),Ue=i("em"),rn=s("stable-diffusion-v1-5 (512x512 resolution)"),ln=f(),ae=i("a"),fn=s("runwayml/stable-diffusion-v1-5"),dn=f(),se=i("li"),Ge=i("em"),pn=s("stable-diffusion-2-base (512x512 resolution)"),cn=s(": "),re=i("a"),un=s("stabilityai/stable-diffusion-2-base"),mn=f(),le=i("li"),We=i("em"),hn=s("stable-diffusion-2 (768x768 resolution)"),gn=s(": "),fe=i("a"),_n=s("stabilityai/stable-diffusion-2"),bn=f(),de=i("li"),Be=i("em"),vn=s("stable-diffusion-2-1-base (512x512 resolution)"),yn=f(),pe=i("a"),wn=s("stabilityai/stable-diffusion-2-1-base"),$n=f(),ce=i("li"),Ke=i("em"),xn=s("stable-diffusion-2-1 (768x768 resolution)"),Dn=s(": "),ue=i("a"),Pn=s("stabilityai/stable-diffusion-2-1"),ut=f(),c=i("div"),x(me.$$.fragment),En=f(),He=i("p"),Sn=s("Pipeline for text-to-image generation using Stable Diffusion."),kn=f(),he=i("p"),In=s("This model inherits from "),Te=i("a"),An=s("DiffusionPipeline"),Cn=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.)`),Tn=f(),L=i("div"),x(ge.$$.fragment),Ln=f(),Je=i("p"),Mn=s("Function invoked when calling the pipeline for generation."),Nn=f(),x(z.$$.fragment),jn=f(),M=i("div"),x(_e.$$.fragment),On=f(),Re=i("p"),Vn=s("Enable sliced attention computation."),qn=f(),Qe=i("p"),Fn=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.`),zn=f(),U=i("div"),x(be.$$.fragment),Un=f(),ve=i("p"),Gn=s("Disable sliced attention computation. If "),Xe=i("code"),Wn=s("enable_attention_slicing"),Bn=s(` was previously invoked, this method will go
back to computing attention in one step.`),Kn=f(),N=i("div"),x(ye.$$.fragment),Hn=f(),Ye=i("p"),Jn=s("Enable sliced VAE decoding."),Rn=f(),Ze=i("p"),Qn=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.`),Xn=f(),G=i("div"),x(we.$$.fragment),Yn=f(),$e=i("p"),Zn=s("Disable sliced VAE decoding. If "),et=i("code"),ei=s("enable_vae_slicing"),ti=s(` was previously invoked, this method will go back to
computing decoding in one step.`),ni=f(),I=i("div"),x(xe.$$.fragment),ii=f(),tt=i("p"),oi=s("Enable memory efficient attention as implemented in xformers."),ai=f(),nt=i("p"),si=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.`),ri=f(),it=i("p"),li=s(`Warning: When Memory Efficient Attention and Sliced attention are both enabled, the Memory Efficient Attention
is used.`),fi=f(),x(W.$$.fragment),di=f(),B=i("div"),x(De.$$.fragment),pi=f(),ot=i("p"),ci=s("Disable memory efficient attention as implemented in xformers."),ui=f(),K=i("div"),x(Pe.$$.fragment),mi=f(),Ee=i("p"),hi=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
`),at=i("code"),gi=s("torch.device('meta') and loaded to GPU only when their specific submodule has its "),_i=s("forward` method called."),this.h()},l(n){const m=mo('[data-svelte="svelte-1phssyn"]',document.head);h=o(m,"META",{name:!0,content:!0}),m.forEach(t),A=d(n),b=o(n,"H1",{class:!0});var Se=a(b);u=o(Se,"A",{id:!0,class:!0,href:!0});var st=a(u);$=o(st,"SPAN",{});var bi=a($);D(p.$$.fragment,bi),bi.forEach(t),st.forEach(t),v=d(Se),je=o(Se,"SPAN",{});var vi=a(je);Lt=r(vi,"Text-to-Image Generation"),vi.forEach(t),Se.forEach(t),rt=d(n),O=o(n,"H2",{class:!0});var ht=a(O);q=o(ht,"A",{id:!0,class:!0,href:!0});var yi=a(q);Oe=o(yi,"SPAN",{});var wi=a(Oe);D(H.$$.fragment,wi),wi.forEach(t),yi.forEach(t),Mt=d(ht),Ve=o(ht,"SPAN",{});var $i=a(Ve);Nt=r($i,"StableDiffusionPipeline"),$i.forEach(t),ht.forEach(t),lt=d(n),y=o(n,"P",{});var C=a(y);jt=r(C,"The Stable Diffusion model was created by the researchers and engineers from "),J=o(C,"A",{href:!0,rel:!0});var xi=a(J);Ot=r(xi,"CompVis"),xi.forEach(t),Vt=r(C,", "),R=o(C,"A",{href:!0,rel:!0});var Di=a(R);qt=r(Di,"Stability AI"),Di.forEach(t),Ft=r(C,", "),Q=o(C,"A",{href:!0,rel:!0});var Pi=a(Q);zt=r(Pi,"runway"),Pi.forEach(t),Ut=r(C,", and "),X=o(C,"A",{href:!0,rel:!0});var Ei=a(X);Gt=r(Ei,"LAION"),Ei.forEach(t),Wt=r(C,". The "),Ie=o(C,"A",{href:!0});var Si=a(Ie);Bt=r(Si,"StableDiffusionPipeline"),Si.forEach(t),Kt=r(C," is capable of generating photo-realistic images given any text input using Stable Diffusion."),C.forEach(t),ft=d(n),Ae=o(n,"P",{});var ki=a(Ae);Ht=r(ki,"The original codebase can be found here:"),ki.forEach(t),dt=d(n),F=o(n,"UL",{});var gt=a(F);Y=o(gt,"LI",{});var _t=a(Y);qe=o(_t,"EM",{});var Ii=a(qe);Jt=r(Ii,"Stable Diffusion V1"),Ii.forEach(t),Rt=r(_t,": "),Z=o(_t,"A",{href:!0,rel:!0});var Ai=a(Z);Qt=r(Ai,"CampVis/stable-diffusion"),Ai.forEach(t),_t.forEach(t),Xt=d(gt),ee=o(gt,"LI",{});var bt=a(ee);Fe=o(bt,"EM",{});var Ci=a(Fe);Yt=r(Ci,"Stable Diffusion v2"),Ci.forEach(t),Zt=r(bt,": "),te=o(bt,"A",{href:!0,rel:!0});var Ti=a(te);en=r(Ti,"Stability-AI/stablediffusion"),Ti.forEach(t),bt.forEach(t),gt.forEach(t),pt=d(n),Ce=o(n,"P",{});var Li=a(Ce);tn=r(Li,"Available Checkpoints are:"),Li.forEach(t),ct=d(n),w=o(n,"UL",{});var T=a(w);ne=o(T,"LI",{});var vt=a(ne);ze=o(vt,"EM",{});var Mi=a(ze);nn=r(Mi,"stable-diffusion-v1-4 (512x512 resolution)"),Mi.forEach(t),on=d(vt),ie=o(vt,"A",{href:!0,rel:!0});var Ni=a(ie);an=r(Ni,"CompVis/stable-diffusion-v1-4"),Ni.forEach(t),vt.forEach(t),sn=d(T),oe=o(T,"LI",{});var yt=a(oe);Ue=o(yt,"EM",{});var ji=a(Ue);rn=r(ji,"stable-diffusion-v1-5 (512x512 resolution)"),ji.forEach(t),ln=d(yt),ae=o(yt,"A",{href:!0,rel:!0});var Oi=a(ae);fn=r(Oi,"runwayml/stable-diffusion-v1-5"),Oi.forEach(t),yt.forEach(t),dn=d(T),se=o(T,"LI",{});var wt=a(se);Ge=o(wt,"EM",{});var Vi=a(Ge);pn=r(Vi,"stable-diffusion-2-base (512x512 resolution)"),Vi.forEach(t),cn=r(wt,": "),re=o(wt,"A",{href:!0,rel:!0});var qi=a(re);un=r(qi,"stabilityai/stable-diffusion-2-base"),qi.forEach(t),wt.forEach(t),mn=d(T),le=o(T,"LI",{});var $t=a(le);We=o($t,"EM",{});var Fi=a(We);hn=r(Fi,"stable-diffusion-2 (768x768 resolution)"),Fi.forEach(t),gn=r($t,": "),fe=o($t,"A",{href:!0,rel:!0});var zi=a(fe);_n=r(zi,"stabilityai/stable-diffusion-2"),zi.forEach(t),$t.forEach(t),bn=d(T),de=o(T,"LI",{});var xt=a(de);Be=o(xt,"EM",{});var Ui=a(Be);vn=r(Ui,"stable-diffusion-2-1-base (512x512 resolution)"),Ui.forEach(t),yn=d(xt),pe=o(xt,"A",{href:!0,rel:!0});var Gi=a(pe);wn=r(Gi,"stabilityai/stable-diffusion-2-1-base"),Gi.forEach(t),xt.forEach(t),$n=d(T),ce=o(T,"LI",{});var Dt=a(ce);Ke=o(Dt,"EM",{});var Wi=a(Ke);xn=r(Wi,"stable-diffusion-2-1 (768x768 resolution)"),Wi.forEach(t),Dn=r(Dt,": "),ue=o(Dt,"A",{href:!0,rel:!0});var Bi=a(ue);Pn=r(Bi,"stabilityai/stable-diffusion-2-1"),Bi.forEach(t),Dt.forEach(t),T.forEach(t),ut=d(n),c=o(n,"DIV",{class:!0});var g=a(c);D(me.$$.fragment,g),En=d(g),He=o(g,"P",{});var Ki=a(He);Sn=r(Ki,"Pipeline for text-to-image generation using Stable Diffusion."),Ki.forEach(t),kn=d(g),he=o(g,"P",{});var Pt=a(he);In=r(Pt,"This model inherits from "),Te=o(Pt,"A",{href:!0});var Hi=a(Te);An=r(Hi,"DiffusionPipeline"),Hi.forEach(t),Cn=r(Pt,`. 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.)`),Pt.forEach(t),Tn=d(g),L=o(g,"DIV",{class:!0});var Le=a(L);D(ge.$$.fragment,Le),Ln=d(Le),Je=o(Le,"P",{});var Ji=a(Je);Mn=r(Ji,"Function invoked when calling the pipeline for generation."),Ji.forEach(t),Nn=d(Le),D(z.$$.fragment,Le),Le.forEach(t),jn=d(g),M=o(g,"DIV",{class:!0});var Me=a(M);D(_e.$$.fragment,Me),On=d(Me),Re=o(Me,"P",{});var Ri=a(Re);Vn=r(Ri,"Enable sliced attention computation."),Ri.forEach(t),qn=d(Me),Qe=o(Me,"P",{});var Qi=a(Qe);Fn=r(Qi,`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.`),Qi.forEach(t),Me.forEach(t),zn=d(g),U=o(g,"DIV",{class:!0});var Et=a(U);D(be.$$.fragment,Et),Un=d(Et),ve=o(Et,"P",{});var St=a(ve);Gn=r(St,"Disable sliced attention computation. If "),Xe=o(St,"CODE",{});var Xi=a(Xe);Wn=r(Xi,"enable_attention_slicing"),Xi.forEach(t),Bn=r(St,` was previously invoked, this method will go
back to computing attention in one step.`),St.forEach(t),Et.forEach(t),Kn=d(g),N=o(g,"DIV",{class:!0});var Ne=a(N);D(ye.$$.fragment,Ne),Hn=d(Ne),Ye=o(Ne,"P",{});var Yi=a(Ye);Jn=r(Yi,"Enable sliced VAE decoding."),Yi.forEach(t),Rn=d(Ne),Ze=o(Ne,"P",{});var Zi=a(Ze);Qn=r(Zi,`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.`),Zi.forEach(t),Ne.forEach(t),Xn=d(g),G=o(g,"DIV",{class:!0});var kt=a(G);D(we.$$.fragment,kt),Yn=d(kt),$e=o(kt,"P",{});var It=a($e);Zn=r(It,"Disable sliced VAE decoding. If "),et=o(It,"CODE",{});var eo=a(et);ei=r(eo,"enable_vae_slicing"),eo.forEach(t),ti=r(It,` was previously invoked, this method will go back to
computing decoding in one step.`),It.forEach(t),kt.forEach(t),ni=d(g),I=o(g,"DIV",{class:!0});var j=a(I);D(xe.$$.fragment,j),ii=d(j),tt=o(j,"P",{});var to=a(tt);oi=r(to,"Enable memory efficient attention as implemented in xformers."),to.forEach(t),ai=d(j),nt=o(j,"P",{});var no=a(nt);si=r(no,`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.`),no.forEach(t),ri=d(j),it=o(j,"P",{});var io=a(it);li=r(io,`Warning: When Memory Efficient Attention and Sliced attention are both enabled, the Memory Efficient Attention
is used.`),io.forEach(t),fi=d(j),D(W.$$.fragment,j),j.forEach(t),di=d(g),B=o(g,"DIV",{class:!0});var At=a(B);D(De.$$.fragment,At),pi=d(At),ot=o(At,"P",{});var oo=a(ot);ci=r(oo,"Disable memory efficient attention as implemented in xformers."),oo.forEach(t),At.forEach(t),ui=d(g),K=o(g,"DIV",{class:!0});var Ct=a(K);D(Pe.$$.fragment,Ct),mi=d(Ct),Ee=o(Ct,"P",{});var Tt=a(Ee);hi=r(Tt,`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
`),at=o(Tt,"CODE",{});var ao=a(at);gi=r(ao,"torch.device('meta') and loaded to GPU only when their specific submodule has its "),ao.forEach(t),_i=r(Tt,"forward` method called."),Tt.forEach(t),Ct.forEach(t),g.forEach(t),this.h()},h(){l(h,"name","hf:doc:metadata"),l(h,"content",JSON.stringify(vo)),l(u,"id","texttoimage-generation"),l(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"),l(u,"href","#texttoimage-generation"),l(b,"class","relative group"),l(q,"id","diffusers.StableDiffusionPipeline"),l(q,"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(q,"href","#diffusers.StableDiffusionPipeline"),l(O,"class","relative group"),l(J,"href","https://github.com/CompVis"),l(J,"rel","nofollow"),l(R,"href","https://stability.ai/"),l(R,"rel","nofollow"),l(Q,"href","https://github.com/runwayml"),l(Q,"rel","nofollow"),l(X,"href","https://laion.ai/"),l(X,"rel","nofollow"),l(Ie,"href","/docs/diffusers/v0.12.0/en/api/pipelines/stable_diffusion/text2img#diffusers.StableDiffusionPipeline"),l(Z,"href","https://github.com/CompVis/stable-diffusion"),l(Z,"rel","nofollow"),l(te,"href","https://github.com/Stability-AI/stablediffusion"),l(te,"rel","nofollow"),l(ie,"href","https://huggingface.co/CompVis/stable-diffusion-v1-4"),l(ie,"rel","nofollow"),l(ae,"href","https://huggingface.co/runwayml/stable-diffusion-v1-5"),l(ae,"rel","nofollow"),l(re,"href","https://huggingface.co/stabilityai/stable-diffusion-2-base"),l(re,"rel","nofollow"),l(fe,"href","https://huggingface.co/stabilityai/stable-diffusion-2"),l(fe,"rel","nofollow"),l(pe,"href","https://huggingface.co/stabilityai/stable-diffusion-2-1-base"),l(pe,"rel","nofollow"),l(ue,"href","https://huggingface.co/stabilityai/stable-diffusion-2-1"),l(ue,"rel","nofollow"),l(Te,"href","/docs/diffusers/v0.12.0/en/api/diffusion_pipeline#diffusers.DiffusionPipeline"),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(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(U,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(N,"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(I,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(B,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(K,"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(n,m){e(document.head,h),_(n,A,m),_(n,b,m),e(b,u),e(u,$),P(p,$,null),e(b,v),e(b,je),e(je,Lt),_(n,rt,m),_(n,O,m),e(O,q),e(q,Oe),P(H,Oe,null),e(O,Mt),e(O,Ve),e(Ve,Nt),_(n,lt,m),_(n,y,m),e(y,jt),e(y,J),e(J,Ot),e(y,Vt),e(y,R),e(R,qt),e(y,Ft),e(y,Q),e(Q,zt),e(y,Ut),e(y,X),e(X,Gt),e(y,Wt),e(y,Ie),e(Ie,Bt),e(y,Kt),_(n,ft,m),_(n,Ae,m),e(Ae,Ht),_(n,dt,m),_(n,F,m),e(F,Y),e(Y,qe),e(qe,Jt),e(Y,Rt),e(Y,Z),e(Z,Qt),e(F,Xt),e(F,ee),e(ee,Fe),e(Fe,Yt),e(ee,Zt),e(ee,te),e(te,en),_(n,pt,m),_(n,Ce,m),e(Ce,tn),_(n,ct,m),_(n,w,m),e(w,ne),e(ne,ze),e(ze,nn),e(ne,on),e(ne,ie),e(ie,an),e(w,sn),e(w,oe),e(oe,Ue),e(Ue,rn),e(oe,ln),e(oe,ae),e(ae,fn),e(w,dn),e(w,se),e(se,Ge),e(Ge,pn),e(se,cn),e(se,re),e(re,un),e(w,mn),e(w,le),e(le,We),e(We,hn),e(le,gn),e(le,fe),e(fe,_n),e(w,bn),e(w,de),e(de,Be),e(Be,vn),e(de,yn),e(de,pe),e(pe,wn),e(w,$n),e(w,ce),e(ce,Ke),e(Ke,xn),e(ce,Dn),e(ce,ue),e(ue,Pn),_(n,ut,m),_(n,c,m),P(me,c,null),e(c,En),e(c,He),e(He,Sn),e(c,kn),e(c,he),e(he,In),e(he,Te),e(Te,An),e(he,Cn),e(c,Tn),e(c,L),P(ge,L,null),e(L,Ln),e(L,Je),e(Je,Mn),e(L,Nn),P(z,L,null),e(c,jn),e(c,M),P(_e,M,null),e(M,On),e(M,Re),e(Re,Vn),e(M,qn),e(M,Qe),e(Qe,Fn),e(c,zn),e(c,U),P(be,U,null),e(U,Un),e(U,ve),e(ve,Gn),e(ve,Xe),e(Xe,Wn),e(ve,Bn),e(c,Kn),e(c,N),P(ye,N,null),e(N,Hn),e(N,Ye),e(Ye,Jn),e(N,Rn),e(N,Ze),e(Ze,Qn),e(c,Xn),e(c,G),P(we,G,null),e(G,Yn),e(G,$e),e($e,Zn),e($e,et),e(et,ei),e($e,ti),e(c,ni),e(c,I),P(xe,I,null),e(I,ii),e(I,tt),e(tt,oi),e(I,ai),e(I,nt),e(nt,si),e(I,ri),e(I,it),e(it,li),e(I,fi),P(W,I,null),e(c,di),e(c,B),P(De,B,null),e(B,pi),e(B,ot),e(ot,ci),e(c,ui),e(c,K),P(Pe,K,null),e(K,mi),e(K,Ee),e(Ee,hi),e(Ee,at),e(at,gi),e(Ee,_i),mt=!0},p(n,[m]){const Se={};m&2&&(Se.$$scope={dirty:m,ctx:n}),z.$set(Se);const st={};m&2&&(st.$$scope={dirty:m,ctx:n}),W.$set(st)},i(n){mt||(E(p.$$.fragment,n),E(H.$$.fragment,n),E(me.$$.fragment,n),E(ge.$$.fragment,n),E(z.$$.fragment,n),E(_e.$$.fragment,n),E(be.$$.fragment,n),E(ye.$$.fragment,n),E(we.$$.fragment,n),E(xe.$$.fragment,n),E(W.$$.fragment,n),E(De.$$.fragment,n),E(Pe.$$.fragment,n),mt=!0)},o(n){S(p.$$.fragment,n),S(H.$$.fragment,n),S(me.$$.fragment,n),S(ge.$$.fragment,n),S(z.$$.fragment,n),S(_e.$$.fragment,n),S(be.$$.fragment,n),S(ye.$$.fragment,n),S(we.$$.fragment,n),S(xe.$$.fragment,n),S(W.$$.fragment,n),S(De.$$.fragment,n),S(Pe.$$.fragment,n),mt=!1},d(n){t(h),n&&t(A),n&&t(b),k(p),n&&t(rt),n&&t(O),k(H),n&&t(lt),n&&t(y),n&&t(ft),n&&t(Ae),n&&t(dt),n&&t(F),n&&t(pt),n&&t(Ce),n&&t(ct),n&&t(w),n&&t(ut),n&&t(c),k(me),k(ge),k(z),k(_e),k(be),k(ye),k(we),k(xe),k(W),k(De),k(Pe)}}}const vo={local:"texttoimage-generation",sections:[{local:"diffusers.StableDiffusionPipeline",title:"StableDiffusionPipeline"}],title:"Text-to-Image Generation"};function yo(ke){return ho(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Eo extends po{constructor(h){super();co(this,h,yo,bo,uo,{})}}export{Eo as default,vo as metadata};
