import{S as Es,i as bs,s as Ps,e as a,k as u,w as m,t as l,M as ks,c as n,d as t,m as f,a as r,x as d,h as o,b as c,N as $s,G as i,g as p,y as h,L as As,q as _,o as g,B as v,v as Ds}from"../../chunks/vendor-hf-doc-builder.js";import{I as ze}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{C as A}from"../../chunks/CodeBlock-hf-doc-builder.js";function Is(ln){let D,Pt,I,N,Be,K,Pi,Ue,ki,kt,Q,V,Ai,Di,At,X,Z,on,Dt,Ie,Ii,It,ee,te,pn,qt,M,qi,We,Ti,ji,Tt,qe,Ye,w,Oi,Fe,Si,Ni,ie,Mi,Li,ae,Ci,Gi,ne,Hi,Ri,jt,q,L,Je,se,zi,Ke,Bi,Ot,T,C,Qe,re,Ui,Ve,Wi,St,Te,Yi,Nt,je,Xe,Fi,Mt,G,Ji,Ze,Ki,Qi,Lt,le,Ct,Oe,Vi,Gt,oe,Ht,H,Xi,pe,Zi,ea,Rt,ce,zt,Se,ta,Bt,ue,Ut,Ne,ia,Wt,fe,Yt,j,R,et,me,aa,tt,na,Ft,b,sa,de,ra,la,he,oa,pa,Jt,x,ca,it,ua,fa,at,ma,da,nt,ha,_a,Kt,_e,Qt,Me,ga,Vt,ge,Xt,z,va,st,wa,xa,Zt,ve,ei,y,ya,rt,$a,Ea,lt,ba,Pa,ot,ka,Aa,ti,we,xe,Da,Ia,ii,Le,pt,ct,qa,ai,O,B,ut,ye,Ta,ft,ja,ni,E,mt,Oa,Sa,$e,Na,Ma,dt,La,Ca,si,Ee,ri,S,U,ht,be,Ga,_t,Ha,li,Ce,Ra,oi,Pe,pi,W,za,ke,Ba,Ua,ci,Ge,Wa,ui,P,gt,vt,Ya,Fa,wt,xt,Ja,Ka,yt,$t,Qa,fi,$,Va,Et,Xa,Za,bt,en,tn,Ae,an,nn,mi;return K=new ze({}),se=new ze({}),re=new ze({}),le=new A({props:{code:`git clone https://github.com/huggingface/diffusers
cd diffusers
pip install -e .`,highlighted:`git <span class="hljs-built_in">clone</span> https://github.com/huggingface/diffusers
<span class="hljs-built_in">cd</span> diffusers
pip install -e .`}}),oe=new A({props:{code:"pip install -r requirements.txt",highlighted:"pip install -r requirements.txt"}}),ce=new A({props:{code:"accelerate config",highlighted:"accelerate config"}}),ue=new A({props:{code:"accelerate config default",highlighted:"accelerate config default"}}),fe=new A({props:{code:`from accelerate.utils import write_basic_config

write_basic_config()`,highlighted:`<span class="hljs-keyword">from</span> accelerate.utils <span class="hljs-keyword">import</span> write_basic_config

write_basic_config()`}}),me=new ze({}),_e=new A({props:{code:`export MODEL_NAME="runwayml/stable-diffusion-v1-5"
export DATASET_ID="fusing/instructpix2pix-1000-samples"`,highlighted:`<span class="hljs-built_in">export</span> MODEL_NAME=<span class="hljs-string">&quot;runwayml/stable-diffusion-v1-5&quot;</span>
<span class="hljs-built_in">export</span> DATASET_ID=<span class="hljs-string">&quot;fusing/instructpix2pix-1000-samples&quot;</span>`}}),ge=new A({props:{code:`accelerate launch --mixed_precision="fp16" train_instruct_pix2pix.py \\
    --pretrained_model_name_or_path=$MODEL_NAME \\
    --dataset_name=$DATASET_ID \\
    --enable_xformers_memory_efficient_attention \\
    --resolution=256 --random_flip \\
    --train_batch_size=4 --gradient_accumulation_steps=4 --gradient_checkpointing \\
    --max_train_steps=15000 \\
    --checkpointing_steps=5000 --checkpoints_total_limit=1 \\
    --learning_rate=5e-05 --max_grad_norm=1 --lr_warmup_steps=0 \\
    --conditioning_dropout_prob=0.05 \\
    --mixed_precision=fp16 \\
    --seed=42 `,highlighted:`accelerate launch --mixed_precision=<span class="hljs-string">&quot;fp16&quot;</span> train_instruct_pix2pix.py \\
    --pretrained_model_name_or_path=<span class="hljs-variable">$MODEL_NAME</span> \\
    --dataset_name=<span class="hljs-variable">$DATASET_ID</span> \\
    --enable_xformers_memory_efficient_attention \\
    --resolution=256 --random_flip \\
    --train_batch_size=4 --gradient_accumulation_steps=4 --gradient_checkpointing \\
    --max_train_steps=15000 \\
    --checkpointing_steps=5000 --checkpoints_total_limit=1 \\
    --learning_rate=5e-05 --max_grad_norm=1 --lr_warmup_steps=0 \\
    --conditioning_dropout_prob=0.05 \\
    --mixed_precision=fp16 \\
    --seed=42 `}}),ve=new A({props:{code:`accelerate launch --mixed_precision="fp16" train_instruct_pix2pix.py \\
    --pretrained_model_name_or_path=$MODEL_NAME \\
    --dataset_name=$DATASET_ID \\
    --enable_xformers_memory_efficient_attention \\
    --resolution=256 --random_flip \\
    --train_batch_size=4 --gradient_accumulation_steps=4 --gradient_checkpointing \\
    --max_train_steps=15000 \\
    --checkpointing_steps=5000 --checkpoints_total_limit=1 \\
    --learning_rate=5e-05 --max_grad_norm=1 --lr_warmup_steps=0 \\
    --conditioning_dropout_prob=0.05 \\
    --mixed_precision=fp16 \\
    --val_image_url="https://hf.co/datasets/diffusers/diffusers-images-docs/resolve/main/mountain.png" \\
    --validation_prompt="make the mountains snowy" \\
    --seed=42 \\
    --report_to=wandb `,highlighted:`accelerate launch --mixed_precision=<span class="hljs-string">&quot;fp16&quot;</span> train_instruct_pix2pix.py \\
    --pretrained_model_name_or_path=<span class="hljs-variable">$MODEL_NAME</span> \\
    --dataset_name=<span class="hljs-variable">$DATASET_ID</span> \\
    --enable_xformers_memory_efficient_attention \\
    --resolution=256 --random_flip \\
    --train_batch_size=4 --gradient_accumulation_steps=4 --gradient_checkpointing \\
    --max_train_steps=15000 \\
    --checkpointing_steps=5000 --checkpoints_total_limit=1 \\
    --learning_rate=5e-05 --max_grad_norm=1 --lr_warmup_steps=0 \\
    --conditioning_dropout_prob=0.05 \\
    --mixed_precision=fp16 \\
    --val_image_url=<span class="hljs-string">&quot;https://hf.co/datasets/diffusers/diffusers-images-docs/resolve/main/mountain.png&quot;</span> \\
    --validation_prompt=<span class="hljs-string">&quot;make the mountains snowy&quot;</span> \\
    --seed=42 \\
    --report_to=wandb `}}),ye=new ze({}),Ee=new A({props:{code:`accelerate launch --mixed_precision="fp16" --multi_gpu train_instruct_pix2pix.py \\
 --pretrained_model_name_or_path=runwayml/stable-diffusion-v1-5 \\
 --dataset_name=sayakpaul/instructpix2pix-1000-samples \\
 --use_ema \\
 --enable_xformers_memory_efficient_attention \\
 --resolution=512 --random_flip \\
 --train_batch_size=4 --gradient_accumulation_steps=4 --gradient_checkpointing \\
 --max_train_steps=15000 \\
 --checkpointing_steps=5000 --checkpoints_total_limit=1 \\
 --learning_rate=5e-05 --lr_warmup_steps=0 \\
 --conditioning_dropout_prob=0.05 \\
 --mixed_precision=fp16 \\
 --seed=42 `,highlighted:`accelerate launch --mixed_precision=<span class="hljs-string">&quot;fp16&quot;</span> --multi_gpu train_instruct_pix2pix.py \\
 --pretrained_model_name_or_path=runwayml/stable-diffusion-v1-5 \\
 --dataset_name=sayakpaul/instructpix2pix-1000-samples \\
 --use_ema \\
 --enable_xformers_memory_efficient_attention \\
 --resolution=512 --random_flip \\
 --train_batch_size=4 --gradient_accumulation_steps=4 --gradient_checkpointing \\
 --max_train_steps=15000 \\
 --checkpointing_steps=5000 --checkpoints_total_limit=1 \\
 --learning_rate=5e-05 --lr_warmup_steps=0 \\
 --conditioning_dropout_prob=0.05 \\
 --mixed_precision=fp16 \\
 --seed=42 `}}),be=new ze({}),Pe=new A({props:{code:`import PIL
import requests
import torch
from diffusers import StableDiffusionInstructPix2PixPipeline

model_id = "your_model_id"  # <- replace this
pipe = StableDiffusionInstructPix2PixPipeline.from_pretrained(model_id, torch_dtype=torch.float16).to("cuda")
generator = torch.Generator("cuda").manual_seed(0)

url = "https://huggingface.co/datasets/sayakpaul/sample-datasets/resolve/main/test_pix2pix_4.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 = "wipe out the lake"
num_inference_steps = 20
image_guidance_scale = 1.5
guidance_scale = 10

edited_image = pipe(
   prompt,
   image=image,
   num_inference_steps=num_inference_steps,
   image_guidance_scale=image_guidance_scale,
   guidance_scale=guidance_scale,
   generator=generator,
).images[0]
edited_image.save("edited_image.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;your_model_id&quot;</span>  <span class="hljs-comment"># &lt;- replace this</span>
pipe = StableDiffusionInstructPix2PixPipeline.from_pretrained(model_id, torch_dtype=torch.float16).to(<span class="hljs-string">&quot;cuda&quot;</span>)
generator = torch.Generator(<span class="hljs-string">&quot;cuda&quot;</span>).manual_seed(<span class="hljs-number">0</span>)

url = <span class="hljs-string">&quot;https://huggingface.co/datasets/sayakpaul/sample-datasets/resolve/main/test_pix2pix_4.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;wipe out the lake&quot;</span>
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">10</span>

edited_image = pipe(
   prompt,
   image=image,
   num_inference_steps=num_inference_steps,
   image_guidance_scale=image_guidance_scale,
   guidance_scale=guidance_scale,
   generator=generator,
).images[<span class="hljs-number">0</span>]
edited_image.save(<span class="hljs-string">&quot;edited_image.png&quot;</span>)`}}),{c(){D=a("meta"),Pt=u(),I=a("h1"),N=a("a"),Be=a("span"),m(K.$$.fragment),Pi=u(),Ue=a("span"),ki=l("InstructPix2Pix"),kt=u(),Q=a("p"),V=a("a"),Ai=l("InstructPix2Pix"),Di=l(" is a method to fine-tune text-conditioned diffusion models such that they can follow an edit instruction for an input image. Models fine-tuned using this method take the following as inputs:"),At=u(),X=a("p"),Z=a("img"),Dt=u(),Ie=a("p"),Ii=l("The output is an \u201Cedited\u201D image that reflects the edit instruction applied on the input image:"),It=u(),ee=a("p"),te=a("img"),qt=u(),M=a("p"),qi=l("The "),We=a("code"),Ti=l("train_instruct_pix2pix.py"),ji=l(" script shows how to implement the training procedure and adapt it for Stable Diffusion."),Tt=u(),qe=a("p"),Ye=a("strong"),w=a("em"),Oi=l("Disclaimer: Even though "),Fe=a("code"),Si=l("train_instruct_pix2pix.py"),Ni=l(` implements the InstructPix2Pix
training procedure while being faithful to the `),ie=a("a"),Mi=l("original implementation"),Li=l(" we have only tested it on a "),ae=a("a"),Ci=l("small-scale dataset"),Gi=l(". This can impact the end results. For better results, we recommend longer training runs with a larger dataset. "),ne=a("a"),Hi=l("Here"),Ri=l(" you can find a large dataset for InstructPix2Pix training."),jt=u(),q=a("h2"),L=a("a"),Je=a("span"),m(se.$$.fragment),zi=u(),Ke=a("span"),Bi=l("Running locally with PyTorch"),Ot=u(),T=a("h3"),C=a("a"),Qe=a("span"),m(re.$$.fragment),Ui=u(),Ve=a("span"),Wi=l("Installing the dependencies"),St=u(),Te=a("p"),Yi=l("Before running the scripts, make sure to install the library\u2019s training dependencies:"),Nt=u(),je=a("p"),Xe=a("strong"),Fi=l("Important"),Mt=u(),G=a("p"),Ji=l("To make sure you can successfully run the latest versions of the example scripts, we highly recommend "),Ze=a("strong"),Ki=l("installing from source"),Qi=l(" and keeping the install up to date as we update the example scripts frequently and install some example-specific requirements. To do this, execute the following steps in a new virtual environment:"),Lt=u(),m(le.$$.fragment),Ct=u(),Oe=a("p"),Vi=l("Then cd in the example folder and run"),Gt=u(),m(oe.$$.fragment),Ht=u(),H=a("p"),Xi=l("And initialize an "),pe=a("a"),Zi=l("\u{1F917}Accelerate"),ea=l(" environment with:"),Rt=u(),m(ce.$$.fragment),zt=u(),Se=a("p"),ta=l("Or for a default accelerate configuration without answering questions about your environment"),Bt=u(),m(ue.$$.fragment),Ut=u(),Ne=a("p"),ia=l("Or if your environment doesn\u2019t support an interactive shell e.g. a notebook"),Wt=u(),m(fe.$$.fragment),Yt=u(),j=a("h3"),R=a("a"),et=a("span"),m(me.$$.fragment),aa=u(),tt=a("span"),na=l("Toy example"),Ft=u(),b=a("p"),sa=l("As mentioned before, we\u2019ll use a "),de=a("a"),ra=l("small toy dataset"),la=l(` for training. The dataset
is a smaller version of the `),he=a("a"),oa=l("original dataset"),pa=l(" used in the InstructPix2Pix paper."),Jt=u(),x=a("p"),ca=l("Specify the "),it=a("code"),ua=l("MODEL_NAME"),fa=l(" environment variable (either a Hub model repository id or a path to the directory containing the model weights) and pass it to the "),at=a("code"),ma=l("~diffusers.DiffusionPipeline.from_pretrained.pretrained_model_name_or_path"),da=l(" argument. You\u2019ll also need to specify the dataset name in "),nt=a("code"),ha=l("DATASET_ID"),_a=l(":"),Kt=u(),m(_e.$$.fragment),Qt=u(),Me=a("p"),ga=l("Now, we can launch training:"),Vt=u(),m(ge.$$.fragment),Xt=u(),z=a("p"),va=l(`Additionally, we support performing validation inference to monitor training progress
with Weights and Biases. You can enable this feature with `),st=a("code"),wa=l('report_to="wandb"'),xa=l(":"),Zt=u(),m(ve.$$.fragment),ei=u(),y=a("p"),ya=l("We recommend this type of validation as it can be useful for model debugging. Note that you need "),rt=a("code"),$a=l("wandb"),Ea=l(" installed to use this. You can install "),lt=a("code"),ba=l("wandb"),Pa=l(" by running "),ot=a("code"),ka=l("pip install wandb"),Aa=l("."),ti=u(),we=a("p"),xe=a("a"),Da=l("Here"),Ia=l(", you can find an example training run that includes some validation samples and the training hyperparameters."),ii=u(),Le=a("p"),pt=a("strong"),ct=a("em"),qa=l("Note: In the original paper, the authors observed that even when the model is trained with an image resolution of 256x256, it generalizes well to bigger resolutions such as 512x512. This is likely because of the larger dataset they used during training."),ai=u(),O=a("h2"),B=a("a"),ut=a("span"),m(ye.$$.fragment),Ta=u(),ft=a("span"),ja=l("Training with multiple GPUs"),ni=u(),E=a("p"),mt=a("code"),Oa=l("accelerate"),Sa=l(" allows for seamless multi-GPU training. Follow the instructions "),$e=a("a"),Na=l("here"),Ma=l(`
for running distributed training with `),dt=a("code"),La=l("accelerate"),Ca=l(". Here is an example command:"),si=u(),m(Ee.$$.fragment),ri=u(),S=a("h2"),U=a("a"),ht=a("span"),m(be.$$.fragment),Ga=u(),_t=a("span"),Ha=l("Inference"),li=u(),Ce=a("p"),Ra=l("Once training is complete, we can perform inference:"),oi=u(),m(Pe.$$.fragment),pi=u(),W=a("p"),za=l(`An example model repo obtained using this training script can be found
here - `),ke=a("a"),Ba=l("sayakpaul/instruct-pix2pix"),Ua=l("."),ci=u(),Ge=a("p"),Wa=l(`We encourage you to play with the following three parameters to control
speed and quality during performance:`),ui=u(),P=a("ul"),gt=a("li"),vt=a("code"),Ya=l("num_inference_steps"),Fa=u(),wt=a("li"),xt=a("code"),Ja=l("image_guidance_scale"),Ka=u(),yt=a("li"),$t=a("code"),Qa=l("guidance_scale"),fi=u(),$=a("p"),Va=l("Particularly, "),Et=a("code"),Xa=l("image_guidance_scale"),Za=l(" and "),bt=a("code"),en=l("guidance_scale"),tn=l(` can have a profound impact
on the generated (\u201Cedited\u201D) image (see `),Ae=a("a"),an=l("here"),nn=l(" for an example)."),this.h()},l(e){const s=ks('[data-svelte="svelte-1phssyn"]',document.head);D=n(s,"META",{name:!0,content:!0}),s.forEach(t),Pt=f(e),I=n(e,"H1",{class:!0});var di=r(I);N=n(di,"A",{id:!0,class:!0,href:!0});var cn=r(N);Be=n(cn,"SPAN",{});var un=r(Be);d(K.$$.fragment,un),un.forEach(t),cn.forEach(t),Pi=f(di),Ue=n(di,"SPAN",{});var fn=r(Ue);ki=o(fn,"InstructPix2Pix"),fn.forEach(t),di.forEach(t),kt=f(e),Q=n(e,"P",{});var sn=r(Q);V=n(sn,"A",{href:!0,rel:!0});var mn=r(V);Ai=o(mn,"InstructPix2Pix"),mn.forEach(t),Di=o(sn," is a method to fine-tune text-conditioned diffusion models such that they can follow an edit instruction for an input image. Models fine-tuned using this method take the following as inputs:"),sn.forEach(t),At=f(e),X=n(e,"P",{align:!0});var dn=r(X);Z=n(dn,"IMG",{src:!0,alt:!0,width:!0}),dn.forEach(t),Dt=f(e),Ie=n(e,"P",{});var hn=r(Ie);Ii=o(hn,"The output is an \u201Cedited\u201D image that reflects the edit instruction applied on the input image:"),hn.forEach(t),It=f(e),ee=n(e,"P",{align:!0});var _n=r(ee);te=n(_n,"IMG",{src:!0,alt:!0,width:!0}),_n.forEach(t),qt=f(e),M=n(e,"P",{});var hi=r(M);qi=o(hi,"The "),We=n(hi,"CODE",{});var gn=r(We);Ti=o(gn,"train_instruct_pix2pix.py"),gn.forEach(t),ji=o(hi," script shows how to implement the training procedure and adapt it for Stable Diffusion."),hi.forEach(t),Tt=f(e),qe=n(e,"P",{});var vn=r(qe);Ye=n(vn,"STRONG",{});var wn=r(Ye);w=n(wn,"EM",{});var k=r(w);Oi=o(k,"Disclaimer: Even though "),Fe=n(k,"CODE",{});var xn=r(Fe);Si=o(xn,"train_instruct_pix2pix.py"),xn.forEach(t),Ni=o(k,` implements the InstructPix2Pix
training procedure while being faithful to the `),ie=n(k,"A",{href:!0,rel:!0});var yn=r(ie);Mi=o(yn,"original implementation"),yn.forEach(t),Li=o(k," we have only tested it on a "),ae=n(k,"A",{href:!0,rel:!0});var $n=r(ae);Ci=o($n,"small-scale dataset"),$n.forEach(t),Gi=o(k,". This can impact the end results. For better results, we recommend longer training runs with a larger dataset. "),ne=n(k,"A",{href:!0,rel:!0});var En=r(ne);Hi=o(En,"Here"),En.forEach(t),Ri=o(k," you can find a large dataset for InstructPix2Pix training."),k.forEach(t),wn.forEach(t),vn.forEach(t),jt=f(e),q=n(e,"H2",{class:!0});var _i=r(q);L=n(_i,"A",{id:!0,class:!0,href:!0});var bn=r(L);Je=n(bn,"SPAN",{});var Pn=r(Je);d(se.$$.fragment,Pn),Pn.forEach(t),bn.forEach(t),zi=f(_i),Ke=n(_i,"SPAN",{});var kn=r(Ke);Bi=o(kn,"Running locally with PyTorch"),kn.forEach(t),_i.forEach(t),Ot=f(e),T=n(e,"H3",{class:!0});var gi=r(T);C=n(gi,"A",{id:!0,class:!0,href:!0});var An=r(C);Qe=n(An,"SPAN",{});var Dn=r(Qe);d(re.$$.fragment,Dn),Dn.forEach(t),An.forEach(t),Ui=f(gi),Ve=n(gi,"SPAN",{});var In=r(Ve);Wi=o(In,"Installing the dependencies"),In.forEach(t),gi.forEach(t),St=f(e),Te=n(e,"P",{});var qn=r(Te);Yi=o(qn,"Before running the scripts, make sure to install the library\u2019s training dependencies:"),qn.forEach(t),Nt=f(e),je=n(e,"P",{});var Tn=r(je);Xe=n(Tn,"STRONG",{});var jn=r(Xe);Fi=o(jn,"Important"),jn.forEach(t),Tn.forEach(t),Mt=f(e),G=n(e,"P",{});var vi=r(G);Ji=o(vi,"To make sure you can successfully run the latest versions of the example scripts, we highly recommend "),Ze=n(vi,"STRONG",{});var On=r(Ze);Ki=o(On,"installing from source"),On.forEach(t),Qi=o(vi," and keeping the install up to date as we update the example scripts frequently and install some example-specific requirements. To do this, execute the following steps in a new virtual environment:"),vi.forEach(t),Lt=f(e),d(le.$$.fragment,e),Ct=f(e),Oe=n(e,"P",{});var Sn=r(Oe);Vi=o(Sn,"Then cd in the example folder and run"),Sn.forEach(t),Gt=f(e),d(oe.$$.fragment,e),Ht=f(e),H=n(e,"P",{});var wi=r(H);Xi=o(wi,"And initialize an "),pe=n(wi,"A",{href:!0,rel:!0});var Nn=r(pe);Zi=o(Nn,"\u{1F917}Accelerate"),Nn.forEach(t),ea=o(wi," environment with:"),wi.forEach(t),Rt=f(e),d(ce.$$.fragment,e),zt=f(e),Se=n(e,"P",{});var Mn=r(Se);ta=o(Mn,"Or for a default accelerate configuration without answering questions about your environment"),Mn.forEach(t),Bt=f(e),d(ue.$$.fragment,e),Ut=f(e),Ne=n(e,"P",{});var Ln=r(Ne);ia=o(Ln,"Or if your environment doesn\u2019t support an interactive shell e.g. a notebook"),Ln.forEach(t),Wt=f(e),d(fe.$$.fragment,e),Yt=f(e),j=n(e,"H3",{class:!0});var xi=r(j);R=n(xi,"A",{id:!0,class:!0,href:!0});var Cn=r(R);et=n(Cn,"SPAN",{});var Gn=r(et);d(me.$$.fragment,Gn),Gn.forEach(t),Cn.forEach(t),aa=f(xi),tt=n(xi,"SPAN",{});var Hn=r(tt);na=o(Hn,"Toy example"),Hn.forEach(t),xi.forEach(t),Ft=f(e),b=n(e,"P",{});var He=r(b);sa=o(He,"As mentioned before, we\u2019ll use a "),de=n(He,"A",{href:!0,rel:!0});var Rn=r(de);ra=o(Rn,"small toy dataset"),Rn.forEach(t),la=o(He,` for training. The dataset
is a smaller version of the `),he=n(He,"A",{href:!0,rel:!0});var zn=r(he);oa=o(zn,"original dataset"),zn.forEach(t),pa=o(He," used in the InstructPix2Pix paper."),He.forEach(t),Jt=f(e),x=n(e,"P",{});var Y=r(x);ca=o(Y,"Specify the "),it=n(Y,"CODE",{});var Bn=r(it);ua=o(Bn,"MODEL_NAME"),Bn.forEach(t),fa=o(Y," environment variable (either a Hub model repository id or a path to the directory containing the model weights) and pass it to the "),at=n(Y,"CODE",{});var Un=r(at);ma=o(Un,"~diffusers.DiffusionPipeline.from_pretrained.pretrained_model_name_or_path"),Un.forEach(t),da=o(Y," argument. You\u2019ll also need to specify the dataset name in "),nt=n(Y,"CODE",{});var Wn=r(nt);ha=o(Wn,"DATASET_ID"),Wn.forEach(t),_a=o(Y,":"),Y.forEach(t),Kt=f(e),d(_e.$$.fragment,e),Qt=f(e),Me=n(e,"P",{});var Yn=r(Me);ga=o(Yn,"Now, we can launch training:"),Yn.forEach(t),Vt=f(e),d(ge.$$.fragment,e),Xt=f(e),z=n(e,"P",{});var yi=r(z);va=o(yi,`Additionally, we support performing validation inference to monitor training progress
with Weights and Biases. You can enable this feature with `),st=n(yi,"CODE",{});var Fn=r(st);wa=o(Fn,'report_to="wandb"'),Fn.forEach(t),xa=o(yi,":"),yi.forEach(t),Zt=f(e),d(ve.$$.fragment,e),ei=f(e),y=n(e,"P",{});var F=r(y);ya=o(F,"We recommend this type of validation as it can be useful for model debugging. Note that you need "),rt=n(F,"CODE",{});var Jn=r(rt);$a=o(Jn,"wandb"),Jn.forEach(t),Ea=o(F," installed to use this. You can install "),lt=n(F,"CODE",{});var Kn=r(lt);ba=o(Kn,"wandb"),Kn.forEach(t),Pa=o(F," by running "),ot=n(F,"CODE",{});var Qn=r(ot);ka=o(Qn,"pip install wandb"),Qn.forEach(t),Aa=o(F,"."),F.forEach(t),ti=f(e),we=n(e,"P",{});var rn=r(we);xe=n(rn,"A",{href:!0,rel:!0});var Vn=r(xe);Da=o(Vn,"Here"),Vn.forEach(t),Ia=o(rn,", you can find an example training run that includes some validation samples and the training hyperparameters."),rn.forEach(t),ii=f(e),Le=n(e,"P",{});var Xn=r(Le);pt=n(Xn,"STRONG",{});var Zn=r(pt);ct=n(Zn,"EM",{});var es=r(ct);qa=o(es,"Note: In the original paper, the authors observed that even when the model is trained with an image resolution of 256x256, it generalizes well to bigger resolutions such as 512x512. This is likely because of the larger dataset they used during training."),es.forEach(t),Zn.forEach(t),Xn.forEach(t),ai=f(e),O=n(e,"H2",{class:!0});var $i=r(O);B=n($i,"A",{id:!0,class:!0,href:!0});var ts=r(B);ut=n(ts,"SPAN",{});var is=r(ut);d(ye.$$.fragment,is),is.forEach(t),ts.forEach(t),Ta=f($i),ft=n($i,"SPAN",{});var as=r(ft);ja=o(as,"Training with multiple GPUs"),as.forEach(t),$i.forEach(t),ni=f(e),E=n(e,"P",{});var De=r(E);mt=n(De,"CODE",{});var ns=r(mt);Oa=o(ns,"accelerate"),ns.forEach(t),Sa=o(De," allows for seamless multi-GPU training. Follow the instructions "),$e=n(De,"A",{href:!0,rel:!0});var ss=r($e);Na=o(ss,"here"),ss.forEach(t),Ma=o(De,`
for running distributed training with `),dt=n(De,"CODE",{});var rs=r(dt);La=o(rs,"accelerate"),rs.forEach(t),Ca=o(De,". Here is an example command:"),De.forEach(t),si=f(e),d(Ee.$$.fragment,e),ri=f(e),S=n(e,"H2",{class:!0});var Ei=r(S);U=n(Ei,"A",{id:!0,class:!0,href:!0});var ls=r(U);ht=n(ls,"SPAN",{});var os=r(ht);d(be.$$.fragment,os),os.forEach(t),ls.forEach(t),Ga=f(Ei),_t=n(Ei,"SPAN",{});var ps=r(_t);Ha=o(ps,"Inference"),ps.forEach(t),Ei.forEach(t),li=f(e),Ce=n(e,"P",{});var cs=r(Ce);Ra=o(cs,"Once training is complete, we can perform inference:"),cs.forEach(t),oi=f(e),d(Pe.$$.fragment,e),pi=f(e),W=n(e,"P",{});var bi=r(W);za=o(bi,`An example model repo obtained using this training script can be found
here - `),ke=n(bi,"A",{href:!0,rel:!0});var us=r(ke);Ba=o(us,"sayakpaul/instruct-pix2pix"),us.forEach(t),Ua=o(bi,"."),bi.forEach(t),ci=f(e),Ge=n(e,"P",{});var fs=r(Ge);Wa=o(fs,`We encourage you to play with the following three parameters to control
speed and quality during performance:`),fs.forEach(t),ui=f(e),P=n(e,"UL",{});var Re=r(P);gt=n(Re,"LI",{});var ms=r(gt);vt=n(ms,"CODE",{});var ds=r(vt);Ya=o(ds,"num_inference_steps"),ds.forEach(t),ms.forEach(t),Fa=f(Re),wt=n(Re,"LI",{});var hs=r(wt);xt=n(hs,"CODE",{});var _s=r(xt);Ja=o(_s,"image_guidance_scale"),_s.forEach(t),hs.forEach(t),Ka=f(Re),yt=n(Re,"LI",{});var gs=r(yt);$t=n(gs,"CODE",{});var vs=r($t);Qa=o(vs,"guidance_scale"),vs.forEach(t),gs.forEach(t),Re.forEach(t),fi=f(e),$=n(e,"P",{});var J=r($);Va=o(J,"Particularly, "),Et=n(J,"CODE",{});var ws=r(Et);Xa=o(ws,"image_guidance_scale"),ws.forEach(t),Za=o(J," and "),bt=n(J,"CODE",{});var xs=r(bt);en=o(xs,"guidance_scale"),xs.forEach(t),tn=o(J,` can have a profound impact
on the generated (\u201Cedited\u201D) image (see `),Ae=n(J,"A",{href:!0,rel:!0});var ys=r(Ae);an=o(ys,"here"),ys.forEach(t),nn=o(J," for an example)."),J.forEach(t),this.h()},h(){c(D,"name","hf:doc:metadata"),c(D,"content",JSON.stringify(qs)),c(N,"id","instructpix2pix"),c(N,"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"),c(N,"href","#instructpix2pix"),c(I,"class","relative group"),c(V,"href","https://arxiv.org/abs/2211.09800"),c(V,"rel","nofollow"),$s(Z.src,on="https://huggingface.co/datasets/diffusers/docs-images/resolve/main/evaluation_diffusion_models/edit-instruction.png")||c(Z,"src",on),c(Z,"alt","instructpix2pix-inputs"),c(Z,"width","600"),c(X,"align","center"),$s(te.src,pn="https://huggingface.co/datasets/diffusers/docs-images/resolve/main/output-gs%407-igs%401-steps%4050.png")||c(te,"src",pn),c(te,"alt","instructpix2pix-output"),c(te,"width","600"),c(ee,"align","center"),c(ie,"href","https://github.com/timothybrooks/instruct-pix2pix"),c(ie,"rel","nofollow"),c(ae,"href","https://huggingface.co/datasets/fusing/instructpix2pix-1000-samples"),c(ae,"rel","nofollow"),c(ne,"href","https://huggingface.co/datasets/timbrooks/instructpix2pix-clip-filtered"),c(ne,"rel","nofollow"),c(L,"id","running-locally-with-pytorch"),c(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"),c(L,"href","#running-locally-with-pytorch"),c(q,"class","relative group"),c(C,"id","installing-the-dependencies"),c(C,"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"),c(C,"href","#installing-the-dependencies"),c(T,"class","relative group"),c(pe,"href","https://github.com/huggingface/accelerate/"),c(pe,"rel","nofollow"),c(R,"id","toy-example"),c(R,"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"),c(R,"href","#toy-example"),c(j,"class","relative group"),c(de,"href","https://huggingface.co/datasets/fusing/instructpix2pix-1000-samples"),c(de,"rel","nofollow"),c(he,"href","https://huggingface.co/datasets/timbrooks/instructpix2pix-clip-filtered"),c(he,"rel","nofollow"),c(xe,"href","https://wandb.ai/sayakpaul/instruct-pix2pix/runs/ctr3kovq"),c(xe,"rel","nofollow"),c(B,"id","training-with-multiple-gpus"),c(B,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),c(B,"href","#training-with-multiple-gpus"),c(O,"class","relative group"),c($e,"href","https://huggingface.co/docs/accelerate/basic_tutorials/launch"),c($e,"rel","nofollow"),c(U,"id","inference"),c(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"),c(U,"href","#inference"),c(S,"class","relative group"),c(ke,"href","https://huggingface.co/sayakpaul/instruct-pix2pix"),c(ke,"rel","nofollow"),c(Ae,"href","https://twitter.com/RisingSayak/status/1628392199196151808?s=20"),c(Ae,"rel","nofollow")},m(e,s){i(document.head,D),p(e,Pt,s),p(e,I,s),i(I,N),i(N,Be),h(K,Be,null),i(I,Pi),i(I,Ue),i(Ue,ki),p(e,kt,s),p(e,Q,s),i(Q,V),i(V,Ai),i(Q,Di),p(e,At,s),p(e,X,s),i(X,Z),p(e,Dt,s),p(e,Ie,s),i(Ie,Ii),p(e,It,s),p(e,ee,s),i(ee,te),p(e,qt,s),p(e,M,s),i(M,qi),i(M,We),i(We,Ti),i(M,ji),p(e,Tt,s),p(e,qe,s),i(qe,Ye),i(Ye,w),i(w,Oi),i(w,Fe),i(Fe,Si),i(w,Ni),i(w,ie),i(ie,Mi),i(w,Li),i(w,ae),i(ae,Ci),i(w,Gi),i(w,ne),i(ne,Hi),i(w,Ri),p(e,jt,s),p(e,q,s),i(q,L),i(L,Je),h(se,Je,null),i(q,zi),i(q,Ke),i(Ke,Bi),p(e,Ot,s),p(e,T,s),i(T,C),i(C,Qe),h(re,Qe,null),i(T,Ui),i(T,Ve),i(Ve,Wi),p(e,St,s),p(e,Te,s),i(Te,Yi),p(e,Nt,s),p(e,je,s),i(je,Xe),i(Xe,Fi),p(e,Mt,s),p(e,G,s),i(G,Ji),i(G,Ze),i(Ze,Ki),i(G,Qi),p(e,Lt,s),h(le,e,s),p(e,Ct,s),p(e,Oe,s),i(Oe,Vi),p(e,Gt,s),h(oe,e,s),p(e,Ht,s),p(e,H,s),i(H,Xi),i(H,pe),i(pe,Zi),i(H,ea),p(e,Rt,s),h(ce,e,s),p(e,zt,s),p(e,Se,s),i(Se,ta),p(e,Bt,s),h(ue,e,s),p(e,Ut,s),p(e,Ne,s),i(Ne,ia),p(e,Wt,s),h(fe,e,s),p(e,Yt,s),p(e,j,s),i(j,R),i(R,et),h(me,et,null),i(j,aa),i(j,tt),i(tt,na),p(e,Ft,s),p(e,b,s),i(b,sa),i(b,de),i(de,ra),i(b,la),i(b,he),i(he,oa),i(b,pa),p(e,Jt,s),p(e,x,s),i(x,ca),i(x,it),i(it,ua),i(x,fa),i(x,at),i(at,ma),i(x,da),i(x,nt),i(nt,ha),i(x,_a),p(e,Kt,s),h(_e,e,s),p(e,Qt,s),p(e,Me,s),i(Me,ga),p(e,Vt,s),h(ge,e,s),p(e,Xt,s),p(e,z,s),i(z,va),i(z,st),i(st,wa),i(z,xa),p(e,Zt,s),h(ve,e,s),p(e,ei,s),p(e,y,s),i(y,ya),i(y,rt),i(rt,$a),i(y,Ea),i(y,lt),i(lt,ba),i(y,Pa),i(y,ot),i(ot,ka),i(y,Aa),p(e,ti,s),p(e,we,s),i(we,xe),i(xe,Da),i(we,Ia),p(e,ii,s),p(e,Le,s),i(Le,pt),i(pt,ct),i(ct,qa),p(e,ai,s),p(e,O,s),i(O,B),i(B,ut),h(ye,ut,null),i(O,Ta),i(O,ft),i(ft,ja),p(e,ni,s),p(e,E,s),i(E,mt),i(mt,Oa),i(E,Sa),i(E,$e),i($e,Na),i(E,Ma),i(E,dt),i(dt,La),i(E,Ca),p(e,si,s),h(Ee,e,s),p(e,ri,s),p(e,S,s),i(S,U),i(U,ht),h(be,ht,null),i(S,Ga),i(S,_t),i(_t,Ha),p(e,li,s),p(e,Ce,s),i(Ce,Ra),p(e,oi,s),h(Pe,e,s),p(e,pi,s),p(e,W,s),i(W,za),i(W,ke),i(ke,Ba),i(W,Ua),p(e,ci,s),p(e,Ge,s),i(Ge,Wa),p(e,ui,s),p(e,P,s),i(P,gt),i(gt,vt),i(vt,Ya),i(P,Fa),i(P,wt),i(wt,xt),i(xt,Ja),i(P,Ka),i(P,yt),i(yt,$t),i($t,Qa),p(e,fi,s),p(e,$,s),i($,Va),i($,Et),i(Et,Xa),i($,Za),i($,bt),i(bt,en),i($,tn),i($,Ae),i(Ae,an),i($,nn),mi=!0},p:As,i(e){mi||(_(K.$$.fragment,e),_(se.$$.fragment,e),_(re.$$.fragment,e),_(le.$$.fragment,e),_(oe.$$.fragment,e),_(ce.$$.fragment,e),_(ue.$$.fragment,e),_(fe.$$.fragment,e),_(me.$$.fragment,e),_(_e.$$.fragment,e),_(ge.$$.fragment,e),_(ve.$$.fragment,e),_(ye.$$.fragment,e),_(Ee.$$.fragment,e),_(be.$$.fragment,e),_(Pe.$$.fragment,e),mi=!0)},o(e){g(K.$$.fragment,e),g(se.$$.fragment,e),g(re.$$.fragment,e),g(le.$$.fragment,e),g(oe.$$.fragment,e),g(ce.$$.fragment,e),g(ue.$$.fragment,e),g(fe.$$.fragment,e),g(me.$$.fragment,e),g(_e.$$.fragment,e),g(ge.$$.fragment,e),g(ve.$$.fragment,e),g(ye.$$.fragment,e),g(Ee.$$.fragment,e),g(be.$$.fragment,e),g(Pe.$$.fragment,e),mi=!1},d(e){t(D),e&&t(Pt),e&&t(I),v(K),e&&t(kt),e&&t(Q),e&&t(At),e&&t(X),e&&t(Dt),e&&t(Ie),e&&t(It),e&&t(ee),e&&t(qt),e&&t(M),e&&t(Tt),e&&t(qe),e&&t(jt),e&&t(q),v(se),e&&t(Ot),e&&t(T),v(re),e&&t(St),e&&t(Te),e&&t(Nt),e&&t(je),e&&t(Mt),e&&t(G),e&&t(Lt),v(le,e),e&&t(Ct),e&&t(Oe),e&&t(Gt),v(oe,e),e&&t(Ht),e&&t(H),e&&t(Rt),v(ce,e),e&&t(zt),e&&t(Se),e&&t(Bt),v(ue,e),e&&t(Ut),e&&t(Ne),e&&t(Wt),v(fe,e),e&&t(Yt),e&&t(j),v(me),e&&t(Ft),e&&t(b),e&&t(Jt),e&&t(x),e&&t(Kt),v(_e,e),e&&t(Qt),e&&t(Me),e&&t(Vt),v(ge,e),e&&t(Xt),e&&t(z),e&&t(Zt),v(ve,e),e&&t(ei),e&&t(y),e&&t(ti),e&&t(we),e&&t(ii),e&&t(Le),e&&t(ai),e&&t(O),v(ye),e&&t(ni),e&&t(E),e&&t(si),v(Ee,e),e&&t(ri),e&&t(S),v(be),e&&t(li),e&&t(Ce),e&&t(oi),v(Pe,e),e&&t(pi),e&&t(W),e&&t(ci),e&&t(Ge),e&&t(ui),e&&t(P),e&&t(fi),e&&t($)}}}const qs={local:"instructpix2pix",sections:[{local:"running-locally-with-pytorch",sections:[{local:"installing-the-dependencies",title:"Installing the dependencies"},{local:"toy-example",title:"Toy example"}],title:"Running locally with PyTorch"}],title:"InstructPix2Pix "};function Ts(ln){return Ds(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Ns extends Es{constructor(D){super();bs(this,D,Ts,Is,Ps,{})}}export{Ns as default,qs as metadata};
