import{S as Xt,i as en,s as tn,e as o,k as f,w as A,t as r,M as nn,c as i,d as n,m as u,a as s,x as P,h as l,b as a,G as t,g as m,y as $,q as x,o as G,B as k,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 kt}from"../../../chunks/IconCopyLink-hf-doc-builder.js";import{E as ln}from"../../../chunks/ExampleCodeBlock-hf-doc-builder.js";function dn(re){let c,D,h,g,b,d,v,C;return{c(){c=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){c=i(L,"P",{});var w=s(c);D=l(w,"Make sure to check out the Schedulers "),h=i(w,"A",{href:!0});var T=s(h);g=l(T,"guide"),T.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 E=s(d);v=l(E,"reuse components across pipelines"),E.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,c,w),t(c,D),t(c,h),t(h,g),t(c,b),t(c,d),t(d,v),t(c,C)},d(L){L&&n(c)}}}function pn(re){let c,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(){c=o("p"),D=r("Examples:"),h=f(),A(g.$$.fragment)},l(d){c=i(d,"P",{});var v=s(c);D=l(v,"Examples:"),v.forEach(n),h=u(d),P(g.$$.fragment,d)},m(d,v){m(d,c,v),t(c,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(c),d&&n(h),k(g,d)}}}function cn(re){let c,D,h,g,b,d,v,C,L,w,T,E,ze,Fe,Pe,le,Ve,$e,de,ue,Be,xe,S,Ze,Z,We,He,W,Re,Ye,H,Ke,Qe,R,Xe,et,Ge,O,ke,U,j,me,Y,tt,he,nt,Te,_,K,ot,ge,it,st,Q,at,pe,rt,lt,dt,I,X,pt,_e,ct,ft,q,ut,z,ee,mt,te,ht,be,gt,_t,bt,F,ne,vt,ve,St,yt,V,oe,wt,Se,Dt,Ee,N,B,ye,ie,At,we,Pt,Ie,J,se,$t,De,xt,Me;return d=new kt({}),O=new an({props:{$$slots:{default:[dn]},$$scope:{ctx:re}}}),Y=new kt({}),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/v0.21.0/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> (<code>CLIPTextModel</code>) &#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> (<code>CLIPTokenizer</code>) &#x2014;
A <code>CLIPTokenizer</code> to tokenize text.`,name:"tokenizer"},{anchor:"diffusers.StableDiffusionSAGPipeline.unet",description:`<strong>unet</strong> (<a href="/docs/diffusers/v0.21.0/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/v0.21.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.21.0/en/api/schedulers/ddim#diffusers.DDIMScheduler">DDIMScheduler</a>, <a href="/docs/diffusers/v0.21.0/en/api/schedulers/lms_discrete#diffusers.LMSDiscreteScheduler">LMSDiscreteScheduler</a>, or <a href="/docs/diffusers/v0.21.0/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> (<code>CLIPImageProcessor</code>) &#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/v0.21.0/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_sag.py#L94"}}),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[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"},{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/v0.21.0/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/v0.21.0/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/v0.21.0/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_sag.py#L468",returnDescription:`
<p>If <code>return_dict</code> is <code>True</code>, <a
  href="/docs/diffusers/v0.21.0/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/v0.21.0/en/api/pipelines/stable_diffusion/img2img#diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput"
>StableDiffusionPipelineOutput</a> or <code>tuple</code></p>
`}}),q=new ln({props:{anchor:"diffusers.StableDiffusionSAGPipeline.__call__.example",$$slots:{default:[pn]},$$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/v0.21.0/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_sag.py#L159"}}),ne=new fe({props:{name:"enable_vae_slicing",anchor:"diffusers.StableDiffusionSAGPipeline.enable_vae_slicing",parameters:[],source:"https://github.com/huggingface/diffusers/blob/v0.21.0/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_sag.py#L151"}}),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/v0.21.0/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_sag.py#L198"}}),ie=new kt({}),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/v0.21.0/src/diffusers/pipelines/stable_diffusion/pipeline_output.py#L15"}}),{c(){c=o("meta"),D=f(),h=o("h1"),g=o("a"),b=o("span"),A(d.$$.fragment),v=f(),C=o("span"),L=r("Self-Attention Guidance"),w=f(),T=o("p"),E=o("a"),ze=r("Improving Sample Quality of Diffusion Models Using Self-Attention Guidance"),Fe=r(" is by Susung Hong et al."),Pe=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(),A(O.$$.fragment),ke=f(),U=o("h2"),j=o("a"),me=o("span"),A(Y.$$.fragment),tt=f(),he=o("span"),nt=r("StableDiffusionSAGPipeline"),Te=f(),_=o("div"),A(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 "),pe=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(),I=o("div"),A(X.$$.fragment),pt=f(),_e=o("p"),ct=r("The call function to the pipeline for generation."),ft=f(),A(q.$$.fragment),ut=f(),z=o("div"),A(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"),A(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"),A(oe.$$.fragment),wt=f(),Se=o("p"),Dt=r("Encodes the prompt into text encoder hidden states."),Ee=f(),N=o("h2"),B=o("a"),ye=o("span"),A(ie.$$.fragment),At=f(),we=o("span"),Pt=r("StableDiffusionOutput"),Ie=f(),J=o("div"),A(se.$$.fragment),$t=f(),De=o("p"),xt=r("Output class for Stable Diffusion pipelines."),this.h()},l(e){const p=nn('[data-svelte="svelte-1phssyn"]',document.head);c=i(p,"META",{name:!0,content:!0}),p.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 Ae=s(g);b=i(Ae,"SPAN",{});var Tt=s(b);P(d.$$.fragment,Tt),Tt.forEach(n),Ae.forEach(n),v=u(ae),C=i(ae,"SPAN",{});var Et=s(C);L=l(Et,"Self-Attention Guidance"),Et.forEach(n),ae.forEach(n),w=u(e),T=i(e,"P",{});var Gt=s(T);E=i(Gt,"A",{href:!0,rel:!0});var It=s(E);ze=l(It,"Improving Sample Quality of Diffusion Models Using Self-Attention Guidance"),It.forEach(n),Fe=l(Gt," is by Susung Hong et al."),Gt.forEach(n),Pe=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),P(O.$$.fragment,e),ke=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 qt=s(me);P(Y.$$.fragment,qt),qt.forEach(n),jt.forEach(n),tt=u(Ce),he=i(Ce,"SPAN",{});var zt=s(he);nt=l(zt,"StableDiffusionSAGPipeline"),zt.forEach(n),Ce.forEach(n),Te=u(e),_=i(e,"DIV",{class:!0});var y=s(_);P(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 "),pe=i(Le,"A",{href:!0});var Vt=s(pe);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),I=i(y,"DIV",{class:!0});var ce=s(I);P(X.$$.fragment,ce),pt=u(ce),_e=i(ce,"P",{});var Bt=s(_e);ct=l(Bt,"The call function to the pipeline for generation."),Bt.forEach(n),ft=u(ce),P(q.$$.fragment,ce),ce.forEach(n),ut=u(y),z=i(y,"DIV",{class:!0});var Ue=s(z);P(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);P(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);P(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),Ee=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);P(ie.$$.fragment,Yt),Yt.forEach(n),Rt.forEach(n),At=u(je),we=i(je,"SPAN",{});var Kt=s(we);Pt=l(Kt,"StableDiffusionOutput"),Kt.forEach(n),je.forEach(n),Ie=u(e),J=i(e,"DIV",{class:!0});var qe=s(J);P(se.$$.fragment,qe),$t=u(qe),De=i(qe,"P",{});var Qt=s(De);xt=l(Qt,"Output class for Stable Diffusion pipelines."),Qt.forEach(n),qe.forEach(n),this.h()},h(){a(c,"name","hf:doc:metadata"),a(c,"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(E,"href","https://huggingface.co/papers/2210.00939"),a(E,"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(pe,"href","/docs/diffusers/v0.21.0/en/api/pipelines/overview#diffusers.DiffusionPipeline"),a(I,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),a(z,"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,p){t(document.head,c),m(e,D,p),m(e,h,p),t(h,g),t(g,b),$(d,b,null),t(h,v),t(h,C),t(C,L),m(e,w,p),m(e,T,p),t(T,E),t(E,ze),t(T,Fe),m(e,Pe,p),m(e,le,p),t(le,Ve),m(e,$e,p),m(e,de,p),t(de,ue),t(ue,Be),m(e,xe,p),m(e,S,p),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,p),$(O,e,p),m(e,ke,p),m(e,U,p),t(U,j),t(j,me),$(Y,me,null),t(U,tt),t(U,he),t(he,nt),m(e,Te,p),m(e,_,p),$(K,_,null),t(_,ot),t(_,ge),t(ge,it),t(_,st),t(_,Q),t(Q,at),t(Q,pe),t(pe,rt),t(Q,lt),t(_,dt),t(_,I),$(X,I,null),t(I,pt),t(I,_e),t(_e,ct),t(I,ft),$(q,I,null),t(_,ut),t(_,z),$(ee,z,null),t(z,mt),t(z,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,Ee,p),m(e,N,p),t(N,B),t(B,ye),$(ie,ye,null),t(N,At),t(N,we),t(we,Pt),m(e,Ie,p),m(e,J,p),$(se,J,null),t(J,$t),t(J,De),t(De,xt),Me=!0},p(e,[p]){const ae={};p&2&&(ae.$$scope={dirty:p,ctx:e}),O.$set(ae);const Ae={};p&2&&(Ae.$$scope={dirty:p,ctx:e}),q.$set(Ae)},i(e){Me||(x(d.$$.fragment,e),x(O.$$.fragment,e),x(Y.$$.fragment,e),x(K.$$.fragment,e),x(X.$$.fragment,e),x(q.$$.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(q.$$.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(c),e&&n(D),e&&n(h),k(d),e&&n(w),e&&n(T),e&&n(Pe),e&&n(le),e&&n($e),e&&n(de),e&&n(xe),e&&n(S),e&&n(Ge),k(O,e),e&&n(ke),e&&n(U),k(Y),e&&n(Te),e&&n(_),k(K),k(X),k(q),k(ee),k(ne),k(oe),e&&n(Ee),e&&n(N),k(ie),e&&n(Ie),e&&n(J),k(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(c){super();en(this,c,un,cn,tn,{})}}export{Sn as default,fn as metadata};
