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 b,q as U,o as _,B as T,v as am,L as Za}from"../../chunks/vendor-hf-doc-builder.js";import{T as Pd}from"../../chunks/Tip-hf-doc-builder.js";import{I as $}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{C as I}from"../../chunks/CodeBlock-hf-doc-builder.js";import{F as sc,M as Xa}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(N){d=s(N,"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 A=o(h);J=i(A,"in-depth analysis"),A.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(N,E){p(N,d,E),l(d,M),l(d,h),l(h,J),l(d,v)},d(N){N&&t(d)}}}function om(R){let d,M,h,J,v,N,E,A,x,S,C,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."),N=c(),E=a("p"),A=r("Specify the "),x=a("code"),S=r("MODEL_NAME"),C=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),N=u(m),E=s(m,"P",{});var Z=o(E);A=i(Z,"Specify the "),x=s(Z,"CODE",{});var X=o(x);S=i(X,"MODEL_NAME"),X.forEach(t),C=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 "),j=s(Z,"CODE",{});var ye=o(j);de=i(ye,"pretrained_model_name_or_path"),ye.forEach(t),O=i(Z," argument. The "),Q=s(Z,"CODE",{});var se=o(Q);Y=i(se,"instance_prompt"),se.forEach(t),F=i(Z," argument is a text prompt that contains a unique identifier, such as "),oe=s(Z,"CODE",{});var be=o(oe);ne=i(be,"sks"),be.forEach(t),k=i(Z,", and the class the image belongs to, which in this example is "),K=s(Z,"CODE",{});var P=o(K);z=i(P,"a photo of a sks dog"),P.forEach(t),ee=i(Z,"."),Z.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,N,g),p(m,E,g),l(E,A),l(E,x),l(x,S),l(E,C),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),b(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),b(G,m,g),q=!0},p:Za,i(m){q||(U(V.$$.fragment,m),U(G.$$.fragment,m),q=!0)},o(m){_(V.$$.fragment,m),_(G.$$.fragment,m),q=!1},d(m){m&&t(d),m&&t(N),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 Xa({props:{$$slots:{default:[om]},$$scope:{ctx:R}}}),{c(){w(d.$$.fragment)},l(h){y(d.$$.fragment,h)},m(h,J){b(d,h,J),M=!0},p(h,J){const v={};J&2&&(v.$$scope={dirty:J,ctx:h}),d.$set(v)},i(h){M||(U(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,N,E,A,x,S,C,j,de,O,Q,Y,F,oe,ne,k,K,z,ee,te,V,L,B,le,W,H,D,ae,G,q;return S=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."),N=c(),E=a("p"),A=r("Before running the script, make sure you have the requirements installed:"),x=c(),w(S.$$.fragment),C=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),N=u(m),E=s(m,"P",{});var Z=o(E);A=i(Z,"Before running the script, make sure you have the requirements installed:"),Z.forEach(t),x=u(m),y(S.$$.fragment,m),C=u(m),j=s(m,"P",{});var X=o(j);de=i(X,"Specify the "),O=s(X,"CODE",{});var ye=o(O);Q=i(ye,"MODEL_NAME"),ye.forEach(t),Y=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 "),F=s(X,"CODE",{});var se=o(F);oe=i(se,"pretrained_model_name_or_path"),se.forEach(t),ne=i(X," argument. The "),k=s(X,"CODE",{});var be=o(k);K=i(be,"instance_prompt"),be.forEach(t),z=i(X," argument is a text prompt that contains a unique identifier, such as "),ee=s(X,"CODE",{});var P=o(ee);te=i(P,"sks"),P.forEach(t),V=i(X,", and the class the image belongs to, which in this example is "),L=s(X,"CODE",{});var Me=o(L);B=i(Me,"a photo of a sks dog"),Me.forEach(t),le=i(X,"."),X.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,N,g),p(m,E,g),l(E,A),p(m,x,g),b(S,m,g),p(m,C,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),b(G,m,g),q=!0},p:Za,i(m){q||(U(S.$$.fragment,m),U(G.$$.fragment,m),q=!0)},o(m){_(S.$$.fragment,m),_(G.$$.fragment,m),q=!1},d(m){m&&t(d),m&&t(N),m&&t(E),m&&t(x),T(S,m),m&&t(C),m&&t(j),m&&t(W),m&&t(H),m&&t(ae),T(G,m)}}}function im(R){let d,M;return d=new Xa({props:{$$slots:{default:[rm]},$$scope:{ctx:R}}}),{c(){w(d.$$.fragment)},l(h){y(d.$$.fragment,h)},m(h,J){b(d,h,J),M=!0},p(h,J){const v={};J&2&&(v.$$scope={dirty:J,ctx:h}),d.$set(v)},i(h){M||(U(d.$$.fragment,h),M=!0)},o(h){_(d.$$.fragment,h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UyMCU1QyUwQSUyMCUyMC0tbGVhcm5pbmdfcmF0ZSUzRDVlLTYlMjAlNUMlMEElMjAlMjAtLWxyX3NjaGVkdWxlciUzRCUyMmNvbnN0YW50JTIyJTIwJTVDJTBBJTIwJTIwLS1scl93YXJtdXBfc3RlcHMlM0QwJTIwJTVDJTBBJTIwJTIwLS1udW1fY2xhc3NfaW1hZ2VzJTNEMjAwJTIwJTVDJTBBJTIwJTIwLS1tYXhfdHJhaW5fc3RlcHMlM0Q4MDAlMjAlNUMlMEElMjAlMjAtLXB1c2hfdG9faHVi",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){b(d,h,J),M=!0},p:Za,i(h){M||(U(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 Xa({props:{$$slots:{default:[pm]},$$scope:{ctx:R}}}),{c(){w(d.$$.fragment)},l(h){y(d.$$.fragment,h)},m(h,J){b(d,h,J),M=!0},p(h,J){const v={};J&2&&(v.$$scope={dirty:J,ctx:h}),d.$set(v)},i(h){M||(U(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){b(d,h,J),M=!0},p:Za,i(h){M||(U(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 Xa({props:{$$slots:{default:[fm]},$$scope:{ctx:R}}}),{c(){w(d.$$.fragment)},l(h){y(d.$$.fragment,h)},m(h,J){b(d,h,J),M=!0},p(h,J){const v={};J&2&&(v.$$scope={dirty:J,ctx:h}),d.$set(v)},i(h){M||(U(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){b(d,h,J),M=!0},p:Za,i(h){M||(U(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 Xa({props:{$$slots:{default:[dm]},$$scope:{ctx:R}}}),{c(){w(d.$$.fragment)},l(h){y(d.$$.fragment,h)},m(h,J){b(d,h,J),M=!0},p(h,J){const v={};J&2&&(v.$$scope={dirty:J,ctx:h}),d.$set(v)},i(h){M||(U(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:"ZXhwb3J0JTIwTU9ERUxfTkFNRSUzRCUyMmR1b25nbmElMkZzdGFibGUtZGlmZnVzaW9uLXYxLTQtZmxheCUyMiUwQWV4cG9ydCUyMElOU1RBTkNFX0RJUiUzRCUyMi4lMkZkb2clMjIlMEFleHBvcnQlMjBDTEFTU19ESVIlM0QlMjJwYXRoLXRvLWNsYXNzLWltYWdlcyUyMiUwQWV4cG9ydCUyME9VVFBVVF9ESVIlM0QlMjJwYXRoLXRvLXNhdmUtbW9kZWwlMjIlMEElMEFweXRob24lMjB0cmFpbl9kcmVhbWJvb3RoX2ZsYXgucHklMjAlNUMlMEElMjAlMjAtLXByZXRyYWluZWRfbW9kZWxfbmFtZV9vcl9wYXRoJTNEJTI0TU9ERUxfTkFNRSUyMCUyMCU1QyUwQSUyMCUyMC0tdHJhaW5fdGV4dF9lbmNvZGVyJTIwJTVDJTBBJTIwJTIwLS1pbnN0YW5jZV9kYXRhX2RpciUzRCUyNElOU1RBTkNFX0RJUiUyMCU1QyUwQSUyMCUyMC0tY2xhc3NfZGF0YV9kaXIlM0QlMjRDTEFTU19ESVIlMjAlNUMlMEElMjAlMjAtLW91dHB1dF9kaXIlM0QlMjRPVVRQVVRfRElSJTIwJTVDJTBBJTIwJTIwLS13aXRoX3ByaW9yX3ByZXNlcnZhdGlvbiUyMC0tcHJpb3JfbG9zc193ZWlnaHQlM0QxLjAlMjAlNUMlMEElMjAlMjAtLWluc3RhbmNlX3Byb21wdCUzRCUyMmElMjBwaG90byUyMG9mJTIwc2tzJTIwZG9nJTIyJTIwJTVDJTBBJTIwJTIwLS1jbGFzc19wcm9tcHQlM0QlMjJhJTIwcGhvdG8lMjBvZiUyMGRvZyUyMiUyMCU1QyUwQSUyMCUyMC0tcmVzb2x1dGlvbiUzRDUxMiUyMCU1QyUwQSUyMCUyMC0tdHJhaW5fYmF0Y2hfc2l6ZSUzRDElMjAlNUMlMEElMjAlMjAtLWxlYXJuaW5nX3JhdGUlM0QyZS02JTIwJTVDJTBBJTIwJTIwLS1udW1fY2xhc3NfaW1hZ2VzJTNEMjAwJTIwJTVDJTBBJTIwJTIwLS1tYXhfdHJhaW5fc3RlcHMlM0Q4MDAlMjAlNUMlMEElMjAlMjAtLXB1c2hfdG9faHVi",highlighted:`<span class="hljs-built_in">export</span> MODEL_NAME=<span class="hljs-string">&quot;duongna/stable-diffusion-v1-4-flax&quot;</span>
<span class="hljs-built_in">export</span> INSTANCE_DIR=<span class="hljs-string">&quot;./dog&quot;</span>
<span class="hljs-built_in">export</span> CLASS_DIR=<span class="hljs-string">&quot;path-to-class-images&quot;</span>
<span class="hljs-built_in">export</span> OUTPUT_DIR=<span class="hljs-string">&quot;path-to-save-model&quot;</span>

python train_dreambooth_flax.py \\
  --pretrained_model_name_or_path=<span class="hljs-variable">$MODEL_NAME</span>  \\
  --train_text_encoder \\
  --instance_data_dir=<span class="hljs-variable">$INSTANCE_DIR</span> \\
  --class_data_dir=<span class="hljs-variable">$CLASS_DIR</span> \\
  --output_dir=<span class="hljs-variable">$OUTPUT_DIR</span> \\
  --with_prior_preservation --prior_loss_weight=1.0 \\
  --instance_prompt=<span class="hljs-string">&quot;a photo of sks dog&quot;</span> \\
  --class_prompt=<span class="hljs-string">&quot;a photo of dog&quot;</span> \\
  --resolution=512 \\
  --train_batch_size=1 \\
  --learning_rate=2e-6 \\
  --num_class_images=200 \\
  --max_train_steps=800 \\
  --push_to_hub`}}),{c(){w(d.$$.fragment)},l(h){y(d.$$.fragment,h)},m(h,J){b(d,h,J),M=!0},p:Za,i(h){M||(U(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 Xa({props:{$$slots:{default:[Mm]},$$scope:{ctx:R}}}),{c(){w(d.$$.fragment)},l(h){y(d.$$.fragment,h)},m(h,J){b(d,h,J),M=!0},p(h,J){const v={};J&2&&(v.$$scope={dirty:J,ctx:h}),d.$set(v)},i(h){M||(U(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,N,E,A,x,S,C,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,Z,X,ye,se,be,P,Me,re,si,oi,bo,ze,ni,Ft,ri,ii,Uo,Wt,_o,na,pi,To,Dt,Jo,ra,hi,vo,xt,go,Le,f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ffusers/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 $({}),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 $({}),lt=new sc({props:{pytorch:!0,tensorflow:!1,jax:!0,$$slots:{jax:[cm],pytorch:[hm]},$$scope:{ctx:R}}}),qt=new $({}),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 $({}),Kt=new $({}),el=new I({props:{code:"JTIwJTIwLS1jaGVja3BvaW50aW5nX3N0ZXBzJTNENTAw",highlighted:"  --checkpointing_steps=500"}}),tl=new $({}),ll=new I({props:{code:"JTIwJTIwLS1yZXN1bWVfZnJvbV9jaGVja3BvaW50JTNEJTIyY2hlY2twb2ludC0xNTAwJTIy",highlighted:'  --resume_from_checkpoint=<span class="hljs-string">&quot;checkpoint-1500&quot;</span>'}}),al=new $({}),sl=new I({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMERpZmZ1c2lvblBpcGVsaW5lJTJDJTIwVU5ldDJEQ29uZGl0aW9uTW9kZWwlMEFmcm9tJTIwdHJhbnNmb3JtZXJzJTIwaW1wb3J0JTIwQ0xJUFRleHRNb2RlbCUwQWltcG9ydCUyMHRvcmNoJTBBJTBBJTIzJTIwTG9hZCUyMHRoZSUyMHBpcGVsaW5lJTIwd2l0aCUyMHRoZSUyMHNhbWUlMjBhcmd1bWVudHMlMjAobW9kZWwlMkMlMjByZXZpc2lvbiklMjB0aGF0JTIwd2VyZSUyMHVzZWQlMjBmb3IlMjB0cmFpbmluZyUwQW1vZGVsX2lkJTIwJTNEJTIwJTIyQ29tcFZpcyUyRnN0YWJsZS1kaWZmdXNpb24tdjEtNCUyMiUwQSUwQXVuZXQlMjAlM0QlMjBVTmV0MkRDb25kaXRpb25Nb2RlbC5mcm9tX3ByZXRyYWluZWQoJTIyJTJGc2RkYXRhJTJGZHJlYW1ib290aCUyRmRhcnVtYS12Mi0xJTJGY2hlY2twb2ludC0xMDAlMkZ1bmV0JTIyKSUwQSUwQSUyMyUyMGlmJTIweW91JTIwaGF2ZSUyMHRyYWluZWQlMjB3aXRoJTIwJTYwLS1hcmdzLnRyYWluX3RleHRfZW5jb2RlciU2MCUyMG1ha2UlMjBzdXJlJTIwdG8lMjBhbHNvJTIwbG9hZCUyMHRoZSUyMHRleHQlMjBlbmNvZGVyJTBBdGV4dF9lbmNvZGVyJTIwJTNEJTIwQ0xJUFRleHRNb2RlbC5mcm9tX3ByZXRyYWluZWQoJTIyJTJGc2RkYXRhJTJGZHJlYW1ib290aCUyRmRhcnVtYS12Mi0xJTJGY2hlY2twb2ludC0xMDAlMkZ0ZXh0X2VuY29kZXIlMjIpJTBBJTBBcGlwZWxpbmUlMjAlM0QlMjBEaWZmdXNpb25QaXBlbGluZS5mcm9tX3ByZXRyYWluZWQoJTBBJTIwJTIwJTIwJTIwbW9kZWxfaWQlMkMlMjB1bmV0JTNEdW5ldCUyQyUyMHRleHRfZW5jb2RlciUzRHRleHRfZW5jb2RlciUyQyUyMGR0eXBlJTNEdG9yY2guZmxvYXQxNiUyQyUyMHVzZV9zYWZldGVuc29ycyUzRFRydWUlMEEpJTBBcGlwZWxpbmUudG8oJTIyY3VkYSUyMiklMEElMEElMjMlMjBQZXJmb3JtJTIwaW5mZXJlbmNlJTJDJTIwb3IlMjBzYXZlJTJDJTIwb3IlMjBwdXNoJTIwdG8lMjB0aGUlMjBodWIlMEFwaXBlbGluZS5zYXZlX3ByZXRyYWluZWQoJTIyZHJlYW1ib290aC1waXBlbGluZSUyMik=",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, use_safetensors=<span class="hljs-literal">True</span>
)
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:"ZnJvbSUyMGFjY2VsZXJhdGUlMjBpbXBvcnQlMjBBY2NlbGVyYXRvciUwQWZyb20lMjBkaWZmdXNlcnMlMjBpbXBvcnQlMjBEaWZmdXNpb25QaXBlbGluZSUwQSUwQSUyMyUyMExvYWQlMjB0aGUlMjBwaXBlbGluZSUyMHdpdGglMjB0aGUlMjBzYW1lJTIwYXJndW1lbnRzJTIwKG1vZGVsJTJDJTIwcmV2aXNpb24pJTIwdGhhdCUyMHdlcmUlMjB1c2VkJTIwZm9yJTIwdHJhaW5pbmclMEFtb2RlbF9pZCUyMCUzRCUyMCUyMkNvbXBWaXMlMkZzdGFibGUtZGlmZnVzaW9uLXYxLTQlMjIlMEFwaXBlbGluZSUyMCUzRCUyMERpZmZ1c2lvblBpcGVsaW5lLmZyb21fcHJldHJhaW5lZChtb2RlbF9pZCUyQyUyMHVzZV9zYWZldGVuc29ycyUzRFRydWUpJTBBJTBBYWNjZWxlcmF0b3IlMjAlM0QlMjBBY2NlbGVyYXRvcigpJTBBJTBBJTIzJTIwVXNlJTIwdGV4dF9lbmNvZGVyJTIwaWYlMjAlNjAtLXRyYWluX3RleHRfZW5jb2Rlci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UyMHRvJTIwdGhlJTIwaHViJTBBcGlwZWxpbmUuc2F2ZV9wcmV0cmFpbmVkKCUyMmRyZWFtYm9vdGgtcGlwZWxpbmUlMjIp",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, use_safetensors=<span class="hljs-literal">True</span>)

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),
    use_safetensors=<span class="hljs-literal">True</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>)`}}),nl=new $({}),rl=new $({}),hl=new I({props:{code:"JTIwJTIwLS1lbmFibGVfeGZvcm1lcnNfbWVtb3J5X2VmZmljaWVudF9hdHRlbnRpb24=",highlighted:"  --enable_xformers_memory_efficient_attention"}}),fl=new $({}),ul=new I({props:{code:"JTIwJTIwLS1zZXRfZ3JhZHNfdG9fbm9uZQ==",highlighted:"  --set_grads_to_none"}}),dl=new $({}),Ml=new I({props:{code:"cGlwJTIwaW5zdGFsbCUyMGJpdHNhbmRieXRlcw==",highlighted:"pip install bitsandbytes"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ludGluZyUyMCU1QyUwQSUyMCUyMC0tdXNlXzhiaXRfYWRhbSUyMCU1QyUwQSUyMCUyMC0tbGVhcm5pbmdfcmF0ZSUzRDVlLTYlMjAlNUMlMEElMjAlMjAtLWxyX3NjaGVkdWxlciUzRCUyMmNvbnN0YW50JTIyJTIwJTVDJTBBJTIwJTIwLS1scl93YXJtdXBfc3RlcHMlM0QwJTIwJTVDJTBBJTIwJTIwLS1udW1fY2xhc3NfaW1hZ2VzJTNEMjAwJTIwJTVDJTBBJTIwJTIwLS1tYXhfdHJhaW5fc3RlcHMlM0Q4MDAlMjAlNUMlMEElMjAlMjAtLXB1c2hfdG9faHVi",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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udF9jaGVja3BvaW50aW5nJTIwJTVDJTBBJTIwJTIwLS11c2VfOGJpdF9hZGFtJTIwJTVDJTBBJTIwJTIwLS1lbmFibGVfeGZvcm1lcnNfbWVtb3J5X2VmZmljaWVudF9hdHRlbnRpb24lMjAlNUMlMEElMjAlMjAtLXNldF9ncmFkc190b19ub25lJTIwJTVDJTBBJTIwJTIwLS1sZWFybmluZ19yYXRlJTNEMmUtNiUyMCU1QyUwQSUyMCUyMC0tbHJfc2NoZWR1bGVyJTNEJTIyY29uc3RhbnQlMjIlMjAlNUMlMEElMjAlMjAtLWxyX3dhcm11cF9zdGVwcyUzRDAlMjAlNUMlMEElMjAlMjAtLW51bV9jbGFzc19pbWFnZXMlM0QyMDAlMjAlNUMlMEElMjAlMjAtLW1heF90cmFpbl9zdGVwcyUzRDgwMCUyMCU1QyUwQSUyMCUyMC0tcHVzaF90b19odWI=",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`}}),Ul=new $({}),Tl=new I({props:{code:"YWNjZWxlcmF0ZSUyMGNvbmZpZw==",highlighted:"accelerate config"}}),gl=new I({props:{code:"ZXhwb3J0JTIwTU9ERUxfTkFNRSUzRCUyMkNvbXBWaXMlMkZzdGFibGUtZGlmZnVzaW9uLXYxLTQlMjIlMEFleHBvcnQlMjBJTlNUQU5DRV9ESVIlM0QlMjIuJTJGZG9nJTIyJTBBZXhwb3J0JTIwQ0xBU1NfRElSJTNEJTIycGF0aF90b19jbGFzc19pbWFnZXMlMjIlMEFleHBvcnQlMjBPVVRQVVRfRElSJTNEJTIycGF0aF90b19zYXZlZF9tb2RlbCUyMiUwQSUwQWFjY2VsZXJhdGUlMjBsYXVuY2glMjB0cmFpbl9kcmVhbWJvb3RoLnB5JTIwJTVDJTBBJTIwJTIwLS1wcmV0cmFpbmVkX21vZGVsX25hbWVfb3JfcGF0aCUzRCUyNE1PREVMX05BTUUlMjAlNUMlMEElMjAlMjAtLWluc3RhbmNlX2RhdGFfZGlyJTNEJTI0SU5TVEFOQ0VfRElSJTIwJTVDJTBBJTIwJTIwLS1jbGFzc19kYXRhX2RpciUzRCUyNENMQVNTX0RJUiUyMCU1QyUwQSUyMCUyMC0tb3V0cHV0X2RpciUzRCUyNE9VVFBVVF9ESVIlMjAlNUMlMEElMjAlMjAtLXdpdGhfcHJpb3JfcHJlc2VydmF0aW9uJTIwLS1wcmlvcl9sb3NzX3dlaWdodCUzRDEuMCUyMCU1QyUwQSUyMCUyMC0taW5zdGFuY2VfcHJvbXB0JTNEJTIyYSUyMHBob3RvJTIwb2YlMjBza3MlMjBkb2clMjIlMjAlNUMlMEElMjAlMjAtLWNsYXNzX3Byb21wdCUzRCUyMmElMjBwaG90byUyMG9mJTIwZG9nJTIyJTIwJTVDJTBBJTIwJTIwLS1yZXNvbHV0aW9uJTNENTEyJTIwJTVDJTBBJTIwJTIwLS10cmFpbl9iYXRjaF9zaXplJTNEMSUyMCU1QyUwQSUyMCUyMC0tc2FtcGxlX2JhdGNoX3NpemUlM0QxJTIwJTVDJTBBJTIwJTIwLS1ncmFkaWVudF9hY2N1bXVsYXRpb25fc3RlcHMlM0QxJTIwLS1ncmFkaWVudF9jaGVja3BvaW50aW5nJTIwJTVDJTBBJTIwJTIwLS1sZWFybmluZ19yYXRlJTNENWUtNiUyMCU1QyUwQSUyMCUyMC0tbHJfc2NoZWR1bGVyJTNEJTIyY29uc3RhbnQlMjIlMjAlNUMlMEElMjAlMjAtLWxyX3dhcm11cF9zdGVwcyUzRDAlMjAlNUMlMEElMjAlMjAtLW51bV9jbGFzc19pbWFnZXMlM0QyMDAlMjAlNUMlMEElMjAlMjAtLW1heF90cmFpbl9zdGVwcyUzRDgwMCUyMCU1QyUwQSUyMCUyMC0tbWl4ZWRfcHJlY2lzaW9uJTNEZnAxNiUyMCU1QyUwQSUyMCUyMC0tcHVzaF90b19odWI=",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 $({}),Il=new I({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMERpZmZ1c2lvblBpcGVsaW5lJTBBaW1wb3J0JTIwdG9yY2glMEElMEFtb2RlbF9pZCUyMCUzRCUyMCUyMnBhdGhfdG9fc2F2ZWRfbW9kZWwlMjIlMEFwaXBlJTIwJTNEJTIwRGlmZnVzaW9uUGlwZWxpbmUuZnJvbV9wcmV0cmFpbmVkKG1vZGVsX2lkJTJDJTIwdG9yY2hfZHR5cGUlM0R0b3JjaC5mbG9hdDE2JTJDJTIwdXNlX3NhZmV0ZW5zb3JzJTNEVHJ1ZSkudG8oJTIyY3VkYSUyMiklMEElMEFwcm9tcHQlMjAlM0QlMjAlMjJBJTIwcGhvdG8lMjBvZiUyMHNrcyUyMGRvZyUyMGluJTIwYSUyMGJ1Y2tldCUyMiUwQWltYWdlJTIwJTNEJTIwcGlwZShwcm9tcHQlMkMlMjBudW1faW5mZXJlbmNlX3N0ZXBzJTNENTAlMkMlMjBndWlkYW5jZV9zY2FsZSUzRDcuNSkuaW1hZ2VzJTVCMCU1RCUwQSUwQWltYWdlLnNhdmUoJTIyZG9nLWJ1Y2tldC5wbmclMjIp",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, use_safetensors=<span class="hljs-literal">True</span>).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 $({}),$l=new I({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMERpZmZ1c2lvblBpcGVsaW5lJTBBJTBBcGlwZSUyMCUzRCUyMERpZmZ1c2lvblBpcGVsaW5lLmZyb21fcHJldHJhaW5lZCglMjJEZWVwRmxveWQlMkZJRi1JLVhMLXYxLjAlMjIlMkMlMjB1c2Vfc2FmZXRlbnNvcnMlM0RUcnVlKSUwQSUwQXBpcGUubG9hZF9sb3JhX3dlaWdodHMoJTIyJTNDbG9yYSUyMHdlaWdodHMlMjBwYXRoJTNFJTIyKSUwQSUwQSUyMyUyMFVwZGF0ZSUyMHNjaGVkdWxlciUyMGNvbmZpZyUyMHRvJTIwZml4ZWQlMjB2YXJpYW5jZSUyMHNjaGVkdWxlJTBBcGlwZS5zY2hlZHVsZXIlMjAlM0QlMjBwaXBlLnNjaGVkdWxlci5fX2NsYXNzX18uZnJvbV9jb25maWcocGlwZS5zY2hlZHVsZXIuY29uZmlnJTJDJTIwdmFyaWFuY2VfdHlwZSUzRCUyMmZpeGVkX3NtYWxsJTIyKQ==",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>, use_safetensors=<span class="hljs-literal">True</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>)`}}),Xl=new $({}),kl=new $({}),Al=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>,
)`}}),Sl=new $({}),Cl=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 $({}),Yl=new I({props:{code:"ZXhwb3J0JTIwTU9ERUxfTkFNRSUzRCUyMkRlZXBGbG95ZCUyRklGLUlJLUwtdjEuMCUyMiUwQWV4cG9ydCUyMElOU1RBTkNFX0RJUiUzRCUyMmRvZyUyMiUwQWV4cG9ydCUyME9VVFBVVF9ESVIlM0QlMjJkcmVhbWJvb3RoX2RvZ191cHNjYWxlJTIyJTBBZXhwb3J0JTIwVkFMSURBVElPTl9JTUFHRVMlM0QlMjJkb2dfZG93bnNpemVkJTJGaW1hZ2VfMS5wbmclMjBkb2dfZG93bnNpemVkJTJGaW1hZ2VfMi5wbmclMjBkb2dfZG93bnNpemVkJTJGaW1hZ2VfMy5wbmclMjBkb2dfZG93bnNpemVkJTJGaW1hZ2VfNC5wbmclMjIlMEElMEFweXRob24lMjB0cmFpbl9kcmVhbWJvb3RoX2xvcmEucHklMjAlNUMlMEElMjAlMjAlMjAlMjAtLXJlcG9ydF90byUyMHdhbmRiJTIwJTVDJTBBJTIwJTIwJTIwJTIwLS1wcmV0cmFpbmVkX21vZGVsX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HRVMlMjAlNUMlMEElMjAlMjAlMjAlMjAtLWNsYXNzX2xhYmVsc19jb25kaXRpb25pbmclM0R0aW1lc3RlcHM=",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 $({}),ql=new I({props:{code:"ZXhwb3J0JTIwTU9ERUxfTkFNRSUzRCUyMkRlZXBGbG95ZCUyRklGLUktWEwtdjEuMCUyMiUwQSUwQWV4cG9ydCUyMElOU1RBTkNFX0RJUiUzRCUyMmRvZyUyMiUwQWV4cG9ydCUyME9VVFBVVF9ESVIlM0QlMjJkcmVhbWJvb3RoX2lmJTIyJTBBJTBBYWNjZWxlcmF0ZSUyMGxhdW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IwJTVDJTBBJTIwJTIwLS1wdXNoX3RvX2h1Yg==",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 $({}),ea=new I({props:{code:"ZXhwb3J0JTIwTU9ERUxfTkFNRSUzRCUyMkRlZXBGbG95ZCUyRklGLUlJLUwtdjEuMCUyMiUwQWV4cG9ydCUyMElOU1RBTkNFX0RJUiUzRCUyMmRvZyUyMiUwQWV4cG9ydCUyME9VVFBVVF9ESVIlM0QlMjJkcmVhbWJvb3RoX2RvZ191cHNjYWxlJTIyJTBBZXhwb3J0JTIwVkFMSURBVElPTl9JTUFHRVMlM0QlMjJkb2dfZG93bnNpemVkJTJGaW1hZ2VfMS5wbmclMjBkb2dfZG93bnNpemVkJTJGaW1hZ2VfMi5wbmclMjBkb2dfZG93bnNpemVkJTJGaW1hZ2VfMy5wbmclMjBkb2dfZG93bnNpemVkJTJGaW1hZ2VfNC5wbm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X2ltYWdlcyUyMCUyNFZBTElEQVRJT05fSU1BR0VTJTIwJTVDJTBBJTIwJTIwLS1jbGFzc19sYWJlbHNfY29uZGl0aW9uaW5nJTIwdGltZXN0ZXBzJTIwJTVDJTBBJTIwJTIwLS1wdXNoX3RvX2h1Yg==",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 $({}),{c(){d=a("meta"),M=c(),h=a("h1"),J=a("a"),v=a("span"),w(N.$$.fragment),E=c(),A=a("span"),x=r("DreamBooth"),S=c(),C=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"),Z=r("main"),X=r(" GitHub branch:"),ye=c(),w(se.$$.fragment),be=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."),bo=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:"),Uo=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(),Aa=a("span"),yi=r("Finetuning"),Ro=c(),w(Pe.$$.fragment),No=c(),w(Oe.$$.fragment),$o=c(),ve=a("h2"),Ke=a("a"),Sa=a("span"),w(Lt.$$.fragment),bi=c(),Ca=a("span"),Ui=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),Zo=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"),Xo=c(),ie=a("p"),Ri=r("The script also allows you to finetune the "),xa=a("code"),Ni=r("text_encoder"),$i=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"),Zi=r(" post for more details), this yields much better results, especially when generating images of faces."),ko=c(),w(st.$$.fragment),Ao=c(),pe=a("p"),Xi=r("Pass the "),Ya=a("code"),ki=r("--train_text_encoder"),Ai=r(" argument to the training script to enable finetuning the "),za=a("code"),Si=r("text_encoder"),Ci=r(" and "),La=a("code"),Fi=r("unet"),Wi=r(":"),So=c(),w(ot.$$.fragment),Co=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(),Ue=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"),bp=r('"accelerate<0.16.0"'),Up=r(" installed, you need to convert it to an inference pipeline first:"),tn=c(),w(ol.$$.fragment),ln=c(),Ne=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(),$e=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"),Np=r("install xFormers"),$p=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"),Zp=r("Another way you can lower your memory footprint is to "),cl=a("a"),Xp=r("set the gradients"),kp=r(" to "),ys=a("code"),Ap=r("None"),Sp=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 "),bs=a("code"),Cp=r("None"),Fp=r(":"),fn=c(),w(ul.$$.fragment),cn=c(),Be=a("h3"),Mt=a("a"),Us=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"),bt=a("a"),Js=a("span"),w(yl.$$.fragment),qp=c(),vs=a("span"),Pp=r("12GB GPU"),yn=c(),Ut=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(":"),bn=c(),w(bl.$$.fragment),Un=c(),Ze=a("h3"),_t=a("a"),Es=a("span"),w(Ul.$$.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(),Xe=a("h2"),vt=a("a"),Ns=a("span"),w(El.$$.fragment),wh=c(),$s=a("span"),yh=r("Inference"),Nn=c(),ce=a("p"),bh=r("Once you have trained a model, specify the path to where the model is saved, and use it for inference in the "),ba=a("a"),Uh=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)."),$n=c(),gt=a("p"),Eh=r("If you have "),Gs=a("strong"),Zs=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 "),Ua=a("a"),Nh=r("saved training checkpoints"),$h=r("."),Gn=c(),ke=a("h2"),It=a("a"),Xs=a("span"),w(jl.$$.fragment),Vh=c(),ks=a("span"),Bh=r("IF"),Zn=c(),Te=a("p"),Gh=r("You can use the lora and full dreambooth scripts to train the text to image "),Rl=a("a"),Zh=r("IF model"),Xh=r(` and the stage II upscaler
`),Nl=a("a"),kh=r("IF model"),Ah=r("."),Xn=c(),_a=a("p"),Sh=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($l.$$.fragment),An=c(),Ta=a("p"),Ch=r("Additionally, a few alternative cli flags are needed for IF."),Sn=c(),Vl=a("p"),As=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."),Cn=c(),Ae=a("p"),Ss=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"),Cs=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(),Zl=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(),Se=a("h3"),jt=a("a"),Ws=a("span"),w(Xl.$$.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(),Ce=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(Al.$$.fragment),On=c(),Fe=a("h3"),Nt=a("a"),Ys=a("span"),w(Sl.$$.fragment),rf=c(),zs=a("span"),pf=r("IF stage I LoRA Dreambooth"),Kn=r(`

This training configuration requires ~28 GB VRAM.

	`),w(Cl.$$.fragment),er=c(),We=a("h3"),$t=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"),bf=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),Uf=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"),Nf=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"),$f=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"),Zf=r("--gradient_accumulation_steps=6"),Xf=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"),Af=r("Stable Diffusion XL"),wr=c(),ue=a("p"),Sf=r("We support fine-tuning of the UNet and text encoders shipped in "),la=a("a"),Cf=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(N.$$.fragment,mo),mo.forEach(t),uo.forEach(t),E=u(sa),A=s(sa,"SPAN",{});var Mo=o(A);x=i(Mo,"DreamBooth"),Mo.forEach(t),sa.forEach(t),S=u(e),C=s(e,"P",{});var Na=o(C);j=s(Na,"A",{href:!0,rel:!0});var oc=o(j);de=i(oc,"DreamBooth"),oc.forEach(t),O=i(Na," 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."),Na.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 $a=o(V);L=i($a,"This guide will show you how to finetune DreamBooth with the "),B=s($a,"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($a," model for various GPU sizes, and with Flax. All the training scripts for DreamBooth used in this guide can be found "),D=s($a,"A",{href:!0,rel:!0});var hc=o(D);ae=i(hc,"here"),hc.forEach(t),G=i($a," if you\u2019re interested in digging deeper and seeing how things work."),$a.forEach(t),q=u(e),m=s(e,"P",{});var br=o(m);g=i(br,"Before running the scripts, make sure you install the library\u2019s training dependencies. We also recommend installing \u{1F9E8} Diffusers from the "),me=s(br,"CODE",{});var fc=o(me);Z=i(fc,"main"),fc.forEach(t),X=i(br," GitHub branch:"),br.forEach(t),ye=u(e),y(se.$$.fragment,e),be=u(e),P=s(e,"P",{});var Ur=o(P);Me=i(Ur,"xFormers is not part of the training requirements, but we recommend you "),re=s(Ur,"A",{href:!0});var cc=o(re);si=i(cc,"install"),cc.forEach(t),oi=i(Ur," it if you can because it could make your training faster and less memory intensive."),Ur.forEach(t),bo=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),Uo=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 bc=o(ka);y(zt.$$.fragment,bc),bc.forEach(t),yc.forEach(t),wi=u(vr),Aa=s(vr,"SPAN",{});var Uc=o(Aa);yi=i(Uc,"Finetuning"),Uc.forEach(t),vr.forEach(t),Ro=u(e),y(Pe.$$.fragment,e),No=u(e),y(Oe.$$.fragment,e),$o=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);Sa=s(_c,"SPAN",{});var Tc=o(Sa);y(Lt.$$.fragment,Tc),Tc.forEach(t),_c.forEach(t),bi=u(gr),Ca=s(gr,"SPAN",{});var Jc=o(Ca);Ui=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),Zo=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),Xo=u(e),ie=s(e,"P",{});var Zt=o(ie);Ri=i(Zt,"The script also allows you to finetune the "),xa=s(Zt,"CODE",{});var Rc=o(xa);Ni=i(Rc,"text_encoder"),Rc.forEach(t),$i=i(Zt," along with the "),Qa=s(Zt,"CODE",{});var Nc=o(Qa);Vi=i(Nc,"unet"),Nc.forEach(t),Bi=i(Zt,". In our experiments (check out the "),Pt=s(Zt,"A",{href:!0,rel:!0});var $c=o(Pt);Gi=i($c,"Training Stable Diffusion with DreamBooth using \u{1F9E8} Diffusers"),$c.forEach(t),Zi=i(Zt," post for more details), this yields much better results, especially when generating images of faces."),Zt.forEach(t),ko=u(e),y(st.$$.fragment,e),Ao=u(e),pe=s(e,"P",{});var Xt=o(pe);Xi=i(Xt,"Pass the "),Ya=s(Xt,"CODE",{});var Vc=o(Ya);ki=i(Vc,"--train_text_encoder"),Vc.forEach(t),Ai=i(Xt," argument to the training script to enable finetuning the "),za=s(Xt,"CODE",{});var Bc=o(za);Si=i(Bc,"text_encoder"),Bc.forEach(t),Ci=i(Xt," and "),La=s(Xt,"CODE",{});var Gc=o(La);Fi=i(Gc,"unet"),Gc.forEach(t),Wi=i(Xt,":"),Xt.forEach(t),So=u(e),y(ot.$$.fragment,e),Co=u(e),Ee=s(e,"H2",{class:!0});var Rr=o(Ee);nt=s(Rr,"A",{id:!0,class:!0,href:!0});var Zc=o(nt);Ha=s(Zc,"SPAN",{});var Xc=o(Ha);y(Ot.$$.fragment,Xc),Xc.forEach(t),Zc.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 Nr=o(rt);Qi=i(Nr,"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(Nr,"A",{href:!0});var Ac=o(pa);Yi=i(Ac,"LoRA training"),Ac.forEach(t),zi=i(Nr," guide."),Nr.forEach(t),Wo=u(e),Ie=s(e,"H2",{class:!0});var $r=o(Ie);it=s($r,"A",{id:!0,class:!0,href:!0});var Sc=o(it);Pa=s(Sc,"SPAN",{});var Cc=o(Pa);y(Kt.$$.fragment,Cc),Cc.forEach(t),Sc.forEach(t),Li=u($r),Oa=s($r,"SPAN",{});var Fc=o(Oa);Hi=i(Fc,"Saving checkpoints while training"),Fc.forEach(t),$r.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),Ue=s(e,"P",{});var Va=o(Ue);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 Zr=o(ct);yp=i(Zr,"If you have "),hs=s(Zr,"STRONG",{});var su=o(hs);fs=s(su,"CODE",{});var ou=o(fs);bp=i(ou,'"accelerate<0.16.0"'),ou.forEach(t),su.forEach(t),Up=i(Zr," installed, you need to convert it to an inference pipeline first:"),Zr.forEach(t),tn=u(e),y(ol.$$.fragment,e),ln=u(e),Ne=s(e,"H2",{class:!0});var Xr=o(Ne);ut=s(Xr,"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(Xr),us=s(Xr,"SPAN",{});var iu=o(us);Tp=i(iu,"Optimizations for different GPU sizes"),iu.forEach(t),Xr.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),$e=s(e,"H3",{class:!0});var kr=o($e);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);Np=i(mu,"install xFormers"),mu.forEach(t),$p=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 Ar=o(Ve);mt=s(Ar,"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(Ar),ws=s(Ar,"SPAN",{});var bu=o(ws);Gp=i(bu,"Set gradients to none"),bu.forEach(t),Ar.forEach(t),hn=u(e),fe=s(e,"P",{});var At=o(fe);Zp=i(At,"Another way you can lower your memory footprint is to "),cl=s(At,"A",{href:!0,rel:!0});var Uu=o(cl);Xp=i(Uu,"set the gradients"),Uu.forEach(t),kp=i(At," to "),ys=s(At,"CODE",{});var _u=o(ys);Ap=i(_u,"None"),_u.forEach(t),Sp=i(At," 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 "),bs=s(At,"CODE",{});var Tu=o(bs);Cp=i(Tu,"None"),Tu.forEach(t),Fp=i(At,":"),At.forEach(t),fn=u(e),y(ul.$$.fragment,e),cn=u(e),Be=s(e,"H3",{class:!0});var Sr=o(Be);Mt=s(Sr,"A",{id:!0,class:!0,href:!0});var Ju=o(Mt);Us=s(Ju,"SPAN",{});var vu=o(Us);y(dl.$$.fragment,vu),vu.forEach(t),Ju.forEach(t),Wp=u(Sr),_s=s(Sr,"SPAN",{});var gu=o(_s);Dp=i(gu,"16GB GPU"),gu.forEach(t),Sr.forEach(t),un=u(e),wt=s(e,"P",{});var Cr=o(wt);xp=i(Cr,"With the help of gradient checkpointing and "),ml=s(Cr,"A",{href:!0,rel:!0});var Eu=o(ml);Qp=i(Eu,"bitsandbytes"),Eu.forEach(t),Yp=i(Cr," 8-bit optimizer, it\u2019s possible to train DreamBooth on a 16GB GPU. Make sure you have bitsandbytes installed:"),Cr.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);bt=s(Wr,"A",{id:!0,class:!0,href:!0});var ju=o(bt);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 Nu=o(vs);Pp=i(Nu,"12GB GPU"),Nu.forEach(t),Wr.forEach(t),yn=u(e),Ut=s(e,"P",{});var Dr=o(Ut);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 $u=o(gs);Kp=i($u,"None"),$u.forEach(t),eh=i(Dr,":"),Dr.forEach(t),bn=u(e),y(bl.$$.fragment,e),Un=u(e),Ze=s(e,"H3",{class:!0});var xr=o(Ze);_t=s(xr,"A",{id:!0,class:!0,href:!0});var Vu=o(_t);Es=s(Vu,"SPAN",{});var Bu=o(Es);y(Ul.$$.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 Zu=o(_l);sh=i(Zu,"DeepSpeed"),Zu.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 Xu=o(Ma);nh=i(Xu,"Run the following command to configure your \u{1F917} Accelerate environment:"),Xu.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 Au=o(vl);js=s(Au,"CODE",{});var Su=o(js);fh=i(Su,"deepspeed.ops.adam.DeepSpeedCPUAdam"),Su.forEach(t),Au.forEach(t),ch=i(Ba," for a substantial speedup. Enabling "),Rs=s(Ba,"CODE",{});var Cu=o(Rs);uh=i(Cu,"DeepSpeedCPUAdam"),Cu.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),Xe=s(e,"H2",{class:!0});var zr=o(Xe);vt=s(zr,"A",{id:!0,class:!0,href:!0});var Du=o(vt);Ns=s(Du,"SPAN",{});var xu=o(Ns);y(El.$$.fragment,xu),xu.forEach(t),Du.forEach(t),wh=u(zr),$s=s(zr,"SPAN",{});var Qu=o($s);yh=i(Qu,"Inference"),Qu.forEach(t),zr.forEach(t),Nn=u(e),ce=s(e,"P",{});var St=o(ce);bh=i(St,"Once you have trained a model, specify the path to where the model is saved, and use it for inference in the "),ba=s(St,"A",{href:!0});var Yu=o(ba);Uh=i(Yu,"StableDiffusionPipeline"),Yu.forEach(t),_h=i(St,". Make sure your prompts include the special "),Vs=s(St,"CODE",{});var zu=o(Vs);Th=i(zu,"identifier"),zu.forEach(t),Jh=i(St," used during training ("),Bs=s(St,"CODE",{});var Lu=o(Bs);vh=i(Lu,"sks"),Lu.forEach(t),gh=i(St," in the previous examples)."),St.forEach(t),$n=u(e),gt=s(e,"P",{});var Lr=o(gt);Eh=i(Lr,"If you have "),Gs=s(Lr,"STRONG",{});var Hu=o(Gs);Zs=s(Hu,"CODE",{});var qu=o(Zs);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 "),Ua=s(Hr,"A",{href:!0});var Pu=o(Ua);Nh=i(Pu,"saved training checkpoints"),Pu.forEach(t),$h=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);Xs=s(Ou,"SPAN",{});var Ku=o(Xs);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),Zn=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);Zh=i(td,"IF model"),td.forEach(t),Xh=i(Ga,` and the stage II upscaler
`),Nl=s(Ga,"A",{href:!0,rel:!0});var ld=o(Nl);kh=i(ld,"IF model"),ld.forEach(t),Ah=i(Ga,"."),Ga.forEach(t),Xn=u(e),_a=s(e,"P",{});var ad=o(_a);Sh=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($l.$$.fragment,e),An=u(e),Ta=s(e,"P",{});var sd=o(Ta);Ch=i(sd,"Additionally, a few alternative cli flags are needed for IF."),sd.forEach(t),Sn=u(e),Vl=s(e,"P",{});var zf=o(Vl);As=s(zf,"CODE",{});var od=o(As);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),Cn=u(e),Ae=s(e,"P",{});var wo=o(Ae);Ss=s(wo,"CODE",{});var nd=o(Ss);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);Cs=s(Lf,"CODE",{});var id=o(Cs);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),Zl=s(e,"P",{});var Hf=o(Zl);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),Se=s(e,"H3",{class:!0});var Pr=o(Se);jt=s(Pr,"A",{id:!0,class:!0,href:!0});var hd=o(jt);Ws=s(hd,"SPAN",{});var fd=o(Ws);y(Xl.$$.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),Ce=s(e,"H3",{class:!0});var Or=o(Ce);Rt=s(Or,"A",{id:!0,class:!0,href:!0});var yd=o(Rt);xs=s(yd,"SPAN",{});var bd=o(xs);y(kl.$$.fragment,bd),bd.forEach(t),yd.forEach(t),sf=u(Or),Qs=s(Or,"SPAN",{});var Ud=o(Qs);of=i(Ud,"Stage II additional validation images"),Ud.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(Al.$$.fragment,e),On=u(e),Fe=s(e,"H3",{class:!0});var Kr=o(Fe);Nt=s(Kr,"A",{id:!0,class:!0,href:!0});var Td=o(Nt);Ys=s(Td,"SPAN",{});var Jd=o(Ys);y(Sl.$$.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(Cl.$$.fragment,e),er=u(e),We=s(e,"H3",{class:!0});var ei=o(We);$t=s(ei,"A",{id:!0,class:!0,href:!0});var gd=o($t);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 Nd=o(Os);Mf=i(Nd,"--learning_rate=1e-6"),Nd.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 $d=o(Ks);yf=i($d,"--resolution=256"),$d.forEach(t),bf=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),Uf=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 Zd=o(lo);Tf=i(Zd,"use_8bit_adam"),Zd.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 Xd=o(ao);vf=i(Xd,"--learning_rate=1e-7"),Xd.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 Ad=o(Bt);so=s(Ad,"SPAN",{});var Sd=o(so);y(Pl.$$.fragment,Sd),Sd.forEach(t),Ad.forEach(t),If=u(li),oo=s(li,"SPAN",{});var Cd=o(oo);jf=i(Cd,"IF Stage II Full Dreambooth"),Cd.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),Nf=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);$f=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);Zf=i(xd,"--gradient_accumulation_steps=6"),xd.forEach(t),Xf=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);Af=i(zd,"Stable Diffusion XL"),zd.forEach(t),ai.forEach(t),wr=u(e),ue=s(e,"P",{});var Ct=o(ue);Sf=i(Ct,"We support fine-tuning of the UNet and text encoders shipped in "),la=s(Ct,"A",{href:!0,rel:!0});var Ld=o(la);Cf=i(Ld,"Stable Diffusion XL"),Ld.forEach(t),Ff=i(Ct," with DreamBooth and LoRA via the "),co=s(Ct,"CODE",{});var Hd=o(co);Wf=i(Hd,"train_dreambooth_lora_sdxl.py"),Hd.forEach(t),Df=i(Ct," script. Please refer to the docs "),aa=s(Ct,"A",{href:!0,rel:!0});var qd=o(aa);xf=i(qd,"here"),qd.forEach(t),Qf=i(Ct,"."),Ct.forEach(t),this.h()},h(){f(d,"name","hf:doc:metadata"),f(d,"content",JSON.stringify(bm)),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(Ne,"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($e,"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(bt,"id","12gb-gpu"),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","#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(Ze,"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(Xe,"class","relative group"),f(ba,"href","/docs/diffusers/main/en/api/pipelines/stable_diffusion/text2img#diffusers.StableDiffusionPipeline"),f(Ua,"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(Nl,"href","https://huggingface.co/DeepFloyd/IF-II-L-v1.0"),f(Nl,"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(Se,"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(Ce,"class","relative group"),f(Nt,"id","if-stage-i-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-i-lora-dreambooth"),f(Fe,"class","relative group"),f($t,"id","if-stage-ii-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-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),b(N,v,null),l(h,E),l(h,A),l(A,x),p(e,S,n),p(e,C,n),l(C,j),l(j,de),l(C,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,Z),l(m,X),p(e,ye,n),b(se,e,n),p(e,be,n),p(e,P,n),l(P,Me),l(P,re),l(re,si),l(P,oi),p(e,bo,n),p(e,ze,n),l(ze,ni),l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,it),l(it,Pa),b(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),b(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),b(tl,ls,null),l(je,sp),l(je,as),l(as,op),p(e,zo,n),p(e,Ue,n),l(Ue,np),l(Ue,ss),l(ss,rp),l(Ue,ip),l(Ue,os),l(os,pp),l(Ue,hp),p(e,Lo,n),b(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),b(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),b(sl,e,n),p(e,en,n),p(e,ct,n),l(ct,yp),l(ct,hs),l(hs,fs),l(fs,bp),l(ct,Up),p(e,tn,n),b(ol,e,n),p(e,ln,n),p(e,Ne,n),l(Ne,ut),l(ut,cs),b(nl,cs,null),l(Ne,_p),l(Ne,us),l(us,Tp),p(e,an,n),p(e,ua,n),l(ua,Jp),p(e,sn,n),p(e,$e,n),l($e,dt),l(dt,ds),b(rl,ds,null),l($e,vp),l($e,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,Np),l(we,$p),p(e,nn,n),b(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),b(fl,Ms,null),l(Ve,Bp),l(Ve,ws),l(ws,Gp),p(e,hn,n),p(e,fe,n),l(fe,Zp),l(fe,cl),l(cl,X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ls),b(Fl,Ls,null),l(We,hf),l(We,Hs),l(Hs,ff),p(e,tr,n),p(e,Wl,n),l(Wl,qs),l(qs,cf),l(Wl,uf),p(e,lr,n),p(e,Dl,n),l(Dl,Ps),l(Ps,df),l(Dl,mf),p(e,ar,n),p(e,xl,n),l(xl,Os),l(Os,Mf),l(xl,wf),p(e,sr,n),p(e,Ql,n),l(Ql,Ks),l(Ks,yf),l(Ql,bf),p(e,or,n),b(Yl,e,n),p(e,nr,n),p(e,De,n),l(De,Vt),l(Vt,eo),b(zl,eo,null),l(De,Uf),l(De,to),l(to,_f),p(e,rr,n),p(e,Ll,n),l(Ll,lo),l(lo,Tf),l(Ll,Jf),p(e,ir,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),b(ql,e,n),p(e,fr,n),p(e,xe,n),l(xe,Bt),l(Bt,so),b(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,Nf),p(e,ur,n),p(e,Kl,n),l(Kl,ro),l(ro,$f),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,Zf),l(Qe,Xf),p(e,mr,n),b(ea,e,n),p(e,Mr,n),p(e,Ye,n),l(Ye,Gt),l(Gt,ho),b(ta,ho,null),l(Ye,kf),l(Ye,fo),l(fo,Af),p(e,wr,n),p(e,ue,n),l(ue,Sf),l(ue,la),l(la,Cf),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 Na={};n&2&&(Na.$$scope={dirty:n,ctx:e}),ot.$set(Na)},i(e){yr||(U(N.$$.fragment,e),U(se.$$.fragment,e),U(Wt.$$.fragment,e),U(Dt.$$.fragment,e),U(xt.$$.fragment,e),U(Yt.$$.fragment,e),U(zt.$$.fragment,e),U(Pe.$$.fragment,e),U(Oe.$$.fragment,e),U(Lt.$$.fragment,e),U(lt.$$.fragment,e),U(qt.$$.fragment,e),U(st.$$.fragment,e),U(ot.$$.fragment,e),U(Ot.$$.fragment,e),U(Kt.$$.fragment,e),U(el.$$.fragment,e),U(tl.$$.fragment,e),U(ll.$$.fragment,e),U(al.$$.fragment,e),U(sl.$$.fragment,e),U(ol.$$.fragment,e),U(nl.$$.fragment,e),U(rl.$$.fragment,e),U(hl.$$.fragment,e),U(fl.$$.fragment,e),U(ul.$$.fragment,e),U(dl.$$.fragment,e),U(Ml.$$.fragment,e),U(wl.$$.fragment,e),U(yl.$$.fragment,e),U(bl.$$.fragment,e),U(Ul.$$.fragment,e),U(Tl.$$.fragment,e),U(gl.$$.fragment,e),U(El.$$.fragment,e),U(Il.$$.fragment,e),U(jl.$$.fragment,e),U($l.$$.fragment,e),U(Xl.$$.fragment,e),U(kl.$$.fragment,e),U(Al.$$.fragment,e),U(Sl.$$.fragment,e),U(Cl.$$.fragment,e),U(Fl.$$.fragment,e),U(Yl.$$.fragment,e),U(zl.$$.fragment,e),U(ql.$$.fragment,e),U(Pl.$$.fragment,e),U(ea.$$.fragment,e),U(ta.$$.fragment,e),yr=!0)},o(e){_(N.$$.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),_(bl.$$.fragment,e),_(Ul.$$.fragment,e),_(Tl.$$.fragment,e),_(gl.$$.fragment,e),_(El.$$.fragment,e),_(Il.$$.fragment,e),_(jl.$$.fragment,e),_($l.$$.fragment,e),_(Xl.$$.fragment,e),_(kl.$$.fragment,e),_(Al.$$.fragment,e),_(Sl.$$.fragment,e),_(Cl.$$.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(N),e&&t(S),e&&t(C),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(be),e&&t(P),e&&t(bo),e&&t(ze),e&&t(Uo),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(No),T(Oe,e),e&&t($o),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(Zo),e&&t(ge),T(qt),e&&t(Xo),e&&t(ie),e&&t(ko),T(st,e),e&&t(Ao),e&&t(pe),e&&t(So),T(ot,e),e&&t(Co),e&&t(Ee),T(Ot),e&&t(Fo),e&&t(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e&&t(Ln),e&&t(Ia),e&&t(Hn),e&&t(Ce),T(kl),e&&t(qn),e&&t(ja),e&&t(Pn),T(Al,e),e&&t(On),e&&t(Fe),T(Sl),e&&t(Kn),T(Cl,e),e&&t(er),e&&t(We),T(Fl),e&&t(tr),e&&t(Wl),e&&t(lr),e&&t(Dl),e&&t(ar),e&&t(xl),e&&t(sr),e&&t(Ql),e&&t(or),T(Yl,e),e&&t(nr),e&&t(De),T(zl),e&&t(rr),e&&t(Ll),e&&t(ir),e&&t(Hl),e&&t(pr),e&&t(Ra),e&&t(hr),T(ql,e),e&&t(fr),e&&t(xe),T(Pl),e&&t(cr),e&&t(Ol),e&&t(ur),e&&t(Kl),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 bm={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 Um(R){return am(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Em extends Od{constructor(d){super();Kd(this,d,Um,ym,em,{})}}export{Em as default,bm as metadata};
