import{s as Pt,o as Ot,n as Bt}from"../chunks/scheduler.23542ac5.js";import{S as Kt,i as te,e as T,s as r,c as M,h as ee,a as b,d as s,b as m,f as qt,g as u,j as y,k as Vt,l as le,m as n,n as d,t as h,o as J,p as w}from"../chunks/index.9b1f405b.js";import{C as ae,H as rt,E as se}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.f1623902.js";import{C as B}from"../chunks/CodeBlock.e697091a.js";import{F as Dt,M as Ft}from"../chunks/Markdown.c81675d8.js";function ne(C){let l,f='다음과 같이 <a href="https://huggingface.co/datasets/lambdalabs/naruto-blip-captions" rel="nofollow">Naruto BLIP 캡션</a> 데이터셋에서 파인튜닝 실행을 위해 <a href="https://github.com/huggingface/diffusers/blob/main/examples/text_to_image/train_text_to_image.py" rel="nofollow">PyTorch 학습 스크립트</a>를 실행합니다:',e,i,c,x,j='자체 데이터셋으로 파인튜닝하려면 🤗 <a href="https://huggingface.co/docs/datasets/index" rel="nofollow">Datasets</a>에서 요구하는 형식에 따라 데이터셋을 준비하세요. <a href="https://huggingface.co/docs/datasets/image_dataset#upload-dataset-to-the-hub" rel="nofollow">데이터셋을 허브에 업로드</a>하거나 [파일들이 있는 로컬 폴더를 준비](https ://huggingface.co/docs/datasets/image_dataset#imagefolder)할 수 있습니다.',R,U,G="사용자 커스텀 loading logic을 사용하려면 스크립트를 수정하십시오. 도움이 되도록 코드의 적절한 위치에 포인터를 남겼습니다. 🤗 아래 예제 스크립트는 <code>TRAIN_DIR</code>의 로컬 데이터셋으로를 파인튜닝하는 방법과 <code>OUTPUT_DIR</code>에서 모델을 저장할 위치를 보여줍니다:",Z,$,W;return i=new B({props:{code:"ZXhwb3J0JTIwTU9ERUxfTkFNRSUzRCUyMkNvbXBWaXMlMkZzdGFibGUtZGlmZnVzaW9uLXYxLTQlMjIlMEFleHBvcnQlMjBkYXRhc2V0X25hbWUlM0QlMjJsYW1iZGFsYWJzJTJGbmFydXRvLWJsaXAtY2FwdGlvbnMlMjIlMEElMEFhY2NlbGVyYXRlJTIwbGF1bmNoJTIwdHJhaW5fdGV4dF90b19pbWFnZS5weSUyMCU1QyUwQSUyMCUyMC0tcHJldHJhaW5lZF9tb2RlbF9uYW1lX29yX3BhdGglM0QlMjRNT0RFTF9OQU1FJTIwJTVDJTBBJTIwJTIwLS1kYXRhc2V0X25hbWUlM0QlMjRkYXRhc2V0X25hbWUlMjAlNUMlMEElMjAlMjAtLXVzZV9lbWElMjAlNUMlMEElMjAlMjAtLXJlc29sdXRpb24lM0Q1MTIlMjAtLWNlbnRlcl9jcm9wJTIwLS1yYW5kb21fZmxpcCUyMCU1QyUwQSUyMCUyMC0tdHJhaW5fYmF0Y2hfc2l6ZSUzRDElMjAlNUMlMEElMjAlMjAtLWdyYWRpZW50X2FjY3VtdWxhdGlvbl9zdGVwcyUzRDQlMjAlNUMlMEElMjAlMjAtLWdyYWRpZW50X2NoZWNrcG9pbnRpbmclMjAlNUMlMEElMjAlMjAtLW1peGVkX3ByZWNpc2lvbiUzRCUyMmZwMTYlMjIlMjAlNUMlMEElMjAlMjAtLW1heF90cmFpbl9zdGVwcyUzRDE1MDAwJTIwJTVDJTBBJTIwJTIwLS1sZWFybmluZ19yYXRlJTNEMWUtMDUlMjAlNUMlMEElMjAlMjAtLW1heF9ncmFkX25vcm0lM0QxJTIwJTVDJTBBJTIwJTIwLS1scl9zY2hlZHVsZXIlM0QlMjJjb25zdGFudCUyMiUyMC0tbHJfd2FybXVwX3N0ZXBzJTNEMCUyMCU1QyUwQSUyMCUyMC0tb3V0cHV0X2RpciUzRCUyMnNkLW5hcnV0by1tb2RlbCUyMg==",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/naruto-blip-captions&quot;</span>

