import{S as ai,i as si,s as oi,e as i,k as f,w as x,t as o,M as ri,c as a,d as n,m as c,a as s,x as P,h as r,b as p,G as e,g as h,y as $,q as D,o as k,B as S,v as li,L as ni}from"../../../../chunks/vendor-hf-doc-builder.js";import{D as ue}from"../../../../chunks/Docstring-hf-doc-builder.js";import{C as ii}from"../../../../chunks/CodeBlock-hf-doc-builder.js";import{I as ei}from"../../../../chunks/IconCopyLink-hf-doc-builder.js";import{E as ti}from"../../../../chunks/ExampleCodeBlock-hf-doc-builder.js";function pi(ge){let u,E,_,d,w;return d=new ii({props:{code:`import PIL
import requests
import torch
from io import BytesIO

from diffusers import StableDiffusionInpaintPipeline


def download_image(url):
    response = requests.get(url)
    return PIL.Image.open(BytesIO(response.content)).convert("RGB")


img_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo.png"
mask_url = "https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo_mask.png"

init_image = download_image(img_url).resize((512, 512))
mask_image = download_image(mask_url).resize((512, 512))

pipe = StableDiffusionInpaintPipeline.from_pretrained(
    "runwayml/stable-diffusion-inpainting", torch_dtype=torch.float16
)
pipe = pipe.to("cuda")

prompt = "Face of a yellow cat, high resolution, sitting on a park bench"
image = pipe(prompt=prompt, image=init_image, mask_image=mask_image).images[0]`,highlighted:`<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> PIL
<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">import</span> requests
<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> io <span class="hljs-keyword">import</span> BytesIO

<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> StableDiffusionInpaintPipeline


<span class="hljs-meta">&gt;&gt;&gt; </span><span class="hljs-keyword">def</span> <span class="hljs-title function_">download_image</span>(<span class="hljs-params">url</span>):
<span class="hljs-meta">... </span>    response = requests.get(url)
<span class="hljs-meta">... </span>    <span class="hljs-keyword">return</span> PIL.Image.<span class="hljs-built_in">open</span>(BytesIO(response.content)).convert(<span class="hljs-string">&quot;RGB&quot;</span>)


<span class="hljs-meta">&gt;&gt;&gt; </span>img_url = <span class="hljs-string">&quot;https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo.png&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>mask_url = <span class="hljs-string">&quot;https://raw.githubusercontent.com/CompVis/latent-diffusion/main/data/inpainting_examples/overture-creations-5sI6fQgYIuo_mask.png&quot;</span>

<span class="hljs-meta">&gt;&gt;&gt; </span>init_image = download_image(img_url).resize((<span class="hljs-number">512</span>, <span class="hljs-number">512</span>))
<span class="hljs-meta">&gt;&gt;&gt; </span>mask_image = download_image(mask_url).resize((<span class="hljs-number">512</span>, <span class="hljs-number">512</span>))

<span class="hljs-meta">&gt;&gt;&gt; </span>pipe = StableDiffusionInpaintPipeline.from_pretrained(
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;runwayml/stable-diffusion-inpainting&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;Face of a yellow cat, high resolution, sitting on a park bench&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>image = pipe(prompt=prompt, image=init_image, mask_image=mask_image).images[<span class="hljs-number">0</span>]`}}),{c(){u=i("p"),E=o("Examples:"),_=f(),x(d.$$.fragment)},l(l){u=a(l,"P",{});var v=s(u);E=r(v,"Examples:"),v.forEach(n),_=c(l),P(d.$$.fragment,l)},m(l,v){h(l,u,v),e(u,E),h(l,_,v),$(d,l,v),w=!0},p:ni,i(l){w||(D(d.$$.fragment,l),w=!0)},o(l){k(d.$$.fragment,l),w=!1},d(l){l&&n(u),l&&n(_),S(d,l)}}}function fi(ge){let u,E,_,d,w;return d=new ii({props:{code:`import torch
from diffusers import DiffusionPipeline
from xformers.ops import MemoryEfficientAttentionFlashAttentionOp

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

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