import{S as $n,i as En,s as yn,e as s,k as f,w as h,t as i,M as kn,c as r,d as t,m as c,a as o,x as _,h as l,b as u,G as a,g as p,y as m,L as xn,q as d,o as g,B as v,v as jn}from"../../chunks/vendor-hf-doc-builder.js";import{I as D}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{C as $}from"../../chunks/CodeBlock-hf-doc-builder.js";function qn(No){let T,ka,P,V,Et,he,Zs,yt,er,xa,A,_e,tr,ar,kt,sr,rr,ja,Y,ir,me,or,lr,qa,O,W,xt,de,nr,jt,pr,Da,C,F,qt,ge,fr,Dt,cr,Ta,et,ur,Pa,tt,Tt,hr,Aa,K,_r,Pt,mr,dr,Oa,ve,Ca,at,gr,Na,we,Ia,J,vr,be,wr,br,Sa,$e,Ra,st,$r,Ma,Ee,za,rt,Er,Ua,ye,Ha,N,Q,At,ke,yr,Ot,kr,La,X,xr,xe,jr,qr,Ba,w,Dr,Ct,Tr,Pr,Nt,Ar,Or,It,Cr,Nr,St,Ir,Sr,Rt,Rr,Mr,Mt,zr,Ur,zt,Hr,Lr,Ut,Br,Gr,Ga,je,Va,it,Ht,Lt,I,Vr,Bt,Yr,Wr,qe,Fr,Kr,Ya,De,Wa,ot,S,Jr,Gt,Qr,Xr,Te,Zr,ei,Fa,Z,ti,Vt,ai,si,Ka,k,R,ri,Yt,ii,oi,Wt,li,ni,pi,Pe,fi,Ft,ci,ui,hi,E,_i,Kt,mi,di,Jt,gi,vi,Qt,wi,bi,Ae,Xt,Zt,$i,Ei,ea,ta,yi,Ja,lt,ki,Qa,Oe,Xa,ee,xi,Ce,ji,qi,Za,x,Di,aa,Ti,Pi,Ne,Ai,Oi,es,M,te,sa,Ie,Ci,ra,Ni,ts,j,Ii,Se,Si,Ri,Re,Mi,zi,as,nt,Ui,ss,Me,rs,pt,Hi,is,ze,os,ae,Li,Ue,Bi,Gi,ls,z,se,ia,He,Vi,oa,Yi,ns,y,Wi,la,Fi,Ki,na,Ji,Qi,pa,Xi,Zi,ps,ft,eo,fs,Le,cs,ct,to,us,Be,hs,U,re,fa,Ge,ao,ca,so,_s,ie,ro,ua,io,oo,ms,Ve,ds,ut,lo,gs,Ye,vs,ht,no,ws,We,bs,q,po,ha,fo,co,_a,uo,ho,$s,H,oe,ma,Fe,_o,da,mo,Es,le,go,ga,vo,wo,ys,_t,bo,ks,L,ne,va,Ke,$o,wa,Eo,xs,pe,yo,ba,ko,xo,js,Je,jo,Qe,qo,qs,B,fe,$a,Xe,Do,Ea,To,Ds,ce,Po,Ze,Ao,Oo,Ts;return he=new D({}),de=new D({}),ge=new D({}),ve=new $({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 .`}}),we=new $({props:{code:`pip install -r requirements.txt
pip install clip-retrieval `,highlighted:`pip install -r requirements.txt
pip install clip-retrieval `}}),$e=new $({props:{code:"accelerate config",highlighted:"accelerate config"}}),Ee=new $({props:{code:"accelerate config default",highlighted:"accelerate config default"}}),ye=new $({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()`}}),ke=new D({}),je=new $({props:{code:`pip install clip-retrieval
python retrieve.py --class_prompt cat --class_data_dir real_reg/samples_cat --num_class_images 200`,highlighted:`pip install clip-retrieval
python retrieve.py --class_prompt <span class="hljs-built_in">cat</span> --class_data_dir real_reg/samples_cat --num_class_images 200`}}),De=new $({props:{code:`export MODEL_NAME="CompVis/stable-diffusion-v1-4"
export OUTPUT_DIR="path-to-save-model"
export INSTANCE_DIR="./data/cat"

accelerate launch train_custom_diffusion.py \\
  --pretrained_model_name_or_path=$MODEL_NAME  \\
  --instance_data_dir=$INSTANCE_DIR \\
  --output_dir=$OUTPUT_DIR \\
  --class_data_dir=./real_reg/samples_cat/ \\
  --with_prior_preservation --real_prior --prior_loss_weight=1.0 \\
  --class_prompt="cat" --num_class_images=200 \\
  --instance_prompt="photo of a <new1> cat"  \\
  --resolution=512  \\
  --train_batch_size=2  \\
  --learning_rate=1e-5  \\
  --lr_warmup_steps=0 \\
  --max_train_steps=250 \\
  --scale_lr --hflip  \\
  --modifier_token "<new1>" `,highlighted:`<span class="hljs-built_in">export</span> MODEL_NAME=<span class="hljs-string">&quot;CompVis/stable-diffusion-v1-4&quot;</span>
<span class="hljs-built_in">export</span> OUTPUT_DIR=<span class="hljs-string">&quot;path-to-save-model&quot;</span>
<span class="hljs-built_in">export</span> INSTANCE_DIR=<span class="hljs-string">&quot;./data/cat&quot;</span>

accelerate launch train_custom_diffusion.py \\
  --pretrained_model_name_or_path=<span class="hljs-variable">$MODEL_NAME</span>  \\
  --instance_data_dir=<span class="hljs-variable">$INSTANCE_DIR</span> \\
  --output_dir=<span class="hljs-variable">$OUTPUT_DIR</span> \\
  --class_data_dir=./real_reg/samples_cat/ \\
  --with_prior_preservation --real_prior --prior_loss_weight=1.0 \\
  --class_prompt=<span class="hljs-string">&quot;cat&quot;</span> --num_class_images=200 \\
  --instance_prompt=<span class="hljs-string">&quot;photo of a &lt;new1&gt; cat&quot;</span>  \\
  --resolution=512  \\
  --train_batch_size=2  \\
  --learning_rate=1e-5  \\
  --lr_warmup_steps=0 \\
  --max_train_steps=250 \\
  --scale_lr --hflip  \\
  --modifier_token <span class="hljs-string">&quot;&lt;new1&gt;&quot;</span> `}}),Oe=new $({props:{code:`accelerate launch train_custom_diffusion.py \\
  --pretrained_model_name_or_path=$MODEL_NAME  \\
  --instance_data_dir=$INSTANCE_DIR \\
  --output_dir=$OUTPUT_DIR \\
  --class_data_dir=./real_reg/samples_cat/ \\
  --with_prior_preservation --real_prior --prior_loss_weight=1.0 \\
  --class_prompt="cat" --num_class_images=200 \\
  --instance_prompt="photo of a <new1> cat"  \\
  --resolution=512  \\
  --train_batch_size=2  \\
  --learning_rate=1e-5  \\
  --lr_warmup_steps=0 \\
  --max_train_steps=250 \\
  --scale_lr --hflip  \\
  --modifier_token "<new1>" \\
  --validation_prompt="<new1> cat sitting in a bucket" \\
  --report_to="wandb"`,highlighted:`accelerate launch train_custom_diffusion.py \\
  --pretrained_model_name_or_path=<span class="hljs-variable">$MODEL_NAME</span>  \\
  --instance_data_dir=<span class="hljs-variable">$INSTANCE_DIR</span> \\
  --output_dir=<span class="hljs-variable">$OUTPUT_DIR</span> \\
  --class_data_dir=./real_reg/samples_cat/ \\
  --with_prior_preservation --real_prior --prior_loss_weight=1.0 \\
  --class_prompt=<span class="hljs-string">&quot;cat&quot;</span> --num_class_images=200 \\
  --instance_prompt=<span class="hljs-string">&quot;photo of a &lt;new1&gt; cat&quot;</span>  \\
  --resolution=512  \\
  --train_batch_size=2  \\
  --learning_rate=1e-5  \\
  --lr_warmup_steps=0 \\
  --max_train_steps=250 \\
  --scale_lr --hflip  \\
  --modifier_token <span class="hljs-string">&quot;&lt;new1&gt;&quot;</span> \\
  --validation_prompt=<span class="hljs-string">&quot;&lt;new1&gt; cat sitting in a bucket&quot;</span> \\
  --report_to=<span class="hljs-string">&quot;wandb&quot;</span>`}}),Ie=new D({}),Me=new $({props:{code:`pip install clip-retrieval
python retrieve.py --class_prompt {} --class_data_dir {} --num_class_images 200`,highlighted:`pip install clip-retrieval
python retrieve.py --class_prompt {} --class_data_dir {} --num_class_images 200`}}),ze=new $({props:{code:`export MODEL_NAME="CompVis/stable-diffusion-v1-4"
export OUTPUT_DIR="path-to-save-model"

accelerate launch train_custom_diffusion.py \\
  --pretrained_model_name_or_path=$MODEL_NAME  \\
  --output_dir=$OUTPUT_DIR \\
  --concepts_list=./concept_list.json \\
  --with_prior_preservation --real_prior --prior_loss_weight=1.0 \\
  --resolution=512  \\
  --train_batch_size=2  \\
  --learning_rate=1e-5  \\
  --lr_warmup_steps=0 \\
  --max_train_steps=500 \\
  --num_class_images=200 \\
  --scale_lr --hflip  \\
  --modifier_token "<new1>+<new2>" `,highlighted:`<span class="hljs-built_in">export</span> MODEL_NAME=<span class="hljs-string">&quot;CompVis/stable-diffusion-v1-4&quot;</span>
<span class="hljs-built_in">export</span> OUTPUT_DIR=<span class="hljs-string">&quot;path-to-save-model&quot;</span>

accelerate launch train_custom_diffusion.py \\
  --pretrained_model_name_or_path=<span class="hljs-variable">$MODEL_NAME</span>  \\
  --output_dir=<span class="hljs-variable">$OUTPUT_DIR</span> \\
  --concepts_list=./concept_list.json \\
  --with_prior_preservation --real_prior --prior_loss_weight=1.0 \\
  --resolution=512  \\
  --train_batch_size=2  \\
  --learning_rate=1e-5  \\
  --lr_warmup_steps=0 \\
  --max_train_steps=500 \\
  --num_class_images=200 \\
  --scale_lr --hflip  \\
  --modifier_token <span class="hljs-string">&quot;&lt;new1&gt;+&lt;new2&gt;&quot;</span> `}}),He=new D({}),Le=new $({props:{code:`pip install clip-retrieval
python retrieve.py --class_prompt person --class_data_dir real_reg/samples_person --num_class_images 200`,highlighted:`pip install clip-retrieval
python retrieve.py --class_prompt person --class_data_dir real_reg/samples_person --num_class_images 200`}}),Be=new $({props:{code:`export MODEL_NAME="CompVis/stable-diffusion-v1-4"
export OUTPUT_DIR="path-to-save-model"
export INSTANCE_DIR="path-to-images"

accelerate launch train_custom_diffusion.py \\
  --pretrained_model_name_or_path=$MODEL_NAME  \\
  --instance_data_dir=$INSTANCE_DIR \\
  --output_dir=$OUTPUT_DIR \\
  --class_data_dir=./real_reg/samples_person/ \\
  --with_prior_preservation --real_prior --prior_loss_weight=1.0 \\
  --class_prompt="person" --num_class_images=200 \\
  --instance_prompt="photo of a <new1> person"  \\
  --resolution=512  \\
  --train_batch_size=2  \\
  --learning_rate=5e-6  \\
  --lr_warmup_steps=0 \\
  --max_train_steps=1000 \\
  --scale_lr --hflip --noaug \\
  --freeze_model crossattn \\
  --modifier_token "<new1>" \\
  --enable_xformers_memory_efficient_attention `,highlighted:`<span class="hljs-built_in">export</span> MODEL_NAME=<span class="hljs-string">&quot;CompVis/stable-diffusion-v1-4&quot;</span>
<span class="hljs-built_in">export</span> OUTPUT_DIR=<span class="hljs-string">&quot;path-to-save-model&quot;</span>
<span class="hljs-built_in">export</span> INSTANCE_DIR=<span class="hljs-string">&quot;path-to-images&quot;</span>

accelerate launch train_custom_diffusion.py \\
  --pretrained_model_name_or_path=<span class="hljs-variable">$MODEL_NAME</span>  \\
  --instance_data_dir=<span class="hljs-variable">$INSTANCE_DIR</span> \\
  --output_dir=<span class="hljs-variable">$OUTPUT_DIR</span> \\
  --class_data_dir=./real_reg/samples_person/ \\
  --with_prior_preservation --real_prior --prior_loss_weight=1.0 \\
  --class_prompt=<span class="hljs-string">&quot;person&quot;</span> --num_class_images=200 \\
  --instance_prompt=<span class="hljs-string">&quot;photo of a &lt;new1&gt; person&quot;</span>  \\
  --resolution=512  \\
  --train_batch_size=2  \\
  --learning_rate=5e-6  \\
  --lr_warmup_steps=0 \\
  --max_train_steps=1000 \\
  --scale_lr --hflip --noaug \\
  --freeze_model crossattn \\
  --modifier_token <span class="hljs-string">&quot;&lt;new1&gt;&quot;</span> \\
  --enable_xformers_memory_efficient_attention `}}),Ge=new D({}),Ve=new $({props:{code:`import torch
from diffusers import DiffusionPipeline

pipe = DiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", torch_dtype=torch.float16).to("cuda")
pipe.unet.load_attn_procs("path-to-save-model", weight_name="pytorch_custom_diffusion_weights.bin")
pipe.load_textual_inversion("path-to-save-model", weight_name="<new1>.bin")

image = pipe(
    "<new1> cat sitting in a bucket",
    num_inference_steps=100,
    guidance_scale=6.0,
    eta=1.0,
).images[0]
image.save("cat.png")`,highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DiffusionPipeline

pipe = DiffusionPipeline.from_pretrained(<span class="hljs-string">&quot;CompVis/stable-diffusion-v1-4&quot;</span>, torch_dtype=torch.float16).to(<span class="hljs-string">&quot;cuda&quot;</span>)
pipe.unet.load_attn_procs(<span class="hljs-string">&quot;path-to-save-model&quot;</span>, weight_name=<span class="hljs-string">&quot;pytorch_custom_diffusion_weights.bin&quot;</span>)
pipe.load_textual_inversion(<span class="hljs-string">&quot;path-to-save-model&quot;</span>, weight_name=<span class="hljs-string">&quot;&lt;new1&gt;.bin&quot;</span>)

image = pipe(
    <span class="hljs-string">&quot;&lt;new1&gt; cat sitting in a bucket&quot;</span>,
    num_inference_steps=<span class="hljs-number">100</span>,
    guidance_scale=<span class="hljs-number">6.0</span>,
    eta=<span class="hljs-number">1.0</span>,
).images[<span class="hljs-number">0</span>]
image.save(<span class="hljs-string">&quot;cat.png&quot;</span>)`}}),Ye=new $({props:{code:`import torch
from huggingface_hub.repocard import RepoCard
from diffusers import DiffusionPipeline

model_id = "sayakpaul/custom-diffusion-cat"
card = RepoCard.load(model_id)
base_model_id = card.data.to_dict()["base_model"]

pipe = DiffusionPipeline.from_pretrained(base_model_id, torch_dtype=torch.float16).to("cuda")
pipe.unet.load_attn_procs(model_id, weight_name="pytorch_custom_diffusion_weights.bin")
pipe.load_textual_inversion(model_id, weight_name="<new1>.bin")

image = pipe(
    "<new1> cat sitting in a bucket",
    num_inference_steps=100,
    guidance_scale=6.0,
    eta=1.0,
).images[0]
image.save("cat.png")`,highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> huggingface_hub.repocard <span class="hljs-keyword">import</span> RepoCard
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DiffusionPipeline

model_id = <span class="hljs-string">&quot;sayakpaul/custom-diffusion-cat&quot;</span>
card = RepoCard.load(model_id)
base_model_id = card.data.to_dict()[<span class="hljs-string">&quot;base_model&quot;</span>]

pipe = DiffusionPipeline.from_pretrained(base_model_id, torch_dtype=torch.float16).to(<span class="hljs-string">&quot;cuda&quot;</span>)
pipe.unet.load_attn_procs(model_id, weight_name=<span class="hljs-string">&quot;pytorch_custom_diffusion_weights.bin&quot;</span>)
pipe.load_textual_inversion(model_id, weight_name=<span class="hljs-string">&quot;&lt;new1&gt;.bin&quot;</span>)

image = pipe(
    <span class="hljs-string">&quot;&lt;new1&gt; cat sitting in a bucket&quot;</span>,
    num_inference_steps=<span class="hljs-number">100</span>,
    guidance_scale=<span class="hljs-number">6.0</span>,
    eta=<span class="hljs-number">1.0</span>,
).images[<span class="hljs-number">0</span>]
image.save(<span class="hljs-string">&quot;cat.png&quot;</span>)`}}),We=new $({props:{code:`import torch
from huggingface_hub.repocard import RepoCard
from diffusers import DiffusionPipeline

model_id = "sayakpaul/custom-diffusion-cat-wooden-pot"
card = RepoCard.load(model_id)
base_model_id = card.data.to_dict()["base_model"]

pipe = DiffusionPipeline.from_pretrained(base_model_id, torch_dtype=torch.float16).to("cuda")
pipe.unet.load_attn_procs(model_id, weight_name="pytorch_custom_diffusion_weights.bin")
pipe.load_textual_inversion(model_id, weight_name="<new1>.bin")
pipe.load_textual_inversion(model_id, weight_name="<new2>.bin")

image = pipe(
    "the <new1> cat sculpture in the style of a <new2> wooden pot",
    num_inference_steps=100,
    guidance_scale=6.0,
    eta=1.0,
).images[0]
image.save("multi-subject.png")`,highlighted:`<span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> huggingface_hub.repocard <span class="hljs-keyword">import</span> RepoCard
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DiffusionPipeline

model_id = <span class="hljs-string">&quot;sayakpaul/custom-diffusion-cat-wooden-pot&quot;</span>
card = RepoCard.load(model_id)
base_model_id = card.data.to_dict()[<span class="hljs-string">&quot;base_model&quot;</span>]

pipe = DiffusionPipeline.from_pretrained(base_model_id, torch_dtype=torch.float16).to(<span class="hljs-string">&quot;cuda&quot;</span>)
pipe.unet.load_attn_procs(model_id, weight_name=<span class="hljs-string">&quot;pytorch_custom_diffusion_weights.bin&quot;</span>)
pipe.load_textual_inversion(model_id, weight_name=<span class="hljs-string">&quot;&lt;new1&gt;.bin&quot;</span>)
pipe.load_textual_inversion(model_id, weight_name=<span class="hljs-string">&quot;&lt;new2&gt;.bin&quot;</span>)

image = pipe(
    <span class="hljs-string">&quot;the &lt;new1&gt; cat sculpture in the style of a &lt;new2&gt; wooden pot&quot;</span>,
    num_inference_steps=<span class="hljs-number">100</span>,
    guidance_scale=<span class="hljs-number">6.0</span>,
    eta=<span class="hljs-number">1.0</span>,
).images[<span class="hljs-number">0</span>]
image.save(<span class="hljs-string">&quot;multi-subject.png&quot;</span>)`}}),Fe=new D({}),Ke=new D({}),Xe=new D({}),{c(){T=s("meta"),ka=f(),P=s("h1"),V=s("a"),Et=s("span"),h(he.$$.fragment),Zs=f(),yt=s("span"),er=i("Custom Diffusion training example"),xa=f(),A=s("p"),_e=s("a"),tr=i("Custom Diffusion"),ar=i(` is a method to customize text-to-image models like Stable Diffusion given just a few (4~5) images of a subject.
The `),kt=s("code"),sr=i("train_custom_diffusion.py"),rr=i(" script shows how to implement the training procedure and adapt it for stable diffusion."),ja=f(),Y=s("p"),ir=i("This training example was contributed by "),me=s("a"),or=i("Nupur Kumari"),lr=i(" (one of the authors of Custom Diffusion)."),qa=f(),O=s("h2"),W=s("a"),xt=s("span"),h(de.$$.fragment),nr=f(),jt=s("span"),pr=i("Running locally with PyTorch"),Da=f(),C=s("h3"),F=s("a"),qt=s("span"),h(ge.$$.fragment),fr=f(),Dt=s("span"),cr=i("Installing the dependencies"),Ta=f(),et=s("p"),ur=i("Before running the scripts, make sure to install the library\u2019s training dependencies:"),Pa=f(),tt=s("p"),Tt=s("strong"),hr=i("Important"),Aa=f(),K=s("p"),_r=i("To make sure you can successfully run the latest versions of the example scripts, we highly recommend "),Pt=s("strong"),mr=i("installing from source"),dr=i(" 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:"),Oa=f(),h(ve.$$.fragment),Ca=f(),at=s("p"),gr=i("Then cd in the example folder and run"),Na=f(),h(we.$$.fragment),Ia=f(),J=s("p"),vr=i("And initialize an "),be=s("a"),wr=i("\u{1F917}Accelerate"),br=i(" environment with:"),Sa=f(),h($e.$$.fragment),Ra=f(),st=s("p"),$r=i("Or for a default accelerate configuration without answering questions about your environment"),Ma=f(),h(Ee.$$.fragment),za=f(),rt=s("p"),Er=i("Or if your environment doesn\u2019t support an interactive shell e.g. a notebook"),Ua=f(),h(ye.$$.fragment),Ha=f(),N=s("h3"),Q=s("a"),At=s("span"),h(ke.$$.fragment),yr=f(),Ot=s("span"),kr=i("Cat example \u{1F63A}"),La=f(),X=s("p"),xr=i("Now let\u2019s get our dataset. Download dataset from "),xe=s("a"),jr=i("here"),qr=i(" and unzip it."),Ba=f(),w=s("p"),Dr=i("We also collect 200 real images using "),Ct=s("code"),Tr=i("clip-retrieval"),Pr=i(" which are combined with the target images in the training dataset as a regularization. This prevents overfitting to the the given target image. The following flags enable the regularization "),Nt=s("code"),Ar=i("with_prior_preservation"),Or=i(", "),It=s("code"),Cr=i("real_prior"),Nr=i(" with "),St=s("code"),Ir=i("prior_loss_weight=1."),Sr=i(`.
The `),Rt=s("code"),Rr=i("class_prompt"),Mr=i(" should be the category name same as target image. The collected real images are with text captions similar to the "),Mt=s("code"),zr=i("class_prompt"),Ur=i(". The retrieved image are saved in "),zt=s("code"),Hr=i("class_data_dir"),Lr=i(". You can disable "),Ut=s("code"),Br=i("real_prior"),Gr=i(" to use generated images as regularization. To collect the real images use this command first before training."),Ga=f(),h(je.$$.fragment),Va=f(),it=s("p"),Ht=s("strong"),Lt=s("strong"),I=s("em"),Vr=i("Note: Change the "),Bt=s("code"),Yr=i("resolution"),Wr=i(" to 768 if you are using the "),qe=s("a"),Fr=i("stable-diffusion-2"),Kr=i(" 768x768 model."),Ya=f(),h(De.$$.fragment),Wa=f(),ot=s("p"),S=s("strong"),Jr=i("Use "),Gt=s("code"),Qr=i("--enable_xformers_memory_efficient_attention"),Xr=i(" for faster training with lower VRAM requirement (16GB per GPU). Follow "),Te=s("a"),Zr=i("this guide"),ei=i(" for installation instructions."),Fa=f(),Z=s("p"),ti=i("To track your experiments using Weights and Biases ("),Vt=s("code"),ai=i("wandb"),si=i(") and to save intermediate results (whcih we HIGHLY recommend), follow these steps:"),Ka=f(),k=s("ul"),R=s("li"),ri=i("Install "),Yt=s("code"),ii=i("wandb"),oi=i(": "),Wt=s("code"),li=i("pip install wandb"),ni=i("."),pi=f(),Pe=s("li"),fi=i("Authorize: "),Ft=s("code"),ci=i("wandb login"),ui=i("."),hi=f(),E=s("li"),_i=i("Then specify a "),Kt=s("code"),mi=i("validation_prompt"),di=i(" and set "),Jt=s("code"),gi=i("report_to"),vi=i(" to "),Qt=s("code"),wi=i("wandb"),bi=i(" while launching training. You can also configure the following related arguments:"),Ae=s("ul"),Xt=s("li"),Zt=s("code"),$i=i("num_validation_images"),Ei=f(),ea=s("li"),ta=s("code"),yi=i("validation_steps"),Ja=f(),lt=s("p"),ki=i("Here is an example command:"),Qa=f(),h(Oe.$$.fragment),Xa=f(),ee=s("p"),xi=i("Here is an example "),Ce=s("a"),ji=i("Weights and Biases page"),qi=i(" where you can check out the intermediate results along with other training details."),Za=f(),x=s("p"),Di=i("If you specify "),aa=s("code"),Ti=i("--push_to_hub"),Pi=i(", the learned parameters will be pushed to a repository on the Hugging Face Hub. Here is an "),Ne=s("a"),Ai=i("example repository"),Oi=i("."),es=f(),M=s("h3"),te=s("a"),sa=s("span"),h(Ie.$$.fragment),Ci=f(),ra=s("span"),Ni=i("Training on multiple concepts \u{1F431}\u{1FAB5}"),ts=f(),j=s("p"),Ii=i("Provide a "),Se=s("a"),Si=i("json"),Ri=i(" file with the info about each concept, similar to "),Re=s("a"),Mi=i("this"),zi=i("."),as=f(),nt=s("p"),Ui=i("To collect the real images run this command for each concept in the json file."),ss=f(),h(Me.$$.fragment),rs=f(),pt=s("p"),Hi=i("And then we\u2019re ready to start training!"),is=f(),h(ze.$$.fragment),os=f(),ae=s("p"),Li=i("Here is an example "),Ue=s("a"),Bi=i("Weights and Biases page"),Gi=i(" where you can check out the intermediate results along with other training details."),ls=f(),z=s("h3"),se=s("a"),ia=s("span"),h(He.$$.fragment),Vi=f(),oa=s("span"),Yi=i("Training on human faces"),ns=f(),y=s("p"),Wi=i("For fine-tuning on human faces we found the following configuration to work better: "),la=s("code"),Fi=i("learning_rate=5e-6"),Ki=i(", "),na=s("code"),Ji=i("max_train_steps=1000 to 2000"),Qi=i(", and "),pa=s("code"),Xi=i("freeze_model=crossattn"),Zi=i(" with at least 15-20 images."),ps=f(),ft=s("p"),eo=i("To collect the real images use this command first before training."),fs=f(),h(Le.$$.fragment),cs=f(),ct=s("p"),to=i("Then start training!"),us=f(),h(Be.$$.fragment),hs=f(),U=s("h2"),re=s("a"),fa=s("span"),h(Ge.$$.fragment),ao=f(),ca=s("span"),so=i("Inference"),_s=f(),ie=s("p"),ro=i("Once you have trained a model using the above command, you can run inference using the below command. Make sure to include the "),ua=s("code"),io=i("modifier token"),oo=i(" (e.g. \\<new1> in above example) in your prompt."),ms=f(),h(Ve.$$.fragment),ds=f(),ut=s("p"),lo=i("It\u2019s possible to directly load these parameters from a Hub repository:"),gs=f(),h(Ye.$$.fragment),vs=f(),ht=s("p"),no=i("Here is an example of performing inference with multiple concepts:"),ws=f(),h(We.$$.fragment),bs=f(),q=s("p"),po=i("Here, "),ha=s("code"),fo=i("cat"),co=i(" and "),_a=s("code"),uo=i("wooden pot"),ho=i(" refer to the multiple concepts."),$s=f(),H=s("h3"),oe=s("a"),ma=s("span"),h(Fe.$$.fragment),_o=f(),da=s("span"),mo=i("Inference from a training checkpoint"),Es=f(),le=s("p"),go=i("You can also perform inference from one of the complete checkpoint saved during the training process, if you used the "),ga=s("code"),vo=i("--checkpointing_steps"),wo=i(" argument."),ys=f(),_t=s("p"),bo=i("TODO."),ks=f(),L=s("h2"),ne=s("a"),va=s("span"),h(Ke.$$.fragment),$o=f(),wa=s("span"),Eo=i("Set grads to none"),xs=f(),pe=s("p"),yo=i("To save even more memory, pass the "),ba=s("code"),ko=i("--set_grads_to_none"),xo=i(" argument to the script. This will set grads to None instead of zero. However, be aware that it changes certain behaviors, so if you start experiencing any problems, remove this argument."),js=f(),Je=s("p"),jo=i("More info: "),Qe=s("a"),qo=i("https://pytorch.org/docs/stable/generated/torch.optim.Optimizer.zero_grad.html"),qs=f(),B=s("h2"),fe=s("a"),$a=s("span"),h(Xe.$$.fragment),Do=f(),Ea=s("span"),To=i("Experimental results"),Ds=f(),ce=s("p"),Po=i("You can refer to "),Ze=s("a"),Ao=i("our webpage"),Oo=i(" that discusses our experiments in detail."),this.h()},l(e){const n=kn('[data-svelte="svelte-1phssyn"]',document.head);T=r(n,"META",{name:!0,content:!0}),n.forEach(t),ka=c(e),P=r(e,"H1",{class:!0});var Ps=o(P);V=r(Ps,"A",{id:!0,class:!0,href:!0});var Io=o(V);Et=r(Io,"SPAN",{});var So=o(Et);_(he.$$.fragment,So),So.forEach(t),Io.forEach(t),Zs=c(Ps),yt=r(Ps,"SPAN",{});var Ro=o(yt);er=l(Ro,"Custom Diffusion training example"),Ro.forEach(t),Ps.forEach(t),xa=c(e),A=r(e,"P",{});var ya=o(A);_e=r(ya,"A",{href:!0,rel:!0});var Mo=o(_e);tr=l(Mo,"Custom Diffusion"),Mo.forEach(t),ar=l(ya,` is a method to customize text-to-image models like Stable Diffusion given just a few (4~5) images of a subject.
The `),kt=r(ya,"CODE",{});var zo=o(kt);sr=l(zo,"train_custom_diffusion.py"),zo.forEach(t),rr=l(ya," script shows how to implement the training procedure and adapt it for stable diffusion."),ya.forEach(t),ja=c(e),Y=r(e,"P",{});var As=o(Y);ir=l(As,"This training example was contributed by "),me=r(As,"A",{href:!0,rel:!0});var Uo=o(me);or=l(Uo,"Nupur Kumari"),Uo.forEach(t),lr=l(As," (one of the authors of Custom Diffusion)."),As.forEach(t),qa=c(e),O=r(e,"H2",{class:!0});var Os=o(O);W=r(Os,"A",{id:!0,class:!0,href:!0});var Ho=o(W);xt=r(Ho,"SPAN",{});var Lo=o(xt);_(de.$$.fragment,Lo),Lo.forEach(t),Ho.forEach(t),nr=c(Os),jt=r(Os,"SPAN",{});var Bo=o(jt);pr=l(Bo,"Running locally with PyTorch"),Bo.forEach(t),Os.forEach(t),Da=c(e),C=r(e,"H3",{class:!0});var Cs=o(C);F=r(Cs,"A",{id:!0,class:!0,href:!0});var Go=o(F);qt=r(Go,"SPAN",{});var Vo=o(qt);_(ge.$$.fragment,Vo),Vo.forEach(t),Go.forEach(t),fr=c(Cs),Dt=r(Cs,"SPAN",{});var Yo=o(Dt);cr=l(Yo,"Installing the dependencies"),Yo.forEach(t),Cs.forEach(t),Ta=c(e),et=r(e,"P",{});var Wo=o(et);ur=l(Wo,"Before running the scripts, make sure to install the library\u2019s training dependencies:"),Wo.forEach(t),Pa=c(e),tt=r(e,"P",{});var Fo=o(tt);Tt=r(Fo,"STRONG",{});var Ko=o(Tt);hr=l(Ko,"Important"),Ko.forEach(t),Fo.forEach(t),Aa=c(e),K=r(e,"P",{});var Ns=o(K);_r=l(Ns,"To make sure you can successfully run the latest versions of the example scripts, we highly recommend "),Pt=r(Ns,"STRONG",{});var Jo=o(Pt);mr=l(Jo,"installing from source"),Jo.forEach(t),dr=l(Ns," 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:"),Ns.forEach(t),Oa=c(e),_(ve.$$.fragment,e),Ca=c(e),at=r(e,"P",{});var Qo=o(at);gr=l(Qo,"Then cd in the example folder and run"),Qo.forEach(t),Na=c(e),_(we.$$.fragment,e),Ia=c(e),J=r(e,"P",{});var Is=o(J);vr=l(Is,"And initialize an "),be=r(Is,"A",{href:!0,rel:!0});var Xo=o(be);wr=l(Xo,"\u{1F917}Accelerate"),Xo.forEach(t),br=l(Is," environment with:"),Is.forEach(t),Sa=c(e),_($e.$$.fragment,e),Ra=c(e),st=r(e,"P",{});var Zo=o(st);$r=l(Zo,"Or for a default accelerate configuration without answering questions about your environment"),Zo.forEach(t),Ma=c(e),_(Ee.$$.fragment,e),za=c(e),rt=r(e,"P",{});var el=o(rt);Er=l(el,"Or if your environment doesn\u2019t support an interactive shell e.g. a notebook"),el.forEach(t),Ua=c(e),_(ye.$$.fragment,e),Ha=c(e),N=r(e,"H3",{class:!0});var Ss=o(N);Q=r(Ss,"A",{id:!0,class:!0,href:!0});var tl=o(Q);At=r(tl,"SPAN",{});var al=o(At);_(ke.$$.fragment,al),al.forEach(t),tl.forEach(t),yr=c(Ss),Ot=r(Ss,"SPAN",{});var sl=o(Ot);kr=l(sl,"Cat example \u{1F63A}"),sl.forEach(t),Ss.forEach(t),La=c(e),X=r(e,"P",{});var Rs=o(X);xr=l(Rs,"Now let\u2019s get our dataset. Download dataset from "),xe=r(Rs,"A",{href:!0,rel:!0});var rl=o(xe);jr=l(rl,"here"),rl.forEach(t),qr=l(Rs," and unzip it."),Rs.forEach(t),Ba=c(e),w=r(e,"P",{});var b=o(w);Dr=l(b,"We also collect 200 real images using "),Ct=r(b,"CODE",{});var il=o(Ct);Tr=l(il,"clip-retrieval"),il.forEach(t),Pr=l(b," which are combined with the target images in the training dataset as a regularization. This prevents overfitting to the the given target image. The following flags enable the regularization "),Nt=r(b,"CODE",{});var ol=o(Nt);Ar=l(ol,"with_prior_preservation"),ol.forEach(t),Or=l(b,", "),It=r(b,"CODE",{});var ll=o(It);Cr=l(ll,"real_prior"),ll.forEach(t),Nr=l(b," with "),St=r(b,"CODE",{});var nl=o(St);Ir=l(nl,"prior_loss_weight=1."),nl.forEach(t),Sr=l(b,`.
The `),Rt=r(b,"CODE",{});var pl=o(Rt);Rr=l(pl,"class_prompt"),pl.forEach(t),Mr=l(b," should be the category name same as target image. The collected real images are with text captions similar to the "),Mt=r(b,"CODE",{});var fl=o(Mt);zr=l(fl,"class_prompt"),fl.forEach(t),Ur=l(b,". The retrieved image are saved in "),zt=r(b,"CODE",{});var cl=o(zt);Hr=l(cl,"class_data_dir"),cl.forEach(t),Lr=l(b,". You can disable "),Ut=r(b,"CODE",{});var ul=o(Ut);Br=l(ul,"real_prior"),ul.forEach(t),Gr=l(b," to use generated images as regularization. To collect the real images use this command first before training."),b.forEach(t),Ga=c(e),_(je.$$.fragment,e),Va=c(e),it=r(e,"P",{});var hl=o(it);Ht=r(hl,"STRONG",{});var _l=o(Ht);Lt=r(_l,"STRONG",{});var ml=o(Lt);I=r(ml,"EM",{});var mt=o(I);Vr=l(mt,"Note: Change the "),Bt=r(mt,"CODE",{});var dl=o(Bt);Yr=l(dl,"resolution"),dl.forEach(t),Wr=l(mt," to 768 if you are using the "),qe=r(mt,"A",{href:!0,rel:!0});var gl=o(qe);Fr=l(gl,"stable-diffusion-2"),gl.forEach(t),Kr=l(mt," 768x768 model."),mt.forEach(t),ml.forEach(t),_l.forEach(t),hl.forEach(t),Ya=c(e),_(De.$$.fragment,e),Wa=c(e),ot=r(e,"P",{});var vl=o(ot);S=r(vl,"STRONG",{});var dt=o(S);Jr=l(dt,"Use "),Gt=r(dt,"CODE",{});var wl=o(Gt);Qr=l(wl,"--enable_xformers_memory_efficient_attention"),wl.forEach(t),Xr=l(dt," for faster training with lower VRAM requirement (16GB per GPU). Follow "),Te=r(dt,"A",{href:!0,rel:!0});var bl=o(Te);Zr=l(bl,"this guide"),bl.forEach(t),ei=l(dt," for installation instructions."),dt.forEach(t),vl.forEach(t),Fa=c(e),Z=r(e,"P",{});var Ms=o(Z);ti=l(Ms,"To track your experiments using Weights and Biases ("),Vt=r(Ms,"CODE",{});var $l=o(Vt);ai=l($l,"wandb"),$l.forEach(t),si=l(Ms,") and to save intermediate results (whcih we HIGHLY recommend), follow these steps:"),Ms.forEach(t),Ka=c(e),k=r(e,"UL",{});var gt=o(k);R=r(gt,"LI",{});var vt=o(R);ri=l(vt,"Install "),Yt=r(vt,"CODE",{});var El=o(Yt);ii=l(El,"wandb"),El.forEach(t),oi=l(vt,": "),Wt=r(vt,"CODE",{});var yl=o(Wt);li=l(yl,"pip install wandb"),yl.forEach(t),ni=l(vt,"."),vt.forEach(t),pi=c(gt),Pe=r(gt,"LI",{});var zs=o(Pe);fi=l(zs,"Authorize: "),Ft=r(zs,"CODE",{});var kl=o(Ft);ci=l(kl,"wandb login"),kl.forEach(t),ui=l(zs,"."),zs.forEach(t),hi=c(gt),E=r(gt,"LI",{});var G=o(E);_i=l(G,"Then specify a "),Kt=r(G,"CODE",{});var xl=o(Kt);mi=l(xl,"validation_prompt"),xl.forEach(t),di=l(G," and set "),Jt=r(G,"CODE",{});var jl=o(Jt);gi=l(jl,"report_to"),jl.forEach(t),vi=l(G," to "),Qt=r(G,"CODE",{});var ql=o(Qt);wi=l(ql,"wandb"),ql.forEach(t),bi=l(G," while launching training. You can also configure the following related arguments:"),Ae=r(G,"UL",{});var Us=o(Ae);Xt=r(Us,"LI",{});var Dl=o(Xt);Zt=r(Dl,"CODE",{});var Tl=o(Zt);$i=l(Tl,"num_validation_images"),Tl.forEach(t),Dl.forEach(t),Ei=c(Us),ea=r(Us,"LI",{});var Pl=o(ea);ta=r(Pl,"CODE",{});var Al=o(ta);yi=l(Al,"validation_steps"),Al.forEach(t),Pl.forEach(t),Us.forEach(t),G.forEach(t),gt.forEach(t),Ja=c(e),lt=r(e,"P",{});var Ol=o(lt);ki=l(Ol,"Here is an example command:"),Ol.forEach(t),Qa=c(e),_(Oe.$$.fragment,e),Xa=c(e),ee=r(e,"P",{});var Hs=o(ee);xi=l(Hs,"Here is an example "),Ce=r(Hs,"A",{href:!0,rel:!0});var Cl=o(Ce);ji=l(Cl,"Weights and Biases page"),Cl.forEach(t),qi=l(Hs," where you can check out the intermediate results along with other training details."),Hs.forEach(t),Za=c(e),x=r(e,"P",{});var wt=o(x);Di=l(wt,"If you specify "),aa=r(wt,"CODE",{});var Nl=o(aa);Ti=l(Nl,"--push_to_hub"),Nl.forEach(t),Pi=l(wt,", the learned parameters will be pushed to a repository on the Hugging Face Hub. Here is an "),Ne=r(wt,"A",{href:!0,rel:!0});var Il=o(Ne);Ai=l(Il,"example repository"),Il.forEach(t),Oi=l(wt,"."),wt.forEach(t),es=c(e),M=r(e,"H3",{class:!0});var Ls=o(M);te=r(Ls,"A",{id:!0,class:!0,href:!0});var Sl=o(te);sa=r(Sl,"SPAN",{});var Rl=o(sa);_(Ie.$$.fragment,Rl),Rl.forEach(t),Sl.forEach(t),Ci=c(Ls),ra=r(Ls,"SPAN",{});var Ml=o(ra);Ni=l(Ml,"Training on multiple concepts \u{1F431}\u{1FAB5}"),Ml.forEach(t),Ls.forEach(t),ts=c(e),j=r(e,"P",{});var bt=o(j);Ii=l(bt,"Provide a "),Se=r(bt,"A",{href:!0,rel:!0});var zl=o(Se);Si=l(zl,"json"),zl.forEach(t),Ri=l(bt," file with the info about each concept, similar to "),Re=r(bt,"A",{href:!0,rel:!0});var Ul=o(Re);Mi=l(Ul,"this"),Ul.forEach(t),zi=l(bt,"."),bt.forEach(t),as=c(e),nt=r(e,"P",{});var Hl=o(nt);Ui=l(Hl,"To collect the real images run this command for each concept in the json file."),Hl.forEach(t),ss=c(e),_(Me.$$.fragment,e),rs=c(e),pt=r(e,"P",{});var Ll=o(pt);Hi=l(Ll,"And then we\u2019re ready to start training!"),Ll.forEach(t),is=c(e),_(ze.$$.fragment,e),os=c(e),ae=r(e,"P",{});var Bs=o(ae);Li=l(Bs,"Here is an example "),Ue=r(Bs,"A",{href:!0,rel:!0});var Bl=o(Ue);Bi=l(Bl,"Weights and Biases page"),Bl.forEach(t),Gi=l(Bs," where you can check out the intermediate results along with other training details."),Bs.forEach(t),ls=c(e),z=r(e,"H3",{class:!0});var Gs=o(z);se=r(Gs,"A",{id:!0,class:!0,href:!0});var Gl=o(se);ia=r(Gl,"SPAN",{});var Vl=o(ia);_(He.$$.fragment,Vl),Vl.forEach(t),Gl.forEach(t),Vi=c(Gs),oa=r(Gs,"SPAN",{});var Yl=o(oa);Yi=l(Yl,"Training on human faces"),Yl.forEach(t),Gs.forEach(t),ns=c(e),y=r(e,"P",{});var ue=o(y);Wi=l(ue,"For fine-tuning on human faces we found the following configuration to work better: "),la=r(ue,"CODE",{});var Wl=o(la);Fi=l(Wl,"learning_rate=5e-6"),Wl.forEach(t),Ki=l(ue,", "),na=r(ue,"CODE",{});var Fl=o(na);Ji=l(Fl,"max_train_steps=1000 to 2000"),Fl.forEach(t),Qi=l(ue,", and "),pa=r(ue,"CODE",{});var Kl=o(pa);Xi=l(Kl,"freeze_model=crossattn"),Kl.forEach(t),Zi=l(ue," with at least 15-20 images."),ue.forEach(t),ps=c(e),ft=r(e,"P",{});var Jl=o(ft);eo=l(Jl,"To collect the real images use this command first before training."),Jl.forEach(t),fs=c(e),_(Le.$$.fragment,e),cs=c(e),ct=r(e,"P",{});var Ql=o(ct);to=l(Ql,"Then start training!"),Ql.forEach(t),us=c(e),_(Be.$$.fragment,e),hs=c(e),U=r(e,"H2",{class:!0});var Vs=o(U);re=r(Vs,"A",{id:!0,class:!0,href:!0});var Xl=o(re);fa=r(Xl,"SPAN",{});var Zl=o(fa);_(Ge.$$.fragment,Zl),Zl.forEach(t),Xl.forEach(t),ao=c(Vs),ca=r(Vs,"SPAN",{});var en=o(ca);so=l(en,"Inference"),en.forEach(t),Vs.forEach(t),_s=c(e),ie=r(e,"P",{});var Ys=o(ie);ro=l(Ys,"Once you have trained a model using the above command, you can run inference using the below command. Make sure to include the "),ua=r(Ys,"CODE",{});var tn=o(ua);io=l(tn,"modifier token"),tn.forEach(t),oo=l(Ys," (e.g. \\<new1> in above example) in your prompt."),Ys.forEach(t),ms=c(e),_(Ve.$$.fragment,e),ds=c(e),ut=r(e,"P",{});var an=o(ut);lo=l(an,"It\u2019s possible to directly load these parameters from a Hub repository:"),an.forEach(t),gs=c(e),_(Ye.$$.fragment,e),vs=c(e),ht=r(e,"P",{});var sn=o(ht);no=l(sn,"Here is an example of performing inference with multiple concepts:"),sn.forEach(t),ws=c(e),_(We.$$.fragment,e),bs=c(e),q=r(e,"P",{});var $t=o(q);po=l($t,"Here, "),ha=r($t,"CODE",{});var rn=o(ha);fo=l(rn,"cat"),rn.forEach(t),co=l($t," and "),_a=r($t,"CODE",{});var on=o(_a);uo=l(on,"wooden pot"),on.forEach(t),ho=l($t," refer to the multiple concepts."),$t.forEach(t),$s=c(e),H=r(e,"H3",{class:!0});var Ws=o(H);oe=r(Ws,"A",{id:!0,class:!0,href:!0});var ln=o(oe);ma=r(ln,"SPAN",{});var nn=o(ma);_(Fe.$$.fragment,nn),nn.forEach(t),ln.forEach(t),_o=c(Ws),da=r(Ws,"SPAN",{});var pn=o(da);mo=l(pn,"Inference from a training checkpoint"),pn.forEach(t),Ws.forEach(t),Es=c(e),le=r(e,"P",{});var Fs=o(le);go=l(Fs,"You can also perform inference from one of the complete checkpoint saved during the training process, if you used the "),ga=r(Fs,"CODE",{});var fn=o(ga);vo=l(fn,"--checkpointing_steps"),fn.forEach(t),wo=l(Fs," argument."),Fs.forEach(t),ys=c(e),_t=r(e,"P",{});var cn=o(_t);bo=l(cn,"TODO."),cn.forEach(t),ks=c(e),L=r(e,"H2",{class:!0});var Ks=o(L);ne=r(Ks,"A",{id:!0,class:!0,href:!0});var un=o(ne);va=r(un,"SPAN",{});var hn=o(va);_(Ke.$$.fragment,hn),hn.forEach(t),un.forEach(t),$o=c(Ks),wa=r(Ks,"SPAN",{});var _n=o(wa);Eo=l(_n,"Set grads to none"),_n.forEach(t),Ks.forEach(t),xs=c(e),pe=r(e,"P",{});var Js=o(pe);yo=l(Js,"To save even more memory, pass the "),ba=r(Js,"CODE",{});var mn=o(ba);ko=l(mn,"--set_grads_to_none"),mn.forEach(t),xo=l(Js," argument to the script. This will set grads to None instead of zero. However, be aware that it changes certain behaviors, so if you start experiencing any problems, remove this argument."),Js.forEach(t),js=c(e),Je=r(e,"P",{});var Co=o(Je);jo=l(Co,"More info: "),Qe=r(Co,"A",{href:!0,rel:!0});var dn=o(Qe);qo=l(dn,"https://pytorch.org/docs/stable/generated/torch.optim.Optimizer.zero_grad.html"),dn.forEach(t),Co.forEach(t),qs=c(e),B=r(e,"H2",{class:!0});var Qs=o(B);fe=r(Qs,"A",{id:!0,class:!0,href:!0});var gn=o(fe);$a=r(gn,"SPAN",{});var vn=o($a);_(Xe.$$.fragment,vn),vn.forEach(t),gn.forEach(t),Do=c(Qs),Ea=r(Qs,"SPAN",{});var wn=o(Ea);To=l(wn,"Experimental results"),wn.forEach(t),Qs.forEach(t),Ds=c(e),ce=r(e,"P",{});var Xs=o(ce);Po=l(Xs,"You can refer to "),Ze=r(Xs,"A",{href:!0,rel:!0});var bn=o(Ze);Ao=l(bn,"our webpage"),bn.forEach(t),Oo=l(Xs," that discusses our experiments in detail."),Xs.forEach(t),this.h()},h(){u(T,"name","hf:doc:metadata"),u(T,"content",JSON.stringify(Dn)),u(V,"id","custom-diffusion-training-example"),u(V,"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"),u(V,"href","#custom-diffusion-training-example"),u(P,"class","relative group"),u(_e,"href","https://arxiv.org/abs/2212.04488"),u(_e,"rel","nofollow"),u(me,"href","https://nupurkmr9.github.io/"),u(me,"rel","nofollow"),u(W,"id","running-locally-with-pytorch"),u(W,"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"),u(W,"href","#running-locally-with-pytorch"),u(O,"class","relative group"),u(F,"id","installing-the-dependencies"),u(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"),u(F,"href","#installing-the-dependencies"),u(C,"class","relative group"),u(be,"href","https://github.com/huggingface/accelerate/"),u(be,"rel","nofollow"),u(Q,"id","cat-example"),u(Q,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),u(Q,"href","#cat-example"),u(N,"class","relative group"),u(xe,"href","https://www.cs.cmu.edu/~custom-diffusion/assets/data.zip"),u(xe,"rel","nofollow"),u(qe,"href","https://huggingface.co/stabilityai/stable-diffusion-2"),u(qe,"rel","nofollow"),u(Te,"href","https://github.com/facebookresearch/xformers"),u(Te,"rel","nofollow"),u(Ce,"href","https://wandb.ai/sayakpaul/custom-diffusion/runs/26ghrcau"),u(Ce,"rel","nofollow"),u(Ne,"href","https://huggingface.co/sayakpaul/custom-diffusion-cat"),u(Ne,"rel","nofollow"),u(te,"id","training-on-multiple-concepts"),u(te,"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"),u(te,"href","#training-on-multiple-concepts"),u(M,"class","relative group"),u(Se,"href","https://github.com/adobe-research/custom-diffusion/blob/main/assets/concept_list.json"),u(Se,"rel","nofollow"),u(Re,"href","https://github.com/ShivamShrirao/diffusers/blob/main/examples/dreambooth/train_dreambooth.py"),u(Re,"rel","nofollow"),u(Ue,"href","https://wandb.ai/sayakpaul/custom-diffusion/runs/3990tzkg"),u(Ue,"rel","nofollow"),u(se,"id","training-on-human-faces"),u(se,"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"),u(se,"href","#training-on-human-faces"),u(z,"class","relative group"),u(re,"id","inference"),u(re,"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"),u(re,"href","#inference"),u(U,"class","relative group"),u(oe,"id","inference-from-a-training-checkpoint"),u(oe,"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"),u(oe,"href","#inference-from-a-training-checkpoint"),u(H,"class","relative group"),u(ne,"id","set-grads-to-none"),u(ne,"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"),u(ne,"href","#set-grads-to-none"),u(L,"class","relative group"),u(Qe,"href","https://pytorch.org/docs/stable/generated/torch.optim.Optimizer.zero_grad.html"),u(Qe,"rel","nofollow"),u(fe,"id","experimental-results"),u(fe,"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"),u(fe,"href","#experimental-results"),u(B,"class","relative group"),u(Ze,"href","https://www.cs.cmu.edu/~custom-diffusion/"),u(Ze,"rel","nofollow")},m(e,n){a(document.head,T),p(e,ka,n),p(e,P,n),a(P,V),a(V,Et),m(he,Et,null),a(P,Zs),a(P,yt),a(yt,er),p(e,xa,n),p(e,A,n),a(A,_e),a(_e,tr),a(A,ar),a(A,kt),a(kt,sr),a(A,rr),p(e,ja,n),p(e,Y,n),a(Y,ir),a(Y,me),a(me,or),a(Y,lr),p(e,qa,n),p(e,O,n),a(O,W),a(W,xt),m(de,xt,null),a(O,nr),a(O,jt),a(jt,pr),p(e,Da,n),p(e,C,n),a(C,F),a(F,qt),m(ge,qt,null),a(C,fr),a(C,Dt),a(Dt,cr),p(e,Ta,n),p(e,et,n),a(et,ur),p(e,Pa,n),p(e,tt,n),a(tt,Tt),a(Tt,hr),p(e,Aa,n),p(e,K,n),a(K,_r),a(K,Pt),a(Pt,mr),a(K,dr),p(e,Oa,n),m(ve,e,n),p(e,Ca,n),p(e,at,n),a(at,gr),p(e,Na,n),m(we,e,n),p(e,Ia,n),p(e,J,n),a(J,vr),a(J,be),a(be,wr),a(J,br),p(e,Sa,n),m($e,e,n),p(e,Ra,n),p(e,st,n),a(st,$r),p(e,Ma,n),m(Ee,e,n),p(e,za,n),p(e,rt,n),a(rt,Er),p(e,Ua,n),m(ye,e,n),p(e,Ha,n),p(e,N,n),a(N,Q),a(Q,At),m(ke,At,null),a(N,yr),a(N,Ot),a(Ot,kr),p(e,La,n),p(e,X,n),a(X,xr),a(X,xe),a(xe,jr),a(X,qr),p(e,Ba,n),p(e,w,n),a(w,Dr),a(w,Ct),a(Ct,Tr),a(w,Pr),a(w,Nt),a(Nt,Ar),a(w,Or),a(w,It),a(It,Cr),a(w,Nr),a(w,St),a(St,Ir),a(w,Sr),a(w,Rt),a(Rt,Rr),a(w,Mr),a(w,Mt),a(Mt,zr),a(w,Ur),a(w,zt),a(zt,Hr),a(w,Lr),a(w,Ut),a(Ut,Br),a(w,Gr),p(e,Ga,n),m(je,e,n),p(e,Va,n),p(e,it,n),a(it,Ht),a(Ht,Lt),a(Lt,I),a(I,Vr),a(I,Bt),a(Bt,Yr),a(I,Wr),a(I,qe),a(qe,Fr),a(I,Kr),p(e,Ya,n),m(De,e,n),p(e,Wa,n),p(e,ot,n),a(ot,S),a(S,Jr),a(S,Gt),a(Gt,Qr),a(S,Xr),a(S,Te),a(Te,Zr),a(S,ei),p(e,Fa,n),p(e,Z,n),a(Z,ti),a(Z,Vt),a(Vt,ai),a(Z,si),p(e,Ka,n),p(e,k,n),a(k,R),a(R,ri),a(R,Yt),a(Yt,ii),a(R,oi),a(R,Wt),a(Wt,li),a(R,ni),a(k,pi),a(k,Pe),a(Pe,fi),a(Pe,Ft),a(Ft,ci),a(Pe,ui),a(k,hi),a(k,E),a(E,_i),a(E,Kt),a(Kt,mi),a(E,di),a(E,Jt),a(Jt,gi),a(E,vi),a(E,Qt),a(Qt,wi),a(E,bi),a(E,Ae),a(Ae,Xt),a(Xt,Zt),a(Zt,$i),a(Ae,Ei),a(Ae,ea),a(ea,ta),a(ta,yi),p(e,Ja,n),p(e,lt,n),a(lt,ki),p(e,Qa,n),m(Oe,e,n),p(e,Xa,n),p(e,ee,n),a(ee,xi),a(ee,Ce),a(Ce,ji),a(ee,qi),p(e,Za,n),p(e,x,n),a(x,Di),a(x,aa),a(aa,Ti),a(x,Pi),a(x,Ne),a(Ne,Ai),a(x,Oi),p(e,es,n),p(e,M,n),a(M,te),a(te,sa),m(Ie,sa,null),a(M,Ci),a(M,ra),a(ra,Ni),p(e,ts,n),p(e,j,n),a(j,Ii),a(j,Se),a(Se,Si),a(j,Ri),a(j,Re),a(Re,Mi),a(j,zi),p(e,as,n),p(e,nt,n),a(nt,Ui),p(e,ss,n),m(Me,e,n),p(e,rs,n),p(e,pt,n),a(pt,Hi),p(e,is,n),m(ze,e,n),p(e,os,n),p(e,ae,n),a(ae,Li),a(ae,Ue),a(Ue,Bi),a(ae,Gi),p(e,ls,n),p(e,z,n),a(z,se),a(se,ia),m(He,ia,null),a(z,Vi),a(z,oa),a(oa,Yi),p(e,ns,n),p(e,y,n),a(y,Wi),a(y,la),a(la,Fi),a(y,Ki),a(y,na),a(na,Ji),a(y,Qi),a(y,pa),a(pa,Xi),a(y,Zi),p(e,ps,n),p(e,ft,n),a(ft,eo),p(e,fs,n),m(Le,e,n),p(e,cs,n),p(e,ct,n),a(ct,to),p(e,us,n),m(Be,e,n),p(e,hs,n),p(e,U,n),a(U,re),a(re,fa),m(Ge,fa,null),a(U,ao),a(U,ca),a(ca,so),p(e,_s,n),p(e,ie,n),a(ie,ro),a(ie,ua),a(ua,io),a(ie,oo),p(e,ms,n),m(Ve,e,n),p(e,ds,n),p(e,ut,n),a(ut,lo),p(e,gs,n),m(Ye,e,n),p(e,vs,n),p(e,ht,n),a(ht,no),p(e,ws,n),m(We,e,n),p(e,bs,n),p(e,q,n),a(q,po),a(q,ha),a(ha,fo),a(q,co),a(q,_a),a(_a,uo),a(q,ho),p(e,$s,n),p(e,H,n),a(H,oe),a(oe,ma),m(Fe,ma,null),a(H,_o),a(H,da),a(da,mo),p(e,Es,n),p(e,le,n),a(le,go),a(le,ga),a(ga,vo),a(le,wo),p(e,ys,n),p(e,_t,n),a(_t,bo),p(e,ks,n),p(e,L,n),a(L,ne),a(ne,va),m(Ke,va,null),a(L,$o),a(L,wa),a(wa,Eo),p(e,xs,n),p(e,pe,n),a(pe,yo),a(pe,ba),a(ba,ko),a(pe,xo),p(e,js,n),p(e,Je,n),a(Je,jo),a(Je,Qe),a(Qe,qo),p(e,qs,n),p(e,B,n),a(B,fe),a(fe,$a),m(Xe,$a,null),a(B,Do),a(B,Ea),a(Ea,To),p(e,Ds,n),p(e,ce,n),a(ce,Po),a(ce,Ze),a(Ze,Ao),a(ce,Oo),Ts=!0},p:xn,i(e){Ts||(d(he.$$.fragment,e),d(de.$$.fragment,e),d(ge.$$.fragment,e),d(ve.$$.fragment,e),d(we.$$.fragment,e),d($e.$$.fragment,e),d(Ee.$$.fragment,e),d(ye.$$.fragment,e),d(ke.$$.fragment,e),d(je.$$.fragment,e),d(De.$$.fragment,e),d(Oe.$$.fragment,e),d(Ie.$$.fragment,e),d(Me.$$.fragment,e),d(ze.$$.fragment,e),d(He.$$.fragment,e),d(Le.$$.fragment,e),d(Be.$$.fragment,e),d(Ge.$$.fragment,e),d(Ve.$$.fragment,e),d(Ye.$$.fragment,e),d(We.$$.fragment,e),d(Fe.$$.fragment,e),d(Ke.$$.fragment,e),d(Xe.$$.fragment,e),Ts=!0)},o(e){g(he.$$.fragment,e),g(de.$$.fragment,e),g(ge.$$.fragment,e),g(ve.$$.fragment,e),g(we.$$.fragment,e),g($e.$$.fragment,e),g(Ee.$$.fragment,e),g(ye.$$.fragment,e),g(ke.$$.fragment,e),g(je.$$.fragment,e),g(De.$$.fragment,e),g(Oe.$$.fragment,e),g(Ie.$$.fragment,e),g(Me.$$.fragment,e),g(ze.$$.fragment,e),g(He.$$.fragment,e),g(Le.$$.fragment,e),g(Be.$$.fragment,e),g(Ge.$$.fragment,e),g(Ve.$$.fragment,e),g(Ye.$$.fragment,e),g(We.$$.fragment,e),g(Fe.$$.fragment,e),g(Ke.$$.fragment,e),g(Xe.$$.fragment,e),Ts=!1},d(e){t(T),e&&t(ka),e&&t(P),v(he),e&&t(xa),e&&t(A),e&&t(ja),e&&t(Y),e&&t(qa),e&&t(O),v(de),e&&t(Da),e&&t(C),v(ge),e&&t(Ta),e&&t(et),e&&t(Pa),e&&t(tt),e&&t(Aa),e&&t(K),e&&t(Oa),v(ve,e),e&&t(Ca),e&&t(at),e&&t(Na),v(we,e),e&&t(Ia),e&&t(J),e&&t(Sa),v($e,e),e&&t(Ra),e&&t(st),e&&t(Ma),v(Ee,e),e&&t(za),e&&t(rt),e&&t(Ua),v(ye,e),e&&t(Ha),e&&t(N),v(ke),e&&t(La),e&&t(X),e&&t(Ba),e&&t(w),e&&t(Ga),v(je,e),e&&t(Va),e&&t(it),e&&t(Ya),v(De,e),e&&t(Wa),e&&t(ot),e&&t(Fa),e&&t(Z),e&&t(Ka),e&&t(k),e&&t(Ja),e&&t(lt),e&&t(Qa),v(Oe,e),e&&t(Xa),e&&t(ee),e&&t(Za),e&&t(x),e&&t(es),e&&t(M),v(Ie),e&&t(ts),e&&t(j),e&&t(as),e&&t(nt),e&&t(ss),v(Me,e),e&&t(rs),e&&t(pt),e&&t(is),v(ze,e),e&&t(os),e&&t(ae),e&&t(ls),e&&t(z),v(He),e&&t(ns),e&&t(y),e&&t(ps),e&&t(ft),e&&t(fs),v(Le,e),e&&t(cs),e&&t(ct),e&&t(us),v(Be,e),e&&t(hs),e&&t(U),v(Ge),e&&t(_s),e&&t(ie),e&&t(ms),v(Ve,e),e&&t(ds),e&&t(ut),e&&t(gs),v(Ye,e),e&&t(vs),e&&t(ht),e&&t(ws),v(We,e),e&&t(bs),e&&t(q),e&&t($s),e&&t(H),v(Fe),e&&t(Es),e&&t(le),e&&t(ys),e&&t(_t),e&&t(ks),e&&t(L),v(Ke),e&&t(xs),e&&t(pe),e&&t(js),e&&t(Je),e&&t(qs),e&&t(B),v(Xe),e&&t(Ds),e&&t(ce)}}}const Dn={local:"custom-diffusion-training-example",sections:[{local:"running-locally-with-pytorch",sections:[{local:"installing-the-dependencies",title:"Installing the dependencies"},{local:"cat-example",title:"Cat example \u{1F63A}"},{local:"training-on-multiple-concepts",title:"Training on multiple concepts \u{1F431}\u{1FAB5}"},{local:"training-on-human-faces",title:"Training on human faces"}],title:"Running locally with PyTorch"},{local:"inference",sections:[{local:"inference-from-a-training-checkpoint",title:"Inference from a training checkpoint"}],title:"Inference"},{local:"set-grads-to-none",title:"Set grads to none"},{local:"experimental-results",title:"Experimental results"}],title:"Custom Diffusion training example "};function Tn(No){return jn(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Cn extends $n{constructor(T){super();En(this,T,Tn,qn,yn,{})}}export{Cn as default,Dn as metadata};
