import{S as Xt,i as en,s as tn,e as o,k as f,w as P,t as r,M as nn,c as i,d as n,m as u,a as s,x as A,h as l,b as a,G as t,g as m,y as $,q as x,o as G,B as T,v as on,L as sn}from"../../../chunks/vendor-hf-doc-builder.js";import{T as an}from"../../../chunks/Tip-hf-doc-builder.js";import{D as fe}from"../../../chunks/Docstring-hf-doc-builder.js";import{C as rn}from"../../../chunks/CodeBlock-hf-doc-builder.js";import{I as Tt}from"../../../chunks/IconCopyLink-hf-doc-builder.js";import{E as ln}from"../../../chunks/ExampleCodeBlock-hf-doc-builder.js";function dn(re){let p,D,h,g,b,d,v,C;return{c(){p=o("p"),D=r("Make sure to check out the Schedulers "),h=o("a"),g=r("guide"),b=r(" to learn how to explore the tradeoff between scheduler speed and quality, and see the "),d=o("a"),v=r("reuse components across pipelines"),C=r(" section to learn how to efficiently load the same components into multiple pipelines."),this.h()},l(L){p=i(L,"P",{});var w=s(p);D=l(w,"Make sure to check out the Schedulers "),h=i(w,"A",{href:!0});var k=s(h);g=l(k,"guide"),k.forEach(n),b=l(w," to learn how to explore the tradeoff between scheduler speed and quality, and see the "),d=i(w,"A",{href:!0});var I=s(d);v=l(I,"reuse components across pipelines"),I.forEach(n),C=l(w," section to learn how to efficiently load the same components into multiple pipelines."),w.forEach(n),this.h()},h(){a(h,"href","/using-diffusers/schedulers"),a(d,"href","/using-diffusers/loading#reuse-components-across-pipelines")},m(L,w){m(L,p,w),t(p,D),t(p,h),t(h,g),t(p,b),t(p,d),t(d,v),t(p,C)},d(L){L&&n(p)}}}function cn(re){let p,D,h,g,b;return g=new rn({props:{code:"aW1wb3J0JTIwdG9yY2glMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwU3RhYmxlRGlmZnVzaW9uU0FHUGlwZWxpbmUlMEElMEFwaXBlJTIwJTNEJTIwU3RhYmxlRGlmZnVzaW9uU0FHUGlwZWxpbmUuZnJvbV9wcmV0cmFpbmVkKCUwQSUyMCUyMCUyMCUyMCUyMnJ1bndheW1sJTJGc3RhYmxlLWRpZmZ1c2lvbi12MS01JTIyJTJDJTIwdG9yY2hfZHR5cGUlM0R0b3JjaC5mbG9hdDE2JTBBKSUwQXBpcGUlMjAlM0QlMjBwaXBlLnRvKCUyMmN1ZGElMjIpJTBBJTBBcHJvbXB0JTIwJTNEJTIwJTIyYSUyMHBob3RvJTIwb2YlMjBhbiUyMGFzdHJvbmF1dCUyMHJpZGluZyUyMGElMjBob3JzZSUyMG9uJTIwbWFycyUyMiUwQWltYWdlJTIwJTNEJTIwcGlwZShwcm9tcHQlMkMlMjBzYWdfc2NhbGUlM0QwLjc1KS5pbWFnZXMlNUIwJTVE",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> StableDiffusionSAGPipeline

<span class="hljs-meta">&gt;&gt;&gt; </span>pipe = StableDiffusionSAGPipeline.from_pretrained(
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;runwayml/stable-diffusion-v1-5&quot;</span>, torch_dtype=torch.float16
<span class="hljs-meta">... </span>)
<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, sag_scale=<span class="hljs-number">0.75</span>).images[<span class="hljs-number">0</span>]`}}),{c(){p=o("p"),D=r("Examples:"),h=f(),P(g.$$.fragment)},l(d){p=i(d,"P",{});var v=s(p);D=l(v,"Examples:"),v.forEach(n),h=u(d),A(g.$$.fragment,d)},m(d,v){m(d,p,v),t(p,D),m(d,h,v),$(g,d,v),b=!0},p:sn,i(d){b||(x(g.$$.fragment,d),b=!0)},o(d){G(g.$$.fragment,d),b=!1},d(d){d&&n(p),d&&n(h),T(g,d)}}}function pn(re){let p,D,h,g,b,d,v,C,L,w,k,I,qe,Fe,Ae,le,Ve,$e,de,ue,Be,xe,S,Ze,Z,We,He,W,Re,Ye,H,Ke,Qe,R,Xe,et,Ge,O,Te,U,j,me,Y,tt,he,nt,ke,_,K,ot,ge,it,st,Q,at,ce,rt,lt,dt,E,X,ct,_e,pt,ft,z,ut,q,ee,mt,te,ht,be,gt,_t,bt,F,ne,vt,ve,St,yt,V,oe,wt,Se,Dt,Ie,N,B,ye,ie,Pt,we,At,Ee,J,se,$t,De,xt,Me;return d=new Tt({}),O=new an({props:{$$slots:{default:[dn]},$$scope:{ctx:re}}}),Y=new Tt({}),K=new fe({props:{name:"class diffusers.StableDiffusionSAGPipeline",anchor:"diffusers.StableDiffusionSAGPipeline",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:": CLIPImageProcessor"},{name:"requires_safety_checker",val:": bool = True"}],parametersDescription:[{anchor:"diffusers.StableDiffusionSAGPipeline.vae",description:`<strong>vae</strong> (<a href="/docs/diffusers/main/en/api/models/autoencoderkl#diffusers.AutoencoderKL">AutoencoderKL</a>) &#x2014;
Variational Auto-Encoder (VAE) model to encode and decode images to and from latent representations.`,name:"vae"},{anchor:"diffusers.StableDiffusionSAGPipeline.text_encoder",description:`<strong>text_encoder</strong> (<a href="https://huggingface.co/docs/transformers/main/en/model_doc/clip#transformers.CLIPTextModel" rel="nofollow">CLIPTextModel</a>) &#x2014;
Frozen text-encoder (<a href="https://huggingface.co/openai/clip-vit-large-patch14" rel="nofollow">clip-vit-large-patch14</a>).`,name:"text_encoder"},{anchor:"diffusers.StableDiffusionSAGPipeline.tokenizer",description:`<strong>tokenizer</strong> (<a href="https://huggingface.co/docs/transformers/main/en/model_doc/clip#transformers.CLIPTokenizer" rel="nofollow">CLIPTokenizer</a>) &#x2014;
A <code>CLIPTokenizer</code> to tokenize text.`,name:"tokenizer"},{anchor:"diffusers.StableDiffusionSAGPipeline.unet",description:`<strong>unet</strong> (<a href="/docs/diffusers/main/en/api/models/unet2d-cond#diffusers.UNet2DConditionModel">UNet2DConditionModel</a>) &#x2014;
A <code>UNet2DConditionModel</code> to denoise the encoded image latents.`,name:"unet"},{anchor:"diffusers.StableDiffusionSAGPipeline.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.StableDiffusionSAGPipeline.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 more details
about a model&#x2019;s potential harms.`,name:"safety_checker"},{anchor:"diffusers.StableDiffusionSAGPipeline.feature_extractor",description:`<strong>feature_extractor</strong> (<a href="https://huggingface.co/docs/transformers/main/en/model_doc/clip#transformers.CLIPImageProcessor" rel="nofollow">CLIPImageProcessor</a>) &#x2014;
A <code>CLIPImageProcessor</code> to extract features from generated images; used as inputs to the <code>safety_checker</code>.`,name:"feature_extractor"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_sag.py#L93"}}),X=new fe({props:{name:"__call__",anchor:"diffusers.StableDiffusionSAGPipeline.__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:"sag_scale",val:": float = 0.75"},{name:"negative_prompt",val:": typing.Union[typing.List[str], 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"},{name:"cross_attention_kwargs",val:": typing.Union[typing.Dict[str, typing.Any], NoneType] = None"}],parametersDescription:[{anchor:"diffusers.StableDiffusionSAGPipeline.__call__.prompt",description:`<strong>prompt</strong> (<code>str</code> or <code>List[str]</code>, <em>optional</em>) &#x2014;
The prompt or prompts to guide image generation. If not defined, you need to pass <code>prompt_embeds</code>.`,name:"prompt"},{anchor:"diffusers.StableDiffusionSAGPipeline.__call__.height",description:`<strong>height</strong> (<code>int</code>, <em>optional</em>, defaults to <code>self.unet.config.sample_size * self.vae_scale_factor</code>) &#x2014;
The height in pixels of the generated image.`,name:"height"},{anchor:"diffusers.StableDiffusionSAGPipeline.__call__.width",description:`<strong>width</strong> (<code>int</code>, <em>optional</em>, defaults to <code>self.unet.config.sample_size * self.vae_scale_factor</code>) &#x2014;
The width in pixels of the generated image.`,name:"width"},{anchor:"diffusers.StableDiffusionSAGPipeline.__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.StableDiffusionSAGPipeline.__call__.guidance_scale",description:`<strong>guidance_scale</strong> (<code>float</code>, <em>optional</em>, defaults to 7.5) &#x2014;
A higher guidance scale value encourages the model to generate images closely linked to the text
<code>prompt</code> at the expense of lower image quality. Guidance scale is enabled when <code>guidance_scale &gt; 1</code>.`,name:"guidance_scale"},{anchor:"diffusers.StableDiffusionSAGPipeline.__call__.sag_scale",description:`<strong>sag_scale</strong> (<code>float</code>, <em>optional</em>, defaults to 0.75) &#x2014;
Chosen between [0, 1.0] for better quality.`,name:"sag_scale"},{anchor:"diffusers.StableDiffusionSAGPipeline.__call__.negative_prompt",description:`<strong>negative_prompt</strong> (<code>str</code> or <code>List[str]</code>, <em>optional</em>) &#x2014;
The prompt or prompts to guide what to not include in image generation. If not defined, you need to
pass <code>negative_prompt_embeds</code> instead. Ignored when not using guidance (<code>guidance_scale &lt; 1</code>).`,name:"negative_prompt"},{anchor:"diffusers.StableDiffusionSAGPipeline.__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.StableDiffusionSAGPipeline.__call__.eta",description:`<strong>eta</strong> (<code>float</code>, <em>optional</em>, defaults to 0.0) &#x2014;
Corresponds to parameter eta (&#x3B7;) from the <a href="https://arxiv.org/abs/2010.02502" rel="nofollow">DDIM</a> paper. Only applies
to the <a href="/docs/diffusers/main/en/api/schedulers/ddim#diffusers.DDIMScheduler">DDIMScheduler</a>, and is ignored in other schedulers.`,name:"eta"},{anchor:"diffusers.StableDiffusionSAGPipeline.__call__.generator",description:`<strong>generator</strong> (<code>torch.Generator</code> or <code>List[torch.Generator]</code>, <em>optional</em>) &#x2014;
A <a href="https://pytorch.org/docs/stable/generated/torch.Generator.html" rel="nofollow"><code>torch.Generator</code></a> to make
generation deterministic.`,name:"generator"},{anchor:"diffusers.StableDiffusionSAGPipeline.__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 is generated by sampling using the supplied random <code>generator</code>.`,name:"latents"},{anchor:"diffusers.StableDiffusionSAGPipeline.__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 (prompt weighting). If not
provided, text embeddings are generated from the <code>prompt</code> input argument.`,name:"prompt_embeds"},{anchor:"diffusers.StableDiffusionSAGPipeline.__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 (prompt weighting). If
not provided, <code>negative_prompt_embeds</code> are generated from the <code>negative_prompt</code> input argument.`,name:"negative_prompt_embeds"},{anchor:"diffusers.StableDiffusionSAGPipeline.__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 generated image. Choose between <code>PIL.Image</code> or <code>np.array</code>.`,name:"output_type"},{anchor:"diffusers.StableDiffusionSAGPipeline.__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/img2img#diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput">StableDiffusionPipelineOutput</a> instead of a
plain tuple.`,name:"return_dict"},{anchor:"diffusers.StableDiffusionSAGPipeline.__call__.callback",description:`<strong>callback</strong> (<code>Callable</code>, <em>optional</em>) &#x2014;
A function that calls every <code>callback_steps</code> steps during inference. The function is called with the
following arguments: <code>callback(step: int, timestep: int, latents: torch.FloatTensor)</code>.`,name:"callback"},{anchor:"diffusers.StableDiffusionSAGPipeline.__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 is called. If not specified, the callback is called at
every step.`,name:"callback_steps"},{anchor:"diffusers.StableDiffusionSAGPipeline.__call__.cross_attention_kwargs",description:`<strong>cross_attention_kwargs</strong> (<code>dict</code>, <em>optional</em>) &#x2014;
A kwargs dictionary that if specified is passed along to the <code>AttentionProcessor</code> as defined in
<a href="https://github.com/huggingface/diffusers/blob/main/src/diffusers/models/attention_processor.py" rel="nofollow"><code>self.processor</code></a>.`,name:"cross_attention_kwargs"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_sag.py#L464",returnDescription:`
<p>If <code>return_dict</code> is <code>True</code>, <a
  href="/docs/diffusers/main/en/api/pipelines/stable_diffusion/img2img#diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput"
>StableDiffusionPipelineOutput</a> is returned,
otherwise a <code>tuple</code> is returned where the first element is a list with the generated images and the
second element is a list of <code>bool</code>s indicating whether the corresponding generated image contains
\u201Cnot-safe-for-work\u201D (nsfw) content.</p>
`,returnType:`
<p><a
  href="/docs/diffusers/main/en/api/pipelines/stable_diffusion/img2img#diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput"
>StableDiffusionPipelineOutput</a> or <code>tuple</code></p>
`}}),z=new ln({props:{anchor:"diffusers.StableDiffusionSAGPipeline.__call__.example",$$slots:{default:[cn]},$$scope:{ctx:re}}}),ee=new fe({props:{name:"disable_vae_slicing",anchor:"diffusers.StableDiffusionSAGPipeline.disable_vae_slicing",parameters:[],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_sag.py#L156"}}),ne=new fe({props:{name:"enable_vae_slicing",anchor:"diffusers.StableDiffusionSAGPipeline.enable_vae_slicing",parameters:[],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_sag.py#L148"}}),oe=new fe({props:{name:"encode_prompt",anchor:"diffusers.StableDiffusionSAGPipeline.encode_prompt",parameters:[{name:"prompt",val:""},{name:"device",val:""},{name:"num_images_per_prompt",val:""},{name:"do_classifier_free_guidance",val:""},{name:"negative_prompt",val:" = None"},{name:"prompt_embeds",val:": typing.Optional[torch.FloatTensor] = None"},{name:"negative_prompt_embeds",val:": typing.Optional[torch.FloatTensor] = None"},{name:"lora_scale",val:": typing.Optional[float] = None"}],parametersDescription:[{anchor:"diffusers.StableDiffusionSAGPipeline.encode_prompt.prompt",description:`<strong>prompt</strong> (<code>str</code> or <code>List[str]</code>, <em>optional</em>) &#x2014;
prompt to be encoded
device &#x2014; (<code>torch.device</code>):
torch device`,name:"prompt"},{anchor:"diffusers.StableDiffusionSAGPipeline.encode_prompt.num_images_per_prompt",description:`<strong>num_images_per_prompt</strong> (<code>int</code>) &#x2014;
number of images that should be generated per prompt`,name:"num_images_per_prompt"},{anchor:"diffusers.StableDiffusionSAGPipeline.encode_prompt.do_classifier_free_guidance",description:`<strong>do_classifier_free_guidance</strong> (<code>bool</code>) &#x2014;
whether to use classifier free guidance or not`,name:"do_classifier_free_guidance"},{anchor:"diffusers.StableDiffusionSAGPipeline.encode_prompt.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. Ignored when not using guidance (i.e., ignored if <code>guidance_scale</code> is
less than <code>1</code>).`,name:"negative_prompt"},{anchor:"diffusers.StableDiffusionSAGPipeline.encode_prompt.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.StableDiffusionSAGPipeline.encode_prompt.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.StableDiffusionSAGPipeline.encode_prompt.lora_scale",description:`<strong>lora_scale</strong> (<code>float</code>, <em>optional</em>) &#x2014;
A lora scale that will be applied to all LoRA layers of the text encoder if LoRA layers are loaded.`,name:"lora_scale"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_sag.py#L195"}}),ie=new Tt({}),se=new fe({props:{name:"class diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput",anchor:"diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput",parameters:[{name:"images",val:": typing.Union[typing.List[PIL.Image.Image], numpy.ndarray]"},{name:"nsfw_content_detected",val:": typing.Optional[typing.List[bool]]"}],parametersDescription:[{anchor:"diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput.images",description:`<strong>images</strong> (<code>List[PIL.Image.Image]</code> or <code>np.ndarray</code>) &#x2014;
List of denoised PIL images of length <code>batch_size</code> or NumPy array of shape <code>(batch_size, height, width, num_channels)</code>.`,name:"images"},{anchor:"diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput.nsfw_content_detected",description:`<strong>nsfw_content_detected</strong> (<code>List[bool]</code>) &#x2014;
List indicating whether the corresponding generated image contains &#x201C;not-safe-for-work&#x201D; (nsfw) content or
<code>None</code> if safety checking could not be performed.`,name:"nsfw_content_detected"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/stable_diffusion/__init__.py#L22"}}),{c(){p=o("meta"),D=f(),h=o("h1"),g=o("a"),b=o("span"),P(d.$$.fragment),v=f(),C=o("span"),L=r("Self-Attention Guidance"),w=f(),k=o("p"),I=o("a"),qe=r("Improving Sample Quality of Diffusion Models Using Self-Attention Guidance"),Fe=r(" is by Susung Hong et al."),Ae=f(),le=o("p"),Ve=r("The abstract from the paper is:"),$e=f(),de=o("p"),ue=o("em"),Be=r("Denoising diffusion models (DDMs) have attracted attention for their exceptional generation quality and diversity. This success is largely attributed to the use of class- or text-conditional diffusion guidance methods, such as classifier and classifier-free guidance. In this paper, we present a more comprehensive perspective that goes beyond the traditional guidance methods. From this generalized perspective, we introduce novel condition- and training-free strategies to enhance the quality of generated images. As a simple solution, blur guidance improves the suitability of intermediate samples for their fine-scale information and structures, enabling diffusion models to generate higher quality samples with a moderate guidance scale. Improving upon this, Self-Attention Guidance (SAG) uses the intermediate self-attention maps of diffusion models to enhance their stability and efficacy. Specifically, SAG adversarially blurs only the regions that diffusion models attend to at each iteration and guides them accordingly. Our experimental results show that our SAG improves the performance of various diffusion models, including ADM, IDDPM, Stable Diffusion, and DiT. Moreover, combining SAG with conventional guidance methods leads to further improvement."),xe=f(),S=o("p"),Ze=r("You can find additional information about Self-Attention Guidance on the "),Z=o("a"),We=r("project page"),He=r(", "),W=o("a"),Re=r("original codebase"),Ye=r(", and try it out in a "),H=o("a"),Ke=r("demo"),Qe=r(" or "),R=o("a"),Xe=r("notebook"),et=r("."),Ge=f(),P(O.$$.fragment),Te=f(),U=o("h2"),j=o("a"),me=o("span"),P(Y.$$.fragment),tt=f(),he=o("span"),nt=r("StableDiffusionSAGPipeline"),ke=f(),_=o("div"),P(K.$$.fragment),ot=f(),ge=o("p"),it=r("Pipeline for text-to-image generation using Stable Diffusion."),st=f(),Q=o("p"),at=r("This model inherits from "),ce=o("a"),rt=r("DiffusionPipeline"),lt=r(`. Check the superclass documentation for the generic methods
implemented for all pipelines (downloading, saving, running on a particular device, etc.).`),dt=f(),E=o("div"),P(X.$$.fragment),ct=f(),_e=o("p"),pt=r("The call function to the pipeline for generation."),ft=f(),P(z.$$.fragment),ut=f(),q=o("div"),P(ee.$$.fragment),mt=f(),te=o("p"),ht=r("Disable sliced VAE decoding. If "),be=o("code"),gt=r("enable_vae_slicing"),_t=r(` was previously enabled, this method will go back to
computing decoding in one step.`),bt=f(),F=o("div"),P(ne.$$.fragment),vt=f(),ve=o("p"),St=r(`Enable sliced VAE decoding. 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.`),yt=f(),V=o("div"),P(oe.$$.fragment),wt=f(),Se=o("p"),Dt=r("Encodes the prompt into text encoder hidden states."),Ie=f(),N=o("h2"),B=o("a"),ye=o("span"),P(ie.$$.fragment),Pt=f(),we=o("span"),At=r("StableDiffusionOutput"),Ee=f(),J=o("div"),P(se.$$.fragment),$t=f(),De=o("p"),xt=r("Output class for Stable Diffusion pipelines."),this.h()},l(e){const c=nn('[data-svelte="svelte-1phssyn"]',document.head);p=i(c,"META",{name:!0,content:!0}),c.forEach(n),D=u(e),h=i(e,"H1",{class:!0});var ae=s(h);g=i(ae,"A",{id:!0,class:!0,href:!0});var Pe=s(g);b=i(Pe,"SPAN",{});var kt=s(b);A(d.$$.fragment,kt),kt.forEach(n),Pe.forEach(n),v=u(ae),C=i(ae,"SPAN",{});var It=s(C);L=l(It,"Self-Attention Guidance"),It.forEach(n),ae.forEach(n),w=u(e),k=i(e,"P",{});var Gt=s(k);I=i(Gt,"A",{href:!0,rel:!0});var Et=s(I);qe=l(Et,"Improving Sample Quality of Diffusion Models Using Self-Attention Guidance"),Et.forEach(n),Fe=l(Gt," is by Susung Hong et al."),Gt.forEach(n),Ae=u(e),le=i(e,"P",{});var Mt=s(le);Ve=l(Mt,"The abstract from the paper is:"),Mt.forEach(n),$e=u(e),de=i(e,"P",{});var Ct=s(de);ue=i(Ct,"EM",{});var Lt=s(ue);Be=l(Lt,"Denoising diffusion models (DDMs) have attracted attention for their exceptional generation quality and diversity. This success is largely attributed to the use of class- or text-conditional diffusion guidance methods, such as classifier and classifier-free guidance. In this paper, we present a more comprehensive perspective that goes beyond the traditional guidance methods. From this generalized perspective, we introduce novel condition- and training-free strategies to enhance the quality of generated images. As a simple solution, blur guidance improves the suitability of intermediate samples for their fine-scale information and structures, enabling diffusion models to generate higher quality samples with a moderate guidance scale. Improving upon this, Self-Attention Guidance (SAG) uses the intermediate self-attention maps of diffusion models to enhance their stability and efficacy. Specifically, SAG adversarially blurs only the regions that diffusion models attend to at each iteration and guides them accordingly. Our experimental results show that our SAG improves the performance of various diffusion models, including ADM, IDDPM, Stable Diffusion, and DiT. Moreover, combining SAG with conventional guidance methods leads to further improvement."),Lt.forEach(n),Ct.forEach(n),xe=u(e),S=i(e,"P",{});var M=s(S);Ze=l(M,"You can find additional information about Self-Attention Guidance on the "),Z=i(M,"A",{href:!0,rel:!0});var Ut=s(Z);We=l(Ut,"project page"),Ut.forEach(n),He=l(M,", "),W=i(M,"A",{href:!0,rel:!0});var Nt=s(W);Re=l(Nt,"original codebase"),Nt.forEach(n),Ye=l(M,", and try it out in a "),H=i(M,"A",{href:!0,rel:!0});var Jt=s(H);Ke=l(Jt,"demo"),Jt.forEach(n),Qe=l(M," or "),R=i(M,"A",{href:!0,rel:!0});var Ot=s(R);Xe=l(Ot,"notebook"),Ot.forEach(n),et=l(M,"."),M.forEach(n),Ge=u(e),A(O.$$.fragment,e),Te=u(e),U=i(e,"H2",{class:!0});var Ce=s(U);j=i(Ce,"A",{id:!0,class:!0,href:!0});var jt=s(j);me=i(jt,"SPAN",{});var zt=s(me);A(Y.$$.fragment,zt),zt.forEach(n),jt.forEach(n),tt=u(Ce),he=i(Ce,"SPAN",{});var qt=s(he);nt=l(qt,"StableDiffusionSAGPipeline"),qt.forEach(n),Ce.forEach(n),ke=u(e),_=i(e,"DIV",{class:!0});var y=s(_);A(K.$$.fragment,y),ot=u(y),ge=i(y,"P",{});var Ft=s(ge);it=l(Ft,"Pipeline for text-to-image generation using Stable Diffusion."),Ft.forEach(n),st=u(y),Q=i(y,"P",{});var Le=s(Q);at=l(Le,"This model inherits from "),ce=i(Le,"A",{href:!0});var Vt=s(ce);rt=l(Vt,"DiffusionPipeline"),Vt.forEach(n),lt=l(Le,`. Check the superclass documentation for the generic methods
implemented for all pipelines (downloading, saving, running on a particular device, etc.).`),Le.forEach(n),dt=u(y),E=i(y,"DIV",{class:!0});var pe=s(E);A(X.$$.fragment,pe),ct=u(pe),_e=i(pe,"P",{});var Bt=s(_e);pt=l(Bt,"The call function to the pipeline for generation."),Bt.forEach(n),ft=u(pe),A(z.$$.fragment,pe),pe.forEach(n),ut=u(y),q=i(y,"DIV",{class:!0});var Ue=s(q);A(ee.$$.fragment,Ue),mt=u(Ue),te=i(Ue,"P",{});var Ne=s(te);ht=l(Ne,"Disable sliced VAE decoding. If "),be=i(Ne,"CODE",{});var Zt=s(be);gt=l(Zt,"enable_vae_slicing"),Zt.forEach(n),_t=l(Ne,` was previously enabled, this method will go back to
computing decoding in one step.`),Ne.forEach(n),Ue.forEach(n),bt=u(y),F=i(y,"DIV",{class:!0});var Je=s(F);A(ne.$$.fragment,Je),vt=u(Je),ve=i(Je,"P",{});var Wt=s(ve);St=l(Wt,`Enable sliced VAE decoding. 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.`),Wt.forEach(n),Je.forEach(n),yt=u(y),V=i(y,"DIV",{class:!0});var Oe=s(V);A(oe.$$.fragment,Oe),wt=u(Oe),Se=i(Oe,"P",{});var Ht=s(Se);Dt=l(Ht,"Encodes the prompt into text encoder hidden states."),Ht.forEach(n),Oe.forEach(n),y.forEach(n),Ie=u(e),N=i(e,"H2",{class:!0});var je=s(N);B=i(je,"A",{id:!0,class:!0,href:!0});var Rt=s(B);ye=i(Rt,"SPAN",{});var Yt=s(ye);A(ie.$$.fragment,Yt),Yt.forEach(n),Rt.forEach(n),Pt=u(je),we=i(je,"SPAN",{});var Kt=s(we);At=l(Kt,"StableDiffusionOutput"),Kt.forEach(n),je.forEach(n),Ee=u(e),J=i(e,"DIV",{class:!0});var ze=s(J);A(se.$$.fragment,ze),$t=u(ze),De=i(ze,"P",{});var Qt=s(De);xt=l(Qt,"Output class for Stable Diffusion pipelines."),Qt.forEach(n),ze.forEach(n),this.h()},h(){a(p,"name","hf:doc:metadata"),a(p,"content",JSON.stringify(fn)),a(g,"id","selfattention-guidance"),a(g,"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"),a(g,"href","#selfattention-guidance"),a(h,"class","relative group"),a(I,"href","https://huggingface.co/papers/2210.00939"),a(I,"rel","nofollow"),a(Z,"href","https://ku-cvlab.github.io/Self-Attention-Guidance"),a(Z,"rel","nofollow"),a(W,"href","https://github.com/KU-CVLAB/Self-Attention-Guidance"),a(W,"rel","nofollow"),a(H,"href","https://huggingface.co/spaces/susunghong/Self-Attention-Guidance"),a(H,"rel","nofollow"),a(R,"href","https://colab.research.google.com/github/SusungHong/Self-Attention-Guidance/blob/main/SAG_Stable.ipynb"),a(R,"rel","nofollow"),a(j,"id","diffusers.StableDiffusionSAGPipeline"),a(j,"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"),a(j,"href","#diffusers.StableDiffusionSAGPipeline"),a(U,"class","relative group"),a(ce,"href","/docs/diffusers/main/en/api/pipelines/overview#diffusers.DiffusionPipeline"),a(E,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),a(q,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),a(F,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),a(V,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),a(_,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),a(B,"id","diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput"),a(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"),a(B,"href","#diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput"),a(N,"class","relative group"),a(J,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8")},m(e,c){t(document.head,p),m(e,D,c),m(e,h,c),t(h,g),t(g,b),$(d,b,null),t(h,v),t(h,C),t(C,L),m(e,w,c),m(e,k,c),t(k,I),t(I,qe),t(k,Fe),m(e,Ae,c),m(e,le,c),t(le,Ve),m(e,$e,c),m(e,de,c),t(de,ue),t(ue,Be),m(e,xe,c),m(e,S,c),t(S,Ze),t(S,Z),t(Z,We),t(S,He),t(S,W),t(W,Re),t(S,Ye),t(S,H),t(H,Ke),t(S,Qe),t(S,R),t(R,Xe),t(S,et),m(e,Ge,c),$(O,e,c),m(e,Te,c),m(e,U,c),t(U,j),t(j,me),$(Y,me,null),t(U,tt),t(U,he),t(he,nt),m(e,ke,c),m(e,_,c),$(K,_,null),t(_,ot),t(_,ge),t(ge,it),t(_,st),t(_,Q),t(Q,at),t(Q,ce),t(ce,rt),t(Q,lt),t(_,dt),t(_,E),$(X,E,null),t(E,ct),t(E,_e),t(_e,pt),t(E,ft),$(z,E,null),t(_,ut),t(_,q),$(ee,q,null),t(q,mt),t(q,te),t(te,ht),t(te,be),t(be,gt),t(te,_t),t(_,bt),t(_,F),$(ne,F,null),t(F,vt),t(F,ve),t(ve,St),t(_,yt),t(_,V),$(oe,V,null),t(V,wt),t(V,Se),t(Se,Dt),m(e,Ie,c),m(e,N,c),t(N,B),t(B,ye),$(ie,ye,null),t(N,Pt),t(N,we),t(we,At),m(e,Ee,c),m(e,J,c),$(se,J,null),t(J,$t),t(J,De),t(De,xt),Me=!0},p(e,[c]){const ae={};c&2&&(ae.$$scope={dirty:c,ctx:e}),O.$set(ae);const Pe={};c&2&&(Pe.$$scope={dirty:c,ctx:e}),z.$set(Pe)},i(e){Me||(x(d.$$.fragment,e),x(O.$$.fragment,e),x(Y.$$.fragment,e),x(K.$$.fragment,e),x(X.$$.fragment,e),x(z.$$.fragment,e),x(ee.$$.fragment,e),x(ne.$$.fragment,e),x(oe.$$.fragment,e),x(ie.$$.fragment,e),x(se.$$.fragment,e),Me=!0)},o(e){G(d.$$.fragment,e),G(O.$$.fragment,e),G(Y.$$.fragment,e),G(K.$$.fragment,e),G(X.$$.fragment,e),G(z.$$.fragment,e),G(ee.$$.fragment,e),G(ne.$$.fragment,e),G(oe.$$.fragment,e),G(ie.$$.fragment,e),G(se.$$.fragment,e),Me=!1},d(e){n(p),e&&n(D),e&&n(h),T(d),e&&n(w),e&&n(k),e&&n(Ae),e&&n(le),e&&n($e),e&&n(de),e&&n(xe),e&&n(S),e&&n(Ge),T(O,e),e&&n(Te),e&&n(U),T(Y),e&&n(ke),e&&n(_),T(K),T(X),T(z),T(ee),T(ne),T(oe),e&&n(Ie),e&&n(N),T(ie),e&&n(Ee),e&&n(J),T(se)}}}const fn={local:"selfattention-guidance",sections:[{local:"diffusers.StableDiffusionSAGPipeline",title:"StableDiffusionSAGPipeline"},{local:"diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput",title:"StableDiffusionOutput"}],title:"Self-Attention Guidance"};function un(re){return on(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Sn extends Xt{constructor(p){super();en(this,p,un,pn,tn,{})}}export{Sn as default,fn as metadata};
