import{S as vn,i as yn,s as In,e as i,k as f,w as $,t as r,M as wn,c as a,d as n,m as c,a as s,x as P,h as l,b as p,G as e,g as y,y as x,q as D,o as S,B as k,v as $n,L as _n}from"../../../../chunks/vendor-hf-doc-builder.js";import{D as oe}from"../../../../chunks/Docstring-hf-doc-builder.js";import{C as bn}from"../../../../chunks/CodeBlock-hf-doc-builder.js";import{I as un}from"../../../../chunks/IconCopyLink-hf-doc-builder.js";import{E as hn}from"../../../../chunks/ExampleCodeBlock-hf-doc-builder.js";function Pn(re){let m,E,h,d,I;return d=new bn({props:{code:`import requests
import torch
from PIL import Image
from io import BytesIO

from diffusers import StableDiffusionImg2ImgPipeline

device = "cuda"
model_id_or_path = "runwayml/stable-diffusion-v1-5"
pipe = StableDiffusionImg2ImgPipeline.from_pretrained(model_id_or_path, torch_dtype=torch.float16)
pipe = pipe.to(device)

url = "https://raw.githubusercontent.com/CompVis/stable-diffusion/main/assets/stable-samples/img2img/sketch-mountains-input.jpg"

response = requests.get(url)
init_image = Image.open(BytesIO(response.content)).convert("RGB")
init_image = init_image.resize((768, 512))

prompt = "A fantasy landscape, trending on artstation"

images = pipe(prompt=prompt, image=init_image, strength=0.75, guidance_scale=7.5).images
images[0].save("fantasy_landscape.png")`,highlighted:`<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> PIL <span class="hljs-keyword">import</span> Image
<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> StableDiffusionImg2ImgPipeline

<span class="hljs-meta">&gt;&gt;&gt; </span>device = <span class="hljs-string">&quot;cuda&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>model_id_or_path = <span class="hljs-string">&quot;runwayml/stable-diffusion-v1-5&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>pipe = StableDiffusionImg2ImgPipeline.from_pretrained(model_id_or_path, torch_dtype=torch.float16)
<span class="hljs-meta">&gt;&gt;&gt; </span>pipe = pipe.to(device)

<span class="hljs-meta">&gt;&gt;&gt; </span>url = <span class="hljs-string">&quot;https://raw.githubusercontent.com/CompVis/stable-diffusion/main/assets/stable-samples/img2img/sketch-mountains-input.jpg&quot;</span>

<span class="hljs-meta">&gt;&gt;&gt; </span>response = requests.get(url)
<span class="hljs-meta">&gt;&gt;&gt; </span>init_image = 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>init_image = init_image.resize((<span class="hljs-number">768</span>, <span class="hljs-number">512</span>))

<span class="hljs-meta">&gt;&gt;&gt; </span>prompt = <span class="hljs-string">&quot;A fantasy landscape, trending on artstation&quot;</span>

<span class="hljs-meta">&gt;&gt;&gt; </span>images = pipe(prompt=prompt, image=init_image, strength=<span class="hljs-number">0.75</span>, guidance_scale=<span class="hljs-number">7.5</span>).images
<span class="hljs-meta">&gt;&gt;&gt; </span>images[<span class="hljs-number">0</span>].save(<span class="hljs-string">&quot;fantasy_landscape.png&quot;</span>)`}}),{c(){m=i("p"),E=r("Examples:"),h=f(),$(d.$$.fragment)},l(o){m=a(o,"P",{});var b=s(m);E=l(b,"Examples:"),b.forEach(n),h=c(o),P(d.$$.fragment,o)},m(o,b){y(o,m,b),e(m,E),y(o,h,b),x(d,o,b),I=!0},p:_n,i(o){I||(D(d.$$.fragment,o),I=!0)},o(o){S(d.$$.fragment,o),I=!1},d(o){o&&n(m),o&&n(h),k(d,o)}}}function xn(re){let m,E,h,d,I;return d=new bn({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(){m=i("p"),E=r("Examples:"),h=f(),$(d.$$.fragment)},l(o){m=a(o,"P",{});var b=s(m);E=l(b,"Examples:"),b.forEach(n),h=c(o),P(d.$$.fragment,o)},m(o,b){y(o,m,b),e(m,E),y(o,h,b),x(d,o,b),I=!0},p:_n,i(o){I||(D(d.$$.fragment,o),I=!0)},o(o){S(d.$$.fragment,o),I=!1},d(o){o&&n(m),o&&n(h),k(d,o)}}}function Dn(re){let m,E,h,d,I,o,b,ge,ze,ke,q,L,ue,z,Ge,he,We,Ee,v,Be,G,Ke,He,W,Re,Je,B,Qe,Xe,K,Ye,Ze,le,et,tt,je,H,nt,R,it,Ce,O,pe,at,st,fe,ot,Te,g,J,rt,_e,lt,pt,Q,ft,ce,ct,dt,mt,C,X,gt,be,ut,ht,M,_t,T,Y,bt,ve,vt,yt,ye,It,wt,N,Z,$t,ee,Pt,Ie,xt,Dt,St,w,te,kt,we,Et,jt,$e,Ct,Tt,Pe,At,qt,F,Lt,U,ne,Ot,xe,Mt,Nt,V,ie,Ft,ae,Ut,De,Vt,zt,Ae;return o=new un({}),z=new un({}),J=new oe({props:{name:"class diffusers.StableDiffusionImg2ImgPipeline",anchor:"diffusers.StableDiffusionImg2ImgPipeline",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.StableDiffusionImg2ImgPipeline.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.StableDiffusionImg2ImgPipeline.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.StableDiffusionImg2ImgPipeline.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.StableDiffusionImg2ImgPipeline.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.StableDiffusionImg2ImgPipeline.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.StableDiffusionImg2ImgPipeline.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.StableDiffusionImg2ImgPipeline.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_img2img.py#L93"}}),X=new oe({props:{name:"__call__",anchor:"diffusers.StableDiffusionImg2ImgPipeline.__call__",parameters:[{name:"prompt",val:": typing.Union[str, typing.List[str]] = None"},{name:"image",val:": typing.Union[torch.FloatTensor, PIL.Image.Image] = None"},{name:"strength",val:": float = 0.8"},{name:"num_inference_steps",val:": typing.Optional[int] = 50"},{name:"guidance_scale",val:": typing.Optional[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:": typing.Optional[float] = 0.0"},{name:"generator",val:": typing.Union[torch._C.Generator, typing.List[torch._C.Generator], NoneType] = 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:"**kwargs",val:""}],parametersDescription:[{anchor:"diffusers.StableDiffusionImg2ImgPipeline.__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.StableDiffusionImg2ImgPipeline.__call__.image",description:`<strong>image</strong> (<code>torch.FloatTensor</code> or <code>PIL.Image.Image</code>) &#x2014;
<code>Image</code>, or tensor representing an image batch, that will be used as the starting point for the
process.`,name:"image"},{anchor:"diffusers.StableDiffusionImg2ImgPipeline.__call__.strength",description:`<strong>strength</strong> (<code>float</code>, <em>optional</em>, defaults to 0.8) &#x2014;
Conceptually, indicates how much to transform the reference <code>image</code>. Must be between 0 and 1. <code>image</code>
will be used as a starting point, adding more noise to it the larger the <code>strength</code>. The number of
denoising steps depends on the amount of noise initially added. When <code>strength</code> is 1, added noise will
be maximum and the denoising process will run for the full number of iterations specified in
<code>num_inference_steps</code>. A value of 1, therefore, essentially ignores <code>image</code>.`,name:"strength"},{anchor:"diffusers.StableDiffusionImg2ImgPipeline.__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. This parameter will be modulated by <code>strength</code>.`,name:"num_inference_steps"},{anchor:"diffusers.StableDiffusionImg2ImgPipeline.__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.StableDiffusionImg2ImgPipeline.__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.StableDiffusionImg2ImgPipeline.__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.StableDiffusionImg2ImgPipeline.__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.StableDiffusionImg2ImgPipeline.__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.StableDiffusionImg2ImgPipeline.__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.StableDiffusionImg2ImgPipeline.__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.StableDiffusionImg2ImgPipeline.__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.StableDiffusionImg2ImgPipeline.__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.StableDiffusionImg2ImgPipeline.__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.StableDiffusionImg2ImgPipeline.__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_img2img.py#L532",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>
`}}),M=new hn({props:{anchor:"diffusers.StableDiffusionImg2ImgPipeline.__call__.example",$$slots:{default:[Pn]},$$scope:{ctx:re}}}),Y=new oe({props:{name:"enable_attention_slicing",anchor:"diffusers.StableDiffusionImg2ImgPipeline.enable_attention_slicing",parameters:[{name:"slice_size",val:": typing.Union[str, int, NoneType] = 'auto'"}],parametersDescription:[{anchor:"diffusers.StableDiffusionImg2ImgPipeline.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"}}),Z=new oe({props:{name:"disable_attention_slicing",anchor:"diffusers.StableDiffusionImg2ImgPipeline.disable_attention_slicing",parameters:[],source:"https://github.com/huggingface/diffusers/blob/v0.12.0/src/diffusers/pipelines/pipeline_utils.py#L918"}}),te=new oe({props:{name:"enable_xformers_memory_efficient_attention",anchor:"diffusers.StableDiffusionImg2ImgPipeline.enable_xformers_memory_efficient_attention",parameters:[{name:"attention_op",val:": typing.Optional[typing.Callable] = None"}],parametersDescription:[{anchor:"diffusers.StableDiffusionImg2ImgPipeline.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"}}),F=new hn({props:{anchor:"diffusers.StableDiffusionImg2ImgPipeline.enable_xformers_memory_efficient_attention.example",$$slots:{default:[xn]},$$scope:{ctx:re}}}),ne=new oe({props:{name:"disable_xformers_memory_efficient_attention",anchor:"diffusers.StableDiffusionImg2ImgPipeline.disable_xformers_memory_efficient_attention",parameters:[],source:"https://github.com/huggingface/diffusers/blob/v0.12.0/src/diffusers/pipelines/pipeline_utils.py#L877"}}),ie=new oe({props:{name:"enable_sequential_cpu_offload",anchor:"diffusers.StableDiffusionImg2ImgPipeline.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_img2img.py#L213"}}),{c(){m=i("meta"),E=f(),h=i("h1"),d=i("a"),I=i("span"),$(o.$$.fragment),b=f(),ge=i("span"),ze=r("Image-to-Image Generation"),ke=f(),q=i("h2"),L=i("a"),ue=i("span"),$(z.$$.fragment),Ge=f(),he=i("span"),We=r("StableDiffusionImg2ImgPipeline"),Ee=f(),v=i("p"),Be=r("The Stable Diffusion model was created by the researchers and engineers from "),G=i("a"),Ke=r("CompVis"),He=r(", "),W=i("a"),Re=r("Stability AI"),Je=r(", "),B=i("a"),Qe=r("runway"),Xe=r(", and "),K=i("a"),Ye=r("LAION"),Ze=r(". The "),le=i("a"),et=r("StableDiffusionImg2ImgPipeline"),tt=r(" lets you pass a text prompt and an initial image to condition the generation of new images using Stable Diffusion."),je=f(),H=i("p"),nt=r("The original codebase can be found here: "),R=i("a"),it=r("CampVis/stable-diffusion"),Ce=f(),O=i("p"),pe=i("a"),at=r("StableDiffusionImg2ImgPipeline"),st=r(" is compatible with all Stable Diffusion checkpoints for "),fe=i("a"),ot=r("Text-to-Image"),Te=f(),g=i("div"),$(J.$$.fragment),rt=f(),_e=i("p"),lt=r("Pipeline for text-guided image to image generation using Stable Diffusion."),pt=f(),Q=i("p"),ft=r("This model inherits from "),ce=i("a"),ct=r("DiffusionPipeline"),dt=r(`. 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.)`),mt=f(),C=i("div"),$(X.$$.fragment),gt=f(),be=i("p"),ut=r("Function invoked when calling the pipeline for generation."),ht=f(),$(M.$$.fragment),_t=f(),T=i("div"),$(Y.$$.fragment),bt=f(),ve=i("p"),vt=r("Enable sliced attention computation."),yt=f(),ye=i("p"),It=r(`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.`),wt=f(),N=i("div"),$(Z.$$.fragment),$t=f(),ee=i("p"),Pt=r("Disable sliced attention computation. If "),Ie=i("code"),xt=r("enable_attention_slicing"),Dt=r(` was previously invoked, this method will go
back to computing attention in one step.`),St=f(),w=i("div"),$(te.$$.fragment),kt=f(),we=i("p"),Et=r("Enable memory efficient attention as implemented in xformers."),jt=f(),$e=i("p"),Ct=r(`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.`),Tt=f(),Pe=i("p"),At=r(`Warning: When Memory Efficient Attention and Sliced attention are both enabled, the Memory Efficient Attention
is used.`),qt=f(),$(F.$$.fragment),Lt=f(),U=i("div"),$(ne.$$.fragment),Ot=f(),xe=i("p"),Mt=r("Disable memory efficient attention as implemented in xformers."),Nt=f(),V=i("div"),$(ie.$$.fragment),Ft=f(),ae=i("p"),Ut=r(`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
`),De=i("code"),Vt=r("torch.device('meta') and loaded to GPU only when their specific submodule has its "),zt=r("forward` method called."),this.h()},l(t){const u=wn('[data-svelte="svelte-1phssyn"]',document.head);m=a(u,"META",{name:!0,content:!0}),u.forEach(n),E=c(t),h=a(t,"H1",{class:!0});var se=s(h);d=a(se,"A",{id:!0,class:!0,href:!0});var Se=s(d);I=a(Se,"SPAN",{});var Wt=s(I);P(o.$$.fragment,Wt),Wt.forEach(n),Se.forEach(n),b=c(se),ge=a(se,"SPAN",{});var Bt=s(ge);ze=l(Bt,"Image-to-Image Generation"),Bt.forEach(n),se.forEach(n),ke=c(t),q=a(t,"H2",{class:!0});var qe=s(q);L=a(qe,"A",{id:!0,class:!0,href:!0});var Kt=s(L);ue=a(Kt,"SPAN",{});var Ht=s(ue);P(z.$$.fragment,Ht),Ht.forEach(n),Kt.forEach(n),Ge=c(qe),he=a(qe,"SPAN",{});var Rt=s(he);We=l(Rt,"StableDiffusionImg2ImgPipeline"),Rt.forEach(n),qe.forEach(n),Ee=c(t),v=a(t,"P",{});var j=s(v);Be=l(j,"The Stable Diffusion model was created by the researchers and engineers from "),G=a(j,"A",{href:!0,rel:!0});var Jt=s(G);Ke=l(Jt,"CompVis"),Jt.forEach(n),He=l(j,", "),W=a(j,"A",{href:!0,rel:!0});var Qt=s(W);Re=l(Qt,"Stability AI"),Qt.forEach(n),Je=l(j,", "),B=a(j,"A",{href:!0,rel:!0});var Xt=s(B);Qe=l(Xt,"runway"),Xt.forEach(n),Xe=l(j,", and "),K=a(j,"A",{href:!0,rel:!0});var Yt=s(K);Ye=l(Yt,"LAION"),Yt.forEach(n),Ze=l(j,". The "),le=a(j,"A",{href:!0});var Zt=s(le);et=l(Zt,"StableDiffusionImg2ImgPipeline"),Zt.forEach(n),tt=l(j," lets you pass a text prompt and an initial image to condition the generation of new images using Stable Diffusion."),j.forEach(n),je=c(t),H=a(t,"P",{});var Gt=s(H);nt=l(Gt,"The original codebase can be found here: "),R=a(Gt,"A",{href:!0,rel:!0});var en=s(R);it=l(en,"CampVis/stable-diffusion"),en.forEach(n),Gt.forEach(n),Ce=c(t),O=a(t,"P",{});var Le=s(O);pe=a(Le,"A",{href:!0});var tn=s(pe);at=l(tn,"StableDiffusionImg2ImgPipeline"),tn.forEach(n),st=l(Le," is compatible with all Stable Diffusion checkpoints for "),fe=a(Le,"A",{href:!0});var nn=s(fe);ot=l(nn,"Text-to-Image"),nn.forEach(n),Le.forEach(n),Te=c(t),g=a(t,"DIV",{class:!0});var _=s(g);P(J.$$.fragment,_),rt=c(_),_e=a(_,"P",{});var an=s(_e);lt=l(an,"Pipeline for text-guided image to image generation using Stable Diffusion."),an.forEach(n),pt=c(_),Q=a(_,"P",{});var Oe=s(Q);ft=l(Oe,"This model inherits from "),ce=a(Oe,"A",{href:!0});var sn=s(ce);ct=l(sn,"DiffusionPipeline"),sn.forEach(n),dt=l(Oe,`. 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.)`),Oe.forEach(n),mt=c(_),C=a(_,"DIV",{class:!0});var de=s(C);P(X.$$.fragment,de),gt=c(de),be=a(de,"P",{});var on=s(be);ut=l(on,"Function invoked when calling the pipeline for generation."),on.forEach(n),ht=c(de),P(M.$$.fragment,de),de.forEach(n),_t=c(_),T=a(_,"DIV",{class:!0});var me=s(T);P(Y.$$.fragment,me),bt=c(me),ve=a(me,"P",{});var rn=s(ve);vt=l(rn,"Enable sliced attention computation."),rn.forEach(n),yt=c(me),ye=a(me,"P",{});var ln=s(ye);It=l(ln,`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.`),ln.forEach(n),me.forEach(n),wt=c(_),N=a(_,"DIV",{class:!0});var Me=s(N);P(Z.$$.fragment,Me),$t=c(Me),ee=a(Me,"P",{});var Ne=s(ee);Pt=l(Ne,"Disable sliced attention computation. If "),Ie=a(Ne,"CODE",{});var pn=s(Ie);xt=l(pn,"enable_attention_slicing"),pn.forEach(n),Dt=l(Ne,` was previously invoked, this method will go
back to computing attention in one step.`),Ne.forEach(n),Me.forEach(n),St=c(_),w=a(_,"DIV",{class:!0});var A=s(w);P(te.$$.fragment,A),kt=c(A),we=a(A,"P",{});var fn=s(we);Et=l(fn,"Enable memory efficient attention as implemented in xformers."),fn.forEach(n),jt=c(A),$e=a(A,"P",{});var cn=s($e);Ct=l(cn,`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.`),cn.forEach(n),Tt=c(A),Pe=a(A,"P",{});var dn=s(Pe);At=l(dn,`Warning: When Memory Efficient Attention and Sliced attention are both enabled, the Memory Efficient Attention
is used.`),dn.forEach(n),qt=c(A),P(F.$$.fragment,A),A.forEach(n),Lt=c(_),U=a(_,"DIV",{class:!0});var Fe=s(U);P(ne.$$.fragment,Fe),Ot=c(Fe),xe=a(Fe,"P",{});var mn=s(xe);Mt=l(mn,"Disable memory efficient attention as implemented in xformers."),mn.forEach(n),Fe.forEach(n),Nt=c(_),V=a(_,"DIV",{class:!0});var Ue=s(V);P(ie.$$.fragment,Ue),Ft=c(Ue),ae=a(Ue,"P",{});var Ve=s(ae);Ut=l(Ve,`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
`),De=a(Ve,"CODE",{});var gn=s(De);Vt=l(gn,"torch.device('meta') and loaded to GPU only when their specific submodule has its "),gn.forEach(n),zt=l(Ve,"forward` method called."),Ve.forEach(n),Ue.forEach(n),_.forEach(n),this.h()},h(){p(m,"name","hf:doc:metadata"),p(m,"content",JSON.stringify(Sn)),p(d,"id","imagetoimage-generation"),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","#imagetoimage-generation"),p(h,"class","relative group"),p(L,"id","diffusers.StableDiffusionImg2ImgPipeline"),p(L,"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(L,"href","#diffusers.StableDiffusionImg2ImgPipeline"),p(q,"class","relative group"),p(G,"href","https://github.com/CompVis"),p(G,"rel","nofollow"),p(W,"href","https://stability.ai/"),p(W,"rel","nofollow"),p(B,"href","https://github.com/runwayml"),p(B,"rel","nofollow"),p(K,"href","https://laion.ai/"),p(K,"rel","nofollow"),p(le,"href","/docs/diffusers/v0.12.0/en/api/pipelines/stable_diffusion/img2img#diffusers.StableDiffusionImg2ImgPipeline"),p(R,"href","https://github.com/CompVis/stable-diffusion/blob/main/scripts/img2img.py"),p(R,"rel","nofollow"),p(pe,"href","/docs/diffusers/v0.12.0/en/api/pipelines/stable_diffusion/img2img#diffusers.StableDiffusionImg2ImgPipeline"),p(fe,"href","./text2img"),p(ce,"href","/docs/diffusers/v0.12.0/en/api/diffusion_pipeline#diffusers.DiffusionPipeline"),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(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(N,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),p(w,"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(V,"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,u){e(document.head,m),y(t,E,u),y(t,h,u),e(h,d),e(d,I),x(o,I,null),e(h,b),e(h,ge),e(ge,ze),y(t,ke,u),y(t,q,u),e(q,L),e(L,ue),x(z,ue,null),e(q,Ge),e(q,he),e(he,We),y(t,Ee,u),y(t,v,u),e(v,Be),e(v,G),e(G,Ke),e(v,He),e(v,W),e(W,Re),e(v,Je),e(v,B),e(B,Qe),e(v,Xe),e(v,K),e(K,Ye),e(v,Ze),e(v,le),e(le,et),e(v,tt),y(t,je,u),y(t,H,u),e(H,nt),e(H,R),e(R,it),y(t,Ce,u),y(t,O,u),e(O,pe),e(pe,at),e(O,st),e(O,fe),e(fe,ot),y(t,Te,u),y(t,g,u),x(J,g,null),e(g,rt),e(g,_e),e(_e,lt),e(g,pt),e(g,Q),e(Q,ft),e(Q,ce),e(ce,ct),e(Q,dt),e(g,mt),e(g,C),x(X,C,null),e(C,gt),e(C,be),e(be,ut),e(C,ht),x(M,C,null),e(g,_t),e(g,T),x(Y,T,null),e(T,bt),e(T,ve),e(ve,vt),e(T,yt),e(T,ye),e(ye,It),e(g,wt),e(g,N),x(Z,N,null),e(N,$t),e(N,ee),e(ee,Pt),e(ee,Ie),e(Ie,xt),e(ee,Dt),e(g,St),e(g,w),x(te,w,null),e(w,kt),e(w,we),e(we,Et),e(w,jt),e(w,$e),e($e,Ct),e(w,Tt),e(w,Pe),e(Pe,At),e(w,qt),x(F,w,null),e(g,Lt),e(g,U),x(ne,U,null),e(U,Ot),e(U,xe),e(xe,Mt),e(g,Nt),e(g,V),x(ie,V,null),e(V,Ft),e(V,ae),e(ae,Ut),e(ae,De),e(De,Vt),e(ae,zt),Ae=!0},p(t,[u]){const se={};u&2&&(se.$$scope={dirty:u,ctx:t}),M.$set(se);const Se={};u&2&&(Se.$$scope={dirty:u,ctx:t}),F.$set(Se)},i(t){Ae||(D(o.$$.fragment,t),D(z.$$.fragment,t),D(J.$$.fragment,t),D(X.$$.fragment,t),D(M.$$.fragment,t),D(Y.$$.fragment,t),D(Z.$$.fragment,t),D(te.$$.fragment,t),D(F.$$.fragment,t),D(ne.$$.fragment,t),D(ie.$$.fragment,t),Ae=!0)},o(t){S(o.$$.fragment,t),S(z.$$.fragment,t),S(J.$$.fragment,t),S(X.$$.fragment,t),S(M.$$.fragment,t),S(Y.$$.fragment,t),S(Z.$$.fragment,t),S(te.$$.fragment,t),S(F.$$.fragment,t),S(ne.$$.fragment,t),S(ie.$$.fragment,t),Ae=!1},d(t){n(m),t&&n(E),t&&n(h),k(o),t&&n(ke),t&&n(q),k(z),t&&n(Ee),t&&n(v),t&&n(je),t&&n(H),t&&n(Ce),t&&n(O),t&&n(Te),t&&n(g),k(J),k(X),k(M),k(Y),k(Z),k(te),k(F),k(ne),k(ie)}}}const Sn={local:"imagetoimage-generation",sections:[{local:"diffusers.StableDiffusionImg2ImgPipeline",title:"StableDiffusionImg2ImgPipeline"}],title:"Image-to-Image Generation"};function kn(re){return $n(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class qn extends vn{constructor(m){super();yn(this,m,kn,Dn,In,{})}}export{qn as default,Sn as metadata};
