import{S as Fp,i as Vp,s as Hp,e as s,k as c,w as $,t as i,M as Yp,c as r,d as t,m,a as n,x as v,h as l,b as u,N as Wp,G as a,g as f,y as b,q as w,o as E,B as y,v as Jp,L as $a}from"../../chunks/vendor-hf-doc-builder.js";import{T as Bp}from"../../chunks/Tip-hf-doc-builder.js";import{I as V}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{C as P}from"../../chunks/CodeBlock-hf-doc-builder.js";import{D as Kp}from"../../chunks/DocNotebookDropdown-hf-doc-builder.js";import{F as Ki,M as va}from"../../chunks/Markdown-hf-doc-builder.js";function Qp(A){let h,d,p,g,D;return{c(){h=s("p"),d=i("DreamBooth finetuning is very sensitive to hyperparameters and easy to overfit. We recommend you take a look at our "),p=s("a"),g=i("in-depth analysis"),D=i(" with recommended settings for different subjects to help you choose the appropriate hyperparameters."),this.h()},l(j){h=r(j,"P",{});var x=n(h);d=l(x,"DreamBooth finetuning is very sensitive to hyperparameters and easy to overfit. We recommend you take a look at our "),p=r(x,"A",{href:!0,rel:!0});var C=n(p);g=l(C,"in-depth analysis"),C.forEach(t),D=l(x," with recommended settings for different subjects to help you choose the appropriate hyperparameters."),x.forEach(t),this.h()},h(){u(p,"href","https://huggingface.co/blog/dreambooth"),u(p,"rel","nofollow")},m(j,x){f(j,h,x),a(h,d),a(h,p),a(p,g),a(h,D)},d(j){j&&t(h)}}}function Xp(A){let h,d,p,g,D,j,x,C,H,R,U,N,O,q,Q,M,L,I,Y,z,G,B,W,S,J;return M=new P({props:{code:`export MODEL_NAME="CompVis/stable-diffusion-v1-4"
export INSTANCE_DIR="./dog"
export OUTPUT_DIR="path_to_saved_model"`,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;./dog&quot;</span>
<span class="hljs-built_in">export</span> OUTPUT_DIR=<span class="hljs-string">&quot;path_to_saved_model&quot;</span>`}}),S=new P({props:{code:`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:`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`}}),{c(){h=s("p"),d=i("Set the "),p=s("code"),g=i("INSTANCE_DIR"),D=i(" environment variable to the path of the directory containing the dog images."),j=c(),x=s("p"),C=i("Specify the "),H=s("code"),R=i("MODEL_NAME"),U=i(" environment variable (either a Hub model repository id or a path to the directory containing the model weights) and pass it to the "),N=s("code"),O=i("~diffusers.DiffusionPipeline.from_pretrained.pretrained_model_name_or_path"),q=i(" argument."),Q=c(),$(M.$$.fragment),L=c(),I=s("p"),Y=i("Then you can launch the training script (you can find the full training script "),z=s("a"),G=i("here"),B=i(") with the following command:"),W=c(),$(S.$$.fragment),this.h()},l(_){h=r(_,"P",{});var k=n(h);d=l(k,"Set the "),p=r(k,"CODE",{});var ie=n(p);g=l(ie,"INSTANCE_DIR"),ie.forEach(t),D=l(k," environment variable to the path of the directory containing the dog images."),k.forEach(t),j=m(_),x=r(_,"P",{});var T=n(x);C=l(T,"Specify the "),H=r(T,"CODE",{});var F=n(H);R=l(F,"MODEL_NAME"),F.forEach(t),U=l(T," environment variable (either a Hub model repository id or a path to the directory containing the model weights) and pass it to the "),N=r(T,"CODE",{});var le=n(N);O=l(le,"~diffusers.DiffusionPipeline.from_pretrained.pretrained_model_name_or_path"),le.forEach(t),q=l(T," argument."),T.forEach(t),Q=m(_),v(M.$$.fragment,_),L=m(_),I=r(_,"P",{});var oe=n(I);Y=l(oe,"Then you can launch the training script (you can find the full training script "),z=r(oe,"A",{href:!0,rel:!0});var K=n(z);G=l(K,"here"),K.forEach(t),B=l(oe,") with the following command:"),oe.forEach(t),W=m(_),v(S.$$.fragment,_),this.h()},h(){u(z,"href","https://github.com/huggingface/diffusers/blob/main/examples/dreambooth/train_dreambooth.py"),u(z,"rel","nofollow")},m(_,k){f(_,h,k),a(h,d),a(h,p),a(p,g),a(h,D),f(_,j,k),f(_,x,k),a(x,C),a(x,H),a(H,R),a(x,U),a(x,N),a(N,O),a(x,q),f(_,Q,k),b(M,_,k),f(_,L,k),f(_,I,k),a(I,Y),a(I,z),a(z,G),a(I,B),f(_,W,k),b(S,_,k),J=!0},p:$a,i(_){J||(w(M.$$.fragment,_),w(S.$$.fragment,_),J=!0)},o(_){E(M.$$.fragment,_),E(S.$$.fragment,_),J=!1},d(_){_&&t(h),_&&t(j),_&&t(x),_&&t(Q),y(M,_),_&&t(L),_&&t(I),_&&t(W),y(S,_)}}}function Zp(A){let h,d;return h=new va({props:{$$slots:{default:[Xp]},$$scope:{ctx:A}}}),{c(){$(h.$$.fragment)},l(p){v(h.$$.fragment,p)},m(p,g){b(h,p,g),d=!0},p(p,g){const D={};g&2&&(D.$$scope={dirty:g,ctx:p}),h.$set(D)},i(p){d||(w(h.$$.fragment,p),d=!0)},o(p){E(h.$$.fragment,p),d=!1},d(p){y(h,p)}}}function ef(A){let h,d,p,g,D,j,x,C,H,R,U,N,O,q,Q,M,L,I,Y,z,G,B,W,S,J;return R=new P({props:{code:"pip install -U -r requirements.txt",highlighted:"pip install -U -r requirements.txt"}}),S=new P({props:{code:`export MODEL_NAME="duongna/stable-diffusion-v1-4-flax"
export INSTANCE_DIR="./dog"
export OUTPUT_DIR="path-to-save-model"

python train_dreambooth_flax.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 \\
  --learning_rate=5e-6 \\
  --max_train_steps=400`,highlighted:`<span class="hljs-built_in">export</span> MODEL_NAME=<span class="hljs-string">&quot;duongna/stable-diffusion-v1-4-flax&quot;</span>
<span class="hljs-built_in">export</span> INSTANCE_DIR=<span class="hljs-string">&quot;./dog&quot;</span>
<span class="hljs-built_in">export</span> OUTPUT_DIR=<span class="hljs-string">&quot;path-to-save-model&quot;</span>

python train_dreambooth_flax.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 \\
  --learning_rate=5e-6 \\
  --max_train_steps=400`}}),{c(){h=s("p"),d=i("If you have access to TPUs or want to train even faster, you can try out the "),p=s("a"),g=i("Flax training script"),D=i(". The Flax training script doesn\u2019t support gradient checkpointing or gradient accumulation, so you\u2019ll need a GPU with at least 30GB of memory."),j=c(),x=s("p"),C=i("Before running the script, make sure you have the requirements installed:"),H=c(),$(R.$$.fragment),U=c(),N=s("p"),O=i("Specify the "),q=s("code"),Q=i("MODEL_NAME"),M=i(" environment variable (either a Hub model repository id or a path to the directory containing the model weights) and pass it to the "),L=s("code"),I=i("~diffusers.DiffusionPipeline.from_pretrained.pretrained_model_name_or_path"),Y=i(" argument."),z=c(),G=s("p"),B=i("Now you can launch the training script with the following command:"),W=c(),$(S.$$.fragment),this.h()},l(_){h=r(_,"P",{});var k=n(h);d=l(k,"If you have access to TPUs or want to train even faster, you can try out the "),p=r(k,"A",{href:!0,rel:!0});var ie=n(p);g=l(ie,"Flax training script"),ie.forEach(t),D=l(k,". The Flax training script doesn\u2019t support gradient checkpointing or gradient accumulation, so you\u2019ll need a GPU with at least 30GB of memory."),k.forEach(t),j=m(_),x=r(_,"P",{});var T=n(x);C=l(T,"Before running the script, make sure you have the requirements installed:"),T.forEach(t),H=m(_),v(R.$$.fragment,_),U=m(_),N=r(_,"P",{});var F=n(N);O=l(F,"Specify the "),q=r(F,"CODE",{});var le=n(q);Q=l(le,"MODEL_NAME"),le.forEach(t),M=l(F," environment variable (either a Hub model repository id or a path to the directory containing the model weights) and pass it to the "),L=r(F,"CODE",{});var oe=n(L);I=l(oe,"~diffusers.DiffusionPipeline.from_pretrained.pretrained_model_name_or_path"),oe.forEach(t),Y=l(F," argument."),F.forEach(t),z=m(_),G=r(_,"P",{});var K=n(G);B=l(K,"Now you can launch the training script with the following command:"),K.forEach(t),W=m(_),v(S.$$.fragment,_),this.h()},h(){u(p,"href","https://github.com/huggingface/diffusers/blob/main/examples/dreambooth/train_dreambooth_flax.py"),u(p,"rel","nofollow")},m(_,k){f(_,h,k),a(h,d),a(h,p),a(p,g),a(h,D),f(_,j,k),f(_,x,k),a(x,C),f(_,H,k),b(R,_,k),f(_,U,k),f(_,N,k),a(N,O),a(N,q),a(q,Q),a(N,M),a(N,L),a(L,I),a(N,Y),f(_,z,k),f(_,G,k),a(G,B),f(_,W,k),b(S,_,k),J=!0},p:$a,i(_){J||(w(R.$$.fragment,_),w(S.$$.fragment,_),J=!0)},o(_){E(R.$$.fragment,_),E(S.$$.fragment,_),J=!1},d(_){_&&t(h),_&&t(j),_&&t(x),_&&t(H),y(R,_),_&&t(U),_&&t(N),_&&t(z),_&&t(G),_&&t(W),y(S,_)}}}function tf(A){let h,d;return h=new va({props:{$$slots:{default:[ef]},$$scope:{ctx:A}}}),{c(){$(h.$$.fragment)},l(p){v(h.$$.fragment,p)},m(p,g){b(h,p,g),d=!0},p(p,g){const D={};g&2&&(D.$$scope={dirty:g,ctx:p}),h.$set(D)},i(p){d||(w(h.$$.fragment,p),d=!0)},o(p){E(h.$$.fragment,p),d=!1},d(p){y(h,p)}}}function af(A){let h,d;return h=new P({props:{code:`export MODEL_NAME="CompVis/stable-diffusion-v1-4"
export INSTANCE_DIR="./dog"
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;./dog&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`}}),{c(){$(h.$$.fragment)},l(p){v(h.$$.fragment,p)},m(p,g){b(h,p,g),d=!0},p:$a,i(p){d||(w(h.$$.fragment,p),d=!0)},o(p){E(h.$$.fragment,p),d=!1},d(p){y(h,p)}}}function of(A){let h,d;return h=new va({props:{$$slots:{default:[af]},$$scope:{ctx:A}}}),{c(){$(h.$$.fragment)},l(p){v(h.$$.fragment,p)},m(p,g){b(h,p,g),d=!0},p(p,g){const D={};g&2&&(D.$$scope={dirty:g,ctx:p}),h.$set(D)},i(p){d||(w(h.$$.fragment,p),d=!0)},o(p){E(h.$$.fragment,p),d=!1},d(p){y(h,p)}}}function sf(A){let h,d;return h=new P({props:{code:`export MODEL_NAME="duongna/stable-diffusion-v1-4-flax"
export INSTANCE_DIR="./dog"
export CLASS_DIR="path-to-class-images"
export OUTPUT_DIR="path-to-save-model"

python train_dreambooth_flax.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 \\
  --learning_rate=5e-6 \\
  --num_class_images=200 \\
  --max_train_steps=800`,highlighted:`<span class="hljs-built_in">export</span> MODEL_NAME=<span class="hljs-string">&quot;duongna/stable-diffusion-v1-4-flax&quot;</span>
<span class="hljs-built_in">export</span> INSTANCE_DIR=<span class="hljs-string">&quot;./dog&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-save-model&quot;</span>

python train_dreambooth_flax.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 \\
  --learning_rate=5e-6 \\
  --num_class_images=200 \\
  --max_train_steps=800`}}),{c(){$(h.$$.fragment)},l(p){v(h.$$.fragment,p)},m(p,g){b(h,p,g),d=!0},p:$a,i(p){d||(w(h.$$.fragment,p),d=!0)},o(p){E(h.$$.fragment,p),d=!1},d(p){y(h,p)}}}function rf(A){let h,d;return h=new va({props:{$$slots:{default:[sf]},$$scope:{ctx:A}}}),{c(){$(h.$$.fragment)},l(p){v(h.$$.fragment,p)},m(p,g){b(h,p,g),d=!0},p(p,g){const D={};g&2&&(D.$$scope={dirty:g,ctx:p}),h.$set(D)},i(p){d||(w(h.$$.fragment,p),d=!0)},o(p){E(h.$$.fragment,p),d=!1},d(p){y(h,p)}}}function nf(A){let h,d;return{c(){h=s("p"),d=i("Training the text encoder requires additional memory and it won\u2019t fit on a 16GB GPU. You\u2019ll need at least 24GB VRAM to use this option.")},l(p){h=r(p,"P",{});var g=n(h);d=l(g,"Training the text encoder requires additional memory and it won\u2019t fit on a 16GB GPU. You\u2019ll need at least 24GB VRAM to use this option."),g.forEach(t)},m(p,g){f(p,h,g),a(h,d)},d(p){p&&t(h)}}}function lf(A){let h,d;return h=new P({props:{code:`export MODEL_NAME="CompVis/stable-diffusion-v1-4"
export INSTANCE_DIR="./dog"
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;./dog&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`}}),{c(){$(h.$$.fragment)},l(p){v(h.$$.fragment,p)},m(p,g){b(h,p,g),d=!0},p:$a,i(p){d||(w(h.$$.fragment,p),d=!0)},o(p){E(h.$$.fragment,p),d=!1},d(p){y(h,p)}}}function pf(A){let h,d;return h=new va({props:{$$slots:{default:[lf]},$$scope:{ctx:A}}}),{c(){$(h.$$.fragment)},l(p){v(h.$$.fragment,p)},m(p,g){b(h,p,g),d=!0},p(p,g){const D={};g&2&&(D.$$scope={dirty:g,ctx:p}),h.$set(D)},i(p){d||(w(h.$$.fragment,p),d=!0)},o(p){E(h.$$.fragment,p),d=!1},d(p){y(h,p)}}}function ff(A){let h,d;return h=new P({props:{code:`export MODEL_NAME="duongna/stable-diffusion-v1-4-flax"
export INSTANCE_DIR="./dog"
export CLASS_DIR="path-to-class-images"
export OUTPUT_DIR="path-to-save-model"

python train_dreambooth_flax.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 \\
  --learning_rate=2e-6 \\
  --num_class_images=200 \\
  --max_train_steps=800`,highlighted:`<span class="hljs-built_in">export</span> MODEL_NAME=<span class="hljs-string">&quot;duongna/stable-diffusion-v1-4-flax&quot;</span>
<span class="hljs-built_in">export</span> INSTANCE_DIR=<span class="hljs-string">&quot;./dog&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-save-model&quot;</span>

python train_dreambooth_flax.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 \\
  --learning_rate=2e-6 \\
  --num_class_images=200 \\
  --max_train_steps=800`}}),{c(){$(h.$$.fragment)},l(p){v(h.$$.fragment,p)},m(p,g){b(h,p,g),d=!0},p:$a,i(p){d||(w(h.$$.fragment,p),d=!0)},o(p){E(h.$$.fragment,p),d=!1},d(p){y(h,p)}}}function hf(A){let h,d;return h=new va({props:{$$slots:{default:[ff]},$$scope:{ctx:A}}}),{c(){$(h.$$.fragment)},l(p){v(h.$$.fragment,p)},m(p,g){b(h,p,g),d=!0},p(p,g){const D={};g&2&&(D.$$scope={dirty:g,ctx:p}),h.$set(D)},i(p){d||(w(h.$$.fragment,p),d=!0)},o(p){E(h.$$.fragment,p),d=!1},d(p){y(h,p)}}}function uf(A){let h,d,p,g,D,j,x,C,H,R,U,N,O,q,Q,M,L,I,Y,z,G,B,W,S,J,_,k,ie,T,F,le,oe,K,gr,$r,ko,ye,vr,ba,br,wr,Do,pt,xo,ke,Er,Zt,yr,kr,Ao,De,Dr,ft,xr,Ar,Po,ht,jo,ea,Pr,So,ut,No,ta,jr,Io,ct,qo,xe,Sr,mt,Nr,Ir,To,_t,Co,pe,Ae,wa,dt,qr,Ea,Tr,Ro,Pe,Uo,je,Oo,fe,Se,ya,gt,Cr,ka,Rr,Mo,Ne,Ur,$t,Or,Mr,Lo,Ie,Lr,Da,zr,Gr,zo,qe,Go,he,Te,xa,vt,Br,Aa,Fr,Bo,X,Vr,Pa,Hr,Yr,ja,Wr,Jr,bt,Kr,Qr,Fo,Ce,Vo,Z,Xr,Sa,Zr,en,Na,tn,an,Ia,on,sn,Ho,Re,Yo,ue,Ue,qa,wt,rn,Ta,nn,Wo,Oe,ln,aa,pn,fn,Jo,ce,Me,Ca,Et,hn,Ra,un,Ko,oa,cn,Qo,yt,Xo,ee,mn,Ua,_n,dn,Oa,gn,$n,Ma,vn,bn,Zo,me,Le,La,kt,wn,za,En,es,re,yn,Ga,kn,Dn,Ba,xn,An,ts,Dt,as,sa,Pn,os,_e,ze,Fa,xt,jn,Va,Sn,ss,ra,Nn,rs,Ge,In,Ha,Ya,qn,Tn,ns,At,is,Be,Cn,Wa,Ja,Rn,Un,ls,Pt,ps,de,Fe,Ka,jt,On,Qa,Mn,fs,na,Ln,hs,ge,Ve,Xa,St,zn,Za,Gn,us,se,Nt,Bn,Fn,It,Vn,Hn,ia,Yn,Wn,cs,qt,ms,la,Jn,_s,$e,He,eo,Tt,Kn,to,Qn,ds,te,Xn,Ct,Zn,ei,ao,ti,ai,oo,oi,si,gs,Rt,$s,ve,Ye,so,Ut,ri,ro,ni,vs,We,ii,Ot,li,pi,bs,Mt,ws,Je,fi,no,hi,ui,Es,Lt,ys,be,Ke,io,zt,ci,lo,mi,ks,Qe,_i,po,di,gi,Ds,Gt,xs,we,Xe,fo,Bt,$i,ho,vi,As,Ze,bi,Ft,wi,Ei,Ps,pa,yi,js,Vt,Ss,et,ki,Ht,Di,xi,Ns,ne,Ai,Yt,uo,Pi,ji,co,Si,Ni,Is,fa,Ii,qs,ha,qi,Ts,Wt,Cs,Ee,tt,mo,Jt,Ti,_o,Ci,Rs,ae,Ri,ua,Ui,Oi,go,Mi,Li,$o,zi,Gi,Us,at,Bi,vo,bo,Fi,Vi,Os,Kt,Ms,ot,Hi,ca,Yi,Wi,Ls;return j=new V({}),U=new Kp({props:{classNames:"absolute z-10 right-0 top-0",options:[{label:"Mixed",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers_doc/en/dreambooth.ipynb"},{label:"PyTorch",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers_doc/en/pytorch/dreambooth.ipynb"},{label:"TensorFlow",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers_doc/en/tensorflow/dreambooth.ipynb"},{label:"Mixed",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/diffusers_doc/en/dreambooth.ipynb"},{label:"PyTorch",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/diffusers_doc/en/pytorch/dreambooth.ipynb"},{label:"TensorFlow",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/diffusers_doc/en/tensorflow/dreambooth.ipynb"}]}}),pt=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`}}),ht=new P({props:{code:"accelerate config",highlighted:"accelerate config"}}),ut=new P({props:{code:"accelerate config default",highlighted:"accelerate config default"}}),ct=new P({props:{code:`from accelerate.utils import write_basic_config

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

write_basic_config()`}}),_t=new P({props:{code:`from huggingface_hub import snapshot_download

local_dir = "./dog"
snapshot_download(
    "diffusers/dog-example",
    local_dir=local_dir,
    repo_type="dataset",
    ignore_patterns=".gitattributes",
)`,highlighted:`<span class="hljs-keyword">from</span> huggingface_hub <span class="hljs-keyword">import</span> snapshot_download

local_dir = <span class="hljs-string">&quot;./dog&quot;</span>
snapshot_download(
    <span class="hljs-string">&quot;diffusers/dog-example&quot;</span>,
    local_dir=local_dir,
    repo_type=<span class="hljs-string">&quot;dataset&quot;</span>,
    ignore_patterns=<span class="hljs-string">&quot;.gitattributes&quot;</span>,
)`}}),dt=new V({}),Pe=new Bp({props:{warning:!0,$$slots:{default:[Qp]},$$scope:{ctx:A}}}),je=new Ki({props:{pytorch:!0,tensorflow:!1,jax:!0,$$slots:{jax:[tf],pytorch:[Zp]},$$scope:{ctx:A}}}),gt=new V({}),qe=new Ki({props:{pytorch:!0,tensorflow:!1,jax:!0,$$slots:{jax:[rf],pytorch:[of]},$$scope:{ctx:A}}}),vt=new V({}),Ce=new Bp({props:{warning:!0,$$slots:{default:[nf]},$$scope:{ctx:A}}}),Re=new Ki({props:{pytorch:!0,tensorflow:!1,jax:!0,$$slots:{jax:[hf],pytorch:[pf]},$$scope:{ctx:A}}}),wt=new V({}),Et=new V({}),yt=new P({props:{code:"  --checkpointing_steps=500",highlighted:"  --checkpointing_steps=500"}}),kt=new V({}),Dt=new P({props:{code:'  --resume_from_checkpoint="checkpoint-1500"',highlighted:'  --resume_from_checkpoint=<span class="hljs-string">&quot;checkpoint-1500&quot;</span>'}}),xt=new V({}),At=new P({props:{code:`from diffusers import DiffusionPipeline, UNet2DConditionModel
from transformers import CLIPTextModel
import torch

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

unet = UNet2DConditionModel.from_pretrained("/sddata/dreambooth/daruma-v2-1/checkpoint-100/unet")

# if you have trained with \`--args.train_text_encoder\` make sure to also load the text encoder
text_encoder = CLIPTextModel.from_pretrained("/sddata/dreambooth/daruma-v2-1/checkpoint-100/text_encoder")

pipeline = DiffusionPipeline.from_pretrained(model_id, unet=unet, text_encoder=text_encoder, dtype=torch.float16)
pipeline.to("cuda")

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

<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>

unet = UNet2DConditionModel.from_pretrained(<span class="hljs-string">&quot;/sddata/dreambooth/daruma-v2-1/checkpoint-100/unet&quot;</span>)

<span class="hljs-comment"># if you have trained with \`--args.train_text_encoder\` make sure to also load the text encoder</span>
text_encoder = CLIPTextModel.from_pretrained(<span class="hljs-string">&quot;/sddata/dreambooth/daruma-v2-1/checkpoint-100/text_encoder&quot;</span>)

pipeline = DiffusionPipeline.from_pretrained(model_id, unet=unet, text_encoder=text_encoder, dtype=torch.float16)
pipeline.to(<span class="hljs-string">&quot;cuda&quot;</span>)

<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>)`}}),Pt=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>)`}}),jt=new V({}),St=new V({}),qt=new P({props:{code:"  --enable_xformers_memory_efficient_attention",highlighted:"  --enable_xformers_memory_efficient_attention"}}),Tt=new V({}),Rt=new P({props:{code:"  --set_grads_to_none",highlighted:"  --set_grads_to_none"}}),Ut=new V({}),Mt=new P({props:{code:"pip install bitsandbytes",highlighted:"pip install bitsandbytes"}}),Lt=new P({props:{code:`export MODEL_NAME="CompVis/stable-diffusion-v1-4"
export INSTANCE_DIR="./dog"
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;./dog&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`}}),zt=new V({}),Gt=new P({props:{code:`export MODEL_NAME="CompVis/stable-diffusion-v1-4"
export INSTANCE_DIR="./dog"
export CLASS_DIR="path-to-class-images"
export OUTPUT_DIR="path-to-save-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 --gradient_checkpointing \\
  --use_8bit_adam \\
  --enable_xformers_memory_efficient_attention \\
  --set_grads_to_none \\
  --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;./dog&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-save-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 --gradient_checkpointing \\
  --use_8bit_adam \\
  --enable_xformers_memory_efficient_attention \\
  --set_grads_to_none \\
  --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`}}),Bt=new V({}),Vt=new P({props:{code:"accelerate config",highlighted:"accelerate config"}}),Wt=new P({props:{code:`export MODEL_NAME="CompVis/stable-diffusion-v1-4"
export INSTANCE_DIR="./dog"
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;./dog&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`}}),Jt=new V({}),Kt=new P({props:{code:`from diffusers import DiffusionPipeline
import torch

model_id = "path_to_saved_model"
pipe = DiffusionPipeline.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> DiffusionPipeline
<span class="hljs-keyword">import</span> torch

model_id = <span class="hljs-string">&quot;path_to_saved_model&quot;</span>
pipe = DiffusionPipeline.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(){h=s("meta"),d=c(),p=s("h1"),g=s("a"),D=s("span"),$(j.$$.fragment),x=c(),C=s("span"),H=i("DreamBooth"),R=c(),$(U.$$.fragment),N=c(),O=s("p"),q=s("a"),Q=i("DreamBooth"),M=i(" is a method to personalize text-to-image models like Stable Diffusion given just a few (3-5) images of a subject. It allows the model to generate contextualized images of the subject in different scenes, poses, and views."),L=c(),I=s("p"),Y=s("img"),G=c(),B=s("small"),W=i("Dreambooth examples from the "),S=s("a"),J=i("project's blog."),_=c(),k=s("p"),ie=i("This guide will show you how to finetune DreamBooth with the "),T=s("a"),F=s("code"),le=i("CompVis/stable-diffusion-v1-4"),oe=i(" model for various GPU sizes, and with Flax. All the training scripts for DreamBooth used in this guide can be found "),K=s("a"),gr=i("here"),$r=i(" if you\u2019re interested in digging deeper and seeing how things work."),ko=c(),ye=s("p"),vr=i("Before running the scripts, make sure you install the library\u2019s training dependencies. We also recommend installing \u{1F9E8} Diffusers from the "),ba=s("code"),br=i("main"),wr=i(" GitHub branch:"),Do=c(),$(pt.$$.fragment),xo=c(),ke=s("p"),Er=i("xFormers is not part of the training requirements, but we recommend you "),Zt=s("a"),yr=i("install"),kr=i(" it if you can because it could make your training faster and less memory intensive."),Ao=c(),De=s("p"),Dr=i("After all the dependencies have been set up, initialize a "),ft=s("a"),xr=i("\u{1F917} Accelerate"),Ar=i(" environment with:"),Po=c(),$(ht.$$.fragment),jo=c(),ea=s("p"),Pr=i("To setup a default \u{1F917} Accelerate environment without choosing any configurations:"),So=c(),$(ut.$$.fragment),No=c(),ta=s("p"),jr=i("Or if your environment doesn\u2019t support an interactive shell like a notebook, you can use:"),Io=c(),$(ct.$$.fragment),qo=c(),xe=s("p"),Sr=i("Finally, download a "),mt=s("a"),Nr=i("few images of a dog"),Ir=i(" to DreamBooth with:"),To=c(),$(_t.$$.fragment),Co=c(),pe=s("h2"),Ae=s("a"),wa=s("span"),$(dt.$$.fragment),qr=c(),Ea=s("span"),Tr=i("Finetuning"),Ro=c(),$(Pe.$$.fragment),Uo=c(),$(je.$$.fragment),Oo=c(),fe=s("h2"),Se=s("a"),ya=s("span"),$(gt.$$.fragment),Cr=c(),ka=s("span"),Rr=i("Finetuning with prior-preserving loss"),Mo=c(),Ne=s("p"),Ur=i("Prior preservation is used to avoid overfitting and language-drift (check out the "),$t=s("a"),Or=i("paper"),Mr=i(" to learn more if you\u2019re interested). For prior preservation, you use other images of the same class as part of the training process. The nice thing is that you can generate those images using the Stable Diffusion model itself! The training script will save the generated images to a local path you specify."),Lo=c(),Ie=s("p"),Lr=i("The authors recommend generating "),Da=s("code"),zr=i("num_epochs * num_samples"),Gr=i(" images for prior preservation. In most cases, 200-300 images work well."),zo=c(),$(qe.$$.fragment),Go=c(),he=s("h2"),Te=s("a"),xa=s("span"),$(vt.$$.fragment),Br=c(),Aa=s("span"),Fr=i("Finetuning the text encoder and UNet"),Bo=c(),X=s("p"),Vr=i("The script also allows you to finetune the "),Pa=s("code"),Hr=i("text_encoder"),Yr=i(" along with the "),ja=s("code"),Wr=i("unet"),Jr=i(". In our experiments (check out the "),bt=s("a"),Kr=i("Training Stable Diffusion with DreamBooth using \u{1F9E8} Diffusers"),Qr=i(" post for more details), this yields much better results, especially when generating images of faces."),Fo=c(),$(Ce.$$.fragment),Vo=c(),Z=s("p"),Xr=i("Pass the "),Sa=s("code"),Zr=i("--train_text_encoder"),en=i(" argument to the training script to enable finetuning the "),Na=s("code"),tn=i("text_encoder"),an=i(" and "),Ia=s("code"),on=i("unet"),sn=i(":"),Ho=c(),$(Re.$$.fragment),Yo=c(),ue=s("h2"),Ue=s("a"),qa=s("span"),$(wt.$$.fragment),rn=c(),Ta=s("span"),nn=i("Finetuning with LoRA"),Wo=c(),Oe=s("p"),ln=i("You can also use Low-Rank Adaptation of Large Language Models (LoRA), a fine-tuning technique for accelerating training large models, on DreamBooth. For more details, take a look at the "),aa=s("a"),pn=i("LoRA training"),fn=i(" guide."),Jo=c(),ce=s("h2"),Me=s("a"),Ca=s("span"),$(Et.$$.fragment),hn=c(),Ra=s("span"),un=i("Saving checkpoints while training"),Ko=c(),oa=s("p"),cn=i("It\u2019s easy to overfit while training with Dreambooth, so sometimes it\u2019s useful to save regular checkpoints during the training process. One of the intermediate checkpoints might actually work better than the final model! Pass the following argument to the training script to enable saving checkpoints:"),Qo=c(),$(yt.$$.fragment),Xo=c(),ee=s("p"),mn=i("This saves the full training state in subfolders of your "),Ua=s("code"),_n=i("output_dir"),dn=i(". Subfolder names begin with the prefix "),Oa=s("code"),gn=i("checkpoint-"),$n=i(", followed by the number of steps performed so far; for example, "),Ma=s("code"),vn=i("checkpoint-1500"),bn=i(" would be a checkpoint saved after 1500 training steps."),Zo=c(),me=s("h3"),Le=s("a"),La=s("span"),$(kt.$$.fragment),wn=c(),za=s("span"),En=i("Resume training from a saved checkpoint"),es=c(),re=s("p"),yn=i("If you want to resume training from any of the saved checkpoints, you can pass the argument "),Ga=s("code"),kn=i("--resume_from_checkpoint"),Dn=i(" to the script and specify the name of the checkpoint you want to use. You can also use the special string "),Ba=s("code"),xn=i('"latest"'),An=i(" to resume from the last saved checkpoint (the one with the largest number of steps). For example, the following would resume training from the checkpoint saved after 1500 steps:"),ts=c(),$(Dt.$$.fragment),as=c(),sa=s("p"),Pn=i("This is a good opportunity to tweak some of your hyperparameters if you wish."),os=c(),_e=s("h3"),ze=s("a"),Fa=s("span"),$(xt.$$.fragment),jn=c(),Va=s("span"),Sn=i("Inference from a saved checkpoint"),ss=c(),ra=s("p"),Nn=i("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."),rs=c(),Ge=s("p"),In=i("If you have "),Ha=s("strong"),Ya=s("code"),qn=i('"accelerate>=0.16.0"'),Tn=i(` installed, use the following code to run
inference from an intermediate checkpoint.`),ns=c(),$(At.$$.fragment),is=c(),Be=s("p"),Cn=i("If you have "),Wa=s("strong"),Ja=s("code"),Rn=i('"accelerate<0.16.0"'),Un=i(" installed, you need to convert it to an inference pipeline first:"),ls=c(),$(Pt.$$.fragment),ps=c(),de=s("h2"),Fe=s("a"),Ka=s("span"),$(jt.$$.fragment),On=c(),Qa=s("span"),Mn=i("Optimizations for different GPU sizes"),fs=c(),na=s("p"),Ln=i("Depending on your hardware, there are a few different ways to optimize DreamBooth on GPUs from 16GB to just 8GB!"),hs=c(),ge=s("h3"),Ve=s("a"),Xa=s("span"),$(St.$$.fragment),zn=c(),Za=s("span"),Gn=i("xFormers"),us=c(),se=s("p"),Nt=s("a"),Bn=i("xFormers"),Fn=i(" is a toolbox for optimizing Transformers, and it includes a "),It=s("a"),Vn=i("memory-efficient attention"),Hn=i(" mechanism that is used in \u{1F9E8} Diffusers. You\u2019ll need to "),ia=s("a"),Yn=i("install xFormers"),Wn=i(" and then add the following argument to your training script:"),cs=c(),$(qt.$$.fragment),ms=c(),la=s("p"),Jn=i("xFormers is not available in Flax."),_s=c(),$e=s("h3"),He=s("a"),eo=s("span"),$(Tt.$$.fragment),Kn=c(),to=s("span"),Qn=i("Set gradients to none"),ds=c(),te=s("p"),Xn=i("Another way you can lower your memory footprint is to "),Ct=s("a"),Zn=i("set the gradients"),ei=i(" to "),ao=s("code"),ti=i("None"),ai=i(" instead of zero. However, this may change certain behaviors, so if you run into any issues, try removing this argument. Add the following argument to your training script to set the gradients to "),oo=s("code"),oi=i("None"),si=i(":"),gs=c(),$(Rt.$$.fragment),$s=c(),ve=s("h3"),Ye=s("a"),so=s("span"),$(Ut.$$.fragment),ri=c(),ro=s("span"),ni=i("16GB GPU"),vs=c(),We=s("p"),ii=i("With the help of gradient checkpointing and "),Ot=s("a"),li=i("bitsandbytes"),pi=i(" 8-bit optimizer, it\u2019s possible to train DreamBooth on a 16GB GPU. Make sure you have bitsandbytes installed:"),bs=c(),$(Mt.$$.fragment),ws=c(),Je=s("p"),fi=i("Then pass the "),no=s("code"),hi=i("--use_8bit_adam"),ui=i(" option to the training script:"),Es=c(),$(Lt.$$.fragment),ys=c(),be=s("h3"),Ke=s("a"),io=s("span"),$(zt.$$.fragment),ci=c(),lo=s("span"),mi=i("12GB GPU"),ks=c(),Qe=s("p"),_i=i("To run DreamBooth on a 12GB GPU, you\u2019ll need to enable gradient checkpointing, the 8-bit optimizer, xFormers, and set the gradients to "),po=s("code"),di=i("None"),gi=i(":"),Ds=c(),$(Gt.$$.fragment),xs=c(),we=s("h3"),Xe=s("a"),fo=s("span"),$(Bt.$$.fragment),$i=c(),ho=s("span"),vi=i("8 GB GPU"),As=c(),Ze=s("p"),bi=i("For 8GB GPUs, you\u2019ll need the help of "),Ft=s("a"),wi=i("DeepSpeed"),Ei=i(` to offload some
tensors from the VRAM to either the CPU or NVME, enabling training with less GPU memory.`),Ps=c(),pa=s("p"),yi=i("Run the following command to configure your \u{1F917} Accelerate environment:"),js=c(),$(Vt.$$.fragment),Ss=c(),et=s("p"),ki=i("During configuration, confirm that you want to use DeepSpeed. Now it\u2019s possible to train on under 8GB VRAM by combining DeepSpeed stage 2, fp16 mixed precision, and offloading the model parameters and the optimizer state to the CPU. The drawback is that this requires more system RAM, about 25 GB. See "),Ht=s("a"),Di=i("the DeepSpeed documentation"),xi=i(" for more configuration options."),Ns=c(),ne=s("p"),Ai=i(`You should also change the default Adam optimizer to DeepSpeed\u2019s optimized version of Adam
`),Yt=s("a"),uo=s("code"),Pi=i("deepspeed.ops.adam.DeepSpeedCPUAdam"),ji=i(" for a substantial speedup. Enabling "),co=s("code"),Si=i("DeepSpeedCPUAdam"),Ni=i(" requires your system\u2019s CUDA toolchain version to be the same as the one installed with PyTorch."),Is=c(),fa=s("p"),Ii=i("8-bit optimizers don\u2019t seem to be compatible with DeepSpeed at the moment."),qs=c(),ha=s("p"),qi=i("Launch training with the following command:"),Ts=c(),$(Wt.$$.fragment),Cs=c(),Ee=s("h2"),tt=s("a"),mo=s("span"),$(Jt.$$.fragment),Ti=c(),_o=s("span"),Ci=i("Inference"),Rs=c(),ae=s("p"),Ri=i("Once you have trained a model, specify the path to where the model is saved, and use it for inference in the "),ua=s("a"),Ui=i("StableDiffusionPipeline"),Oi=i(". Make sure your prompts include the special "),go=s("code"),Mi=i("identifier"),Li=i(" used during training ("),$o=s("code"),zi=i("sks"),Gi=i(" in the previous examples)."),Us=c(),at=s("p"),Bi=i("If you have "),vo=s("strong"),bo=s("code"),Fi=i('"accelerate>=0.16.0"'),Vi=i(` installed, you can use the following code to run
inference from an intermediate checkpoint:`),Os=c(),$(Kt.$$.fragment),Ms=c(),ot=s("p"),Hi=i("You may also run inference from any of the "),ca=s("a"),Yi=i("saved training checkpoints"),Wi=i("."),this.h()},l(e){const o=Yp('[data-svelte="svelte-1phssyn"]',document.head);h=r(o,"META",{name:!0,content:!0}),o.forEach(t),d=m(e),p=r(e,"H1",{class:!0});var Qt=n(p);g=r(Qt,"A",{id:!0,class:!0,href:!0});var wo=n(g);D=r(wo,"SPAN",{});var Eo=n(D);v(j.$$.fragment,Eo),Eo.forEach(t),wo.forEach(t),x=m(Qt),C=r(Qt,"SPAN",{});var yo=n(C);H=l(yo,"DreamBooth"),yo.forEach(t),Qt.forEach(t),R=m(e),v(U.$$.fragment,e),N=m(e),O=r(e,"P",{});var ma=n(O);q=r(ma,"A",{href:!0,rel:!0});var Qi=n(q);Q=l(Qi,"DreamBooth"),Qi.forEach(t),M=l(ma," is a method to personalize text-to-image models like Stable Diffusion given just a few (3-5) images of a subject. It allows the model to generate contextualized images of the subject in different scenes, poses, and views."),ma.forEach(t),L=m(e),I=r(e,"P",{});var Xi=n(I);Y=r(Xi,"IMG",{src:!0,alt:!0}),Xi.forEach(t),G=m(e),B=r(e,"SMALL",{});var Ji=n(B);W=l(Ji,"Dreambooth examples from the "),S=r(Ji,"A",{href:!0});var Zi=n(S);J=l(Zi,"project's blog."),Zi.forEach(t),Ji.forEach(t),_=m(e),k=r(e,"P",{});var _a=n(k);ie=l(_a,"This guide will show you how to finetune DreamBooth with the "),T=r(_a,"A",{href:!0,rel:!0});var el=n(T);F=r(el,"CODE",{});var tl=n(F);le=l(tl,"CompVis/stable-diffusion-v1-4"),tl.forEach(t),el.forEach(t),oe=l(_a," model for various GPU sizes, and with Flax. All the training scripts for DreamBooth used in this guide can be found "),K=r(_a,"A",{href:!0,rel:!0});var al=n(K);gr=l(al,"here"),al.forEach(t),$r=l(_a," if you\u2019re interested in digging deeper and seeing how things work."),_a.forEach(t),ko=m(e),ye=r(e,"P",{});var zs=n(ye);vr=l(zs,"Before running the scripts, make sure you install the library\u2019s training dependencies. We also recommend installing \u{1F9E8} Diffusers from the "),ba=r(zs,"CODE",{});var ol=n(ba);br=l(ol,"main"),ol.forEach(t),wr=l(zs," GitHub branch:"),zs.forEach(t),Do=m(e),v(pt.$$.fragment,e),xo=m(e),ke=r(e,"P",{});var Gs=n(ke);Er=l(Gs,"xFormers is not part of the training requirements, but we recommend you "),Zt=r(Gs,"A",{href:!0});var sl=n(Zt);yr=l(sl,"install"),sl.forEach(t),kr=l(Gs," it if you can because it could make your training faster and less memory intensive."),Gs.forEach(t),Ao=m(e),De=r(e,"P",{});var Bs=n(De);Dr=l(Bs,"After all the dependencies have been set up, initialize a "),ft=r(Bs,"A",{href:!0,rel:!0});var rl=n(ft);xr=l(rl,"\u{1F917} Accelerate"),rl.forEach(t),Ar=l(Bs," environment with:"),Bs.forEach(t),Po=m(e),v(ht.$$.fragment,e),jo=m(e),ea=r(e,"P",{});var nl=n(ea);Pr=l(nl,"To setup a default \u{1F917} Accelerate environment without choosing any configurations:"),nl.forEach(t),So=m(e),v(ut.$$.fragment,e),No=m(e),ta=r(e,"P",{});var il=n(ta);jr=l(il,"Or if your environment doesn\u2019t support an interactive shell like a notebook, you can use:"),il.forEach(t),Io=m(e),v(ct.$$.fragment,e),qo=m(e),xe=r(e,"P",{});var Fs=n(xe);Sr=l(Fs,"Finally, download a "),mt=r(Fs,"A",{href:!0,rel:!0});var ll=n(mt);Nr=l(ll,"few images of a dog"),ll.forEach(t),Ir=l(Fs," to DreamBooth with:"),Fs.forEach(t),To=m(e),v(_t.$$.fragment,e),Co=m(e),pe=r(e,"H2",{class:!0});var Vs=n(pe);Ae=r(Vs,"A",{id:!0,class:!0,href:!0});var pl=n(Ae);wa=r(pl,"SPAN",{});var fl=n(wa);v(dt.$$.fragment,fl),fl.forEach(t),pl.forEach(t),qr=m(Vs),Ea=r(Vs,"SPAN",{});var hl=n(Ea);Tr=l(hl,"Finetuning"),hl.forEach(t),Vs.forEach(t),Ro=m(e),v(Pe.$$.fragment,e),Uo=m(e),v(je.$$.fragment,e),Oo=m(e),fe=r(e,"H2",{class:!0});var Hs=n(fe);Se=r(Hs,"A",{id:!0,class:!0,href:!0});var ul=n(Se);ya=r(ul,"SPAN",{});var cl=n(ya);v(gt.$$.fragment,cl),cl.forEach(t),ul.forEach(t),Cr=m(Hs),ka=r(Hs,"SPAN",{});var ml=n(ka);Rr=l(ml,"Finetuning with prior-preserving loss"),ml.forEach(t),Hs.forEach(t),Mo=m(e),Ne=r(e,"P",{});var Ys=n(Ne);Ur=l(Ys,"Prior preservation is used to avoid overfitting and language-drift (check out the "),$t=r(Ys,"A",{href:!0,rel:!0});var _l=n($t);Or=l(_l,"paper"),_l.forEach(t),Mr=l(Ys," to learn more if you\u2019re interested). For prior preservation, you use other images of the same class as part of the training process. The nice thing is that you can generate those images using the Stable Diffusion model itself! The training script will save the generated images to a local path you specify."),Ys.forEach(t),Lo=m(e),Ie=r(e,"P",{});var Ws=n(Ie);Lr=l(Ws,"The authors recommend generating "),Da=r(Ws,"CODE",{});var dl=n(Da);zr=l(dl,"num_epochs * num_samples"),dl.forEach(t),Gr=l(Ws," images for prior preservation. In most cases, 200-300 images work well."),Ws.forEach(t),zo=m(e),v(qe.$$.fragment,e),Go=m(e),he=r(e,"H2",{class:!0});var Js=n(he);Te=r(Js,"A",{id:!0,class:!0,href:!0});var gl=n(Te);xa=r(gl,"SPAN",{});var $l=n(xa);v(vt.$$.fragment,$l),$l.forEach(t),gl.forEach(t),Br=m(Js),Aa=r(Js,"SPAN",{});var vl=n(Aa);Fr=l(vl,"Finetuning the text encoder and UNet"),vl.forEach(t),Js.forEach(t),Bo=m(e),X=r(e,"P",{});var st=n(X);Vr=l(st,"The script also allows you to finetune the "),Pa=r(st,"CODE",{});var bl=n(Pa);Hr=l(bl,"text_encoder"),bl.forEach(t),Yr=l(st," along with the "),ja=r(st,"CODE",{});var wl=n(ja);Wr=l(wl,"unet"),wl.forEach(t),Jr=l(st,". In our experiments (check out the "),bt=r(st,"A",{href:!0,rel:!0});var El=n(bt);Kr=l(El,"Training Stable Diffusion with DreamBooth using \u{1F9E8} Diffusers"),El.forEach(t),Qr=l(st," post for more details), this yields much better results, especially when generating images of faces."),st.forEach(t),Fo=m(e),v(Ce.$$.fragment,e),Vo=m(e),Z=r(e,"P",{});var rt=n(Z);Xr=l(rt,"Pass the "),Sa=r(rt,"CODE",{});var yl=n(Sa);Zr=l(yl,"--train_text_encoder"),yl.forEach(t),en=l(rt," argument to the training script to enable finetuning the "),Na=r(rt,"CODE",{});var kl=n(Na);tn=l(kl,"text_encoder"),kl.forEach(t),an=l(rt," and "),Ia=r(rt,"CODE",{});var Dl=n(Ia);on=l(Dl,"unet"),Dl.forEach(t),sn=l(rt,":"),rt.forEach(t),Ho=m(e),v(Re.$$.fragment,e),Yo=m(e),ue=r(e,"H2",{class:!0});var Ks=n(ue);Ue=r(Ks,"A",{id:!0,class:!0,href:!0});var xl=n(Ue);qa=r(xl,"SPAN",{});var Al=n(qa);v(wt.$$.fragment,Al),Al.forEach(t),xl.forEach(t),rn=m(Ks),Ta=r(Ks,"SPAN",{});var Pl=n(Ta);nn=l(Pl,"Finetuning with LoRA"),Pl.forEach(t),Ks.forEach(t),Wo=m(e),Oe=r(e,"P",{});var Qs=n(Oe);ln=l(Qs,"You can also use Low-Rank Adaptation of Large Language Models (LoRA), a fine-tuning technique for accelerating training large models, on DreamBooth. For more details, take a look at the "),aa=r(Qs,"A",{href:!0});var jl=n(aa);pn=l(jl,"LoRA training"),jl.forEach(t),fn=l(Qs," guide."),Qs.forEach(t),Jo=m(e),ce=r(e,"H2",{class:!0});var Xs=n(ce);Me=r(Xs,"A",{id:!0,class:!0,href:!0});var Sl=n(Me);Ca=r(Sl,"SPAN",{});var Nl=n(Ca);v(Et.$$.fragment,Nl),Nl.forEach(t),Sl.forEach(t),hn=m(Xs),Ra=r(Xs,"SPAN",{});var Il=n(Ra);un=l(Il,"Saving checkpoints while training"),Il.forEach(t),Xs.forEach(t),Ko=m(e),oa=r(e,"P",{});var ql=n(oa);cn=l(ql,"It\u2019s easy to overfit while training with Dreambooth, so sometimes it\u2019s useful to save regular checkpoints during the training process. One of the intermediate checkpoints might actually work better than the final model! Pass the following argument to the training script to enable saving checkpoints:"),ql.forEach(t),Qo=m(e),v(yt.$$.fragment,e),Xo=m(e),ee=r(e,"P",{});var nt=n(ee);mn=l(nt,"This saves the full training state in subfolders of your "),Ua=r(nt,"CODE",{});var Tl=n(Ua);_n=l(Tl,"output_dir"),Tl.forEach(t),dn=l(nt,". Subfolder names begin with the prefix "),Oa=r(nt,"CODE",{});var Cl=n(Oa);gn=l(Cl,"checkpoint-"),Cl.forEach(t),$n=l(nt,", followed by the number of steps performed so far; for example, "),Ma=r(nt,"CODE",{});var Rl=n(Ma);vn=l(Rl,"checkpoint-1500"),Rl.forEach(t),bn=l(nt," would be a checkpoint saved after 1500 training steps."),nt.forEach(t),Zo=m(e),me=r(e,"H3",{class:!0});var Zs=n(me);Le=r(Zs,"A",{id:!0,class:!0,href:!0});var Ul=n(Le);La=r(Ul,"SPAN",{});var Ol=n(La);v(kt.$$.fragment,Ol),Ol.forEach(t),Ul.forEach(t),wn=m(Zs),za=r(Zs,"SPAN",{});var Ml=n(za);En=l(Ml,"Resume training from a saved checkpoint"),Ml.forEach(t),Zs.forEach(t),es=m(e),re=r(e,"P",{});var da=n(re);yn=l(da,"If you want to resume training from any of the saved checkpoints, you can pass the argument "),Ga=r(da,"CODE",{});var Ll=n(Ga);kn=l(Ll,"--resume_from_checkpoint"),Ll.forEach(t),Dn=l(da," to the script and specify the name of the checkpoint you want to use. You can also use the special string "),Ba=r(da,"CODE",{});var zl=n(Ba);xn=l(zl,'"latest"'),zl.forEach(t),An=l(da," to resume from the last saved checkpoint (the one with the largest number of steps). For example, the following would resume training from the checkpoint saved after 1500 steps:"),da.forEach(t),ts=m(e),v(Dt.$$.fragment,e),as=m(e),sa=r(e,"P",{});var Gl=n(sa);Pn=l(Gl,"This is a good opportunity to tweak some of your hyperparameters if you wish."),Gl.forEach(t),os=m(e),_e=r(e,"H3",{class:!0});var er=n(_e);ze=r(er,"A",{id:!0,class:!0,href:!0});var Bl=n(ze);Fa=r(Bl,"SPAN",{});var Fl=n(Fa);v(xt.$$.fragment,Fl),Fl.forEach(t),Bl.forEach(t),jn=m(er),Va=r(er,"SPAN",{});var Vl=n(Va);Sn=l(Vl,"Inference from a saved checkpoint"),Vl.forEach(t),er.forEach(t),ss=m(e),ra=r(e,"P",{});var Hl=n(ra);Nn=l(Hl,"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."),Hl.forEach(t),rs=m(e),Ge=r(e,"P",{});var tr=n(Ge);In=l(tr,"If you have "),Ha=r(tr,"STRONG",{});var Yl=n(Ha);Ya=r(Yl,"CODE",{});var Wl=n(Ya);qn=l(Wl,'"accelerate>=0.16.0"'),Wl.forEach(t),Yl.forEach(t),Tn=l(tr,` installed, use the following code to run
inference from an intermediate checkpoint.`),tr.forEach(t),ns=m(e),v(At.$$.fragment,e),is=m(e),Be=r(e,"P",{});var ar=n(Be);Cn=l(ar,"If you have "),Wa=r(ar,"STRONG",{});var Jl=n(Wa);Ja=r(Jl,"CODE",{});var Kl=n(Ja);Rn=l(Kl,'"accelerate<0.16.0"'),Kl.forEach(t),Jl.forEach(t),Un=l(ar," installed, you need to convert it to an inference pipeline first:"),ar.forEach(t),ls=m(e),v(Pt.$$.fragment,e),ps=m(e),de=r(e,"H2",{class:!0});var or=n(de);Fe=r(or,"A",{id:!0,class:!0,href:!0});var Ql=n(Fe);Ka=r(Ql,"SPAN",{});var Xl=n(Ka);v(jt.$$.fragment,Xl),Xl.forEach(t),Ql.forEach(t),On=m(or),Qa=r(or,"SPAN",{});var Zl=n(Qa);Mn=l(Zl,"Optimizations for different GPU sizes"),Zl.forEach(t),or.forEach(t),fs=m(e),na=r(e,"P",{});var ep=n(na);Ln=l(ep,"Depending on your hardware, there are a few different ways to optimize DreamBooth on GPUs from 16GB to just 8GB!"),ep.forEach(t),hs=m(e),ge=r(e,"H3",{class:!0});var sr=n(ge);Ve=r(sr,"A",{id:!0,class:!0,href:!0});var tp=n(Ve);Xa=r(tp,"SPAN",{});var ap=n(Xa);v(St.$$.fragment,ap),ap.forEach(t),tp.forEach(t),zn=m(sr),Za=r(sr,"SPAN",{});var op=n(Za);Gn=l(op,"xFormers"),op.forEach(t),sr.forEach(t),us=m(e),se=r(e,"P",{});var Xt=n(se);Nt=r(Xt,"A",{href:!0,rel:!0});var sp=n(Nt);Bn=l(sp,"xFormers"),sp.forEach(t),Fn=l(Xt," is a toolbox for optimizing Transformers, and it includes a "),It=r(Xt,"A",{href:!0,rel:!0});var rp=n(It);Vn=l(rp,"memory-efficient attention"),rp.forEach(t),Hn=l(Xt," mechanism that is used in \u{1F9E8} Diffusers. You\u2019ll need to "),ia=r(Xt,"A",{href:!0});var np=n(ia);Yn=l(np,"install xFormers"),np.forEach(t),Wn=l(Xt," and then add the following argument to your training script:"),Xt.forEach(t),cs=m(e),v(qt.$$.fragment,e),ms=m(e),la=r(e,"P",{});var ip=n(la);Jn=l(ip,"xFormers is not available in Flax."),ip.forEach(t),_s=m(e),$e=r(e,"H3",{class:!0});var rr=n($e);He=r(rr,"A",{id:!0,class:!0,href:!0});var lp=n(He);eo=r(lp,"SPAN",{});var pp=n(eo);v(Tt.$$.fragment,pp),pp.forEach(t),lp.forEach(t),Kn=m(rr),to=r(rr,"SPAN",{});var fp=n(to);Qn=l(fp,"Set gradients to none"),fp.forEach(t),rr.forEach(t),ds=m(e),te=r(e,"P",{});var it=n(te);Xn=l(it,"Another way you can lower your memory footprint is to "),Ct=r(it,"A",{href:!0,rel:!0});var hp=n(Ct);Zn=l(hp,"set the gradients"),hp.forEach(t),ei=l(it," to "),ao=r(it,"CODE",{});var up=n(ao);ti=l(up,"None"),up.forEach(t),ai=l(it," instead of zero. However, this may change certain behaviors, so if you run into any issues, try removing this argument. Add the following argument to your training script to set the gradients to "),oo=r(it,"CODE",{});var cp=n(oo);oi=l(cp,"None"),cp.forEach(t),si=l(it,":"),it.forEach(t),gs=m(e),v(Rt.$$.fragment,e),$s=m(e),ve=r(e,"H3",{class:!0});var nr=n(ve);Ye=r(nr,"A",{id:!0,class:!0,href:!0});var mp=n(Ye);so=r(mp,"SPAN",{});var _p=n(so);v(Ut.$$.fragment,_p),_p.forEach(t),mp.forEach(t),ri=m(nr),ro=r(nr,"SPAN",{});var dp=n(ro);ni=l(dp,"16GB GPU"),dp.forEach(t),nr.forEach(t),vs=m(e),We=r(e,"P",{});var ir=n(We);ii=l(ir,"With the help of gradient checkpointing and "),Ot=r(ir,"A",{href:!0,rel:!0});var gp=n(Ot);li=l(gp,"bitsandbytes"),gp.forEach(t),pi=l(ir," 8-bit optimizer, it\u2019s possible to train DreamBooth on a 16GB GPU. Make sure you have bitsandbytes installed:"),ir.forEach(t),bs=m(e),v(Mt.$$.fragment,e),ws=m(e),Je=r(e,"P",{});var lr=n(Je);fi=l(lr,"Then pass the "),no=r(lr,"CODE",{});var $p=n(no);hi=l($p,"--use_8bit_adam"),$p.forEach(t),ui=l(lr," option to the training script:"),lr.forEach(t),Es=m(e),v(Lt.$$.fragment,e),ys=m(e),be=r(e,"H3",{class:!0});var pr=n(be);Ke=r(pr,"A",{id:!0,class:!0,href:!0});var vp=n(Ke);io=r(vp,"SPAN",{});var bp=n(io);v(zt.$$.fragment,bp),bp.forEach(t),vp.forEach(t),ci=m(pr),lo=r(pr,"SPAN",{});var wp=n(lo);mi=l(wp,"12GB GPU"),wp.forEach(t),pr.forEach(t),ks=m(e),Qe=r(e,"P",{});var fr=n(Qe);_i=l(fr,"To run DreamBooth on a 12GB GPU, you\u2019ll need to enable gradient checkpointing, the 8-bit optimizer, xFormers, and set the gradients to "),po=r(fr,"CODE",{});var Ep=n(po);di=l(Ep,"None"),Ep.forEach(t),gi=l(fr,":"),fr.forEach(t),Ds=m(e),v(Gt.$$.fragment,e),xs=m(e),we=r(e,"H3",{class:!0});var hr=n(we);Xe=r(hr,"A",{id:!0,class:!0,href:!0});var yp=n(Xe);fo=r(yp,"SPAN",{});var kp=n(fo);v(Bt.$$.fragment,kp),kp.forEach(t),yp.forEach(t),$i=m(hr),ho=r(hr,"SPAN",{});var Dp=n(ho);vi=l(Dp,"8 GB GPU"),Dp.forEach(t),hr.forEach(t),As=m(e),Ze=r(e,"P",{});var ur=n(Ze);bi=l(ur,"For 8GB GPUs, you\u2019ll need the help of "),Ft=r(ur,"A",{href:!0,rel:!0});var xp=n(Ft);wi=l(xp,"DeepSpeed"),xp.forEach(t),Ei=l(ur,` to offload some
tensors from the VRAM to either the CPU or NVME, enabling training with less GPU memory.`),ur.forEach(t),Ps=m(e),pa=r(e,"P",{});var Ap=n(pa);yi=l(Ap,"Run the following command to configure your \u{1F917} Accelerate environment:"),Ap.forEach(t),js=m(e),v(Vt.$$.fragment,e),Ss=m(e),et=r(e,"P",{});var cr=n(et);ki=l(cr,"During configuration, confirm that you want to use DeepSpeed. Now it\u2019s possible to train on under 8GB VRAM by combining DeepSpeed stage 2, fp16 mixed precision, and offloading the model parameters and the optimizer state to the CPU. The drawback is that this requires more system RAM, about 25 GB. See "),Ht=r(cr,"A",{href:!0,rel:!0});var Pp=n(Ht);Di=l(Pp,"the DeepSpeed documentation"),Pp.forEach(t),xi=l(cr," for more configuration options."),cr.forEach(t),Ns=m(e),ne=r(e,"P",{});var ga=n(ne);Ai=l(ga,`You should also change the default Adam optimizer to DeepSpeed\u2019s optimized version of Adam
`),Yt=r(ga,"A",{href:!0,rel:!0});var jp=n(Yt);uo=r(jp,"CODE",{});var Sp=n(uo);Pi=l(Sp,"deepspeed.ops.adam.DeepSpeedCPUAdam"),Sp.forEach(t),jp.forEach(t),ji=l(ga," for a substantial speedup. Enabling "),co=r(ga,"CODE",{});var Np=n(co);Si=l(Np,"DeepSpeedCPUAdam"),Np.forEach(t),Ni=l(ga," requires your system\u2019s CUDA toolchain version to be the same as the one installed with PyTorch."),ga.forEach(t),Is=m(e),fa=r(e,"P",{});var Ip=n(fa);Ii=l(Ip,"8-bit optimizers don\u2019t seem to be compatible with DeepSpeed at the moment."),Ip.forEach(t),qs=m(e),ha=r(e,"P",{});var qp=n(ha);qi=l(qp,"Launch training with the following command:"),qp.forEach(t),Ts=m(e),v(Wt.$$.fragment,e),Cs=m(e),Ee=r(e,"H2",{class:!0});var mr=n(Ee);tt=r(mr,"A",{id:!0,class:!0,href:!0});var Tp=n(tt);mo=r(Tp,"SPAN",{});var Cp=n(mo);v(Jt.$$.fragment,Cp),Cp.forEach(t),Tp.forEach(t),Ti=m(mr),_o=r(mr,"SPAN",{});var Rp=n(_o);Ci=l(Rp,"Inference"),Rp.forEach(t),mr.forEach(t),Rs=m(e),ae=r(e,"P",{});var lt=n(ae);Ri=l(lt,"Once you have trained a model, specify the path to where the model is saved, and use it for inference in the "),ua=r(lt,"A",{href:!0});var Up=n(ua);Ui=l(Up,"StableDiffusionPipeline"),Up.forEach(t),Oi=l(lt,". Make sure your prompts include the special "),go=r(lt,"CODE",{});var Op=n(go);Mi=l(Op,"identifier"),Op.forEach(t),Li=l(lt," used during training ("),$o=r(lt,"CODE",{});var Mp=n($o);zi=l(Mp,"sks"),Mp.forEach(t),Gi=l(lt," in the previous examples)."),lt.forEach(t),Us=m(e),at=r(e,"P",{});var _r=n(at);Bi=l(_r,"If you have "),vo=r(_r,"STRONG",{});var Lp=n(vo);bo=r(Lp,"CODE",{});var zp=n(bo);Fi=l(zp,'"accelerate>=0.16.0"'),zp.forEach(t),Lp.forEach(t),Vi=l(_r,` installed, you can use the following code to run
inference from an intermediate checkpoint:`),_r.forEach(t),Os=m(e),v(Kt.$$.fragment,e),Ms=m(e),ot=r(e,"P",{});var dr=n(ot);Hi=l(dr,"You may also run inference from any of the "),ca=r(dr,"A",{href:!0});var Gp=n(ca);Yi=l(Gp,"saved training checkpoints"),Gp.forEach(t),Wi=l(dr,"."),dr.forEach(t),this.h()},h(){u(h,"name","hf:doc:metadata"),u(h,"content",JSON.stringify(cf)),u(g,"id","dreambooth"),u(g,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),u(g,"href","#dreambooth"),u(p,"class","relative group"),u(q,"href","https://arxiv.org/abs/2208.12242"),u(q,"rel","nofollow"),Wp(Y.src,z="https://dreambooth.github.io/DreamBooth_files/teaser_static.jpg")||u(Y,"src",z),u(Y,"alt","Dreambooth examples from the project's blog"),u(S,"href","https://dreambooth.github.io"),u(T,"href","https://huggingface.co/CompVis/stable-diffusion-v1-4"),u(T,"rel","nofollow"),u(K,"href","https://github.com/huggingface/diffusers/tree/main/examples/dreambooth"),u(K,"rel","nofollow"),u(Zt,"href","../optimization/xformers"),u(ft,"href","https://github.com/huggingface/accelerate/"),u(ft,"rel","nofollow"),u(mt,"href","https://huggingface.co/datasets/diffusers/dog-example"),u(mt,"rel","nofollow"),u(Ae,"id","finetuning"),u(Ae,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),u(Ae,"href","#finetuning"),u(pe,"class","relative group"),u(Se,"id","finetuning-with-priorpreserving-loss"),u(Se,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),u(Se,"href","#finetuning-with-priorpreserving-loss"),u(fe,"class","relative group"),u($t,"href","https://arxiv.org/abs/2208.12242"),u($t,"rel","nofollow"),u(Te,"id","finetuning-the-text-encoder-and-unet"),u(Te,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),u(Te,"href","#finetuning-the-text-encoder-and-unet"),u(he,"class","relative group"),u(bt,"href","https://huggingface.co/blog/dreambooth"),u(bt,"rel","nofollow"),u(Ue,"id","finetuning-with-lora"),u(Ue,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),u(Ue,"href","#finetuning-with-lora"),u(ue,"class","relative group"),u(aa,"href","./lora#dreambooth"),u(Me,"id","saving-checkpoints-while-training"),u(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"),u(Me,"href","#saving-checkpoints-while-training"),u(ce,"class","relative group"),u(Le,"id","resume-training-from-a-saved-checkpoint"),u(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"),u(Le,"href","#resume-training-from-a-saved-checkpoint"),u(me,"class","relative group"),u(ze,"id","inference-from-a-saved-checkpoint"),u(ze,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),u(ze,"href","#inference-from-a-saved-checkpoint"),u(_e,"class","relative group"),u(Fe,"id","optimizations-for-different-gpu-sizes"),u(Fe,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),u(Fe,"href","#optimizations-for-different-gpu-sizes"),u(de,"class","relative group"),u(Ve,"id","xformers"),u(Ve,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),u(Ve,"href","#xformers"),u(ge,"class","relative group"),u(Nt,"href","https://github.com/facebookresearch/xformers"),u(Nt,"rel","nofollow"),u(It,"href","https://facebookresearch.github.io/xformers/components/ops.html#module-xformers.ops"),u(It,"rel","nofollow"),u(ia,"href","./optimization/xformers"),u(He,"id","set-gradients-to-none"),u(He,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),u(He,"href","#set-gradients-to-none"),u($e,"class","relative group"),u(Ct,"href","https://pytorch.org/docs/stable/generated/torch.optim.Optimizer.zero_grad.html"),u(Ct,"rel","nofollow"),u(Ye,"id","16gb-gpu"),u(Ye,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),u(Ye,"href","#16gb-gpu"),u(ve,"class","relative group"),u(Ot,"href","https://github.com/TimDettmers/bitsandbytes"),u(Ot,"rel","nofollow"),u(Ke,"id","12gb-gpu"),u(Ke,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),u(Ke,"href","#12gb-gpu"),u(be,"class","relative group"),u(Xe,"id","8-gb-gpu"),u(Xe,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),u(Xe,"href","#8-gb-gpu"),u(we,"class","relative group"),u(Ft,"href","https://www.deepspeed.ai/"),u(Ft,"rel","nofollow"),u(Ht,"href","https://huggingface.co/docs/accelerate/usage_guides/deepspeed"),u(Ht,"rel","nofollow"),u(Yt,"href","https://deepspeed.readthedocs.io/en/latest/optimizers.html#adam-cpu"),u(Yt,"rel","nofollow"),u(tt,"id","inference"),u(tt,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),u(tt,"href","#inference"),u(Ee,"class","relative group"),u(ua,"href","/docs/diffusers/v0.16.0/en/api/pipelines/stable_diffusion/text2img#diffusers.StableDiffusionPipeline"),u(ca,"href","#inference-from-a-saved-checkpoint")},m(e,o){a(document.head,h),f(e,d,o),f(e,p,o),a(p,g),a(g,D),b(j,D,null),a(p,x),a(p,C),a(C,H),f(e,R,o),b(U,e,o),f(e,N,o),f(e,O,o),a(O,q),a(q,Q),a(O,M),f(e,L,o),f(e,I,o),a(I,Y),f(e,G,o),f(e,B,o),a(B,W),a(B,S),a(S,J),f(e,_,o),f(e,k,o),a(k,ie),a(k,T),a(T,F),a(F,le),a(k,oe),a(k,K),a(K,gr),a(k,$r),f(e,ko,o),f(e,ye,o),a(ye,vr),a(ye,ba),a(ba,br),a(ye,wr),f(e,Do,o),b(pt,e,o),f(e,xo,o),f(e,ke,o),a(ke,Er),a(ke,Zt),a(Zt,yr),a(ke,kr),f(e,Ao,o),f(e,De,o),a(De,Dr),a(De,ft),a(ft,xr),a(De,Ar),f(e,Po,o),b(ht,e,o),f(e,jo,o),f(e,ea,o),a(ea,Pr),f(e,So,o),b(ut,e,o),f(e,No,o),f(e,ta,o),a(ta,jr),f(e,Io,o),b(ct,e,o),f(e,qo,o),f(e,xe,o),a(xe,Sr),a(xe,mt),a(mt,Nr),a(xe,Ir),f(e,To,o),b(_t,e,o),f(e,Co,o),f(e,pe,o),a(pe,Ae),a(Ae,wa),b(dt,wa,null),a(pe,qr),a(pe,Ea),a(Ea,Tr),f(e,Ro,o),b(Pe,e,o),f(e,Uo,o),b(je,e,o),f(e,Oo,o),f(e,fe,o),a(fe,Se),a(Se,ya),b(gt,ya,null),a(fe,Cr),a(fe,ka),a(ka,Rr),f(e,Mo,o),f(e,Ne,o),a(Ne,Ur),a(Ne,$t),a($t,Or),a(Ne,Mr),f(e,Lo,o),f(e,Ie,o),a(Ie,Lr),a(Ie,Da),a(Da,zr),a(Ie,Gr),f(e,zo,o),b(qe,e,o),f(e,Go,o),f(e,he,o),a(he,Te),a(Te,xa),b(vt,xa,null),a(he,Br),a(he,Aa),a(Aa,Fr),f(e,Bo,o),f(e,X,o),a(X,Vr),a(X,Pa),a(Pa,Hr),a(X,Yr),a(X,ja),a(ja,Wr),a(X,Jr),a(X,bt),a(bt,Kr),a(X,Qr),f(e,Fo,o),b(Ce,e,o),f(e,Vo,o),f(e,Z,o),a(Z,Xr),a(Z,Sa),a(Sa,Zr),a(Z,en),a(Z,Na),a(Na,tn),a(Z,an),a(Z,Ia),a(Ia,on),a(Z,sn),f(e,Ho,o),b(Re,e,o),f(e,Yo,o),f(e,ue,o),a(ue,Ue),a(Ue,qa),b(wt,qa,null),a(ue,rn),a(ue,Ta),a(Ta,nn),f(e,Wo,o),f(e,Oe,o),a(Oe,ln),a(Oe,aa),a(aa,pn),a(Oe,fn),f(e,Jo,o),f(e,ce,o),a(ce,Me),a(Me,Ca),b(Et,Ca,null),a(ce,hn),a(ce,Ra),a(Ra,un),f(e,Ko,o),f(e,oa,o),a(oa,cn),f(e,Qo,o),b(yt,e,o),f(e,Xo,o),f(e,ee,o),a(ee,mn),a(ee,Ua),a(Ua,_n),a(ee,dn),a(ee,Oa),a(Oa,gn),a(ee,$n),a(ee,Ma),a(Ma,vn),a(ee,bn),f(e,Zo,o),f(e,me,o),a(me,Le),a(Le,La),b(kt,La,null),a(me,wn),a(me,za),a(za,En),f(e,es,o),f(e,re,o),a(re,yn),a(re,Ga),a(Ga,kn),a(re,Dn),a(re,Ba),a(Ba,xn),a(re,An),f(e,ts,o),b(Dt,e,o),f(e,as,o),f(e,sa,o),a(sa,Pn),f(e,os,o),f(e,_e,o),a(_e,ze),a(ze,Fa),b(xt,Fa,null),a(_e,jn),a(_e,Va),a(Va,Sn),f(e,ss,o),f(e,ra,o),a(ra,Nn),f(e,rs,o),f(e,Ge,o),a(Ge,In),a(Ge,Ha),a(Ha,Ya),a(Ya,qn),a(Ge,Tn),f(e,ns,o),b(At,e,o),f(e,is,o),f(e,Be,o),a(Be,Cn),a(Be,Wa),a(Wa,Ja),a(Ja,Rn),a(Be,Un),f(e,ls,o),b(Pt,e,o),f(e,ps,o),f(e,de,o),a(de,Fe),a(Fe,Ka),b(jt,Ka,null),a(de,On),a(de,Qa),a(Qa,Mn),f(e,fs,o),f(e,na,o),a(na,Ln),f(e,hs,o),f(e,ge,o),a(ge,Ve),a(Ve,Xa),b(St,Xa,null),a(ge,zn),a(ge,Za),a(Za,Gn),f(e,us,o),f(e,se,o),a(se,Nt),a(Nt,Bn),a(se,Fn),a(se,It),a(It,Vn),a(se,Hn),a(se,ia),a(ia,Yn),a(se,Wn),f(e,cs,o),b(qt,e,o),f(e,ms,o),f(e,la,o),a(la,Jn),f(e,_s,o),f(e,$e,o),a($e,He),a(He,eo),b(Tt,eo,null),a($e,Kn),a($e,to),a(to,Qn),f(e,ds,o),f(e,te,o),a(te,Xn),a(te,Ct),a(Ct,Zn),a(te,ei),a(te,ao),a(ao,ti),a(te,ai),a(te,oo),a(oo,oi),a(te,si),f(e,gs,o),b(Rt,e,o),f(e,$s,o),f(e,ve,o),a(ve,Ye),a(Ye,so),b(Ut,so,null),a(ve,ri),a(ve,ro),a(ro,ni),f(e,vs,o),f(e,We,o),a(We,ii),a(We,Ot),a(Ot,li),a(We,pi),f(e,bs,o),b(Mt,e,o),f(e,ws,o),f(e,Je,o),a(Je,fi),a(Je,no),a(no,hi),a(Je,ui),f(e,Es,o),b(Lt,e,o),f(e,ys,o),f(e,be,o),a(be,Ke),a(Ke,io),b(zt,io,null),a(be,ci),a(be,lo),a(lo,mi),f(e,ks,o),f(e,Qe,o),a(Qe,_i),a(Qe,po),a(po,di),a(Qe,gi),f(e,Ds,o),b(Gt,e,o),f(e,xs,o),f(e,we,o),a(we,Xe),a(Xe,fo),b(Bt,fo,null),a(we,$i),a(we,ho),a(ho,vi),f(e,As,o),f(e,Ze,o),a(Ze,bi),a(Ze,Ft),a(Ft,wi),a(Ze,Ei),f(e,Ps,o),f(e,pa,o),a(pa,yi),f(e,js,o),b(Vt,e,o),f(e,Ss,o),f(e,et,o),a(et,ki),a(et,Ht),a(Ht,Di),a(et,xi),f(e,Ns,o),f(e,ne,o),a(ne,Ai),a(ne,Yt),a(Yt,uo),a(uo,Pi),a(ne,ji),a(ne,co),a(co,Si),a(ne,Ni),f(e,Is,o),f(e,fa,o),a(fa,Ii),f(e,qs,o),f(e,ha,o),a(ha,qi),f(e,Ts,o),b(Wt,e,o),f(e,Cs,o),f(e,Ee,o),a(Ee,tt),a(tt,mo),b(Jt,mo,null),a(Ee,Ti),a(Ee,_o),a(_o,Ci),f(e,Rs,o),f(e,ae,o),a(ae,Ri),a(ae,ua),a(ua,Ui),a(ae,Oi),a(ae,go),a(go,Mi),a(ae,Li),a(ae,$o),a($o,zi),a(ae,Gi),f(e,Us,o),f(e,at,o),a(at,Bi),a(at,vo),a(vo,bo),a(bo,Fi),a(at,Vi),f(e,Os,o),b(Kt,e,o),f(e,Ms,o),f(e,ot,o),a(ot,Hi),a(ot,ca),a(ca,Yi),a(ot,Wi),Ls=!0},p(e,[o]){const Qt={};o&2&&(Qt.$$scope={dirty:o,ctx:e}),Pe.$set(Qt);const wo={};o&2&&(wo.$$scope={dirty:o,ctx:e}),je.$set(wo);const Eo={};o&2&&(Eo.$$scope={dirty:o,ctx:e}),qe.$set(Eo);const yo={};o&2&&(yo.$$scope={dirty:o,ctx:e}),Ce.$set(yo);const ma={};o&2&&(ma.$$scope={dirty:o,ctx:e}),Re.$set(ma)},i(e){Ls||(w(j.$$.fragment,e),w(U.$$.fragment,e),w(pt.$$.fragment,e),w(ht.$$.fragment,e),w(ut.$$.fragment,e),w(ct.$$.fragment,e),w(_t.$$.fragment,e),w(dt.$$.fragment,e),w(Pe.$$.fragment,e),w(je.$$.fragment,e),w(gt.$$.fragment,e),w(qe.$$.fragment,e),w(vt.$$.fragment,e),w(Ce.$$.fragment,e),w(Re.$$.fragment,e),w(wt.$$.fragment,e),w(Et.$$.fragment,e),w(yt.$$.fragment,e),w(kt.$$.fragment,e),w(Dt.$$.fragment,e),w(xt.$$.fragment,e),w(At.$$.fragment,e),w(Pt.$$.fragment,e),w(jt.$$.fragment,e),w(St.$$.fragment,e),w(qt.$$.fragment,e),w(Tt.$$.fragment,e),w(Rt.$$.fragment,e),w(Ut.$$.fragment,e),w(Mt.$$.fragment,e),w(Lt.$$.fragment,e),w(zt.$$.fragment,e),w(Gt.$$.fragment,e),w(Bt.$$.fragment,e),w(Vt.$$.fragment,e),w(Wt.$$.fragment,e),w(Jt.$$.fragment,e),w(Kt.$$.fragment,e),Ls=!0)},o(e){E(j.$$.fragment,e),E(U.$$.fragment,e),E(pt.$$.fragment,e),E(ht.$$.fragment,e),E(ut.$$.fragment,e),E(ct.$$.fragment,e),E(_t.$$.fragment,e),E(dt.$$.fragment,e),E(Pe.$$.fragment,e),E(je.$$.fragment,e),E(gt.$$.fragment,e),E(qe.$$.fragment,e),E(vt.$$.fragment,e),E(Ce.$$.fragment,e),E(Re.$$.fragment,e),E(wt.$$.fragment,e),E(Et.$$.fragment,e),E(yt.$$.fragment,e),E(kt.$$.fragment,e),E(Dt.$$.fragment,e),E(xt.$$.fragment,e),E(At.$$.fragment,e),E(Pt.$$.fragment,e),E(jt.$$.fragment,e),E(St.$$.fragment,e),E(qt.$$.fragment,e),E(Tt.$$.fragment,e),E(Rt.$$.fragment,e),E(Ut.$$.fragment,e),E(Mt.$$.fragment,e),E(Lt.$$.fragment,e),E(zt.$$.fragment,e),E(Gt.$$.fragment,e),E(Bt.$$.fragment,e),E(Vt.$$.fragment,e),E(Wt.$$.fragment,e),E(Jt.$$.fragment,e),E(Kt.$$.fragment,e),Ls=!1},d(e){t(h),e&&t(d),e&&t(p),y(j),e&&t(R),y(U,e),e&&t(N),e&&t(O),e&&t(L),e&&t(I),e&&t(G),e&&t(B),e&&t(_),e&&t(k),e&&t(ko),e&&t(ye),e&&t(Do),y(pt,e),e&&t(xo),e&&t(ke),e&&t(Ao),e&&t(De),e&&t(Po),y(ht,e),e&&t(jo),e&&t(ea),e&&t(So),y(ut,e),e&&t(No),e&&t(ta),e&&t(Io),y(ct,e),e&&t(qo),e&&t(xe),e&&t(To),y(_t,e),e&&t(Co),e&&t(pe),y(dt),e&&t(Ro),y(Pe,e),e&&t(Uo),y(je,e),e&&t(Oo),e&&t(fe),y(gt),e&&t(Mo),e&&t(Ne),e&&t(Lo),e&&t(Ie),e&&t(zo),y(qe,e),e&&t(Go),e&&t(he),y(vt),e&&t(Bo),e&&t(X),e&&t(Fo),y(Ce,e),e&&t(Vo),e&&t(Z),e&&t(Ho),y(Re,e),e&&t(Yo),e&&t(ue),y(wt),e&&t(Wo),e&&t(Oe),e&&t(Jo),e&&t(ce),y(Et),e&&t(Ko),e&&t(oa),e&&t(Qo),y(yt,e),e&&t(Xo),e&&t(ee),e&&t(Zo),e&&t(me),y(kt),e&&t(es),e&&t(re),e&&t(ts),y(Dt,e),e&&t(as),e&&t(sa),e&&t(os),e&&t(_e),y(xt),e&&t(ss),e&&t(ra),e&&t(rs),e&&t(Ge),e&&t(ns),y(At,e),e&&t(is),e&&t(Be),e&&t(ls),y(Pt,e),e&&t(ps),e&&t(de),y(jt),e&&t(fs),e&&t(na),e&&t(hs),e&&t(ge),y(St),e&&t(us),e&&t(se),e&&t(cs),y(qt,e),e&&t(ms),e&&t(la),e&&t(_s),e&&t($e),y(Tt),e&&t(ds),e&&t(te),e&&t(gs),y(Rt,e),e&&t($s),e&&t(ve),y(Ut),e&&t(vs),e&&t(We),e&&t(bs),y(Mt,e),e&&t(ws),e&&t(Je),e&&t(Es),y(Lt,e),e&&t(ys),e&&t(be),y(zt),e&&t(ks),e&&t(Qe),e&&t(Ds),y(Gt,e),e&&t(xs),e&&t(we),y(Bt),e&&t(As),e&&t(Ze),e&&t(Ps),e&&t(pa),e&&t(js),y(Vt,e),e&&t(Ss),e&&t(et),e&&t(Ns),e&&t(ne),e&&t(Is),e&&t(fa),e&&t(qs),e&&t(ha),e&&t(Ts),y(Wt,e),e&&t(Cs),e&&t(Ee),y(Jt),e&&t(Rs),e&&t(ae),e&&t(Us),e&&t(at),e&&t(Os),y(Kt,e),e&&t(Ms),e&&t(ot)}}}const cf={local:"dreambooth",sections:[{local:"finetuning",title:"Finetuning"},{local:"finetuning-with-priorpreserving-loss",title:"Finetuning with prior-preserving loss"},{local:"finetuning-the-text-encoder-and-unet",title:"Finetuning the text encoder and UNet"},{local:"finetuning-with-lora",title:"Finetuning with LoRA"},{local:"saving-checkpoints-while-training",sections:[{local:"resume-training-from-a-saved-checkpoint",title:"Resume training from a saved checkpoint"},{local:"inference-from-a-saved-checkpoint",title:"Inference from a saved checkpoint"}],title:"Saving checkpoints while training"},{local:"optimizations-for-different-gpu-sizes",sections:[{local:"xformers",title:"xFormers"},{local:"set-gradients-to-none",title:"Set gradients to none"},{local:"16gb-gpu",title:"16GB GPU"},{local:"12gb-gpu",title:"12GB GPU"},{local:"8-gb-gpu",title:"8 GB GPU"}],title:"Optimizations for different GPU sizes"},{local:"inference",title:"Inference"}],title:"DreamBooth"};function mf(A){return Jp(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class wf extends Fp{constructor(h){super();Vp(this,h,mf,uf,Hp,{})}}export{wf as default,cf as metadata};
