import{S as Id,i as Ed,s as jd,e as s,k as c,w,t as r,M as Rd,c as o,d as t,m as f,a as n,x as y,h as i,b as u,N as $d,G as l,g as p,y as b,q as U,o as _,B as T,v as Nd,L as Ra}from"../../chunks/vendor-hf-doc-builder.js";import{T as gd}from"../../chunks/Tip-hf-doc-builder.js";import{I as B}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{C as E}from"../../chunks/CodeBlock-hf-doc-builder.js";import{D as Vd}from"../../chunks/DocNotebookDropdown-hf-doc-builder.js";import{F as Zc,M as $a}from"../../chunks/Markdown-hf-doc-builder.js";function Bd(j){let d,M,h,J,g;return{c(){d=s("p"),M=r("DreamBooth finetuning is very sensitive to hyperparameters and easy to overfit. We recommend you take a look at our "),h=s("a"),J=r("in-depth analysis"),g=r(" with recommended settings for different subjects to help you choose the appropriate hyperparameters."),this.h()},l($){d=o($,"P",{});var I=n(d);M=i(I,"DreamBooth finetuning is very sensitive to hyperparameters and easy to overfit. We recommend you take a look at our "),h=o(I,"A",{href:!0,rel:!0});var C=n(h);J=i(C,"in-depth analysis"),C.forEach(t),g=i(I," with recommended settings for different subjects to help you choose the appropriate hyperparameters."),I.forEach(t),this.h()},h(){u(h,"href","https://huggingface.co/blog/dreambooth"),u(h,"rel","nofollow")},m($,I){p($,d,I),l(d,M),l(d,h),l(h,J),l(d,g)},d($){$&&t(d)}}}function Gd(j){let d,M,h,J,g,$,I,C,L,A,S,R,D,Z,ee,fe,q,F,H,oe,P,x,te,Q,Y,z,N,ue,X,W,de,le,V,ae;return Y=new E({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>`}}),V=new E({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=s("p"),M=r("Set the "),h=s("code"),J=r("INSTANCE_DIR"),g=r(" environment variable to the path of the directory containing the dog images."),$=c(),I=s("p"),C=r("Specify the "),L=s("code"),A=r("MODEL_NAME"),S=r(" environment variable (either a Hub model repository id or a path to the directory containing the model weights) and pass it to the "),R=s("code"),D=r("pretrained_model_name_or_path"),Z=r(" argument. The "),ee=s("code"),fe=r("instance_prompt"),q=r(" argument is a text prompt that contains a unique identifier, such as "),F=s("code"),H=r("sks"),oe=r(", and the class the image belongs to, which in this example is "),P=s("code"),x=r("a photo of a sks dog"),te=r("."),Q=c(),w(Y.$$.fragment),z=c(),N=s("p"),ue=r("Then you can launch the training script (you can find the full training script "),X=s("a"),W=r("here"),de=r(") with the following command:"),le=c(),w(V.$$.fragment),this.h()},l(m){d=o(m,"P",{});var v=n(d);M=i(v,"Set the "),h=o(v,"CODE",{});var O=n(h);J=i(O,"INSTANCE_DIR"),O.forEach(t),g=i(v," environment variable to the path of the directory containing the dog images."),v.forEach(t),$=f(m),I=o(m,"P",{});var k=n(I);C=i(k,"Specify the "),L=o(k,"CODE",{});var G=n(L);A=i(G,"MODEL_NAME"),G.forEach(t),S=i(k," environment variable (either a Hub model repository id or a path to the directory containing the model weights) and pass it to the "),R=o(k,"CODE",{});var Ue=n(R);D=i(Ue,"pretrained_model_name_or_path"),Ue.forEach(t),Z=i(k," argument. The "),ee=o(k,"CODE",{});var _e=n(ee);fe=i(_e,"instance_prompt"),_e.forEach(t),q=i(k," argument is a text prompt that contains a unique identifier, such as "),F=o(k,"CODE",{});var Me=n(F);H=i(Me,"sks"),Me.forEach(t),oe=i(k,", and the class the image belongs to, which in this example is "),P=o(k,"CODE",{});var se=n(P);x=i(se,"a photo of a sks dog"),se.forEach(t),te=i(k,"."),k.forEach(t),Q=f(m),y(Y.$$.fragment,m),z=f(m),N=o(m,"P",{});var ne=n(N);ue=i(ne,"Then you can launch the training script (you can find the full training script "),X=o(ne,"A",{href:!0,rel:!0});var K=n(X);W=i(K,"here"),K.forEach(t),de=i(ne,") with the following command:"),ne.forEach(t),le=f(m),y(V.$$.fragment,m),this.h()},h(){u(X,"href","https://github.com/huggingface/diffusers/blob/main/examples/dreambooth/train_dreambooth.py"),u(X,"rel","nofollow")},m(m,v){p(m,d,v),l(d,M),l(d,h),l(h,J),l(d,g),p(m,$,v),p(m,I,v),l(I,C),l(I,L),l(L,A),l(I,S),l(I,R),l(R,D),l(I,Z),l(I,ee),l(ee,fe),l(I,q),l(I,F),l(F,H),l(I,oe),l(I,P),l(P,x),l(I,te),p(m,Q,v),b(Y,m,v),p(m,z,v),p(m,N,v),l(N,ue),l(N,X),l(X,W),l(N,de),p(m,le,v),b(V,m,v),ae=!0},p:Ra,i(m){ae||(U(Y.$$.fragment,m),U(V.$$.fragment,m),ae=!0)},o(m){_(Y.$$.fragment,m),_(V.$$.fragment,m),ae=!1},d(m){m&&t(d),m&&t($),m&&t(I),m&&t(Q),T(Y,m),m&&t(z),m&&t(N),m&&t(le),T(V,m)}}}function Xd(j){let d,M;return d=new $a({props:{$$slots:{default:[Gd]},$$scope:{ctx:j}}}),{c(){w(d.$$.fragment)},l(h){y(d.$$.fragment,h)},m(h,J){b(d,h,J),M=!0},p(h,J){const g={};J&2&&(g.$$scope={dirty:J,ctx:h}),d.$set(g)},i(h){M||(U(d.$$.fragment,h),M=!0)},o(h){_(d.$$.fragment,h),M=!1},d(h){T(d,h)}}}function kd(j){let d,M,h,J,g,$,I,C,L,A,S,R,D,Z,ee,fe,q,F,H,oe,P,x,te,Q,Y,z,N,ue,X,W,de,le,V,ae;return A=new E({props:{code:"cGlwJTIwaW5zdGFsbCUyMC1VJTIwLXIlMjByZXF1aXJlbWVudHMudHh0",highlighted:"pip install -U -r requirements.txt"}}),V=new E({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=s("p"),M=r("If you have access to TPUs or want to train even faster, you can try out the "),h=s("a"),J=r("Flax training script"),g=r(". The Flax training script doesn\u2019t support gradient checkpointing or gradient accumulation, so you\u2019ll need a GPU with at least 30GB of memory."),$=c(),I=s("p"),C=r("Before running the script, make sure you have the requirements installed:"),L=c(),w(A.$$.fragment),S=c(),R=s("p"),D=r("Specify the "),Z=s("code"),ee=r("MODEL_NAME"),fe=r(" environment variable (either a Hub model repository id or a path to the directory containing the model weights) and pass it to the "),q=s("code"),F=r("pretrained_model_name_or_path"),H=r(" argument. The "),oe=s("code"),P=r("instance_prompt"),x=r(" argument is a text prompt that contains a unique identifier, such as "),te=s("code"),Q=r("sks"),Y=r(", and the class the image belongs to, which in this example is "),z=s("code"),N=r("a photo of a sks dog"),ue=r("."),X=c(),W=s("p"),de=r("Now you can launch the training script with the following command:"),le=c(),w(V.$$.fragment),this.h()},l(m){d=o(m,"P",{});var v=n(d);M=i(v,"If you have access to TPUs or want to train even faster, you can try out the "),h=o(v,"A",{href:!0,rel:!0});var O=n(h);J=i(O,"Flax training script"),O.forEach(t),g=i(v,". The Flax training script doesn\u2019t support gradient checkpointing or gradient accumulation, so you\u2019ll need a GPU with at least 30GB of memory."),v.forEach(t),$=f(m),I=o(m,"P",{});var k=n(I);C=i(k,"Before running the script, make sure you have the requirements installed:"),k.forEach(t),L=f(m),y(A.$$.fragment,m),S=f(m),R=o(m,"P",{});var G=n(R);D=i(G,"Specify the "),Z=o(G,"CODE",{});var Ue=n(Z);ee=i(Ue,"MODEL_NAME"),Ue.forEach(t),fe=i(G," environment variable (either a Hub model repository id or a path to the directory containing the model weights) and pass it to the "),q=o(G,"CODE",{});var _e=n(q);F=i(_e,"pretrained_model_name_or_path"),_e.forEach(t),H=i(G," argument. The "),oe=o(G,"CODE",{});var Me=n(oe);P=i(Me,"instance_prompt"),Me.forEach(t),x=i(G," argument is a text prompt that contains a unique identifier, such as "),te=o(G,"CODE",{});var se=n(te);Q=i(se,"sks"),se.forEach(t),Y=i(G,", and the class the image belongs to, which in this example is "),z=o(G,"CODE",{});var ne=n(z);N=i(ne,"a photo of a sks dog"),ne.forEach(t),ue=i(G,"."),G.forEach(t),X=f(m),W=o(m,"P",{});var K=n(W);de=i(K,"Now you can launch the training script with the following command:"),K.forEach(t),le=f(m),y(V.$$.fragment,m),this.h()},h(){u(h,"href","https://github.com/huggingface/diffusers/blob/main/examples/dreambooth/train_dreambooth_flax.py"),u(h,"rel","nofollow")},m(m,v){p(m,d,v),l(d,M),l(d,h),l(h,J),l(d,g),p(m,$,v),p(m,I,v),l(I,C),p(m,L,v),b(A,m,v),p(m,S,v),p(m,R,v),l(R,D),l(R,Z),l(Z,ee),l(R,fe),l(R,q),l(q,F),l(R,H),l(R,oe),l(oe,P),l(R,x),l(R,te),l(te,Q),l(R,Y),l(R,z),l(z,N),l(R,ue),p(m,X,v),p(m,W,v),l(W,de),p(m,le,v),b(V,m,v),ae=!0},p:Ra,i(m){ae||(U(A.$$.fragment,m),U(V.$$.fragment,m),ae=!0)},o(m){_(A.$$.fragment,m),_(V.$$.fragment,m),ae=!1},d(m){m&&t(d),m&&t($),m&&t(I),m&&t(L),T(A,m),m&&t(S),m&&t(R),m&&t(X),m&&t(W),m&&t(le),T(V,m)}}}function Zd(j){let d,M;return d=new $a({props:{$$slots:{default:[kd]},$$scope:{ctx:j}}}),{c(){w(d.$$.fragment)},l(h){y(d.$$.fragment,h)},m(h,J){b(d,h,J),M=!0},p(h,J){const g={};J&2&&(g.$$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EMSUyMCU1QyUwQSUyMCUyMC0tZ3JhZGllbnRfYWNjdW11bGF0aW9uX3N0ZXBzJTNEMSUyMCU1QyUwQSUyMCUyMC0tbGVhcm5pbmdfcmF0ZSUzRDVlLTYlMjAlNUMlMEElMjAlMjAtLWxyX3NjaGVkdWxlciUzRCUyMmNvbnN0YW50JTIyJTIwJTVDJTBBJTIwJTIwLS1scl93YXJtdXBfc3RlcHMlM0QwJTIwJTVDJTBBJTIwJTIwLS1udW1fY2xhc3NfaW1hZ2VzJTNEMjAwJTIwJTVDJTBBJTIwJTIwLS1tYXhfdHJhaW5fc3RlcHMlM0Q4MDAlMjAlNUMlMEElMjAlMjAtLXB1c2hfdG9faHVi",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:Ra,i(h){M||(U(d.$$.fragment,h),M=!0)},o(h){_(d.$$.fragment,h),M=!1},d(h){T(d,h)}}}function Ad(j){let d,M;return d=new $a({props:{$$slots:{default:[Cd]},$$scope:{ctx:j}}}),{c(){w(d.$$.fragment)},l(h){y(d.$$.fragment,h)},m(h,J){b(d,h,J),M=!0},p(h,J){const g={};J&2&&(g.$$scope={dirty:J,ctx:h}),d.$set(g)},i(h){M||(U(d.$$.fragment,h),M=!0)},o(h){_(d.$$.fragment,h),M=!1},d(h){T(d,h)}}}function Sd(j){let d,M;return d=new E({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:Ra,i(h){M||(U(d.$$.fragment,h),M=!0)},o(h){_(d.$$.fragment,h),M=!1},d(h){T(d,h)}}}function Fd(j){let d,M;return d=new $a({props:{$$slots:{default:[Sd]},$$scope:{ctx:j}}}),{c(){w(d.$$.fragment)},l(h){y(d.$$.fragment,h)},m(h,J){b(d,h,J),M=!0},p(h,J){const g={};J&2&&(g.$$scope={dirty:J,ctx:h}),d.$set(g)},i(h){M||(U(d.$$.fragment,h),M=!0)},o(h){_(d.$$.fragment,h),M=!1},d(h){T(d,h)}}}function Wd(j){let d,M;return{c(){d=s("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=o(h,"P",{});var J=n(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 Dd(j){let d,M;return d=new E({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:Ra,i(h){M||(U(d.$$.fragment,h),M=!0)},o(h){_(d.$$.fragment,h),M=!1},d(h){T(d,h)}}}function xd(j){let d,M;return d=new $a({props:{$$slots:{default:[Dd]},$$scope:{ctx:j}}}),{c(){w(d.$$.fragment)},l(h){y(d.$$.fragment,h)},m(h,J){b(d,h,J),M=!0},p(h,J){const g={};J&2&&(g.$$scope={dirty:J,ctx:h}),d.$set(g)},i(h){M||(U(d.$$.fragment,h),M=!0)},o(h){_(d.$$.fragment,h),M=!1},d(h){T(d,h)}}}function Qd(j){let d,M;return d=new E({props:{code:"ZXhwb3J0JTIwTU9ERUxfTkFNRSUzRCUyMmR1b25nbmElMkZzdGFibGUtZGlmZnVzaW9uLXYxLTQtZmxheCUyMiUwQWV4cG9ydCUyMElOU1RBTkNFX0RJUiUzRCUyMi4lMkZ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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:Ra,i(h){M||(U(d.$$.fragment,h),M=!0)},o(h){_(d.$$.fragment,h),M=!1},d(h){T(d,h)}}}function Yd(j){let d,M;return d=new $a({props:{$$slots:{default:[Qd]},$$scope:{ctx:j}}}),{c(){w(d.$$.fragment)},l(h){y(d.$$.fragment,h)},m(h,J){b(d,h,J),M=!0},p(h,J){const g={};J&2&&(g.$$scope={dirty:J,ctx:h}),d.$set(g)},i(h){M||(U(d.$$.fragment,h),M=!0)},o(h){_(d.$$.fragment,h),M=!1},d(h){T(d,h)}}}function zd(j){let d,M,h,J,g,$,I,C,L,A,S,R,D,Z,ee,fe,q,F,H,oe,P,x,te,Q,Y,z,N,ue,X,W,de,le,V,ae,m,v,O,k,G,Ue,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p,bl,Pp,Op,Mn,ye,Kp,Ul,Ts,eh,th,Js,lh,ah,wn,ca,sh,yn,fa,oh,bn,_l,Un,Xe,Tt,vs,Tl,nh,gs,rh,_n,ce,ih,ua,ph,hh,Is,ch,fh,Es,uh,dh,Tn,Jt,mh,js,Rs,Mh,wh,Jn,Jl,vn,vt,yh,da,bh,Uh,gn,ke,gt,$s,vl,_h,Ns,Th,In,be,Jh,gl,vh,gh,Il,Ih,Eh,En,ma,jh,jn,El,Rn,Ma,Rh,$n,jl,Vs,$h,Nh,Nn,Ze,Bs,Vh,Bh,Rl,Gh,Xh,Vn,$l,Gs,kh,Zh,Bn,Nl,Xs,Ch,Ah,Gn,Ce,It,ks,Vl,Sh,Zs,Fh,Xn,wa,Wh,kn,ya,Dh,Zn,ba,xh,Cn,Ua,Qh,An,_a,Yh,Sn,Ae,Et,Cs,Bl,zh,As,Lh,Fn,Ta,qh,Wn,Gl,Dn,Se,jt,Ss,Xl,Hh,Fs,Ph,xn,kl,Qn,Fe,Rt,Ws,Zl,Oh,Ds,Kh,Yn,Cl,xs,ec,tc,zn,Al,Qs,lc,ac,Ln,Sl,Ys,sc,oc,qn,Fl,zs,nc,rc,Hn,Wl,Pn,We,$t,Ls,Dl,ic,qs,pc,On,xl,Hs,hc,cc,Kn,Ql,Ps,fc,uc,er,Ja,dc,tr,Yl,lr,De,Nt,Os,zl,mc,Ks,Mc,ar,Ll,eo,wc,yc,sr,ql,to,bc,Uc,or,xe,lo,_c,Tc,ao,Jc,vc,nr,Hl,rr;return $=new B({}),S=new Vd({props:{classNames:"absolute z-10 right-0 top-0",options:[{label:"Mixed",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers_doc/en/dreambooth.ipynb"},{label:"PyTorch",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers_doc/en/pytorch/dreambooth.ipynb"},{label:"TensorFlow",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers_doc/en/tensorflow/dreambooth.ipynb"},{label:"Mixed",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/diffusers_doc/en/dreambooth.ipynb"},{label:"PyTorch",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/diffusers_doc/en/pytorch/dreambooth.ipynb"},{label:"TensorFlow",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/diffusers_doc/en/tensorflow/dreambooth.ipynb"}]}}),se=new E({props:{code:"cGlwJTIwaW5zdGFsbCUyMGdpdCUyQmh0dHBzJTNBJTJGJTJGZ2l0aHViLmNvbSUyRmh1Z2dpbmdmYWNlJTJGZGlmZnVzZXJzJTBBcGlwJTIwaW5zdGFsbCUyMC1VJTIwLXIlMjBkaWZmdXNlcnMlMkZleGFtcGxlcyUyRmRyZWFtYm9vdGglMkZyZXF1aXJlbWVudHMudHh0",highlighted:`pip install git+https://github.com/huggingface/diffusers
pip install -U -r diffusers/examples/dreambooth/requirements.txt`}}),Ct=new E({props:{code:"YWNjZWxlcmF0ZSUyMGNvbmZpZw==",highlighted:"accelerate config"}}),At=new E({props:{code:"YWNjZWxlcmF0ZSUyMGNvbmZpZyUyMGRlZmF1bHQ=",highlighted:"accelerate config default"}}),St=new E({props:{code:"ZnJvbSUyMGFjY2VsZXJhdGUudXRpbHMlMjBpbXBvcnQlMjB3cml0ZV9iYXNpY19jb25maWclMEElMEF3cml0ZV9iYXNpY19jb25maWcoKQ==",highlighted:`<span class="hljs-keyword">from</span> accelerate.utils <span class="hljs-keyword">import</span> write_basic_config

write_basic_config()`}}),Wt=new E({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>,
)`}}),Dt=new B({}),qe=new gd({props:{warning:!0,$$slots:{default:[Bd]},$$scope:{ctx:j}}}),He=new Zc({props:{pytorch:!0,tensorflow:!1,jax:!0,$$slots:{jax:[Zd],pytorch:[Xd]},$$scope:{ctx:j}}}),xt=new B({}),et=new Zc({props:{pytorch:!0,tensorflow:!1,jax:!0,$$slots:{jax:[Fd],pytorch:[Ad]},$$scope:{ctx:j}}}),Yt=new B({}),lt=new gd({props:{warning:!0,$$slots:{default:[Wd]},$$scope:{ctx:j}}}),at=new Zc({props:{pytorch:!0,tensorflow:!1,jax:!0,$$slots:{jax:[Yd],pytorch:[xd]},$$scope:{ctx:j}}}),Lt=new B({}),qt=new B({}),Ht=new E({props:{code:"JTIwJTIwLS1jaGVja3BvaW50aW5nX3N0ZXBzJTNENTAw",highlighted:"  --checkpointing_steps=500"}}),Pt=new B({}),Ot=new E({props:{code:"JTIwJTIwLS1yZXN1bWVfZnJvbV9jaGVja3BvaW50JTNEJTIyY2hlY2twb2ludC0xNTAwJTIy",highlighted:'  --resume_from_checkpoint=<span class="hljs-string">&quot;checkpoint-1500&quot;</span>'}}),Kt=new B({}),el=new E({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyM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lciUyQyUyMGR0eXBlJTNEdG9yY2guZmxvYXQxNiklMEFwaXBlbGluZS50byglMjJjdWRhJTIyKSUwQSUwQSUyMyUyMFBlcmZvcm0lMjBpbmZlcmVuY2UlMkMlMjBvciUyMHNhdmUlMkMlMjBvciUyMHB1c2glMjB0byUyMHRoZSUyMGh1YiUwQXBpcGVsaW5lLnNhdmVfcHJldHJhaW5lZCglMjJkcmVhbWJvb3RoLXBpcGVsaW5lJTIyKQ==",highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DiffusionPipeline, UNet2DConditionModel
<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> CLIPTextModel
<span class="hljs-keyword">import</span> torch

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

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

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

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

<span class="hljs-comment"># Perform inference, or save, or push to the hub</span>
pipeline.save_pretrained(<span class="hljs-string">&quot;dreambooth-pipeline&quot;</span>)`}}),tl=new E({props:{code:"ZnJvbSUyMGFjY2VsZXJhdGUlMjBpbXBvcnQlMjBBY2NlbGVyYXRvciUwQWZyb20lMjBkaWZmdXNlcnMlMjBpbXBvcnQlMjBEaWZmdXNpb25QaXBlbGluZSUwQSUwQSUyMyUyMExvYWQlMjB0aGUlMjBwaXBlbGluZSUyMHdpdGglMjB0aGUlMjBzYW1lJTIwYXJndW1lbnR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VzaW9uUGlwZWxpbmUuZnJvbV9wcmV0cmFpbmVkKCUwQSUyMCUyMCUyMCUyMG1vZGVsX2lkJTJDJTBBJTIwJTIwJTIwJTIwdW5ldCUzRGFjY2VsZXJhdG9yLnVud3JhcF9tb2RlbCh1bmV0KSUyQyUwQSUyMCUyMCUyMCUyMHRleHRfZW5jb2RlciUzRGFjY2VsZXJhdG9yLnVud3JhcF9tb2RlbCh0ZXh0X2VuY29kZXIpJTJDJTBBKSUwQSUwQSUyMyUyMFBlcmZvcm0lMjBpbmZlcmVuY2UlMkMlMjBvciUyMHNhdmUlMkMlMjBvciUyMHB1c2glMjB0byUyMHRoZSUyMGh1YiUwQXBpcGVsaW5lLnNhdmVfcHJldHJhaW5lZCglMjJkcmVhbWJvb3RoLXBpcGVsaW5lJTIyKQ==",highlighted:`<span class="hljs-keyword">from</span> accelerate <span class="hljs-keyword">import</span> Accelerator
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DiffusionPipeline

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

accelerator = Accelerator()

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

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

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

<span class="hljs-comment"># Perform inference, or save, or push to the hub</span>
pipeline.save_pretrained(<span class="hljs-string">&quot;dreambooth-pipeline&quot;</span>)`}}),ll=new B({}),al=new B({}),nl=new E({props:{code:"JTIwJTIwLS1lbmFibGVfeGZvcm1lcnNfbWVtb3J5X2VmZmljaWVudF9hdHRlbnRpb24=",highlighted:"  --enable_xformers_memory_efficient_attention"}}),rl=new B({}),pl=new E({props:{code:"JTIwJTIwLS1zZXRfZ3JhZHNfdG9fbm9uZQ==",highlighted:"  --set_grads_to_none"}}),hl=new B({}),fl=new E({props:{code:"cGlwJTIwaW5zdGFsbCUyMGJpdHNhbmRieXRlcw==",highlighted:"pip install bitsandbytes"}}),ul=new E({props:{code:"ZXhwb3J0JTIwTU9ERUxfTkFNRSUzRCUyMkNvbXBWaXMlMkZzdGFibGUtZGlmZnVzaW9uLXYxLTQlMjIlMEFleHBvcnQlMjBJTlNUQU5DRV9ESVIlM0QlMjIuJTJGZG9nJTIyJTBBZXhwb3J0JTIwQ0xBU1NfRElSJTNEJTIycGF0aF90b19jbGFzc19pbWFnZXMlMjIlMEFleHBvcnQlMjBPVVRQVVRfRElSJTNEJTIycGF0aF90b19zYXZlZF9tb2RlbCUyMiUwQSUwQWFjY2VsZXJhdGUlMjBsYXVuY2glMjB0cmFpbl9kcmVhbWJvb3RoLnB5JTIwJTVDJTBBJTIwJTIwLS1wcmV0cmFpbmVkX21vZGVsX25hbWVfb3JfcGF0aCUzRCUyNE1PREVMX05BTUUlMjAlMjAlNUMlMEElMjAlMjAtLWluc3RhbmNlX2RhdGFfZGlyJTNEJTI0SU5TVEFOQ0VfRElSJTIwJTVDJTBBJTIwJTIwLS1jbGFzc19kYXRhX2RpciUzRCUyNENMQVNTX0RJUiUyMCU1QyUwQSUyMCUyMC0tb3V0cHV0X2RpciUzRCUyNE9VVFBVVF9ESVIlMjAlNUMlMEElMjAlMjAtLXdpdGhfcHJpb3JfcHJlc2VydmF0aW9uJTIwLS1wcmlvcl9sb3NzX3dlaWdodCUzRDEuMCUyMCU1QyUwQSUyMCUyMC0taW5zdGFuY2VfcHJvbXB0JTNEJTIyYSUyMHBob3RvJTIwb2YlMjBza3MlMjBkb2clMjIlMjAlNUMlMEElMjAlMjAtLWNsYXNzX3Byb21wdCUzRCUyMmElMjBwaG90byUyMG9mJTIwZG9nJTIyJTIwJTVDJTBBJTIwJTIwLS1yZXNvbHV0aW9uJTNENTEyJTIwJTVDJTBBJTIwJTIwLS10cmFpbl9iYXRjaF9zaXplJTNEMSUyMCU1QyUwQSUyMCUyMC0tZ3JhZGllbnRfYWNjdW11bGF0aW9uX3N0ZXBzJTNEMiUyMC0tZ3JhZGllbnRfY2hlY2twb2ludGluZyUyMCU1QyUwQSUyMCUyMC0tdXNlXzhiaXRfYWRhbSUyMCU1QyUwQSUyMCUyMC0tbGVhcm5pbmdfcmF0ZSUzRDVlLTYlMjAlNUMlMEElMjAlMjAtLWxyX3NjaGVkdWxlciUzRCUyMmNvbnN0YW50JTIyJTIwJTVDJTBBJTIwJTIwLS1scl93YXJtdXBfc3RlcHMlM0QwJTIwJTVDJTBBJTIwJTIwLS1udW1fY2xhc3NfaW1hZ2VzJTNEMjAwJTIwJTVDJTBBJTIwJTIwLS1tYXhfdHJhaW5fc3RlcHMlM0Q4MDAlMjAlNUMlMEElMjAlMjAtLXB1c2hfdG9faHVi",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`}}),dl=new B({}),ml=new E({props:{code:"ZXhwb3J0JTIwTU9ERUxfTkFNRSUzRCUyMkNvbXBWaXMlMkZzdGFibGUtZGlmZnVzaW9uLXYxLTQlMjIlMEFleHBvcnQlMjBJTlNUQU5DRV9ESVIlM0QlMjIuJTJGZG9nJTIyJTBBZXhwb3J0JTIwQ0xBU1NfRElSJTNEJTIycGF0aC10by1jbGFzcy1pbWFnZXMlMjIlMEFleHBvcnQlMjBPVVRQVVRfRElSJTNEJTIycGF0aC10by1zYXZlLW1vZGVsJTIyJTBBJTBBYWNjZWxlcmF0ZSUyMGxhdW5jaCUyMHRyYWluX2RyZWFtYm9vdGgucHklMjAlNUMlMEElMjAlMjAtLXByZXRyYWluZWRfbW9kZWxfbmFtZV9vcl9wYXRoJTNEJTI0TU9ERUxfTkFNRSUyMCUyMCU1QyUwQSUyMCUyMC0taW5zdGFuY2VfZGF0YV9kaXIlM0QlMjRJTlNUQU5DRV9ESVIlMjAlNUMlMEElMjAlMjAtLWNsYXNzX2RhdGFfZGlyJTNEJTI0Q0xBU1NfRElSJTIwJTVDJTBBJTIwJTIwLS1vdXRwdXRfZGlyJTNEJTI0T1VUUFVUX0RJUiUyMCU1QyUwQSUyMCUyMC0td2l0aF9wcmlvcl9wcmVzZXJ2YXRpb24lMjAtLXByaW9yX2xvc3Nfd2VpZ2h0JTNEMS4wJTIwJTVDJTBBJTIwJTIwLS1pbnN0YW5jZV9wcm9tcHQlM0QlMjJhJTIwcGhvdG8lMjBvZiUyMHNrcyUyMGRvZyUyMiUyMCU1QyUwQSUyMCUyMC0tY2xhc3NfcHJvbXB0JTNEJTIyYSUyMHBob3RvJTIwb2YlMjBkb2clMjIlMjAlNUMlMEElMjAlMjAtLXJlc29sdXRpb24lM0Q1MTIlMjAlNUMlMEElMjAlMjAtLXRyYWluX2JhdGNoX3NpemUlM0QxJTIwJTVDJTBBJTIwJTIwLS1ncmFkaWVudF9hY2N1bXVsYXRpb25fc3RlcHMlM0QxJTIwLS1ncmFkaWVudF9jaGVja3BvaW50aW5nJTIwJTVDJTBBJTIwJTIwLS11c2VfOGJpdF9hZGFtJTIwJTVDJTBBJTIwJTIwLS1lbmFibGVfeGZvcm1lcnNfbWVtb3J5X2VmZmljaWVudF9hdHRlbnRpb24lMjAlNUMlMEElMjAlMjAtLXNldF9ncmFkc190b19ub25lJTIwJTVDJTBBJTIwJTIwLS1sZWFybmluZ19yYXRlJTNEMmUtNiUyMCU1QyUwQSUyMCUyMC0tbHJfc2NoZWR1bGVyJTNEJTIyY29uc3RhbnQlMjIlMjAlNUMlMEElMjAlMjAtLWxyX3dhcm11cF9zdGVwcyUzRDAlMjAlNUMlMEElMjAlMjAtLW51bV9jbGFzc19pbWFnZXMlM0QyMDAlMjAlNUMlMEElMjAlMjAtLW1heF90cmFpbl9zdGVwcyUzRDgwMCUyMCU1QyUwQSUyMCUyMC0tcHVzaF90b19odWI=",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`}}),Ml=new B({}),yl=new E({props:{code:"YWNjZWxlcmF0ZSUyMGNvbmZpZw==",highlighted:"accelerate config"}}),_l=new E({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`}}),Tl=new B({}),Jl=new E({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMERpZmZ1c2lvblBpcGVsaW5lJTBBaW1wb3J0JTIwdG9yY2glMEElMEFtb2RlbF9pZCUyMCUzRCUyMCUyMnBhdGhfdG9fc2F2ZWRfbW9kZWwlMjIlMEFwaXBlJTIwJTNEJTIwRGlmZnVzaW9uUGlwZWxpbmUuZnJvbV9wcmV0cmFpbmVkKG1vZGVsX2lkJTJDJTIwdG9yY2hfZHR5cGUlM0R0b3JjaC5mbG9hdDE2KS50byglMjJjdWRhJTIyKSUwQSUwQXByb21wdCUyMCUzRCUyMCUyMkElMjBwaG90byUyMG9mJTIwc2tzJTIwZG9nJTIwaW4lMjBhJTIwYnVja2V0JTIyJTBBaW1hZ2UlMjAlM0QlMjBwaXBlKHByb21wdCUyQyUyMG51bV9pbmZlcmVuY2Vfc3RlcHMlM0Q1MCUyQyUyMGd1aWRhbmNlX3NjYWxlJTNENy41KS5pbWFnZXMlNUIwJTVEJTBBJTBBaW1hZ2Uuc2F2ZSglMjJkb2ctYnVja2V0LnBuZyUyMik=",highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DiffusionPipeline
<span class="hljs-keyword">import</span> torch

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

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

image.save(<span class="hljs-string">&quot;dog-bucket.png&quot;</span>)`}}),vl=new B({}),El=new E({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMERpZmZ1c2lvblBpcGVsaW5lJTBBJTBBcGlwZSUyMCUzRCUyMERpZmZ1c2lvblBpcGVsaW5lLmZyb21fcHJldHJhaW5lZCglMjJEZWVwRmxveWQlMkZJRi1JLVhMLXYxLjAlMjIpJTBBJTBBcGlwZS5sb2FkX2xvcmFfd2VpZ2h0cyglMjIlM0Nsb3JhJTIwd2VpZ2h0cyUyMHBhdGglM0UlMjIpJTBBJTBBJTIzJTIwVXBkYXRlJTIwc2NoZWR1bGVyJTIwY29uZmlnJTIwdG8lMjBmaXhlZCUyMHZhcmlhbmNlJTIwc2NoZWR1bGUlMEFwaXBlLnNjaGVkdWxlciUyMCUzRCUyMHBpcGUuc2NoZWR1bGVyLl9fY2xhc3NfXy5mcm9tX2NvbmZpZyhwaXBlLnNjaGVkdWxlci5jb25maWclMkMlMjB2YXJpYW5jZV90eXBlJTNEJTIyZml4ZWRfc21hbGwlMjIp",highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DiffusionPipeline

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

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

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

This training configuration requires ~28 GB VRAM.

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

This training configuration requires ~28 GB VRAM.

	`),y(kl.$$.fragment,e),Qn=f(e),Fe=o(e,"H3",{class:!0});var Dr=n(Fe);Rt=o(Dr,"A",{id:!0,class:!0,href:!0});var od=n(Rt);Ws=o(od,"SPAN",{});var nd=n(Ws);y(Zl.$$.fragment,nd),nd.forEach(t),od.forEach(t),Oh=f(Dr),Ds=o(Dr,"SPAN",{});var rd=n(Ds);Kh=i(rd,"IF stage II LoRA Dreambooth"),rd.forEach(t),Dr.forEach(t),Yn=f(e),Cl=o(e,"P",{});var Rc=n(Cl);xs=o(Rc,"CODE",{});var id=n(xs);ec=i(id,"--validation_images"),id.forEach(t),tc=i(Rc,": These images are upscaled during validation steps."),Rc.forEach(t),zn=f(e),Al=o(e,"P",{});var $c=n(Al);Qs=o($c,"CODE",{});var pd=n(Qs);lc=i(pd,"--class_labels_conditioning=timesteps"),pd.forEach(t),ac=i($c,": Pass additional conditioning to the UNet needed for stage II."),$c.forEach(t),Ln=f(e),Sl=o(e,"P",{});var Nc=n(Sl);Ys=o(Nc,"CODE",{});var hd=n(Ys);sc=i(hd,"--learning_rate=1e-6"),hd.forEach(t),oc=i(Nc,": Lower learning rate than stage I."),Nc.forEach(t),qn=f(e),Fl=o(e,"P",{});var Vc=n(Fl);zs=o(Vc,"CODE",{});var cd=n(zs);nc=i(cd,"--resolution=256"),cd.forEach(t),rc=i(Vc,": The upscaler expects higher resolution inputs"),Vc.forEach(t),Hn=f(e),y(Wl.$$.fragment,e),Pn=f(e),We=o(e,"H3",{class:!0});var xr=n(We);$t=o(xr,"A",{id:!0,class:!0,href:!0});var fd=n($t);Ls=o(fd,"SPAN",{});var ud=n(Ls);y(Dl.$$.fragment,ud),ud.forEach(t),fd.forEach(t),ic=f(xr),qs=o(xr,"SPAN",{});var dd=n(qs);pc=i(dd,"IF Stage I Full Dreambooth"),dd.forEach(t),xr.forEach(t),On=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.
`),xl=o(e,"P",{});var Bc=n(xl);Hs=o(Bc,"CODE",{});var md=n(Hs);hc=i(md,"use_8bit_adam"),md.forEach(t),cc=i(Bc,": Due to the size of the optimizer states, we recommend training the full XL IF model with 8bit adam."),Bc.forEach(t),Kn=f(e),Ql=o(e,"P",{});var Gc=n(Ql);Ps=o(Gc,"CODE",{});var Md=n(Ps);fc=i(Md,"--learning_rate=1e-7"),Md.forEach(t),uc=i(Gc,`: 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.`),Gc.forEach(t),er=f(e),Ja=o(e,"P",{});var wd=n(Ja);dc=i(wd,"Using 8bit adam and a batch size of 4, the model can be trained in ~48 GB VRAM."),wd.forEach(t),tr=f(e),y(Yl.$$.fragment,e),lr=f(e),De=o(e,"H3",{class:!0});var Qr=n(De);Nt=o(Qr,"A",{id:!0,class:!0,href:!0});var yd=n(Nt);Os=o(yd,"SPAN",{});var bd=n(Os);y(zl.$$.fragment,bd),bd.forEach(t),yd.forEach(t),mc=f(Qr),Ks=o(Qr,"SPAN",{});var Ud=n(Ks);Mc=i(Ud,"IF Stage II Full Dreambooth"),Ud.forEach(t),Qr.forEach(t),ar=f(e),Ll=o(e,"P",{});var Xc=n(Ll);eo=o(Xc,"CODE",{});var _d=n(eo);wc=i(_d,"--learning_rate=5e-6"),_d.forEach(t),yc=i(Xc,`: With a smaller effective batch size of 4, we found that we required learning rates as low as
1e-8.`),Xc.forEach(t),sr=f(e),ql=o(e,"P",{});var kc=n(ql);to=o(kc,"CODE",{});var Td=n(to);bc=i(Td,"--resolution=256"),Td.forEach(t),Uc=i(kc,": The upscaler expects higher resolution inputs"),kc.forEach(t),or=f(e),xe=o(e,"P",{});var io=n(xe);lo=o(io,"CODE",{});var Jd=n(lo);_c=i(Jd,"--train_batch_size=2"),Jd.forEach(t),Tc=i(io," and "),ao=o(io,"CODE",{});var vd=n(ao);Jc=i(vd,"--gradient_accumulation_steps=6"),vd.forEach(t),vc=i(io,`: We found that full training of stage II particularly with
faces required large effective batch sizes.`),io.forEach(t),nr=f(e),y(Hl.$$.fragment,e),this.h()},h(){u(d,"name","hf:doc:metadata"),u(d,"content",JSON.stringify(Ld)),u(J,"id","dreambooth"),u(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"),u(J,"href","#dreambooth"),u(h,"class","relative group"),u(Z,"href","https://arxiv.org/abs/2208.12242"),u(Z,"rel","nofollow"),$d(H.src,oe="https://dreambooth.github.io/DreamBooth_files/teaser_static.jpg")||u(H,"src",oe),u(H,"alt","Dreambooth examples from the project's blog"),u(Q,"href","https://dreambooth.github.io"),u(X,"href","https://huggingface.co/CompVis/stable-diffusion-v1-4"),u(X,"rel","nofollow"),u(V,"href","https://github.com/huggingface/diffusers/tree/main/examples/dreambooth"),u(V,"rel","nofollow"),u(Kl,"href","../optimization/xformers"),u(Zt,"href","https://github.com/huggingface/accelerate/"),u(Zt,"rel","nofollow"),u(Ft,"href","https://huggingface.co/datasets/diffusers/dog-example"),u(Ft,"rel","nofollow"),u(la,"href","create_dataset"),u(Le,"id","finetuning"),u(Le,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),u(Le,"href","#finetuning"),u(Te,"class","relative group"),u(Pe,"id","finetuning-with-priorpreserving-loss"),u(Pe,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),u(Pe,"href","#finetuning-with-priorpreserving-loss"),u(Je,"class","relative group"),u(Qt,"href","https://arxiv.org/abs/2208.12242"),u(Qt,"rel","nofollow"),u(tt,"id","finetuning-the-text-encoder-and-unet"),u(tt,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),u(tt,"href","#finetuning-the-text-encoder-and-unet"),u(ve,"class","relative group"),u(zt,"href","https://huggingface.co/blog/dreambooth"),u(zt,"rel","nofollow"),u(st,"id","finetuning-with-lora"),u(st,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),u(st,"href","#finetuning-with-lora"),u(ge,"class","relative group"),u(aa,"href","./lora#dreambooth"),u(nt,"id","saving-checkpoints-while-training"),u(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"),u(nt,"href","#saving-checkpoints-while-training"),u(Ie,"class","relative group"),u(rt,"id","resume-training-from-a-saved-checkpoint"),u(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"),u(rt,"href","#resume-training-from-a-saved-checkpoint"),u(Ee,"class","relative group"),u(it,"id","inference-from-a-saved-checkpoint"),u(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"),u(it,"href","#inference-from-a-saved-checkpoint"),u(je,"class","relative group"),u(ct,"id","optimizations-for-different-gpu-sizes"),u(ct,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),u(ct,"href","#optimizations-for-different-gpu-sizes"),u(Re,"class","relative group"),u(ft,"id","xformers"),u(ft,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),u(ft,"href","#xformers"),u($e,"class","relative group"),u(sl,"href","https://github.com/facebookresearch/xformers"),u(sl,"rel","nofollow"),u(ol,"href","https://facebookresearch.github.io/xformers/components/ops.html#module-xformers.ops"),u(ol,"rel","nofollow"),u(ia,"href","./optimization/xformers"),u(ut,"id","set-gradients-to-none"),u(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"),u(ut,"href","#set-gradients-to-none"),u(Ne,"class","relative group"),u(il,"href","https://pytorch.org/docs/stable/generated/torch.optim.Optimizer.zero_grad.html"),u(il,"rel","nofollow"),u(dt,"id","16gb-gpu"),u(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"),u(dt,"href","#16gb-gpu"),u(Ve,"class","relative group"),u(cl,"href","https://github.com/TimDettmers/bitsandbytes"),u(cl,"rel","nofollow"),u(wt,"id","12gb-gpu"),u(wt,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),u(wt,"href","#12gb-gpu"),u(Be,"class","relative group"),u(bt,"id","8-gb-gpu"),u(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"),u(bt,"href","#8-gb-gpu"),u(Ge,"class","relative group"),u(wl,"href","https://www.deepspeed.ai/"),u(wl,"rel","nofollow"),u(bl,"href","https://huggingface.co/docs/accelerate/usage_guides/deepspeed"),u(bl,"rel","nofollow"),u(Ul,"href","https://deepspeed.readthedocs.io/en/latest/optimizers.html#adam-cpu"),u(Ul,"rel","nofollow"),u(Tt,"id","inference"),u(Tt,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),u(Tt,"href","#inference"),u(Xe,"class","relative group"),u(ua,"href","/docs/diffusers/v0.17.1/en/api/pipelines/stable_diffusion/text2img#diffusers.StableDiffusionPipeline"),u(da,"href","#inference-from-a-saved-checkpoint"),u(gt,"id","if"),u(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"),u(gt,"href","#if"),u(ke,"class","relative group"),u(gl,"href","https://huggingface.co/DeepFloyd/IF-I-XL-v1.0"),u(gl,"rel","nofollow"),u(Il,"href","https://huggingface.co/DeepFloyd/IF-II-L-v1.0"),u(Il,"rel","nofollow"),u(Rl,"href","https://huggingface.co/docs/transformers/model_doc/t5"),u(Rl,"rel","nofollow"),u(It,"id","tips-and-tricks"),u(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"),u(It,"href","#tips-and-tricks"),u(Ce,"class","relative group"),u(Et,"id","stage-ii-additional-validation-images"),u(Et,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),u(Et,"href","#stage-ii-additional-validation-images"),u(Ae,"class","relative group"),u(jt,"id","if-stage-i-lora-dreambooth"),u(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"),u(jt,"href","#if-stage-i-lora-dreambooth"),u(Se,"class","relative group"),u(Rt,"id","if-stage-ii-lora-dreambooth"),u(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"),u(Rt,"href","#if-stage-ii-lora-dreambooth"),u(Fe,"class","relative group"),u($t,"id","if-stage-i-full-dreambooth"),u($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"),u($t,"href","#if-stage-i-full-dreambooth"),u(We,"class","relative group"),u(Nt,"id","if-stage-ii-full-dreambooth"),u(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"),u(Nt,"href","#if-stage-ii-full-dreambooth"),u(De,"class","relative group")},m(e,a){l(document.head,d),p(e,M,a),p(e,h,a),l(h,J),l(J,g),b($,g,null),l(h,I),l(h,C),l(C,L),p(e,A,a),b(S,e,a),p(e,R,a),p(e,D,a),l(D,Z),l(Z,ee),l(D,fe),p(e,q,a),p(e,F,a),l(F,H),p(e,P,a),p(e,x,a),l(x,te),l(x,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fa),l(Fa,ji),l(ie,Ri),l(ie,Wa),l(Wa,$i),l(ie,Ni),p(e,$o,a),b(at,e,a),p(e,No,a),p(e,ge,a),l(ge,st),l(st,Da),b(Lt,Da,null),l(ge,Vi),l(ge,xa),l(xa,Bi),p(e,Vo,a),p(e,ot,a),l(ot,Gi),l(ot,aa),l(aa,Xi),l(ot,ki),p(e,Bo,a),p(e,Ie,a),l(Ie,nt),l(nt,Qa),b(qt,Qa,null),l(Ie,Zi),l(Ie,Ya),l(Ya,Ci),p(e,Go,a),p(e,sa,a),l(sa,Ai),p(e,Xo,a),b(Ht,e,a),p(e,ko,a),p(e,pe,a),l(pe,Si),l(pe,za),l(za,Fi),l(pe,Wi),l(pe,La),l(La,Di),l(pe,xi),l(pe,qa),l(qa,Qi),l(pe,Yi),p(e,Zo,a),p(e,Ee,a),l(Ee,rt),l(rt,Ha),b(Pt,Ha,null),l(Ee,zi),l(Ee,Pa),l(Pa,Li),p(e,Co,a),p(e,we,a),l(we,qi),l(we,Oa),l(Oa,Hi),l(we,Pi),l(we,Ka),l(Ka,Oi),l(we,Ki),p(e,Ao,a),b(Ot,e,a),p(e,So,a),p(e,oa,a),l(oa,ep),p(e,Fo,a),p(e,je,a),l(je,it),l(it,es),b(Kt,es,null),l(je,tp),l(je,ts),l(ts,lp),p(e,Wo,a),p(e,na,a),l(na,ap),p(e,Do,a),p(e,pt,a),l(pt,sp),l(pt,ls),l(ls,as),l(as,op),l(pt,np),p(e,xo,a),b(el,e,a),p(e,Qo,a),p(e,ht,a),l(ht,rp),l(ht,ss),l(ss,os),l(os,ip),l(ht,pp),p(e,Yo,a),b(tl,e,a),p(e,zo,a),p(e,Re,a),l(Re,ct),l(ct,ns),b(ll,ns,null),l(Re,hp),l(Re,rs),l(rs,cp),p(e,Lo,a),p(e,ra,a),l(ra,fp),p(e,qo,a),p(e,$e,a),l($e,ft),l(ft,is),b(al,is,null),l($e,up),l($e,ps),l(ps,dp),p(e,Ho,a),p(e,me,a),l(me,sl),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,Lh),p(e,Fn,a),p(e,Ta,a),l(Ta,qh),p(e,Wn,a),b(Gl,e,a),p(e,Dn,a),p(e,Se,a),l(Se,jt),l(jt,Ss),b(Xl,Ss,null),l(Se,Hh),l(Se,Fs),l(Fs,Ph),p(e,xn,a),b(kl,e,a),p(e,Qn,a),p(e,Fe,a),l(Fe,Rt),l(Rt,Ws),b(Zl,Ws,null),l(Fe,Oh),l(Fe,Ds),l(Ds,Kh),p(e,Yn,a),p(e,Cl,a),l(Cl,xs),l(xs,ec),l(Cl,tc),p(e,zn,a),p(e,Al,a),l(Al,Qs),l(Qs,lc),l(Al,ac),p(e,Ln,a),p(e,Sl,a),l(Sl,Ys),l(Ys,sc),l(Sl,oc),p(e,qn,a),p(e,Fl,a),l(Fl,zs),l(zs,nc),l(Fl,rc),p(e,Hn,a),b(Wl,e,a),p(e,Pn,a),p(e,We,a),l(We,$t),l($t,Ls),b(Dl,Ls,null),l(We,ic),l(We,qs),l(qs,pc),p(e,On,a),p(e,xl,a),l(xl,Hs),l(Hs,hc),l(xl,cc),p(e,Kn,a),p(e,Ql,a),l(Ql,Ps),l(Ps,fc),l(Ql,uc),p(e,er,a),p(e,Ja,a),l(Ja,dc),p(e,tr,a),b(Yl,e,a),p(e,lr,a),p(e,De,a),l(De,Nt),l(Nt,Os),b(zl,Os,null),l(De,mc),l(De,Ks),l(Ks,Mc),p(e,ar,a),p(e,Ll,a),l(Ll,eo),l(eo,wc),l(Ll,yc),p(e,sr,a),p(e,ql,a),l(ql,to),l(to,bc),l(ql,Uc),p(e,or,a),p(e,xe,a),l(xe,lo),l(lo,_c),l(xe,Tc),l(xe,ao),l(ao,Jc),l(xe,vc),p(e,nr,a),b(Hl,e,a),rr=!0},p(e,[a]){const Pl={};a&2&&(Pl.$$scope={dirty:a,ctx:e}),qe.$set(Pl);const so={};a&2&&(so.$$scope={dirty:a,ctx:e}),He.$set(so);const oo={};a&2&&(oo.$$scope={dirty:a,ctx:e}),et.$set(oo);const no={};a&2&&(no.$$scope={dirty:a,ctx:e}),lt.$set(no);const va={};a&2&&(va.$$scope={dirty:a,ctx:e}),at.$set(va)},i(e){rr||(U($.$$.fragment,e),U(S.$$.fragment,e),U(se.$$.fragment,e),U(Ct.$$.fragment,e),U(At.$$.fragment,e),U(St.$$.fragment,e),U(Wt.$$.fragment,e),U(Dt.$$.fragment,e),U(qe.$$.fragment,e),U(He.$$.fragment,e),U(xt.$$.fragment,e),U(et.$$.fragment,e),U(Yt.$$.fragment,e),U(lt.$$.fragment,e),U(at.$$.fragment,e),U(Lt.$$.fragment,e),U(qt.$$.fragment,e),U(Ht.$$.fragment,e),U(Pt.$$.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(nl.$$.fragment,e),U(rl.$$.fragment,e),U(pl.$$.fragment,e),U(hl.$$.fragment,e),U(fl.$$.fragment,e),U(ul.$$.fragment,e),U(dl.$$.fragment,e),U(ml.$$.fragment,e),U(Ml.$$.fragment,e),U(yl.$$.fragment,e),U(_l.$$.fragment,e),U(Tl.$$.fragment,e),U(Jl.$$.fragment,e),U(vl.$$.fragment,e),U(El.$$.fragment,e),U(Vl.$$.fragment,e),U(Bl.$$.fragment,e),U(Gl.$$.fragment,e),U(Xl.$$.fragment,e),U(kl.$$.fragment,e),U(Zl.$$.fragment,e),U(Wl.$$.fragment,e),U(Dl.$$.fragment,e),U(Yl.$$.fragment,e),U(zl.$$.fragment,e),U(Hl.$$.fragment,e),rr=!0)},o(e){_($.$$.fragment,e),_(S.$$.fragment,e),_(se.$$.fragment,e),_(Ct.$$.fragment,e),_(At.$$.fragment,e),_(St.$$.fragment,e),_(Wt.$$.fragment,e),_(Dt.$$.fragment,e),_(qe.$$.fragment,e),_(He.$$.fragment,e),_(xt.$$.fragment,e),_(et.$$.fragment,e),_(Yt.$$.fragment,e),_(lt.$$.fragment,e),_(at.$$.fragment,e),_(Lt.$$.fragment,e),_(qt.$$.fragment,e),_(Ht.$$.fragment,e),_(Pt.$$.fragment,e),_(Ot.$$.fragment,e),_(Kt.$$.fragment,e),_(el.$$.fragment,e),_(tl.$$.fragment,e),_(ll.$$.fragment,e),_(al.$$.fragment,e),_(nl.$$.fragment,e),_(rl.$$.fragment,e),_(pl.$$.fragment,e),_(hl.$$.fragment,e),_(fl.$$.fragment,e),_(ul.$$.fragment,e),_(dl.$$.fragment,e),_(ml.$$.fragment,e),_(Ml.$$.fragment,e),_(yl.$$.fragment,e),_(_l.$$.fragment,e),_(Tl.$$.fragment,e),_(Jl.$$.fragment,e),_(vl.$$.fragment,e),_(El.$$.fragment,e),_(Vl.$$.fragment,e),_(Bl.$$.fragment,e),_(Gl.$$.fragment,e),_(Xl.$$.fragment,e),_(kl.$$.fragment,e),_(Zl.$$.fragment,e),_(Wl.$$.fragment,e),_(Dl.$$.fragment,e),_(Yl.$$.fragment,e),_(zl.$$.fragment,e),_(Hl.$$.fragment,e),rr=!1},d(e){t(d),e&&t(M),e&&t(h),T($),e&&t(A),T(S,e),e&&t(R),e&&t(D),e&&t(q),e&&t(F),e&&t(P),e&&t(x),e&&t(z),e&&t(N),e&&t(v),e&&t(O),e&&t(Me),T(se,e),e&&t(ne),e&&t(K),e&&t(po),e&&t(Qe),e&&t(ho),T(Ct,e),e&&t(co),e&&t(ea),e&&t(fo),T(At,e),e&&t(uo),e&&t(ta),e&&t(mo),T(St,e),e&&t(Mo),e&&t(Ye),e&&t(wo),T(Wt,e),e&&t(yo),e&&t(ze),e&&t(bo),e&&t(Te),T(Dt),e&&t(Uo),T(qe,e),e&&t(_o),T(He,e),e&&t(To),e&&t(Je),T(xt),e&&t(Jo),e&&t(Oe),e&&t(vo),e&&t(Ke),e&&t(go),T(et,e),e&&t(Io),e&&t(ve),T(Yt),e&&t(Eo),e&&t(re),e&&t(jo),T(lt,e),e&&t(Ro),e&&t(ie),e&&t($o),T(at,e),e&&t(No),e&&t(ge),T(Lt),e&&t(Vo),e&&t(ot),e&&t(Bo),e&&t(Ie),T(qt),e&&t(Go),e&&t(sa),e&&t(Xo),T(Ht,e),e&&t(ko),e&&t(pe),e&&t(Zo),e&&t(Ee),T(Pt),e&&t(Co),e&&t(we),e&&t(Ao),T(Ot,e),e&&t(So),e&&t(oa),e&&t(Fo),e&&t(je),T(Kt),e&&t(Wo),e&&t(na),e&&t(Do),e&&t(pt),e&&t(xo),T(el,e),e&&t(Qo),e&&t(ht),e&&t(Yo),T(tl,e),e&&t(zo),e&&t(Re),T(ll),e&&t(Lo),e&&t(ra),e&&t(qo),e&&t($e),T(al),e&&t(Ho),e&&t(me),e&&t(Po),T(nl,e),e&&t(Oo),e&&t(pa),e&&t(Ko),e&&t(Ne),T(rl),e&&t(en),e&&t(he),e&&t(tn),T(pl,e),e&&t(ln),e&&t(Ve),T(hl),e&&t(an),e&&t(mt),e&&t(sn),T(fl,e),e&&t(on),e&&t(Mt),e&&t(nn),T(ul,e),e&&t(rn),e&&t(Be),T(dl),e&&t(pn),e&&t(yt),e&&t(hn),T(ml,e),e&&t(cn),e&&t(Ge),T(Ml),e&&t(fn),e&&t(Ut),e&&t(un),e&&t(ha),e&&t(dn),T(yl,e),e&&t(mn),e&&t(_t),e&&t(Mn),e&&t(ye),e&&t(wn),e&&t(ca),e&&t(yn),e&&t(fa),e&&t(bn),T(_l,e),e&&t(Un),e&&t(Xe),T(Tl),e&&t(_n),e&&t(ce),e&&t(Tn),e&&t(Jt),e&&t(Jn),T(Jl,e),e&&t(vn),e&&t(vt),e&&t(gn),e&&t(ke),T(vl),e&&t(In),e&&t(be),e&&t(En),e&&t(ma),e&&t(jn),T(El,e),e&&t(Rn),e&&t(Ma),e&&t($n),e&&t(jl),e&&t(Nn),e&&t(Ze),e&&t(Vn),e&&t($l),e&&t(Bn),e&&t(Nl),e&&t(Gn),e&&t(Ce),T(Vl),e&&t(Xn),e&&t(wa),e&&t(kn),e&&t(ya),e&&t(Zn),e&&t(ba),e&&t(Cn),e&&t(Ua),e&&t(An),e&&t(_a),e&&t(Sn),e&&t(Ae),T(Bl),e&&t(Fn),e&&t(Ta),e&&t(Wn),T(Gl,e),e&&t(Dn),e&&t(Se),T(Xl),e&&t(xn),T(kl,e),e&&t(Qn),e&&t(Fe),T(Zl),e&&t(Yn),e&&t(Cl),e&&t(zn),e&&t(Al),e&&t(Ln),e&&t(Sl),e&&t(qn),e&&t(Fl),e&&t(Hn),T(Wl,e),e&&t(Pn),e&&t(We),T(Dl),e&&t(On),e&&t(xl),e&&t(Kn),e&&t(Ql),e&&t(er),e&&t(Ja),e&&t(tr),T(Yl,e),e&&t(lr),e&&t(De),T(zl),e&&t(ar),e&&t(Ll),e&&t(sr),e&&t(ql),e&&t(or),e&&t(xe),e&&t(nr),T(Hl,e)}}}const Ld={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"}],title:"DreamBooth"};function qd(j){return Nd(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class lm extends Id{constructor(d){super();Ed(this,d,qd,zd,jd,{})}}export{lm as default,Ld as metadata};
