import{S as Ar,i as Br,s as Cr,e as r,k as d,w as y,t as l,M as Sr,c as s,d as a,m as w,a as n,x as M,h as o,b as f,G as t,g as h,y as b,q as T,o as v,B as J,v as Fr,L as ul}from"../../chunks/vendor-hf-doc-builder.js";import{T as Xr}from"../../chunks/Tip-hf-doc-builder.js";import{I as He}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{C as Ue}from"../../chunks/CodeBlock-hf-doc-builder.js";import{F as Zr,M as ml}from"../../chunks/Markdown-hf-doc-builder.js";function Gr(X){let p,_;return{c(){p=r("p"),_=l("The text-to-image fine-tuning script is experimental. It\u2019s easy to overfit and run into issues like catastrophic forgetting. We recommend you explore different hyperparameters to get the best results on your dataset.")},l(i){p=s(i,"P",{});var g=n(p);_=o(g,"The text-to-image fine-tuning script is experimental. It\u2019s easy to overfit and run into issues like catastrophic forgetting. We recommend you explore different hyperparameters to get the best results on your dataset."),g.forEach(a)},m(i,g){h(i,p,g),t(p,_)},d(i){i&&a(p)}}}function Vr(X){let p,_,i,g,W,Z,ue,ge,ye,x,P,I,V,Me,B,re,se,be,O,ne,Te,k,me,C,$e,ie,Q,A,Ee,E,xe,pe,ve,R,K,ee,Re,te,S,ae,de,N,he,le,H,z,j,F,we,u,U,Je,L,oe,ke,Fe,_e,fe,Ge,Y,Ie,q,Ne,G,Xe;return ne=new Ue({props:{code:"ZXhwb3J0JTIwTU9ERUxfTkFNRSUzRCUyMkNvbXBWaXMlMkZzdGFibGUtZGlmZnVzaW9uLXYxLTQlMjIlMEFleHBvcnQlMjBkYXRhc2V0X25hbWUlM0QlMjJsYW1iZGFsYWJzJTJGcG9rZW1vbi1ibGlwLWNhcHRpb25zJTIyJTBBJTBBYWNjZWxlcmF0ZSUyMGxhdW5jaCUyMC0tbWl4ZWRfcHJlY2lzaW9uJTNEJTIyZnAxNiUyMiUyMCUyMHRyYWluX3RleHRfdG9faW1hZ2UucHklMjAlNUMlMEElMjAlMjAtLXByZXRyYWluZWRfbW9kZWxfbmFtZV9vcl9wYXRoJTNEJTI0TU9ERUxfTkFNRSUyMCU1QyUwQSUyMCUyMC0tZGF0YXNldF9uYW1lJTNEJTI0ZGF0YXNldF9uYW1lJTIwJTVDJTBBJTIwJTIwLS11c2VfZW1hJTIwJTVDJTBBJTIwJTIwLS1yZXNvbHV0aW9uJTNENTEyJTIwLS1jZW50ZXJfY3JvcCUyMC0tcmFuZG9tX2ZsaXAlMjAlNUMlMEElMjAlMjAtLXRyYWluX2JhdGNoX3NpemUlM0QxJTIwJTVDJTBBJTIwJTIwLS1ncmFkaWVudF9hY2N1bXVsYXRpb25fc3RlcHMlM0Q0JTIwJTVDJTBBJTIwJTIwLS1ncmFkaWVudF9jaGVja3BvaW50aW5nJTIwJTVDJTBBJTIwJTIwLS1tYXhfdHJhaW5fc3RlcHMlM0QxNTAwMCUyMCU1QyUwQSUyMCUyMC0tbGVhcm5pbmdfcmF0ZSUzRDFlLTA1JTIwJTVDJTBBJTIwJTIwLS1tYXhfZ3JhZF9ub3JtJTNEMSUyMCU1QyUwQSUyMCUyMC0tbHJfc2NoZWR1bGVyJTNEJTIyY29uc3RhbnQlMjIlMjAtLWxyX3dhcm11cF9zdGVwcyUzRDAlMjAlNUMlMEElMjAlMjAtLW91dHB1dF9kaXIlM0QlMjJzZC1wb2tlbW9uLW1vZGVsJTIyJTIwJTVDJTBBJTIwJTIwLS1wdXNoX3RvX2h1Yg==",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> dataset_name=<span class="hljs-string">&quot;lambdalabs/pokemon-blip-captions&quot;</span>

accelerate launch --mixed_precision=<span class="hljs-string">&quot;fp16&quot;</span>  train_text_to_image.py \\
  --pretrained_model_name_or_path=<span class="hljs-variable">$MODEL_NAME</span> \\
  --dataset_name=<span class="hljs-variable">$dataset_name</span> \\
  --use_ema \\
  --resolution=512 --center_crop --random_flip \\
  --train_batch_size=1 \\
  --gradient_accumulation_steps=4 \\
  --gradient_checkpointing \\
  --max_train_steps=15000 \\
  --learning_rate=1e-05 \\
  --max_grad_norm=1 \\
  --lr_scheduler=<span class="hljs-string">&quot;constant&quot;</span> --lr_warmup_steps=0 \\
  --output_dir=<span class="hljs-string">&quot;sd-pokemon-model&quot;</span> \\
  --push_to_hub`}}),he=new Ue({props:{code:"ZXhwb3J0JTIwTU9ERUxfTkFNRSUzRCUyMkNvbXBWaXMlMkZzdGFibGUtZGlmZnVzaW9uLXYxLTQlMjIlMEFleHBvcnQlMjBUUkFJTl9ESVIlM0QlMjJwYXRoX3RvX3lvdXJfZGF0YXNldCUyMiUwQWV4cG9ydCUyME9VVFBVVF9ESVIlM0QlMjJwYXRoX3RvX3NhdmVfbW9kZWwlMjIlMEElMEFhY2NlbGVyYXRlJTIwbGF1bmNoJTIwdHJhaW5fdGV4dF90b19pbWFnZS5weSUyMCU1QyUwQSUyMCUyMC0tcHJldHJhaW5lZF9tb2RlbF9uYW1lX29yX3BhdGglM0QlMjRNT0RFTF9OQU1FJTIwJTVDJTBBJTIwJTIwLS10cmFpbl9kYXRhX2RpciUzRCUyNFRSQUlOX0RJUiUyMCU1QyUwQSUyMCUyMC0tdXNlX2VtYSUyMCU1QyUwQSUyMCUyMC0tcmVzb2x1dGlvbiUzRDUxMiUyMC0tY2VudGVyX2Nyb3AlMjAtLXJhbmRvbV9mbGlwJTIwJTVDJTBBJTIwJTIwLS10cmFpbl9iYXRjaF9zaXplJTNEMSUyMCU1QyUwQSUyMCUyMC0tZ3JhZGllbnRfYWNjdW11bGF0aW9uX3N0ZXBzJTNENCUyMCU1QyUwQSUyMCUyMC0tZ3JhZGllbnRfY2hlY2twb2ludGluZyUyMCU1QyUwQSUyMCUyMC0tbWl4ZWRfcHJlY2lzaW9uJTNEJTIyZnAxNiUyMiUyMCU1QyUwQSUyMCUyMC0tbWF4X3RyYWluX3N0ZXBzJTNEMTUwMDAlMjAlNUMlMEElMjAlMjAtLWxlYXJuaW5nX3JhdGUlM0QxZS0wNSUyMCU1QyUwQSUyMCUyMC0tbWF4X2dyYWRfbm9ybSUzRDElMjAlNUMlMEElMjAlMjAtLWxyX3NjaGVkdWxlciUzRCUyMmNvbnN0YW50JTIyJTIwJTBBJTIwJTIwLS1scl93YXJtdXBfc3RlcHMlM0QwJTIwJTVDJTBBJTIwJTIwLS1vdXRwdXRfZGlyJTNEJTI0JTdCT1VUUFVUX0RJUiU3RCUyMCU1QyUwQSUyMCUyMC0tcHVzaF90b19odWI=",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> TRAIN_DIR=<span class="hljs-string">&quot;path_to_your_dataset&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_text_to_image.py \\
  --pretrained_model_name_or_path=<span class="hljs-variable">$MODEL_NAME</span> \\
  --train_data_dir=<span class="hljs-variable">$TRAIN_DIR</span> \\
  --use_ema \\
  --resolution=512 --center_crop --random_flip \\
  --train_batch_size=1 \\
  --gradient_accumulation_steps=4 \\
  --gradient_checkpointing \\
  --mixed_precision=<span class="hljs-string">&quot;fp16&quot;</span> \\
  --max_train_steps=15000 \\
  --learning_rate=1e-05 \\
  --max_grad_norm=1 \\
  --lr_scheduler=<span class="hljs-string">&quot;constant&quot;</span> 
  --lr_warmup_steps=0 \\
  --output_dir=<span class="hljs-variable">\${OUTPUT_DIR}</span> \\
  --push_to_hub`}}),F=new He({}),G=new Ue({props:{code:"ZXhwb3J0JTIwTU9ERUxfTkFNRSUzRCUyMkNvbXBWaXMlMkZzdGFibGUtZGlmZnVzaW9uLXYxLTQlMjIlMEFleHBvcnQlMjBkYXRhc2V0X25hbWUlM0QlMjJsYW1iZGFsYWJzJTJGcG9rZW1vbi1ibGlwLWNhcHRpb25zJTIyJTBBJTBBYWNjZWxlcmF0ZSUyMGxhdW5jaCUyMC0tbWl4ZWRfcHJlY2lzaW9uJTNEJTIyZnAxNiUyMiUyMC0tbXVsdGlfZ3B1JTIwJTIwdHJhaW5fdGV4dF90b19pbWFnZS5weSUyMCU1QyUwQSUyMCUyMC0tcHJldHJhaW5lZF9tb2RlbF9uYW1lX29yX3BhdGglM0QlMjRNT0RFTF9OQU1FJTIwJTVDJTBBJTIwJTIwLS1kYXRhc2V0X25hbWUlM0QlMjRkYXRhc2V0X25hbWUlMjAlNUMlMEElMjAlMjAtLXVzZV9lbWElMjAlNUMlMEElMjAlMjAtLXJlc29sdXRpb24lM0Q1MTIlMjAtLWNlbnRlcl9jcm9wJTIwLS1yYW5kb21fZmxpcCUyMCU1QyUwQSUyMCUyMC0tdHJhaW5fYmF0Y2hfc2l6ZSUzRDElMjAlNUMlMEElMjAlMjAtLWdyYWRpZW50X2FjY3VtdWxhdGlvbl9zdGVwcyUzRDQlMjAlNUMlMEElMjAlMjAtLWdyYWRpZW50X2NoZWNrcG9pbnRpbmclMjAlNUMlMEElMjAlMjAtLW1heF90cmFpbl9zdGVwcyUzRDE1MDAwJTIwJTVDJTIwJTBBJTIwJTIwLS1sZWFybmluZ19yYXRlJTNEMWUtMDUlMjAlNUMlMEElMjAlMjAtLW1heF9ncmFkX25vcm0lM0QxJTIwJTVDJTBBJTIwJTIwLS1scl9zY2hlZHVsZXIlM0QlMjJjb25zdGFudCUyMiUyMCU1QyUwQSUyMCUyMC0tbHJfd2FybXVwX3N0ZXBzJTNEMCUyMCU1QyUwQSUyMCUyMC0tb3V0cHV0X2RpciUzRCUyMnNkLXBva2Vtb24tbW9kZWwlMjIlMjAlNUMlMEElMjAlMjAtLXB1c2hfdG9faHVi",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> dataset_name=<span class="hljs-string">&quot;lambdalabs/pokemon-blip-captions&quot;</span>

accelerate launch --mixed_precision=<span class="hljs-string">&quot;fp16&quot;</span> --multi_gpu  train_text_to_image.py \\
  --pretrained_model_name_or_path=<span class="hljs-variable">$MODEL_NAME</span> \\
  --dataset_name=<span class="hljs-variable">$dataset_name</span> \\
  --use_ema \\
  --resolution=512 --center_crop --random_flip \\
  --train_batch_size=1 \\
  --gradient_accumulation_steps=4 \\
  --gradient_checkpointing \\
  --max_train_steps=15000 \\ 
  --learning_rate=1e-05 \\
  --max_grad_norm=1 \\
  --lr_scheduler=<span class="hljs-string">&quot;constant&quot;</span> \\
  --lr_warmup_steps=0 \\
  --output_dir=<span class="hljs-string">&quot;sd-pokemon-model&quot;</span> \\
  --push_to_hub`}}),{c(){p=r("p"),_=l("Launch the "),i=r("a"),g=l("PyTorch training script"),W=l(" for a fine-tuning run on the "),Z=r("a"),ue=l("Pok\xE9mon BLIP captions"),ge=l(" dataset like this."),ye=d(),x=r("p"),P=l("Specify the "),I=r("code"),V=l("MODEL_NAME"),Me=l(" environment variable (either a Hub model repository id or a path to the directory containing the model weights) and pass it to the "),B=r("a"),re=r("code"),se=l("pretrained_model_name_or_path"),be=l(" argument."),O=d(),y(ne.$$.fragment),Te=d(),k=r("p"),me=l("To finetune on your own dataset, prepare the dataset according to the format required by \u{1F917} "),C=r("a"),$e=l("Datasets"),ie=l(". You can "),Q=r("a"),A=l("upload your dataset to the Hub"),Ee=l(", or you can "),E=r("a"),xe=l("prepare a local folder with your files"),pe=l("."),ve=d(),R=r("p"),K=l("Modify the script if you want to use custom loading logic. We left pointers in the code in the appropriate places to help you. \u{1F917} The example script below shows how to finetune on a local dataset in "),ee=r("code"),Re=l("TRAIN_DIR"),te=l(" and where to save the model to in "),S=r("code"),ae=l("OUTPUT_DIR"),de=l(":"),N=d(),y(he.$$.fragment),le=d(),H=r("h4"),z=r("a"),j=r("span"),y(F.$$.fragment),we=d(),u=r("span"),U=l("Training with multiple GPUs"),Je=d(),L=r("p"),oe=r("code"),ke=l("accelerate"),Fe=l(" allows for seamless multi-GPU training. Follow the instructions "),_e=r("a"),fe=l("here"),Ge=l(`
for running distributed training with `),Y=r("code"),Ie=l("accelerate"),q=l(". Here is an example command:"),Ne=d(),y(G.$$.fragment),this.h()},l(m){p=s(m,"P",{});var $=n(p);_=o($,"Launch the "),i=s($,"A",{href:!0,rel:!0});var Gt=n(i);g=o(Gt,"PyTorch training script"),Gt.forEach(a),W=o($," for a fine-tuning run on the "),Z=s($,"A",{href:!0,rel:!0});var Vt=n(Z);ue=o(Vt,"Pok\xE9mon BLIP captions"),Vt.forEach(a),ge=o($," dataset like this."),$.forEach(a),ye=w(m),x=s(m,"P",{});var Ze=n(x);P=o(Ze,"Specify the "),I=s(Ze,"CODE",{});var ze=n(I);V=o(ze,"MODEL_NAME"),ze.forEach(a),Me=o(Ze," environment variable (either a Hub model repository id or a path to the directory containing the model weights) and pass it to the "),B=s(Ze,"A",{href:!0,rel:!0});var Lt=n(B);re=s(Lt,"CODE",{});var Tt=n(re);se=o(Tt,"pretrained_model_name_or_path"),Tt.forEach(a),Lt.forEach(a),be=o(Ze," argument."),Ze.forEach(a),O=w(m),M(ne.$$.fragment,m),Te=w(m),k=s(m,"P",{});var D=n(k);me=o(D,"To finetune on your own dataset, prepare the dataset according to the format required by \u{1F917} "),C=s(D,"A",{href:!0,rel:!0});var Ae=n(C);$e=o(Ae,"Datasets"),Ae.forEach(a),ie=o(D,". You can "),Q=s(D,"A",{href:!0,rel:!0});var ot=n(Q);A=o(ot,"upload your dataset to the Hub"),ot.forEach(a),Ee=o(D,", or you can "),E=s(D,"A",{href:!0,rel:!0});var Ve=n(E);xe=o(Ve,"prepare a local folder with your files"),Ve.forEach(a),pe=o(D,"."),D.forEach(a),ve=w(m),R=s(m,"P",{});var Le=n(R);K=o(Le,"Modify the script if you want to use custom loading logic. We left pointers in the code in the appropriate places to help you. \u{1F917} The example script below shows how to finetune on a local dataset in "),ee=s(Le,"CODE",{});var rt=n(ee);Re=o(rt,"TRAIN_DIR"),rt.forEach(a),te=o(Le," and where to save the model to in "),S=s(Le,"CODE",{});var Yt=n(S);ae=o(Yt,"OUTPUT_DIR"),Yt.forEach(a),de=o(Le,":"),Le.forEach(a),N=w(m),M(he.$$.fragment,m),le=w(m),H=s(m,"H4",{class:!0});var qe=n(H);z=s(qe,"A",{id:!0,class:!0,href:!0});var Oe=n(z);j=s(Oe,"SPAN",{});var Dt=n(j);M(F.$$.fragment,Dt),Dt.forEach(a),Oe.forEach(a),we=w(qe),u=s(qe,"SPAN",{});var vt=n(u);U=o(vt,"Training with multiple GPUs"),vt.forEach(a),qe.forEach(a),Je=w(m),L=s(m,"P",{});var ce=n(L);oe=s(ce,"CODE",{});var Jt=n(oe);ke=o(Jt,"accelerate"),Jt.forEach(a),Fe=o(ce," allows for seamless multi-GPU training. Follow the instructions "),_e=s(ce,"A",{href:!0,rel:!0});var We=n(_e);fe=o(We,"here"),We.forEach(a),Ge=o(ce,`
for running distributed training with `),Y=s(ce,"CODE",{});var Be=n(Y);Ie=o(Be,"accelerate"),Be.forEach(a),q=o(ce,". Here is an example command:"),ce.forEach(a),Ne=w(m),M(G.$$.fragment,m),this.h()},h(){f(i,"href","https://github.com/huggingface/diffusers/blob/main/examples/text_to_image/train_text_to_image.py"),f(i,"rel","nofollow"),f(Z,"href","https://huggingface.co/datasets/lambdalabs/pokemon-blip-captions"),f(Z,"rel","nofollow"),f(B,"href","https://huggingface.co/docs/diffusers/en/api/diffusion_pipeline#diffusers.DiffusionPipeline.from_pretrained.pretrained_model_name_or_path"),f(B,"rel","nofollow"),f(C,"href","https://huggingface.co/docs/datasets/index"),f(C,"rel","nofollow"),f(Q,"href","https://huggingface.co/docs/datasets/image_dataset#upload-dataset-to-the-hub"),f(Q,"rel","nofollow"),f(E,"href","https://huggingface.co/docs/datasets/image_dataset#imagefolder"),f(E,"rel","nofollow"),f(z,"id","training-with-multiple-gpus"),f(z,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),f(z,"href","#training-with-multiple-gpus"),f(H,"class","relative group"),f(_e,"href","https://huggingface.co/docs/accelerate/basic_tutorials/launch"),f(_e,"rel","nofollow")},m(m,$){h(m,p,$),t(p,_),t(p,i),t(i,g),t(p,W),t(p,Z),t(Z,ue),t(p,ge),h(m,ye,$),h(m,x,$),t(x,P),t(x,I),t(I,V),t(x,Me),t(x,B),t(B,re),t(re,se),t(x,be),h(m,O,$),b(ne,m,$),h(m,Te,$),h(m,k,$),t(k,me),t(k,C),t(C,$e),t(k,ie),t(k,Q),t(Q,A),t(k,Ee),t(k,E),t(E,xe),t(k,pe),h(m,ve,$),h(m,R,$),t(R,K),t(R,ee),t(ee,Re),t(R,te),t(R,S),t(S,ae),t(R,de),h(m,N,$),b(he,m,$),h(m,le,$),h(m,H,$),t(H,z),t(z,j),b(F,j,null),t(H,we),t(H,u),t(u,U),h(m,Je,$),h(m,L,$),t(L,oe),t(oe,ke),t(L,Fe),t(L,_e),t(_e,fe),t(L,Ge),t(L,Y),t(Y,Ie),t(L,q),h(m,Ne,$),b(G,m,$),Xe=!0},p:ul,i(m){Xe||(T(ne.$$.fragment,m),T(he.$$.fragment,m),T(F.$$.fragment,m),T(G.$$.fragment,m),Xe=!0)},o(m){v(ne.$$.fragment,m),v(he.$$.fragment,m),v(F.$$.fragment,m),v(G.$$.fragment,m),Xe=!1},d(m){m&&a(p),m&&a(ye),m&&a(x),m&&a(O),J(ne,m),m&&a(Te),m&&a(k),m&&a(ve),m&&a(R),m&&a(N),J(he,m),m&&a(le),m&&a(H),J(F),m&&a(Je),m&&a(L),m&&a(Ne),J(G,m)}}}function Lr(X){let p,_;return p=new ml({props:{$$slots:{default:[Vr]},$$scope:{ctx:X}}}),{c(){y(p.$$.fragment)},l(i){M(p.$$.fragment,i)},m(i,g){b(p,i,g),_=!0},p(i,g){const W={};g&2&&(W.$$scope={dirty:g,ctx:i}),p.$set(W)},i(i){_||(T(p.$$.fragment,i),_=!0)},o(i){v(p.$$.fragment,i),_=!1},d(i){J(p,i)}}}function Yr(X){let p,_,i,g,W,Z,ue,ge,ye,x,P,I,V,Me,B,re,se,be,O,ne,Te,k,me,C,$e,ie,Q,A,Ee,E,xe,pe,ve,R,K,ee,Re,te,S,ae,de,N,he,le,H,z,j,F,we;return x=new Ue({props:{code:"cGlwJTIwaW5zdGFsbCUyMC1VJTIwLXIlMjByZXF1aXJlbWVudHNfZmxheC50eHQ=",highlighted:"pip install -U -r requirements_flax.txt"}}),A=new Ue({props:{code:"ZXhwb3J0JTIwTU9ERUxfTkFNRSUzRCUyMnJ1bndheW1sJTJGc3RhYmxlLWRpZmZ1c2lvbi12MS01JTIyJTBBZXhwb3J0JTIwZGF0YXNldF9uYW1lJTNEJTIybGFtYmRhbGFicyUyRnBva2Vtb24tYmxpcC1jYXB0aW9ucyUyMiUwQSUwQXB5dGhvbiUyMHRyYWluX3RleHRfdG9faW1hZ2VfZmxheC5weSUyMCU1QyUwQSUyMCUyMC0tcHJldHJhaW5lZF9tb2RlbF9uYW1lX29yX3BhdGglM0QlMjRNT0RFTF9OQU1FJTIwJTVDJTBBJTIwJTIwLS1kYXRhc2V0X25hbWUlM0QlMjRkYXRhc2V0X25hbWUlMjAlNUMlMEElMjAlMjAtLXJlc29sdXRpb24lM0Q1MTIlMjAtLWNlbnRlcl9jcm9wJTIwLS1yYW5kb21fZmxpcCUyMCU1QyUwQSUyMCUyMC0tdHJhaW5fYmF0Y2hfc2l6ZSUzRDElMjAlNUMlMEElMjAlMjAtLW1heF90cmFpbl9zdGVwcyUzRDE1MDAwJTIwJTVDJTBBJTIwJTIwLS1sZWFybmluZ19yYXRlJTNEMWUtMDUlMjAlNUMlMEElMjAlMjAtLW1heF9ncmFkX25vcm0lM0QxJTIwJTVDJTBBJTIwJTIwLS1vdXRwdXRfZGlyJTNEJTIyc2QtcG9rZW1vbi1tb2RlbCUyMiUyMCU1QyUwQSUyMCUyMC0tcHVzaF90b19odWI=",highlighted:`<span class="hljs-built_in">export</span> MODEL_NAME=<span class="hljs-string">&quot;runwayml/stable-diffusion-v1-5&quot;</span>
<span class="hljs-built_in">export</span> dataset_name=<span class="hljs-string">&quot;lambdalabs/pokemon-blip-captions&quot;</span>

python train_text_to_image_flax.py \\
  --pretrained_model_name_or_path=<span class="hljs-variable">$MODEL_NAME</span> \\
  --dataset_name=<span class="hljs-variable">$dataset_name</span> \\
  --resolution=512 --center_crop --random_flip \\
  --train_batch_size=1 \\
  --max_train_steps=15000 \\
  --learning_rate=1e-05 \\
  --max_grad_norm=1 \\
  --output_dir=<span class="hljs-string">&quot;sd-pokemon-model&quot;</span> \\
  --push_to_hub`}}),F=new Ue({props:{code:"ZXhwb3J0JTIwTU9ERUxfTkFNRSUzRCUyMmR1b25nbmElMkZzdGFibGUtZGlmZnVzaW9uLXYxLTQtZmxheCUyMiUwQWV4cG9ydCUyMFRSQUlOX0RJUiUzRCUyMnBhdGhfdG9feW91cl9kYXRhc2V0JTIyJTBBJTBBcHl0aG9uJTIwdHJhaW5fdGV4dF90b19pbWFnZV9mbGF4LnB5JTIwJTVDJTBBJTIwJTIwLS1wcmV0cmFpbmVkX21vZGVsX25hbWVfb3JfcGF0aCUzRCUyNE1PREVMX05BTUUlMjAlNUMlMEElMjAlMjAtLXRyYWluX2RhdGFfZGlyJTNEJTI0VFJBSU5fRElSJTIwJTVDJTBBJTIwJTIwLS1yZXNvbHV0aW9uJTNENTEyJTIwLS1jZW50ZXJfY3JvcCUyMC0tcmFuZG9tX2ZsaXAlMjAlNUMlMEElMjAlMjAtLXRyYWluX2JhdGNoX3NpemUlM0QxJTIwJTVDJTBBJTIwJTIwLS1taXhlZF9wcmVjaXNpb24lM0QlMjJmcDE2JTIyJTIwJTVDJTBBJTIwJTIwLS1tYXhfdHJhaW5fc3RlcHMlM0QxNTAwMCUyMCU1QyUwQSUyMCUyMC0tbGVhcm5pbmdfcmF0ZSUzRDFlLTA1JTIwJTVDJTBBJTIwJTIwLS1tYXhfZ3JhZF9ub3JtJTNEMSUyMCU1QyUwQSUyMCUyMC0tb3V0cHV0X2RpciUzRCUyMnNkLXBva2Vtb24tbW9kZWwlMjIlMjAlNUMlMEElMjAlMjAtLXB1c2hfdG9faHVi",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> TRAIN_DIR=<span class="hljs-string">&quot;path_to_your_dataset&quot;</span>

python train_text_to_image_flax.py \\
  --pretrained_model_name_or_path=<span class="hljs-variable">$MODEL_NAME</span> \\
  --train_data_dir=<span class="hljs-variable">$TRAIN_DIR</span> \\
  --resolution=512 --center_crop --random_flip \\
  --train_batch_size=1 \\
  --mixed_precision=<span class="hljs-string">&quot;fp16&quot;</span> \\
  --max_train_steps=15000 \\
  --learning_rate=1e-05 \\
  --max_grad_norm=1 \\
  --output_dir=<span class="hljs-string">&quot;sd-pokemon-model&quot;</span> \\
  --push_to_hub`}}),{c(){p=r("p"),_=l("With Flax, it\u2019s possible to train a Stable Diffusion model faster on TPUs and GPUs thanks to "),i=r("a"),g=l("@duongna211"),W=l(". This is very efficient on TPU hardware but works great on GPUs too. The Flax training script doesn\u2019t support features like gradient checkpointing or gradient accumulation yet, so you\u2019ll need a GPU with at least 30GB of memory or a TPU v3."),Z=d(),ue=r("p"),ge=l("Before running the script, make sure you have the requirements installed:"),ye=d(),y(x.$$.fragment),P=d(),I=r("p"),V=l("Specify the "),Me=r("code"),B=l("MODEL_NAME"),re=l(" environment variable (either a Hub model repository id or a path to the directory containing the model weights) and pass it to the "),se=r("a"),be=r("code"),O=l("pretrained_model_name_or_path"),ne=l(" argument."),Te=d(),k=r("p"),me=l("Now you can launch the "),C=r("a"),$e=l("Flax training script"),ie=l(" like this:"),Q=d(),y(A.$$.fragment),Ee=d(),E=r("p"),xe=l("To finetune on your own dataset, prepare the dataset according to the format required by \u{1F917} "),pe=r("a"),ve=l("Datasets"),R=l(". You can "),K=r("a"),ee=l("upload your dataset to the Hub"),Re=l(", or you can "),te=r("a"),S=l("prepare a local folder with your files"),ae=l("."),de=d(),N=r("p"),he=l("Modify the script if you want to use custom loading logic. We left pointers in the code in the appropriate places to help you. \u{1F917} The example script below shows how to finetune on a local dataset in "),le=r("code"),H=l("TRAIN_DIR"),z=l(":"),j=d(),y(F.$$.fragment),this.h()},l(u){p=s(u,"P",{});var U=n(p);_=o(U,"With Flax, it\u2019s possible to train a Stable Diffusion model faster on TPUs and GPUs thanks to "),i=s(U,"A",{href:!0,rel:!0});var Je=n(i);g=o(Je,"@duongna211"),Je.forEach(a),W=o(U,". This is very efficient on TPU hardware but works great on GPUs too. The Flax training script doesn\u2019t support features like gradient checkpointing or gradient accumulation yet, so you\u2019ll need a GPU with at least 30GB of memory or a TPU v3."),U.forEach(a),Z=w(u),ue=s(u,"P",{});var L=n(ue);ge=o(L,"Before running the script, make sure you have the requirements installed:"),L.forEach(a),ye=w(u),M(x.$$.fragment,u),P=w(u),I=s(u,"P",{});var oe=n(I);V=o(oe,"Specify the "),Me=s(oe,"CODE",{});var ke=n(Me);B=o(ke,"MODEL_NAME"),ke.forEach(a),re=o(oe," environment variable (either a Hub model repository id or a path to the directory containing the model weights) and pass it to the "),se=s(oe,"A",{href:!0,rel:!0});var Fe=n(se);be=s(Fe,"CODE",{});var _e=n(be);O=o(_e,"pretrained_model_name_or_path"),_e.forEach(a),Fe.forEach(a),ne=o(oe," argument."),oe.forEach(a),Te=w(u),k=s(u,"P",{});var fe=n(k);me=o(fe,"Now you can launch the "),C=s(fe,"A",{href:!0,rel:!0});var Ge=n(C);$e=o(Ge,"Flax training script"),Ge.forEach(a),ie=o(fe," like this:"),fe.forEach(a),Q=w(u),M(A.$$.fragment,u),Ee=w(u),E=s(u,"P",{});var Y=n(E);xe=o(Y,"To finetune on your own dataset, prepare the dataset according to the format required by \u{1F917} "),pe=s(Y,"A",{href:!0,rel:!0});var Ie=n(pe);ve=o(Ie,"Datasets"),Ie.forEach(a),R=o(Y,". You can "),K=s(Y,"A",{href:!0,rel:!0});var q=n(K);ee=o(q,"upload your dataset to the Hub"),q.forEach(a),Re=o(Y,", or you can "),te=s(Y,"A",{href:!0,rel:!0});var Ne=n(te);S=o(Ne,"prepare a local folder with your files"),Ne.forEach(a),ae=o(Y,"."),Y.forEach(a),de=w(u),N=s(u,"P",{});var G=n(N);he=o(G,"Modify the script if you want to use custom loading logic. We left pointers in the code in the appropriate places to help you. \u{1F917} The example script below shows how to finetune on a local dataset in "),le=s(G,"CODE",{});var Xe=n(le);H=o(Xe,"TRAIN_DIR"),Xe.forEach(a),z=o(G,":"),G.forEach(a),j=w(u),M(F.$$.fragment,u),this.h()},h(){f(i,"href","https://github.com/duongna21"),f(i,"rel","nofollow"),f(se,"href","https://huggingface.co/docs/diffusers/en/api/diffusion_pipeline#diffusers.DiffusionPipeline.from_pretrained.pretrained_model_name_or_path"),f(se,"rel","nofollow"),f(C,"href","https://github.com/huggingface/diffusers/blob/main/examples/text_to_image/train_text_to_image_flax.py"),f(C,"rel","nofollow"),f(pe,"href","https://huggingface.co/docs/datasets/index"),f(pe,"rel","nofollow"),f(K,"href","https://huggingface.co/docs/datasets/image_dataset#upload-dataset-to-the-hub"),f(K,"rel","nofollow"),f(te,"href","https://huggingface.co/docs/datasets/image_dataset#imagefolder"),f(te,"rel","nofollow")},m(u,U){h(u,p,U),t(p,_),t(p,i),t(i,g),t(p,W),h(u,Z,U),h(u,ue,U),t(ue,ge),h(u,ye,U),b(x,u,U),h(u,P,U),h(u,I,U),t(I,V),t(I,Me),t(Me,B),t(I,re),t(I,se),t(se,be),t(be,O),t(I,ne),h(u,Te,U),h(u,k,U),t(k,me),t(k,C),t(C,$e),t(k,ie),h(u,Q,U),b(A,u,U),h(u,Ee,U),h(u,E,U),t(E,xe),t(E,pe),t(pe,ve),t(E,R),t(E,K),t(K,ee),t(E,Re),t(E,te),t(te,S),t(E,ae),h(u,de,U),h(u,N,U),t(N,he),t(N,le),t(le,H),t(N,z),h(u,j,U),b(F,u,U),we=!0},p:ul,i(u){we||(T(x.$$.fragment,u),T(A.$$.fragment,u),T(F.$$.fragment,u),we=!0)},o(u){v(x.$$.fragment,u),v(A.$$.fragment,u),v(F.$$.fragment,u),we=!1},d(u){u&&a(p),u&&a(Z),u&&a(ue),u&&a(ye),J(x,u),u&&a(P),u&&a(I),u&&a(Te),u&&a(k),u&&a(Q),J(A,u),u&&a(Ee),u&&a(E),u&&a(de),u&&a(N),u&&a(j),J(F,u)}}}function Dr(X){let p,_;return p=new ml({props:{$$slots:{default:[Yr]},$$scope:{ctx:X}}}),{c(){y(p.$$.fragment)},l(i){M(p.$$.fragment,i)},m(i,g){b(p,i,g),_=!0},p(i,g){const W={};g&2&&(W.$$scope={dirty:g,ctx:i}),p.$set(W)},i(i){_||(T(p.$$.fragment,i),_=!0)},o(i){v(p.$$.fragment,i),_=!1},d(i){J(p,i)}}}function Pr(X){let p,_;return{c(){p=r("p"),_=l("Training with Min-SNR weighting strategy is only supported in PyTorch.")},l(i){p=s(i,"P",{});var g=n(p);_=o(g,"Training with Min-SNR weighting strategy is only supported in PyTorch."),g.forEach(a)},m(i,g){h(i,p,g),t(p,_)},d(i){i&&a(p)}}}function Qr(X){let p,_;return p=new Ue({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMFN0YWJsZURpZmZ1c2lvblBpcGVsaW5lJTBBJTBBbW9kZWxfcGF0aCUyMCUzRCUyMCUyMnBhdGhfdG9fc2F2ZWRfbW9kZWwlMjIlMEFwaXBlJTIwJTNEJTIwU3RhYmxlRGlmZnVzaW9uUGlwZWxpbmUuZnJvbV9wcmV0cmFpbmVkKG1vZGVsX3BhdGglMkMlMjB0b3JjaF9kdHlwZSUzRHRvcmNoLmZsb2F0MTYlMkMlMjB1c2Vfc2FmZXRlbnNvcnMlM0RUcnVlKSUwQXBpcGUudG8oJTIyY3VkYSUyMiklMEElMEFpbWFnZSUyMCUzRCUyMHBpcGUocHJvbXB0JTNEJTIyeW9kYSUyMikuaW1hZ2VzJTVCMCU1RCUwQWltYWdlLnNhdmUoJTIyeW9kYS1wb2tlbW9uLnBuZyUyMik=",highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> StableDiffusionPipeline

model_path = <span class="hljs-string">&quot;path_to_saved_model&quot;</span>
pipe = StableDiffusionPipeline.from_pretrained(model_path, torch_dtype=torch.float16, use_safetensors=<span class="hljs-literal">True</span>)
pipe.to(<span class="hljs-string">&quot;cuda&quot;</span>)

image = pipe(prompt=<span class="hljs-string">&quot;yoda&quot;</span>).images[<span class="hljs-number">0</span>]
image.save(<span class="hljs-string">&quot;yoda-pokemon.png&quot;</span>)`}}),{c(){y(p.$$.fragment)},l(i){M(p.$$.fragment,i)},m(i,g){b(p,i,g),_=!0},p:ul,i(i){_||(T(p.$$.fragment,i),_=!0)},o(i){v(p.$$.fragment,i),_=!1},d(i){J(p,i)}}}function Hr(X){let p,_;return p=new ml({props:{$$slots:{default:[Qr]},$$scope:{ctx:X}}}),{c(){y(p.$$.fragment)},l(i){M(p.$$.fragment,i)},m(i,g){b(p,i,g),_=!0},p(i,g){const W={};g&2&&(W.$$scope={dirty:g,ctx:i}),p.$set(W)},i(i){_||(T(p.$$.fragment,i),_=!0)},o(i){v(p.$$.fragment,i),_=!1},d(i){J(p,i)}}}function zr(X){let p,_;return p=new Ue({props:{code:"aW1wb3J0JTIwamF4JTBBaW1wb3J0JTIwbnVtcHklMjBhcyUyMG5wJTBBZnJvbSUyMGZsYXguamF4X3V0aWxzJTIwaW1wb3J0JTIwcmVwbGljYXRlJTBBZnJvbSUyMGZsYXgudHJhaW5pbmcuY29tbW9uX3V0aWxzJTIwaW1wb3J0JTIwc2hhcmQlMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwRmxheFN0YWJsZURpZmZ1c2lvblBpcGVsaW5lJTBBJTBBbW9kZWxfcGF0aCUyMCUzRCUyMCUyMnBhdGhfdG9fc2F2ZWRfbW9kZWwlMjIlMEFwaXBlJTJDJTIwcGFyYW1zJTIwJTNEJTIwRmxheFN0YWJsZURpZmZ1c2lvblBpcGVsaW5lLmZyb21fcHJldHJhaW5lZChtb2RlbF9wYXRoJTJDJTIwZHR5cGUlM0RqYXgubnVtcHkuYmZsb2F0MTYpJTBBJTBBcHJvbXB0JTIwJTNEJTIwJTIyeW9kYSUyMHBva2Vtb24lMjIlMEFwcm5nX3NlZWQlMjAlM0QlMjBqYXgucmFuZG9tLlBSTkdLZXkoMCklMEFudW1faW5mZXJlbmNlX3N0ZXBzJTIwJTNEJTIwNTAlMEElMEFudW1fc2FtcGxlcyUyMCUzRCUyMGpheC5kZXZpY2VfY291bnQoKSUwQXByb21wdCUyMCUzRCUyMG51bV9zYW1wbGVzJTIwKiUyMCU1QnByb21wdCU1RCUwQXByb21wdF9pZHMlMjAlM0QlMjBwaXBlbGluZS5wcmVwYXJlX2lucHV0cyhwcm9tcHQpJTBBJTBBJTIzJTIwc2hhcmQlMjBpbnB1dHMlMjBhbmQlMjBybmclMEFwYXJhbXMlMjAlM0QlMjByZXBsaWNhdGUocGFyYW1zKSUwQXBybmdfc2VlZCUyMCUzRCUyMGpheC5yYW5kb20uc3BsaXQocHJuZ19zZWVkJTJDJTIwamF4LmRldmljZV9jb3VudCgpKSUwQXByb21wdF9pZHMlMjAlM0QlMjBzaGFyZChwcm9tcHRfaWRzKSUwQSUwQWltYWdlcyUyMCUzRCUyMHBpcGVsaW5lKHByb21wdF9pZHMlMkMlMjBwYXJhbXMlMkMlMjBwcm5nX3NlZWQlMkMlMjBudW1faW5mZXJlbmNlX3N0ZXBzJTJDJTIwaml0JTNEVHJ1ZSkuaW1hZ2VzJTBBaW1hZ2VzJTIwJTNEJTIwcGlwZWxpbmUubnVtcHlfdG9fcGlsKG5wLmFzYXJyYXkoaW1hZ2VzLnJlc2hhcGUoKG51bV9zYW1wbGVzJTJDKSUyMCUyQiUyMGltYWdlcy5zaGFwZSU1Qi0zJTNBJTVEKSkpJTBBaW1hZ2Uuc2F2ZSglMjJ5b2RhLXBva2Vtb24ucG5nJTIyKQ==",highlighted:`<span class="hljs-keyword">import</span> jax
<span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np
<span class="hljs-keyword">from</span> flax.jax_utils <span class="hljs-keyword">import</span> replicate
<span class="hljs-keyword">from</span> flax.training.common_utils <span class="hljs-keyword">import</span> shard
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> FlaxStableDiffusionPipeline

model_path = <span class="hljs-string">&quot;path_to_saved_model&quot;</span>
pipe, params = FlaxStableDiffusionPipeline.from_pretrained(model_path, dtype=jax.numpy.bfloat16)

prompt = <span class="hljs-string">&quot;yoda pokemon&quot;</span>
prng_seed = jax.random.PRNGKey(<span class="hljs-number">0</span>)
num_inference_steps = <span class="hljs-number">50</span>

num_samples = jax.device_count()
prompt = num_samples * [prompt]
prompt_ids = pipeline.prepare_inputs(prompt)

<span class="hljs-comment"># shard inputs and rng</span>
params = replicate(params)
prng_seed = jax.random.split(prng_seed, jax.device_count())
prompt_ids = shard(prompt_ids)

images = pipeline(prompt_ids, params, prng_seed, num_inference_steps, jit=<span class="hljs-literal">True</span>).images
images = pipeline.numpy_to_pil(np.asarray(images.reshape((num_samples,) + images.shape[-<span class="hljs-number">3</span>:])))
image.save(<span class="hljs-string">&quot;yoda-pokemon.png&quot;</span>)`}}),{c(){y(p.$$.fragment)},l(i){M(p.$$.fragment,i)},m(i,g){b(p,i,g),_=!0},p:ul,i(i){_||(T(p.$$.fragment,i),_=!0)},o(i){v(p.$$.fragment,i),_=!1},d(i){J(p,i)}}}function qr(X){let p,_;return p=new ml({props:{$$slots:{default:[zr]},$$scope:{ctx:X}}}),{c(){y(p.$$.fragment)},l(i){M(p.$$.fragment,i)},m(i,g){b(p,i,g),_=!0},p(i,g){const W={};g&2&&(W.$$scope={dirty:g,ctx:i}),p.$set(W)},i(i){_||(T(p.$$.fragment,i),_=!0)},o(i){v(p.$$.fragment,i),_=!1},d(i){J(p,i)}}}function Or(X){let p,_,i,g,W,Z,ue,ge,ye,x,P,I,V,Me,B,re,se,be,O,ne,Te,k,me,C,$e,ie,Q,A,Ee,E,xe,pe,ve,R,K,ee,Re,te,S,ae,de,N,he,le,H,z,j,F,we,u,U,Je,L,oe,ke,Fe,_e,fe,Ge,Y,Ie,q,Ne,G,Xe,m,$,Gt,Vt,Ze,ze,Lt,Tt,D,Ae,ot,Ve,Le,rt,Yt,qe,Oe,Dt,vt,ce,Jt,We,Be,aa,Ut,dl,la,wl,Wa,Pt,_l,ja,$t,xa,je,gl,oa,yl,Ml,ra,bl,Tl,sa,vl,Jl,Ra,st,Ul,na,$l,El,Ia,Et,Na,Ke,nt,ia,kt,kl,pa,Wl,Xa,it,Za,et,pt,ha,Wt,jl,fa,xl,Aa,Ye,Rl,jt,Il,Nl,ca,Xl,Zl,Ba,ht,Al,xt,Bl,Cl,Ca,De,ua,Sl,Fl,Rt,Gl,ma,Vl,Ll,Yl,It,Dl,da,Pl,Ql,Sa,Qt,Hl,Fa,Pe,zl,wa,ql,Ol,_a,Kl,eo,Ga,ft,Va,tt,ct,ga,Nt,to,ya,ao,La,ut,lo,Ht,oo,ro,Ya,at,mt,Ma,Xt,so,ba,no,Da,dt,io,zt,po,ho,Pa,wt,Qa,lt,_t,Ta,Zt,fo,va,co,Ha,gt,Ce,uo,At,mo,wo,Ja,_o,go,Bt,yo,Mo,bo,Se,To,Ct,vo,Jo,Ua,Uo,$o,St,Eo,ko,za;return Z=new He({}),P=new Xr({props:{warning:!0,$$slots:{default:[Gr]},$$scope:{ctx:X}}}),ie=new Ue({props:{code:"cGlwJTIwaW5zdGFsbCUyMGdpdCUyQmh0dHBzJTNBJTJGJTJGZ2l0aHViLmNvbSUyRmh1Z2dpbmdmYWNlJTJGZGlmZnVzZXJzLmdpdCUwQXBpcCUyMGluc3RhbGwlMjAtVSUyMC1yJTIwcmVxdWlyZW1lbnRzLnR4dA==",highlighted:`pip install git+https://github.com/huggingface/diffusers.git
pip install -U -r requirements.txt`}}),R=new Ue({props:{code:"YWNjZWxlcmF0ZSUyMGNvbmZpZw==",highlighted:"accelerate config"}}),N=new He({}),Ve=new He({}),ce=new Ue({props:{code:"JTIwJTIwLS1wdXNoX3RvX2h1Yg==",highlighted:"  --push_to_hub"}}),Ut=new He({}),$t=new Ue({props:{code:"JTIwJTIwLS1jaGVja3BvaW50aW5nX3N0ZXBzJTNENTAw",highlighted:"  --checkpointing_steps=500"}}),Et=new Ue({props:{code:"JTIwJTIwLS1yZXN1bWVfZnJvbV9jaGVja3BvaW50JTNEJTIyY2hlY2twb2ludC0xNTAwJTIy",highlighted:'  --resume_from_checkpoint=<span class="hljs-string">&quot;checkpoint-1500&quot;</span>'}}),kt=new He({}),it=new Zr({props:{pytorch:!0,tensorflow:!1,jax:!0,$$slots:{jax:[Dr],pytorch:[Lr]},$$scope:{ctx:X}}}),Wt=new He({}),ft=new Xr({props:{warning:!0,$$slots:{default:[Pr]},$$scope:{ctx:X}}}),Nt=new He({}),Xt=new He({}),wt=new Zr({props:{pytorch:!0,tensorflow:!1,jax:!0,$$slots:{jax:[qr],pytorch:[Hr]},$$scope:{ctx:X}}}),Zt=new He({}),{c(){p=r("meta"),_=d(),i=r("h1"),g=r("a"),W=r("span"),y(Z.$$.fragment),ue=d(),ge=r("span"),ye=l("Text-to-image"),x=d(),y(P.$$.fragment),I=d(),V=r("p"),Me=l("Text-to-image models like Stable Diffusion generate an image from a text prompt. This guide will show you how to finetune the "),B=r("a"),re=r("code"),se=l("CompVis/stable-diffusion-v1-4"),be=l(" model on your own dataset with PyTorch and Flax. All the training scripts for text-to-image finetuning used in this guide can be found in this "),O=r("a"),ne=l("repository"),Te=l(" if you\u2019re interested in taking a closer look."),k=d(),me=r("p"),C=l("Before running the scripts, make sure to install the library\u2019s training dependencies:"),$e=d(),y(ie.$$.fragment),Q=d(),A=r("p"),Ee=l("And initialize an "),E=r("a"),xe=l("\u{1F917} Accelerate"),pe=l(" environment with:"),ve=d(),y(R.$$.fragment),K=d(),ee=r("p"),Re=l("If you have already cloned the repo, then you won\u2019t need to go through these steps. Instead, you can pass the path to your local checkout to the training script and it will be loaded from there."),te=d(),S=r("h2"),ae=r("a"),de=r("span"),y(N.$$.fragment),he=d(),le=r("span"),H=l("Hardware requirements"),z=d(),j=r("p"),F=l("Using "),we=r("code"),u=l("gradient_checkpointing"),U=l(" and "),Je=r("code"),L=l("mixed_precision"),oe=l(", it should be possible to finetune the model on a single 24GB GPU. For higher "),ke=r("code"),Fe=l("batch_size"),_e=l("\u2019s and faster training, it\u2019s better to use GPUs with more than 30GB of GPU memory. You can also use JAX/Flax for fine-tuning on TPUs or GPUs, which will be covered "),fe=r("a"),Ge=l("below"),Y=l("."),Ie=d(),q=r("p"),Ne=l("You can reduce your memory footprint even more by enabling memory efficient attention with xFormers. Make sure you have "),G=r("a"),Xe=l("xFormers installed"),m=l(" and pass the "),$=r("code"),Gt=l("--enable_xformers_memory_efficient_attention"),Vt=l(" flag to the training script."),Ze=d(),ze=r("p"),Lt=l("xFormers is not available for Flax."),Tt=d(),D=r("h2"),Ae=r("a"),ot=r("span"),y(Ve.$$.fragment),Le=d(),rt=r("span"),Yt=l("Upload model to Hub"),qe=d(),Oe=r("p"),Dt=l("Store your model on the Hub by adding the following argument to the training script:"),vt=d(),y(ce.$$.fragment),Jt=d(),We=r("h2"),Be=r("a"),aa=r("span"),y(Ut.$$.fragment),dl=d(),la=r("span"),wl=l("Save and load checkpoints"),Wa=d(),Pt=r("p"),_l=l("It is a good idea to regularly save checkpoints in case anything happens during training. To save a checkpoint, pass the following argument to the training script:"),ja=d(),y($t.$$.fragment),xa=d(),je=r("p"),gl=l("Every 500 steps, the full training state is saved in a subfolder in the "),oa=r("code"),yl=l("output_dir"),Ml=l(". The checkpoint has the format "),ra=r("code"),bl=l("checkpoint-"),Tl=l(" followed by the number of steps trained so far. For example, "),sa=r("code"),vl=l("checkpoint-1500"),Jl=l(" is a checkpoint saved after 1500 training steps."),Ra=d(),st=r("p"),Ul=l("To load a checkpoint to resume training, pass the argument "),na=r("code"),$l=l("--resume_from_checkpoint"),El=l(" to the training script and specify the checkpoint you want to resume from. For example, the following argument resumes training from the checkpoint saved after 1500 training steps:"),Ia=d(),y(Et.$$.fragment),Na=d(),Ke=r("h2"),nt=r("a"),ia=r("span"),y(kt.$$.fragment),kl=d(),pa=r("span"),Wl=l("Fine-tuning"),Xa=d(),y(it.$$.fragment),Za=d(),et=r("h2"),pt=r("a"),ha=r("span"),y(Wt.$$.fragment),jl=d(),fa=r("span"),xl=l("Training with Min-SNR weighting"),Aa=d(),Ye=r("p"),Rl=l("We support training with the Min-SNR weighting strategy proposed in "),jt=r("a"),Il=l("Efficient Diffusion Training via Min-SNR Weighting Strategy"),Nl=l(` which helps to achieve faster convergence
by rebalancing the loss. In order to use it, one needs to set the `),ca=r("code"),Xl=l("--snr_gamma"),Zl=l(` argument. The recommended
value when using it is 5.0.`),Ba=d(),ht=r("p"),Al=l("You can find "),xt=r("a"),Bl=l("this project on Weights and Biases"),Cl=l(" that compares the loss surfaces of the following setups:"),Ca=d(),De=r("ul"),ua=r("li"),Sl=l("Training without the Min-SNR weighting strategy"),Fl=d(),Rt=r("li"),Gl=l("Training with the Min-SNR weighting strategy ("),ma=r("code"),Vl=l("snr_gamma"),Ll=l(" set to 5.0)"),Yl=d(),It=r("li"),Dl=l("Training with the Min-SNR weighting strategy ("),da=r("code"),Pl=l("snr_gamma"),Ql=l(" set to 1.0)"),Sa=d(),Qt=r("p"),Hl=l("For our small Pokemons dataset, the effects of Min-SNR weighting strategy might not appear to be pronounced, but for larger datasets, we believe the effects will be more pronounced."),Fa=d(),Pe=r("p"),zl=l("Also, note that in this example, we either predict "),wa=r("code"),ql=l("epsilon"),Ol=l(" (i.e., the noise) or the "),_a=r("code"),Kl=l("v_prediction"),eo=l(". For both of these cases, the formulation of the Min-SNR weighting strategy that we have used holds."),Ga=d(),y(ft.$$.fragment),Va=d(),tt=r("h2"),ct=r("a"),ga=r("span"),y(Nt.$$.fragment),to=d(),ya=r("span"),ao=l("LoRA"),La=d(),ut=r("p"),lo=l("You can also use Low-Rank Adaptation of Large Language Models (LoRA), a fine-tuning technique for accelerating training large models, for fine-tuning text-to-image models. For more details, take a look at the "),Ht=r("a"),oo=l("LoRA training"),ro=l(" guide."),Ya=d(),at=r("h2"),mt=r("a"),Ma=r("span"),y(Xt.$$.fragment),so=d(),ba=r("span"),no=l("Inference"),Da=d(),dt=r("p"),io=l("Now you can load the fine-tuned model for inference by passing the model path or model name on the Hub to the "),zt=r("a"),po=l("StableDiffusionPipeline"),ho=l(":"),Pa=d(),y(wt.$$.fragment),Qa=d(),lt=r("h2"),_t=r("a"),Ta=r("span"),y(Zt.$$.fragment),fo=d(),va=r("span"),co=l("Stable Diffusion XL"),Ha=d(),gt=r("ul"),Ce=r("li"),uo=l("We support fine-tuning the UNet shipped in "),At=r("a"),mo=l("Stable Diffusion XL"),wo=l(" via the "),Ja=r("code"),_o=l("train_text_to_image_sdxl.py"),go=l(" script. Please refer to the docs "),Bt=r("a"),yo=l("here"),Mo=l("."),bo=d(),Se=r("li"),To=l("We also support fine-tuning of the UNet and Text Encoder shipped in "),Ct=r("a"),vo=l("Stable Diffusion XL"),Jo=l(" with LoRA via the "),Ua=r("code"),Uo=l("train_text_to_image_lora_sdxl.py"),$o=l(" script. Please refer to the docs "),St=r("a"),Eo=l("here"),ko=l("."),this.h()},l(e){const c=Sr('[data-svelte="svelte-1phssyn"]',document.head);p=s(c,"META",{name:!0,content:!0}),c.forEach(a),_=w(e),i=s(e,"H1",{class:!0});var Ft=n(i);g=s(Ft,"A",{id:!0,class:!0,href:!0});var $a=n(g);W=s($a,"SPAN",{});var Ea=n(W);M(Z.$$.fragment,Ea),Ea.forEach(a),$a.forEach(a),ue=w(Ft),ge=s(Ft,"SPAN",{});var ka=n(ge);ye=o(ka,"Text-to-image"),ka.forEach(a),Ft.forEach(a),x=w(e),M(P.$$.fragment,e),I=w(e),V=s(e,"P",{});var qt=n(V);Me=o(qt,"Text-to-image models like Stable Diffusion generate an image from a text prompt. This guide will show you how to finetune the "),B=s(qt,"A",{href:!0,rel:!0});var Wo=n(B);re=s(Wo,"CODE",{});var jo=n(re);se=o(jo,"CompVis/stable-diffusion-v1-4"),jo.forEach(a),Wo.forEach(a),be=o(qt," model on your own dataset with PyTorch and Flax. All the training scripts for text-to-image finetuning used in this guide can be found in this "),O=s(qt,"A",{href:!0,rel:!0});var xo=n(O);ne=o(xo,"repository"),xo.forEach(a),Te=o(qt," if you\u2019re interested in taking a closer look."),qt.forEach(a),k=w(e),me=s(e,"P",{});var Ro=n(me);C=o(Ro,"Before running the scripts, make sure to install the library\u2019s training dependencies:"),Ro.forEach(a),$e=w(e),M(ie.$$.fragment,e),Q=w(e),A=s(e,"P",{});var qa=n(A);Ee=o(qa,"And initialize an "),E=s(qa,"A",{href:!0,rel:!0});var Io=n(E);xe=o(Io,"\u{1F917} Accelerate"),Io.forEach(a),pe=o(qa," environment with:"),qa.forEach(a),ve=w(e),M(R.$$.fragment,e),K=w(e),ee=s(e,"P",{});var No=n(ee);Re=o(No,"If you have already cloned the repo, then you won\u2019t need to go through these steps. Instead, you can pass the path to your local checkout to the training script and it will be loaded from there."),No.forEach(a),te=w(e),S=s(e,"H2",{class:!0});var Oa=n(S);ae=s(Oa,"A",{id:!0,class:!0,href:!0});var Xo=n(ae);de=s(Xo,"SPAN",{});var Zo=n(de);M(N.$$.fragment,Zo),Zo.forEach(a),Xo.forEach(a),he=w(Oa),le=s(Oa,"SPAN",{});var Ao=n(le);H=o(Ao,"Hardware requirements"),Ao.forEach(a),Oa.forEach(a),z=w(e),j=s(e,"P",{});var Qe=n(j);F=o(Qe,"Using "),we=s(Qe,"CODE",{});var Bo=n(we);u=o(Bo,"gradient_checkpointing"),Bo.forEach(a),U=o(Qe," and "),Je=s(Qe,"CODE",{});var Co=n(Je);L=o(Co,"mixed_precision"),Co.forEach(a),oe=o(Qe,", it should be possible to finetune the model on a single 24GB GPU. For higher "),ke=s(Qe,"CODE",{});var So=n(ke);Fe=o(So,"batch_size"),So.forEach(a),_e=o(Qe,"\u2019s and faster training, it\u2019s better to use GPUs with more than 30GB of GPU memory. You can also use JAX/Flax for fine-tuning on TPUs or GPUs, which will be covered "),fe=s(Qe,"A",{href:!0});var Fo=n(fe);Ge=o(Fo,"below"),Fo.forEach(a),Y=o(Qe,"."),Qe.forEach(a),Ie=w(e),q=s(e,"P",{});var Ot=n(q);Ne=o(Ot,"You can reduce your memory footprint even more by enabling memory efficient attention with xFormers. Make sure you have "),G=s(Ot,"A",{href:!0});var Go=n(G);Xe=o(Go,"xFormers installed"),Go.forEach(a),m=o(Ot," and pass the "),$=s(Ot,"CODE",{});var Vo=n($);Gt=o(Vo,"--enable_xformers_memory_efficient_attention"),Vo.forEach(a),Vt=o(Ot," flag to the training script."),Ot.forEach(a),Ze=w(e),ze=s(e,"P",{});var Lo=n(ze);Lt=o(Lo,"xFormers is not available for Flax."),Lo.forEach(a),Tt=w(e),D=s(e,"H2",{class:!0});var Ka=n(D);Ae=s(Ka,"A",{id:!0,class:!0,href:!0});var Yo=n(Ae);ot=s(Yo,"SPAN",{});var Do=n(ot);M(Ve.$$.fragment,Do),Do.forEach(a),Yo.forEach(a),Le=w(Ka),rt=s(Ka,"SPAN",{});var Po=n(rt);Yt=o(Po,"Upload model to Hub"),Po.forEach(a),Ka.forEach(a),qe=w(e),Oe=s(e,"P",{});var Qo=n(Oe);Dt=o(Qo,"Store your model on the Hub by adding the following argument to the training script:"),Qo.forEach(a),vt=w(e),M(ce.$$.fragment,e),Jt=w(e),We=s(e,"H2",{class:!0});var el=n(We);Be=s(el,"A",{id:!0,class:!0,href:!0});var Ho=n(Be);aa=s(Ho,"SPAN",{});var zo=n(aa);M(Ut.$$.fragment,zo),zo.forEach(a),Ho.forEach(a),dl=w(el),la=s(el,"SPAN",{});var qo=n(la);wl=o(qo,"Save and load checkpoints"),qo.forEach(a),el.forEach(a),Wa=w(e),Pt=s(e,"P",{});var Oo=n(Pt);_l=o(Oo,"It is a good idea to regularly save checkpoints in case anything happens during training. To save a checkpoint, pass the following argument to the training script:"),Oo.forEach(a),ja=w(e),M($t.$$.fragment,e),xa=w(e),je=s(e,"P",{});var yt=n(je);gl=o(yt,"Every 500 steps, the full training state is saved in a subfolder in the "),oa=s(yt,"CODE",{});var Ko=n(oa);yl=o(Ko,"output_dir"),Ko.forEach(a),Ml=o(yt,". The checkpoint has the format "),ra=s(yt,"CODE",{});var er=n(ra);bl=o(er,"checkpoint-"),er.forEach(a),Tl=o(yt," followed by the number of steps trained so far. For example, "),sa=s(yt,"CODE",{});var tr=n(sa);vl=o(tr,"checkpoint-1500"),tr.forEach(a),Jl=o(yt," is a checkpoint saved after 1500 training steps."),yt.forEach(a),Ra=w(e),st=s(e,"P",{});var tl=n(st);Ul=o(tl,"To load a checkpoint to resume training, pass the argument "),na=s(tl,"CODE",{});var ar=n(na);$l=o(ar,"--resume_from_checkpoint"),ar.forEach(a),El=o(tl," to the training script and specify the checkpoint you want to resume from. For example, the following argument resumes training from the checkpoint saved after 1500 training steps:"),tl.forEach(a),Ia=w(e),M(Et.$$.fragment,e),Na=w(e),Ke=s(e,"H2",{class:!0});var al=n(Ke);nt=s(al,"A",{id:!0,class:!0,href:!0});var lr=n(nt);ia=s(lr,"SPAN",{});var or=n(ia);M(kt.$$.fragment,or),or.forEach(a),lr.forEach(a),kl=w(al),pa=s(al,"SPAN",{});var rr=n(pa);Wl=o(rr,"Fine-tuning"),rr.forEach(a),al.forEach(a),Xa=w(e),M(it.$$.fragment,e),Za=w(e),et=s(e,"H2",{class:!0});var ll=n(et);pt=s(ll,"A",{id:!0,class:!0,href:!0});var sr=n(pt);ha=s(sr,"SPAN",{});var nr=n(ha);M(Wt.$$.fragment,nr),nr.forEach(a),sr.forEach(a),jl=w(ll),fa=s(ll,"SPAN",{});var ir=n(fa);xl=o(ir,"Training with Min-SNR weighting"),ir.forEach(a),ll.forEach(a),Aa=w(e),Ye=s(e,"P",{});var Kt=n(Ye);Rl=o(Kt,"We support training with the Min-SNR weighting strategy proposed in "),jt=s(Kt,"A",{href:!0,rel:!0});var pr=n(jt);Il=o(pr,"Efficient Diffusion Training via Min-SNR Weighting Strategy"),pr.forEach(a),Nl=o(Kt,` which helps to achieve faster convergence
by rebalancing the loss. In order to use it, one needs to set the `),ca=s(Kt,"CODE",{});var hr=n(ca);Xl=o(hr,"--snr_gamma"),hr.forEach(a),Zl=o(Kt,` argument. The recommended
value when using it is 5.0.`),Kt.forEach(a),Ba=w(e),ht=s(e,"P",{});var ol=n(ht);Al=o(ol,"You can find "),xt=s(ol,"A",{href:!0,rel:!0});var fr=n(xt);Bl=o(fr,"this project on Weights and Biases"),fr.forEach(a),Cl=o(ol," that compares the loss surfaces of the following setups:"),ol.forEach(a),Ca=w(e),De=s(e,"UL",{});var ea=n(De);ua=s(ea,"LI",{});var cr=n(ua);Sl=o(cr,"Training without the Min-SNR weighting strategy"),cr.forEach(a),Fl=w(ea),Rt=s(ea,"LI",{});var rl=n(Rt);Gl=o(rl,"Training with the Min-SNR weighting strategy ("),ma=s(rl,"CODE",{});var ur=n(ma);Vl=o(ur,"snr_gamma"),ur.forEach(a),Ll=o(rl," set to 5.0)"),rl.forEach(a),Yl=w(ea),It=s(ea,"LI",{});var sl=n(It);Dl=o(sl,"Training with the Min-SNR weighting strategy ("),da=s(sl,"CODE",{});var mr=n(da);Pl=o(mr,"snr_gamma"),mr.forEach(a),Ql=o(sl," set to 1.0)"),sl.forEach(a),ea.forEach(a),Sa=w(e),Qt=s(e,"P",{});var dr=n(Qt);Hl=o(dr,"For our small Pokemons dataset, the effects of Min-SNR weighting strategy might not appear to be pronounced, but for larger datasets, we believe the effects will be more pronounced."),dr.forEach(a),Fa=w(e),Pe=s(e,"P",{});var ta=n(Pe);zl=o(ta,"Also, note that in this example, we either predict "),wa=s(ta,"CODE",{});var wr=n(wa);ql=o(wr,"epsilon"),wr.forEach(a),Ol=o(ta," (i.e., the noise) or the "),_a=s(ta,"CODE",{});var _r=n(_a);Kl=o(_r,"v_prediction"),_r.forEach(a),eo=o(ta,". For both of these cases, the formulation of the Min-SNR weighting strategy that we have used holds."),ta.forEach(a),Ga=w(e),M(ft.$$.fragment,e),Va=w(e),tt=s(e,"H2",{class:!0});var nl=n(tt);ct=s(nl,"A",{id:!0,class:!0,href:!0});var gr=n(ct);ga=s(gr,"SPAN",{});var yr=n(ga);M(Nt.$$.fragment,yr),yr.forEach(a),gr.forEach(a),to=w(nl),ya=s(nl,"SPAN",{});var Mr=n(ya);ao=o(Mr,"LoRA"),Mr.forEach(a),nl.forEach(a),La=w(e),ut=s(e,"P",{});var il=n(ut);lo=o(il,"You can also use Low-Rank Adaptation of Large Language Models (LoRA), a fine-tuning technique for accelerating training large models, for fine-tuning text-to-image models. For more details, take a look at the "),Ht=s(il,"A",{href:!0});var br=n(Ht);oo=o(br,"LoRA training"),br.forEach(a),ro=o(il," guide."),il.forEach(a),Ya=w(e),at=s(e,"H2",{class:!0});var pl=n(at);mt=s(pl,"A",{id:!0,class:!0,href:!0});var Tr=n(mt);Ma=s(Tr,"SPAN",{});var vr=n(Ma);M(Xt.$$.fragment,vr),vr.forEach(a),Tr.forEach(a),so=w(pl),ba=s(pl,"SPAN",{});var Jr=n(ba);no=o(Jr,"Inference"),Jr.forEach(a),pl.forEach(a),Da=w(e),dt=s(e,"P",{});var hl=n(dt);io=o(hl,"Now you can load the fine-tuned model for inference by passing the model path or model name on the Hub to the "),zt=s(hl,"A",{href:!0});var Ur=n(zt);po=o(Ur,"StableDiffusionPipeline"),Ur.forEach(a),ho=o(hl,":"),hl.forEach(a),Pa=w(e),M(wt.$$.fragment,e),Qa=w(e),lt=s(e,"H2",{class:!0});var fl=n(lt);_t=s(fl,"A",{id:!0,class:!0,href:!0});var $r=n(_t);Ta=s($r,"SPAN",{});var Er=n(Ta);M(Zt.$$.fragment,Er),Er.forEach(a),$r.forEach(a),fo=w(fl),va=s(fl,"SPAN",{});var kr=n(va);co=o(kr,"Stable Diffusion XL"),kr.forEach(a),fl.forEach(a),Ha=w(e),gt=s(e,"UL",{});var cl=n(gt);Ce=s(cl,"LI",{});var Mt=n(Ce);uo=o(Mt,"We support fine-tuning the UNet shipped in "),At=s(Mt,"A",{href:!0,rel:!0});var Wr=n(At);mo=o(Wr,"Stable Diffusion XL"),Wr.forEach(a),wo=o(Mt," via the "),Ja=s(Mt,"CODE",{});var jr=n(Ja);_o=o(jr,"train_text_to_image_sdxl.py"),jr.forEach(a),go=o(Mt," script. Please refer to the docs "),Bt=s(Mt,"A",{href:!0,rel:!0});var xr=n(Bt);yo=o(xr,"here"),xr.forEach(a),Mo=o(Mt,"."),Mt.forEach(a),bo=w(cl),Se=s(cl,"LI",{});var bt=n(Se);To=o(bt,"We also support fine-tuning of the UNet and Text Encoder shipped in "),Ct=s(bt,"A",{href:!0,rel:!0});var Rr=n(Ct);vo=o(Rr,"Stable Diffusion XL"),Rr.forEach(a),Jo=o(bt," with LoRA via the "),Ua=s(bt,"CODE",{});var Ir=n(Ua);Uo=o(Ir,"train_text_to_image_lora_sdxl.py"),Ir.forEach(a),$o=o(bt," script. Please refer to the docs "),St=s(bt,"A",{href:!0,rel:!0});var Nr=n(St);Eo=o(Nr,"here"),Nr.forEach(a),ko=o(bt,"."),bt.forEach(a),cl.forEach(a),this.h()},h(){f(p,"name","hf:doc:metadata"),f(p,"content",JSON.stringify(Kr)),f(g,"id","texttoimage"),f(g,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),f(g,"href","#texttoimage"),f(i,"class","relative group"),f(B,"href","https://huggingface.co/CompVis/stable-diffusion-v1-4"),f(B,"rel","nofollow"),f(O,"href","https://github.com/huggingface/diffusers/tree/main/examples/text_to_image"),f(O,"rel","nofollow"),f(E,"href","https://github.com/huggingface/accelerate/"),f(E,"rel","nofollow"),f(ae,"id","hardware-requirements"),f(ae,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),f(ae,"href","#hardware-requirements"),f(S,"class","relative group"),f(fe,"href","#flax-jax-finetuning"),f(G,"href","./optimization/xformers"),f(Ae,"id","upload-model-to-hub"),f(Ae,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),f(Ae,"href","#upload-model-to-hub"),f(D,"class","relative group"),f(Be,"id","save-and-load-checkpoints"),f(Be,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),f(Be,"href","#save-and-load-checkpoints"),f(We,"class","relative group"),f(nt,"id","finetuning"),f(nt,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),f(nt,"href","#finetuning"),f(Ke,"class","relative group"),f(pt,"id","training-with-minsnr-weighting"),f(pt,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),f(pt,"href","#training-with-minsnr-weighting"),f(et,"class","relative group"),f(jt,"href","https://arxiv.org/abs/2303.09556"),f(jt,"rel","nofollow"),f(xt,"href","https://wandb.ai/sayakpaul/text2image-finetune-minsnr"),f(xt,"rel","nofollow"),f(ct,"id","lora"),f(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"),f(ct,"href","#lora"),f(tt,"class","relative group"),f(Ht,"href","lora#text-to-image"),f(mt,"id","inference"),f(mt,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),f(mt,"href","#inference"),f(at,"class","relative group"),f(zt,"href","/docs/diffusers/v0.21.0/en/api/pipelines/stable_diffusion/text2img#diffusers.StableDiffusionPipeline"),f(_t,"id","stable-diffusion-xl"),f(_t,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),f(_t,"href","#stable-diffusion-xl"),f(lt,"class","relative group"),f(At,"href","https://huggingface.co/papers/2307.01952"),f(At,"rel","nofollow"),f(Bt,"href","https://github.com/huggingface/diffusers/blob/main/examples/text_to_image/README_sdxl.md"),f(Bt,"rel","nofollow"),f(Ct,"href","https://huggingface.co/papers/2307.01952"),f(Ct,"rel","nofollow"),f(St,"href","https://github.com/huggingface/diffusers/blob/main/examples/text_to_image/README_sdxl.md"),f(St,"rel","nofollow")},m(e,c){t(document.head,p),h(e,_,c),h(e,i,c),t(i,g),t(g,W),b(Z,W,null),t(i,ue),t(i,ge),t(ge,ye),h(e,x,c),b(P,e,c),h(e,I,c),h(e,V,c),t(V,Me),t(V,B),t(B,re),t(re,se),t(V,be),t(V,O),t(O,ne),t(V,Te),h(e,k,c),h(e,me,c),t(me,C),h(e,$e,c),b(ie,e,c),h(e,Q,c),h(e,A,c),t(A,Ee),t(A,E),t(E,xe),t(A,pe),h(e,ve,c),b(R,e,c),h(e,K,c),h(e,ee,c),t(ee,Re),h(e,te,c),h(e,S,c),t(S,ae),t(ae,de),b(N,de,null),t(S,he),t(S,le),t(le,H),h(e,z,c),h(e,j,c),t(j,F),t(j,we),t(we,u),t(j,U),t(j,Je),t(Je,L),t(j,oe),t(j,ke),t(ke,Fe),t(j,_e),t(j,fe),t(fe,Ge),t(j,Y),h(e,Ie,c),h(e,q,c),t(q,Ne),t(q,G),t(G,Xe),t(q,m),t(q,$),t($,Gt),t(q,Vt),h(e,Ze,c),h(e,ze,c),t(ze,Lt),h(e,Tt,c),h(e,D,c),t(D,Ae),t(Ae,ot),b(Ve,ot,null),t(D,Le),t(D,rt),t(rt,Yt),h(e,qe,c),h(e,Oe,c),t(Oe,Dt),h(e,vt,c),b(ce,e,c),h(e,Jt,c),h(e,We,c),t(We,Be),t(Be,aa),b(Ut,aa,null),t(We,dl),t(We,la),t(la,wl),h(e,Wa,c),h(e,Pt,c),t(Pt,_l),h(e,ja,c),b($t,e,c),h(e,xa,c),h(e,je,c),t(je,gl),t(je,oa),t(oa,yl),t(je,Ml),t(je,ra),t(ra,bl),t(je,Tl),t(je,sa),t(sa,vl),t(je,Jl),h(e,Ra,c),h(e,st,c),t(st,Ul),t(st,na),t(na,$l),t(st,El),h(e,Ia,c),b(Et,e,c),h(e,Na,c),h(e,Ke,c),t(Ke,nt),t(nt,ia),b(kt,ia,null),t(Ke,kl),t(Ke,pa),t(pa,Wl),h(e,Xa,c),b(it,e,c),h(e,Za,c),h(e,et,c),t(et,pt),t(pt,ha),b(Wt,ha,null),t(et,jl),t(et,fa),t(fa,xl),h(e,Aa,c),h(e,Ye,c),t(Ye,Rl),t(Ye,jt),t(jt,Il),t(Ye,Nl),t(Ye,ca),t(ca,Xl),t(Ye,Zl),h(e,Ba,c),h(e,ht,c),t(ht,Al),t(ht,xt),t(xt,Bl),t(ht,Cl),h(e,Ca,c),h(e,De,c),t(De,ua),t(ua,Sl),t(De,Fl),t(De,Rt),t(Rt,Gl),t(Rt,ma),t(ma,Vl),t(Rt,Ll),t(De,Yl),t(De,It),t(It,Dl),t(It,da),t(da,Pl),t(It,Ql),h(e,Sa,c),h(e,Qt,c),t(Qt,Hl),h(e,Fa,c),h(e,Pe,c),t(Pe,zl),t(Pe,wa),t(wa,ql),t(Pe,Ol),t(Pe,_a),t(_a,Kl),t(Pe,eo),h(e,Ga,c),b(ft,e,c),h(e,Va,c),h(e,tt,c),t(tt,ct),t(ct,ga),b(Nt,ga,null),t(tt,to),t(tt,ya),t(ya,ao),h(e,La,c),h(e,ut,c),t(ut,lo),t(ut,Ht),t(Ht,oo),t(ut,ro),h(e,Ya,c),h(e,at,c),t(at,mt),t(mt,Ma),b(Xt,Ma,null),t(at,so),t(at,ba),t(ba,no),h(e,Da,c),h(e,dt,c),t(dt,io),t(dt,zt),t(zt,po),t(dt,ho),h(e,Pa,c),b(wt,e,c),h(e,Qa,c),h(e,lt,c),t(lt,_t),t(_t,Ta),b(Zt,Ta,null),t(lt,fo),t(lt,va),t(va,co),h(e,Ha,c),h(e,gt,c),t(gt,Ce),t(Ce,uo),t(Ce,At),t(At,mo),t(Ce,wo),t(Ce,Ja),t(Ja,_o),t(Ce,go),t(Ce,Bt),t(Bt,yo),t(Ce,Mo),t(gt,bo),t(gt,Se),t(Se,To),t(Se,Ct),t(Ct,vo),t(Se,Jo),t(Se,Ua),t(Ua,Uo),t(Se,$o),t(Se,St),t(St,Eo),t(Se,ko),za=!0},p(e,[c]){const Ft={};c&2&&(Ft.$$scope={dirty:c,ctx:e}),P.$set(Ft);const $a={};c&2&&($a.$$scope={dirty:c,ctx:e}),it.$set($a);const Ea={};c&2&&(Ea.$$scope={dirty:c,ctx:e}),ft.$set(Ea);const ka={};c&2&&(ka.$$scope={dirty:c,ctx:e}),wt.$set(ka)},i(e){za||(T(Z.$$.fragment,e),T(P.$$.fragment,e),T(ie.$$.fragment,e),T(R.$$.fragment,e),T(N.$$.fragment,e),T(Ve.$$.fragment,e),T(ce.$$.fragment,e),T(Ut.$$.fragment,e),T($t.$$.fragment,e),T(Et.$$.fragment,e),T(kt.$$.fragment,e),T(it.$$.fragment,e),T(Wt.$$.fragment,e),T(ft.$$.fragment,e),T(Nt.$$.fragment,e),T(Xt.$$.fragment,e),T(wt.$$.fragment,e),T(Zt.$$.fragment,e),za=!0)},o(e){v(Z.$$.fragment,e),v(P.$$.fragment,e),v(ie.$$.fragment,e),v(R.$$.fragment,e),v(N.$$.fragment,e),v(Ve.$$.fragment,e),v(ce.$$.fragment,e),v(Ut.$$.fragment,e),v($t.$$.fragment,e),v(Et.$$.fragment,e),v(kt.$$.fragment,e),v(it.$$.fragment,e),v(Wt.$$.fragment,e),v(ft.$$.fragment,e),v(Nt.$$.fragment,e),v(Xt.$$.fragment,e),v(wt.$$.fragment,e),v(Zt.$$.fragment,e),za=!1},d(e){a(p),e&&a(_),e&&a(i),J(Z),e&&a(x),J(P,e),e&&a(I),e&&a(V),e&&a(k),e&&a(me),e&&a($e),J(ie,e),e&&a(Q),e&&a(A),e&&a(ve),J(R,e),e&&a(K),e&&a(ee),e&&a(te),e&&a(S),J(N),e&&a(z),e&&a(j),e&&a(Ie),e&&a(q),e&&a(Ze),e&&a(ze),e&&a(Tt),e&&a(D),J(Ve),e&&a(qe),e&&a(Oe),e&&a(vt),J(ce,e),e&&a(Jt),e&&a(We),J(Ut),e&&a(Wa),e&&a(Pt),e&&a(ja),J($t,e),e&&a(xa),e&&a(je),e&&a(Ra),e&&a(st),e&&a(Ia),J(Et,e),e&&a(Na),e&&a(Ke),J(kt),e&&a(Xa),J(it,e),e&&a(Za),e&&a(et),J(Wt),e&&a(Aa),e&&a(Ye),e&&a(Ba),e&&a(ht),e&&a(Ca),e&&a(De),e&&a(Sa),e&&a(Qt),e&&a(Fa),e&&a(Pe),e&&a(Ga),J(ft,e),e&&a(Va),e&&a(tt),J(Nt),e&&a(La),e&&a(ut),e&&a(Ya),e&&a(at),J(Xt),e&&a(Da),e&&a(dt),e&&a(Pa),J(wt,e),e&&a(Qa),e&&a(lt),J(Zt),e&&a(Ha),e&&a(gt)}}}const Kr={local:"texttoimage",sections:[{local:"hardware-requirements",title:"Hardware requirements"},{local:"upload-model-to-hub",title:"Upload model to Hub"},{local:"save-and-load-checkpoints",title:"Save and load checkpoints"},{local:"finetuning",sections:[{local:"training-with-multiple-gpus",title:"Training with multiple GPUs"}],title:"Fine-tuning"},{local:"training-with-minsnr-weighting",title:"Training with Min-SNR weighting"},{local:"lora",title:"LoRA"},{local:"inference",title:"Inference"},{local:"stable-diffusion-xl",title:"Stable Diffusion XL"}],title:"Text-to-image"};function es(X){return Fr(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class ss extends Ar{constructor(p){super();Br(this,p,es,Or,Cr,{})}}export{ss as default,Kr as metadata};
