import{S as Ei,i as ki,s as xi,e as r,k as f,w as m,t as l,M as Pi,c as i,d as t,m as h,a as n,x as _,h as p,b as u,N as gr,G as a,g as s,y as g,q as $,o as v,B as w,v as qi}from"../../chunks/vendor-hf-doc-builder.js";import{T as $r}from"../../chunks/Tip-hf-doc-builder.js";import{I as ne}from"../../chunks/IconCopyLink-hf-doc-builder.js";import{C as x}from"../../chunks/CodeBlock-hf-doc-builder.js";function Ai(O){let d,k;return{c(){d=r("p"),k=l("\u{1F4A1} A full training run takes 2 hours on 4xV100 GPUs.")},l(c){d=i(c,"P",{});var y=n(d);k=p(y,"\u{1F4A1} A full training run takes 2 hours on 4xV100 GPUs."),y.forEach(t)},m(c,y){s(c,d,y),a(d,k)},d(c){c&&t(d)}}}function ji(O){let d,k,c,y,P;return{c(){d=r("p"),k=l("\u{1F4A1} Learn more about how to create an image dataset for training in the "),c=r("a"),y=l("Create an image dataset"),P=l(" guide."),this.h()},l(b){d=i(b,"P",{});var E=n(d);k=p(E,"\u{1F4A1} Learn more about how to create an image dataset for training in the "),c=i(E,"A",{href:!0,rel:!0});var A=n(c);y=p(A,"Create an image dataset"),A.forEach(t),P=p(E," guide."),E.forEach(t),this.h()},h(){u(c,"href","https://huggingface.co/docs/datasets/image_dataset"),u(c,"rel","nofollow")},m(b,E){s(b,d,E),a(d,k),a(d,c),a(c,y),a(d,P)},d(b){b&&t(d)}}}function zi(O){let d,k,c,y,P;return{c(){d=r("p"),k=l("\u{1F4A1} For more details and context about creating and uploading a dataset to the Hub, take a look at the "),c=r("a"),y=l("Image search with \u{1F917} Datasets"),P=l(" post."),this.h()},l(b){d=i(b,"P",{});var E=n(d);k=p(E,"\u{1F4A1} For more details and context about creating and uploading a dataset to the Hub, take a look at the "),c=i(E,"A",{href:!0,rel:!0});var A=n(c);y=p(A,"Image search with \u{1F917} Datasets"),A.forEach(t),P=p(E," post."),E.forEach(t),this.h()},h(){u(c,"href","https://huggingface.co/blog/image-search-datasets"),u(c,"rel","nofollow")},m(b,E){s(b,d,E),a(d,k),a(d,c),a(c,y),a(d,P)},d(b){b&&t(d)}}}function Hi(O){let d,k,c,y,P,b,E,A,Ya,It,Me,Ra,St,z,vr,Dt,B,Ja,le,Ka,Qa,Tt,Ve,Wa,Ct,pe,Ft,G,Xa,ue,Za,eo,Nt,fe,Ut,Ye,to,Ot,he,Bt,Re,ao,Gt,de,Lt,S,L,tt,ce,oo,at,ro,Mt,Je,io,Vt,me,Yt,D,M,ot,_e,so,rt,no,Rt,Ke,lo,Jt,ge,Kt,H,po,it,uo,fo,st,ho,co,Qt,$e,Wt,T,V,nt,ve,mo,lt,_o,Xt,q,go,we,$o,vo,pt,wo,yo,ut,bo,Eo,Zt,Y,ea,R,ko,ye,xo,Po,ta,be,aa,Ee,ft,wr,oa,J,qo,ke,Ao,jo,ra,xe,ia,Pe,ht,yr,sa,C,K,dt,qe,zo,ct,Ho,na,j,mt,Io,So,Ae,Do,To,_t,Co,Fo,la,je,pa,F,Q,gt,ze,No,$t,Uo,ua,Qe,Oo,fa,W,He,Bo,vt,Go,Lo,Mo,Ie,Vo,wt,Yo,Ro,ha,X,da,We,Jo,ca,N,Z,yt,Se,Ko,bt,Qo,ma,Xe,Wo,_a,De,ga,ee,Xo,Et,Zo,er,$a,Te,va,te,tr,Ce,kt,ar,or,wa,U,ae,xt,Fe,rr,Pt,ir,ya,oe,ba,I,sr,Ne,qt,nr,lr,At,pr,ur,Ea,Ue,ka,re,fr,Oe,hr,dr,xa,Be,Pa,ie,cr,jt,mr,_r,qa;return b=new ne({}),pe=new x({props:{code:"pip install diffusers[training] accelerate datasets",highlighted:"pip install diffusers[training] accelerate datasets"}}),fe=new x({props:{code:"accelerate config",highlighted:"accelerate config"}}),he=new x({props:{code:"accelerate config default",highlighted:"accelerate config default"}}),de=new x({props:{code:`from accelerate.utils import write_basic_config

write_basic_config()`,highlighted:`from accelerate.utils import write_basic_config

write_basic_config()`}}),ce=new ne({}),me=new x({props:{code:"--push_to_hub",highlighted:"--push_to_hub"}}),_e=new ne({}),ge=new x({props:{code:"--checkpointing_steps=500",highlighted:"--checkpointing_steps=500"}}),$e=new x({props:{code:'--resume_from_checkpoint="checkpoint-1500"',highlighted:'--resume_from_checkpoint=<span class="hljs-string">&quot;checkpoint-1500&quot;</span>'}}),ve=new ne({}),Y=new $r({props:{$$slots:{default:[Ai]},$$scope:{ctx:O}}}),be=new x({props:{code:`accelerate launch train_unconditional.py \\
  --dataset_name="huggan/flowers-102-categories" \\
  --resolution=64 \\
  --output_dir="ddpm-ema-flowers-64" \\
  --train_batch_size=16 \\
  --num_epochs=100 \\
  --gradient_accumulation_steps=1 \\
  --learning_rate=1e-4 \\
  --lr_warmup_steps=500 \\
  --mixed_precision=no \\
  --push_to_hub`,highlighted:`accelerate launch train_unconditional.py \\
  --dataset_name=<span class="hljs-string">&quot;huggan/flowers-102-categories&quot;</span> \\
  --resolution=64 \\
  --output_dir=<span class="hljs-string">&quot;ddpm-ema-flowers-64&quot;</span> \\
  --train_batch_size=16 \\
  --num_epochs=100 \\
  --gradient_accumulation_steps=1 \\
  --learning_rate=1e-4 \\
  --lr_warmup_steps=500 \\
  --mixed_precision=no \\
  --push_to_hub`}}),xe=new x({props:{code:`accelerate launch train_unconditional.py \\
  --dataset_name="huggan/pokemon" \\
  --resolution=64 \\
  --output_dir="ddpm-ema-pokemon-64" \\
  --train_batch_size=16 \\
  --num_epochs=100 \\
  --gradient_accumulation_steps=1 \\
  --learning_rate=1e-4 \\
  --lr_warmup_steps=500 \\
  --mixed_precision=no \\
  --push_to_hub`,highlighted:`accelerate launch train_unconditional.py \\
  --dataset_name=<span class="hljs-string">&quot;huggan/pokemon&quot;</span> \\
  --resolution=64 \\
  --output_dir=<span class="hljs-string">&quot;ddpm-ema-pokemon-64&quot;</span> \\
  --train_batch_size=16 \\
  --num_epochs=100 \\
  --gradient_accumulation_steps=1 \\
  --learning_rate=1e-4 \\
  --lr_warmup_steps=500 \\
  --mixed_precision=no \\
  --push_to_hub`}}),qe=new ne({}),je=new x({props:{code:`accelerate launch --mixed_precision="fp16" --multi_gpu train_unconditional.py \\
  --dataset_name="huggan/pokemon" \\
  --resolution=64 --center_crop --random_flip \\
  --output_dir="ddpm-ema-pokemon-64" \\
  --train_batch_size=16 \\
  --num_epochs=100 \\
  --gradient_accumulation_steps=1 \\
  --use_ema \\
  --learning_rate=1e-4 \\
  --lr_warmup_steps=500 \\
  --mixed_precision="fp16" \\
  --logger="wandb"`,highlighted:`accelerate launch --mixed_precision=<span class="hljs-string">&quot;fp16&quot;</span> --multi_gpu train_unconditional.py \\
  --dataset_name=<span class="hljs-string">&quot;huggan/pokemon&quot;</span> \\
  --resolution=64 --center_crop --random_flip \\
  --output_dir=<span class="hljs-string">&quot;ddpm-ema-pokemon-64&quot;</span> \\
  --train_batch_size=16 \\
  --num_epochs=100 \\
  --gradient_accumulation_steps=1 \\
  --use_ema \\
  --learning_rate=1e-4 \\
  --lr_warmup_steps=500 \\
  --mixed_precision=<span class="hljs-string">&quot;fp16&quot;</span> \\
  --logger=<span class="hljs-string">&quot;wandb&quot;</span>`}}),ze=new ne({}),X=new $r({props:{$$slots:{default:[ji]},$$scope:{ctx:O}}}),Se=new ne({}),De=new x({props:{code:`data_dir/xxx.png
data_dir/xxy.png
data_dir/[...]/xxz.png`,highlighted:`data_dir/xxx.png
data_dir/xxy.png
data_dir/[...]/xxz.png`}}),Te=new x({props:{code:`accelerate launch train_unconditional.py \\
    --train_data_dir <path-to-train-directory> \\
    <other-arguments>`,highlighted:`accelerate launch train_unconditional.py \\
    --train_data_dir &lt;path-to-train-directory&gt; \\
    &lt;other-arguments&gt;`}}),Fe=new ne({}),oe=new $r({props:{$$slots:{default:[zi]},$$scope:{ctx:O}}}),Ue=new x({props:{code:`from datasets import load_dataset

# example 1: local folder
dataset = load_dataset("imagefolder", data_dir="path_to_your_folder")

# example 2: local files (supported formats are tar, gzip, zip, xz, rar, zstd)
dataset = load_dataset("imagefolder", data_files="path_to_zip_file")

# example 3: remote files (supported formats are tar, gzip, zip, xz, rar, zstd)
dataset = load_dataset(
    "imagefolder",
    data_files="https://download.microsoft.com/download/3/E/1/3E1C3F21-ECDB-4869-8368-6DEBA77B919F/kagglecatsanddogs_3367a.zip",
)

# example 4: providing several splits
dataset = load_dataset(
    "imagefolder", data_files={"train": ["path/to/file1", "path/to/file2"], "test": ["path/to/file3", "path/to/file4"]}
)`,highlighted:`<span class="hljs-keyword">from</span> datasets <span class="hljs-keyword">import</span> load_dataset

<span class="hljs-comment"># example 1: local folder</span>
dataset = load_dataset(<span class="hljs-string">&quot;imagefolder&quot;</span>, data_dir=<span class="hljs-string">&quot;path_to_your_folder&quot;</span>)

<span class="hljs-comment"># example 2: local files (supported formats are tar, gzip, zip, xz, rar, zstd)</span>
dataset = load_dataset(<span class="hljs-string">&quot;imagefolder&quot;</span>, data_files=<span class="hljs-string">&quot;path_to_zip_file&quot;</span>)

<span class="hljs-comment"># example 3: remote files (supported formats are tar, gzip, zip, xz, rar, zstd)</span>
dataset = load_dataset(
    <span class="hljs-string">&quot;imagefolder&quot;</span>,
    data_files=<span class="hljs-string">&quot;https://download.microsoft.com/download/3/E/1/3E1C3F21-ECDB-4869-8368-6DEBA77B919F/kagglecatsanddogs_3367a.zip&quot;</span>,
)

<span class="hljs-comment"># example 4: providing several splits</span>
dataset = load_dataset(
    <span class="hljs-string">&quot;imagefolder&quot;</span>, data_files={<span class="hljs-string">&quot;train&quot;</span>: [<span class="hljs-string">&quot;path/to/file1&quot;</span>, <span class="hljs-string">&quot;path/to/file2&quot;</span>], <span class="hljs-string">&quot;test&quot;</span>: [<span class="hljs-string">&quot;path/to/file3&quot;</span>, <span class="hljs-string">&quot;path/to/file4&quot;</span>]}
)`}}),Be=new x({props:{code:`# assuming you have ran the huggingface-cli login command in a terminal
dataset.push_to_hub("name_of_your_dataset")

# if you want to push to a private repo, simply pass private=True:
dataset.push_to_hub("name_of_your_dataset", private=True)`,highlighted:`<span class="hljs-comment"># assuming you have ran the huggingface-cli login command in a terminal</span>
dataset.push_to_hub(<span class="hljs-string">&quot;name_of_your_dataset&quot;</span>)

<span class="hljs-comment"># if you want to push to a private repo, simply pass private=True:</span>
dataset.push_to_hub(<span class="hljs-string">&quot;name_of_your_dataset&quot;</span>, private=<span class="hljs-literal">True</span>)`}}),{c(){d=r("meta"),k=f(),c=r("h1"),y=r("a"),P=r("span"),m(b.$$.fragment),E=f(),A=r("span"),Ya=l("Unconditional image generation"),It=f(),Me=r("p"),Ra=l("Unconditional image generation is not conditioned on any text or images, unlike text- or image-to-image models. It only generates images that resemble its training data distribution."),St=f(),z=r("iframe"),Dt=f(),B=r("p"),Ja=l("This guide will show you how to train an unconditional image generation model on existing datasets as well as your own custom dataset. All the training scripts for unconditional image generation can be found "),le=r("a"),Ka=l("here"),Qa=l(" if you\u2019re interested in learning more about the training details."),Tt=f(),Ve=r("p"),Wa=l("Before running the script, make sure you install the library\u2019s training dependencies:"),Ct=f(),m(pe.$$.fragment),Ft=f(),G=r("p"),Xa=l("Next, initialize an \u{1F917} "),ue=r("a"),Za=l("Accelerate"),eo=l(" environment with:"),Nt=f(),m(fe.$$.fragment),Ut=f(),Ye=r("p"),to=l("To setup a default \u{1F917} Accelerate environment without choosing any configurations:"),Ot=f(),m(he.$$.fragment),Bt=f(),Re=r("p"),ao=l("Or if your environment doesn\u2019t support an interactive shell like a notebook, you can use:"),Gt=f(),m(de.$$.fragment),Lt=f(),S=r("h2"),L=r("a"),tt=r("span"),m(ce.$$.fragment),oo=f(),at=r("span"),ro=l("Upload model to Hub"),Mt=f(),Je=r("p"),io=l("You can upload your model on the Hub by adding the following argument to the training script:"),Vt=f(),m(me.$$.fragment),Yt=f(),D=r("h2"),M=r("a"),ot=r("span"),m(_e.$$.fragment),so=f(),rt=r("span"),no=l("Save and load checkpoints"),Rt=f(),Ke=r("p"),lo=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:"),Jt=f(),m(ge.$$.fragment),Kt=f(),H=r("p"),po=l("The full training state is saved in a subfolder in the "),it=r("code"),uo=l("output_dir"),fo=l(" every 500 steps, which allows you to load a checkpoint and resume training if you pass the "),st=r("code"),ho=l("--resume_from_checkpoint"),co=l(" argument to the training script:"),Qt=f(),m($e.$$.fragment),Wt=f(),T=r("h2"),V=r("a"),nt=r("span"),m(ve.$$.fragment),mo=f(),lt=r("span"),_o=l("Finetuning"),Xt=f(),q=r("p"),go=l("You\u2019re ready to launch the "),we=r("a"),$o=l("training script"),vo=l(" now! Specify the dataset name to finetune on with the "),pt=r("code"),wo=l("--dataset_name"),yo=l(" argument and then save it to the path in "),ut=r("code"),bo=l("--output_dir"),Eo=l("."),Zt=f(),m(Y.$$.fragment),ea=f(),R=r("p"),ko=l("For example, to finetune on the "),ye=r("a"),xo=l("Oxford Flowers"),Po=l(" dataset:"),ta=f(),m(be.$$.fragment),aa=f(),Ee=r("div"),ft=r("img"),oa=f(),J=r("p"),qo=l("Or if you want to train your model on the "),ke=r("a"),Ao=l("Pokemon"),jo=l(" dataset:"),ra=f(),m(xe.$$.fragment),ia=f(),Pe=r("div"),ht=r("img"),sa=f(),C=r("h3"),K=r("a"),dt=r("span"),m(qe.$$.fragment),zo=f(),ct=r("span"),Ho=l("Training with multiple GPUs"),na=f(),j=r("p"),mt=r("code"),Io=l("accelerate"),So=l(" allows for seamless multi-GPU training. Follow the instructions "),Ae=r("a"),Do=l("here"),To=l(`
for running distributed training with `),_t=r("code"),Co=l("accelerate"),Fo=l(". Here is an example command:"),la=f(),m(je.$$.fragment),pa=f(),F=r("h2"),Q=r("a"),gt=r("span"),m(ze.$$.fragment),No=f(),$t=r("span"),Uo=l("Finetuning with your own data"),ua=f(),Qe=r("p"),Oo=l("There are two ways to finetune a model on your own dataset:"),fa=f(),W=r("ul"),He=r("li"),Bo=l("provide your own folder of images to the "),vt=r("code"),Go=l("--train_data_dir"),Lo=l(" argument"),Mo=f(),Ie=r("li"),Vo=l("upload your dataset to the Hub and pass the dataset repository id to the "),wt=r("code"),Yo=l("--dataset_name"),Ro=l(" argument."),ha=f(),m(X.$$.fragment),da=f(),We=r("p"),Jo=l("Below, we explain both in more detail."),ca=f(),N=r("h3"),Z=r("a"),yt=r("span"),m(Se.$$.fragment),Ko=f(),bt=r("span"),Qo=l("Provide the dataset as a folder"),ma=f(),Xe=r("p"),Wo=l("If you provide your own dataset as a folder, the script expects the following directory structure:"),_a=f(),m(De.$$.fragment),ga=f(),ee=r("p"),Xo=l("Pass the path to the folder containing the images to the "),Et=r("code"),Zo=l("--train_data_dir"),er=l(" argument and launch the training:"),$a=f(),m(Te.$$.fragment),va=f(),te=r("p"),tr=l("Internally, the script uses the "),Ce=r("a"),kt=r("code"),ar=l("ImageFolder"),or=l(" to automatically build a dataset from the folder."),wa=f(),U=r("h3"),ae=r("a"),xt=r("span"),m(Fe.$$.fragment),rr=f(),Pt=r("span"),ir=l("Upload your data to the Hub"),ya=f(),m(oe.$$.fragment),ba=f(),I=r("p"),sr=l("To upload your dataset to the Hub, you can start by creating one with the "),Ne=r("a"),qt=r("code"),nr=l("ImageFolder"),lr=l(" feature, which creates an "),At=r("code"),pr=l("image"),ur=l(" column containing the PIL-encoded images, from \u{1F917} Datasets:"),Ea=f(),m(Ue.$$.fragment),ka=f(),re=r("p"),fr=l("Then you can use the "),Oe=r("a"),hr=l("push_to_hub"),dr=l(" method to upload it to the Hub:"),xa=f(),m(Be.$$.fragment),Pa=f(),ie=r("p"),cr=l("Now train your model by simply setting the "),jt=r("code"),mr=l("--dataset_name"),_r=l(" argument to the name of your dataset on the Hub."),this.h()},l(e){const o=Pi('[data-svelte="svelte-1phssyn"]',document.head);d=i(o,"META",{name:!0,content:!0}),o.forEach(t),k=h(e),c=i(e,"H1",{class:!0});var Ge=n(c);y=i(Ge,"A",{id:!0,class:!0,href:!0});var zt=n(y);P=i(zt,"SPAN",{});var Ht=n(P);_(b.$$.fragment,Ht),Ht.forEach(t),zt.forEach(t),E=h(Ge),A=i(Ge,"SPAN",{});var br=n(A);Ya=p(br,"Unconditional image generation"),br.forEach(t),Ge.forEach(t),It=h(e),Me=i(e,"P",{});var Er=n(Me);Ra=p(Er,"Unconditional image generation is not conditioned on any text or images, unlike text- or image-to-image models. It only generates images that resemble its training data distribution."),Er.forEach(t),St=h(e),z=i(e,"IFRAME",{src:!0,frameborder:!0,width:!0,height:!0}),n(z).forEach(t),Dt=h(e),B=i(e,"P",{});var Aa=n(B);Ja=p(Aa,"This guide will show you how to train an unconditional image generation model on existing datasets as well as your own custom dataset. All the training scripts for unconditional image generation can be found "),le=i(Aa,"A",{href:!0,rel:!0});var kr=n(le);Ka=p(kr,"here"),kr.forEach(t),Qa=p(Aa," if you\u2019re interested in learning more about the training details."),Aa.forEach(t),Tt=h(e),Ve=i(e,"P",{});var xr=n(Ve);Wa=p(xr,"Before running the script, make sure you install the library\u2019s training dependencies:"),xr.forEach(t),Ct=h(e),_(pe.$$.fragment,e),Ft=h(e),G=i(e,"P",{});var ja=n(G);Xa=p(ja,"Next, initialize an \u{1F917} "),ue=i(ja,"A",{href:!0,rel:!0});var Pr=n(ue);Za=p(Pr,"Accelerate"),Pr.forEach(t),eo=p(ja," environment with:"),ja.forEach(t),Nt=h(e),_(fe.$$.fragment,e),Ut=h(e),Ye=i(e,"P",{});var qr=n(Ye);to=p(qr,"To setup a default \u{1F917} Accelerate environment without choosing any configurations:"),qr.forEach(t),Ot=h(e),_(he.$$.fragment,e),Bt=h(e),Re=i(e,"P",{});var Ar=n(Re);ao=p(Ar,"Or if your environment doesn\u2019t support an interactive shell like a notebook, you can use:"),Ar.forEach(t),Gt=h(e),_(de.$$.fragment,e),Lt=h(e),S=i(e,"H2",{class:!0});var za=n(S);L=i(za,"A",{id:!0,class:!0,href:!0});var jr=n(L);tt=i(jr,"SPAN",{});var zr=n(tt);_(ce.$$.fragment,zr),zr.forEach(t),jr.forEach(t),oo=h(za),at=i(za,"SPAN",{});var Hr=n(at);ro=p(Hr,"Upload model to Hub"),Hr.forEach(t),za.forEach(t),Mt=h(e),Je=i(e,"P",{});var Ir=n(Je);io=p(Ir,"You can upload your model on the Hub by adding the following argument to the training script:"),Ir.forEach(t),Vt=h(e),_(me.$$.fragment,e),Yt=h(e),D=i(e,"H2",{class:!0});var Ha=n(D);M=i(Ha,"A",{id:!0,class:!0,href:!0});var Sr=n(M);ot=i(Sr,"SPAN",{});var Dr=n(ot);_(_e.$$.fragment,Dr),Dr.forEach(t),Sr.forEach(t),so=h(Ha),rt=i(Ha,"SPAN",{});var Tr=n(rt);no=p(Tr,"Save and load checkpoints"),Tr.forEach(t),Ha.forEach(t),Rt=h(e),Ke=i(e,"P",{});var Cr=n(Ke);lo=p(Cr,"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:"),Cr.forEach(t),Jt=h(e),_(ge.$$.fragment,e),Kt=h(e),H=i(e,"P",{});var Ze=n(H);po=p(Ze,"The full training state is saved in a subfolder in the "),it=i(Ze,"CODE",{});var Fr=n(it);uo=p(Fr,"output_dir"),Fr.forEach(t),fo=p(Ze," every 500 steps, which allows you to load a checkpoint and resume training if you pass the "),st=i(Ze,"CODE",{});var Nr=n(st);ho=p(Nr,"--resume_from_checkpoint"),Nr.forEach(t),co=p(Ze," argument to the training script:"),Ze.forEach(t),Qt=h(e),_($e.$$.fragment,e),Wt=h(e),T=i(e,"H2",{class:!0});var Ia=n(T);V=i(Ia,"A",{id:!0,class:!0,href:!0});var Ur=n(V);nt=i(Ur,"SPAN",{});var Or=n(nt);_(ve.$$.fragment,Or),Or.forEach(t),Ur.forEach(t),mo=h(Ia),lt=i(Ia,"SPAN",{});var Br=n(lt);_o=p(Br,"Finetuning"),Br.forEach(t),Ia.forEach(t),Xt=h(e),q=i(e,"P",{});var se=n(q);go=p(se,"You\u2019re ready to launch the "),we=i(se,"A",{href:!0,rel:!0});var Gr=n(we);$o=p(Gr,"training script"),Gr.forEach(t),vo=p(se," now! Specify the dataset name to finetune on with the "),pt=i(se,"CODE",{});var Lr=n(pt);wo=p(Lr,"--dataset_name"),Lr.forEach(t),yo=p(se," argument and then save it to the path in "),ut=i(se,"CODE",{});var Mr=n(ut);bo=p(Mr,"--output_dir"),Mr.forEach(t),Eo=p(se,"."),se.forEach(t),Zt=h(e),_(Y.$$.fragment,e),ea=h(e),R=i(e,"P",{});var Sa=n(R);ko=p(Sa,"For example, to finetune on the "),ye=i(Sa,"A",{href:!0,rel:!0});var Vr=n(ye);xo=p(Vr,"Oxford Flowers"),Vr.forEach(t),Po=p(Sa," dataset:"),Sa.forEach(t),ta=h(e),_(be.$$.fragment,e),aa=h(e),Ee=i(e,"DIV",{class:!0});var Yr=n(Ee);ft=i(Yr,"IMG",{src:!0}),Yr.forEach(t),oa=h(e),J=i(e,"P",{});var Da=n(J);qo=p(Da,"Or if you want to train your model on the "),ke=i(Da,"A",{href:!0,rel:!0});var Rr=n(ke);Ao=p(Rr,"Pokemon"),Rr.forEach(t),jo=p(Da," dataset:"),Da.forEach(t),ra=h(e),_(xe.$$.fragment,e),ia=h(e),Pe=i(e,"DIV",{class:!0});var Jr=n(Pe);ht=i(Jr,"IMG",{src:!0}),Jr.forEach(t),sa=h(e),C=i(e,"H3",{class:!0});var Ta=n(C);K=i(Ta,"A",{id:!0,class:!0,href:!0});var Kr=n(K);dt=i(Kr,"SPAN",{});var Qr=n(dt);_(qe.$$.fragment,Qr),Qr.forEach(t),Kr.forEach(t),zo=h(Ta),ct=i(Ta,"SPAN",{});var Wr=n(ct);Ho=p(Wr,"Training with multiple GPUs"),Wr.forEach(t),Ta.forEach(t),na=h(e),j=i(e,"P",{});var Le=n(j);mt=i(Le,"CODE",{});var Xr=n(mt);Io=p(Xr,"accelerate"),Xr.forEach(t),So=p(Le," allows for seamless multi-GPU training. Follow the instructions "),Ae=i(Le,"A",{href:!0,rel:!0});var Zr=n(Ae);Do=p(Zr,"here"),Zr.forEach(t),To=p(Le,`
for running distributed training with `),_t=i(Le,"CODE",{});var ei=n(_t);Co=p(ei,"accelerate"),ei.forEach(t),Fo=p(Le,". Here is an example command:"),Le.forEach(t),la=h(e),_(je.$$.fragment,e),pa=h(e),F=i(e,"H2",{class:!0});var Ca=n(F);Q=i(Ca,"A",{id:!0,class:!0,href:!0});var ti=n(Q);gt=i(ti,"SPAN",{});var ai=n(gt);_(ze.$$.fragment,ai),ai.forEach(t),ti.forEach(t),No=h(Ca),$t=i(Ca,"SPAN",{});var oi=n($t);Uo=p(oi,"Finetuning with your own data"),oi.forEach(t),Ca.forEach(t),ua=h(e),Qe=i(e,"P",{});var ri=n(Qe);Oo=p(ri,"There are two ways to finetune a model on your own dataset:"),ri.forEach(t),fa=h(e),W=i(e,"UL",{});var Fa=n(W);He=i(Fa,"LI",{});var Na=n(He);Bo=p(Na,"provide your own folder of images to the "),vt=i(Na,"CODE",{});var ii=n(vt);Go=p(ii,"--train_data_dir"),ii.forEach(t),Lo=p(Na," argument"),Na.forEach(t),Mo=h(Fa),Ie=i(Fa,"LI",{});var Ua=n(Ie);Vo=p(Ua,"upload your dataset to the Hub and pass the dataset repository id to the "),wt=i(Ua,"CODE",{});var si=n(wt);Yo=p(si,"--dataset_name"),si.forEach(t),Ro=p(Ua," argument."),Ua.forEach(t),Fa.forEach(t),ha=h(e),_(X.$$.fragment,e),da=h(e),We=i(e,"P",{});var ni=n(We);Jo=p(ni,"Below, we explain both in more detail."),ni.forEach(t),ca=h(e),N=i(e,"H3",{class:!0});var Oa=n(N);Z=i(Oa,"A",{id:!0,class:!0,href:!0});var li=n(Z);yt=i(li,"SPAN",{});var pi=n(yt);_(Se.$$.fragment,pi),pi.forEach(t),li.forEach(t),Ko=h(Oa),bt=i(Oa,"SPAN",{});var ui=n(bt);Qo=p(ui,"Provide the dataset as a folder"),ui.forEach(t),Oa.forEach(t),ma=h(e),Xe=i(e,"P",{});var fi=n(Xe);Wo=p(fi,"If you provide your own dataset as a folder, the script expects the following directory structure:"),fi.forEach(t),_a=h(e),_(De.$$.fragment,e),ga=h(e),ee=i(e,"P",{});var Ba=n(ee);Xo=p(Ba,"Pass the path to the folder containing the images to the "),Et=i(Ba,"CODE",{});var hi=n(Et);Zo=p(hi,"--train_data_dir"),hi.forEach(t),er=p(Ba," argument and launch the training:"),Ba.forEach(t),$a=h(e),_(Te.$$.fragment,e),va=h(e),te=i(e,"P",{});var Ga=n(te);tr=p(Ga,"Internally, the script uses the "),Ce=i(Ga,"A",{href:!0,rel:!0});var di=n(Ce);kt=i(di,"CODE",{});var ci=n(kt);ar=p(ci,"ImageFolder"),ci.forEach(t),di.forEach(t),or=p(Ga," to automatically build a dataset from the folder."),Ga.forEach(t),wa=h(e),U=i(e,"H3",{class:!0});var La=n(U);ae=i(La,"A",{id:!0,class:!0,href:!0});var mi=n(ae);xt=i(mi,"SPAN",{});var _i=n(xt);_(Fe.$$.fragment,_i),_i.forEach(t),mi.forEach(t),rr=h(La),Pt=i(La,"SPAN",{});var gi=n(Pt);ir=p(gi,"Upload your data to the Hub"),gi.forEach(t),La.forEach(t),ya=h(e),_(oe.$$.fragment,e),ba=h(e),I=i(e,"P",{});var et=n(I);sr=p(et,"To upload your dataset to the Hub, you can start by creating one with the "),Ne=i(et,"A",{href:!0,rel:!0});var $i=n(Ne);qt=i($i,"CODE",{});var vi=n(qt);nr=p(vi,"ImageFolder"),vi.forEach(t),$i.forEach(t),lr=p(et," feature, which creates an "),At=i(et,"CODE",{});var wi=n(At);pr=p(wi,"image"),wi.forEach(t),ur=p(et," column containing the PIL-encoded images, from \u{1F917} Datasets:"),et.forEach(t),Ea=h(e),_(Ue.$$.fragment,e),ka=h(e),re=i(e,"P",{});var Ma=n(re);fr=p(Ma,"Then you can use the "),Oe=i(Ma,"A",{href:!0,rel:!0});var yi=n(Oe);hr=p(yi,"push_to_hub"),yi.forEach(t),dr=p(Ma," method to upload it to the Hub:"),Ma.forEach(t),xa=h(e),_(Be.$$.fragment,e),Pa=h(e),ie=i(e,"P",{});var Va=n(ie);cr=p(Va,"Now train your model by simply setting the "),jt=i(Va,"CODE",{});var bi=n(jt);mr=p(bi,"--dataset_name"),bi.forEach(t),_r=p(Va," argument to the name of your dataset on the Hub."),Va.forEach(t),this.h()},h(){u(d,"name","hf:doc:metadata"),u(d,"content",JSON.stringify(Ii)),u(y,"id","unconditional-image-generation"),u(y,"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(y,"href","#unconditional-image-generation"),u(c,"class","relative group"),gr(z.src,vr="https://stevhliu-ddpm-butterflies-128.hf.space")||u(z,"src",vr),u(z,"frameborder","0"),u(z,"width","850"),u(z,"height","550"),u(le,"href","https://github.com/huggingface/diffusers/tree/main/examples/unconditional_image_generation"),u(le,"rel","nofollow"),u(ue,"href","https://github.com/huggingface/accelerate/"),u(ue,"rel","nofollow"),u(L,"id","upload-model-to-hub"),u(L,"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(L,"href","#upload-model-to-hub"),u(S,"class","relative group"),u(M,"id","save-and-load-checkpoints"),u(M,"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(M,"href","#save-and-load-checkpoints"),u(D,"class","relative group"),u(V,"id","finetuning"),u(V,"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(V,"href","#finetuning"),u(T,"class","relative group"),u(we,"href","https://github.com/huggingface/diffusers/blob/main/examples/unconditional_image_generation/train_unconditional.py"),u(we,"rel","nofollow"),u(ye,"href","https://huggingface.co/datasets/huggan/flowers-102-categories"),u(ye,"rel","nofollow"),gr(ft.src,wr="https://user-images.githubusercontent.com/26864830/180248660-a0b143d0-b89a-42c5-8656-2ebf6ece7e52.png")||u(ft,"src",wr),u(Ee,"class","flex justify-center"),u(ke,"href","https://huggingface.co/datasets/huggan/pokemon"),u(ke,"rel","nofollow"),gr(ht.src,yr="https://user-images.githubusercontent.com/26864830/180248200-928953b4-db38-48db-b0c6-8b740fe6786f.png")||u(ht,"src",yr),u(Pe,"class","flex justify-center"),u(K,"id","training-with-multiple-gpus"),u(K,"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(K,"href","#training-with-multiple-gpus"),u(C,"class","relative group"),u(Ae,"href","https://huggingface.co/docs/accelerate/basic_tutorials/launch"),u(Ae,"rel","nofollow"),u(Q,"id","finetuning-with-your-own-data"),u(Q,"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(Q,"href","#finetuning-with-your-own-data"),u(F,"class","relative group"),u(Z,"id","provide-the-dataset-as-a-folder"),u(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"),u(Z,"href","#provide-the-dataset-as-a-folder"),u(N,"class","relative group"),u(Ce,"href","https://huggingface.co/docs/datasets/image_load#imagefolder"),u(Ce,"rel","nofollow"),u(ae,"id","upload-your-data-to-the-hub"),u(ae,"class","header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full"),u(ae,"href","#upload-your-data-to-the-hub"),u(U,"class","relative group"),u(Ne,"href","https://huggingface.co/docs/datasets/image_load#imagefolder"),u(Ne,"rel","nofollow"),u(Oe,"href","https://huggingface.co/docs/datasets/v2.11.0/en/package_reference/main_classes#datasets.Dataset.push_to_hub"),u(Oe,"rel","nofollow")},m(e,o){a(document.head,d),s(e,k,o),s(e,c,o),a(c,y),a(y,P),g(b,P,null),a(c,E),a(c,A),a(A,Ya),s(e,It,o),s(e,Me,o),a(Me,Ra),s(e,St,o),s(e,z,o),s(e,Dt,o),s(e,B,o),a(B,Ja),a(B,le),a(le,Ka),a(B,Qa),s(e,Tt,o),s(e,Ve,o),a(Ve,Wa),s(e,Ct,o),g(pe,e,o),s(e,Ft,o),s(e,G,o),a(G,Xa),a(G,ue),a(ue,Za),a(G,eo),s(e,Nt,o),g(fe,e,o),s(e,Ut,o),s(e,Ye,o),a(Ye,to),s(e,Ot,o),g(he,e,o),s(e,Bt,o),s(e,Re,o),a(Re,ao),s(e,Gt,o),g(de,e,o),s(e,Lt,o),s(e,S,o),a(S,L),a(L,tt),g(ce,tt,null),a(S,oo),a(S,at),a(at,ro),s(e,Mt,o),s(e,Je,o),a(Je,io),s(e,Vt,o),g(me,e,o),s(e,Yt,o),s(e,D,o),a(D,M),a(M,ot),g(_e,ot,null),a(D,so),a(D,rt),a(rt,no),s(e,Rt,o),s(e,Ke,o),a(Ke,lo),s(e,Jt,o),g(ge,e,o),s(e,Kt,o),s(e,H,o),a(H,po),a(H,it),a(it,uo),a(H,fo),a(H,st),a(st,ho),a(H,co),s(e,Qt,o),g($e,e,o),s(e,Wt,o),s(e,T,o),a(T,V),a(V,nt),g(ve,nt,null),a(T,mo),a(T,lt),a(lt,_o),s(e,Xt,o),s(e,q,o),a(q,go),a(q,we),a(we,$o),a(q,vo),a(q,pt),a(pt,wo),a(q,yo),a(q,ut),a(ut,bo),a(q,Eo),s(e,Zt,o),g(Y,e,o),s(e,ea,o),s(e,R,o),a(R,ko),a(R,ye),a(ye,xo),a(R,Po),s(e,ta,o),g(be,e,o),s(e,aa,o),s(e,Ee,o),a(Ee,ft),s(e,oa,o),s(e,J,o),a(J,qo),a(J,ke),a(ke,Ao),a(J,jo),s(e,ra,o),g(xe,e,o),s(e,ia,o),s(e,Pe,o),a(Pe,ht),s(e,sa,o),s(e,C,o),a(C,K),a(K,dt),g(qe,dt,null),a(C,zo),a(C,ct),a(ct,Ho),s(e,na,o),s(e,j,o),a(j,mt),a(mt,Io),a(j,So),a(j,Ae),a(Ae,Do),a(j,To),a(j,_t),a(_t,Co),a(j,Fo),s(e,la,o),g(je,e,o),s(e,pa,o),s(e,F,o),a(F,Q),a(Q,gt),g(ze,gt,null),a(F,No),a(F,$t),a($t,Uo),s(e,ua,o),s(e,Qe,o),a(Qe,Oo),s(e,fa,o),s(e,W,o),a(W,He),a(He,Bo),a(He,vt),a(vt,Go),a(He,Lo),a(W,Mo),a(W,Ie),a(Ie,Vo),a(Ie,wt),a(wt,Yo),a(Ie,Ro),s(e,ha,o),g(X,e,o),s(e,da,o),s(e,We,o),a(We,Jo),s(e,ca,o),s(e,N,o),a(N,Z),a(Z,yt),g(Se,yt,null),a(N,Ko),a(N,bt),a(bt,Qo),s(e,ma,o),s(e,Xe,o),a(Xe,Wo),s(e,_a,o),g(De,e,o),s(e,ga,o),s(e,ee,o),a(ee,Xo),a(ee,Et),a(Et,Zo),a(ee,er),s(e,$a,o),g(Te,e,o),s(e,va,o),s(e,te,o),a(te,tr),a(te,Ce),a(Ce,kt),a(kt,ar),a(te,or),s(e,wa,o),s(e,U,o),a(U,ae),a(ae,xt),g(Fe,xt,null),a(U,rr),a(U,Pt),a(Pt,ir),s(e,ya,o),g(oe,e,o),s(e,ba,o),s(e,I,o),a(I,sr),a(I,Ne),a(Ne,qt),a(qt,nr),a(I,lr),a(I,At),a(At,pr),a(I,ur),s(e,Ea,o),g(Ue,e,o),s(e,ka,o),s(e,re,o),a(re,fr),a(re,Oe),a(Oe,hr),a(re,dr),s(e,xa,o),g(Be,e,o),s(e,Pa,o),s(e,ie,o),a(ie,cr),a(ie,jt),a(jt,mr),a(ie,_r),qa=!0},p(e,[o]){const Ge={};o&2&&(Ge.$$scope={dirty:o,ctx:e}),Y.$set(Ge);const zt={};o&2&&(zt.$$scope={dirty:o,ctx:e}),X.$set(zt);const Ht={};o&2&&(Ht.$$scope={dirty:o,ctx:e}),oe.$set(Ht)},i(e){qa||($(b.$$.fragment,e),$(pe.$$.fragment,e),$(fe.$$.fragment,e),$(he.$$.fragment,e),$(de.$$.fragment,e),$(ce.$$.fragment,e),$(me.$$.fragment,e),$(_e.$$.fragment,e),$(ge.$$.fragment,e),$($e.$$.fragment,e),$(ve.$$.fragment,e),$(Y.$$.fragment,e),$(be.$$.fragment,e),$(xe.$$.fragment,e),$(qe.$$.fragment,e),$(je.$$.fragment,e),$(ze.$$.fragment,e),$(X.$$.fragment,e),$(Se.$$.fragment,e),$(De.$$.fragment,e),$(Te.$$.fragment,e),$(Fe.$$.fragment,e),$(oe.$$.fragment,e),$(Ue.$$.fragment,e),$(Be.$$.fragment,e),qa=!0)},o(e){v(b.$$.fragment,e),v(pe.$$.fragment,e),v(fe.$$.fragment,e),v(he.$$.fragment,e),v(de.$$.fragment,e),v(ce.$$.fragment,e),v(me.$$.fragment,e),v(_e.$$.fragment,e),v(ge.$$.fragment,e),v($e.$$.fragment,e),v(ve.$$.fragment,e),v(Y.$$.fragment,e),v(be.$$.fragment,e),v(xe.$$.fragment,e),v(qe.$$.fragment,e),v(je.$$.fragment,e),v(ze.$$.fragment,e),v(X.$$.fragment,e),v(Se.$$.fragment,e),v(De.$$.fragment,e),v(Te.$$.fragment,e),v(Fe.$$.fragment,e),v(oe.$$.fragment,e),v(Ue.$$.fragment,e),v(Be.$$.fragment,e),qa=!1},d(e){t(d),e&&t(k),e&&t(c),w(b),e&&t(It),e&&t(Me),e&&t(St),e&&t(z),e&&t(Dt),e&&t(B),e&&t(Tt),e&&t(Ve),e&&t(Ct),w(pe,e),e&&t(Ft),e&&t(G),e&&t(Nt),w(fe,e),e&&t(Ut),e&&t(Ye),e&&t(Ot),w(he,e),e&&t(Bt),e&&t(Re),e&&t(Gt),w(de,e),e&&t(Lt),e&&t(S),w(ce),e&&t(Mt),e&&t(Je),e&&t(Vt),w(me,e),e&&t(Yt),e&&t(D),w(_e),e&&t(Rt),e&&t(Ke),e&&t(Jt),w(ge,e),e&&t(Kt),e&&t(H),e&&t(Qt),w($e,e),e&&t(Wt),e&&t(T),w(ve),e&&t(Xt),e&&t(q),e&&t(Zt),w(Y,e),e&&t(ea),e&&t(R),e&&t(ta),w(be,e),e&&t(aa),e&&t(Ee),e&&t(oa),e&&t(J),e&&t(ra),w(xe,e),e&&t(ia),e&&t(Pe),e&&t(sa),e&&t(C),w(qe),e&&t(na),e&&t(j),e&&t(la),w(je,e),e&&t(pa),e&&t(F),w(ze),e&&t(ua),e&&t(Qe),e&&t(fa),e&&t(W),e&&t(ha),w(X,e),e&&t(da),e&&t(We),e&&t(ca),e&&t(N),w(Se),e&&t(ma),e&&t(Xe),e&&t(_a),w(De,e),e&&t(ga),e&&t(ee),e&&t($a),w(Te,e),e&&t(va),e&&t(te),e&&t(wa),e&&t(U),w(Fe),e&&t(ya),w(oe,e),e&&t(ba),e&&t(I),e&&t(Ea),w(Ue,e),e&&t(ka),e&&t(re),e&&t(xa),w(Be,e),e&&t(Pa),e&&t(ie)}}}const Ii={local:"unconditional-image-generation",sections:[{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:"Finetuning"},{local:"finetuning-with-your-own-data",sections:[{local:"provide-the-dataset-as-a-folder",title:"Provide the dataset as a folder"},{local:"upload-your-data-to-the-hub",title:"Upload your data to the Hub"}],title:"Finetuning with your own data"}],title:"Unconditional image generation"};function Si(O){return qi(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Ni extends Ei{constructor(d){super();ki(this,d,Si,Hi,xi,{})}}export{Ni as default,Ii as metadata};