accelerate launch 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 \\
  --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-string">&quot;sd-naruto-model&quot;</span>`,wrap:!1}}),$=new B({props:{code:"ZXhwb3J0JTIwTU9ERUxfTkFNRSUzRCUyMkNvbXBWaXMlMkZzdGFibGUtZGlmZnVzaW9uLXYxLTQlMjIlMEFleHBvcnQlMjBUUkFJTl9ESVIlM0QlMjJwYXRoX3RvX3lvdXJfZGF0YXNldCUyMiUwQWV4cG9ydCUyME9VVFBVVF9ESVIlM0QlMjJwYXRoX3RvX3NhdmVfbW9kZWwlMjIlMEElMEFhY2NlbGVyYXRlJTIwbGF1bmNoJTIwdHJhaW5fdGV4dF90b19pbWFnZS5weSUyMCU1QyUwQSUyMCUyMC0tcHJldHJhaW5lZF9tb2RlbF9uYW1lX29yX3BhdGglM0QlMjRNT0RFTF9OQU1FJTIwJTVDJTBBJTIwJTIwLS10cmFpbl9kYXRhX2RpciUzRCUyNFRSQUlOX0RJUiUyMCU1QyUwQSUyMCUyMC0tdXNlX2VtYSUyMCU1QyUwQSUyMCUyMC0tcmVzb2x1dGlvbiUzRDUxMiUyMC0tY2VudGVyX2Nyb3AlMjAtLXJhbmRvbV9mbGlwJTIwJTVDJTBBJTIwJTIwLS10cmFpbl9iYXRjaF9zaXplJTNEMSUyMCU1QyUwQSUyMCUyMC0tZ3JhZGllbnRfYWNjdW11bGF0aW9uX3N0ZXBzJTNENCUyMCU1QyUwQSUyMCUyMC0tZ3JhZGllbnRfY2hlY2twb2ludGluZyUyMCU1QyUwQSUyMCUyMC0tbWl4ZWRfcHJlY2lzaW9uJTNEJTIyZnAxNiUyMiUyMCU1QyUwQSUyMCUyMC0tbWF4X3RyYWluX3N0ZXBzJTNEMTUwMDAlMjAlNUMlMEElMjAlMjAtLWxlYXJuaW5nX3JhdGUlM0QxZS0wNSUyMCU1QyUwQSUyMCUyMC0tbWF4X2dyYWRfbm9ybSUzRDElMjAlNUMlMEElMjAlMjAtLWxyX3NjaGVkdWxlciUzRCUyMmNvbnN0YW50JTIyJTIwLS1scl93YXJtdXBfc3RlcHMlM0QwJTIwJTVDJTBBJTIwJTIwLS1vdXRwdXRfZGlyJTNEJTI0JTdCT1VUUFVUX0RJUiU3RA==",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>`,wrap:!1}}),{c(){l=T("p"),l.innerHTML=f,e=r(),M(i.$$.fragment),c=r(),x=T("p"),x.innerHTML=j,R=r(),U=T("p"),U.innerHTML=G,Z=r(),M($.$$.fragment)},l(o){l=b(o,"P",{"data-svelte-h":!0}),y(l)!=="svelte-jxsit4"&&(l.innerHTML=f),e=m(o),u(i.$$.fragment,o),c=m(o),x=b(o,"P",{"data-svelte-h":!0}),y(x)!=="svelte-19wquqk"&&(x.innerHTML=j),R=m(o),U=b(o,"P",{"data-svelte-h":!0}),y(U)!=="svelte-i9hrjr"&&(U.innerHTML=G),Z=m(o),u($.$$.fragment,o)},m(o,g){n(o,l,g),n(o,e,g),d(i,o,g),n(o,c,g),n(o,x,g),n(o,R,g),n(o,U,g),n(o,Z,g),d($,o,g),W=!0},p:Bt,i(o){W||(h(i.$$.fragment,o),h($.$$.fragment,o),W=!0)},o(o){J(i.$$.fragment,o),J($.$$.fragment,o),W=!1},d(o){o&&(s(l),s(e),s(c),s(x),s(R),s(U),s(Z)),w(i,o),w($,o)}}}function pe(C){let l,f;return l=new Ft({props:{$$slots:{default:[ne]},$$scope:{ctx:C}}}),{c(){M(l.$$.fragment)},l(e){u(l.$$.fragment,e)},m(e,i){d(l,e,i),f=!0},p(e,i){const c={};i&2&&(c.$$scope={dirty:i,ctx:e}),l.$set(c)},i(e){f||(h(l.$$.fragment,e),f=!0)},o(e){J(l.$$.fragment,e),f=!1},d(e){w(l,e)}}}function ie(C){let l,f='<a href="https://github.com/duongna21" rel="nofollow">@duongna211</a>의 기여로, Flax를 사용해 TPU 및 GPU에서 Stable Diffusion 모델을 더 빠르게 학습할 수 있습니다. 이는 TPU 하드웨어에서 매우 효율적이지만 GPU에서도 훌륭하게 작동합니다. Flax 학습 스크립트는 gradient checkpointing나 gradient accumulation과 같은 기능을 아직 지원하지 않으므로 메모리가 30GB 이상인 GPU 또는 TPU v3가 필요합니다.',e,i,c="스크립트를 실행하기 전에 요구 사항이 설치되어 있는지 확인하십시오:",x,j,R,U,G='그러면 다음과 같이 <a href="https://github.com/huggingface/diffusers/blob/main/examples/text_to_image/train_text_to_image_flax.py" rel="nofollow">Flax 학습 스크립트</a>를 실행할 수 있습니다.',Z,$,W,o,g='자체 데이터셋으로 파인튜닝하려면 🤗 <a href="https://huggingface.co/docs/datasets/index" rel="nofollow">Datasets</a>에서 요구하는 형식에 따라 데이터셋을 준비하세요. <a href="https://huggingface.co/docs/datasets/image_dataset#upload-dataset-to-the-hub" rel="nofollow">데이터셋을 허브에 업로드</a>하거나 [파일들이 있는 로컬 폴더를 준비](https ://huggingface.co/docs/datasets/image_dataset#imagefolder)할 수 있습니다.',E,I,F="사용자 커스텀 loading logic을 사용하려면 스크립트를 수정하십시오. 도움이 되도록 코드의 적절한 위치에 포인터를 남겼습니다. 🤗 아래 예제 스크립트는 <code>TRAIN_DIR</code>의 로컬 데이터셋으로를 파인튜닝하는 방법을 보여줍니다:",V,X,k;return j=new B({props:{code:"cGlwJTIwaW5zdGFsbCUyMC1VJTIwLXIlMjByZXF1aXJlbWVudHNfZmxheC50eHQ=",highlighted:"pip install -U -r requirements_flax.txt",wrap:!1}}),$=new B({props:{code:"ZXhwb3J0JTIwTU9ERUxfTkFNRSUzRCUyMnN0YWJsZS1kaWZmdXNpb24tdjEtNSUyRnN0YWJsZS1kaWZmdXNpb24tdjEtNSUyMiUwQWV4cG9ydCUyMGRhdGFzZXRfbmFtZSUzRCUyMmxhbWJkYWxhYnMlMkZuYXJ1dG8tYmxpcC1jYXB0aW9ucyUyMiUwQSUwQXB5dGhvbiUyMHRyYWluX3RleHRfdG9faW1hZ2VfZmxheC5weSUyMCU1QyUwQSUyMCUyMC0tcHJldHJhaW5lZF9tb2RlbF9uYW1lX29yX3BhdGglM0QlMjRNT0RFTF9OQU1FJTIwJTVDJTBBJTIwJTIwLS1kYXRhc2V0X25hbWUlM0QlMjRkYXRhc2V0X25hbWUlMjAlNUMlMEElMjAlMjAtLXJlc29sdXRpb24lM0Q1MTIlMjAtLWNlbnRlcl9jcm9wJTIwLS1yYW5kb21fZmxpcCUyMCU1QyUwQSUyMCUyMC0tdHJhaW5fYmF0Y2hfc2l6ZSUzRDElMjAlNUMlMEElMjAlMjAtLW1heF90cmFpbl9zdGVwcyUzRDE1MDAwJTIwJTVDJTBBJTIwJTIwLS1sZWFybmluZ19yYXRlJTNEMWUtMDUlMjAlNUMlMEElMjAlMjAtLW1heF9ncmFkX25vcm0lM0QxJTIwJTVDJTBBJTIwJTIwLS1vdXRwdXRfZGlyJTNEJTIyc2QtbmFydXRvLW1vZGVsJTIy",highlighted:`<span class="hljs-built_in">export</span> MODEL_NAME=<span class="hljs-string">&quot;stable-diffusion-v1-5/stable-diffusion-v1-5&quot;</span>
