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