import{s as le,z as ne,o as ie,n as ae}from"../chunks/scheduler.182ea377.js";import{S as se,i as oe,g as s,s as i,r as u,A as re,h as o,f as l,c as a,j as Rt,u as m,x as p,k as b,y as pe,a as n,v as f,d as c,t as M,w as d}from"../chunks/index.abf12888.js";import{T as ue}from"../chunks/Tip.230e2334.js";import{C as $}from"../chunks/CodeBlock.57fe6e13.js";import{H as et}from"../chunks/Heading.16916d63.js";function me(lt){let r,_="💡 A full training run takes 2 hours on 4xV100 GPUs.";return{c(){r=s("p"),r.textContent=_},l(h){r=o(h,"P",{"data-svelte-h":!0}),p(r)!=="svelte-1tmqfon"&&(r.textContent=_)},m(h,K){n(h,r,K)},p:ae,d(h){h&&l(r)}}}function fe(lt){let r,_,h,K,j,nt,C,kt="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.",it,g,Gt,at,T,Ht='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 <a href="https://github.com/huggingface/diffusers/tree/main/examples/unconditional_image_generation" rel="nofollow">here</a> if you’re interested in learning more about the training details.',st,v,Vt="Before running the script, make sure you install the library’s training dependencies:",ot,x,rt,W,Yt='Next, initialize an 🤗 <a href="https://github.com/huggingface/accelerate/" rel="nofollow">Accelerate</a> environment with:',pt,Z,ut,A,St="To setup a default 🤗 Accelerate environment without choosing any configurations:",mt,N,ft,X,Qt="Or if your environment doesn’t support an interactive shell like a notebook, you can use:",ct,E,Mt,J,dt,L,zt="You can upload your model on the Hub by adding the following argument to the training script:",ht,R,gt,k,$t,G,Ft="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:",yt,H,Ut,V,It="The full training state is saved in a subfolder in the <code>output_dir</code> every 500 steps, which allows you to load a checkpoint and resume training if you pass the <code>--resume_from_checkpoint</code> argument to the training script:",wt,Y,bt,S,_t,Q,Pt='You’re ready to launch the <a href="https://github.com/huggingface/diffusers/blob/main/examples/unconditional_image_generation/train_unconditional.py" rel="nofollow">training script</a> now! Specify the dataset name to finetune on with the <code>--dataset_name</code> argument and then save it to the path in <code>--output_dir</code>. To use your own dataset, take a look at the <a href="create_dataset">Create a dataset for training</a> guide.',jt,z,Bt="The training script creates and saves a <code>diffusion_pytorch_model.bin</code> file in your repository.",Ct,y,Tt,F,qt='For example, to finetune on the <a href="https://huggingface.co/datasets/huggan/flowers-102-categories" rel="nofollow">Oxford Flowers</a> dataset:',vt,I,xt,U,Dt='<img src="https://user-images.githubusercontent.com/26864830/180248660-a0b143d0-b89a-42c5-8656-2ebf6ece7e52.png"/>',Wt,P,Ot='Or if you want to train your model on the <a href="https://huggingface.co/datasets/huggan/pokemon" rel="nofollow">Pokemon</a> dataset:',Zt,B,At,w,Kt='<img src="https://user-images.githubusercontent.com/26864830/180248200-928953b4-db38-48db-b0c6-8b740fe6786f.png"/>',Nt,q,Xt,D,te=`<code>accelerate</code> allows for seamless multi-GPU training. Follow the instructions <a href="https://huggingface.co/docs/accelerate/basic_tutorials/launch" rel="nofollow">here</a>
for running distributed training with <code>accelerate</code>. Here is an example command:`,Et,O,Jt,tt,Lt;return j=new et({props:{title:"Unconditional image generation",local:"unconditional-image-generation",headingTag:"h1"}}),x=new $({props:{code:"cGlwJTIwaW5zdGFsbCUyMGRpZmZ1c2VycyU1QnRyYWluaW5nJTVEJTIwYWNjZWxlcmF0ZSUyMGRhdGFzZXRz",highlighted:"pip install diffusers[training] accelerate datasets",wrap:!1}}),Z=new $({props:{code:"YWNjZWxlcmF0ZSUyMGNvbmZpZw==",highlighted:"accelerate config",wrap:!1}}),N=new $({props:{code:"YWNjZWxlcmF0ZSUyMGNvbmZpZyUyMGRlZmF1bHQ=",highlighted:"accelerate config default",wrap:!1}}),E=new $({props:{code:"ZnJvbSUyMGFjY2VsZXJhdGUudXRpbHMlMjBpbXBvcnQlMjB3cml0ZV9iYXNpY19jb25maWclMEElMEF3cml0ZV9iYXNpY19jb25maWcoKQ==",highlighted:`from accelerate.utils import write_basic_config

write_basic_config()`,wrap:!1}}),J=new et({props:{title:"Upload model to Hub",local:"upload-model-to-hub",headingTag:"h2"}}),R=new $({props:{code:"LS1wdXNoX3RvX2h1Yg==",highlighted:"--push_to_hub",wrap:!1}}),k=new et({props:{title:"Save and load checkpoints",local:"save-and-load-checkpoints",headingTag:"h2"}}),H=new $({props:{code:"LS1jaGVja3BvaW50aW5nX3N0ZXBzJTNENTAw",highlighted:"--checkpointing_steps=500",wrap:!1}}),Y=new $({props:{code:"LS1yZXN1bWVfZnJvbV9jaGVja3BvaW50JTNEJTIyY2hlY2twb2ludC0xNTAwJTIy",highlighted:'--resume_from_checkpoint=<span class="hljs-string">&quot;checkpoint-1500&quot;</span>',wrap:!1}}),S=new et({props:{title:"Finetuning",local:"finetuning",headingTag:"h2"}}),y=new ue({props:{$$slots:{default:[me]},$$scope:{ctx:lt}}}),I=new $({props:{code:"YWNjZWxlcmF0ZSUyMGxhdW5jaCUyMHRyYWluX3VuY29uZGl0aW9uYWwucHklMjAlNUMlMEElMjAlMjAtLWRhdGFzZXRfbmFtZSUzRCUyMmh1Z2dhbiUyRmZsb3dlcnMtMTAyLWNhdGVnb3JpZXMlMjIlMjAlNUMlMEElMjAlMjAtLXJlc29sdXRpb24lM0Q2NCUyMCU1QyUwQSUyMCUyMC0tb3V0cHV0X2RpciUzRCUyMmRkcG0tZW1hLWZsb3dlcnMtNjQlMjIlMjAlNUMlMEElMjAlMjAtLXRyYWluX2JhdGNoX3NpemUlM0QxNiUyMCU1QyUwQSUyMCUyMC0tbnVtX2Vwb2NocyUzRDEwMCUyMCU1QyUwQSUyMCUyMC0tZ3JhZGllbnRfYWNjdW11bGF0aW9uX3N0ZXBzJTNEMSUyMCU1QyUwQSUyMCUyMC0tbGVhcm5pbmdfcmF0ZSUzRDFlLTQlMjAlNUMlMEElMjAlMjAtLWxyX3dhcm11cF9zdGVwcyUzRDUwMCUyMCU1QyUwQSUyMCUyMC0tbWl4ZWRfcHJlY2lzaW9uJTNEbm8lMjAlNUMlMEElMjAlMjAtLXB1c2hfdG9faHVi",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`,wrap:!1}}),B=new $({props:{code:"YWNjZWxlcmF0ZSUyMGxhdW5jaCUyMHRyYWluX3VuY29uZGl0aW9uYWwucHklMjAlNUMlMEElMjAlMjAtLWRhdGFzZXRfbmFtZSUzRCUyMmh1Z2dhbiUyRnBva2Vtb24lMjIlMjAlNUMlMEElMjAlMjAtLXJlc29sdXRpb24lM0Q2NCUyMCU1QyUwQSUyMCUyMC0tb3V0cHV0X2RpciUzRCUyMmRkcG0tZW1hLXBva2Vtb24tNjQlMjIlMjAlNUMlMEElMjAlMjAtLXRyYWluX2JhdGNoX3NpemUlM0QxNiUyMCU1QyUwQSUyMCUyMC0tbnVtX2Vwb2NocyUzRDEwMCUyMCU1QyUwQSUyMCUyMC0tZ3JhZGllbnRfYWNjdW11bGF0aW9uX3N0ZXBzJTNEMSUyMCU1QyUwQSUyMCUyMC0tbGVhcm5pbmdfcmF0ZSUzRDFlLTQlMjAlNUMlMEElMjAlMjAtLWxyX3dhcm11cF9zdGVwcyUzRDUwMCUyMCU1QyUwQSUyMCUyMC0tbWl4ZWRfcHJlY2lzaW9uJTNEbm8lMjAlNUMlMEElMjAlMjAtLXB1c2hfdG9faHVi",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`,wrap:!1}}),q=new et({props:{title:"Training with multiple GPUs",local:"training-with-multiple-gpus",headingTag:"h3"}}),O=new $({props:{code:"YWNjZWxlcmF0ZSUyMGxhdW5jaCUyMC0tbWl4ZWRfcHJlY2lzaW9uJTNEJTIyZnAxNiUyMiUyMC0tbXVsdGlfZ3B1JTIwdHJhaW5fdW5jb25kaXRpb25hbC5weSUyMCU1QyUwQSUyMCUyMC0tZGF0YXNldF9uYW1lJTNEJTIyaHVnZ2FuJTJGcG9rZW1vbiUyMiUyMCU1QyUwQSUyMCUyMC0tcmVzb2x1dGlvbiUzRDY0JTIwLS1jZW50ZXJfY3JvcCUyMC0tcmFuZG9tX2ZsaXAlMjAlNUMlMEElMjAlMjAtLW91dHB1dF9kaXIlM0QlMjJkZHBtLWVtYS1wb2tlbW9uLTY0JTIyJTIwJTVDJTBBJTIwJTIwLS10cmFpbl9iYXRjaF9zaXplJTNEMTYlMjAlNUMlMEElMjAlMjAtLW51bV9lcG9jaHMlM0QxMDAlMjAlNUMlMEElMjAlMjAtLWdyYWRpZW50X2FjY3VtdWxhdGlvbl9zdGVwcyUzRDElMjAlNUMlMEElMjAlMjAtLXVzZV9lbWElMjAlNUMlMEElMjAlMjAtLWxlYXJuaW5nX3JhdGUlM0QxZS00JTIwJTVDJTBBJTIwJTIwLS1scl93YXJtdXBfc3RlcHMlM0Q1MDAlMjAlNUMlMEElMjAlMjAtLW1peGVkX3ByZWNpc2lvbiUzRCUyMmZwMTYlMjIlMjAlNUMlMEElMjAlMjAtLWxvZ2dlciUzRCUyMndhbmRiJTIyJTIwJTVDJTBBJTIwJTIwLS1wdXNoX3RvX2h1Yg==",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> \\
  --push_to_hub`,wrap:!1}}),{c(){r=s("meta"),_=i(),h=s("p"),K=i(),u(j.$$.fragment),nt=i(),C=s("p"),C.textContent=kt,it=i(),g=s("iframe"),at=i(),T=s("p"),T.innerHTML=Ht,st=i(),v=s("p"),v.textContent=Vt,ot=i(),u(x.$$.fragment),rt=i(),W=s("p"),W.innerHTML=Yt,pt=i(),u(Z.$$.fragment),ut=i(),A=s("p"),A.textContent=St,mt=i(),u(N.$$.fragment),ft=i(),X=s("p"),X.textContent=Qt,ct=i(),u(E.$$.fragment),Mt=i(),u(J.$$.fragment),dt=i(),L=s("p"),L.textContent=zt,ht=i(),u(R.$$.fragment),gt=i(),u(k.$$.fragment),$t=i(),G=s("p"),G.textContent=Ft,yt=i(),u(H.$$.fragment),Ut=i(),V=s("p"),V.innerHTML=It,wt=i(),u(Y.$$.fragment),bt=i(),u(S.$$.fragment),_t=i(),Q=s("p"),Q.innerHTML=Pt,jt=i(),z=s("p"),z.innerHTML=Bt,Ct=i(),u(y.$$.fragment),Tt=i(),F=s("p"),F.innerHTML=qt,vt=i(),u(I.$$.fragment),xt=i(),U=s("div"),U.innerHTML=Dt,Wt=i(),P=s("p"),P.innerHTML=Ot,Zt=i(),u(B.$$.fragment),At=i(),w=s("div"),w.innerHTML=Kt,Nt=i(),u(q.$$.fragment),Xt=i(),D=s("p"),D.innerHTML=te,Et=i(),u(O.$$.fragment),Jt=i(),tt=s("p"),this.h()},l(t){const e=re("svelte-u9bgzb",document.head);r=o(e,"META",{name:!0,content:!0}),e.forEach(l),_=a(t),h=o(t,"P",{}),Rt(h).forEach(l),K=a(t),m(j.$$.fragment,t),nt=a(t),C=o(t,"P",{"data-svelte-h":!0}),p(C)!=="svelte-198nvm5"&&(C.textContent=kt),it=a(t),g=o(t,"IFRAME",{src:!0,frameborder:!0,width:!0,height:!0}),Rt(g).forEach(l),at=a(t),T=o(t,"P",{"data-svelte-h":!0}),p(T)!=="svelte-l5nu9k"&&(T.innerHTML=Ht),st=a(t),v=o(t,"P",{"data-svelte-h":!0}),p(v)!=="svelte-12poyp8"&&(v.textContent=Vt),ot=a(t),m(x.$$.fragment,t),rt=a(t),W=o(t,"P",{"data-svelte-h":!0}),p(W)!=="svelte-69x92l"&&(W.innerHTML=Yt),pt=a(t),m(Z.$$.fragment,t),ut=a(t),A=o(t,"P",{"data-svelte-h":!0}),p(A)!=="svelte-di6juu"&&(A.textContent=St),mt=a(t),m(N.$$.fragment,t),ft=a(t),X=o(t,"P",{"data-svelte-h":!0}),p(X)!=="svelte-130n95n"&&(X.textContent=Qt),ct=a(t),m(E.$$.fragment,t),Mt=a(t),m(J.$$.fragment,t),dt=a(t),L=o(t,"P",{"data-svelte-h":!0}),p(L)!=="svelte-1j5w4r5"&&(L.textContent=zt),ht=a(t),m(R.$$.fragment,t),gt=a(t),m(k.$$.fragment,t),$t=a(t),G=o(t,"P",{"data-svelte-h":!0}),p(G)!=="svelte-1p6not5"&&(G.textContent=Ft),yt=a(t),m(H.$$.fragment,t),Ut=a(t),V=o(t,"P",{"data-svelte-h":!0}),p(V)!=="svelte-1tt64ot"&&(V.innerHTML=It),wt=a(t),m(Y.$$.fragment,t),bt=a(t),m(S.$$.fragment,t),_t=a(t),Q=o(t,"P",{"data-svelte-h":!0}),p(Q)!=="svelte-126yifr"&&(Q.innerHTML=Pt),jt=a(t),z=o(t,"P",{"data-svelte-h":!0}),p(z)!=="svelte-l3tgq2"&&(z.innerHTML=Bt),Ct=a(t),m(y.$$.fragment,t),Tt=a(t),F=o(t,"P",{"data-svelte-h":!0}),p(F)!=="svelte-uv9yzj"&&(F.innerHTML=qt),vt=a(t),m(I.$$.fragment,t),xt=a(t),U=o(t,"DIV",{class:!0,"data-svelte-h":!0}),p(U)!=="svelte-198gx0e"&&(U.innerHTML=Dt),Wt=a(t),P=o(t,"P",{"data-svelte-h":!0}),p(P)!=="svelte-14khsak"&&(P.innerHTML=Ot),Zt=a(t),m(B.$$.fragment,t),At=a(t),w=o(t,"DIV",{class:!0,"data-svelte-h":!0}),p(w)!=="svelte-kyasla"&&(w.innerHTML=Kt),Nt=a(t),m(q.$$.fragment,t),Xt=a(t),D=o(t,"P",{"data-svelte-h":!0}),p(D)!=="svelte-1tkye3l"&&(D.innerHTML=te),Et=a(t),m(O.$$.fragment,t),Jt=a(t),tt=o(t,"P",{}),Rt(tt).forEach(l),this.h()},h(){b(r,"name","hf:doc:metadata"),b(r,"content",ce),ne(g.src,Gt="https://stevhliu-ddpm-butterflies-128.hf.space")||b(g,"src",Gt),b(g,"frameborder","0"),b(g,"width","850"),b(g,"height","550"),b(U,"class","flex justify-center"),b(w,"class","flex justify-center")},m(t,e){pe(document.head,r),n(t,_,e),n(t,h,e),n(t,K,e),f(j,t,e),n(t,nt,e),n(t,C,e),n(t,it,e),n(t,g,e),n(t,at,e),n(t,T,e),n(t,st,e),n(t,v,e),n(t,ot,e),f(x,t,e),n(t,rt,e),n(t,W,e),n(t,pt,e),f(Z,t,e),n(t,ut,e),n(t,A,e),n(t,mt,e),f(N,t,e),n(t,ft,e),n(t,X,e),n(t,ct,e),f(E,t,e),n(t,Mt,e),f(J,t,e),n(t,dt,e),n(t,L,e),n(t,ht,e),f(R,t,e),n(t,gt,e),f(k,t,e),n(t,$t,e),n(t,G,e),n(t,yt,e),f(H,t,e),n(t,Ut,e),n(t,V,e),n(t,wt,e),f(Y,t,e),n(t,bt,e),f(S,t,e),n(t,_t,e),n(t,Q,e),n(t,jt,e),n(t,z,e),n(t,Ct,e),f(y,t,e),n(t,Tt,e),n(t,F,e),n(t,vt,e),f(I,t,e),n(t,xt,e),n(t,U,e),n(t,Wt,e),n(t,P,e),n(t,Zt,e),f(B,t,e),n(t,At,e),n(t,w,e),n(t,Nt,e),f(q,t,e),n(t,Xt,e),n(t,D,e),n(t,Et,e),f(O,t,e),n(t,Jt,e),n(t,tt,e),Lt=!0},p(t,[e]){const ee={};e&2&&(ee.$$scope={dirty:e,ctx:t}),y.$set(ee)},i(t){Lt||(c(j.$$.fragment,t),c(x.$$.fragment,t),c(Z.$$.fragment,t),c(N.$$.fragment,t),c(E.$$.fragment,t),c(J.$$.fragment,t),c(R.$$.fragment,t),c(k.$$.fragment,t),c(H.$$.fragment,t),c(Y.$$.fragment,t),c(S.$$.fragment,t),c(y.$$.fragment,t),c(I.$$.fragment,t),c(B.$$.fragment,t),c(q.$$.fragment,t),c(O.$$.fragment,t),Lt=!0)},o(t){M(j.$$.fragment,t),M(x.$$.fragment,t),M(Z.$$.fragment,t),M(N.$$.fragment,t),M(E.$$.fragment,t),M(J.$$.fragment,t),M(R.$$.fragment,t),M(k.$$.fragment,t),M(H.$$.fragment,t),M(Y.$$.fragment,t),M(S.$$.fragment,t),M(y.$$.fragment,t),M(I.$$.fragment,t),M(B.$$.fragment,t),M(q.$$.fragment,t),M(O.$$.fragment,t),Lt=!1},d(t){t&&(l(_),l(h),l(K),l(nt),l(C),l(it),l(g),l(at),l(T),l(st),l(v),l(ot),l(rt),l(W),l(pt),l(ut),l(A),l(mt),l(ft),l(X),l(ct),l(Mt),l(dt),l(L),l(ht),l(gt),l($t),l(G),l(yt),l(Ut),l(V),l(wt),l(bt),l(_t),l(Q),l(jt),l(z),l(Ct),l(Tt),l(F),l(vt),l(xt),l(U),l(Wt),l(P),l(Zt),l(At),l(w),l(Nt),l(Xt),l(D),l(Et),l(Jt),l(tt)),l(r),d(j,t),d(x,t),d(Z,t),d(N,t),d(E,t),d(J,t),d(R,t),d(k,t),d(H,t),d(Y,t),d(S,t),d(y,t),d(I,t),d(B,t),d(q,t),d(O,t)}}}const ce='{"title":"Unconditional image generation","local":"unconditional-image-generation","sections":[{"title":"Upload model to Hub","local":"upload-model-to-hub","sections":[],"depth":2},{"title":"Save and load checkpoints","local":"save-and-load-checkpoints","sections":[],"depth":2},{"title":"Finetuning","local":"finetuning","sections":[{"title":"Training with multiple GPUs","local":"training-with-multiple-gpus","sections":[],"depth":3}],"depth":2}],"depth":1}';function Me(lt){return ie(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Ue extends se{constructor(r){super(),oe(this,r,Me,fe,le,{})}}export{Ue as component};