<span class="hljs-built_in">export</span> dataset_name=<span class="hljs-string">&quot;lambdalabs/naruto-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-naruto-model&quot;</span>`,wrap:!1}}),X=new B({props:{code:"ZXhwb3J0JTIwTU9ERUxfTkFNRSUzRCUyMmR1b25nbmElMkZzdGFibGUtZGlmZnVzaW9uLXYxLTQtZmxheCUyMiUwQWV4cG9ydCUyMFRSQUlOX0RJUiUzRCUyMnBhdGhfdG9feW91cl9kYXRhc2V0JTIyJTBBJTBBcHl0aG9uJTIwdHJhaW5fdGV4dF90b19pbWFnZV9mbGF4LnB5JTIwJTVDJTBBJTIwJTIwLS1wcmV0cmFpbmVkX21vZGVsX25hbWVfb3JfcGF0aCUzRCUyNE1PREVMX05BTUUlMjAlNUMlMEElMjAlMjAtLXRyYWluX2RhdGFfZGlyJTNEJTI0VFJBSU5fRElSJTIwJTVDJTBBJTIwJTIwLS1yZXNvbHV0aW9uJTNENTEyJTIwLS1jZW50ZXJfY3JvcCUyMC0tcmFuZG9tX2ZsaXAlMjAlNUMlMEElMjAlMjAtLXRyYWluX2JhdGNoX3NpemUlM0QxJTIwJTVDJTBBJTIwJTIwLS1taXhlZF9wcmVjaXNpb24lM0QlMjJmcDE2JTIyJTIwJTVDJTBBJTIwJTIwLS1tYXhfdHJhaW5fc3RlcHMlM0QxNTAwMCUyMCU1QyUwQSUyMCUyMC0tbGVhcm5pbmdfcmF0ZSUzRDFlLTA1JTIwJTVDJTBBJTIwJTIwLS1tYXhfZ3JhZF9ub3JtJTNEMSUyMCU1QyUwQSUyMCUyMC0tb3V0cHV0X2RpciUzRCUyMnNkLW5hcnV0by1tb2RlbCUyMg==",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-naruto-model&quot;</span>`,wrap:!1}}),{c(){l=T("p"),l.innerHTML=f,e=r(),i=T("p"),i.textContent=c,x=r(),M(j.$$.fragment),R=r(),U=T("p"),U.innerHTML=G,Z=r(),M($.$$.fragment),W=r(),o=T("p"),o.innerHTML=g,E=r(),I=T("p"),I.innerHTML=F,V=r(),M(X.$$.fragment)},l(p){l=b(p,"P",{"data-svelte-h":!0}),y(l)!=="svelte-c7loxj"&&(l.innerHTML=f),e=m(p),i=b(p,"P",{"data-svelte-h":!0}),y(i)!=="svelte-1w9ydbl"&&(i.textContent=c),x=m(p),u(j.$$.fragment,p),R=m(p),U=b(p,"P",{"data-svelte-h":!0}),y(U)!=="svelte-16f5q4a"&&(U.innerHTML=G),Z=m(p),u($.$$.fragment,p),W=m(p),o=b(p,"P",{"data-svelte-h":!0}),y(o)!=="svelte-19wquqk"&&(o.innerHTML=g),E=m(p),I=b(p,"P",{"data-svelte-h":!0}),y(I)!=="svelte-3igbkc"&&(I.innerHTML=F),V=m(p),u(X.$$.fragment,p)},m(p,_){n(p,l,_),n(p,e,_),n(p,i,_),n(p,x,_),d(j,p,_),n(p,R,_),n(p,U,_),n(p,Z,_),d($,p,_),n(p,W,_),n(p,o,_),n(p,E,_),n(p,I,_),n(p,V,_),d(X,p,_),k=!0},p:Bt,i(p){k||(h(j.$$.fragment,p),h($.$$.fragment,p),h(X.$$.fragment,p),k=!0)},o(p){J(j.$$.fragment,p),J($.$$.fragment,p),J(X.$$.fragment,p),k=!1},d(p){p&&(s(l),s(e),s(i),s(x),s(R),s(U),s(Z),s(W),s(o),s(E),s(I),s(V)),w(j,p),w($,p),w(X,p)}}}function re(C){let l,f;return l=new Ft({props:{$$slots:{default:[ie]},$$scope:{ctx:C}}}),{c(){M(l.$$.fragment)},l(e){u(l.$$.fragment,e)},m(e,i){d(l,e,i),f=!0},p(e,i){const c={};i&2&&(c.$$scope={dirty:i,ctx:e}),l.$set(c)},i(e){f||(h(l.$$.fragment,e),f=!0)},o(e){J(l.$$.fragment,e),f=!1},d(e){w(l,e)}}}function me(C){let l,f;return l=new B({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMFN0YWJsZURpZmZ1c2lvblBpcGVsaW5lJTBBJTBBbW9kZWxfcGF0aCUyMCUzRCUyMCUyMnBhdGhfdG9fc2F2ZWRfbW9kZWwlMjIlMEFwaXBlJTIwJTNEJTIwU3RhYmxlRGlmZnVzaW9uUGlwZWxpbmUuZnJvbV9wcmV0cmFpbmVkKG1vZGVsX3BhdGglMkMlMjB0b3JjaF9kdHlwZSUzRHRvcmNoLmZsb2F0MTYpJTBBcGlwZS50byglMjJjdWRhJTIyKSUwQSUwQWltYWdlJTIwJTNEJTIwcGlwZShwcm9tcHQlM0QlMjJ5b2RhJTIyKS5pbWFnZXMlNUIwJTVEJTBBaW1hZ2Uuc2F2ZSglMjJ5b2RhLW5hcnV0by5wbmclMjIp",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)
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-naruto.png&quot;</span>)`,wrap:!1}}),{c(){M(l.$$.fragment)},l(e){u(l.$$.fragment,e)},m(e,i){d(l,e,i),f=!0},p:Bt,i(e){f||(h(l.$$.fragment,e),f=!0)},o(e){J(l.$$.fragment,e),f=!1},d(e){w(l,e)}}}function oe(C){let l,f;return l=new Ft({props:{$$slots:{default:[me]},$$scope:{ctx:C}}}),{c(){M(l.$$.fragment)},l(e){u(l.$$.fragment,e)},m(e,i){d(l,e,i),f=!0},p(e,i){const c={};i&2&&(c.$$scope={dirty:i,ctx:e}),l.$set(c)},i(e){f||(h(l.$$.fragment,e),f=!0)},o(e){J(l.$$.fragment,e),f=!1},d(e){w(l,e)}}}function fe(C){let l,f;return l=new B({props:{code:"aW1wb3J0JTIwamF4JTBBaW1wb3J0JTIwbnVtcHklMjBhcyUyMG5wJTBBZnJvbSUyMGZsYXguamF4X3V0aWxzJTIwaW1wb3J0JTIwcmVwbGljYXRlJTBBZnJvbSUyMGZsYXgudHJhaW5pbmcuY29tbW9uX3V0aWxzJTIwaW1wb3J0JTIwc2hhcmQlMEFmcm9tJTIwZGlmZnVzZXJzJTIwaW1wb3J0JTIwRmxheFN0YWJsZURpZmZ1c2lvblBpcGVsaW5lJTBBJTBBbW9kZWxfcGF0aCUyMCUzRCUyMCUyMnBhdGhfdG9fc2F2ZWRfbW9kZWwlMjIlMEFwaXBlJTJDJTIwcGFyYW1zJTIwJTNEJTIwRmxheFN0YWJsZURpZmZ1c2lvblBpcGVsaW5lLmZyb21fcHJldHJhaW5lZChtb2RlbF9wYXRoJTJDJTIwZHR5cGUlM0RqYXgubnVtcHkuYmZsb2F0MTYpJTBBJTBBcHJvbXB0JTIwJTNEJTIwJTIyeW9kYSUyMG5hcnV0byUyMiUwQXBybmdfc2VlZCUyMCUzRCUyMGpheC5yYW5kb20uUFJOR0tleSgwKSUwQW51bV9pbmZlcmVuY2Vfc3RlcHMlMjAlM0QlMjA1MCUwQSUwQW51bV9zYW1wbGVzJTIwJTNEJTIwamF4LmRldmljZV9jb3VudCgpJTBBcHJvbXB0JTIwJTNEJTIwbnVtX3NhbXBsZXMlMjAqJTIwJTVCcHJvbXB0JTVEJTBBcHJvbXB0X2lkcyUyMCUzRCUyMHBpcGVsaW5lLnByZXBhcmVfaW5wdXRzKHByb21wdCklMEElMEElMjMlMjBzaGFyZCUyMGlucHV0cyUyMGFuZCUyMHJuZyUwQXBhcmFtcyUyMCUzRCUyMHJlcGxpY2F0ZShwYXJhbXMpJTBBcHJuZ19zZWVkJTIwJTNEJTIwamF4LnJhbmRvbS5zcGxpdChwcm5nX3NlZWQlMkMlMjBqYXguZGV2aWNlX2NvdW50KCkpJTBBcHJvbXB0X2lkcyUyMCUzRCUyMHNoYXJkKHByb21wdF9pZHMpJTBBJTBBaW1hZ2VzJTIwJTNEJTIwcGlwZWxpbmUocHJvbXB0X2lkcyUyQyUyMHBhcmFtcyUyQyUyMHBybmdfc2VlZCUyQyUyMG51bV9pbmZlcmVuY2Vfc3RlcHMlMkMlMjBqaXQlM0RUcnVlKS5pbWFnZXMlMEFpbWFnZXMlMjAlM0QlMjBwaXBlbGluZS5udW1weV90b19waWwobnAuYXNhcnJheShpbWFnZXMucmVzaGFwZSgobnVtX3NhbXBsZXMlMkMpJTIwJTJCJTIwaW1hZ2VzLnNoYXBlJTVCLTMlM0ElNUQpKSklMEFpbWFnZS5zYXZlKCUyMnlvZGEtbmFydXRvLnBuZyUyMik=",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 naruto&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-naruto.png&quot;</span>)`,wrap:!1}}),{c(){M(l.$$.fragment)},l(e){u(l.$$.fragment,e)},m(e,i){d(l,e,i),f=!0},p:Bt,i(e){f||(h(l.$$.fragment,e),f=!0)},o(e){J(l.$$.fragment,e),f=!1},d(e){w(l,e)}}}function ce(C){let l,f;return l=new Ft({props:{$$slots:{default:[fe]},$$scope:{ctx:C}}}),{c(){M(l.$$.fragment)},l(e){u(l.$$.fragment,e)},m(e,i){d(l,e,i),f=!0},p(e,i){const c={};i&2&&(c.$$scope={dirty:i,ctx:e}),l.$set(c)},i(e){f||(h(l.$$.fragment,e),f=!0)},o(e){J(l.$$.fragment,e),f=!1},d(e){w(l,e)}}}function Me(C){let l,f,e,i,c,x,j,R,U,G="<p>text-to-image 파인튜닝 스크립트는 experimental 상태입니다. 과적합하기 쉽고 치명적인 망각과 같은 문제에 부딪히기 쉽습니다. 자체 데이터셋에서 최상의 결과를 얻으려면 다양한 하이퍼파라미터를 탐색하는 것이 좋습니다.</p>",Z,$,W='Stable Diffusion과 같은 text-to-image 모델은 텍스트 프롬프트에서 이미지를 생성합니다. 이 가이드는 PyTorch 및 Flax를 사용하여 자체 데이터셋에서 <a href="https://huggingface.co/CompVis/stable-diffusion-v1-4" rel="nofollow"><code>CompVis/stable-diffusion-v1-4</code></a> 모델로 파인튜닝하는 방법을 보여줍니다. 이 가이드에 사용된 text-to-image 파인튜닝을 위한 모든 학습 스크립트에 관심이 있는 경우 이 <a href="https://github.com/huggingface/diffusers/tree/main/examples/text_to_image" rel="nofollow">리포지토리</a>에서 자세히 찾을 수 있습니다.',o,g,E="스크립트를 실행하기 전에, 라이브러리의 학습 dependency들을 설치해야 합니다:",I,F,V,X,k='그리고 <a href="https://github.com/huggingface/accelerate/" rel="nofollow">🤗Accelerate</a> 환경을 초기화합니다:',p,_,ot,L,Gt="리포지토리를 이미 복제한 경우, 이 단계를 수행할 필요가 없습니다. 대신, 로컬 체크아웃 경로를 학습 스크립트에 명시할 수 있으며 거기에서 로드됩니다.",ft,S,ct,Y,Nt='<code>gradient_checkpointing</code> 및 <code>mixed_precision</code>을 사용하면 단일 24GB GPU에서 모델을 파인튜닝할 수 있습니다. 더 높은 <code>batch_size</code>와 더 빠른 훈련을 위해서는 GPU 메모리가 30GB 이상인 GPU를 사용하는 것이 좋습니다. TPU 또는 GPU에서 파인튜닝을 위해 JAX나 Flax를 사용할 수도 있습니다. 자세한 내용은 <a href="#flax-jax-finetuning">아래</a>를 참조하세요.',Mt,H,vt='xFormers로 memory efficient attention을 활성화하여 메모리 사용량 훨씬 더 줄일 수 있습니다. <a href="./optimization/xformers">xFormers가 설치</a>되어 있는지 확인하고 <code>--enable_xformers_memory_efficient_attention</code>를 학습 스크립트에 명시합니다.',ut,Q,Et="xFormers는 Flax에 사용할 수 없습니다.",dt,A,ht,z,kt="학습 스크립트에 다음 인수를 추가하여 모델을 허브에 저장합니다:",Jt,q,wt,D,Tt,P,Lt="학습 중 발생할 수 있는 일에 대비하여 정기적으로 체크포인트를 저장해 두는 것이 좋습니다. 체크포인트를 저장하려면 학습 스크립트에 다음 인수를 명시합니다.",bt,O,Ut,K,St="500스텝마다 전체 학습 state가 ‘output_dir’의 하위 폴더에 저장됩니다. 체크포인트는 ‘checkpoint-‘에 지금까지 학습된 step 수입니다. 예를 들어 ‘checkpoint-1500’은 1500 학습 step 후에 저장된 체크포인트입니다.",$t,tt,Yt="학습을 재개하기 위해 체크포인트를 불러오려면 ‘—resume_from_checkpoint’ 인수를 학습 스크립트에 명시하고 재개할 체크포인트를 지정하십시오. 예를 들어 다음 인수는 1500개의 학습 step 후에 저장된 체크포인트에서부터 훈련을 재개합니다.",_t,et,yt,lt,gt,N,jt,at,xt,st,Ht='Text-to-image 모델 파인튜닝을 위해, 대규모 모델 학습을 가속화하기 위한 파인튜닝 기술인 LoRA(Low-Rank Adaptation of Large Language Models)를 사용할 수 있습니다. 자세한 내용은 <a href="lora#text-to-image">LoRA 학습</a> 가이드를 참조하세요.',Ct,nt,Xt,pt,Qt="허브의 모델 경로 또는 모델 이름을 <code>StableDiffusionPipeline</code>에 전달하여 추론을 위해 파인 튜닝된 모델을 불러올 수 있습니다:",Rt,v,Zt,it,Wt,mt,It;return c=new ae({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),j=new rt({props:{title:"Text-to-image",local:"text-to-image",headingTag:"h1"}}),F=new B({props:{code:"cGlwJTIwaW5zdGFsbCUyMGdpdCUyQmh0dHBzJTNBJTJGJTJGZ2l0aHViLmNvbSUyRmh1Z2dpbmdmYWNlJTJGZGlmZnVzZXJzLmdpdCUwQXBpcCUyMGluc3RhbGwlMjAtVSUyMC1yJTIwcmVxdWlyZW1lbnRzLnR4dA==",highlighted:`pip install git+https://github.com/huggingface/diffusers.git
pip install -U -r requirements.txt`,wrap:!1}}),_=new B({props:{code:"YWNjZWxlcmF0ZSUyMGNvbmZpZw==",highlighted:"accelerate config",wrap:!1}}),S=new rt({props:{title:"하드웨어 요구 사항",local:"하드웨어-요구-사항",headingTag:"h3"}}),A=new rt({props:{title:"Hub에 모델 업로드하기",local:"hub에-모델-업로드하기",headingTag:"h2"}}),q=new B({props:{code:"JTIwJTIwLS1wdXNoX3RvX2h1Yg==",highlighted:"  --push_to_hub",wrap:!1}}),D=new rt({props:{title:"체크포인트 저장 및 불러오기",local:"체크포인트-저장-및-불러오기",headingTag:"h2"}}),O=new B({props:{code:"JTIwJTIwLS1jaGVja3BvaW50aW5nX3N0ZXBzJTNENTAw",highlighted:"  --checkpointing_steps=500",wrap:!1}}),et=new B({props:{code:"JTIwJTIwLS1yZXN1bWVfZnJvbV9jaGVja3BvaW50JTNEJTIyY2hlY2twb2ludC0xNTAwJTIy",highlighted:'  --resume_from_checkpoint=<span class="hljs-string">&quot;checkpoint-1500&quot;</span>',wrap:!1}}),lt=new rt({props:{title:"파인튜닝",local:"파인튜닝",headingTag:"h2"}}),N=new Dt({props:{pytorch:!0,tensorflow:!1,jax:!0,$$slots:{jax:[re],pytorch:[pe]},$$scope:{ctx:C}}}),at=new rt({props:{title:"LoRA",local:"lora",headingTag:"h2"}}),nt=new rt({props:{title:"추론",local:"추론",headingTag:"h2"}}),v=new Dt({props:{pytorch:!0,tensorflow:!1,jax:!0,$$slots:{jax:[ce],pytorch:[oe]},$$scope:{ctx:C}}}),it=new se({props:{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/ko/training/text2image.md"}}),{c(){l=T("meta"),f=r(),e=T("p"),i=r(),M(c.$$.fragment),x=r(),M(j.$$.fragment),R=r(),U=T("blockquote"),U.innerHTML=G,Z=r(),$=T("p"),$.innerHTML=W,o=r(),g=T("p"),g.textContent=E,I=r(),M(F.$$.fragment),V=r(),X=T("p"),X.innerHTML=k,p=r(),M(_.$$.fragment),ot=r(),L=T("p"),L.textContent=Gt,ft=r(),M(S.$$.fragment),ct=r(),Y=T("p"),Y.innerHTML=Nt,Mt=r(),H=T("p"),H.innerHTML=vt,ut=r(),Q=T("p"),Q.textContent=Et,dt=r(),M(A.$$.fragment),ht=r(),z=T("p"),z.textContent=kt,Jt=r(),M(q.$$.fragment),wt=r(),M(D.$$.fragment),Tt=r(),P=T("p"),P.textContent=Lt,bt=r(),M(O.$$.fragment),Ut=r(),K=T("p"),K.textContent=St,$t=r(),tt=T("p"),tt.textContent=Yt,_t=r(),M(et.$$.fragment),yt=r(),M(lt.$$.fragment),gt=r(),M(N.$$.fragment),jt=r(),M(at.$$.fragment),xt=r(),st=T("p"),st.innerHTML=Ht,Ct=r(),M(nt.$$.fragment),Xt=r(),pt=T("p"),pt.innerHTML=Qt,Rt=r(),M(v.$$.fragment),Zt=r(),M(it.$$.fragment),Wt=r(),mt=T("p"),this.h()},l(t){const a=ee("svelte-u9bgzb",document.head);l=b(a,"META",{name:!0,content:!0}),a.forEach(s),f=m(t),e=b(t,"P",{}),qt(e).forEach(s),i=m(t),u(c.$$.fragment,t),x=m(t),u(j.$$.fragment,t),R=m(t),U=b(t,"BLOCKQUOTE",{class:!0,"data-svelte-h":!0}),y(U)!=="svelte-4s267r"&&(U.innerHTML=G),Z=m(t),$=b(t,"P",{"data-svelte-h":!0}),y($)!=="svelte-6focsf"&&($.innerHTML=W),o=m(t),g=b(t,"P",{"data-svelte-h":!0}),y(g)!=="svelte-d6uma"&&(g.textContent=E),I=m(t),u(F.$$.fragment,t),V=m(t),X=b(t,"P",{"data-svelte-h":!0}),y(X)!=="svelte-1q84qbk"&&(X.innerHTML=k),p=m(t),u(_.$$.fragment,t),ot=m(t),L=b(t,"P",{"data-svelte-h":!0}),y(L)!=="svelte-9go34t"&&(L.textContent=Gt),ft=m(t),u(S.$$.fragment,t),ct=m(t),Y=b(t,"P",{"data-svelte-h":!0}),y(Y)!=="svelte-1x90o2u"&&(Y.innerHTML=Nt),Mt=m(t),H=b(t,"P",{"data-svelte-h":!0}),y(H)!=="svelte-yc0tb6"&&(H.innerHTML=vt),ut=m(t),Q=b(t,"P",{"data-svelte-h":!0}),y(Q)!=="svelte-1ksou9j"&&(Q.textContent=Et),dt=m(t),u(A.$$.fragment,t),ht=m(t),z=b(t,"P",{"data-svelte-h":!0}),y(z)!=="svelte-1cshqoz"&&(z.textContent=kt),Jt=m(t),u(q.$$.fragment,t),wt=m(t),u(D.$$.fragment,t),Tt=m(t),P=b(t,"P",{"data-svelte-h":!0}),y(P)!=="svelte-dt8b2s"&&(P.textContent=Lt),bt=m(t),u(O.$$.fragment,t),Ut=m(t),K=b(t,"P",{"data-svelte-h":!0}),y(K)!=="svelte-1rb33uz"&&(K.textContent=St),$t=m(t),tt=b(t,"P",{"data-svelte-h":!0}),y(tt)!=="svelte-19yki7i"&&(tt.textContent=Yt),_t=m(t),u(et.$$.fragment,t),yt=m(t),u(lt.$$.fragment,t),gt=m(t),u(N.$$.fragment,t),jt=m(t),u(at.$$.fragment,t),xt=m(t),st=b(t,"P",{"data-svelte-h":!0}),y(st)!=="svelte-1dpocf9"&&(st.innerHTML=Ht),Ct=m(t),u(nt.$$.fragment,t),Xt=m(t),pt=b(t,"P",{"data-svelte-h":!0}),y(pt)!=="svelte-1an9epu"&&(pt.innerHTML=Qt),Rt=m(t),u(v.$$.fragment,t),Zt=m(t),u(it.$$.fragment,t),Wt=m(t),mt=b(t,"P",{}),qt(mt).forEach(s),this.h()},h(){Vt(l,"name","hf:doc:metadata"),Vt(l,"content",ue),Vt(U,"class","warning")},m(t,a){le(document.head,l),n(t,f,a),n(t,e,a),n(t,i,a),d(c,t,a),n(t,x,a),d(j,t,a),n(t,R,a),n(t,U,a),n(t,Z,a),n(t,$,a),n(t,o,a),n(t,g,a),n(t,I,a),d(F,t,a),n(t,V,a),n(t,X,a),n(t,p,a),d(_,t,a),n(t,ot,a),n(t,L,a),n(t,ft,a),d(S,t,a),n(t,ct,a),n(t,Y,a),n(t,Mt,a),n(t,H,a),n(t,ut,a),n(t,Q,a),n(t,dt,a),d(A,t,a),n(t,ht,a),n(t,z,a),n(t,Jt,a),d(q,t,a),n(t,wt,a),d(D,t,a),n(t,Tt,a),n(t,P,a),n(t,bt,a),d(O,t,a),n(t,Ut,a),n(t,K,a),n(t,$t,a),n(t,tt,a),n(t,_t,a),d(et,t,a),n(t,yt,a),d(lt,t,a),n(t,gt,a),d(N,t,a),n(t,jt,a),d(at,t,a),n(t,xt,a),n(t,st,a),n(t,Ct,a),d(nt,t,a),n(t,Xt,a),n(t,pt,a),n(t,Rt,a),d(v,t,a),n(t,Zt,a),d(it,t,a),n(t,Wt,a),n(t,mt,a),It=!0},p(t,[a]){const At={};a&2&&(At.$$scope={dirty:a,ctx:t}),N.$set(At);const zt={};a&2&&(zt.$$scope={dirty:a,ctx:t}),v.$set(zt)},i(t){It||(h(c.$$.fragment,t),h(j.$$.fragment,t),h(F.$$.fragment,t),h(_.$$.fragment,t),h(S.$$.fragment,t),h(A.$$.fragment,t),h(q.$$.fragment,t),h(D.$$.fragment,t),h(O.$$.fragment,t),h(et.$$.fragment,t),h(lt.$$.fragment,t),h(N.$$.fragment,t),h(at.$$.fragment,t),h(nt.$$.fragment,t),h(v.$$.fragment,t),h(it.$$.fragment,t),It=!0)},o(t){J(c.$$.fragment,t),J(j.$$.fragment,t),J(F.$$.fragment,t),J(_.$$.fragment,t),J(S.$$.fragment,t),J(A.$$.fragment,t),J(q.$$.fragment,t),J(D.$$.fragment,t),J(O.$$.fragment,t),J(et.$$.fragment,t),J(lt.$$.fragment,t),J(N.$$.fragment,t),J(at.$$.fragment,t),J(nt.$$.fragment,t),J(v.$$.fragment,t),J(it.$$.fragment,t),It=!1},d(t){t&&(s(f),s(e),s(i),s(x),s(R),s(U),s(Z),s($),s(o),s(g),s(I),s(V),s(X),s(p),s(ot),s(L),s(ft),s(ct),s(Y),s(Mt),s(H),s(ut),s(Q),s(dt),s(ht),s(z),s(Jt),s(wt),s(Tt),s(P),s(bt),s(Ut),s(K),s($t),s(tt),s(_t),s(yt),s(gt),s(jt),s(xt),s(st),s(Ct),s(Xt),s(pt),s(Rt),s(Zt),s(Wt),s(mt)),s(l),w(c,t),w(j,t),w(F,t),w(_,t),w(S,t),w(A,t),w(q,t),w(D,t),w(O,t),w(et,t),w(lt,t),w(N,t),w(at,t),w(nt,t),w(v,t),w(it,t)}}}const ue='{"title":"Text-to-image","local":"text-to-image","sections":[{"title":"하드웨어 요구 사항","local":"하드웨어-요구-사항","sections":[],"depth":3},{"title":"Hub에 모델 업로드하기","local":"hub에-모델-업로드하기","sections":[],"depth":2},{"title":"체크포인트 저장 및 불러오기","local":"체크포인트-저장-및-불러오기","sections":[],"depth":2},{"title":"파인튜닝","local":"파인튜닝","sections":[],"depth":2},{"title":"LoRA","local":"lora","sections":[],"depth":2},{"title":"추론","local":"추론","sections":[],"depth":2}],"depth":1}';function de(C){return Ot(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Ue extends Kt{constructor(l){super(),te(this,l,de,Me,Pt,{})}}export{Ue as component};
