import{S as Ft,i as Zt,s as Wt,e as i,k as p,w as P,t as r,M as Ht,c as o,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 k,v as Rt,L as Yt}from"../../../chunks/vendor-hf-doc-builder.js";import{T as Kt}from"../../../chunks/Tip-hf-doc-builder.js";import{D as ye}from"../../../chunks/Docstring-hf-doc-builder.js";import{C as Qt}from"../../../chunks/CodeBlock-hf-doc-builder.js";import{I as wt}from"../../../chunks/IconCopyLink-hf-doc-builder.js";import{E as Xt}from"../../../chunks/ExampleCodeBlock-hf-doc-builder.js";function en(se){let c,w,h,g,b,f,v,C;return{c(){c=i("p"),w=r("Make sure to check out the Schedulers "),h=i("a"),g=r("guide"),b=r(" to learn how to explore the tradeoff between scheduler speed and quality, and see the "),f=i("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=o(L,"P",{});var y=s(c);w=l(y,"Make sure to check out the Schedulers "),h=o(y,"A",{href:!0});var T=s(h);g=l(T,"guide"),T.forEach(n),b=l(y," to learn how to explore the tradeoff between scheduler speed and quality, and see the "),f=o(y,"A",{href:!0});var I=s(f);v=l(I,"reuse components across pipelines"),I.forEach(n),C=l(y," section to learn how to efficiently load the same components into multiple pipelines."),y.forEach(n),this.h()},h(){a(h,"href","/using-diffusers/schedulers"),a(f,"href","/using-diffusers/loading#reuse-components-across-pipelines")},m(L,y){m(L,c,y),t(c,w),t(c,h),t(h,g),t(c,b),t(c,f),t(f,v),t(c,C)},d(L){L&&n(c)}}}function tn(se){let c,w,h,g,b;return g=new Qt({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=i("p"),w=r("Examples:"),h=p(),P(g.$$.fragment)},l(f){c=o(f,"P",{});var v=s(c);w=l(v,"Examples:"),v.forEach(n),h=u(f),A(g.$$.fragment,f)},m(f,v){m(f,c,v),t(c,w),m(f,h,v),$(g,f,v),b=!0},p:Yt,i(f){b||(x(g.$$.fragment,f),b=!0)},o(f){G(g.$$.fragment,f),b=!1},d(f){f&&n(c),f&&n(h),k(g,f)}}}function nn(se){let c,w,h,g,b,f,v,C,L,y,T,I,Ne,Oe,we,ae,je,De,re,de,ze,Pe,S,qe,F,Ve,Be,Z,Fe,Ze,W,We,He,H,Re,Ye,Ae,O,$e,U,j,ce,R,Ke,pe,Qe,xe,_,Y,Xe,ue,et,tt,K,nt,le,it,ot,st,E,Q,at,me,rt,lt,z,ft,q,X,dt,ee,ct,he,pt,ut,mt,V,te,ht,ge,gt,Ge,J,B,_e,ne,_t,be,bt,ke,N,ie,vt,ve,St,Te;return f=new wt({}),O=new Kt({props:{$$slots:{default:[en]},$$scope:{ctx:se}}}),R=new wt({}),Y=new ye({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"}}),Q=new ye({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#L438",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 Xt({props:{anchor:"diffusers.StableDiffusionSAGPipeline.__call__.example",$$slots:{default:[tn]},$$scope:{ctx:se}}}),X=new ye({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"}}),te=new ye({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"}}),ne=new wt({}),ie=new ye({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(){c=i("meta"),w=p(),h=i("h1"),g=i("a"),b=i("span"),P(f.$$.fragment),v=p(),C=i("span"),L=r("Self-Attention Guidance"),y=p(),T=i("p"),I=i("a"),Ne=r("Improving Sample Quality of Diffusion Models Using Self-Attention Guidance"),Oe=r(" is by Susung Hong et al."),we=p(),ae=i("p"),je=r("The abstract from the paper is:"),De=p(),re=i("p"),de=i("em"),ze=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."),Pe=p(),S=i("p"),qe=r("You can find additional information about Self-Attention Guidance on the "),F=i("a"),Ve=r("project page"),Be=r(", "),Z=i("a"),Fe=r("original codebase"),Ze=r(", and try it out in a "),W=i("a"),We=r("demo"),He=r(" or "),H=i("a"),Re=r("notebook"),Ye=r("."),Ae=p(),P(O.$$.fragment),$e=p(),U=i("h2"),j=i("a"),ce=i("span"),P(R.$$.fragment),Ke=p(),pe=i("span"),Qe=r("StableDiffusionSAGPipeline"),xe=p(),_=i("div"),P(Y.$$.fragment),Xe=p(),ue=i("p"),et=r("Pipeline for text-to-image generation using Stable Diffusion."),tt=p(),K=i("p"),nt=r("This model inherits from "),le=i("a"),it=r("DiffusionPipeline"),ot=r(`. Check the superclass documentation for the generic methods
implemented for all pipelines (downloading, saving, running on a particular device, etc.).`),st=p(),E=i("div"),P(Q.$$.fragment),at=p(),me=i("p"),rt=r("The call function to the pipeline for generation."),lt=p(),P(z.$$.fragment),ft=p(),q=i("div"),P(X.$$.fragment),dt=p(),ee=i("p"),ct=r("Disable sliced VAE decoding. If "),he=i("code"),pt=r("enable_vae_slicing"),ut=r(` was previously enabled, this method will go back to
computing decoding in one step.`),mt=p(),V=i("div"),P(te.$$.fragment),ht=p(),ge=i("p"),gt=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.`),Ge=p(),J=i("h2"),B=i("a"),_e=i("span"),P(ne.$$.fragment),_t=p(),be=i("span"),bt=r("StableDiffusionOutput"),ke=p(),N=i("div"),P(ie.$$.fragment),vt=p(),ve=i("p"),St=r("Output class for Stable Diffusion pipelines."),this.h()},l(e){const d=Ht('[data-svelte="svelte-1phssyn"]',document.head);c=o(d,"META",{name:!0,content:!0}),d.forEach(n),w=u(e),h=o(e,"H1",{class:!0});var oe=s(h);g=o(oe,"A",{id:!0,class:!0,href:!0});var Se=s(g);b=o(Se,"SPAN",{});var Dt=s(b);A(f.$$.fragment,Dt),Dt.forEach(n),Se.forEach(n),v=u(oe),C=o(oe,"SPAN",{});var Pt=s(C);L=l(Pt,"Self-Attention Guidance"),Pt.forEach(n),oe.forEach(n),y=u(e),T=o(e,"P",{});var yt=s(T);I=o(yt,"A",{href:!0,rel:!0});var At=s(I);Ne=l(At,"Improving Sample Quality of Diffusion Models Using Self-Attention Guidance"),At.forEach(n),Oe=l(yt," is by Susung Hong et al."),yt.forEach(n),we=u(e),ae=o(e,"P",{});var $t=s(ae);je=l($t,"The abstract from the paper is:"),$t.forEach(n),De=u(e),re=o(e,"P",{});var xt=s(re);de=o(xt,"EM",{});var Gt=s(de);ze=l(Gt,"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."),Gt.forEach(n),xt.forEach(n),Pe=u(e),S=o(e,"P",{});var M=s(S);qe=l(M,"You can find additional information about Self-Attention Guidance on the "),F=o(M,"A",{href:!0,rel:!0});var kt=s(F);Ve=l(kt,"project page"),kt.forEach(n),Be=l(M,", "),Z=o(M,"A",{href:!0,rel:!0});var Tt=s(Z);Fe=l(Tt,"original codebase"),Tt.forEach(n),Ze=l(M,", and try it out in a "),W=o(M,"A",{href:!0,rel:!0});var It=s(W);We=l(It,"demo"),It.forEach(n),He=l(M," or "),H=o(M,"A",{href:!0,rel:!0});var Et=s(H);Re=l(Et,"notebook"),Et.forEach(n),Ye=l(M,"."),M.forEach(n),Ae=u(e),A(O.$$.fragment,e),$e=u(e),U=o(e,"H2",{class:!0});var Ie=s(U);j=o(Ie,"A",{id:!0,class:!0,href:!0});var Mt=s(j);ce=o(Mt,"SPAN",{});var Ct=s(ce);A(R.$$.fragment,Ct),Ct.forEach(n),Mt.forEach(n),Ke=u(Ie),pe=o(Ie,"SPAN",{});var Lt=s(pe);Qe=l(Lt,"StableDiffusionSAGPipeline"),Lt.forEach(n),Ie.forEach(n),xe=u(e),_=o(e,"DIV",{class:!0});var D=s(_);A(Y.$$.fragment,D),Xe=u(D),ue=o(D,"P",{});var Ut=s(ue);et=l(Ut,"Pipeline for text-to-image generation using Stable Diffusion."),Ut.forEach(n),tt=u(D),K=o(D,"P",{});var Ee=s(K);nt=l(Ee,"This model inherits from "),le=o(Ee,"A",{href:!0});var Jt=s(le);it=l(Jt,"DiffusionPipeline"),Jt.forEach(n),ot=l(Ee,`. Check the superclass documentation for the generic methods
implemented for all pipelines (downloading, saving, running on a particular device, etc.).`),Ee.forEach(n),st=u(D),E=o(D,"DIV",{class:!0});var fe=s(E);A(Q.$$.fragment,fe),at=u(fe),me=o(fe,"P",{});var Nt=s(me);rt=l(Nt,"The call function to the pipeline for generation."),Nt.forEach(n),lt=u(fe),A(z.$$.fragment,fe),fe.forEach(n),ft=u(D),q=o(D,"DIV",{class:!0});var Me=s(q);A(X.$$.fragment,Me),dt=u(Me),ee=o(Me,"P",{});var Ce=s(ee);ct=l(Ce,"Disable sliced VAE decoding. If "),he=o(Ce,"CODE",{});var Ot=s(he);pt=l(Ot,"enable_vae_slicing"),Ot.forEach(n),ut=l(Ce,` was previously enabled, this method will go back to
computing decoding in one step.`),Ce.forEach(n),Me.forEach(n),mt=u(D),V=o(D,"DIV",{class:!0});var Le=s(V);A(te.$$.fragment,Le),ht=u(Le),ge=o(Le,"P",{});var jt=s(ge);gt=l(jt,`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.`),jt.forEach(n),Le.forEach(n),D.forEach(n),Ge=u(e),J=o(e,"H2",{class:!0});var Ue=s(J);B=o(Ue,"A",{id:!0,class:!0,href:!0});var zt=s(B);_e=o(zt,"SPAN",{});var qt=s(_e);A(ne.$$.fragment,qt),qt.forEach(n),zt.forEach(n),_t=u(Ue),be=o(Ue,"SPAN",{});var Vt=s(be);bt=l(Vt,"StableDiffusionOutput"),Vt.forEach(n),Ue.forEach(n),ke=u(e),N=o(e,"DIV",{class:!0});var Je=s(N);A(ie.$$.fragment,Je),vt=u(Je),ve=o(Je,"P",{});var Bt=s(ve);St=l(Bt,"Output class for Stable Diffusion pipelines."),Bt.forEach(n),Je.forEach(n),this.h()},h(){a(c,"name","hf:doc:metadata"),a(c,"content",JSON.stringify(on)),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(F,"href","https://ku-cvlab.github.io/Self-Attention-Guidance"),a(F,"rel","nofollow"),a(Z,"href","https://github.com/KU-CVLAB/Self-Attention-Guidance"),a(Z,"rel","nofollow"),a(W,"href","https://huggingface.co/spaces/susunghong/Self-Attention-Guidance"),a(W,"rel","nofollow"),a(H,"href","https://colab.research.google.com/github/SusungHong/Self-Attention-Guidance/blob/main/SAG_Stable.ipynb"),a(H,"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(le,"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(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(J,"class","relative group"),a(N,"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,d){t(document.head,c),m(e,w,d),m(e,h,d),t(h,g),t(g,b),$(f,b,null),t(h,v),t(h,C),t(C,L),m(e,y,d),m(e,T,d),t(T,I),t(I,Ne),t(T,Oe),m(e,we,d),m(e,ae,d),t(ae,je),m(e,De,d),m(e,re,d),t(re,de),t(de,ze),m(e,Pe,d),m(e,S,d),t(S,qe),t(S,F),t(F,Ve),t(S,Be),t(S,Z),t(Z,Fe),t(S,Ze),t(S,W),t(W,We),t(S,He),t(S,H),t(H,Re),t(S,Ye),m(e,Ae,d),$(O,e,d),m(e,$e,d),m(e,U,d),t(U,j),t(j,ce),$(R,ce,null),t(U,Ke),t(U,pe),t(pe,Qe),m(e,xe,d),m(e,_,d),$(Y,_,null),t(_,Xe),t(_,ue),t(ue,et),t(_,tt),t(_,K),t(K,nt),t(K,le),t(le,it),t(K,ot),t(_,st),t(_,E),$(Q,E,null),t(E,at),t(E,me),t(me,rt),t(E,lt),$(z,E,null),t(_,ft),t(_,q),$(X,q,null),t(q,dt),t(q,ee),t(ee,ct),t(ee,he),t(he,pt),t(ee,ut),t(_,mt),t(_,V),$(te,V,null),t(V,ht),t(V,ge),t(ge,gt),m(e,Ge,d),m(e,J,d),t(J,B),t(B,_e),$(ne,_e,null),t(J,_t),t(J,be),t(be,bt),m(e,ke,d),m(e,N,d),$(ie,N,null),t(N,vt),t(N,ve),t(ve,St),Te=!0},p(e,[d]){const oe={};d&2&&(oe.$$scope={dirty:d,ctx:e}),O.$set(oe);const Se={};d&2&&(Se.$$scope={dirty:d,ctx:e}),z.$set(Se)},i(e){Te||(x(f.$$.fragment,e),x(O.$$.fragment,e),x(R.$$.fragment,e),x(Y.$$.fragment,e),x(Q.$$.fragment,e),x(z.$$.fragment,e),x(X.$$.fragment,e),x(te.$$.fragment,e),x(ne.$$.fragment,e),x(ie.$$.fragment,e),Te=!0)},o(e){G(f.$$.fragment,e),G(O.$$.fragment,e),G(R.$$.fragment,e),G(Y.$$.fragment,e),G(Q.$$.fragment,e),G(z.$$.fragment,e),G(X.$$.fragment,e),G(te.$$.fragment,e),G(ne.$$.fragment,e),G(ie.$$.fragment,e),Te=!1},d(e){n(c),e&&n(w),e&&n(h),k(f),e&&n(y),e&&n(T),e&&n(we),e&&n(ae),e&&n(De),e&&n(re),e&&n(Pe),e&&n(S),e&&n(Ae),k(O,e),e&&n($e),e&&n(U),k(R),e&&n(xe),e&&n(_),k(Y),k(Q),k(z),k(X),k(te),e&&n(Ge),e&&n(J),k(ne),e&&n(ke),e&&n(N),k(ie)}}}const on={local:"selfattention-guidance",sections:[{local:"diffusers.StableDiffusionSAGPipeline",title:"StableDiffusionSAGPipeline"},{local:"diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput",title:"StableDiffusionOutput"}],title:"Self-Attention Guidance"};function sn(se){return Rt(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class pn extends Ft{constructor(c){super();Zt(this,c,sn,nn,Wt,{})}}export{pn as default,on as metadata};
