import{S as Wr,i as Jr,s as Zr,e as o,k as c,w as u,t as n,M as Kr,c as i,d as t,m as f,a as r,x as m,h as l,b as h,N as Qr,G as a,g as p,y as d,q as _,o as g,B as v,v as Xr}from"../../chunks/vendor-hf-doc-builder.js";import{T as Fr}from"../../chunks/Tip-hf-doc-builder.js";import{I as A}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{C as P}from"../../chunks/CodeBlock-hf-doc-builder.js";function en(st){let b,$,w,y,N;return{c(){b=o("p"),$=n("Dreambooth fine-tuning is very sensitive to hyperparameters and easy to overfit. We recommend you take a look at our "),w=o("a"),y=n("in-depth analysis"),N=n(" with recommended settings for different subjects, and go from there."),this.h()},l(E){b=i(E,"P",{});var S=r(b);$=l(S,"Dreambooth fine-tuning is very sensitive to hyperparameters and easy to overfit. We recommend you take a look at our "),w=i(S,"A",{href:!0,rel:!0});var Y=r(w);y=l(Y,"in-depth analysis"),Y.forEach(t),N=l(S," with recommended settings for different subjects, and go from there."),S.forEach(t),this.h()},h(){h(w,"href","https://huggingface.co/blog/dreambooth"),h(w,"rel","nofollow")},m(E,S){p(E,b,S),a(b,$),a(b,w),a(w,y),a(b,N)},d(E){E&&t(b)}}}function tn(st){let b;return{c(){b=n("Training the text encoder requires additional memory, so training won't fit on a 16GB GPU. You'll need at least 24GB VRAM to use this option.")},l($){b=l($,"Training the text encoder requires additional memory, so training won't fit on a 16GB GPU. You'll need at least 24GB VRAM to use this option.")},m($,w){p($,b,w)},d($){$&&t(b)}}}function an(st){let b,$,w,y,N,E,S,Y,xs,oa,$e,Ee,As,Ps,ia,F,ot,Si,Ss,ye,Ts,ke,js,qs,ra,W,Is,De,Ns,Cs,na,J,la,C,Z,_t,xe,Rs,gt,Us,pa,R,K,vt,Ae,Os,bt,Ms,ha,T,Ls,wt,Gs,Bs,$t,zs,Vs,ca,Pe,fa,Q,Hs,it,Ys,Fs,ua,X,Ws,Se,Js,Zs,ma,Te,da,j,Ks,Et,Qs,Xs,je,eo,to,_a,ee,ao,yt,so,oo,ga,U,te,kt,qe,io,Dt,ro,va,ae,no,Ie,lo,po,ba,rt,ho,wa,Ne,$a,O,se,xt,Ce,co,At,fo,Ea,nt,uo,ya,oe,mo,Pt,_o,go,ka,Re,Da,M,ie,St,Ue,vo,Tt,bo,xa,lt,wo,Aa,Oe,Pa,k,$o,jt,Eo,yo,qt,ko,Do,It,xo,Ao,Sa,L,re,Nt,Me,Po,Ct,So,Ta,q,To,Rt,jo,qo,Ut,Io,No,ja,Le,qa,pt,Co,Ia,G,ne,Ot,Ge,Ro,Mt,Uo,Na,ht,Oo,Ca,ct,Mo,Ra,Be,Ua,B,le,Lt,ze,Lo,Gt,Go,Oa,pe,Bo,Ve,zo,Vo,Ma,He,La,he,Ho,Bt,Yo,Fo,Ga,Ye,Ba,z,ce,zt,Fe,Wo,Vt,Jo,za,D,Zo,Ht,Ko,Qo,Yt,Xo,ei,We,ti,ai,Va,fe,si,Ft,oi,ii,Ha,ue,Ya,Je,Fa,V,me,Wt,Ze,ri,Jt,ni,Wa,de,li,Ke,pi,hi,Ja,I,ci,Zt,fi,ui,Qe,mi,di,Za,_e,_i,Kt,gi,vi,Ka,Xe,Qa,H,ge,Qt,et,bi,Xt,wi,Xa,x,$i,ea,Ei,yi,ta,ki,Di,aa,xi,Ai,es,tt,ts;return E=new A({}),J=new Fr({props:{warning:!0,$$slots:{default:[en]},$$scope:{ctx:st}}}),xe=new A({}),Ae=new A({}),Pe=new P({props:{code:`pip install git+https://github.com/huggingface/diffusers
pip install -U -r diffusers/examples/dreambooth/requirements.txt`,highlighted:`pip install git+https://github.com/huggingface/diffusers
pip install -U -r diffusers/examples/dreambooth/requirements.txt`}}),Te=new P({props:{code:"accelerate config",highlighted:"accelerate config"}}),qe=new A({}),Ne=new P({props:{code:`export MODEL_NAME="CompVis/stable-diffusion-v1-4"
export INSTANCE_DIR="path_to_training_images"
export OUTPUT_DIR="path_to_saved_model"

accelerate launch train_dreambooth.py \\
  --pretrained_model_name_or_path=$MODEL_NAME  \\
  --instance_data_dir=$INSTANCE_DIR \\
  --output_dir=$OUTPUT_DIR \\
  --instance_prompt="a photo of sks dog" \\
  --resolution=512 \\
  --train_batch_size=1 \\
  --gradient_accumulation_steps=1 \\
  --learning_rate=5e-6 \\
  --lr_scheduler="constant" \\
  --lr_warmup_steps=0 \\
  --max_train_steps=400`,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> INSTANCE_DIR=<span class="hljs-string">&quot;path_to_training_images&quot;</span>
<span class="hljs-built_in">export</span> OUTPUT_DIR=<span class="hljs-string">&quot;path_to_saved_model&quot;</span>

accelerate launch train_dreambooth.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> \\
  --instance_prompt=<span class="hljs-string">&quot;a photo of sks dog&quot;</span> \\
  --resolution=512 \\
  --train_batch_size=1 \\
  --gradient_accumulation_steps=1 \\
  --learning_rate=5e-6 \\
  --lr_scheduler=<span class="hljs-string">&quot;constant&quot;</span> \\
  --lr_warmup_steps=0 \\
  --max_train_steps=400`}}),Ce=new A({}),Re=new P({props:{code:`export MODEL_NAME="CompVis/stable-diffusion-v1-4"
export INSTANCE_DIR="path_to_training_images"
export CLASS_DIR="path_to_class_images"
export OUTPUT_DIR="path_to_saved_model"

accelerate launch train_dreambooth.py \\
  --pretrained_model_name_or_path=$MODEL_NAME  \\
  --instance_data_dir=$INSTANCE_DIR \\
  --class_data_dir=$CLASS_DIR \\
  --output_dir=$OUTPUT_DIR \\
  --with_prior_preservation --prior_loss_weight=1.0 \\
  --instance_prompt="a photo of sks dog" \\
  --class_prompt="a photo of dog" \\
  --resolution=512 \\
  --train_batch_size=1 \\
  --gradient_accumulation_steps=1 \\
  --learning_rate=5e-6 \\
  --lr_scheduler="constant" \\
  --lr_warmup_steps=0 \\
  --num_class_images=200 \\
  --max_train_steps=800`,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> INSTANCE_DIR=<span class="hljs-string">&quot;path_to_training_images&quot;</span>
<span class="hljs-built_in">export</span> CLASS_DIR=<span class="hljs-string">&quot;path_to_class_images&quot;</span>
<span class="hljs-built_in">export</span> OUTPUT_DIR=<span class="hljs-string">&quot;path_to_saved_model&quot;</span>

accelerate launch train_dreambooth.py \\
  --pretrained_model_name_or_path=<span class="hljs-variable">$MODEL_NAME</span>  \\
  --instance_data_dir=<span class="hljs-variable">$INSTANCE_DIR</span> \\
  --class_data_dir=<span class="hljs-variable">$CLASS_DIR</span> \\
  --output_dir=<span class="hljs-variable">$OUTPUT_DIR</span> \\
  --with_prior_preservation --prior_loss_weight=1.0 \\
  --instance_prompt=<span class="hljs-string">&quot;a photo of sks dog&quot;</span> \\
  --class_prompt=<span class="hljs-string">&quot;a photo of dog&quot;</span> \\
  --resolution=512 \\
  --train_batch_size=1 \\
  --gradient_accumulation_steps=1 \\
  --learning_rate=5e-6 \\
  --lr_scheduler=<span class="hljs-string">&quot;constant&quot;</span> \\
  --lr_warmup_steps=0 \\
  --num_class_images=200 \\
  --max_train_steps=800`}}),Ue=new A({}),Oe=new P({props:{code:"  --checkpointing_steps=500",highlighted:"  --checkpointing_steps=500"}}),Me=new A({}),Le=new P({props:{code:'  --resume_from_checkpoint="checkpoint-1500"',highlighted:'  --resume_from_checkpoint=<span class="hljs-string">&quot;checkpoint-1500&quot;</span>'}}),Ge=new A({}),Be=new P({props:{code:`from accelerate import Accelerator
from diffusers import DiffusionPipeline

# Load the pipeline with the same arguments (model, revision) that were used for training
model_id = "CompVis/stable-diffusion-v1-4"
pipeline = DiffusionPipeline.from_pretrained(model_id)

accelerator = Accelerator()

# Use text_encoder if \`--train_text_encoder\` was used for the initial training
unet, text_encoder = accelerator.prepare(pipeline.unet, pipeline.text_encoder)

# Restore state from a checkpoint path. You have to use the absolute path here.
accelerator.load_state("/sddata/dreambooth/daruma-v2-1/checkpoint-100")

# Rebuild the pipeline with the unwrapped models (assignment to .unet and .text_encoder should work too)
pipeline = DiffusionPipeline.from_pretrained(
    model_id,
    unet=accelerator.unwrap_model(unet),
    text_encoder=accelerator.unwrap_model(text_encoder),
)

# Perform inference, or save, or push to the hub
pipeline.save_pretrained("dreambooth-pipeline")`,highlighted:`<span class="hljs-keyword">from</span> accelerate <span class="hljs-keyword">import</span> Accelerator
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DiffusionPipeline

<span class="hljs-comment"># Load the pipeline with the same arguments (model, revision) that were used for training</span>
model_id = <span class="hljs-string">&quot;CompVis/stable-diffusion-v1-4&quot;</span>
pipeline = DiffusionPipeline.from_pretrained(model_id)

accelerator = Accelerator()

<span class="hljs-comment"># Use text_encoder if \`--train_text_encoder\` was used for the initial training</span>
unet, text_encoder = accelerator.prepare(pipeline.unet, pipeline.text_encoder)

<span class="hljs-comment"># Restore state from a checkpoint path. You have to use the absolute path here.</span>
accelerator.load_state(<span class="hljs-string">&quot;/sddata/dreambooth/daruma-v2-1/checkpoint-100&quot;</span>)

<span class="hljs-comment"># Rebuild the pipeline with the unwrapped models (assignment to .unet and .text_encoder should work too)</span>
pipeline = DiffusionPipeline.from_pretrained(
    model_id,
    unet=accelerator.unwrap_model(unet),
    text_encoder=accelerator.unwrap_model(text_encoder),
)

<span class="hljs-comment"># Perform inference, or save, or push to the hub</span>
pipeline.save_pretrained(<span class="hljs-string">&quot;dreambooth-pipeline&quot;</span>)`}}),ze=new A({}),He=new P({props:{code:"pip install bitsandbytes",highlighted:"pip install bitsandbytes"}}),Ye=new P({props:{code:`export MODEL_NAME="CompVis/stable-diffusion-v1-4"
export INSTANCE_DIR="path_to_training_images"
export CLASS_DIR="path_to_class_images"
export OUTPUT_DIR="path_to_saved_model"

accelerate launch train_dreambooth.py \\
  --pretrained_model_name_or_path=$MODEL_NAME  \\
  --instance_data_dir=$INSTANCE_DIR \\
  --class_data_dir=$CLASS_DIR \\
  --output_dir=$OUTPUT_DIR \\
  --with_prior_preservation --prior_loss_weight=1.0 \\
  --instance_prompt="a photo of sks dog" \\
  --class_prompt="a photo of dog" \\
  --resolution=512 \\
  --train_batch_size=1 \\
  --gradient_accumulation_steps=2 --gradient_checkpointing \\
  --use_8bit_adam \\
  --learning_rate=5e-6 \\
  --lr_scheduler="constant" \\
  --lr_warmup_steps=0 \\
  --num_class_images=200 \\
  --max_train_steps=800`,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> INSTANCE_DIR=<span class="hljs-string">&quot;path_to_training_images&quot;</span>
<span class="hljs-built_in">export</span> CLASS_DIR=<span class="hljs-string">&quot;path_to_class_images&quot;</span>
<span class="hljs-built_in">export</span> OUTPUT_DIR=<span class="hljs-string">&quot;path_to_saved_model&quot;</span>

accelerate launch train_dreambooth.py \\
  --pretrained_model_name_or_path=<span class="hljs-variable">$MODEL_NAME</span>  \\
  --instance_data_dir=<span class="hljs-variable">$INSTANCE_DIR</span> \\
  --class_data_dir=<span class="hljs-variable">$CLASS_DIR</span> \\
  --output_dir=<span class="hljs-variable">$OUTPUT_DIR</span> \\
  --with_prior_preservation --prior_loss_weight=1.0 \\
  --instance_prompt=<span class="hljs-string">&quot;a photo of sks dog&quot;</span> \\
  --class_prompt=<span class="hljs-string">&quot;a photo of dog&quot;</span> \\
  --resolution=512 \\
  --train_batch_size=1 \\
  --gradient_accumulation_steps=2 --gradient_checkpointing \\
  --use_8bit_adam \\
  --learning_rate=5e-6 \\
  --lr_scheduler=<span class="hljs-string">&quot;constant&quot;</span> \\
  --lr_warmup_steps=0 \\
  --num_class_images=200 \\
  --max_train_steps=800`}}),Fe=new A({}),ue=new Fr({props:{$$slots:{default:[tn]},$$scope:{ctx:st}}}),Je=new P({props:{code:`export MODEL_NAME="CompVis/stable-diffusion-v1-4"
export INSTANCE_DIR="path_to_training_images"
export CLASS_DIR="path_to_class_images"
export OUTPUT_DIR="path_to_saved_model"

accelerate launch train_dreambooth.py \\
  --pretrained_model_name_or_path=$MODEL_NAME  \\
  --train_text_encoder \\
  --instance_data_dir=$INSTANCE_DIR \\
  --class_data_dir=$CLASS_DIR \\
  --output_dir=$OUTPUT_DIR \\
  --with_prior_preservation --prior_loss_weight=1.0 \\
  --instance_prompt="a photo of sks dog" \\
  --class_prompt="a photo of dog" \\
  --resolution=512 \\
  --train_batch_size=1 \\
  --use_8bit_adam
  --gradient_checkpointing \\
  --learning_rate=2e-6 \\
  --lr_scheduler="constant" \\
  --lr_warmup_steps=0 \\
  --num_class_images=200 \\
  --max_train_steps=800`,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> INSTANCE_DIR=<span class="hljs-string">&quot;path_to_training_images&quot;</span>
<span class="hljs-built_in">export</span> CLASS_DIR=<span class="hljs-string">&quot;path_to_class_images&quot;</span>
<span class="hljs-built_in">export</span> OUTPUT_DIR=<span class="hljs-string">&quot;path_to_saved_model&quot;</span>

accelerate launch train_dreambooth.py \\
  --pretrained_model_name_or_path=<span class="hljs-variable">$MODEL_NAME</span>  \\
  --train_text_encoder \\
  --instance_data_dir=<span class="hljs-variable">$INSTANCE_DIR</span> \\
  --class_data_dir=<span class="hljs-variable">$CLASS_DIR</span> \\
  --output_dir=<span class="hljs-variable">$OUTPUT_DIR</span> \\
  --with_prior_preservation --prior_loss_weight=1.0 \\
  --instance_prompt=<span class="hljs-string">&quot;a photo of sks dog&quot;</span> \\
  --class_prompt=<span class="hljs-string">&quot;a photo of dog&quot;</span> \\
  --resolution=512 \\
  --train_batch_size=1 \\
  --use_8bit_adam
  --gradient_checkpointing \\
  --learning_rate=2e-6 \\
  --lr_scheduler=<span class="hljs-string">&quot;constant&quot;</span> \\
  --lr_warmup_steps=0 \\
  --num_class_images=200 \\
  --max_train_steps=800`}}),Ze=new A({}),Xe=new P({props:{code:`export MODEL_NAME="CompVis/stable-diffusion-v1-4"
export INSTANCE_DIR="path_to_training_images"
export CLASS_DIR="path_to_class_images"
export OUTPUT_DIR="path_to_saved_model"

accelerate launch train_dreambooth.py \\
  --pretrained_model_name_or_path=$MODEL_NAME \\
  --instance_data_dir=$INSTANCE_DIR \\
  --class_data_dir=$CLASS_DIR \\
  --output_dir=$OUTPUT_DIR \\
  --with_prior_preservation --prior_loss_weight=1.0 \\
  --instance_prompt="a photo of sks dog" \\
  --class_prompt="a photo of dog" \\
  --resolution=512 \\
  --train_batch_size=1 \\
  --sample_batch_size=1 \\
  --gradient_accumulation_steps=1 --gradient_checkpointing \\
  --learning_rate=5e-6 \\
  --lr_scheduler="constant" \\
  --lr_warmup_steps=0 \\
  --num_class_images=200 \\
  --max_train_steps=800 \\
  --mixed_precision=fp16`,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> INSTANCE_DIR=<span class="hljs-string">&quot;path_to_training_images&quot;</span>
<span class="hljs-built_in">export</span> CLASS_DIR=<span class="hljs-string">&quot;path_to_class_images&quot;</span>
<span class="hljs-built_in">export</span> OUTPUT_DIR=<span class="hljs-string">&quot;path_to_saved_model&quot;</span>

accelerate launch train_dreambooth.py \\
  --pretrained_model_name_or_path=<span class="hljs-variable">$MODEL_NAME</span> \\
  --instance_data_dir=<span class="hljs-variable">$INSTANCE_DIR</span> \\
  --class_data_dir=<span class="hljs-variable">$CLASS_DIR</span> \\
  --output_dir=<span class="hljs-variable">$OUTPUT_DIR</span> \\
  --with_prior_preservation --prior_loss_weight=1.0 \\
  --instance_prompt=<span class="hljs-string">&quot;a photo of sks dog&quot;</span> \\
  --class_prompt=<span class="hljs-string">&quot;a photo of dog&quot;</span> \\
  --resolution=512 \\
  --train_batch_size=1 \\
  --sample_batch_size=1 \\
  --gradient_accumulation_steps=1 --gradient_checkpointing \\
  --learning_rate=5e-6 \\
  --lr_scheduler=<span class="hljs-string">&quot;constant&quot;</span> \\
  --lr_warmup_steps=0 \\
  --num_class_images=200 \\
  --max_train_steps=800 \\
  --mixed_precision=fp16`}}),et=new A({}),tt=new P({props:{code:`from diffusers import StableDiffusionPipeline
import torch

model_id = "path_to_saved_model"
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16).to("cuda")

prompt = "A photo of sks dog in a bucket"
image = pipe(prompt, num_inference_steps=50, guidance_scale=7.5).images[0]

image.save("dog-bucket.png")`,highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> StableDiffusionPipeline
<span class="hljs-keyword">import</span> torch

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

prompt = <span class="hljs-string">&quot;A photo of sks dog in a bucket&quot;</span>
image = pipe(prompt, num_inference_steps=<span class="hljs-number">50</span>, guidance_scale=<span class="hljs-number">7.5</span>).images[<span class="hljs-number">0</span>]

image.save(<span class="hljs-string">&quot;dog-bucket.png&quot;</span>)`}}),{c(){b=o("meta"),$=c(),w=o("h1"),y=o("a"),N=o("span"),u(E.$$.fragment),S=c(),Y=o("span"),xs=n("DreamBooth fine-tuning example"),oa=c(),$e=o("p"),Ee=o("a"),As=n("DreamBooth"),Ps=n(" is a method to personalize text-to-image models like stable diffusion given just a few (3~5) images of a subject."),ia=c(),F=o("p"),ot=o("img"),Ss=c(),ye=o("em"),Ts=n("Dreambooth examples from the "),ke=o("a"),js=n("project\u2019s blog"),qs=n("."),ra=c(),W=o("p"),Is=n("The "),De=o("a"),Ns=n("Dreambooth training script"),Cs=n(" shows how to implement this training procedure on a pre-trained Stable Diffusion model."),na=c(),u(J.$$.fragment),la=c(),C=o("h2"),Z=o("a"),_t=o("span"),u(xe.$$.fragment),Rs=c(),gt=o("span"),Us=n("Training locally"),pa=c(),R=o("h3"),K=o("a"),vt=o("span"),u(Ae.$$.fragment),Os=c(),bt=o("span"),Ms=n("Installing the dependencies"),ha=c(),T=o("p"),Ls=n("Before running the scripts, make sure to install the library\u2019s training dependencies. We also recommend to install "),wt=o("code"),Gs=n("diffusers"),Bs=n(" from the "),$t=o("code"),zs=n("main"),Vs=n(" github branch."),ca=c(),u(Pe.$$.fragment),fa=c(),Q=o("p"),Hs=n("xFormers is not part of the training requirements, but "),it=o("a"),Ys=n("we recommend you install it if you can"),Fs=n(". It could make your training faster and less memory intensive."),ua=c(),X=o("p"),Ws=n("After all dependencies have been set up you can configure a "),Se=o("a"),Js=n("\u{1F917} Accelerate"),Zs=n(" environment with:"),ma=c(),u(Te.$$.fragment),da=c(),j=o("p"),Ks=n("In this example we\u2019ll use model version "),Et=o("code"),Qs=n("v1-4"),Xs=n(", so please visit "),je=o("a"),eo=n("its card"),to=n(" and carefully read the license before proceeding."),_a=c(),ee=o("p"),ao=n("The command below will download and cache the model weights from the Hub because we use the model\u2019s Hub id "),yt=o("code"),so=n("CompVis/stable-diffusion-v1-4"),oo=n(". You may also clone the repo locally and use the local path in your system where the checkout was saved."),ga=c(),U=o("h3"),te=o("a"),kt=o("span"),u(qe.$$.fragment),io=c(),Dt=o("span"),ro=n("Dog toy example"),va=c(),ae=o("p"),no=n("In this example we\u2019ll use "),Ie=o("a"),lo=n("these images"),po=n(" to add a new concept to Stable Diffusion using the Dreambooth process. They will be our training data. Please, download them and place them somewhere in your system."),ba=c(),rt=o("p"),ho=n("Then you can launch the training script using:"),wa=c(),u(Ne.$$.fragment),$a=c(),O=o("h3"),se=o("a"),xt=o("span"),u(Ce.$$.fragment),co=c(),At=o("span"),fo=n("Training with a prior-preserving loss"),Ea=c(),nt=o("p"),uo=n("Prior preservation is used to avoid overfitting and language-drift. Please, refer to the paper to learn more about it if you are interested. For prior preservation, we use other images of the same class as part of the training process. The nice thing is that we can generate those images using the Stable Diffusion model itself! The training script will save the generated images to a local path we specify."),ya=c(),oe=o("p"),mo=n("According to the paper, it\u2019s recommended to generate "),Pt=o("code"),_o=n("num_epochs * num_samples"),go=n(" images for prior preservation. 200-300 works well for most cases."),ka=c(),u(Re.$$.fragment),Da=c(),M=o("h3"),ie=o("a"),St=o("span"),u(Ue.$$.fragment),vo=c(),Tt=o("span"),bo=n("Saving checkpoints while training"),xa=c(),lt=o("p"),wo=n("It\u2019s easy to overfit while training with Dreambooth, so sometimes it\u2019s useful to save regular checkpoints during the process. One of the intermediate checkpoints might work better than the final model! To use this feature you need to pass the following argument to the training script:"),Aa=c(),u(Oe.$$.fragment),Pa=c(),k=o("p"),$o=n("This will save the full training state in subfolders of your "),jt=o("code"),Eo=n("output_dir"),yo=n(". Subfolder names begin with the prefix "),qt=o("code"),ko=n("checkpoint-"),Do=n(", and then the number of steps performed so far; for example: "),It=o("code"),xo=n("checkpoint-1500"),Ao=n(" would be a checkpoint saved after 1500 training steps."),Sa=c(),L=o("h4"),re=o("a"),Nt=o("span"),u(Me.$$.fragment),Po=c(),Ct=o("span"),So=n("Resuming training from a saved checkpoint"),Ta=c(),q=o("p"),To=n("If you want to resume training from any of the saved checkpoints, you can pass the argument "),Rt=o("code"),jo=n("--resume_from_checkpoint"),qo=n(" and then indicate the name of the checkpoint you want to use. You can also use the special string "),Ut=o("code"),Io=n('"latest"'),No=n(" to resume from the last checkpoint saved (i.e., the one with the largest number of steps). For example, the following would resume training from the checkpoint saved after 1500 steps:"),ja=c(),u(Le.$$.fragment),qa=c(),pt=o("p"),Co=n("This would be a good opportunity to tweak some of your hyperparameters if you wish."),Ia=c(),G=o("h4"),ne=o("a"),Ot=o("span"),u(Ge.$$.fragment),Ro=c(),Mt=o("span"),Uo=n("Performing inference using a saved checkpoint"),Na=c(),ht=o("p"),Oo=n("Saved checkpoints are stored in a format suitable for resuming training. They not only include the model weights, but also the state of the optimizer, data loaders and learning rate."),Ca=c(),ct=o("p"),Mo=n("You can use a checkpoint for inference, but first you need to convert it to an inference pipeline. This is how you could do it:"),Ra=c(),u(Be.$$.fragment),Ua=c(),B=o("h3"),le=o("a"),Lt=o("span"),u(ze.$$.fragment),Lo=c(),Gt=o("span"),Go=n("Training on a 16GB GPU"),Oa=c(),pe=o("p"),Bo=n("With the help of gradient checkpointing and the 8-bit optimizer from "),Ve=o("a"),zo=n("bitsandbytes"),Vo=n(", it\u2019s possible to train dreambooth on a 16GB GPU."),Ma=c(),u(He.$$.fragment),La=c(),he=o("p"),Ho=n("Then pass the "),Bt=o("code"),Yo=n("--use_8bit_adam"),Fo=n(" option to the training script."),Ga=c(),u(Ye.$$.fragment),Ba=c(),z=o("h3"),ce=o("a"),zt=o("span"),u(Fe.$$.fragment),Wo=c(),Vt=o("span"),Jo=n("Fine-tune the text encoder in addition to the UNet"),za=c(),D=o("p"),Zo=n("The script also allows to fine-tune the "),Ht=o("code"),Ko=n("text_encoder"),Qo=n(" along with the "),Yt=o("code"),Xo=n("unet"),ei=n(". It has been observed experimentally that this gives much better results, especially on faces. Please, refer to "),We=o("a"),ti=n("our blog"),ai=n(" for more details."),Va=c(),fe=o("p"),si=n("To enable this option, pass the "),Ft=o("code"),oi=n("--train_text_encoder"),ii=n(" argument to the training script."),Ha=c(),u(ue.$$.fragment),Ya=c(),u(Je.$$.fragment),Fa=c(),V=o("h3"),me=o("a"),Wt=o("span"),u(Ze.$$.fragment),ri=c(),Jt=o("span"),ni=n("Training on a 8 GB GPU:"),Wa=c(),de=o("p"),li=n("Using "),Ke=o("a"),pi=n("DeepSpeed"),hi=n(` it\u2019s even possible to offload some
tensors from VRAM to either CPU or NVME, allowing training to proceed with less GPU memory.`),Ja=c(),I=o("p"),ci=n("DeepSpeed needs to be enabled with "),Zt=o("code"),fi=n("accelerate config"),ui=n(`. During configuration,
answer yes to \u201CDo you want to use DeepSpeed?\u201C. Combining DeepSpeed stage 2, fp16
mixed precision, and offloading both the model parameters and the optimizer state to CPU, it\u2019s
possible to train on under 8 GB VRAM. The drawback is that this requires more system RAM (about 25 GB). See `),Qe=o("a"),mi=n("the DeepSpeed documentation"),di=n(" for more configuration options."),Za=c(),_e=o("p"),_i=n(`Changing the default Adam optimizer to DeepSpeed\u2019s special version of Adam
`),Kt=o("code"),gi=n("deepspeed.ops.adam.DeepSpeedCPUAdam"),vi=n(` gives a substantial speedup, but enabling
it requires the system\u2019s CUDA toolchain version to be the same as the one installed with PyTorch. 8-bit optimizers don\u2019t seem to be compatible with DeepSpeed at the moment.`),Ka=c(),u(Xe.$$.fragment),Qa=c(),H=o("h2"),ge=o("a"),Qt=o("span"),u(et.$$.fragment),bi=c(),Xt=o("span"),wi=n("Inference"),Xa=c(),x=o("p"),$i=n("Once you have trained a model, inference can be done using the "),ea=o("code"),Ei=n("StableDiffusionPipeline"),yi=n(", by simply indicating the path where the model was saved. Make sure that your prompts include the special "),ta=o("code"),ki=n("identifier"),Di=n(" used during training ("),aa=o("code"),xi=n("sks"),Ai=n(" in the previous examples)."),es=c(),u(tt.$$.fragment),this.h()},l(e){const s=Kr('[data-svelte="svelte-1phssyn"]',document.head);b=i(s,"META",{name:!0,content:!0}),s.forEach(t),$=f(e),w=i(e,"H1",{class:!0});var at=r(w);y=i(at,"A",{id:!0,class:!0,href:!0});var sa=r(y);N=i(sa,"SPAN",{});var Ti=r(N);m(E.$$.fragment,Ti),Ti.forEach(t),sa.forEach(t),S=f(at),Y=i(at,"SPAN",{});var ji=r(Y);xs=l(ji,"DreamBooth fine-tuning example"),ji.forEach(t),at.forEach(t),oa=f(e),$e=i(e,"P",{});var Pi=r($e);Ee=i(Pi,"A",{href:!0,rel:!0});var qi=r(Ee);As=l(qi,"DreamBooth"),qi.forEach(t),Ps=l(Pi," is a method to personalize text-to-image models like stable diffusion given just a few (3~5) images of a subject."),Pi.forEach(t),ia=f(e),F=i(e,"P",{});var as=r(F);ot=i(as,"IMG",{src:!0,alt:!0}),Ss=f(as),ye=i(as,"EM",{});var ss=r(ye);Ts=l(ss,"Dreambooth examples from the "),ke=i(ss,"A",{href:!0,rel:!0});var Ii=r(ke);js=l(Ii,"project\u2019s blog"),Ii.forEach(t),qs=l(ss,"."),ss.forEach(t),as.forEach(t),ra=f(e),W=i(e,"P",{});var os=r(W);Is=l(os,"The "),De=i(os,"A",{href:!0,rel:!0});var Ni=r(De);Ns=l(Ni,"Dreambooth training script"),Ni.forEach(t),Cs=l(os," shows how to implement this training procedure on a pre-trained Stable Diffusion model."),os.forEach(t),na=f(e),m(J.$$.fragment,e),la=f(e),C=i(e,"H2",{class:!0});var is=r(C);Z=i(is,"A",{id:!0,class:!0,href:!0});var Ci=r(Z);_t=i(Ci,"SPAN",{});var Ri=r(_t);m(xe.$$.fragment,Ri),Ri.forEach(t),Ci.forEach(t),Rs=f(is),gt=i(is,"SPAN",{});var Ui=r(gt);Us=l(Ui,"Training locally"),Ui.forEach(t),is.forEach(t),pa=f(e),R=i(e,"H3",{class:!0});var rs=r(R);K=i(rs,"A",{id:!0,class:!0,href:!0});var Oi=r(K);vt=i(Oi,"SPAN",{});var Mi=r(vt);m(Ae.$$.fragment,Mi),Mi.forEach(t),Oi.forEach(t),Os=f(rs),bt=i(rs,"SPAN",{});var Li=r(bt);Ms=l(Li,"Installing the dependencies"),Li.forEach(t),rs.forEach(t),ha=f(e),T=i(e,"P",{});var ft=r(T);Ls=l(ft,"Before running the scripts, make sure to install the library\u2019s training dependencies. We also recommend to install "),wt=i(ft,"CODE",{});var Gi=r(wt);Gs=l(Gi,"diffusers"),Gi.forEach(t),Bs=l(ft," from the "),$t=i(ft,"CODE",{});var Bi=r($t);zs=l(Bi,"main"),Bi.forEach(t),Vs=l(ft," github branch."),ft.forEach(t),ca=f(e),m(Pe.$$.fragment,e),fa=f(e),Q=i(e,"P",{});var ns=r(Q);Hs=l(ns,"xFormers is not part of the training requirements, but "),it=i(ns,"A",{href:!0});var zi=r(it);Ys=l(zi,"we recommend you install it if you can"),zi.forEach(t),Fs=l(ns,". It could make your training faster and less memory intensive."),ns.forEach(t),ua=f(e),X=i(e,"P",{});var ls=r(X);Ws=l(ls,"After all dependencies have been set up you can configure a "),Se=i(ls,"A",{href:!0,rel:!0});var Vi=r(Se);Js=l(Vi,"\u{1F917} Accelerate"),Vi.forEach(t),Zs=l(ls," environment with:"),ls.forEach(t),ma=f(e),m(Te.$$.fragment,e),da=f(e),j=i(e,"P",{});var ut=r(j);Ks=l(ut,"In this example we\u2019ll use model version "),Et=i(ut,"CODE",{});var Hi=r(Et);Qs=l(Hi,"v1-4"),Hi.forEach(t),Xs=l(ut,", so please visit "),je=i(ut,"A",{href:!0,rel:!0});var Yi=r(je);eo=l(Yi,"its card"),Yi.forEach(t),to=l(ut," and carefully read the license before proceeding."),ut.forEach(t),_a=f(e),ee=i(e,"P",{});var ps=r(ee);ao=l(ps,"The command below will download and cache the model weights from the Hub because we use the model\u2019s Hub id "),yt=i(ps,"CODE",{});var Fi=r(yt);so=l(Fi,"CompVis/stable-diffusion-v1-4"),Fi.forEach(t),oo=l(ps,". You may also clone the repo locally and use the local path in your system where the checkout was saved."),ps.forEach(t),ga=f(e),U=i(e,"H3",{class:!0});var hs=r(U);te=i(hs,"A",{id:!0,class:!0,href:!0});var Wi=r(te);kt=i(Wi,"SPAN",{});var Ji=r(kt);m(qe.$$.fragment,Ji),Ji.forEach(t),Wi.forEach(t),io=f(hs),Dt=i(hs,"SPAN",{});var Zi=r(Dt);ro=l(Zi,"Dog toy example"),Zi.forEach(t),hs.forEach(t),va=f(e),ae=i(e,"P",{});var cs=r(ae);no=l(cs,"In this example we\u2019ll use "),Ie=i(cs,"A",{href:!0,rel:!0});var Ki=r(Ie);lo=l(Ki,"these images"),Ki.forEach(t),po=l(cs," to add a new concept to Stable Diffusion using the Dreambooth process. They will be our training data. Please, download them and place them somewhere in your system."),cs.forEach(t),ba=f(e),rt=i(e,"P",{});var Qi=r(rt);ho=l(Qi,"Then you can launch the training script using:"),Qi.forEach(t),wa=f(e),m(Ne.$$.fragment,e),$a=f(e),O=i(e,"H3",{class:!0});var fs=r(O);se=i(fs,"A",{id:!0,class:!0,href:!0});var Xi=r(se);xt=i(Xi,"SPAN",{});var er=r(xt);m(Ce.$$.fragment,er),er.forEach(t),Xi.forEach(t),co=f(fs),At=i(fs,"SPAN",{});var tr=r(At);fo=l(tr,"Training with a prior-preserving loss"),tr.forEach(t),fs.forEach(t),Ea=f(e),nt=i(e,"P",{});var ar=r(nt);uo=l(ar,"Prior preservation is used to avoid overfitting and language-drift. Please, refer to the paper to learn more about it if you are interested. For prior preservation, we use other images of the same class as part of the training process. The nice thing is that we can generate those images using the Stable Diffusion model itself! The training script will save the generated images to a local path we specify."),ar.forEach(t),ya=f(e),oe=i(e,"P",{});var us=r(oe);mo=l(us,"According to the paper, it\u2019s recommended to generate "),Pt=i(us,"CODE",{});var sr=r(Pt);_o=l(sr,"num_epochs * num_samples"),sr.forEach(t),go=l(us," images for prior preservation. 200-300 works well for most cases."),us.forEach(t),ka=f(e),m(Re.$$.fragment,e),Da=f(e),M=i(e,"H3",{class:!0});var ms=r(M);ie=i(ms,"A",{id:!0,class:!0,href:!0});var or=r(ie);St=i(or,"SPAN",{});var ir=r(St);m(Ue.$$.fragment,ir),ir.forEach(t),or.forEach(t),vo=f(ms),Tt=i(ms,"SPAN",{});var rr=r(Tt);bo=l(rr,"Saving checkpoints while training"),rr.forEach(t),ms.forEach(t),xa=f(e),lt=i(e,"P",{});var nr=r(lt);wo=l(nr,"It\u2019s easy to overfit while training with Dreambooth, so sometimes it\u2019s useful to save regular checkpoints during the process. One of the intermediate checkpoints might work better than the final model! To use this feature you need to pass the following argument to the training script:"),nr.forEach(t),Aa=f(e),m(Oe.$$.fragment,e),Pa=f(e),k=i(e,"P",{});var ve=r(k);$o=l(ve,"This will save the full training state in subfolders of your "),jt=i(ve,"CODE",{});var lr=r(jt);Eo=l(lr,"output_dir"),lr.forEach(t),yo=l(ve,". Subfolder names begin with the prefix "),qt=i(ve,"CODE",{});var pr=r(qt);ko=l(pr,"checkpoint-"),pr.forEach(t),Do=l(ve,", and then the number of steps performed so far; for example: "),It=i(ve,"CODE",{});var hr=r(It);xo=l(hr,"checkpoint-1500"),hr.forEach(t),Ao=l(ve," would be a checkpoint saved after 1500 training steps."),ve.forEach(t),Sa=f(e),L=i(e,"H4",{class:!0});var ds=r(L);re=i(ds,"A",{id:!0,class:!0,href:!0});var cr=r(re);Nt=i(cr,"SPAN",{});var fr=r(Nt);m(Me.$$.fragment,fr),fr.forEach(t),cr.forEach(t),Po=f(ds),Ct=i(ds,"SPAN",{});var ur=r(Ct);So=l(ur,"Resuming training from a saved checkpoint"),ur.forEach(t),ds.forEach(t),Ta=f(e),q=i(e,"P",{});var mt=r(q);To=l(mt,"If you want to resume training from any of the saved checkpoints, you can pass the argument "),Rt=i(mt,"CODE",{});var mr=r(Rt);jo=l(mr,"--resume_from_checkpoint"),mr.forEach(t),qo=l(mt," and then indicate the name of the checkpoint you want to use. You can also use the special string "),Ut=i(mt,"CODE",{});var dr=r(Ut);Io=l(dr,'"latest"'),dr.forEach(t),No=l(mt," to resume from the last checkpoint saved (i.e., the one with the largest number of steps). For example, the following would resume training from the checkpoint saved after 1500 steps:"),mt.forEach(t),ja=f(e),m(Le.$$.fragment,e),qa=f(e),pt=i(e,"P",{});var _r=r(pt);Co=l(_r,"This would be a good opportunity to tweak some of your hyperparameters if you wish."),_r.forEach(t),Ia=f(e),G=i(e,"H4",{class:!0});var _s=r(G);ne=i(_s,"A",{id:!0,class:!0,href:!0});var gr=r(ne);Ot=i(gr,"SPAN",{});var vr=r(Ot);m(Ge.$$.fragment,vr),vr.forEach(t),gr.forEach(t),Ro=f(_s),Mt=i(_s,"SPAN",{});var br=r(Mt);Uo=l(br,"Performing inference using a saved checkpoint"),br.forEach(t),_s.forEach(t),Na=f(e),ht=i(e,"P",{});var wr=r(ht);Oo=l(wr,"Saved checkpoints are stored in a format suitable for resuming training. They not only include the model weights, but also the state of the optimizer, data loaders and learning rate."),wr.forEach(t),Ca=f(e),ct=i(e,"P",{});var $r=r(ct);Mo=l($r,"You can use a checkpoint for inference, but first you need to convert it to an inference pipeline. This is how you could do it:"),$r.forEach(t),Ra=f(e),m(Be.$$.fragment,e),Ua=f(e),B=i(e,"H3",{class:!0});var gs=r(B);le=i(gs,"A",{id:!0,class:!0,href:!0});var Er=r(le);Lt=i(Er,"SPAN",{});var yr=r(Lt);m(ze.$$.fragment,yr),yr.forEach(t),Er.forEach(t),Lo=f(gs),Gt=i(gs,"SPAN",{});var kr=r(Gt);Go=l(kr,"Training on a 16GB GPU"),kr.forEach(t),gs.forEach(t),Oa=f(e),pe=i(e,"P",{});var vs=r(pe);Bo=l(vs,"With the help of gradient checkpointing and the 8-bit optimizer from "),Ve=i(vs,"A",{href:!0,rel:!0});var Dr=r(Ve);zo=l(Dr,"bitsandbytes"),Dr.forEach(t),Vo=l(vs,", it\u2019s possible to train dreambooth on a 16GB GPU."),vs.forEach(t),Ma=f(e),m(He.$$.fragment,e),La=f(e),he=i(e,"P",{});var bs=r(he);Ho=l(bs,"Then pass the "),Bt=i(bs,"CODE",{});var xr=r(Bt);Yo=l(xr,"--use_8bit_adam"),xr.forEach(t),Fo=l(bs," option to the training script."),bs.forEach(t),Ga=f(e),m(Ye.$$.fragment,e),Ba=f(e),z=i(e,"H3",{class:!0});var ws=r(z);ce=i(ws,"A",{id:!0,class:!0,href:!0});var Ar=r(ce);zt=i(Ar,"SPAN",{});var Pr=r(zt);m(Fe.$$.fragment,Pr),Pr.forEach(t),Ar.forEach(t),Wo=f(ws),Vt=i(ws,"SPAN",{});var Sr=r(Vt);Jo=l(Sr,"Fine-tune the text encoder in addition to the UNet"),Sr.forEach(t),ws.forEach(t),za=f(e),D=i(e,"P",{});var be=r(D);Zo=l(be,"The script also allows to fine-tune the "),Ht=i(be,"CODE",{});var Tr=r(Ht);Ko=l(Tr,"text_encoder"),Tr.forEach(t),Qo=l(be," along with the "),Yt=i(be,"CODE",{});var jr=r(Yt);Xo=l(jr,"unet"),jr.forEach(t),ei=l(be,". It has been observed experimentally that this gives much better results, especially on faces. Please, refer to "),We=i(be,"A",{href:!0,rel:!0});var qr=r(We);ti=l(qr,"our blog"),qr.forEach(t),ai=l(be," for more details."),be.forEach(t),Va=f(e),fe=i(e,"P",{});var $s=r(fe);si=l($s,"To enable this option, pass the "),Ft=i($s,"CODE",{});var Ir=r(Ft);oi=l(Ir,"--train_text_encoder"),Ir.forEach(t),ii=l($s," argument to the training script."),$s.forEach(t),Ha=f(e),m(ue.$$.fragment,e),Ya=f(e),m(Je.$$.fragment,e),Fa=f(e),V=i(e,"H3",{class:!0});var Es=r(V);me=i(Es,"A",{id:!0,class:!0,href:!0});var Nr=r(me);Wt=i(Nr,"SPAN",{});var Cr=r(Wt);m(Ze.$$.fragment,Cr),Cr.forEach(t),Nr.forEach(t),ri=f(Es),Jt=i(Es,"SPAN",{});var Rr=r(Jt);ni=l(Rr,"Training on a 8 GB GPU:"),Rr.forEach(t),Es.forEach(t),Wa=f(e),de=i(e,"P",{});var ys=r(de);li=l(ys,"Using "),Ke=i(ys,"A",{href:!0,rel:!0});var Ur=r(Ke);pi=l(Ur,"DeepSpeed"),Ur.forEach(t),hi=l(ys,` it\u2019s even possible to offload some
tensors from VRAM to either CPU or NVME, allowing training to proceed with less GPU memory.`),ys.forEach(t),Ja=f(e),I=i(e,"P",{});var dt=r(I);ci=l(dt,"DeepSpeed needs to be enabled with "),Zt=i(dt,"CODE",{});var Or=r(Zt);fi=l(Or,"accelerate config"),Or.forEach(t),ui=l(dt,`. During configuration,
answer yes to \u201CDo you want to use DeepSpeed?\u201C. Combining DeepSpeed stage 2, fp16
mixed precision, and offloading both the model parameters and the optimizer state to CPU, it\u2019s
possible to train on under 8 GB VRAM. The drawback is that this requires more system RAM (about 25 GB). See `),Qe=i(dt,"A",{href:!0,rel:!0});var Mr=r(Qe);mi=l(Mr,"the DeepSpeed documentation"),Mr.forEach(t),di=l(dt," for more configuration options."),dt.forEach(t),Za=f(e),_e=i(e,"P",{});var ks=r(_e);_i=l(ks,`Changing the default Adam optimizer to DeepSpeed\u2019s special version of Adam
`),Kt=i(ks,"CODE",{});var Lr=r(Kt);gi=l(Lr,"deepspeed.ops.adam.DeepSpeedCPUAdam"),Lr.forEach(t),vi=l(ks,` gives a substantial speedup, but enabling
it requires the system\u2019s CUDA toolchain version to be the same as the one installed with PyTorch. 8-bit optimizers don\u2019t seem to be compatible with DeepSpeed at the moment.`),ks.forEach(t),Ka=f(e),m(Xe.$$.fragment,e),Qa=f(e),H=i(e,"H2",{class:!0});var Ds=r(H);ge=i(Ds,"A",{id:!0,class:!0,href:!0});var Gr=r(ge);Qt=i(Gr,"SPAN",{});var Br=r(Qt);m(et.$$.fragment,Br),Br.forEach(t),Gr.forEach(t),bi=f(Ds),Xt=i(Ds,"SPAN",{});var zr=r(Xt);wi=l(zr,"Inference"),zr.forEach(t),Ds.forEach(t),Xa=f(e),x=i(e,"P",{});var we=r(x);$i=l(we,"Once you have trained a model, inference can be done using the "),ea=i(we,"CODE",{});var Vr=r(ea);Ei=l(Vr,"StableDiffusionPipeline"),Vr.forEach(t),yi=l(we,", by simply indicating the path where the model was saved. Make sure that your prompts include the special "),ta=i(we,"CODE",{});var Hr=r(ta);ki=l(Hr,"identifier"),Hr.forEach(t),Di=l(we," used during training ("),aa=i(we,"CODE",{});var Yr=r(aa);xi=l(Yr,"sks"),Yr.forEach(t),Ai=l(we," in the previous examples)."),we.forEach(t),es=f(e),m(tt.$$.fragment,e),this.h()},h(){h(b,"name","hf:doc:metadata"),h(b,"content",JSON.stringify(sn)),h(y,"id","dreambooth-finetuning-example"),h(y,"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"),h(y,"href","#dreambooth-finetuning-example"),h(w,"class","relative group"),h(Ee,"href","https://arxiv.org/abs/2208.12242"),h(Ee,"rel","nofollow"),Qr(ot.src,Si="https://dreambooth.github.io/DreamBooth_files/teaser_static.jpg")||h(ot,"src",Si),h(ot,"alt","Dreambooth examples from the project's blog"),h(ke,"href","https://dreambooth.github.io"),h(ke,"rel","nofollow"),h(De,"href","https://github.com/huggingface/diffusers/tree/main/examples/dreambooth"),h(De,"rel","nofollow"),h(Z,"id","training-locally"),h(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"),h(Z,"href","#training-locally"),h(C,"class","relative group"),h(K,"id","installing-the-dependencies"),h(K,"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"),h(K,"href","#installing-the-dependencies"),h(R,"class","relative group"),h(it,"href","../optimization/xformers"),h(Se,"href","https://github.com/huggingface/accelerate/"),h(Se,"rel","nofollow"),h(je,"href","https://huggingface.co/CompVis/stable-diffusion-v1-4"),h(je,"rel","nofollow"),h(te,"id","dog-toy-example"),h(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"),h(te,"href","#dog-toy-example"),h(U,"class","relative group"),h(Ie,"href","https://drive.google.com/drive/folders/1BO_dyz-p65qhBRRMRA4TbZ8qW4rB99JZ"),h(Ie,"rel","nofollow"),h(se,"id","training-with-a-priorpreserving-loss"),h(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"),h(se,"href","#training-with-a-priorpreserving-loss"),h(O,"class","relative group"),h(ie,"id","saving-checkpoints-while-training"),h(ie,"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"),h(ie,"href","#saving-checkpoints-while-training"),h(M,"class","relative group"),h(re,"id","resuming-training-from-a-saved-checkpoint"),h(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"),h(re,"href","#resuming-training-from-a-saved-checkpoint"),h(L,"class","relative group"),h(ne,"id","performing-inference-using-a-saved-checkpoint"),h(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"),h(ne,"href","#performing-inference-using-a-saved-checkpoint"),h(G,"class","relative group"),h(le,"id","training-on-a-16gb-gpu"),h(le,"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"),h(le,"href","#training-on-a-16gb-gpu"),h(B,"class","relative group"),h(Ve,"href","https://github.com/TimDettmers/bitsandbytes"),h(Ve,"rel","nofollow"),h(ce,"id","finetune-the-text-encoder-in-addition-to-the-unet"),h(ce,"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"),h(ce,"href","#finetune-the-text-encoder-in-addition-to-the-unet"),h(z,"class","relative group"),h(We,"href","https://huggingface.co/blog/dreambooth"),h(We,"rel","nofollow"),h(me,"id","training-on-a-8-gb-gpu"),h(me,"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"),h(me,"href","#training-on-a-8-gb-gpu"),h(V,"class","relative group"),h(Ke,"href","https://www.deepspeed.ai/"),h(Ke,"rel","nofollow"),h(Qe,"href","https://huggingface.co/docs/accelerate/usage_guides/deepspeed"),h(Qe,"rel","nofollow"),h(ge,"id","inference"),h(ge,"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"),h(ge,"href","#inference"),h(H,"class","relative group")},m(e,s){a(document.head,b),p(e,$,s),p(e,w,s),a(w,y),a(y,N),d(E,N,null),a(w,S),a(w,Y),a(Y,xs),p(e,oa,s),p(e,$e,s),a($e,Ee),a(Ee,As),a($e,Ps),p(e,ia,s),p(e,F,s),a(F,ot),a(F,Ss),a(F,ye),a(ye,Ts),a(ye,ke),a(ke,js),a(ye,qs),p(e,ra,s),p(e,W,s),a(W,Is),a(W,De),a(De,Ns),a(W,Cs),p(e,na,s),d(J,e,s),p(e,la,s),p(e,C,s),a(C,Z),a(Z,_t),d(xe,_t,null),a(C,Rs),a(C,gt),a(gt,Us),p(e,pa,s),p(e,R,s),a(R,K),a(K,vt),d(Ae,vt,null),a(R,Os),a(R,bt),a(bt,Ms),p(e,ha,s),p(e,T,s),a(T,Ls),a(T,wt),a(wt,Gs),a(T,Bs),a(T,$t),a($t,zs),a(T,Vs),p(e,ca,s),d(Pe,e,s),p(e,fa,s),p(e,Q,s),a(Q,Hs),a(Q,it),a(it,Ys),a(Q,Fs),p(e,ua,s),p(e,X,s),a(X,Ws),a(X,Se),a(Se,Js),a(X,Zs),p(e,ma,s),d(Te,e,s),p(e,da,s),p(e,j,s),a(j,Ks),a(j,Et),a(Et,Qs),a(j,Xs),a(j,je),a(je,eo),a(j,to),p(e,_a,s),p(e,ee,s),a(ee,ao),a(ee,yt),a(yt,so),a(ee,oo),p(e,ga,s),p(e,U,s),a(U,te),a(te,kt),d(qe,kt,null),a(U,io),a(U,Dt),a(Dt,ro),p(e,va,s),p(e,ae,s),a(ae,no),a(ae,Ie),a(Ie,lo),a(ae,po),p(e,ba,s),p(e,rt,s),a(rt,ho),p(e,wa,s),d(Ne,e,s),p(e,$a,s),p(e,O,s),a(O,se),a(se,xt),d(Ce,xt,null),a(O,co),a(O,At),a(At,fo),p(e,Ea,s),p(e,nt,s),a(nt,uo),p(e,ya,s),p(e,oe,s),a(oe,mo),a(oe,Pt),a(Pt,_o),a(oe,go),p(e,ka,s),d(Re,e,s),p(e,Da,s),p(e,M,s),a(M,ie),a(ie,St),d(Ue,St,null),a(M,vo),a(M,Tt),a(Tt,bo),p(e,xa,s),p(e,lt,s),a(lt,wo),p(e,Aa,s),d(Oe,e,s),p(e,Pa,s),p(e,k,s),a(k,$o),a(k,jt),a(jt,Eo),a(k,yo),a(k,qt),a(qt,ko),a(k,Do),a(k,It),a(It,xo),a(k,Ao),p(e,Sa,s),p(e,L,s),a(L,re),a(re,Nt),d(Me,Nt,null),a(L,Po),a(L,Ct),a(Ct,So),p(e,Ta,s),p(e,q,s),a(q,To),a(q,Rt),a(Rt,jo),a(q,qo),a(q,Ut),a(Ut,Io),a(q,No),p(e,ja,s),d(Le,e,s),p(e,qa,s),p(e,pt,s),a(pt,Co),p(e,Ia,s),p(e,G,s),a(G,ne),a(ne,Ot),d(Ge,Ot,null),a(G,Ro),a(G,Mt),a(Mt,Uo),p(e,Na,s),p(e,ht,s),a(ht,Oo),p(e,Ca,s),p(e,ct,s),a(ct,Mo),p(e,Ra,s),d(Be,e,s),p(e,Ua,s),p(e,B,s),a(B,le),a(le,Lt),d(ze,Lt,null),a(B,Lo),a(B,Gt),a(Gt,Go),p(e,Oa,s),p(e,pe,s),a(pe,Bo),a(pe,Ve),a(Ve,zo),a(pe,Vo),p(e,Ma,s),d(He,e,s),p(e,La,s),p(e,he,s),a(he,Ho),a(he,Bt),a(Bt,Yo),a(he,Fo),p(e,Ga,s),d(Ye,e,s),p(e,Ba,s),p(e,z,s),a(z,ce),a(ce,zt),d(Fe,zt,null),a(z,Wo),a(z,Vt),a(Vt,Jo),p(e,za,s),p(e,D,s),a(D,Zo),a(D,Ht),a(Ht,Ko),a(D,Qo),a(D,Yt),a(Yt,Xo),a(D,ei),a(D,We),a(We,ti),a(D,ai),p(e,Va,s),p(e,fe,s),a(fe,si),a(fe,Ft),a(Ft,oi),a(fe,ii),p(e,Ha,s),d(ue,e,s),p(e,Ya,s),d(Je,e,s),p(e,Fa,s),p(e,V,s),a(V,me),a(me,Wt),d(Ze,Wt,null),a(V,ri),a(V,Jt),a(Jt,ni),p(e,Wa,s),p(e,de,s),a(de,li),a(de,Ke),a(Ke,pi),a(de,hi),p(e,Ja,s),p(e,I,s),a(I,ci),a(I,Zt),a(Zt,fi),a(I,ui),a(I,Qe),a(Qe,mi),a(I,di),p(e,Za,s),p(e,_e,s),a(_e,_i),a(_e,Kt),a(Kt,gi),a(_e,vi),p(e,Ka,s),d(Xe,e,s),p(e,Qa,s),p(e,H,s),a(H,ge),a(ge,Qt),d(et,Qt,null),a(H,bi),a(H,Xt),a(Xt,wi),p(e,Xa,s),p(e,x,s),a(x,$i),a(x,ea),a(ea,Ei),a(x,yi),a(x,ta),a(ta,ki),a(x,Di),a(x,aa),a(aa,xi),a(x,Ai),p(e,es,s),d(tt,e,s),ts=!0},p(e,[s]){const at={};s&2&&(at.$$scope={dirty:s,ctx:e}),J.$set(at);const sa={};s&2&&(sa.$$scope={dirty:s,ctx:e}),ue.$set(sa)},i(e){ts||(_(E.$$.fragment,e),_(J.$$.fragment,e),_(xe.$$.fragment,e),_(Ae.$$.fragment,e),_(Pe.$$.fragment,e),_(Te.$$.fragment,e),_(qe.$$.fragment,e),_(Ne.$$.fragment,e),_(Ce.$$.fragment,e),_(Re.$$.fragment,e),_(Ue.$$.fragment,e),_(Oe.$$.fragment,e),_(Me.$$.fragment,e),_(Le.$$.fragment,e),_(Ge.$$.fragment,e),_(Be.$$.fragment,e),_(ze.$$.fragment,e),_(He.$$.fragment,e),_(Ye.$$.fragment,e),_(Fe.$$.fragment,e),_(ue.$$.fragment,e),_(Je.$$.fragment,e),_(Ze.$$.fragment,e),_(Xe.$$.fragment,e),_(et.$$.fragment,e),_(tt.$$.fragment,e),ts=!0)},o(e){g(E.$$.fragment,e),g(J.$$.fragment,e),g(xe.$$.fragment,e),g(Ae.$$.fragment,e),g(Pe.$$.fragment,e),g(Te.$$.fragment,e),g(qe.$$.fragment,e),g(Ne.$$.fragment,e),g(Ce.$$.fragment,e),g(Re.$$.fragment,e),g(Ue.$$.fragment,e),g(Oe.$$.fragment,e),g(Me.$$.fragment,e),g(Le.$$.fragment,e),g(Ge.$$.fragment,e),g(Be.$$.fragment,e),g(ze.$$.fragment,e),g(He.$$.fragment,e),g(Ye.$$.fragment,e),g(Fe.$$.fragment,e),g(ue.$$.fragment,e),g(Je.$$.fragment,e),g(Ze.$$.fragment,e),g(Xe.$$.fragment,e),g(et.$$.fragment,e),g(tt.$$.fragment,e),ts=!1},d(e){t(b),e&&t($),e&&t(w),v(E),e&&t(oa),e&&t($e),e&&t(ia),e&&t(F),e&&t(ra),e&&t(W),e&&t(na),v(J,e),e&&t(la),e&&t(C),v(xe),e&&t(pa),e&&t(R),v(Ae),e&&t(ha),e&&t(T),e&&t(ca),v(Pe,e),e&&t(fa),e&&t(Q),e&&t(ua),e&&t(X),e&&t(ma),v(Te,e),e&&t(da),e&&t(j),e&&t(_a),e&&t(ee),e&&t(ga),e&&t(U),v(qe),e&&t(va),e&&t(ae),e&&t(ba),e&&t(rt),e&&t(wa),v(Ne,e),e&&t($a),e&&t(O),v(Ce),e&&t(Ea),e&&t(nt),e&&t(ya),e&&t(oe),e&&t(ka),v(Re,e),e&&t(Da),e&&t(M),v(Ue),e&&t(xa),e&&t(lt),e&&t(Aa),v(Oe,e),e&&t(Pa),e&&t(k),e&&t(Sa),e&&t(L),v(Me),e&&t(Ta),e&&t(q),e&&t(ja),v(Le,e),e&&t(qa),e&&t(pt),e&&t(Ia),e&&t(G),v(Ge),e&&t(Na),e&&t(ht),e&&t(Ca),e&&t(ct),e&&t(Ra),v(Be,e),e&&t(Ua),e&&t(B),v(ze),e&&t(Oa),e&&t(pe),e&&t(Ma),v(He,e),e&&t(La),e&&t(he),e&&t(Ga),v(Ye,e),e&&t(Ba),e&&t(z),v(Fe),e&&t(za),e&&t(D),e&&t(Va),e&&t(fe),e&&t(Ha),v(ue,e),e&&t(Ya),v(Je,e),e&&t(Fa),e&&t(V),v(Ze),e&&t(Wa),e&&t(de),e&&t(Ja),e&&t(I),e&&t(Za),e&&t(_e),e&&t(Ka),v(Xe,e),e&&t(Qa),e&&t(H),v(et),e&&t(Xa),e&&t(x),e&&t(es),v(tt,e)}}}const sn={local:"dreambooth-finetuning-example",sections:[{local:"training-locally",sections:[{local:"installing-the-dependencies",title:"Installing the dependencies"},{local:"dog-toy-example",title:"Dog toy example"},{local:"training-with-a-priorpreserving-loss",title:"Training with a prior-preserving loss"},{local:"saving-checkpoints-while-training",sections:[{local:"resuming-training-from-a-saved-checkpoint",title:"Resuming training from a saved checkpoint"},{local:"performing-inference-using-a-saved-checkpoint",title:"Performing inference using a saved checkpoint"}],title:"Saving checkpoints while training"},{local:"training-on-a-16gb-gpu",title:"Training on a 16GB GPU"},{local:"finetune-the-text-encoder-in-addition-to-the-unet",title:"Fine-tune the text encoder in addition to the UNet"},{local:"training-on-a-8-gb-gpu",title:"Training on a 8 GB GPU:"}],title:"Training locally "},{local:"inference",title:"Inference"}],title:"DreamBooth fine-tuning example"};function on(st){return Xr(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class hn extends Wr{constructor(b){super();Jr(this,b,on,an,Zr,{})}}export{hn as default,sn as metadata};
