import{S as Ei,i as Si,s as Ti,e as i,k as c,w as P,t as o,M as ji,c as n,d as a,m as p,a as s,x as w,h as r,b as l,G as e,g as f,y,q as I,o as k,B as $,v as qi,L as Li}from"../../../../chunks/vendor-hf-doc-builder.js";import{D as Pt}from"../../../../chunks/Docstring-hf-doc-builder.js";import{C as Di}from"../../../../chunks/CodeBlock-hf-doc-builder.js";import{I as Xe}from"../../../../chunks/IconCopyLink-hf-doc-builder.js";import{E as Ci}from"../../../../chunks/ExampleCodeBlock-hf-doc-builder.js";function Ai(Ze){let h,M,_,g,D;return g=new Di({props:{code:`import PIL
import requests
import torch
from io import BytesIO

from diffusers import StableDiffusionInstructPix2PixPipeline


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


img_url = "https://huggingface.co/datasets/diffusers/diffusers-images-docs/resolve/main/mountain.png"

image = download_image(img_url).resize((512, 512))

pipe = StableDiffusionInstructPix2PixPipeline.from_pretrained(
    "timbrooks/instruct-pix2pix", torch_dtype=torch.float16
)
pipe = pipe.to("cuda")

prompt = "make the mountains snowy"
image = pipe(prompt=prompt, image=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> StableDiffusionInstructPix2PixPipeline


<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://huggingface.co/datasets/diffusers/diffusers-images-docs/resolve/main/mountain.png&quot;</span>

<span class="hljs-meta">&gt;&gt;&gt; </span>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>pipe = StableDiffusionInstructPix2PixPipeline.from_pretrained(
<span class="hljs-meta">... </span>    <span class="hljs-string">&quot;timbrooks/instruct-pix2pix&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;make the mountains snowy&quot;</span>
<span class="hljs-meta">&gt;&gt;&gt; </span>image = pipe(prompt=prompt, image=image).images[<span class="hljs-number">0</span>]`}}),{c(){h=i("p"),M=o("Examples:"),_=c(),P(g.$$.fragment)},l(u){h=n(u,"P",{});var E=s(h);M=r(E,"Examples:"),E.forEach(a),_=p(u),w(g.$$.fragment,u)},m(u,E){f(u,h,E),e(h,M),f(u,_,E),y(g,u,E),D=!0},p:Li,i(u){D||(I(g.$$.fragment,u),D=!0)},o(u){k(g.$$.fragment,u),D=!1},d(u){u&&a(h),u&&a(_),$(g,u)}}}function Oi(Ze){let h,M,_,g,D,u,E,De,wt,et,j,U,Ee,K,yt,Se,It,tt,J,Y,kt,$t,at,ue,Dt,it,me,Te,Et,nt,he,St,st,v,ge,Q,Tt,jt,qt,_e,X,Lt,Ct,At,be,Z,Ot,Nt,Mt,ve,ee,Ut,Gt,ot,q,G,je,te,Bt,qe,Ft,rt,B,Le,L,Ce,zt,Ht,Ae,Rt,Wt,xe,Vt,Kt,Oe,C,Ne,ae,Jt,Yt,Me,Ue,Qt,Xt,Pe,ie,Zt,lt,A,F,Ge,ne,ea,Be,ta,ct,se,pt,O,z,Fe,oe,aa,ze,ia,dt,m,re,na,He,sa,oa,le,ra,we,la,ca,pa,S,ce,da,Re,fa,ua,H,ma,R,pe,ha,b,ga,We,_a,ba,Ve,va,xa,Ke,Pa,wa,Je,ya,Ia,ka,W,de,$a,N,Da,Ye,Ea,Sa,Qe,Ta,ja,ft;return u=new Xe({}),K=new Xe({}),te=new Xe({}),ne=new Xe({}),se=new Di({props:{code:`import PIL
import requests
import torch
from diffusers import StableDiffusionInstructPix2PixPipeline

model_id = "timbrooks/instruct-pix2pix"
pipe = StableDiffusionInstructPix2PixPipeline.from_pretrained(model_id, torch_dtype=torch.float16).to("cuda")

url = "https://huggingface.co/datasets/diffusers/diffusers-images-docs/resolve/main/mountain.png"


def download_image(url):
    image = PIL.Image.open(requests.get(url, stream=True).raw)
    image = PIL.ImageOps.exif_transpose(image)
    image = image.convert("RGB")
    return image


image = download_image(url)

prompt = "make the mountains snowy"
images = pipe(prompt, image=image, num_inference_steps=20, image_guidance_scale=1.5, guidance_scale=7).images
images[0].save("snowy_mountains.png")`,highlighted:`<span class="hljs-keyword">import</span> PIL
<span class="hljs-keyword">import</span> requests
<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> StableDiffusionInstructPix2PixPipeline

model_id = <span class="hljs-string">&quot;timbrooks/instruct-pix2pix&quot;</span>
pipe = StableDiffusionInstructPix2PixPipeline.from_pretrained(model_id, torch_dtype=torch.float16).to(<span class="hljs-string">&quot;cuda&quot;</span>)

url = <span class="hljs-string">&quot;https://huggingface.co/datasets/diffusers/diffusers-images-docs/resolve/main/mountain.png&quot;</span>


<span class="hljs-keyword">def</span> <span class="hljs-title function_">download_image</span>(<span class="hljs-params">url</span>):
    image = PIL.Image.<span class="hljs-built_in">open</span>(requests.get(url, stream=<span class="hljs-literal">True</span>).raw)
    image = PIL.ImageOps.exif_transpose(image)
    image = image.convert(<span class="hljs-string">&quot;RGB&quot;</span>)
    <span class="hljs-keyword">return</span> image


image = download_image(url)

prompt = <span class="hljs-string">&quot;make the mountains snowy&quot;</span>
images = pipe(prompt, image=image, num_inference_steps=<span class="hljs-number">20</span>, image_guidance_scale=<span class="hljs-number">1.5</span>, guidance_scale=<span class="hljs-number">7</span>).images
images[<span class="hljs-number">0</span>].save(<span class="hljs-string">&quot;snowy_mountains.png&quot;</span>)`}}),oe=new Xe({}),re=new Pt({props:{name:"class diffusers.StableDiffusionInstructPix2PixPipeline",anchor:"diffusers.StableDiffusionInstructPix2PixPipeline",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.StableDiffusionInstructPix2PixPipeline.vae",description:`<strong>vae</strong> (<a href="/docs/diffusers/main/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.StableDiffusionInstructPix2PixPipeline.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.StableDiffusionInstructPix2PixPipeline.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.StableDiffusionInstructPix2PixPipeline.unet",description:'<strong>unet</strong> (<a href="/docs/diffusers/main/en/api/models#diffusers.UNet2DConditionModel">UNet2DConditionModel</a>) &#x2014; Conditional U-Net architecture to denoise the encoded image latents.',name:"unet"},{anchor:"diffusers.StableDiffusionInstructPix2PixPipeline.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.StableDiffusionInstructPix2PixPipeline.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.StableDiffusionInstructPix2PixPipeline.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/main/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_instruct_pix2pix.py#L63"}}),ce=new Pt({props:{name:"__call__",anchor:"diffusers.StableDiffusionInstructPix2PixPipeline.__call__",parameters:[{name:"prompt",val:": typing.Union[str, typing.List[str]] = None"},{name:"image",val:": typing.Union[torch.FloatTensor, PIL.Image.Image] = None"},{name:"num_inference_steps",val:": int = 100"},{name:"guidance_scale",val:": float = 7.5"},{name:"image_guidance_scale",val:": float = 1.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:"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:": int = 1"}],parametersDescription:[{anchor:"diffusers.StableDiffusionInstructPix2PixPipeline.__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.StableDiffusionInstructPix2PixPipeline.__call__.image",description:`<strong>image</strong> (<code>PIL.Image.Image</code>) &#x2014;
<code>Image</code>, or tensor representing an image batch which will be repainted according to <code>prompt</code>.`,name:"image"},{anchor:"diffusers.StableDiffusionInstructPix2PixPipeline.__call__.num_inference_steps",description:`<strong>num_inference_steps</strong> (<code>int</code>, <em>optional</em>, defaults to 100) &#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.StableDiffusionInstructPix2PixPipeline.__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. This pipeline requires a value of at least <code>1</code>.`,name:"guidance_scale"},{anchor:"diffusers.StableDiffusionInstructPix2PixPipeline.__call__.image_guidance_scale",description:`<strong>image_guidance_scale</strong> (<code>float</code>, <em>optional</em>, defaults to 1.5) &#x2014;
Image guidance scale is to push the generated image towards the inital image <code>image</code>. Image guidance
scale is enabled by setting <code>image_guidance_scale &gt; 1</code>. Higher image guidance scale encourages to
generate images that are closely linked to the source image <code>image</code>, usually at the expense of lower
image quality. This pipeline requires a value of at least <code>1</code>.`,name:"image_guidance_scale"},{anchor:"diffusers.StableDiffusionInstructPix2PixPipeline.__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.StableDiffusionInstructPix2PixPipeline.__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.StableDiffusionInstructPix2PixPipeline.__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/main/en/api/schedulers/ddim#diffusers.DDIMScheduler">schedulers.DDIMScheduler</a>, will be ignored for others.`,name:"eta"},{anchor:"diffusers.StableDiffusionInstructPix2PixPipeline.__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.StableDiffusionInstructPix2PixPipeline.__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.StableDiffusionInstructPix2PixPipeline.__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.StableDiffusionInstructPix2PixPipeline.__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.StableDiffusionInstructPix2PixPipeline.__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.StableDiffusionInstructPix2PixPipeline.__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/overview#diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput">StableDiffusionPipelineOutput</a> instead of a
plain tuple.`,name:"return_dict"},{anchor:"diffusers.StableDiffusionInstructPix2PixPipeline.__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.StableDiffusionInstructPix2PixPipeline.__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/main/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_instruct_pix2pix.py#L133",returnDescription:`
<p><a
  href="/docs/diffusers/main/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/main/en/api/pipelines/stable_diffusion/overview#diffusers.pipelines.stable_diffusion.StableDiffusionPipelineOutput"
>StableDiffusionPipelineOutput</a> or <code>tuple</code></p>
`}}),H=new Ci({props:{anchor:"diffusers.StableDiffusionInstructPix2PixPipeline.__call__.example",$$slots:{default:[Ai]},$$scope:{ctx:Ze}}}),pe=new Pt({props:{name:"enable_model_cpu_offload",anchor:"diffusers.StableDiffusionInstructPix2PixPipeline.enable_model_cpu_offload",parameters:[{name:"gpu_id",val:" = 0"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_instruct_pix2pix.py#L415"}}),de=new Pt({props:{name:"enable_sequential_cpu_offload",anchor:"diffusers.StableDiffusionInstructPix2PixPipeline.enable_sequential_cpu_offload",parameters:[{name:"gpu_id",val:" = 0"}],source:"https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_instruct_pix2pix.py#L393"}}),{c(){h=i("meta"),M=c(),_=i("h1"),g=i("a"),D=i("span"),P(u.$$.fragment),E=c(),De=i("span"),wt=o("InstructPix2Pix: Learning to Follow Image Editing Instructions"),et=c(),j=i("h2"),U=i("a"),Ee=i("span"),P(K.$$.fragment),yt=c(),Se=i("span"),It=o("Overview"),tt=c(),J=i("p"),Y=i("a"),kt=o("InstructPix2Pix: Learning to Follow Image Editing Instructions"),$t=o(" by Tim Brooks, Aleksander Holynski and Alexei A. Efros."),at=c(),ue=i("p"),Dt=o("The abstract of the paper is the following:"),it=c(),me=i("p"),Te=i("em"),Et=o("We propose a method for editing images from human instructions: given an input image and a written instruction that tells the model what to do, our model follows these instructions to edit the image. To obtain training data for this problem, we combine the knowledge of two large pretrained models \u2014 a language model (GPT-3) and a text-to-image model (Stable Diffusion) \u2014 to generate a large dataset of image editing examples. Our conditional diffusion model, InstructPix2Pix, is trained on our generated data, and generalizes to real images and user-written instructions at inference time. Since it performs edits in the forward pass and does not require per example fine-tuning or inversion, our model edits images quickly, in a matter of seconds. We show compelling editing results for a diverse collection of input images and written instructions."),nt=c(),he=i("p"),St=o("Resources:"),st=c(),v=i("ul"),ge=i("li"),Q=i("a"),Tt=o("Project Page"),jt=o("."),qt=c(),_e=i("li"),X=i("a"),Lt=o("Paper"),Ct=o("."),At=c(),be=i("li"),Z=i("a"),Ot=o("Original Code"),Nt=o("."),Mt=c(),ve=i("li"),ee=i("a"),Ut=o("Demo"),Gt=o("."),ot=c(),q=i("h2"),G=i("a"),je=i("span"),P(te.$$.fragment),Bt=c(),qe=i("span"),Ft=o("Available Pipelines:"),rt=c(),B=i("table"),Le=i("thead"),L=i("tr"),Ce=i("th"),zt=o("Pipeline"),Ht=c(),Ae=i("th"),Rt=o("Tasks"),Wt=c(),xe=i("th"),Vt=o("Demo"),Kt=c(),Oe=i("tbody"),C=i("tr"),Ne=i("td"),ae=i("a"),Jt=o("StableDiffusionInstructPix2PixPipeline"),Yt=c(),Me=i("td"),Ue=i("em"),Qt=o("Text-Based Image Editing"),Xt=c(),Pe=i("td"),ie=i("a"),Zt=o("\u{1F917} Space"),lt=c(),A=i("h2"),F=i("a"),Ge=i("span"),P(ne.$$.fragment),ea=c(),Be=i("span"),ta=o("Usage example"),ct=c(),P(se.$$.fragment),pt=c(),O=i("h2"),z=i("a"),Fe=i("span"),P(oe.$$.fragment),aa=c(),ze=i("span"),ia=o("StableDiffusionInstructPix2PixPipeline"),dt=c(),m=i("div"),P(re.$$.fragment),na=c(),He=i("p"),sa=o("Pipeline for pixel-level image editing by following text instructions. Based on Stable Diffusion."),oa=c(),le=i("p"),ra=o("This model inherits from "),we=i("a"),la=o("DiffusionPipeline"),ca=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.)`),pa=c(),S=i("div"),P(ce.$$.fragment),da=c(),Re=i("p"),fa=o("Function invoked when calling the pipeline for generation."),ua=c(),P(H.$$.fragment),ma=c(),R=i("div"),P(pe.$$.fragment),ha=c(),b=i("p"),ga=o(`Offloads all models to CPU using accelerate, reducing memory usage with a low impact on performance. Compared
to `),We=i("code"),_a=o("enable_sequential_cpu_offload"),ba=o(", this method moves one whole model at a time to the GPU when its "),Ve=i("code"),va=o("forward"),xa=o(`
method is called, and the model remains in GPU until the next model runs. Memory savings are lower than with
`),Ke=i("code"),Pa=o("enable_sequential_cpu_offload"),wa=o(", but performance is much better due to the iterative execution of the "),Je=i("code"),ya=o("unet"),Ia=o("."),ka=c(),W=i("div"),P(de.$$.fragment),$a=c(),N=i("p"),Da=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
`),Ye=i("code"),Ea=o("torch.device('meta') and loaded to GPU only when their specific submodule has its "),Sa=o("forward"),Qe=i("code"),Ta=o("method called. Note that offloading happens on a submodule basis. Memory savings are higher than with"),ja=o("enable_model_cpu_offload`, but performance is lower."),this.h()},l(t){const d=ji('[data-svelte="svelte-1phssyn"]',document.head);h=n(d,"META",{name:!0,content:!0}),d.forEach(a),M=p(t),_=n(t,"H1",{class:!0});var fe=s(_);g=n(fe,"A",{id:!0,class:!0,href:!0});var Na=s(g);D=n(Na,"SPAN",{});var Ma=s(D);w(u.$$.fragment,Ma),Ma.forEach(a),Na.forEach(a),E=p(fe),De=n(fe,"SPAN",{});var Ua=s(De);wt=r(Ua,"InstructPix2Pix: Learning to Follow Image Editing Instructions"),Ua.forEach(a),fe.forEach(a),et=p(t),j=n(t,"H2",{class:!0});var ut=s(j);U=n(ut,"A",{id:!0,class:!0,href:!0});var Ga=s(U);Ee=n(Ga,"SPAN",{});var Ba=s(Ee);w(K.$$.fragment,Ba),Ba.forEach(a),Ga.forEach(a),yt=p(ut),Se=n(ut,"SPAN",{});var Fa=s(Se);It=r(Fa,"Overview"),Fa.forEach(a),ut.forEach(a),tt=p(t),J=n(t,"P",{});var qa=s(J);Y=n(qa,"A",{href:!0,rel:!0});var za=s(Y);kt=r(za,"InstructPix2Pix: Learning to Follow Image Editing Instructions"),za.forEach(a),$t=r(qa," by Tim Brooks, Aleksander Holynski and Alexei A. Efros."),qa.forEach(a),at=p(t),ue=n(t,"P",{});var Ha=s(ue);Dt=r(Ha,"The abstract of the paper is the following:"),Ha.forEach(a),it=p(t),me=n(t,"P",{});var Ra=s(me);Te=n(Ra,"EM",{});var Wa=s(Te);Et=r(Wa,"We propose a method for editing images from human instructions: given an input image and a written instruction that tells the model what to do, our model follows these instructions to edit the image. To obtain training data for this problem, we combine the knowledge of two large pretrained models \u2014 a language model (GPT-3) and a text-to-image model (Stable Diffusion) \u2014 to generate a large dataset of image editing examples. Our conditional diffusion model, InstructPix2Pix, is trained on our generated data, and generalizes to real images and user-written instructions at inference time. Since it performs edits in the forward pass and does not require per example fine-tuning or inversion, our model edits images quickly, in a matter of seconds. We show compelling editing results for a diverse collection of input images and written instructions."),Wa.forEach(a),Ra.forEach(a),nt=p(t),he=n(t,"P",{});var Va=s(he);St=r(Va,"Resources:"),Va.forEach(a),st=p(t),v=n(t,"UL",{});var V=s(v);ge=n(V,"LI",{});var La=s(ge);Q=n(La,"A",{href:!0,rel:!0});var Ka=s(Q);Tt=r(Ka,"Project Page"),Ka.forEach(a),jt=r(La,"."),La.forEach(a),qt=p(V),_e=n(V,"LI",{});var Ca=s(_e);X=n(Ca,"A",{href:!0,rel:!0});var Ja=s(X);Lt=r(Ja,"Paper"),Ja.forEach(a),Ct=r(Ca,"."),Ca.forEach(a),At=p(V),be=n(V,"LI",{});var Aa=s(be);Z=n(Aa,"A",{href:!0,rel:!0});var Ya=s(Z);Ot=r(Ya,"Original Code"),Ya.forEach(a),Nt=r(Aa,"."),Aa.forEach(a),Mt=p(V),ve=n(V,"LI",{});var Oa=s(ve);ee=n(Oa,"A",{href:!0,rel:!0});var Qa=s(ee);Ut=r(Qa,"Demo"),Qa.forEach(a),Gt=r(Oa,"."),Oa.forEach(a),V.forEach(a),ot=p(t),q=n(t,"H2",{class:!0});var mt=s(q);G=n(mt,"A",{id:!0,class:!0,href:!0});var Xa=s(G);je=n(Xa,"SPAN",{});var Za=s(je);w(te.$$.fragment,Za),Za.forEach(a),Xa.forEach(a),Bt=p(mt),qe=n(mt,"SPAN",{});var ei=s(qe);Ft=r(ei,"Available Pipelines:"),ei.forEach(a),mt.forEach(a),rt=p(t),B=n(t,"TABLE",{});var ht=s(B);Le=n(ht,"THEAD",{});var ti=s(Le);L=n(ti,"TR",{});var ye=s(L);Ce=n(ye,"TH",{});var ai=s(Ce);zt=r(ai,"Pipeline"),ai.forEach(a),Ht=p(ye),Ae=n(ye,"TH",{});var ii=s(Ae);Rt=r(ii,"Tasks"),ii.forEach(a),Wt=p(ye),xe=n(ye,"TH",{align:!0});var ni=s(xe);Vt=r(ni,"Demo"),ni.forEach(a),ye.forEach(a),ti.forEach(a),Kt=p(ht),Oe=n(ht,"TBODY",{});var si=s(Oe);C=n(si,"TR",{});var Ie=s(C);Ne=n(Ie,"TD",{});var oi=s(Ne);ae=n(oi,"A",{href:!0,rel:!0});var ri=s(ae);Jt=r(ri,"StableDiffusionInstructPix2PixPipeline"),ri.forEach(a),oi.forEach(a),Yt=p(Ie),Me=n(Ie,"TD",{});var li=s(Me);Ue=n(li,"EM",{});var ci=s(Ue);Qt=r(ci,"Text-Based Image Editing"),ci.forEach(a),li.forEach(a),Xt=p(Ie),Pe=n(Ie,"TD",{align:!0});var pi=s(Pe);ie=n(pi,"A",{href:!0,rel:!0});var di=s(ie);Zt=r(di,"\u{1F917} Space"),di.forEach(a),pi.forEach(a),Ie.forEach(a),si.forEach(a),ht.forEach(a),lt=p(t),A=n(t,"H2",{class:!0});var gt=s(A);F=n(gt,"A",{id:!0,class:!0,href:!0});var fi=s(F);Ge=n(fi,"SPAN",{});var ui=s(Ge);w(ne.$$.fragment,ui),ui.forEach(a),fi.forEach(a),ea=p(gt),Be=n(gt,"SPAN",{});var mi=s(Be);ta=r(mi,"Usage example"),mi.forEach(a),gt.forEach(a),ct=p(t),w(se.$$.fragment,t),pt=p(t),O=n(t,"H2",{class:!0});var _t=s(O);z=n(_t,"A",{id:!0,class:!0,href:!0});var hi=s(z);Fe=n(hi,"SPAN",{});var gi=s(Fe);w(oe.$$.fragment,gi),gi.forEach(a),hi.forEach(a),aa=p(_t),ze=n(_t,"SPAN",{});var _i=s(ze);ia=r(_i,"StableDiffusionInstructPix2PixPipeline"),_i.forEach(a),_t.forEach(a),dt=p(t),m=n(t,"DIV",{class:!0});var x=s(m);w(re.$$.fragment,x),na=p(x),He=n(x,"P",{});var bi=s(He);sa=r(bi,"Pipeline for pixel-level image editing by following text instructions. Based on Stable Diffusion."),bi.forEach(a),oa=p(x),le=n(x,"P",{});var bt=s(le);ra=r(bt,"This model inherits from "),we=n(bt,"A",{href:!0});var vi=s(we);la=r(vi,"DiffusionPipeline"),vi.forEach(a),ca=r(bt,`. 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.)`),bt.forEach(a),pa=p(x),S=n(x,"DIV",{class:!0});var ke=s(S);w(ce.$$.fragment,ke),da=p(ke),Re=n(ke,"P",{});var xi=s(Re);fa=r(xi,"Function invoked when calling the pipeline for generation."),xi.forEach(a),ua=p(ke),w(H.$$.fragment,ke),ke.forEach(a),ma=p(x),R=n(x,"DIV",{class:!0});var vt=s(R);w(pe.$$.fragment,vt),ha=p(vt),b=n(vt,"P",{});var T=s(b);ga=r(T,`Offloads all models to CPU using accelerate, reducing memory usage with a low impact on performance. Compared
to `),We=n(T,"CODE",{});var Pi=s(We);_a=r(Pi,"enable_sequential_cpu_offload"),Pi.forEach(a),ba=r(T,", this method moves one whole model at a time to the GPU when its "),Ve=n(T,"CODE",{});var wi=s(Ve);va=r(wi,"forward"),wi.forEach(a),xa=r(T,`
method is called, and the model remains in GPU until the next model runs. Memory savings are lower than with
`),Ke=n(T,"CODE",{});var yi=s(Ke);Pa=r(yi,"enable_sequential_cpu_offload"),yi.forEach(a),wa=r(T,", but performance is much better due to the iterative execution of the "),Je=n(T,"CODE",{});var Ii=s(Je);ya=r(Ii,"unet"),Ii.forEach(a),Ia=r(T,"."),T.forEach(a),vt.forEach(a),ka=p(x),W=n(x,"DIV",{class:!0});var xt=s(W);w(de.$$.fragment,xt),$a=p(xt),N=n(xt,"P",{});var $e=s(N);Da=r($e,`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
`),Ye=n($e,"CODE",{});var ki=s(Ye);Ea=r(ki,"torch.device('meta') and loaded to GPU only when their specific submodule has its "),ki.forEach(a),Sa=r($e,"forward"),Qe=n($e,"CODE",{});var $i=s(Qe);Ta=r($i,"method called. Note that offloading happens on a submodule basis. Memory savings are higher than with"),$i.forEach(a),ja=r($e,"enable_model_cpu_offload`, but performance is lower."),$e.forEach(a),xt.forEach(a),x.forEach(a),this.h()},h(){l(h,"name","hf:doc:metadata"),l(h,"content",JSON.stringify(Ni)),l(g,"id","instructpix2pix-learning-to-follow-image-editing-instructions"),l(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"),l(g,"href","#instructpix2pix-learning-to-follow-image-editing-instructions"),l(_,"class","relative group"),l(U,"id","overview"),l(U,"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"),l(U,"href","#overview"),l(j,"class","relative group"),l(Y,"href","https://arxiv.org/abs/2211.09800"),l(Y,"rel","nofollow"),l(Q,"href","https://www.timothybrooks.com/instruct-pix2pix"),l(Q,"rel","nofollow"),l(X,"href","https://arxiv.org/abs/2211.09800"),l(X,"rel","nofollow"),l(Z,"href","https://github.com/timothybrooks/instruct-pix2pix"),l(Z,"rel","nofollow"),l(ee,"href","https://huggingface.co/spaces/timbrooks/instruct-pix2pix"),l(ee,"rel","nofollow"),l(G,"id","available-pipelines"),l(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"),l(G,"href","#available-pipelines"),l(q,"class","relative group"),l(xe,"align","center"),l(ae,"href","https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_instruct_pix2pix.py"),l(ae,"rel","nofollow"),l(ie,"href","https://huggingface.co/spaces/timbrooks/instruct-pix2pix"),l(ie,"rel","nofollow"),l(Pe,"align","center"),l(F,"id","usage-example"),l(F,"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"),l(F,"href","#usage-example"),l(A,"class","relative group"),l(z,"id","diffusers.StableDiffusionInstructPix2PixPipeline"),l(z,"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"),l(z,"href","#diffusers.StableDiffusionInstructPix2PixPipeline"),l(O,"class","relative group"),l(we,"href","/docs/diffusers/main/en/api/diffusion_pipeline#diffusers.DiffusionPipeline"),l(S,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(R,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(W,"class","docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"),l(m,"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,d){e(document.head,h),f(t,M,d),f(t,_,d),e(_,g),e(g,D),y(u,D,null),e(_,E),e(_,De),e(De,wt),f(t,et,d),f(t,j,d),e(j,U),e(U,Ee),y(K,Ee,null),e(j,yt),e(j,Se),e(Se,It),f(t,tt,d),f(t,J,d),e(J,Y),e(Y,kt),e(J,$t),f(t,at,d),f(t,ue,d),e(ue,Dt),f(t,it,d),f(t,me,d),e(me,Te),e(Te,Et),f(t,nt,d),f(t,he,d),e(he,St),f(t,st,d),f(t,v,d),e(v,ge),e(ge,Q),e(Q,Tt),e(ge,jt),e(v,qt),e(v,_e),e(_e,X),e(X,Lt),e(_e,Ct),e(v,At),e(v,be),e(be,Z),e(Z,Ot),e(be,Nt),e(v,Mt),e(v,ve),e(ve,ee),e(ee,Ut),e(ve,Gt),f(t,ot,d),f(t,q,d),e(q,G),e(G,je),y(te,je,null),e(q,Bt),e(q,qe),e(qe,Ft),f(t,rt,d),f(t,B,d),e(B,Le),e(Le,L),e(L,Ce),e(Ce,zt),e(L,Ht),e(L,Ae),e(Ae,Rt),e(L,Wt),e(L,xe),e(xe,Vt),e(B,Kt),e(B,Oe),e(Oe,C),e(C,Ne),e(Ne,ae),e(ae,Jt),e(C,Yt),e(C,Me),e(Me,Ue),e(Ue,Qt),e(C,Xt),e(C,Pe),e(Pe,ie),e(ie,Zt),f(t,lt,d),f(t,A,d),e(A,F),e(F,Ge),y(ne,Ge,null),e(A,ea),e(A,Be),e(Be,ta),f(t,ct,d),y(se,t,d),f(t,pt,d),f(t,O,d),e(O,z),e(z,Fe),y(oe,Fe,null),e(O,aa),e(O,ze),e(ze,ia),f(t,dt,d),f(t,m,d),y(re,m,null),e(m,na),e(m,He),e(He,sa),e(m,oa),e(m,le),e(le,ra),e(le,we),e(we,la),e(le,ca),e(m,pa),e(m,S),y(ce,S,null),e(S,da),e(S,Re),e(Re,fa),e(S,ua),y(H,S,null),e(m,ma),e(m,R),y(pe,R,null),e(R,ha),e(R,b),e(b,ga),e(b,We),e(We,_a),e(b,ba),e(b,Ve),e(Ve,va),e(b,xa),e(b,Ke),e(Ke,Pa),e(b,wa),e(b,Je),e(Je,ya),e(b,Ia),e(m,ka),e(m,W),y(de,W,null),e(W,$a),e(W,N),e(N,Da),e(N,Ye),e(Ye,Ea),e(N,Sa),e(N,Qe),e(Qe,Ta),e(N,ja),ft=!0},p(t,[d]){const fe={};d&2&&(fe.$$scope={dirty:d,ctx:t}),H.$set(fe)},i(t){ft||(I(u.$$.fragment,t),I(K.$$.fragment,t),I(te.$$.fragment,t),I(ne.$$.fragment,t),I(se.$$.fragment,t),I(oe.$$.fragment,t),I(re.$$.fragment,t),I(ce.$$.fragment,t),I(H.$$.fragment,t),I(pe.$$.fragment,t),I(de.$$.fragment,t),ft=!0)},o(t){k(u.$$.fragment,t),k(K.$$.fragment,t),k(te.$$.fragment,t),k(ne.$$.fragment,t),k(se.$$.fragment,t),k(oe.$$.fragment,t),k(re.$$.fragment,t),k(ce.$$.fragment,t),k(H.$$.fragment,t),k(pe.$$.fragment,t),k(de.$$.fragment,t),ft=!1},d(t){a(h),t&&a(M),t&&a(_),$(u),t&&a(et),t&&a(j),$(K),t&&a(tt),t&&a(J),t&&a(at),t&&a(ue),t&&a(it),t&&a(me),t&&a(nt),t&&a(he),t&&a(st),t&&a(v),t&&a(ot),t&&a(q),$(te),t&&a(rt),t&&a(B),t&&a(lt),t&&a(A),$(ne),t&&a(ct),$(se,t),t&&a(pt),t&&a(O),$(oe),t&&a(dt),t&&a(m),$(re),$(ce),$(H),$(pe),$(de)}}}const Ni={local:"instructpix2pix-learning-to-follow-image-editing-instructions",sections:[{local:"overview",title:"Overview"},{local:"available-pipelines",title:"Available Pipelines:"},{local:"usage-example",title:"Usage example"},{local:"diffusers.StableDiffusionInstructPix2PixPipeline",title:"StableDiffusionInstructPix2PixPipeline"}],title:"InstructPix2Pix: Learning to Follow Image Editing Instructions"};function Mi(Ze){return qi(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Hi extends Ei{constructor(h){super();Si(this,h,Mi,Oi,Ti,{})}}export{Hi as default,Ni as metadata};
