import{S as Od,i as Kd,s as em,e as a,k as c,w,t as r,M as tm,c as s,d as t,m as u,a as o,x as y,h as i,b as f,N as lm,G as l,g as p,y as U,q as b,o as _,B as T,v as am,L as Xa}from"../../chunks/vendor-hf-doc-builder.js";import{T as Pd}from"../../chunks/Tip-hf-doc-builder.js";import{I as N}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{C as I}from"../../chunks/CodeBlock-hf-doc-builder.js";import{F as sc,M as Za}from"../../chunks/Markdown-hf-doc-builder.js";function sm(R){let d,M,h,J,v;return{c(){d=a("p"),M=r("DreamBooth finetuning is very sensitive to hyperparameters and easy to overfit. We recommend you take a look at our "),h=a("a"),J=r("in-depth analysis"),v=r(" with recommended settings for different subjects to help you choose the appropriate hyperparameters."),this.h()},l($){d=s($,"P",{});var E=o(d);M=i(E,"DreamBooth finetuning is very sensitive to hyperparameters and easy to overfit. We recommend you take a look at our "),h=s(E,"A",{href:!0,rel:!0});var C=o(h);J=i(C,"in-depth analysis"),C.forEach(t),v=i(E," with recommended settings for different subjects to help you choose the appropriate hyperparameters."),E.forEach(t),this.h()},h(){f(h,"href","https://huggingface.co/blog/dreambooth"),f(h,"rel","nofollow")},m($,E){p($,d,E),l(d,M),l(d,h),l(h,J),l(d,v)},d($){$&&t(d)}}}function om(R){let d,M,h,J,v,$,E,C,x,A,S,j,de,O,Q,Y,F,oe,ne,k,K,z,ee,te,V,L,B,le,W,H,D,ae,G,q;return V=new I({props:{code:"ZXhwb3J0JTIwTU9ERUxfTkFNRSUzRCUyMkNvbXBWaXMlMkZzdGFibGUtZGlmZnVzaW9uLXYxLTQlMjIlMEFleHBvcnQlMjBJTlNUQU5DRV9ESVIlM0QlMjIuJTJGZG9nJTIyJTBBZXhwb3J0JTIwT1VUUFVUX0RJUiUzRCUyMnBhdGhfdG9fc2F2ZWRfbW9kZWwlMjI=",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>`}}),G=new I({props:{code:"YWNjZWxlcmF0ZSUyMGxhdW5jaCUyMHRyYWluX2RyZWFtYm9vdGgucHklMjAlNUMlMEElMjAlMjAtLXByZXRyYWluZWRfbW9kZWxfbmFtZV9vcl9wYXRoJTNEJTI0TU9ERUxfTkFNRSUyMCUyMCU1QyUwQSUyMCUyMC0taW5zdGFuY2VfZGF0YV9kaXIlM0QlMjRJTlNUQU5DRV9ESVIlMjAlNUMlMEElMjAlMjAtLW91dHB1dF9kaXIlM0QlMjRPVVRQVVRfRElSJTIwJTVDJTBBJTIwJTIwLS1pbnN0YW5jZV9wcm9tcHQlM0QlMjJhJTIwcGhvdG8lMjBvZiUyMHNrcyUyMGRvZyUyMiUyMCU1QyUwQSUyMCUyMC0tcmVzb2x1dGlvbiUzRDUxMiUyMCU1QyUwQSUyMCUyMC0tdHJhaW5fYmF0Y2hfc2l6ZSUzRDElMjAlNUMlMEElMjAlMjAtLWdyYWRpZW50X2FjY3VtdWxhdGlvbl9zdGVwcyUzRDElMjAlNUMlMEElMjAlMjAtLWxlYXJuaW5nX3JhdGUlM0Q1ZS02JTIwJTVDJTBBJTIwJTIwLS1scl9zY2hlZHVsZXIlM0QlMjJjb25zdGFudCUyMiUyMCU1QyUwQSUyMCUyMC0tbHJfd2FybXVwX3N0ZXBzJTNEMCUyMCU1QyUwQSUyMCUyMC0tbWF4X3RyYWluX3N0ZXBzJTNENDAwJTIwJTVDJTBBJTIwJTIwLS1wdXNoX3RvX2h1Yg==",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 \\
  --push_to_hub`}}),{c(){d=a("p"),M=r("Set the "),h=a("code"),J=r("INSTANCE_DIR"),v=r(" environment variable to the path of the directory containing the dog images."),$=c(),E=a("p"),C=r("Specify the "),x=a("code"),A=r("MODEL_NAME"),S=r(" environment variable (either a Hub model repository id or a path to the directory containing the model weights) and pass it to the "),j=a("code"),de=r("pretrained_model_name_or_path"),O=r(" argument. The "),Q=a("code"),Y=r("instance_prompt"),F=r(" argument is a text prompt that contains a unique identifier, such as "),oe=a("code"),ne=r("sks"),k=r(", and the class the image belongs to, which in this example is "),K=a("code"),z=r("a photo of a sks dog"),ee=r("."),te=c(),w(V.$$.fragment),L=c(),B=a("p"),le=r("Then you can launch the training script (you can find the full training script "),W=a("a"),H=r("here"),D=r(") with the following command:"),ae=c(),w(G.$$.fragment),this.h()},l(m){d=s(m,"P",{});var g=o(d);M=i(g,"Set the "),h=s(g,"CODE",{});var me=o(h);J=i(me,"INSTANCE_DIR"),me.forEach(t),v=i(g," environment variable to the path of the directory containing the dog images."),g.forEach(t),$=u(m),E=s(m,"P",{});var X=o(E);C=i(X,"Specify the "),x=s(X,"CODE",{});var Z=o(x);A=i(Z,"MODEL_NAME"),Z.forEach(t),S=i(X," environment variable (either a Hub model repository id or a path to the directory containing the model weights) and pass it to the "),j=s(X,"CODE",{});var ye=o(j);de=i(ye,"pretrained_model_name_or_path"),ye.forEach(t),O=i(X," argument. The "),Q=s(X,"CODE",{});var se=o(Q);Y=i(se,"instance_prompt"),se.forEach(t),F=i(X," argument is a text prompt that contains a unique identifier, such as "),oe=s(X,"CODE",{});var Ue=o(oe);ne=i(Ue,"sks"),Ue.forEach(t),k=i(X,", and the class the image belongs to, which in this example is "),K=s(X,"CODE",{});var P=o(K);z=i(P,"a photo of a sks dog"),P.forEach(t),ee=i(X,"."),X.forEach(t),te=u(m),y(V.$$.fragment,m),L=u(m),B=s(m,"P",{});var Me=o(B);le=i(Me,"Then you can launch the training script (you can find the full training script "),W=s(Me,"A",{href:!0,rel:!0});var re=o(W);H=i(re,"here"),re.forEach(t),D=i(Me,") with the following command:"),Me.forEach(t),ae=u(m),y(G.$$.fragment,m),this.h()},h(){f(W,"href","https://github.com/huggingface/diffusers/blob/main/examples/dreambooth/train_dreambooth.py"),f(W,"rel","nofollow")},m(m,g){p(m,d,g),l(d,M),l(d,h),l(h,J),l(d,v),p(m,$,g),p(m,E,g),l(E,C),l(E,x),l(x,A),l(E,S),l(E,j),l(j,de),l(E,O),l(E,Q),l(Q,Y),l(E,F),l(E,oe),l(oe,ne),l(E,k),l(E,K),l(K,z),l(E,ee),p(m,te,g),U(V,m,g),p(m,L,g),p(m,B,g),l(B,le),l(B,W),l(W,H),l(B,D),p(m,ae,g),U(G,m,g),q=!0},p:Xa,i(m){q||(b(V.$$.fragment,m),b(G.$$.fragment,m),q=!0)},o(m){_(V.$$.fragment,m),_(G.$$.fragment,m),q=!1},d(m){m&&t(d),m&&t($),m&&t(E),m&&t(te),T(V,m),m&&t(L),m&&t(B),m&&t(ae),T(G,m)}}}function nm(R){let d,M;return d=new Za({props:{$$slots:{default:[om]},$$scope:{ctx:R}}}),{c(){w(d.$$.fragment)},l(h){y(d.$$.fragment,h)},m(h,J){U(d,h,J),M=!0},p(h,J){const v={};J&2&&(v.$$scope={dirty:J,ctx:h}),d.$set(v)},i(h){M||(b(d.$$.fragment,h),M=!0)},o(h){_(d.$$.fragment,h),M=!1},d(h){T(d,h)}}}function rm(R){let d,M,h,J,v,$,E,C,x,A,S,j,de,O,Q,Y,F,oe,ne,k,K,z,ee,te,V,L,B,le,W,H,D,ae,G,q;return A=new I({props:{code:"cGlwJTIwaW5zdGFsbCUyMC1VJTIwLXIlMjByZXF1aXJlbWVudHMudHh0",highlighted:"pip install -U -r requirements.txt"}}),G=new I({props:{code:"ZXhwb3J0JTIwTU9ERUxfTkFNRSUzRCUyMmR1b25nbmElMkZzdGFibGUtZGlmZnVzaW9uLXYxLTQtZmxheCUyMiUwQWV4cG9ydCUyMElOU1RBTkNFX0RJUiUzRCUyMi4lMkZkb2clMjIlMEFleHBvcnQlMjBPVVRQVVRfRElSJTNEJTIycGF0aC10by1zYXZlLW1vZGVsJTIyJTBBJTBBcHl0aG9uJTIwdHJhaW5fZHJlYW1ib290aF9mbGF4LnB5JTIwJTVDJTBBJTIwJTIwLS1wcmV0cmFpbmVkX21vZGVsX25hbWVfb3JfcGF0aCUzRCUyNE1PREVMX05BTUUlMjAlMjAlNUMlMEElMjAlMjAtLWluc3RhbmNlX2RhdGFfZGlyJTNEJTI0SU5TVEFOQ0VfRElSJTIwJTVDJTBBJTIwJTIwLS1vdXRwdXRfZGlyJTNEJTI0T1VUUFVUX0RJUiUyMCU1QyUwQSUyMCUyMC0taW5zdGFuY2VfcHJvbXB0JTNEJTIyYSUyMHBob3RvJTIwb2YlMjBza3MlMjBkb2clMjIlMjAlNUMlMEElMjAlMjAtLXJlc29sdXRpb24lM0Q1MTIlMjAlNUMlMEElMjAlMjAtLXRyYWluX2JhdGNoX3NpemUlM0QxJTIwJTVDJTBBJTIwJTIwLS1sZWFybmluZ19yYXRlJTNENWUtNiUyMCU1QyUwQSUyMCUyMC0tbWF4X3RyYWluX3N0ZXBzJTNENDAwJTIwJTVDJTBBJTIwJTIwLS1wdXNoX3RvX2h1Yg==",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 \\
  --push_to_hub`}}),{c(){d=a("p"),M=r("If you have access to TPUs or want to train even faster, you can try out the "),h=a("a"),J=r("Flax training script"),v=r(". The Flax training script doesn\u2019t support gradient checkpointing or gradient accumulation, so you\u2019ll need a GPU with at least 30GB of memory."),$=c(),E=a("p"),C=r("Before running the script, make sure you have the requirements installed:"),x=c(),w(A.$$.fragment),S=c(),j=a("p"),de=r("Specify the "),O=a("code"),Q=r("MODEL_NAME"),Y=r(" environment variable (either a Hub model repository id or a path to the directory containing the model weights) and pass it to the "),F=a("code"),oe=r("pretrained_model_name_or_path"),ne=r(" argument. The "),k=a("code"),K=r("instance_prompt"),z=r(" argument is a text prompt that contains a unique identifier, such as "),ee=a("code"),te=r("sks"),V=r(", and the class the image belongs to, which in this example is "),L=a("code"),B=r("a photo of a sks dog"),le=r("."),W=c(),H=a("p"),D=r("Now you can launch the training script with the following command:"),ae=c(),w(G.$$.fragment),this.h()},l(m){d=s(m,"P",{});var g=o(d);M=i(g,"If you have access to TPUs or want to train even faster, you can try out the "),h=s(g,"A",{href:!0,rel:!0});var me=o(h);J=i(me,"Flax training script"),me.forEach(t),v=i(g,". The Flax training script doesn\u2019t support gradient checkpointing or gradient accumulation, so you\u2019ll need a GPU with at least 30GB of memory."),g.forEach(t),$=u(m),E=s(m,"P",{});var X=o(E);C=i(X,"Before running the script, make sure you have the requirements installed:"),X.forEach(t),x=u(m),y(A.$$.fragment,m),S=u(m),j=s(m,"P",{});var Z=o(j);de=i(Z,"Specify the "),O=s(Z,"CODE",{});var ye=o(O);Q=i(ye,"MODEL_NAME"),ye.forEach(t),Y=i(Z," environment variable (either a Hub model repository id or a path to the directory containing the model weights) and pass it to the "),F=s(Z,"CODE",{});var se=o(F);oe=i(se,"pretrained_model_name_or_path"),se.forEach(t),ne=i(Z," argument. The "),k=s(Z,"CODE",{});var Ue=o(k);K=i(Ue,"instance_prompt"),Ue.forEach(t),z=i(Z," argument is a text prompt that contains a unique identifier, such as "),ee=s(Z,"CODE",{});var P=o(ee);te=i(P,"sks"),P.forEach(t),V=i(Z,", and the class the image belongs to, which in this example is "),L=s(Z,"CODE",{});var Me=o(L);B=i(Me,"a photo of a sks dog"),Me.forEach(t),le=i(Z,"."),Z.forEach(t),W=u(m),H=s(m,"P",{});var re=o(H);D=i(re,"Now you can launch the training script with the following command:"),re.forEach(t),ae=u(m),y(G.$$.fragment,m),this.h()},h(){f(h,"href","https://github.com/huggingface/diffusers/blob/main/examples/dreambooth/train_dreambooth_flax.py"),f(h,"rel","nofollow")},m(m,g){p(m,d,g),l(d,M),l(d,h),l(h,J),l(d,v),p(m,$,g),p(m,E,g),l(E,C),p(m,x,g),U(A,m,g),p(m,S,g),p(m,j,g),l(j,de),l(j,O),l(O,Q),l(j,Y),l(j,F),l(F,oe),l(j,ne),l(j,k),l(k,K),l(j,z),l(j,ee),l(ee,te),l(j,V),l(j,L),l(L,B),l(j,le),p(m,W,g),p(m,H,g),l(H,D),p(m,ae,g),U(G,m,g),q=!0},p:Xa,i(m){q||(b(A.$$.fragment,m),b(G.$$.fragment,m),q=!0)},o(m){_(A.$$.fragment,m),_(G.$$.fragment,m),q=!1},d(m){m&&t(d),m&&t($),m&&t(E),m&&t(x),T(A,m),m&&t(S),m&&t(j),m&&t(W),m&&t(H),m&&t(ae),T(G,m)}}}function im(R){let d,M;return d=new Za({props:{$$slots:{default:[rm]},$$scope:{ctx:R}}}),{c(){w(d.$$.fragment)},l(h){y(d.$$.fragment,h)},m(h,J){U(d,h,J),M=!0},p(h,J){const v={};J&2&&(v.$$scope={dirty:J,ctx:h}),d.$set(v)},i(h){M||(b(d.$$.fragment,h),M=!0)},o(h){_(d.$$.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TNEMSUyMCU1QyUwQSUyMCUyMC0tbGVhcm5pbmdfcmF0ZSUzRDVlLTYlMjAlNUMlMEElMjAlMjAtLWxyX3NjaGVkdWxlciUzRCUyMmNvbnN0YW50JTIyJTIwJTVDJTBBJTIwJTIwLS1scl93YXJtdXBfc3RlcHMlM0QwJTIwJTVDJTBBJTIwJTIwLS1udW1fY2xhc3NfaW1hZ2VzJTNEMjAwJTIwJTVDJTBBJTIwJTIwLS1tYXhfdHJhaW5fc3RlcHMlM0Q4MDAlMjAlNUMlMEElMjAlMjAtLXB1c2hfdG9faHVi",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 \\
  --push_to_hub`}}),{c(){w(d.$$.fragment)},l(h){y(d.$$.fragment,h)},m(h,J){U(d,h,J),M=!0},p:Xa,i(h){M||(b(d.$$.fragment,h),M=!0)},o(h){_(d.$$.fragment,h),M=!1},d(h){T(d,h)}}}function hm(R){let d,M;return d=new Za({props:{$$slots:{default:[pm]},$$scope:{ctx:R}}}),{c(){w(d.$$.fragment)},l(h){y(d.$$.fragment,h)},m(h,J){U(d,h,J),M=!0},p(h,J){const v={};J&2&&(v.$$scope={dirty:J,ctx:h}),d.$set(v)},i(h){M||(b(d.$$.fragment,h),M=!0)},o(h){_(d.$$.fragment,h),M=!1},d(h){T(d,h)}}}function fm(R){let d,M;return d=new I({props:{code:"ZXhwb3J0JTIwTU9ERUxfTkFNRSUzRCUyMmR1b25nbmElMkZzdGFibGUtZGlmZnVzaW9uLXYxLTQtZmxheCUyMiUwQWV4cG9ydCUyMElOU1RBTkNFX0RJUiUzRCUyMi4lMkZkb2clMjIlMEFleHBvcnQlMjBDTEFTU19ESVIlM0QlMjJwYXRoLXRvLWNsYXNzLWltYWdlcyUyMiUwQWV4cG9ydCUyME9VVFBVVF9ESVIlM0QlMjJwYXRoLXRvLXNhdmUtbW9kZWwlMjIlMEElMEFweXRob24lMjB0cmFpbl9kcmVhbWJvb3RoX2ZsYXgucHklMjAlNUMlMEElMjAlMjAtLXByZXRyYWluZWRfbW9kZWxfbmFtZV9vcl9wYXRoJTNEJTI0TU9ERUxfTkFNRSUyMCUyMCU1QyUwQSUyMCUyMC0taW5zdGFuY2VfZGF0YV9kaXIlM0QlMjRJTlNUQU5DRV9ESVIlMjAlNUMlMEElMjAlMjAtLWNsYXNzX2RhdGFfZGlyJTNEJTI0Q0xBU1NfRElSJTIwJTVDJTBBJTIwJTIwLS1vdXRwdXRfZGlyJTNEJTI0T1VUUFVUX0RJUiUyMCU1QyUwQSUyMCUyMC0td2l0aF9wcmlvcl9wcmVzZXJ2YXRpb24lMjAtLXByaW9yX2xvc3Nfd2VpZ2h0JTNEMS4wJTIwJTVDJTBBJTIwJTIwLS1pbnN0YW5jZV9wcm9tcHQlM0QlMjJhJTIwcGhvdG8lMjBvZiUyMHNrcyUyMGRvZyUyMiUyMCU1QyUwQSUyMCUyMC0tY2xhc3NfcHJvbXB0JTNEJTIyYSUyMHBob3RvJTIwb2YlMjBkb2clMjIlMjAlNUMlMEElMjAlMjAtLXJlc29sdXRpb24lM0Q1MTIlMjAlNUMlMEElMjAlMjAtLXRyYWluX2JhdGNoX3NpemUlM0QxJTIwJTVDJTBBJTIwJTIwLS1sZWFybmluZ19yYXRlJTNENWUtNiUyMCU1QyUwQSUyMCUyMC0tbnVtX2NsYXNzX2ltYWdlcyUzRDIwMCUyMCU1QyUwQSUyMCUyMC0tbWF4X3RyYWluX3N0ZXBzJTNEODAwJTIwJTVDJTBBJTIwJTIwLS1wdXNoX3RvX2h1Yg==",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 \\
  --push_to_hub`}}),{c(){w(d.$$.fragment)},l(h){y(d.$$.fragment,h)},m(h,J){U(d,h,J),M=!0},p:Xa,i(h){M||(b(d.$$.fragment,h),M=!0)},o(h){_(d.$$.fragment,h),M=!1},d(h){T(d,h)}}}function cm(R){let d,M;return d=new Za({props:{$$slots:{default:[fm]},$$scope:{ctx:R}}}),{c(){w(d.$$.fragment)},l(h){y(d.$$.fragment,h)},m(h,J){U(d,h,J),M=!0},p(h,J){const v={};J&2&&(v.$$scope={dirty:J,ctx:h}),d.$set(v)},i(h){M||(b(d.$$.fragment,h),M=!0)},o(h){_(d.$$.fragment,h),M=!1},d(h){T(d,h)}}}function um(R){let d,M;return{c(){d=a("p"),M=r("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(h){d=s(h,"P",{});var J=o(d);M=i(J,"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."),J.forEach(t)},m(h,J){p(h,d,J),l(d,M)},d(h){h&&t(d)}}}function dm(R){let d,M;return d=new I({props:{code:"ZXhwb3J0JTIwTU9ERUxfTkFNRSUzRCUyMkNvbXBWaXMlMkZzdGFibGUtZGlmZnVzaW9uLXYxLTQlMjIlMEFleHBvcnQlMjBJTlNUQU5DRV9ESVIlM0QlMjIuJTJGZG9nJTIyJTBBZXhwb3J0JTIwQ0xBU1NfRElSJTNEJTIycGF0aF90b19jbGFzc19pbWFnZXMlMjIlMEFleHBvcnQlMjBPVVRQVVRfRElSJTNEJTIycGF0aF90b19zYXZlZF9tb2RlbCUyMiUwQSUwQWFjY2VsZXJhdGUlMjBsYXVuY2glMjB0cmFpbl9kcmVhbWJvb3RoLnB5JTIwJTVDJTBBJTIwJTIwLS1wcmV0cmFpbmVkX21vZGVsX25hbWVfb3JfcGF0aCUzRCUyNE1PREVMX05BTUUlMjAlMjAlNUMlMEElMjAlMjAtLXRyYWluX3RleHRfZW5jb2RlciUyMCU1QyUwQSUyMCUyMC0taW5zdGFuY2VfZGF0YV9kaXIlM0QlMjRJTlNUQU5DRV9ESVIlMjAlNUMlMEElMjAlMjAtLWNsYXNzX2RhdGFfZGlyJTNEJTI0Q0xBU1NfRElSJTIwJTVDJTBBJTIwJTIwLS1vdXRwdXRfZGlyJTNEJTI0T1VUUFVUX0RJUiUyMCU1QyUwQSUyMCUyMC0td2l0aF9wcmlvcl9wcmVzZXJ2YXRpb24lMjAtLXByaW9yX2xvc3Nfd2VpZ2h0JTNEMS4wJTIwJTVDJTBBJTIwJTIwLS1pbnN0YW5jZV9wcm9tcHQlM0QlMjJhJTIwcGhvdG8lMjBvZiUyMHNrcyUyMGRvZyUyMiUyMCU1QyUwQSUyMCUyMC0tY2xhc3NfcHJvbXB0JTNEJTIyYSUyMHBob3RvJTIwb2YlMjBkb2clMjIlMjAlNUMlMEElMjAlMjAtLXJlc29sdXRpb24lM0Q1MTIlMjAlNUMlMEElMjAlMjAtLXRyYWluX2JhdGNoX3NpemUlM0QxJTIwJTVDJTBBJTIwJTIwLS11c2VfOGJpdF9hZGFtJTIwJTVDJTBBJTIwJTIwLS1ncmFkaWVudF9jaGVja3BvaW50aW5nJTIwJTVDJTBBJTIwJTIwLS1sZWFybmluZ19yYXRlJTNEMmUtNiUyMCU1QyUwQSUyMCUyMC0tbHJfc2NoZWR1bGVyJTNEJTIyY29uc3RhbnQlMjIlMjAlNUMlMEElMjAlMjAtLWxyX3dhcm11cF9zdGVwcyUzRDAlMjAlNUMlMEElMjAlMjAtLW51bV9jbGFzc19pbWFnZXMlM0QyMDAlMjAlNUMlMEElMjAlMjAtLW1heF90cmFpbl9zdGVwcyUzRDgwMCUyMCU1QyUwQSUyMCUyMC0tcHVzaF90b19odWI=",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 \\
  --push_to_hub`}}),{c(){w(d.$$.fragment)},l(h){y(d.$$.fragment,h)},m(h,J){U(d,h,J),M=!0},p:Xa,i(h){M||(b(d.$$.fragment,h),M=!0)},o(h){_(d.$$.fragment,h),M=!1},d(h){T(d,h)}}}function mm(R){let d,M;return d=new Za({props:{$$slots:{default:[dm]},$$scope:{ctx:R}}}),{c(){w(d.$$.fragment)},l(h){y(d.$$.fragment,h)},m(h,J){U(d,h,J),M=!0},p(h,J){const v={};J&2&&(v.$$scope={dirty:J,ctx:h}),d.$set(v)},i(h){M||(b(d.$$.fragment,h),M=!0)},o(h){_(d.$$.fragment,h),M=!1},d(h){T(d,h)}}}function Mm(R){let d,M;return d=new I({props:{code:"ZXhwb3J0JTIwTU9ERUxfTkFNRSUzRCUyMmR1b25nbmElMkZzdGFibGUtZGlmZnVzaW9uLXYxLTQtZmxheCUyMiUwQWV4cG9ydCUyMElOU1RBTkNFX0RJUiUzRCUyMi4lMkZkb2clMjIlMEFleHBvcnQlMjBDTEFTU19ESVIlM0QlMjJwYXRoLXRvLWNsYXNzLWltYWdlcyUyMi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
<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 \\
  --push_to_hub`}}),{c(){w(d.$$.fragment)},l(h){y(d.$$.fragment,h)},m(h,J){U(d,h,J),M=!0},p:Xa,i(h){M||(b(d.$$.fragment,h),M=!0)},o(h){_(d.$$.fragment,h),M=!1},d(h){T(d,h)}}}function wm(R){let d,M;return d=new Za({props:{$$slots:{default:[Mm]},$$scope:{ctx:R}}}),{c(){w(d.$$.fragment)},l(h){y(d.$$.fragment,h)},m(h,J){U(d,h,J),M=!0},p(h,J){const v={};J&2&&(v.$$scope={dirty:J,ctx:h}),d.$set(v)},i(h){M||(b(d.$$.fragment,h),M=!0)},o(h){_(d.$$.fragment,h),M=!1},d(h){T(d,h)}}}function ym(R){let d,M,h,J,v,$,E,C,x,A,S,j,de,O,Q,Y,F,oe,ne,k,K,z,ee,te,V,L,B,le,W,H,D,ae,G,q,m,g,me,X,Z,ye,se,Ue,P,Me,re,si,oi,Uo,ze,ni,Ft,ri,ii,bo,Wt,_o,na,pi,To,Dt,Jo,ra,hi,vo,xt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-U -r diffusers/examples/dreambooth/requirements.txt`}}),Wt=new I({props:{code:"YWNjZWxlcmF0ZSUyMGNvbmZpZw==",highlighted:"accelerate config"}}),Dt=new I({props:{code:"YWNjZWxlcmF0ZSUyMGNvbmZpZyUyMGRlZmF1bHQ=",highlighted:"accelerate config default"}}),xt=new I({props:{code:"ZnJvbSUyMGFjY2VsZXJhdGUudXRpbHMlMjBpbXBvcnQlMjB3cml0ZV9iYXNpY19jb25maWclMEElMEF3cml0ZV9iYXNpY19jb25maWcoKQ==",highlighted:`<span class="hljs-keyword">from</span> accelerate.utils <span class="hljs-keyword">import</span> write_basic_config

write_basic_config()`}}),Yt=new I({props:{code:"ZnJvbSUyMGh1Z2dpbmdmYWNlX2h1YiUyMGltcG9ydCUyMHNuYXBzaG90X2Rvd25sb2FkJTBBJTBBbG9jYWxfZGlyJTIwJTNEJTIwJTIyLiUyRmRvZyUyMiUwQXNuYXBzaG90X2Rvd25sb2FkKCUwQSUyMCUyMCUyMCUyMCUyMmRpZmZ1c2VycyUyRmRvZy1leGFtcGxlJTIyJTJDJTBBJTIwJTIwJTIwJTIwbG9jYWxfZGlyJTNEbG9jYWxfZGlyJTJDJTBBJTIwJTIwJTIwJTIwcmVwb190eXBlJTNEJTIyZGF0YXNldCUyMiUyQyUwQSUyMCUyMCUyMCUyMGlnbm9yZV9wYXR0ZXJucyUzRCUyMi5naXRhdHRyaWJ1dGVzJTIyJTJDJTBBKQ==",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>,
)`}}),zt=new N({}),Pe=new Pd({props:{warning:!0,$$slots:{default:[sm]},$$scope:{ctx:R}}}),Oe=new sc({props:{pytorch:!0,tensorflow:!1,jax:!0,$$slots:{jax:[im],pytorch:[nm]},$$scope:{ctx:R}}}),Lt=new N({}),lt=new sc({props:{pytorch:!0,tensorflow:!1,jax:!0,$$slots:{jax:[cm],pytorch:[hm]},$$scope:{ctx:R}}}),qt=new N({}),st=new Pd({props:{warning:!0,$$slots:{default:[um]},$$scope:{ctx:R}}}),ot=new sc({props:{pytorch:!0,tensorflow:!1,jax:!0,$$slots:{jax:[wm],pytorch:[mm]},$$scope:{ctx:R}}}),Ot=new N({}),Kt=new N({}),el=new I({props:{code:"JTIwJTIwLS1jaGVja3BvaW50aW5nX3N0ZXBzJTNENTAw",highlighted:"  --checkpointing_steps=500"}}),tl=new N({}),ll=new I({props:{code:"JTIwJTIwLS1yZXN1bWVfZnJvbV9jaGVja3BvaW50JTNEJTIyY2hlY2twb2ludC0xNTAwJTIy",highlighted:'  --resume_from_checkpoint=<span class="hljs-string">&quot;checkpoint-1500&quot;</span>'}}),al=new N({}),sl=new I({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMERpZmZ1c2lvblBpcGVsaW5lJTJDJTIwVU5ldDJEQ29uZGl0aW9uTW9kZWwlMEFmcm9tJTIwdHJhbnNmb3JtZXJzJTIwaW1wb3J0JTIwQ0xJUFRleHRNb2RlbCUwQWltcG9ydCUyMHRvcmNoJTBBJTBBJTIzJTIwTG9hZCUyMHRoZSUyMHBpcGVsaW5lJTIwd2l0aCUyMHRoZSUyMHNhbWUlMjBhcmd1bWVudHMlMjAobW9kZWwlMkMlMjByZXZpc2lvbiklMjB0aGF0JTIwd2VyZSUyMHVzZWQlMjBmb3IlMjB0cmFpbmluZyUwQW1vZGVsX2lkJTIwJTNEJTIwJTIyQ29tcFZpcyUyRnN0YWJsZS1kaWZmdXNpb24tdjEtNCUyMiUwQSUwQXVuZXQlMjAlM0QlMjBVTmV0MkRDb25kaXRpb25Nb2RlbC5mcm9tX3ByZXRyYWluZWQoJTIyJTJGc2RkYXRhJTJGZHJlYW1ib290aCUyRmRhcnVtYS12Mi0xJTJGY2hlY2twb2ludC0xMDAlMkZ1bmV0JTIyKSUwQSUwQSUyMyUyMGlmJTIweW91JTIwaGF2ZSUyMHRyYWluZWQlMjB3aXRoJTIwJTYwLS1hcmdzLnRyYWluX3RleHRfZW5jb2RlciU2MCUyMG1ha2UlMjBzdXJlJTIwdG8lMjBhbHNvJTIwbG9hZCUyMHRoZSUyMHRleHQlMjBlbmNvZGVyJTBBdGV4dF9lbmNvZGVyJTIwJTNEJTIwQ0xJUFRleHRNb2RlbC5mcm9tX3ByZXRyYWluZWQoJTIyJTJGc2RkYXRhJTJGZHJlYW1ib290aCUyRmRhcnVtYS12Mi0xJTJGY2hlY2twb2ludC0xMDAlMkZ0ZXh0X2VuY29kZXIlMjIpJTBBJTBBcGlwZWxpbmUlMjAlM0QlMjBEaWZmdXNpb25QaXBlbGluZS5mcm9tX3ByZXRyYWluZWQobW9kZWxfaWQlMkMlMjB1bmV0JTNEdW5ldCUyQyUyMHRleHRfZW5jb2RlciUzRHRleHRfZW5jb2RlciUyQyUyMGR0eXBlJTNEdG9yY2guZmxvYXQxNiklMEFwaXBlbGluZS50byglMjJjdWRhJTIyKSUwQSUwQSUyMyUyMFBlcmZvcm0lMjBpbmZlcmVuY2UlMkMlMjBvciUyMHNhdmUlMkMlMjBvciUyMHB1c2glMjB0byUyMHRoZSUyMGh1YiUwQXBpcGVsaW5lLnNhdmVfcHJldHJhaW5lZCglMjJkcmVhbWJvb3RoLXBpcGVsaW5lJTIyKQ==",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>)`}}),ol=new I({props:{code:"ZnJvbSUyMGFjY2VsZXJhdGUlMjBpbXBvcnQlMjBBY2NlbGVyYXRvciUwQWZyb20lMjBkaWZmdXNlcnMlMjBpbXBvcnQlMjBEaWZmdXNpb25QaXBlbGluZSUwQSUwQSUyMyUyMExvYWQlMjB0aGUlMjBwaXBlbGluZSUyMHdpdGglMjB0aGUlMjBzYW1lJTIwYXJndW1lbnRzJTIwKG1vZGVsJTJDJTIwcmV2aXNpb24pJTIwdGhhdCUyMHdlcmUlMjB1c2VkJTIwZm9yJTIwdHJhaW5pbmclMEFtb2RlbF9pZCUyMCUzRCUyMCUyMkNvbXBWaXMlMkZzdGFibGUtZGlmZnVzaW9uLXYxLTQlMjIlMEFwaXBlbGluZSUyMCUzRCUyMERpZmZ1c2lvblBpcGVsaW5lLmZyb21fcHJldHJhaW5lZChtb2RlbF9pZCklMEElMEFhY2NlbGVyYXRvciUyMCUzRCUyMEFjY2VsZXJhdG9yKCklMEElMEElMjMlMjBVc2UlMjB0ZXh0X2VuY29kZXIlMjBpZiUyMCU2MC0tdHJhaW5fdGV4dF9lbmNvZGVyJTYwJTIwd2FzJTIwdXNlZCUyMGZvciUyMHRoZSUyMGluaXRpYWwlMjB0cmFpbmluZyUwQXVuZXQlMkMlMjB0ZXh0X2VuY29kZXIlMjAlM0QlMjBhY2NlbGVyYXRvci5wcmVwYXJlKHBpcGVsaW5lLnVuZXQlMkMlMjBwaXBlbGluZS50ZXh0X2VuY29kZXIpJTBBJTBBJTIzJTIwUmVzdG9yZSUyMHN0YXRlJTIwZnJvbSUyMGElMjBjaGVja3BvaW50JTIwcGF0aC4lMjBZb3UlMjBoYXZlJTIwdG8lMjB1c2UlMjB0aGUlMjBhYnNvbHV0ZSUyMHBhdGglMjBoZXJlLiUwQWFjY2VsZXJhdG9yLmxvYWRfc3RhdGUoJTIyJTJGc2RkYXRhJTJGZHJlYW1ib290aCUyRmRhcnVtYS12Mi0xJTJGY2hlY2twb2ludC0xMDAlMjIpJTBBJTBBJTIzJTIwUmVidWlsZCUyMHRoZSUyMHBpcGVsaW5lJTIwd2l0aCUyMHRoZSUyMHVud3JhcHBlZCUyMG1vZGVscyUyMChhc3NpZ25tZW50JTIwdG8lMjAudW5ldCUyMGFuZCUyMC50ZXh0X2VuY29kZXIlMjBzaG91bGQlMjB3b3JrJTIwdG9vKSUwQXBpcGVsaW5lJTIwJTNEJTIwRGlmZnVzaW9uUGlwZWxpbmUuZnJvbV9wcmV0cmFpbmVkKCUwQSUyMCUyMCUyMCUyMG1vZGVsX2lkJTJDJTBBJTIwJTIwJTIwJTIwdW5ldCUzRGFjY2VsZXJhdG9yLnVud3JhcF9tb2RlbCh1bmV0KSUyQyUwQSUyMCUyMCUyMCUyMHRleHRfZW5jb2RlciUzRGFjY2VsZXJhdG9yLnVud3JhcF9tb2RlbCh0ZXh0X2VuY29kZXIpJTJDJTBBKSUwQSUwQSUyMyUyMFBlcmZvcm0lMjBpbmZlcmVuY2UlMkMlMjBvciUyMHNhdmUlMkMlMjBvciUyMHB1c2glMjB0byUyMHRoZSUyMGh1YiUwQXBpcGVsaW5lLnNhdmVfcHJldHJhaW5lZCglMjJkcmVhbWJvb3RoLXBpcGVsaW5lJTIyKQ==",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>)`}}),nl=new N({}),rl=new N({}),hl=new I({props:{code:"JTIwJTIwLS1lbmFibGVfeGZvcm1lcnNfbWVtb3J5X2VmZmljaWVudF9hdHRlbnRpb24=",highlighted:"  --enable_xformers_memory_efficient_attention"}}),fl=new N({}),ul=new I({props:{code:"JTIwJTIwLS1zZXRfZ3JhZHNfdG9fbm9uZQ==",highlighted:"  --set_grads_to_none"}}),dl=new N({}),Ml=new I({props:{code:"cGlwJTIwaW5zdGFsbCUyMGJpdHNhbmRieXRlcw==",highlighted:"pip install bitsandbytes"}}),wl=new I({props:{code:"ZXhwb3J0JTIwTU9ERUxfTkFNRSUzRCUyMkNvbXBWaXMlMkZzdGFibGUtZGlmZnVzaW9uLXYxLTQlMjIlMEFleHBvcnQlMjBJTlNUQU5DRV9ESVIlM0QlMjIuJTJGZG9nJTIyJTBBZXhwb3J0JTIwQ0xBU1NfRElSJTNEJTIycGF0aF90b19jbGFzc19pbWFnZX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JTVDJTBBJTIwJTIwLS1udW1fY2xhc3NfaW1hZ2VzJTNEMjAwJTIwJTVDJTBBJTIwJTIwLS1tYXhfdHJhaW5fc3RlcHMlM0Q4MDAlMjAlNUMlMEElMjAlMjAtLXB1c2hfdG9faHVi",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 \\
  --push_to_hub`}}),yl=new N({}),Ul=new I({props:{code:"ZXhwb3J0JTIwTU9ERUxfTkFNRSUzRCUyMkNvbXBWaXMlMkZzdGFibGUtZGlmZnVzaW9uLXYxLTQlMjIlMEFleHBvcnQlMjBJTlNUQU5DRV9ESVIlM0QlMjIuJTJGZG9nJTIyJTBBZXhwb3J0JTIwQ0xBU1NfRElSJTNEJTIycGF0aC10by1jbGFzcy1pb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19yYXRlJTNEMmUtNiUyMCU1QyUwQSUyMCUyMC0tbHJfc2NoZWR1bGVyJTNEJTIyY29uc3RhbnQlMjIlMjAlNUMlMEElMjAlMjAtLWxyX3dhcm11cF9zdGVwcyUzRDAlMjAlNUMlMEElMjAlMjAtLW51bV9jbGFzc19pbWFnZXMlM0QyMDAlMjAlNUMlMEElMjAlMjAtLW1heF90cmFpbl9zdGVwcyUzRDgwMCUyMCU1QyUwQSUyMCUyMC0tcHVzaF90b19odWI=",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 \\
  --push_to_hub`}}),bl=new N({}),Tl=new I({props:{code:"YWNjZWxlcmF0ZSUyMGNvbmZpZw==",highlighted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1bXVsYXRpb25fc3RlcHMlM0QxJTIwLS1ncmFkaWVudF9jaGVja3BvaW50aW5nJTIwJTVDJTBBJTIwJTIwLS1sZWFybmluZ19yYXRlJTNENWUtNiUyMCU1QyUwQSUyMCUyMC0tbHJfc2NoZWR1bGVyJTNEJTIyY29uc3RhbnQlMjIlMjAlNUMlMEElMjAlMjAtLWxyX3dhcm11cF9zdGVwcyUzRDAlMjAlNUMlMEElMjAlMjAtLW51bV9jbGFzc19pbWFnZXMlM0QyMDAlMjAlNUMlMEElMjAlMjAtLW1heF90cmFpbl9zdGVwcyUzRDgwMCUyMCU1QyUwQSUyMCUyMC0tbWl4ZWRfcHJlY2lzaW9uJTNEZnAxNiUyMCU1QyUwQSUyMCUyMC0tcHVzaF90b19odWI=",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 \\
  --push_to_hub`}}),El=new N({}),Il=new I({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMERpZmZ1c2lvblBpcGVsaW5lJTBBaW1wb3J0JTIwdG9yY2glMEElMEFtb2RlbF9pZCUyMCUzRCUyMCUyMnBhdGhfdG9fc2F2ZWRfbW9kZWwlMjIlMEFwaXBlJTIwJTNEJTIwRGlmZnVzaW9uUGlwZWxpbmUuZnJvbV9wcmV0cmFpbmVkKG1vZGVsX2lkJTJDJTIwdG9yY2hfZHR5cGUlM0R0b3JjaC5mbG9hdDE2KS50byglMjJjdWRhJTIyKSUwQSUwQXByb21wdCUyMCUzRCUyMCUyMkElMjBwaG90byUyMG9mJTIwc2tzJTIwZG9nJTIwaW4lMjBhJTIwYnVja2V0JTIyJTBBaW1hZ2UlMjAlM0QlMjBwaXBlKHByb21wdCUyQyUyMG51bV9pbmZlcmVuY2Vfc3RlcHMlM0Q1MCUyQyUyMGd1aWRhbmNlX3NjYWxlJTNENy41KS5pbWFnZXMlNUIwJTVEJTBBJTBBaW1hZ2Uuc2F2ZSglMjJkb2ctYnVja2V0LnBuZyUyMik=",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>)`}}),jl=new N({}),Nl=new I({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMERpZmZ1c2lvblBpcGVsaW5lJTBBJTBBcGlwZSUyMCUzRCUyMERpZmZ1c2lvblBpcGVsaW5lLmZyb21fcHJldHJhaW5lZCglMjJEZWVwRmxveWQlMkZJRi1JLVhMLXYxLjAlMjIpJTBBJTBBcGlwZS5sb2FkX2xvcmFfd2VpZ2h0cyglMjIlM0Nsb3JhJTIwd2VpZ2h0cyUyMHBhdGglM0UlMjIpJTBBJTBBJTIzJTIwVXBkYXRlJTIwc2NoZWR1bGVyJTIwY29uZmlnJTIwdG8lMjBmaXhlZCUyMHZhcmlhbmNlJTIwc2NoZWR1bGUlMEFwaXBlLnNjaGVkdWxlciUyMCUzRCUyMHBpcGUuc2NoZWR1bGVyLl9fY2xhc3NfXy5mcm9tX2NvbmZpZyhwaXBlLnNjaGVkdWxlci5jb25maWclMkMlMjB2YXJpYW5jZV90eXBlJTNEJTIyZml4ZWRfc21hbGwlMjIp",highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DiffusionPipeline

pipe = DiffusionPipeline.from_pretrained(<span class="hljs-string">&quot;DeepFloyd/IF-I-XL-v1.0&quot;</span>)

pipe.load_lora_weights(<span class="hljs-string">&quot;&lt;lora weights path&gt;&quot;</span>)

<span class="hljs-comment"># Update scheduler config to fixed variance schedule</span>
pipe.scheduler = pipe.scheduler.__class__.from_config(pipe.scheduler.config, variance_type=<span class="hljs-string">&quot;fixed_small&quot;</span>)`}}),Zl=new N({}),kl=new N({}),Cl=new I({props:{code:"ZnJvbSUyMGh1Z2dpbmdmYWNlX2h1YiUyMGltcG9ydCUyMHNuYXBzaG90X2Rvd25sb2FkJTBBJTBBbG9jYWxfZGlyJTIwJTNEJTIwJTIyLiUyRmRvZ19kb3duc2l6ZWQlMjIlMEFzbmFwc2hvdF9kb3dubG9hZCglMEElMjAlMjAlMjAlMjAlMjJkaWZmdXNlcnMlMkZkb2ctZXhhbXBsZS1kb3duc2l6ZWQlMjIlMkMlMEElMjAlMjAlMjAlMjBsb2NhbF9kaXIlM0Rsb2NhbF9kaXIlMkMlMEElMjAlMjAlMjAlMjByZXBvX3R5cGUlM0QlMjJkYXRhc2V0JTIyJTJDJTBBJTIwJTIwJTIwJTIwaWdub3JlX3BhdHRlcm5zJTNEJTIyLmdpdGF0dHJpYnV0ZXMlMjIlMkMlMEEp",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_downsized&quot;</span>
snapshot_download(
    <span class="hljs-string">&quot;diffusers/dog-example-downsized&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>,
)`}}),Al=new N({}),Sl=new I({props:{code:"ZXhwb3J0JTIwTU9ERUxfTkFNRSUzRCUyMkRlZXBGbG95ZCUyRklGLUktWEwtdjEuMCUyMiUwQWV4cG9ydCUyMElOU1RBTkNFX0RJUiUzRCUyMmRvZyUyMiUwQWV4cG9ydCUyME9VVFBVVF9ESVIlM0QlMjJkcmVhbWJvb3RoX2RvZ19sb3JhJTIyJTBBJTBBYWNjZWxlcmF0ZSUyMGxhdW5jaCUyMHRyYWluX2RyZWFtYm9vdGhfbG9yYS5weSUyMCU1QyUwQSUyMCUyMC0tcmVwb3J0X3RvJTIwd2FuZGIlMjAlNUMlMEElMjAlMjAtLXByZXRyYWluZWRfbW9kZWxfbmFtZV9vcl9wYXRoJTNEJTI0TU9ERUxfTkFNRSUyMCUyMCU1QyUwQSUyMCUyMC0taW5zdGFuY2VfZGF0YV9kaXIlM0QlMjRJTlNUQU5DRV9ESVIlMjAlNUMlMEElMjAlMjAtLW91dHB1dF9kaXIlM0QlMjRPVVRQVVRfRElSJTIwJTVDJTBBJTIwJTIwLS1pbnN0YW5jZV9wcm9tcHQlM0QlMjJhJTIwc2tzJTIwZG9nJTIyJTIwJTVDJTBBJTIwJTIwLS1yZXNvbHV0aW9uJTNENjQlMjAlNUMlMEElMjAlMjAtLXRyYWluX2JhdGNoX3NpemUlM0Q0JTIwJTVDJTBBJTIwJTIwLS1ncmFkaWVudF9hY2N1bXVsYXRpb25fc3RlcHMlM0QxJTIwJTVDJTBBJTIwJTIwLS1sZWFybmluZ19yYXRlJTNENWUtNiUyMCU1QyUwQSUyMCUyMC0tc2NhbGVfbHIlMjAlNUMlMEElMjAlMjAtLW1heF90cmFpbl9zdGVwcyUzRDEyMDAlMjAlNUMlMEElMjAlMjAtLXZhbGlkYXRpb25fcHJvbXB0JTNEJTIyYSUyMHNrcyUyMGRvZyUyMiUyMCU1QyUwQSUyMCUyMC0tdmFsaWRhdGlvbl9lcG9jaHMlM0QyNSUyMCU1QyUwQSUyMCUyMC0tY2hlY2twb2ludGluZ19zdGVwcyUzRDEwMCUyMCU1QyUwQSUyMCUyMC0tcHJlX2NvbXB1dGVfdGV4dF9lbWJlZGRpbmdzJTIwJTVDJTBBJTIwJTIwLS10b2tlbml6ZXJfbWF4X2xlbmd0aCUzRDc3JTIwJTVDJTBBJTIwJTIwLS10ZXh0X2VuY29kZXJfdXNlX2F0dGVudGlvbl9tYXNr",highlighted:`<span class="hljs-built_in">export</span> MODEL_NAME=<span class="hljs-string">&quot;DeepFloyd/IF-I-XL-v1.0&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;dreambooth_dog_lora&quot;</span>

accelerate launch train_dreambooth_lora.py \\
  --report_to wandb \\
  --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 sks dog&quot;</span> \\
  --resolution=64 \\
  --train_batch_size=4 \\
  --gradient_accumulation_steps=1 \\
  --learning_rate=5e-6 \\
  --scale_lr \\
  --max_train_steps=1200 \\
  --validation_prompt=<span class="hljs-string">&quot;a sks dog&quot;</span> \\
  --validation_epochs=25 \\
  --checkpointing_steps=100 \\
  --pre_compute_text_embeddings \\
  --tokenizer_max_length=77 \\
  --text_encoder_use_attention_mask`}}),Fl=new N({}),Yl=new I({props:{code:"ZXhwb3J0JTIwTU9ERUxfTkFNRSUzRCUyMkRlZXBGbG95ZCUyRklGLUlJLUwtdjEuMCUyMiUwQWV4cG9ydCUyMElOU1RBTkNFX0RJUiUzRCUyMmRvZyUyMiUwQWV4cG9ydCUyME9VVFBVVF9ESVIlM0QlMjJkcmVhbWJvb3RoX2RvZ191cHNjYWxlJTIyJTBBZXhwb3J0JTIwVkFMSURBVElPTl9JTUFHRVMlM0QlMjJkb2dfZG93bnNpemVkJTJGaW1hZ2VfMS5wbmclMjBkb2dfZG93bnNpemVkJTJGaW1hZ2VfMi5wbmclMjBkb2dfZG93bnNpemVkJTJGaW1hZ2VfMy5wbmclMjBkb2dfZG93bnNpemVkJTJGaW1hZ2VfNC5wbmclMjIlMEElMEFweXRob24lMjB0cmFpbl9kcmVhbWJvb3RoX2xvcmEucHklMjAlNUMlMEElMjAlMjAlMjAlMjAtLXJlcG9ydF90byUyMHdhbmRiJTIwJTVDJTBBJTIwJTIwJTIwJTIwLS1wcmV0cmFpbmVkX21vZGVsX25hbWVfb3JfcGF0aCUzRCUyNE1PREVMX05BTUUlMjAlNUMlMEElMjAlMjAlMjAlMjAtLWluc3RhbmNlX2RhdGFfZGlyJTNEJTI0SU5TVEFOQ0VfRElSJTIwJTVDJTBBJTIwJTIwJTIwJTIwLS1vdXRwdXRfZGlyJTNEJTI0T1VUUFVUX0RJUiUyMCU1QyUwQSUyMCUyMCUyMCUyMC0taW5zdGFuY2VfcHJvbXB0JTNEJTIyYSUyMHNrcyUyMGRvZyUyMiUyMCU1QyUwQSUyMCUyMCUyMCUyMC0tcmVzb2x1dGlvbiUzRDI1NiUyMCU1QyUwQSUyMCUyMCUyMCUyMC0tdHJhaW5fYmF0Y2hfc2l6ZSUzRDQlMjAlNUMlMEElMjAlMjAlMjAlMjAtLWdyYWRpZW50X2FjY3VtdWxhdGlvbl9zdGVwcyUzRDElMjAlNUMlMEElMjAlMjAlMjAlMjAtLWxlYXJuaW5nX3JhdGUlM0QxZS02JTIwJTVDJTIwJTBBJTIwJTIwJTIwJTIwLS1tYXhfdHJhaW5fc3RlcHMlM0QyMDAwJTIwJTVDJTBBJTIwJTIwJTIwJTIwLS12YWxpZGF0aW9uX3Byb21wdCUzRCUyMmElMjBza3MlMjBkb2clMjIlMjAlNUMlMEElMjAlMjAlMjAlMjAtLXZhbGlkYXRpb25fZXBvY2hzJTNEMTAwJTIwJTVDJTBBJTIwJTIwJTIwJTIwLS1jaGVja3BvaW50aW5nX3N0ZXBzJTNENTAwJTIwJTVDJTBBJTIwJTIwJTIwJTIwLS1wcmVfY29tcHV0ZV90ZXh0X2VtYmVkZGluZ3MlMjAlNUMlMEElMjAlMjAlMjAlMjAtLXRva2VuaXplcl9tYXhfbGVuZ3RoJTNENzclMjAlNUMlMEElMjAlMjAlMjAlMjAtLXRleHRfZW5jb2Rlcl91c2VfYXR0ZW50aW9uX21hc2slMjAlNUMlMEElMjAlMjAlMjAlMjAtLXZhbGlkYXRpb25faW1hZ2VzJTIwJTI0VkFMSURBVElPTl9JTUFHRVMlMjAlNUMlMEElMjAlMjAlMjAlMjAtLWNsYXNzX2xhYmVsc19jb25kaXRpb25pbmclM0R0aW1lc3RlcHM=",highlighted:`<span class="hljs-built_in">export</span> MODEL_NAME=<span class="hljs-string">&quot;DeepFloyd/IF-II-L-v1.0&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;dreambooth_dog_upscale&quot;</span>
<span class="hljs-built_in">export</span> VALIDATION_IMAGES=<span class="hljs-string">&quot;dog_downsized/image_1.png dog_downsized/image_2.png dog_downsized/image_3.png dog_downsized/image_4.png&quot;</span>

python train_dreambooth_lora.py \\
    --report_to wandb \\
    --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 sks dog&quot;</span> \\
    --resolution=256 \\
    --train_batch_size=4 \\
    --gradient_accumulation_steps=1 \\
    --learning_rate=1e-6 \\ 
    --max_train_steps=2000 \\
    --validation_prompt=<span class="hljs-string">&quot;a sks dog&quot;</span> \\
    --validation_epochs=100 \\
    --checkpointing_steps=500 \\
    --pre_compute_text_embeddings \\
    --tokenizer_max_length=77 \\
    --text_encoder_use_attention_mask \\
    --validation_images <span class="hljs-variable">$VALIDATION_IMAGES</span> \\
    --class_labels_conditioning=timesteps`}}),zl=new N({}),ql=new I({props:{code:"ZXhwb3J0JTIwTU9ERUxfTkFNRSUzRCUyMkRlZXBGbG95ZCUyRklGLUktWEwtdjEuMCUyMiUwQSUwQWV4cG9ydCUyMElOU1RBTkNFX0RJUiUzRCUyMmRvZyUyMiUwQWV4cG9ydCUyME9VVFBVVF9ESVIlM0QlMjJkcmVhbWJvb3RoX2lmJTIyJTBBJTBBYWNjZWxlcmF0ZSUyMGxhdW5jaCUyMHRyYWluX2RyZWFtYm9vdGgucHklMjAlNUMlMEElMjAlMjAtLXByZXRyYWluZWRfbW9kZWxfbmFtZV9vcl9wYXRoJTNEJTI0TU9ERUxfTkFNRSUyMCUyMCU1QyUwQSUyMCUyMC0taW5zdGFuY2VfZGF0YV9kaXIlM0QlMjRJTlNUQU5DRV9ESVIlMjAlNUMlMEElMjAlMjAtLW91dHB1dF9kaXIlM0QlMjRPVVRQVVRfRElSJTIwJTVDJTBBJTIwJTIwLS1pbnN0YW5jZV9wcm9tcHQlM0QlMjJhJTIwcGhvdG8lMjBvZiUyMHNrcyUyMGRvZyUyMiUyMCU1QyUwQSUyMCUyMC0tcmVzb2x1dGlvbiUzRDY0JTIwJTVDJTBBJTIwJTIwLS10cmFpbl9iYXRjaF9zaXplJTNENCUyMCU1QyUwQSUyMCUyMC0tZ3JhZGllbnRfYWNjdW11bGF0aW9uX3N0ZXBzJTNEMSUyMCU1QyUwQSUyMCUyMC0tbGVhcm5pbmdfcmF0ZSUzRDFlLTclMjAlNUMlMEElMjAlMjAtLW1heF90cmFpbl9zdGVwcyUzRDE1MCUyMCU1QyUwQSUyMCUyMC0tdmFsaWRhdGlvbl9wcm9tcHQlMjAlMjJhJTIwcGhvdG8lMjBvZiUyMHNrcyUyMGRvZyUyMiUyMCU1QyUwQSUyMCUyMC0tdmFsaWRhdGlvbl9zdGVwcyUyMDI1JTIwJTVDJTBBJTIwJTIwLS10ZXh0X2VuY29kZXJfdXNlX2F0dGVudGlvbl9tYXNrJTIwJTVDJTBBJTIwJTIwLS10b2tlbml6ZXJfbWF4X2xlbmd0aCUyMDc3JTIwJTVDJTBBJTIwJTIwLS1wcmVfY29tcHV0ZV90ZXh0X2VtYmVkZGluZ3MlMjAlNUMlMEElMjAlMjAtLXVzZV84Yml0X2FkYW0lMjAlNUMlMEElMjAlMjAtLXNldF9ncmFkc190b19ub25lJTIwJTVDJTBBJTIwJTIwLS1za2lwX3NhdmVfdGV4dF9lbmNvZGVyJTIwJTVDJTBBJTIwJTIwLS1wdXNoX3RvX2h1Yg==",highlighted:`<span class="hljs-built_in">export</span> MODEL_NAME=<span class="hljs-string">&quot;DeepFloyd/IF-I-XL-v1.0&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;dreambooth_if&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=64 \\
  --train_batch_size=4 \\
  --gradient_accumulation_steps=1 \\
  --learning_rate=1e-7 \\
  --max_train_steps=150 \\
  --validation_prompt <span class="hljs-string">&quot;a photo of sks dog&quot;</span> \\
  --validation_steps 25 \\
  --text_encoder_use_attention_mask \\
  --tokenizer_max_length 77 \\
  --pre_compute_text_embeddings \\
  --use_8bit_adam \\
  --set_grads_to_none \\
  --skip_save_text_encoder \\
  --push_to_hub`}}),Pl=new N({}),ea=new I({props:{code:"ZXhwb3J0JTIwTU9ERUxfTkFNRSUzRCUyMkRlZXBGbG95ZCUyRklGLUlJLUwtdjEuMCUyMiUwQWV4cG9ydCUyMElOU1RBTkNFX0RJUiUzRCUyMmRvZyUyMiUwQWV4cG9ydCUyME9VVFBVVF9ESVIlM0QlMjJkcmVhbWJvb3RoX2RvZ191cHNjYWxlJTIyJTBBZXhwb3J0JTIwVkFMSURBVElPTl9JTUFHRVMlM0QlMjJkb2dfZG93bnNpemVkJTJGaW1hZ2VfMS5wbmclMjBkb2dfZG93bnNpemVkJTJGaW1hZ2VfMi5wbmclMjBkb2dfZG93bnNpemVkJTJGaW1hZ2VfMy5wbmclMjBkb2dfZG93bnNpemVkJTJGaW1hZ2VfNC5wbmclMjIlMEElMEFhY2NlbGVyYXRlJTIwbGF1bmNoJTIwdHJhaW5fZHJlYW1ib290aC5weSUyMCU1QyUwQSUyMCUyMC0tcmVwb3J0X3RvJTIwd2FuZGIlMjAlNUMlMEElMjAlMjAtLXByZXRyYWluZWRfbW9kZWxfbmFtZV9vcl9wYXRoJTNEJTI0TU9ERUxfTkFNRSUyMCU1QyUwQSUyMCUyMC0taW5zdGFuY2VfZGF0YV9kaXIlM0QlMjRJTlNUQU5DRV9ESVIlMjAlNUMlMEElMjAlMjAtLW91dHB1dF9kaXIlM0QlMjRPVVRQVVRfRElSJTIwJTVDJTBBJTIwJTIwLS1pbnN0YW5jZV9wcm9tcHQlM0QlMjJhJTIwc2tzJTIwZG9nJTIyJTIwJTVDJTBBJTIwJTIwLS1yZXNvbHV0aW9uJTNEMjU2JTIwJTVDJTBBJTIwJTIwLS10cmFpbl9iYXRjaF9zaXplJTNEMiUyMCU1QyUwQSUyMCUyMC0tZ3JhZGllbnRfYWNjdW11bGF0aW9uX3N0ZXBzJTNENiUyMCU1QyUwQSUyMCUyMC0tbGVhcm5pbmdfcmF0ZSUzRDVlLTYlMjAlNUMlMEElMjAlMjAtLW1heF90cmFpbl9zdGVwcyUzRDIwMDAlMjAlNUMlMEElMjAlMjAtLXZhbGlkYXRpb25fcHJvbXB0JTNEJTIyYSUyMHNrcyUyMGRvZyUyMiUyMCU1QyUwQSUyMCUyMC0tdmFsaWRhdGlvbl9zdGVwcyUzRDE1MCUyMCU1QyUwQSUyMCUyMC0tY2hlY2twb2ludGluZ19zdGVwcyUzRDUwMCUyMCU1QyUwQSUyMCUyMC0tcHJlX2NvbXB1dGVfdGV4dF9lbWJlZGRpbmdzJTIwJTVDJTBBJTIwJTIwLS10b2tlbml6ZXJfbWF4X2xlbmd0aCUzRDc3JTIwJTVDJTBBJTIwJTIwLS10ZXh0X2VuY29kZXJfdXNlX2F0dGVudGlvbl9tYXNrJTIwJTVDJTBBJTIwJTIwLS12YWxpZGF0aW9uX2ltYWdlcyUyMCUyNFZBTElEQVRJT05fSU1BR0VTJTIwJTVDJTBBJTIwJTIwLS1jbGFzc19sYWJlbHNfY29uZGl0aW9uaW5nJTIwdGltZXN0ZXBzJTIwJTVDJTBBJTIwJTIwLS1wdXNoX3RvX2h1Yg==",highlighted:`<span class="hljs-built_in">export</span> MODEL_NAME=<span class="hljs-string">&quot;DeepFloyd/IF-II-L-v1.0&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;dreambooth_dog_upscale&quot;</span>
<span class="hljs-built_in">export</span> VALIDATION_IMAGES=<span class="hljs-string">&quot;dog_downsized/image_1.png dog_downsized/image_2.png dog_downsized/image_3.png dog_downsized/image_4.png&quot;</span>

accelerate launch train_dreambooth.py \\
  --report_to wandb \\
  --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 sks dog&quot;</span> \\
  --resolution=256 \\
  --train_batch_size=2 \\
  --gradient_accumulation_steps=6 \\
  --learning_rate=5e-6 \\
  --max_train_steps=2000 \\
  --validation_prompt=<span class="hljs-string">&quot;a sks dog&quot;</span> \\
  --validation_steps=150 \\
  --checkpointing_steps=500 \\
  --pre_compute_text_embeddings \\
  --tokenizer_max_length=77 \\
  --text_encoder_use_attention_mask \\
  --validation_images <span class="hljs-variable">$VALIDATION_IMAGES</span> \\
  --class_labels_conditioning timesteps \\
  --push_to_hub`}}),ta=new N({}),{c(){d=a("meta"),M=c(),h=a("h1"),J=a("a"),v=a("span"),w($.$$.fragment),E=c(),C=a("span"),x=r("DreamBooth"),A=c(),S=a("p"),j=a("a"),de=r("DreamBooth"),O=r(" 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."),Q=c(),Y=a("p"),F=a("img"),ne=c(),k=a("small"),K=r("Dreambooth examples from the "),z=a("a"),ee=r("project's blog."),te=c(),V=a("p"),L=r("This guide will show you how to finetune DreamBooth with the "),B=a("a"),le=a("code"),W=r("CompVis/stable-diffusion-v1-4"),H=r(" model for various GPU sizes, and with Flax. All the training scripts for DreamBooth used in this guide can be found "),D=a("a"),ae=r("here"),G=r(" if you\u2019re interested in digging deeper and seeing how things work."),q=c(),m=a("p"),g=r("Before running the scripts, make sure you install the library\u2019s training dependencies. We also recommend installing \u{1F9E8} Diffusers from the "),me=a("code"),X=r("main"),Z=r(" GitHub branch:"),ye=c(),w(se.$$.fragment),Ue=c(),P=a("p"),Me=r("xFormers is not part of the training requirements, but we recommend you "),re=a("a"),si=r("install"),oi=r(" it if you can because it could make your training faster and less memory intensive."),Uo=c(),ze=a("p"),ni=r("After all the dependencies have been set up, initialize a "),Ft=a("a"),ri=r("\u{1F917} Accelerate"),ii=r(" environment with:"),bo=c(),w(Wt.$$.fragment),_o=c(),na=a("p"),pi=r("To setup a default \u{1F917} Accelerate environment without choosing any configurations:"),To=c(),w(Dt.$$.fragment),Jo=c(),ra=a("p"),hi=r("Or if your environment doesn\u2019t support an interactive shell like a notebook, you can use:"),vo=c(),w(xt.$$.fragment),go=c(),Le=a("p"),fi=r("Finally, download a "),Qt=a("a"),ci=r("few images of a dog"),ui=r(" to DreamBooth with:"),Eo=c(),w(Yt.$$.fragment),Io=c(),He=a("p"),di=r("To use your own dataset, take a look at the "),ia=a("a"),mi=r("Create a dataset for training"),Mi=r(" guide."),jo=c(),Je=a("h2"),qe=a("a"),ka=a("span"),w(zt.$$.fragment),wi=c(),Ca=a("span"),yi=r("Finetuning"),Ro=c(),w(Pe.$$.fragment),$o=c(),w(Oe.$$.fragment),No=c(),ve=a("h2"),Ke=a("a"),Aa=a("span"),w(Lt.$$.fragment),Ui=c(),Sa=a("span"),bi=r("Finetuning with prior-preserving loss"),Vo=c(),et=a("p"),_i=r("Prior preservation is used to avoid overfitting and language-drift (check out the "),Ht=a("a"),Ti=r("paper"),Ji=r(" 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."),Bo=c(),tt=a("p"),vi=r("The authors recommend generating "),Fa=a("code"),gi=r("num_epochs * num_samples"),Ei=r(" images for prior preservation. In most cases, 200-300 images work well."),Go=c(),w(lt.$$.fragment),Xo=c(),ge=a("h2"),at=a("a"),Wa=a("span"),w(qt.$$.fragment),Ii=c(),Da=a("span"),ji=r("Finetuning the text encoder and UNet"),Zo=c(),ie=a("p"),Ri=r("The script also allows you to finetune the "),xa=a("code"),$i=r("text_encoder"),Ni=r(" along with the "),Qa=a("code"),Vi=r("unet"),Bi=r(". In our experiments (check out the "),Pt=a("a"),Gi=r("Training Stable Diffusion with DreamBooth using \u{1F9E8} Diffusers"),Xi=r(" post for more details), this yields much better results, especially when generating images of faces."),ko=c(),w(st.$$.fragment),Co=c(),pe=a("p"),Zi=r("Pass the "),Ya=a("code"),ki=r("--train_text_encoder"),Ci=r(" argument to the training script to enable finetuning the "),za=a("code"),Ai=r("text_encoder"),Si=r(" and "),La=a("code"),Fi=r("unet"),Wi=r(":"),Ao=c(),w(ot.$$.fragment),So=c(),Ee=a("h2"),nt=a("a"),Ha=a("span"),w(Ot.$$.fragment),Di=c(),qa=a("span"),xi=r("Finetuning with LoRA"),Fo=c(),rt=a("p"),Qi=r("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 "),pa=a("a"),Yi=r("LoRA training"),zi=r(" guide."),Wo=c(),Ie=a("h2"),it=a("a"),Pa=a("span"),w(Kt.$$.fragment),Li=c(),Oa=a("span"),Hi=r("Saving checkpoints while training"),Do=c(),ha=a("p"),qi=r("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:"),xo=c(),w(el.$$.fragment),Qo=c(),he=a("p"),Pi=r("This saves the full training state in subfolders of your "),Ka=a("code"),Oi=r("output_dir"),Ki=r(". Subfolder names begin with the prefix "),es=a("code"),ep=r("checkpoint-"),tp=r(", followed by the number of steps performed so far; for example, "),ts=a("code"),lp=r("checkpoint-1500"),ap=r(" would be a checkpoint saved after 1500 training steps."),Yo=c(),je=a("h3"),pt=a("a"),ls=a("span"),w(tl.$$.fragment),sp=c(),as=a("span"),op=r("Resume training from a saved checkpoint"),zo=c(),be=a("p"),np=r("If you want to resume training from any of the saved checkpoints, you can pass the argument "),ss=a("code"),rp=r("--resume_from_checkpoint"),ip=r(" to the script and specify the name of the checkpoint you want to use. You can also use the special string "),os=a("code"),pp=r('"latest"'),hp=r(" 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:"),Lo=c(),w(ll.$$.fragment),Ho=c(),fa=a("p"),fp=r("This is a good opportunity to tweak some of your hyperparameters if you wish."),qo=c(),Re=a("h3"),ht=a("a"),ns=a("span"),w(al.$$.fragment),cp=c(),rs=a("span"),up=r("Inference from a saved checkpoint"),Po=c(),ca=a("p"),dp=r("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."),Oo=c(),ft=a("p"),mp=r("If you have "),is=a("strong"),ps=a("code"),Mp=r('"accelerate>=0.16.0"'),wp=r(` installed, use the following code to run
inference from an intermediate checkpoint.`),Ko=c(),w(sl.$$.fragment),en=c(),ct=a("p"),yp=r("If you have "),hs=a("strong"),fs=a("code"),Up=r('"accelerate<0.16.0"'),bp=r(" installed, you need to convert it to an inference pipeline first:"),tn=c(),w(ol.$$.fragment),ln=c(),$e=a("h2"),ut=a("a"),cs=a("span"),w(nl.$$.fragment),_p=c(),us=a("span"),Tp=r("Optimizations for different GPU sizes"),an=c(),ua=a("p"),Jp=r("Depending on your hardware, there are a few different ways to optimize DreamBooth on GPUs from 16GB to just 8GB!"),sn=c(),Ne=a("h3"),dt=a("a"),ds=a("span"),w(rl.$$.fragment),vp=c(),ms=a("span"),gp=r("xFormers"),on=c(),we=a("p"),il=a("a"),Ep=r("xFormers"),Ip=r(" is a toolbox for optimizing Transformers, and it includes a "),pl=a("a"),jp=r("memory-efficient attention"),Rp=r(" mechanism that is used in \u{1F9E8} Diffusers. You\u2019ll need to "),da=a("a"),$p=r("install xFormers"),Np=r(" and then add the following argument to your training script:"),nn=c(),w(hl.$$.fragment),rn=c(),ma=a("p"),Vp=r("xFormers is not available in Flax."),pn=c(),Ve=a("h3"),mt=a("a"),Ms=a("span"),w(fl.$$.fragment),Bp=c(),ws=a("span"),Gp=r("Set gradients to none"),hn=c(),fe=a("p"),Xp=r("Another way you can lower your memory footprint is to "),cl=a("a"),Zp=r("set the gradients"),kp=r(" to "),ys=a("code"),Cp=r("None"),Ap=r(" 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 "),Us=a("code"),Sp=r("None"),Fp=r(":"),fn=c(),w(ul.$$.fragment),cn=c(),Be=a("h3"),Mt=a("a"),bs=a("span"),w(dl.$$.fragment),Wp=c(),_s=a("span"),Dp=r("16GB GPU"),un=c(),wt=a("p"),xp=r("With the help of gradient checkpointing and "),ml=a("a"),Qp=r("bitsandbytes"),Yp=r(" 8-bit optimizer, it\u2019s possible to train DreamBooth on a 16GB GPU. Make sure you have bitsandbytes installed:"),dn=c(),w(Ml.$$.fragment),mn=c(),yt=a("p"),zp=r("Then pass the "),Ts=a("code"),Lp=r("--use_8bit_adam"),Hp=r(" option to the training script:"),Mn=c(),w(wl.$$.fragment),wn=c(),Ge=a("h3"),Ut=a("a"),Js=a("span"),w(yl.$$.fragment),qp=c(),vs=a("span"),Pp=r("12GB GPU"),yn=c(),bt=a("p"),Op=r("To run DreamBooth on a 12GB GPU, you\u2019ll need to enable gradient checkpointing, the 8-bit optimizer, xFormers, and set the gradients to "),gs=a("code"),Kp=r("None"),eh=r(":"),Un=c(),w(Ul.$$.fragment),bn=c(),Xe=a("h3"),_t=a("a"),Es=a("span"),w(bl.$$.fragment),th=c(),Is=a("span"),lh=r("8 GB GPU"),_n=c(),Tt=a("p"),ah=r("For 8GB GPUs, you\u2019ll need the help of "),_l=a("a"),sh=r("DeepSpeed"),oh=r(` to offload some
tensors from the VRAM to either the CPU or NVME, enabling training with less GPU memory.`),Tn=c(),Ma=a("p"),nh=r("Run the following command to configure your \u{1F917} Accelerate environment:"),Jn=c(),w(Tl.$$.fragment),vn=c(),Jt=a("p"),rh=r("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 "),Jl=a("a"),ih=r("the DeepSpeed documentation"),ph=r(" for more configuration options."),gn=c(),_e=a("p"),hh=r(`You should also change the default Adam optimizer to DeepSpeed\u2019s optimized version of Adam
`),vl=a("a"),js=a("code"),fh=r("deepspeed.ops.adam.DeepSpeedCPUAdam"),ch=r(" for a substantial speedup. Enabling "),Rs=a("code"),uh=r("DeepSpeedCPUAdam"),dh=r(" requires your system\u2019s CUDA toolchain version to be the same as the one installed with PyTorch."),En=c(),wa=a("p"),mh=r("8-bit optimizers don\u2019t seem to be compatible with DeepSpeed at the moment."),In=c(),ya=a("p"),Mh=r("Launch training with the following command:"),jn=c(),w(gl.$$.fragment),Rn=c(),Ze=a("h2"),vt=a("a"),$s=a("span"),w(El.$$.fragment),wh=c(),Ns=a("span"),yh=r("Inference"),$n=c(),ce=a("p"),Uh=r("Once you have trained a model, specify the path to where the model is saved, and use it for inference in the "),Ua=a("a"),bh=r("StableDiffusionPipeline"),_h=r(". Make sure your prompts include the special "),Vs=a("code"),Th=r("identifier"),Jh=r(" used during training ("),Bs=a("code"),vh=r("sks"),gh=r(" in the previous examples)."),Nn=c(),gt=a("p"),Eh=r("If you have "),Gs=a("strong"),Xs=a("code"),Ih=r('"accelerate>=0.16.0"'),jh=r(` installed, you can use the following code to run
inference from an intermediate checkpoint:`),Vn=c(),w(Il.$$.fragment),Bn=c(),Et=a("p"),Rh=r("You may also run inference from any of the "),ba=a("a"),$h=r("saved training checkpoints"),Nh=r("."),Gn=c(),ke=a("h2"),It=a("a"),Zs=a("span"),w(jl.$$.fragment),Vh=c(),ks=a("span"),Bh=r("IF"),Xn=c(),Te=a("p"),Gh=r("You can use the lora and full dreambooth scripts to train the text to image "),Rl=a("a"),Xh=r("IF model"),Zh=r(` and the stage II upscaler
`),$l=a("a"),kh=r("IF model"),Ch=r("."),Zn=c(),_a=a("p"),Ah=r(`Note that IF has a predicted variance, and our finetuning scripts only train the models predicted error, so for finetuned IF models we switch to a fixed
variance schedule. The full finetuning scripts will update the scheduler config for the full saved model. However, when loading saved LoRA weights, you
must also update the pipeline\u2019s scheduler config.`),kn=c(),w(Nl.$$.fragment),Cn=c(),Ta=a("p"),Sh=r("Additionally, a few alternative cli flags are needed for IF."),An=c(),Vl=a("p"),Cs=a("code"),Fh=r("--resolution=64"),Wh=r(": IF is a pixel space diffusion model. In order to operate on un-compressed pixels, the input images are of a much smaller resolution."),Sn=c(),Ce=a("p"),As=a("code"),Dh=r("--pre_compute_text_embeddings"),xh=r(": IF uses "),Bl=a("a"),Qh=r("T5"),Yh=r(` for its text encoder. In order to save GPU memory, we pre compute all text embeddings and then de-allocate
T5.`),Fn=c(),Gl=a("p"),Ss=a("code"),zh=r("--tokenizer_max_length=77"),Lh=r(": T5 has a longer default text length, but the default IF encoding procedure uses a smaller number."),Wn=c(),Xl=a("p"),Fs=a("code"),Hh=r("--text_encoder_use_attention_mask"),qh=r(": T5 passes the attention mask to the text encoder."),Dn=c(),Ae=a("h3"),jt=a("a"),Ws=a("span"),w(Zl.$$.fragment),Ph=c(),Ds=a("span"),Oh=r("Tips and Tricks"),xn=r(`

We find LoRA to be sufficient for finetuning the stage I model as the low resolution of the model makes representing finegrained detail hard regardless.
`),Ja=a("p"),Kh=r(`For common and/or not-visually complex object concepts, you can get away with not-finetuning the upscaler. Just be sure to adjust the prompt passed to the
upscaler to remove the new token from the instance prompt. I.e. if your stage I prompt is \u201Ca sks dog\u201D, use \u201Ca dog\u201D for your stage II prompt.`),Qn=c(),va=a("p"),ef=r(`For finegrained detail like faces that aren\u2019t present in the original training set, we find that full finetuning of the stage II upscaler is better than
LoRA finetuning stage II.`),Yn=c(),ga=a("p"),tf=r("For finegrained detail like faces, we find that lower learning rates along with larger batch sizes work best."),zn=c(),Ea=a("p"),lf=r("For stage II, we find that lower learning rates are also needed."),Ln=c(),Ia=a("p"),af=r(`We found experimentally that the DDPM scheduler with the default larger number of denoising steps to sometimes work better than the DPM Solver scheduler
used in the training scripts.`),Hn=c(),Se=a("h3"),Rt=a("a"),xs=a("span"),w(kl.$$.fragment),sf=c(),Qs=a("span"),of=r("Stage II additional validation images"),qn=c(),ja=a("p"),nf=r("The stage II validation requires images to upscale, we can download a downsized version of the training set:"),Pn=c(),w(Cl.$$.fragment),On=c(),Fe=a("h3"),$t=a("a"),Ys=a("span"),w(Al.$$.fragment),rf=c(),zs=a("span"),pf=r("IF stage I LoRA Dreambooth"),Kn=r(`

This training configuration requires ~28 GB VRAM.

	`),w(Sl.$$.fragment),er=c(),We=a("h3"),Nt=a("a"),Ls=a("span"),w(Fl.$$.fragment),hf=c(),Hs=a("span"),ff=r("IF stage II LoRA Dreambooth"),tr=c(),Wl=a("p"),qs=a("code"),cf=r("--validation_images"),uf=r(": These images are upscaled during validation steps."),lr=c(),Dl=a("p"),Ps=a("code"),df=r("--class_labels_conditioning=timesteps"),mf=r(": Pass additional conditioning to the UNet needed for stage II."),ar=c(),xl=a("p"),Os=a("code"),Mf=r("--learning_rate=1e-6"),wf=r(": Lower learning rate than stage I."),sr=c(),Ql=a("p"),Ks=a("code"),yf=r("--resolution=256"),Uf=r(": The upscaler expects higher resolution inputs"),or=c(),w(Yl.$$.fragment),nr=c(),De=a("h3"),Vt=a("a"),eo=a("span"),w(zl.$$.fragment),bf=c(),to=a("span"),_f=r("IF Stage I Full Dreambooth"),rr=r(`

\`--skip_save_text_encoder\`: When training the full model, this will skip saving the entire T5 with the finetuned model. You can still load the pipeline
with a T5 loaded from the original model.
`),Ll=a("p"),lo=a("code"),Tf=r("use_8bit_adam"),Jf=r(": Due to the size of the optimizer states, we recommend training the full XL IF model with 8bit adam."),ir=c(),Hl=a("p"),ao=a("code"),vf=r("--learning_rate=1e-7"),gf=r(`: For full dreambooth, IF requires very low learning rates. With higher learning rates model quality will degrade. Note that it is
likely the learning rate can be increased with larger batch sizes.`),pr=c(),Ra=a("p"),Ef=r("Using 8bit adam and a batch size of 4, the model can be trained in ~48 GB VRAM."),hr=c(),w(ql.$$.fragment),fr=c(),xe=a("h3"),Bt=a("a"),so=a("span"),w(Pl.$$.fragment),If=c(),oo=a("span"),jf=r("IF Stage II Full Dreambooth"),cr=c(),Ol=a("p"),no=a("code"),Rf=r("--learning_rate=5e-6"),$f=r(`: With a smaller effective batch size of 4, we found that we required learning rates as low as
1e-8.`),ur=c(),Kl=a("p"),ro=a("code"),Nf=r("--resolution=256"),Vf=r(": The upscaler expects higher resolution inputs"),dr=c(),Qe=a("p"),io=a("code"),Bf=r("--train_batch_size=2"),Gf=r(" and "),po=a("code"),Xf=r("--gradient_accumulation_steps=6"),Zf=r(`: We found that full training of stage II particularly with
faces required large effective batch sizes.`),mr=c(),w(ea.$$.fragment),Mr=c(),Ye=a("h2"),Gt=a("a"),ho=a("span"),w(ta.$$.fragment),kf=c(),fo=a("span"),Cf=r("Stable Diffusion XL"),wr=c(),ue=a("p"),Af=r("We support fine-tuning of the UNet shipped in "),la=a("a"),Sf=r("Stable Diffusion XL"),Ff=r(" with DreamBooth and LoRA via the "),co=a("code"),Wf=r("train_dreambooth_lora_sdxl.py"),Df=r(" script. Please refer to the docs "),aa=a("a"),xf=r("here"),Qf=r("."),this.h()},l(e){const n=tm('[data-svelte="svelte-1phssyn"]',document.head);d=s(n,"META",{name:!0,content:!0}),n.forEach(t),M=u(e),h=s(e,"H1",{class:!0});var sa=o(h);J=s(sa,"A",{id:!0,class:!0,href:!0});var uo=o(J);v=s(uo,"SPAN",{});var mo=o(v);y($.$$.fragment,mo),mo.forEach(t),uo.forEach(t),E=u(sa),C=s(sa,"SPAN",{});var Mo=o(C);x=i(Mo,"DreamBooth"),Mo.forEach(t),sa.forEach(t),A=u(e),S=s(e,"P",{});var $a=o(S);j=s($a,"A",{href:!0,rel:!0});var oc=o(j);de=i(oc,"DreamBooth"),oc.forEach(t),O=i($a," 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."),$a.forEach(t),Q=u(e),Y=s(e,"P",{});var nc=o(Y);F=s(nc,"IMG",{src:!0,alt:!0}),nc.forEach(t),ne=u(e),k=s(e,"SMALL",{});var Yf=o(k);K=i(Yf,"Dreambooth examples from the "),z=s(Yf,"A",{href:!0});var rc=o(z);ee=i(rc,"project's blog."),rc.forEach(t),Yf.forEach(t),te=u(e),V=s(e,"P",{});var Na=o(V);L=i(Na,"This guide will show you how to finetune DreamBooth with the "),B=s(Na,"A",{href:!0,rel:!0});var ic=o(B);le=s(ic,"CODE",{});var pc=o(le);W=i(pc,"CompVis/stable-diffusion-v1-4"),pc.forEach(t),ic.forEach(t),H=i(Na," model for various GPU sizes, and with Flax. All the training scripts for DreamBooth used in this guide can be found "),D=s(Na,"A",{href:!0,rel:!0});var hc=o(D);ae=i(hc,"here"),hc.forEach(t),G=i(Na," if you\u2019re interested in digging deeper and seeing how things work."),Na.forEach(t),q=u(e),m=s(e,"P",{});var Ur=o(m);g=i(Ur,"Before running the scripts, make sure you install the library\u2019s training dependencies. We also recommend installing \u{1F9E8} Diffusers from the "),me=s(Ur,"CODE",{});var fc=o(me);X=i(fc,"main"),fc.forEach(t),Z=i(Ur," GitHub branch:"),Ur.forEach(t),ye=u(e),y(se.$$.fragment,e),Ue=u(e),P=s(e,"P",{});var br=o(P);Me=i(br,"xFormers is not part of the training requirements, but we recommend you "),re=s(br,"A",{href:!0});var cc=o(re);si=i(cc,"install"),cc.forEach(t),oi=i(br," it if you can because it could make your training faster and less memory intensive."),br.forEach(t),Uo=u(e),ze=s(e,"P",{});var _r=o(ze);ni=i(_r,"After all the dependencies have been set up, initialize a "),Ft=s(_r,"A",{href:!0,rel:!0});var uc=o(Ft);ri=i(uc,"\u{1F917} Accelerate"),uc.forEach(t),ii=i(_r," environment with:"),_r.forEach(t),bo=u(e),y(Wt.$$.fragment,e),_o=u(e),na=s(e,"P",{});var dc=o(na);pi=i(dc,"To setup a default \u{1F917} Accelerate environment without choosing any configurations:"),dc.forEach(t),To=u(e),y(Dt.$$.fragment,e),Jo=u(e),ra=s(e,"P",{});var mc=o(ra);hi=i(mc,"Or if your environment doesn\u2019t support an interactive shell like a notebook, you can use:"),mc.forEach(t),vo=u(e),y(xt.$$.fragment,e),go=u(e),Le=s(e,"P",{});var Tr=o(Le);fi=i(Tr,"Finally, download a "),Qt=s(Tr,"A",{href:!0,rel:!0});var Mc=o(Qt);ci=i(Mc,"few images of a dog"),Mc.forEach(t),ui=i(Tr," to DreamBooth with:"),Tr.forEach(t),Eo=u(e),y(Yt.$$.fragment,e),Io=u(e),He=s(e,"P",{});var Jr=o(He);di=i(Jr,"To use your own dataset, take a look at the "),ia=s(Jr,"A",{href:!0});var wc=o(ia);mi=i(wc,"Create a dataset for training"),wc.forEach(t),Mi=i(Jr," guide."),Jr.forEach(t),jo=u(e),Je=s(e,"H2",{class:!0});var vr=o(Je);qe=s(vr,"A",{id:!0,class:!0,href:!0});var yc=o(qe);ka=s(yc,"SPAN",{});var Uc=o(ka);y(zt.$$.fragment,Uc),Uc.forEach(t),yc.forEach(t),wi=u(vr),Ca=s(vr,"SPAN",{});var bc=o(Ca);yi=i(bc,"Finetuning"),bc.forEach(t),vr.forEach(t),Ro=u(e),y(Pe.$$.fragment,e),$o=u(e),y(Oe.$$.fragment,e),No=u(e),ve=s(e,"H2",{class:!0});var gr=o(ve);Ke=s(gr,"A",{id:!0,class:!0,href:!0});var _c=o(Ke);Aa=s(_c,"SPAN",{});var Tc=o(Aa);y(Lt.$$.fragment,Tc),Tc.forEach(t),_c.forEach(t),Ui=u(gr),Sa=s(gr,"SPAN",{});var Jc=o(Sa);bi=i(Jc,"Finetuning with prior-preserving loss"),Jc.forEach(t),gr.forEach(t),Vo=u(e),et=s(e,"P",{});var Er=o(et);_i=i(Er,"Prior preservation is used to avoid overfitting and language-drift (check out the "),Ht=s(Er,"A",{href:!0,rel:!0});var vc=o(Ht);Ti=i(vc,"paper"),vc.forEach(t),Ji=i(Er," 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."),Er.forEach(t),Bo=u(e),tt=s(e,"P",{});var Ir=o(tt);vi=i(Ir,"The authors recommend generating "),Fa=s(Ir,"CODE",{});var gc=o(Fa);gi=i(gc,"num_epochs * num_samples"),gc.forEach(t),Ei=i(Ir," images for prior preservation. In most cases, 200-300 images work well."),Ir.forEach(t),Go=u(e),y(lt.$$.fragment,e),Xo=u(e),ge=s(e,"H2",{class:!0});var jr=o(ge);at=s(jr,"A",{id:!0,class:!0,href:!0});var Ec=o(at);Wa=s(Ec,"SPAN",{});var Ic=o(Wa);y(qt.$$.fragment,Ic),Ic.forEach(t),Ec.forEach(t),Ii=u(jr),Da=s(jr,"SPAN",{});var jc=o(Da);ji=i(jc,"Finetuning the text encoder and UNet"),jc.forEach(t),jr.forEach(t),Zo=u(e),ie=s(e,"P",{});var Xt=o(ie);Ri=i(Xt,"The script also allows you to finetune the "),xa=s(Xt,"CODE",{});var Rc=o(xa);$i=i(Rc,"text_encoder"),Rc.forEach(t),Ni=i(Xt," along with the "),Qa=s(Xt,"CODE",{});var $c=o(Qa);Vi=i($c,"unet"),$c.forEach(t),Bi=i(Xt,". In our experiments (check out the "),Pt=s(Xt,"A",{href:!0,rel:!0});var Nc=o(Pt);Gi=i(Nc,"Training Stable Diffusion with DreamBooth using \u{1F9E8} Diffusers"),Nc.forEach(t),Xi=i(Xt," post for more details), this yields much better results, especially when generating images of faces."),Xt.forEach(t),ko=u(e),y(st.$$.fragment,e),Co=u(e),pe=s(e,"P",{});var Zt=o(pe);Zi=i(Zt,"Pass the "),Ya=s(Zt,"CODE",{});var Vc=o(Ya);ki=i(Vc,"--train_text_encoder"),Vc.forEach(t),Ci=i(Zt," argument to the training script to enable finetuning the "),za=s(Zt,"CODE",{});var Bc=o(za);Ai=i(Bc,"text_encoder"),Bc.forEach(t),Si=i(Zt," and "),La=s(Zt,"CODE",{});var Gc=o(La);Fi=i(Gc,"unet"),Gc.forEach(t),Wi=i(Zt,":"),Zt.forEach(t),Ao=u(e),y(ot.$$.fragment,e),So=u(e),Ee=s(e,"H2",{class:!0});var Rr=o(Ee);nt=s(Rr,"A",{id:!0,class:!0,href:!0});var Xc=o(nt);Ha=s(Xc,"SPAN",{});var Zc=o(Ha);y(Ot.$$.fragment,Zc),Zc.forEach(t),Xc.forEach(t),Di=u(Rr),qa=s(Rr,"SPAN",{});var kc=o(qa);xi=i(kc,"Finetuning with LoRA"),kc.forEach(t),Rr.forEach(t),Fo=u(e),rt=s(e,"P",{});var $r=o(rt);Qi=i($r,"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 "),pa=s($r,"A",{href:!0});var Cc=o(pa);Yi=i(Cc,"LoRA training"),Cc.forEach(t),zi=i($r," guide."),$r.forEach(t),Wo=u(e),Ie=s(e,"H2",{class:!0});var Nr=o(Ie);it=s(Nr,"A",{id:!0,class:!0,href:!0});var Ac=o(it);Pa=s(Ac,"SPAN",{});var Sc=o(Pa);y(Kt.$$.fragment,Sc),Sc.forEach(t),Ac.forEach(t),Li=u(Nr),Oa=s(Nr,"SPAN",{});var Fc=o(Oa);Hi=i(Fc,"Saving checkpoints while training"),Fc.forEach(t),Nr.forEach(t),Do=u(e),ha=s(e,"P",{});var Wc=o(ha);qi=i(Wc,"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:"),Wc.forEach(t),xo=u(e),y(el.$$.fragment,e),Qo=u(e),he=s(e,"P",{});var kt=o(he);Pi=i(kt,"This saves the full training state in subfolders of your "),Ka=s(kt,"CODE",{});var Dc=o(Ka);Oi=i(Dc,"output_dir"),Dc.forEach(t),Ki=i(kt,". Subfolder names begin with the prefix "),es=s(kt,"CODE",{});var xc=o(es);ep=i(xc,"checkpoint-"),xc.forEach(t),tp=i(kt,", followed by the number of steps performed so far; for example, "),ts=s(kt,"CODE",{});var Qc=o(ts);lp=i(Qc,"checkpoint-1500"),Qc.forEach(t),ap=i(kt," would be a checkpoint saved after 1500 training steps."),kt.forEach(t),Yo=u(e),je=s(e,"H3",{class:!0});var Vr=o(je);pt=s(Vr,"A",{id:!0,class:!0,href:!0});var Yc=o(pt);ls=s(Yc,"SPAN",{});var zc=o(ls);y(tl.$$.fragment,zc),zc.forEach(t),Yc.forEach(t),sp=u(Vr),as=s(Vr,"SPAN",{});var Lc=o(as);op=i(Lc,"Resume training from a saved checkpoint"),Lc.forEach(t),Vr.forEach(t),zo=u(e),be=s(e,"P",{});var Va=o(be);np=i(Va,"If you want to resume training from any of the saved checkpoints, you can pass the argument "),ss=s(Va,"CODE",{});var Hc=o(ss);rp=i(Hc,"--resume_from_checkpoint"),Hc.forEach(t),ip=i(Va," to the script and specify the name of the checkpoint you want to use. You can also use the special string "),os=s(Va,"CODE",{});var qc=o(os);pp=i(qc,'"latest"'),qc.forEach(t),hp=i(Va," 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:"),Va.forEach(t),Lo=u(e),y(ll.$$.fragment,e),Ho=u(e),fa=s(e,"P",{});var Pc=o(fa);fp=i(Pc,"This is a good opportunity to tweak some of your hyperparameters if you wish."),Pc.forEach(t),qo=u(e),Re=s(e,"H3",{class:!0});var Br=o(Re);ht=s(Br,"A",{id:!0,class:!0,href:!0});var Oc=o(ht);ns=s(Oc,"SPAN",{});var Kc=o(ns);y(al.$$.fragment,Kc),Kc.forEach(t),Oc.forEach(t),cp=u(Br),rs=s(Br,"SPAN",{});var eu=o(rs);up=i(eu,"Inference from a saved checkpoint"),eu.forEach(t),Br.forEach(t),Po=u(e),ca=s(e,"P",{});var tu=o(ca);dp=i(tu,"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."),tu.forEach(t),Oo=u(e),ft=s(e,"P",{});var Gr=o(ft);mp=i(Gr,"If you have "),is=s(Gr,"STRONG",{});var lu=o(is);ps=s(lu,"CODE",{});var au=o(ps);Mp=i(au,'"accelerate>=0.16.0"'),au.forEach(t),lu.forEach(t),wp=i(Gr,` installed, use the following code to run
inference from an intermediate checkpoint.`),Gr.forEach(t),Ko=u(e),y(sl.$$.fragment,e),en=u(e),ct=s(e,"P",{});var Xr=o(ct);yp=i(Xr,"If you have "),hs=s(Xr,"STRONG",{});var su=o(hs);fs=s(su,"CODE",{});var ou=o(fs);Up=i(ou,'"accelerate<0.16.0"'),ou.forEach(t),su.forEach(t),bp=i(Xr," installed, you need to convert it to an inference pipeline first:"),Xr.forEach(t),tn=u(e),y(ol.$$.fragment,e),ln=u(e),$e=s(e,"H2",{class:!0});var Zr=o($e);ut=s(Zr,"A",{id:!0,class:!0,href:!0});var nu=o(ut);cs=s(nu,"SPAN",{});var ru=o(cs);y(nl.$$.fragment,ru),ru.forEach(t),nu.forEach(t),_p=u(Zr),us=s(Zr,"SPAN",{});var iu=o(us);Tp=i(iu,"Optimizations for different GPU sizes"),iu.forEach(t),Zr.forEach(t),an=u(e),ua=s(e,"P",{});var pu=o(ua);Jp=i(pu,"Depending on your hardware, there are a few different ways to optimize DreamBooth on GPUs from 16GB to just 8GB!"),pu.forEach(t),sn=u(e),Ne=s(e,"H3",{class:!0});var kr=o(Ne);dt=s(kr,"A",{id:!0,class:!0,href:!0});var hu=o(dt);ds=s(hu,"SPAN",{});var fu=o(ds);y(rl.$$.fragment,fu),fu.forEach(t),hu.forEach(t),vp=u(kr),ms=s(kr,"SPAN",{});var cu=o(ms);gp=i(cu,"xFormers"),cu.forEach(t),kr.forEach(t),on=u(e),we=s(e,"P",{});var oa=o(we);il=s(oa,"A",{href:!0,rel:!0});var uu=o(il);Ep=i(uu,"xFormers"),uu.forEach(t),Ip=i(oa," is a toolbox for optimizing Transformers, and it includes a "),pl=s(oa,"A",{href:!0,rel:!0});var du=o(pl);jp=i(du,"memory-efficient attention"),du.forEach(t),Rp=i(oa," mechanism that is used in \u{1F9E8} Diffusers. You\u2019ll need to "),da=s(oa,"A",{href:!0});var mu=o(da);$p=i(mu,"install xFormers"),mu.forEach(t),Np=i(oa," and then add the following argument to your training script:"),oa.forEach(t),nn=u(e),y(hl.$$.fragment,e),rn=u(e),ma=s(e,"P",{});var Mu=o(ma);Vp=i(Mu,"xFormers is not available in Flax."),Mu.forEach(t),pn=u(e),Ve=s(e,"H3",{class:!0});var Cr=o(Ve);mt=s(Cr,"A",{id:!0,class:!0,href:!0});var wu=o(mt);Ms=s(wu,"SPAN",{});var yu=o(Ms);y(fl.$$.fragment,yu),yu.forEach(t),wu.forEach(t),Bp=u(Cr),ws=s(Cr,"SPAN",{});var Uu=o(ws);Gp=i(Uu,"Set gradients to none"),Uu.forEach(t),Cr.forEach(t),hn=u(e),fe=s(e,"P",{});var Ct=o(fe);Xp=i(Ct,"Another way you can lower your memory footprint is to "),cl=s(Ct,"A",{href:!0,rel:!0});var bu=o(cl);Zp=i(bu,"set the gradients"),bu.forEach(t),kp=i(Ct," to "),ys=s(Ct,"CODE",{});var _u=o(ys);Cp=i(_u,"None"),_u.forEach(t),Ap=i(Ct," 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 "),Us=s(Ct,"CODE",{});var Tu=o(Us);Sp=i(Tu,"None"),Tu.forEach(t),Fp=i(Ct,":"),Ct.forEach(t),fn=u(e),y(ul.$$.fragment,e),cn=u(e),Be=s(e,"H3",{class:!0});var Ar=o(Be);Mt=s(Ar,"A",{id:!0,class:!0,href:!0});var Ju=o(Mt);bs=s(Ju,"SPAN",{});var vu=o(bs);y(dl.$$.fragment,vu),vu.forEach(t),Ju.forEach(t),Wp=u(Ar),_s=s(Ar,"SPAN",{});var gu=o(_s);Dp=i(gu,"16GB GPU"),gu.forEach(t),Ar.forEach(t),un=u(e),wt=s(e,"P",{});var Sr=o(wt);xp=i(Sr,"With the help of gradient checkpointing and "),ml=s(Sr,"A",{href:!0,rel:!0});var Eu=o(ml);Qp=i(Eu,"bitsandbytes"),Eu.forEach(t),Yp=i(Sr," 8-bit optimizer, it\u2019s possible to train DreamBooth on a 16GB GPU. Make sure you have bitsandbytes installed:"),Sr.forEach(t),dn=u(e),y(Ml.$$.fragment,e),mn=u(e),yt=s(e,"P",{});var Fr=o(yt);zp=i(Fr,"Then pass the "),Ts=s(Fr,"CODE",{});var Iu=o(Ts);Lp=i(Iu,"--use_8bit_adam"),Iu.forEach(t),Hp=i(Fr," option to the training script:"),Fr.forEach(t),Mn=u(e),y(wl.$$.fragment,e),wn=u(e),Ge=s(e,"H3",{class:!0});var Wr=o(Ge);Ut=s(Wr,"A",{id:!0,class:!0,href:!0});var ju=o(Ut);Js=s(ju,"SPAN",{});var Ru=o(Js);y(yl.$$.fragment,Ru),Ru.forEach(t),ju.forEach(t),qp=u(Wr),vs=s(Wr,"SPAN",{});var $u=o(vs);Pp=i($u,"12GB GPU"),$u.forEach(t),Wr.forEach(t),yn=u(e),bt=s(e,"P",{});var Dr=o(bt);Op=i(Dr,"To run DreamBooth on a 12GB GPU, you\u2019ll need to enable gradient checkpointing, the 8-bit optimizer, xFormers, and set the gradients to "),gs=s(Dr,"CODE",{});var Nu=o(gs);Kp=i(Nu,"None"),Nu.forEach(t),eh=i(Dr,":"),Dr.forEach(t),Un=u(e),y(Ul.$$.fragment,e),bn=u(e),Xe=s(e,"H3",{class:!0});var xr=o(Xe);_t=s(xr,"A",{id:!0,class:!0,href:!0});var Vu=o(_t);Es=s(Vu,"SPAN",{});var Bu=o(Es);y(bl.$$.fragment,Bu),Bu.forEach(t),Vu.forEach(t),th=u(xr),Is=s(xr,"SPAN",{});var Gu=o(Is);lh=i(Gu,"8 GB GPU"),Gu.forEach(t),xr.forEach(t),_n=u(e),Tt=s(e,"P",{});var Qr=o(Tt);ah=i(Qr,"For 8GB GPUs, you\u2019ll need the help of "),_l=s(Qr,"A",{href:!0,rel:!0});var Xu=o(_l);sh=i(Xu,"DeepSpeed"),Xu.forEach(t),oh=i(Qr,` to offload some
tensors from the VRAM to either the CPU or NVME, enabling training with less GPU memory.`),Qr.forEach(t),Tn=u(e),Ma=s(e,"P",{});var Zu=o(Ma);nh=i(Zu,"Run the following command to configure your \u{1F917} Accelerate environment:"),Zu.forEach(t),Jn=u(e),y(Tl.$$.fragment,e),vn=u(e),Jt=s(e,"P",{});var Yr=o(Jt);rh=i(Yr,"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 "),Jl=s(Yr,"A",{href:!0,rel:!0});var ku=o(Jl);ih=i(ku,"the DeepSpeed documentation"),ku.forEach(t),ph=i(Yr," for more configuration options."),Yr.forEach(t),gn=u(e),_e=s(e,"P",{});var Ba=o(_e);hh=i(Ba,`You should also change the default Adam optimizer to DeepSpeed\u2019s optimized version of Adam
`),vl=s(Ba,"A",{href:!0,rel:!0});var Cu=o(vl);js=s(Cu,"CODE",{});var Au=o(js);fh=i(Au,"deepspeed.ops.adam.DeepSpeedCPUAdam"),Au.forEach(t),Cu.forEach(t),ch=i(Ba," for a substantial speedup. Enabling "),Rs=s(Ba,"CODE",{});var Su=o(Rs);uh=i(Su,"DeepSpeedCPUAdam"),Su.forEach(t),dh=i(Ba," requires your system\u2019s CUDA toolchain version to be the same as the one installed with PyTorch."),Ba.forEach(t),En=u(e),wa=s(e,"P",{});var Fu=o(wa);mh=i(Fu,"8-bit optimizers don\u2019t seem to be compatible with DeepSpeed at the moment."),Fu.forEach(t),In=u(e),ya=s(e,"P",{});var Wu=o(ya);Mh=i(Wu,"Launch training with the following command:"),Wu.forEach(t),jn=u(e),y(gl.$$.fragment,e),Rn=u(e),Ze=s(e,"H2",{class:!0});var zr=o(Ze);vt=s(zr,"A",{id:!0,class:!0,href:!0});var Du=o(vt);$s=s(Du,"SPAN",{});var xu=o($s);y(El.$$.fragment,xu),xu.forEach(t),Du.forEach(t),wh=u(zr),Ns=s(zr,"SPAN",{});var Qu=o(Ns);yh=i(Qu,"Inference"),Qu.forEach(t),zr.forEach(t),$n=u(e),ce=s(e,"P",{});var At=o(ce);Uh=i(At,"Once you have trained a model, specify the path to where the model is saved, and use it for inference in the "),Ua=s(At,"A",{href:!0});var Yu=o(Ua);bh=i(Yu,"StableDiffusionPipeline"),Yu.forEach(t),_h=i(At,". Make sure your prompts include the special "),Vs=s(At,"CODE",{});var zu=o(Vs);Th=i(zu,"identifier"),zu.forEach(t),Jh=i(At," used during training ("),Bs=s(At,"CODE",{});var Lu=o(Bs);vh=i(Lu,"sks"),Lu.forEach(t),gh=i(At," in the previous examples)."),At.forEach(t),Nn=u(e),gt=s(e,"P",{});var Lr=o(gt);Eh=i(Lr,"If you have "),Gs=s(Lr,"STRONG",{});var Hu=o(Gs);Xs=s(Hu,"CODE",{});var qu=o(Xs);Ih=i(qu,'"accelerate>=0.16.0"'),qu.forEach(t),Hu.forEach(t),jh=i(Lr,` installed, you can use the following code to run
inference from an intermediate checkpoint:`),Lr.forEach(t),Vn=u(e),y(Il.$$.fragment,e),Bn=u(e),Et=s(e,"P",{});var Hr=o(Et);Rh=i(Hr,"You may also run inference from any of the "),ba=s(Hr,"A",{href:!0});var Pu=o(ba);$h=i(Pu,"saved training checkpoints"),Pu.forEach(t),Nh=i(Hr,"."),Hr.forEach(t),Gn=u(e),ke=s(e,"H2",{class:!0});var qr=o(ke);It=s(qr,"A",{id:!0,class:!0,href:!0});var Ou=o(It);Zs=s(Ou,"SPAN",{});var Ku=o(Zs);y(jl.$$.fragment,Ku),Ku.forEach(t),Ou.forEach(t),Vh=u(qr),ks=s(qr,"SPAN",{});var ed=o(ks);Bh=i(ed,"IF"),ed.forEach(t),qr.forEach(t),Xn=u(e),Te=s(e,"P",{});var Ga=o(Te);Gh=i(Ga,"You can use the lora and full dreambooth scripts to train the text to image "),Rl=s(Ga,"A",{href:!0,rel:!0});var td=o(Rl);Xh=i(td,"IF model"),td.forEach(t),Zh=i(Ga,` and the stage II upscaler
`),$l=s(Ga,"A",{href:!0,rel:!0});var ld=o($l);kh=i(ld,"IF model"),ld.forEach(t),Ch=i(Ga,"."),Ga.forEach(t),Zn=u(e),_a=s(e,"P",{});var ad=o(_a);Ah=i(ad,`Note that IF has a predicted variance, and our finetuning scripts only train the models predicted error, so for finetuned IF models we switch to a fixed
variance schedule. The full finetuning scripts will update the scheduler config for the full saved model. However, when loading saved LoRA weights, you
must also update the pipeline\u2019s scheduler config.`),ad.forEach(t),kn=u(e),y(Nl.$$.fragment,e),Cn=u(e),Ta=s(e,"P",{});var sd=o(Ta);Sh=i(sd,"Additionally, a few alternative cli flags are needed for IF."),sd.forEach(t),An=u(e),Vl=s(e,"P",{});var zf=o(Vl);Cs=s(zf,"CODE",{});var od=o(Cs);Fh=i(od,"--resolution=64"),od.forEach(t),Wh=i(zf,": IF is a pixel space diffusion model. In order to operate on un-compressed pixels, the input images are of a much smaller resolution."),zf.forEach(t),Sn=u(e),Ce=s(e,"P",{});var wo=o(Ce);As=s(wo,"CODE",{});var nd=o(As);Dh=i(nd,"--pre_compute_text_embeddings"),nd.forEach(t),xh=i(wo,": IF uses "),Bl=s(wo,"A",{href:!0,rel:!0});var rd=o(Bl);Qh=i(rd,"T5"),rd.forEach(t),Yh=i(wo,` for its text encoder. In order to save GPU memory, we pre compute all text embeddings and then de-allocate
T5.`),wo.forEach(t),Fn=u(e),Gl=s(e,"P",{});var Lf=o(Gl);Ss=s(Lf,"CODE",{});var id=o(Ss);zh=i(id,"--tokenizer_max_length=77"),id.forEach(t),Lh=i(Lf,": T5 has a longer default text length, but the default IF encoding procedure uses a smaller number."),Lf.forEach(t),Wn=u(e),Xl=s(e,"P",{});var Hf=o(Xl);Fs=s(Hf,"CODE",{});var pd=o(Fs);Hh=i(pd,"--text_encoder_use_attention_mask"),pd.forEach(t),qh=i(Hf,": T5 passes the attention mask to the text encoder."),Hf.forEach(t),Dn=u(e),Ae=s(e,"H3",{class:!0});var Pr=o(Ae);jt=s(Pr,"A",{id:!0,class:!0,href:!0});var hd=o(jt);Ws=s(hd,"SPAN",{});var fd=o(Ws);y(Zl.$$.fragment,fd),fd.forEach(t),hd.forEach(t),Ph=u(Pr),Ds=s(Pr,"SPAN",{});var cd=o(Ds);Oh=i(cd,"Tips and Tricks"),cd.forEach(t),Pr.forEach(t),xn=i(e,`

We find LoRA to be sufficient for finetuning the stage I model as the low resolution of the model makes representing finegrained detail hard regardless.
`),Ja=s(e,"P",{});var ud=o(Ja);Kh=i(ud,`For common and/or not-visually complex object concepts, you can get away with not-finetuning the upscaler. Just be sure to adjust the prompt passed to the
upscaler to remove the new token from the instance prompt. I.e. if your stage I prompt is \u201Ca sks dog\u201D, use \u201Ca dog\u201D for your stage II prompt.`),ud.forEach(t),Qn=u(e),va=s(e,"P",{});var dd=o(va);ef=i(dd,`For finegrained detail like faces that aren\u2019t present in the original training set, we find that full finetuning of the stage II upscaler is better than
LoRA finetuning stage II.`),dd.forEach(t),Yn=u(e),ga=s(e,"P",{});var md=o(ga);tf=i(md,"For finegrained detail like faces, we find that lower learning rates along with larger batch sizes work best."),md.forEach(t),zn=u(e),Ea=s(e,"P",{});var Md=o(Ea);lf=i(Md,"For stage II, we find that lower learning rates are also needed."),Md.forEach(t),Ln=u(e),Ia=s(e,"P",{});var wd=o(Ia);af=i(wd,`We found experimentally that the DDPM scheduler with the default larger number of denoising steps to sometimes work better than the DPM Solver scheduler
used in the training scripts.`),wd.forEach(t),Hn=u(e),Se=s(e,"H3",{class:!0});var Or=o(Se);Rt=s(Or,"A",{id:!0,class:!0,href:!0});var yd=o(Rt);xs=s(yd,"SPAN",{});var Ud=o(xs);y(kl.$$.fragment,Ud),Ud.forEach(t),yd.forEach(t),sf=u(Or),Qs=s(Or,"SPAN",{});var bd=o(Qs);of=i(bd,"Stage II additional validation images"),bd.forEach(t),Or.forEach(t),qn=u(e),ja=s(e,"P",{});var _d=o(ja);nf=i(_d,"The stage II validation requires images to upscale, we can download a downsized version of the training set:"),_d.forEach(t),Pn=u(e),y(Cl.$$.fragment,e),On=u(e),Fe=s(e,"H3",{class:!0});var Kr=o(Fe);$t=s(Kr,"A",{id:!0,class:!0,href:!0});var Td=o($t);Ys=s(Td,"SPAN",{});var Jd=o(Ys);y(Al.$$.fragment,Jd),Jd.forEach(t),Td.forEach(t),rf=u(Kr),zs=s(Kr,"SPAN",{});var vd=o(zs);pf=i(vd,"IF stage I LoRA Dreambooth"),vd.forEach(t),Kr.forEach(t),Kn=i(e,`

This training configuration requires ~28 GB VRAM.

	`),y(Sl.$$.fragment,e),er=u(e),We=s(e,"H3",{class:!0});var ei=o(We);Nt=s(ei,"A",{id:!0,class:!0,href:!0});var gd=o(Nt);Ls=s(gd,"SPAN",{});var Ed=o(Ls);y(Fl.$$.fragment,Ed),Ed.forEach(t),gd.forEach(t),hf=u(ei),Hs=s(ei,"SPAN",{});var Id=o(Hs);ff=i(Id,"IF stage II LoRA Dreambooth"),Id.forEach(t),ei.forEach(t),tr=u(e),Wl=s(e,"P",{});var qf=o(Wl);qs=s(qf,"CODE",{});var jd=o(qs);cf=i(jd,"--validation_images"),jd.forEach(t),uf=i(qf,": These images are upscaled during validation steps."),qf.forEach(t),lr=u(e),Dl=s(e,"P",{});var Pf=o(Dl);Ps=s(Pf,"CODE",{});var Rd=o(Ps);df=i(Rd,"--class_labels_conditioning=timesteps"),Rd.forEach(t),mf=i(Pf,": Pass additional conditioning to the UNet needed for stage II."),Pf.forEach(t),ar=u(e),xl=s(e,"P",{});var Of=o(xl);Os=s(Of,"CODE",{});var $d=o(Os);Mf=i($d,"--learning_rate=1e-6"),$d.forEach(t),wf=i(Of,": Lower learning rate than stage I."),Of.forEach(t),sr=u(e),Ql=s(e,"P",{});var Kf=o(Ql);Ks=s(Kf,"CODE",{});var Nd=o(Ks);yf=i(Nd,"--resolution=256"),Nd.forEach(t),Uf=i(Kf,": The upscaler expects higher resolution inputs"),Kf.forEach(t),or=u(e),y(Yl.$$.fragment,e),nr=u(e),De=s(e,"H3",{class:!0});var ti=o(De);Vt=s(ti,"A",{id:!0,class:!0,href:!0});var Vd=o(Vt);eo=s(Vd,"SPAN",{});var Bd=o(eo);y(zl.$$.fragment,Bd),Bd.forEach(t),Vd.forEach(t),bf=u(ti),to=s(ti,"SPAN",{});var Gd=o(to);_f=i(Gd,"IF Stage I Full Dreambooth"),Gd.forEach(t),ti.forEach(t),rr=i(e,`

\`--skip_save_text_encoder\`: When training the full model, this will skip saving the entire T5 with the finetuned model. You can still load the pipeline
with a T5 loaded from the original model.
`),Ll=s(e,"P",{});var ec=o(Ll);lo=s(ec,"CODE",{});var Xd=o(lo);Tf=i(Xd,"use_8bit_adam"),Xd.forEach(t),Jf=i(ec,": Due to the size of the optimizer states, we recommend training the full XL IF model with 8bit adam."),ec.forEach(t),ir=u(e),Hl=s(e,"P",{});var tc=o(Hl);ao=s(tc,"CODE",{});var Zd=o(ao);vf=i(Zd,"--learning_rate=1e-7"),Zd.forEach(t),gf=i(tc,`: For full dreambooth, IF requires very low learning rates. With higher learning rates model quality will degrade. Note that it is
likely the learning rate can be increased with larger batch sizes.`),tc.forEach(t),pr=u(e),Ra=s(e,"P",{});var kd=o(Ra);Ef=i(kd,"Using 8bit adam and a batch size of 4, the model can be trained in ~48 GB VRAM."),kd.forEach(t),hr=u(e),y(ql.$$.fragment,e),fr=u(e),xe=s(e,"H3",{class:!0});var li=o(xe);Bt=s(li,"A",{id:!0,class:!0,href:!0});var Cd=o(Bt);so=s(Cd,"SPAN",{});var Ad=o(so);y(Pl.$$.fragment,Ad),Ad.forEach(t),Cd.forEach(t),If=u(li),oo=s(li,"SPAN",{});var Sd=o(oo);jf=i(Sd,"IF Stage II Full Dreambooth"),Sd.forEach(t),li.forEach(t),cr=u(e),Ol=s(e,"P",{});var lc=o(Ol);no=s(lc,"CODE",{});var Fd=o(no);Rf=i(Fd,"--learning_rate=5e-6"),Fd.forEach(t),$f=i(lc,`: With a smaller effective batch size of 4, we found that we required learning rates as low as
1e-8.`),lc.forEach(t),ur=u(e),Kl=s(e,"P",{});var ac=o(Kl);ro=s(ac,"CODE",{});var Wd=o(ro);Nf=i(Wd,"--resolution=256"),Wd.forEach(t),Vf=i(ac,": The upscaler expects higher resolution inputs"),ac.forEach(t),dr=u(e),Qe=s(e,"P",{});var yo=o(Qe);io=s(yo,"CODE",{});var Dd=o(io);Bf=i(Dd,"--train_batch_size=2"),Dd.forEach(t),Gf=i(yo," and "),po=s(yo,"CODE",{});var xd=o(po);Xf=i(xd,"--gradient_accumulation_steps=6"),xd.forEach(t),Zf=i(yo,`: We found that full training of stage II particularly with
faces required large effective batch sizes.`),yo.forEach(t),mr=u(e),y(ea.$$.fragment,e),Mr=u(e),Ye=s(e,"H2",{class:!0});var ai=o(Ye);Gt=s(ai,"A",{id:!0,class:!0,href:!0});var Qd=o(Gt);ho=s(Qd,"SPAN",{});var Yd=o(ho);y(ta.$$.fragment,Yd),Yd.forEach(t),Qd.forEach(t),kf=u(ai),fo=s(ai,"SPAN",{});var zd=o(fo);Cf=i(zd,"Stable Diffusion XL"),zd.forEach(t),ai.forEach(t),wr=u(e),ue=s(e,"P",{});var St=o(ue);Af=i(St,"We support fine-tuning of the UNet shipped in "),la=s(St,"A",{href:!0,rel:!0});var Ld=o(la);Sf=i(Ld,"Stable Diffusion XL"),Ld.forEach(t),Ff=i(St," with DreamBooth and LoRA via the "),co=s(St,"CODE",{});var Hd=o(co);Wf=i(Hd,"train_dreambooth_lora_sdxl.py"),Hd.forEach(t),Df=i(St," script. Please refer to the docs "),aa=s(St,"A",{href:!0,rel:!0});var qd=o(aa);xf=i(qd,"here"),qd.forEach(t),Qf=i(St,"."),St.forEach(t),this.h()},h(){f(d,"name","hf:doc:metadata"),f(d,"content",JSON.stringify(Um)),f(J,"id","dreambooth"),f(J,"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"),f(J,"href","#dreambooth"),f(h,"class","relative group"),f(j,"href","https://arxiv.org/abs/2208.12242"),f(j,"rel","nofollow"),lm(F.src,oe="https://dreambooth.github.io/DreamBooth_files/teaser_static.jpg")||f(F,"src",oe),f(F,"alt","Dreambooth examples from the project's blog"),f(z,"href","https://dreambooth.github.io"),f(B,"href","https://huggingface.co/CompVis/stable-diffusion-v1-4"),f(B,"rel","nofollow"),f(D,"href","https://github.com/huggingface/diffusers/tree/main/examples/dreambooth"),f(D,"rel","nofollow"),f(re,"href","../optimization/xformers"),f(Ft,"href","https://github.com/huggingface/accelerate/"),f(Ft,"rel","nofollow"),f(Qt,"href","https://huggingface.co/datasets/diffusers/dog-example"),f(Qt,"rel","nofollow"),f(ia,"href","create_dataset"),f(qe,"id","finetuning"),f(qe,"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"),f(qe,"href","#finetuning"),f(Je,"class","relative group"),f(Ke,"id","finetuning-with-priorpreserving-loss"),f(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"),f(Ke,"href","#finetuning-with-priorpreserving-loss"),f(ve,"class","relative group"),f(Ht,"href","https://arxiv.org/abs/2208.12242"),f(Ht,"rel","nofollow"),f(at,"id","finetuning-the-text-encoder-and-unet"),f(at,"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"),f(at,"href","#finetuning-the-text-encoder-and-unet"),f(ge,"class","relative group"),f(Pt,"href","https://huggingface.co/blog/dreambooth"),f(Pt,"rel","nofollow"),f(nt,"id","finetuning-with-lora"),f(nt,"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"),f(nt,"href","#finetuning-with-lora"),f(Ee,"class","relative group"),f(pa,"href","./lora#dreambooth"),f(it,"id","saving-checkpoints-while-training"),f(it,"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"),f(it,"href","#saving-checkpoints-while-training"),f(Ie,"class","relative group"),f(pt,"id","resume-training-from-a-saved-checkpoint"),f(pt,"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"),f(pt,"href","#resume-training-from-a-saved-checkpoint"),f(je,"class","relative group"),f(ht,"id","inference-from-a-saved-checkpoint"),f(ht,"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"),f(ht,"href","#inference-from-a-saved-checkpoint"),f(Re,"class","relative group"),f(ut,"id","optimizations-for-different-gpu-sizes"),f(ut,"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"),f(ut,"href","#optimizations-for-different-gpu-sizes"),f($e,"class","relative group"),f(dt,"id","xformers"),f(dt,"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"),f(dt,"href","#xformers"),f(Ne,"class","relative group"),f(il,"href","https://github.com/facebookresearch/xformers"),f(il,"rel","nofollow"),f(pl,"href","https://facebookresearch.github.io/xformers/components/ops.html#module-xformers.ops"),f(pl,"rel","nofollow"),f(da,"href","./optimization/xformers"),f(mt,"id","set-gradients-to-none"),f(mt,"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"),f(mt,"href","#set-gradients-to-none"),f(Ve,"class","relative group"),f(cl,"href","https://pytorch.org/docs/stable/generated/torch.optim.Optimizer.zero_grad.html"),f(cl,"rel","nofollow"),f(Mt,"id","16gb-gpu"),f(Mt,"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"),f(Mt,"href","#16gb-gpu"),f(Be,"class","relative group"),f(ml,"href","https://github.com/TimDettmers/bitsandbytes"),f(ml,"rel","nofollow"),f(Ut,"id","12gb-gpu"),f(Ut,"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"),f(Ut,"href","#12gb-gpu"),f(Ge,"class","relative group"),f(_t,"id","8-gb-gpu"),f(_t,"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"),f(_t,"href","#8-gb-gpu"),f(Xe,"class","relative group"),f(_l,"href","https://www.deepspeed.ai/"),f(_l,"rel","nofollow"),f(Jl,"href","https://huggingface.co/docs/accelerate/usage_guides/deepspeed"),f(Jl,"rel","nofollow"),f(vl,"href","https://deepspeed.readthedocs.io/en/latest/optimizers.html#adam-cpu"),f(vl,"rel","nofollow"),f(vt,"id","inference"),f(vt,"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"),f(vt,"href","#inference"),f(Ze,"class","relative group"),f(Ua,"href","/docs/diffusers/main/en/api/pipelines/stable_diffusion/text2img#diffusers.StableDiffusionPipeline"),f(ba,"href","#inference-from-a-saved-checkpoint"),f(It,"id","if"),f(It,"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"),f(It,"href","#if"),f(ke,"class","relative group"),f(Rl,"href","https://huggingface.co/DeepFloyd/IF-I-XL-v1.0"),f(Rl,"rel","nofollow"),f($l,"href","https://huggingface.co/DeepFloyd/IF-II-L-v1.0"),f($l,"rel","nofollow"),f(Bl,"href","https://huggingface.co/docs/transformers/model_doc/t5"),f(Bl,"rel","nofollow"),f(jt,"id","tips-and-tricks"),f(jt,"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"),f(jt,"href","#tips-and-tricks"),f(Ae,"class","relative group"),f(Rt,"id","stage-ii-additional-validation-images"),f(Rt,"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"),f(Rt,"href","#stage-ii-additional-validation-images"),f(Se,"class","relative group"),f($t,"id","if-stage-i-lora-dreambooth"),f($t,"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"),f($t,"href","#if-stage-i-lora-dreambooth"),f(Fe,"class","relative group"),f(Nt,"id","if-stage-ii-lora-dreambooth"),f(Nt,"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"),f(Nt,"href","#if-stage-ii-lora-dreambooth"),f(We,"class","relative group"),f(Vt,"id","if-stage-i-full-dreambooth"),f(Vt,"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"),f(Vt,"href","#if-stage-i-full-dreambooth"),f(De,"class","relative group"),f(Bt,"id","if-stage-ii-full-dreambooth"),f(Bt,"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"),f(Bt,"href","#if-stage-ii-full-dreambooth"),f(xe,"class","relative group"),f(Gt,"id","stable-diffusion-xl"),f(Gt,"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"),f(Gt,"href","#stable-diffusion-xl"),f(Ye,"class","relative group"),f(la,"href","https://huggingface.co/papers/2307.01952"),f(la,"rel","nofollow"),f(aa,"href","https://github.com/huggingface/diffusers/blob/main/examples/dreambooth/README_sdxl.md"),f(aa,"rel","nofollow")},m(e,n){l(document.head,d),p(e,M,n),p(e,h,n),l(h,J),l(J,v),U($,v,null),l(h,E),l(h,C),l(C,x),p(e,A,n),p(e,S,n),l(S,j),l(j,de),l(S,O),p(e,Q,n),p(e,Y,n),l(Y,F),p(e,ne,n),p(e,k,n),l(k,K),l(k,z),l(z,ee),p(e,te,n),p(e,V,n),l(V,L),l(V,B),l(B,le),l(le,W),l(V,H),l(V,D),l(D,ae),l(V,G),p(e,q,n),p(e,m,n),l(m,g),l(m,me),l(me,X),l(m,Z),p(e,ye,n),U(se,e,n),p(e,Ue,n),p(e,P,n),l(P,Me),l(P,re),l(re,si),l(P,oi),p(e,Uo,n),p(e,ze,n),l(ze,ni),l(ze,Ft),l(Ft,ri),l(ze,ii),p(e,bo,n),U(Wt,e,n),p(e,_o,n),p(e,na,n),l(na,pi),p(e,To,n),U(Dt,e,n),p(e,Jo,n),p(e,ra,n),l(ra,hi),p(e,vo,n),U(xt,e,n),p(e,go,n),p(e,Le,n),l(Le,fi),l(Le,Qt),l(Qt,ci),l(Le,ui),p(e,Eo,n),U(Yt,e,n),p(e,Io,n),p(e,He,n),l(He,di),l(He,ia),l(ia,mi),l(He,Mi),p(e,jo,n),p(e,Je,n),l(Je,qe),l(qe,ka),U(zt,ka,null),l(Je,wi),l(Je,Ca),l(Ca,yi),p(e,Ro,n),U(Pe,e,n),p(e,$o,n),U(Oe,e,n),p(e,No,n),p(e,ve,n),l(ve,Ke),l(Ke,Aa),U(Lt,Aa,null),l(ve,Ui),l(ve,Sa),l(Sa,bi),p(e,Vo,n),p(e,et,n),l(et,_i),l(et,Ht),l(Ht,Ti),l(et,Ji),p(e,Bo,n),p(e,tt,n),l(tt,vi),l(tt,Fa),l(Fa,gi),l(tt,Ei),p(e,Go,n),U(lt,e,n),p(e,Xo,n),p(e,ge,n),l(ge,at),l(at,Wa),U(qt,Wa,null),l(ge,Ii),l(ge,Da),l(Da,ji),p(e,Zo,n),p(e,ie,n),l(ie,Ri),l(ie,xa),l(xa,$i),l(ie,Ni),l(ie,Qa),l(Qa,Vi),l(ie,Bi),l(ie,Pt),l(Pt,Gi),l(ie,Xi),p(e,ko,n),U(st,e,n),p(e,Co,n),p(e,pe,n),l(pe,Zi),l(pe,Ya),l(Ya,ki),l(pe,Ci),l(pe,za),l(za,Ai),l(pe,Si),l(pe,La),l(La,Fi),l(pe,Wi),p(e,Ao,n),U(ot,e,n),p(e,So,n),p(e,Ee,n),l(Ee,nt),l(nt,Ha),U(Ot,Ha,null),l(Ee,Di),l(Ee,qa),l(qa,xi),p(e,Fo,n),p(e,rt,n),l(rt,Qi),l(rt,pa),l(pa,Yi),l(rt,zi),p(e,Wo,n),p(e,Ie,n),l(Ie,it),l(it,Pa),U(Kt,Pa,null),l(Ie,Li),l(Ie,Oa),l(Oa,Hi),p(e,Do,n),p(e,ha,n),l(ha,qi),p(e,xo,n),U(el,e,n),p(e,Qo,n),p(e,he,n),l(he,Pi),l(he,Ka),l(Ka,Oi),l(he,Ki),l(he,es),l(es,ep),l(he,tp),l(he,ts),l(ts,lp),l(he,ap),p(e,Yo,n),p(e,je,n),l(je,pt),l(pt,ls),U(tl,ls,null),l(je,sp),l(je,as),l(as,op),p(e,zo,n),p(e,be,n),l(be,np),l(be,ss),l(ss,rp),l(be,ip),l(be,os),l(os,pp),l(be,hp),p(e,Lo,n),U(ll,e,n),p(e,Ho,n),p(e,fa,n),l(fa,fp),p(e,qo,n),p(e,Re,n),l(Re,ht),l(ht,ns),U(al,ns,null),l(Re,cp),l(Re,rs),l(rs,up),p(e,Po,n),p(e,ca,n),l(ca,dp),p(e,Oo,n),p(e,ft,n),l(ft,mp),l(ft,is),l(is,ps),l(ps,Mp),l(ft,wp),p(e,Ko,n),U(sl,e,n),p(e,en,n),p(e,ct,n),l(ct,yp),l(ct,hs),l(hs,fs),l(fs,Up),l(ct,bp),p(e,tn,n),U(ol,e,n),p(e,ln,n),p(e,$e,n),l($e,ut),l(ut,cs),U(nl,cs,null),l($e,_p),l($e,us),l(us,Tp),p(e,an,n),p(e,ua,n),l(ua,Jp),p(e,sn,n),p(e,Ne,n),l(Ne,dt),l(dt,ds),U(rl,ds,null),l(Ne,vp),l(Ne,ms),l(ms,gp),p(e,on,n),p(e,we,n),l(we,il),l(il,Ep),l(we,Ip),l(we,pl),l(pl,jp),l(we,Rp),l(we,da),l(da,$p),l(we,Np),p(e,nn,n),U(hl,e,n),p(e,rn,n),p(e,ma,n),l(ma,Vp),p(e,pn,n),p(e,Ve,n),l(Ve,mt),l(mt,Ms),U(fl,Ms,null),l(Ve,Bp),l(Ve,ws),l(ws,Gp),p(e,hn,n),p(e,fe,n),l(fe,Xp),l(fe,cl),l(cl,Zp),l(fe,kp),l(fe,ys),l(ys,Cp),l(fe,Ap),l(fe,Us),l(Us,Sp),l(fe,Fp),p(e,fn,n),U(ul,e,n),p(e,cn,n),p(e,Be,n),l(Be,Mt),l(Mt,bs),U(dl,bs,null),l(Be,Wp),l(Be,_s),l(_s,Dp),p(e,un,n),p(e,wt,n),l(wt,xp),l(wt,ml),l(ml,Qp),l(wt,Yp),p(e,dn,n),U(Ml,e,n),p(e,mn,n),p(e,yt,n),l(yt,zp),l(yt,Ts),l(Ts,Lp),l(yt,Hp),p(e,Mn,n),U(wl,e,n),p(e,wn,n),p(e,Ge,n),l(Ge,Ut),l(Ut,Js),U(yl,Js,null),l(Ge,qp),l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,n),p(e,Hl,n),l(Hl,ao),l(ao,vf),l(Hl,gf),p(e,pr,n),p(e,Ra,n),l(Ra,Ef),p(e,hr,n),U(ql,e,n),p(e,fr,n),p(e,xe,n),l(xe,Bt),l(Bt,so),U(Pl,so,null),l(xe,If),l(xe,oo),l(oo,jf),p(e,cr,n),p(e,Ol,n),l(Ol,no),l(no,Rf),l(Ol,$f),p(e,ur,n),p(e,Kl,n),l(Kl,ro),l(ro,Nf),l(Kl,Vf),p(e,dr,n),p(e,Qe,n),l(Qe,io),l(io,Bf),l(Qe,Gf),l(Qe,po),l(po,Xf),l(Qe,Zf),p(e,mr,n),U(ea,e,n),p(e,Mr,n),p(e,Ye,n),l(Ye,Gt),l(Gt,ho),U(ta,ho,null),l(Ye,kf),l(Ye,fo),l(fo,Cf),p(e,wr,n),p(e,ue,n),l(ue,Af),l(ue,la),l(la,Sf),l(ue,Ff),l(ue,co),l(co,Wf),l(ue,Df),l(ue,aa),l(aa,xf),l(ue,Qf),yr=!0},p(e,[n]){const sa={};n&2&&(sa.$$scope={dirty:n,ctx:e}),Pe.$set(sa);const uo={};n&2&&(uo.$$scope={dirty:n,ctx:e}),Oe.$set(uo);const mo={};n&2&&(mo.$$scope={dirty:n,ctx:e}),lt.$set(mo);const Mo={};n&2&&(Mo.$$scope={dirty:n,ctx:e}),st.$set(Mo);const $a={};n&2&&($a.$$scope={dirty:n,ctx:e}),ot.$set($a)},i(e){yr||(b($.$$.fragment,e),b(se.$$.fragment,e),b(Wt.$$.fragment,e),b(Dt.$$.fragment,e),b(xt.$$.fragment,e),b(Yt.$$.fragment,e),b(zt.$$.fragment,e),b(Pe.$$.fragment,e),b(Oe.$$.fragment,e),b(Lt.$$.fragment,e),b(lt.$$.fragment,e),b(qt.$$.fragment,e),b(st.$$.fragment,e),b(ot.$$.fragment,e),b(Ot.$$.fragment,e),b(Kt.$$.fragment,e),b(el.$$.fragment,e),b(tl.$$.fragment,e),b(ll.$$.fragment,e),b(al.$$.fragment,e),b(sl.$$.fragment,e),b(ol.$$.fragment,e),b(nl.$$.fragment,e),b(rl.$$.fragment,e),b(hl.$$.fragment,e),b(fl.$$.fragment,e),b(ul.$$.fragment,e),b(dl.$$.fragment,e),b(Ml.$$.fragment,e),b(wl.$$.fragment,e),b(yl.$$.fragment,e),b(Ul.$$.fragment,e),b(bl.$$.fragment,e),b(Tl.$$.fragment,e),b(gl.$$.fragment,e),b(El.$$.fragment,e),b(Il.$$.fragment,e),b(jl.$$.fragment,e),b(Nl.$$.fragment,e),b(Zl.$$.fragment,e),b(kl.$$.fragment,e),b(Cl.$$.fragment,e),b(Al.$$.fragment,e),b(Sl.$$.fragment,e),b(Fl.$$.fragment,e),b(Yl.$$.fragment,e),b(zl.$$.fragment,e),b(ql.$$.fragment,e),b(Pl.$$.fragment,e),b(ea.$$.fragment,e),b(ta.$$.fragment,e),yr=!0)},o(e){_($.$$.fragment,e),_(se.$$.fragment,e),_(Wt.$$.fragment,e),_(Dt.$$.fragment,e),_(xt.$$.fragment,e),_(Yt.$$.fragment,e),_(zt.$$.fragment,e),_(Pe.$$.fragment,e),_(Oe.$$.fragment,e),_(Lt.$$.fragment,e),_(lt.$$.fragment,e),_(qt.$$.fragment,e),_(st.$$.fragment,e),_(ot.$$.fragment,e),_(Ot.$$.fragment,e),_(Kt.$$.fragment,e),_(el.$$.fragment,e),_(tl.$$.fragment,e),_(ll.$$.fragment,e),_(al.$$.fragment,e),_(sl.$$.fragment,e),_(ol.$$.fragment,e),_(nl.$$.fragment,e),_(rl.$$.fragment,e),_(hl.$$.fragment,e),_(fl.$$.fragment,e),_(ul.$$.fragment,e),_(dl.$$.fragment,e),_(Ml.$$.fragment,e),_(wl.$$.fragment,e),_(yl.$$.fragment,e),_(Ul.$$.fragment,e),_(bl.$$.fragment,e),_(Tl.$$.fragment,e),_(gl.$$.fragment,e),_(El.$$.fragment,e),_(Il.$$.fragment,e),_(jl.$$.fragment,e),_(Nl.$$.fragment,e),_(Zl.$$.fragment,e),_(kl.$$.fragment,e),_(Cl.$$.fragment,e),_(Al.$$.fragment,e),_(Sl.$$.fragment,e),_(Fl.$$.fragment,e),_(Yl.$$.fragment,e),_(zl.$$.fragment,e),_(ql.$$.fragment,e),_(Pl.$$.fragment,e),_(ea.$$.fragment,e),_(ta.$$.fragment,e),yr=!1},d(e){t(d),e&&t(M),e&&t(h),T($),e&&t(A),e&&t(S),e&&t(Q),e&&t(Y),e&&t(ne),e&&t(k),e&&t(te),e&&t(V),e&&t(q),e&&t(m),e&&t(ye),T(se,e),e&&t(Ue),e&&t(P),e&&t(Uo),e&&t(ze),e&&t(bo),T(Wt,e),e&&t(_o),e&&t(na),e&&t(To),T(Dt,e),e&&t(Jo),e&&t(ra),e&&t(vo),T(xt,e),e&&t(go),e&&t(Le),e&&t(Eo),T(Yt,e),e&&t(Io),e&&t(He),e&&t(jo),e&&t(Je),T(zt),e&&t(Ro),T(Pe,e),e&&t($o),T(Oe,e),e&&t(No),e&&t(ve),T(Lt),e&&t(Vo),e&&t(et),e&&t(Bo),e&&t(tt),e&&t(Go),T(lt,e),e&&t(Xo),e&&t(ge),T(qt),e&&t(Zo),e&&t(ie),e&&t(ko),T(st,e),e&&t(Co),e&&t(pe),e&&t(Ao),T(ot,e),e&&t(So),e&&t(Ee),T(Ot),e&&t(Fo),e&&t(rt),e&&t(Wo),e&&t(Ie),T(Kt),e&&t(Do),e&&t(ha),e&&t(xo),T(el,e),e&&t(Qo),e&&t(he),e&&t(Yo),e&&t(je),T(tl),e&&t(zo),e&&t(be),e&&t(Lo),T(ll,e),e&&t(Ho),e&&t(fa),e&&t(qo),e&&t(Re),T(al),e&&t(Po),e&&t(ca),e&&t(Oo),e&&t(ft),e&&t(Ko),T(sl,e),e&&t(en),e&&t(ct),e&&t(tn),T(ol,e),e&&t(ln),e&&t($e),T(nl),e&&t(an),e&&t(ua),e&&t(sn),e&&t(Ne),T(rl),e&&t(on),e&&t(we),e&&t(nn),T(hl,e),e&&t(rn),e&&t(ma),e&&t(pn),e&&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),e&&t(dr),e&&t(Qe),e&&t(mr),T(ea,e),e&&t(Mr),e&&t(Ye),T(ta),e&&t(wr),e&&t(ue)}}}const Um={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"},{local:"if",sections:[{local:"tips-and-tricks",title:"Tips and Tricks"},{local:"stage-ii-additional-validation-images",title:"Stage II additional validation images"},{local:"if-stage-i-lora-dreambooth",title:"IF stage I LoRA Dreambooth"},{local:"if-stage-ii-lora-dreambooth",title:"IF stage II LoRA Dreambooth"},{local:"if-stage-i-full-dreambooth",title:"IF Stage I Full Dreambooth"},{local:"if-stage-ii-full-dreambooth",title:"IF Stage II Full Dreambooth"}],title:"IF"},{local:"stable-diffusion-xl",title:"Stable Diffusion XL"}],title:"DreamBooth"};function bm(R){return am(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Em extends Od{constructor(d){super();Kd(this,d,bm,ym,em,{})}}export{Em as default,Um as metadata};
