import{s as qt,o as Dt,n as mt}from"../chunks/scheduler.6e0d5ff7.js";import{S as Pt,i as Kt,g as h,s as o,r as u,E as Ot,h as $,f as s,c as f,j as Ht,u as J,x as U,k as zt,y as te,a as n,v as T,d as M,t as w,w as d}from"../chunks/index.d7c1b260.js";import{T as ee}from"../chunks/Tip.c000e27b.js";import{C as B}from"../chunks/CodeBlock.09a08494.js";import{F as At,M as Rt}from"../chunks/Markdown.ef851fc4.js";import{H as pt,E as le}from"../chunks/EditOnGithub.733546da.js";function ae(j){let l,r="text-to-image 파인튜닝 스크립트는 experimental 상태입니다. 과적합하기 쉽고 치명적인 망각과 같은 문제에 부딪히기 쉽습니다. 자체 데이터셋에서 최상의 결과를 얻으려면 다양한 하이퍼파라미터를 탐색하는 것이 좋습니다.";return{c(){l=h("p"),l.textContent=r},l(e){l=$(e,"P",{"data-svelte-h":!0}),U(l)!=="svelte-szes5h"&&(l.textContent=r)},m(e,i){n(e,l,i)},p:mt,d(e){e&&s(l)}}}function se(j){let l,r='다음과 같이 <a href="https://huggingface.co/datasets/lambdalabs/pokemon-blip-captions" rel="nofollow">Pokémon 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,Z,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)할 수 있습니다.',I,_,N="사용자 커스텀 loading logic을 사용하려면 스크립트를 수정하십시오. 도움이 되도록 코드의 적절한 위치에 포인터를 남겼습니다. 🤗 아래 예제 스크립트는 <code>TRAIN_DIR</code>의 로컬 데이터셋으로를 파인튜닝하는 방법과 <code>OUTPUT_DIR</code>에서 모델을 저장할 위치를 보여줍니다:",W,b,R;return i=new B({props:{code:"ZXhwb3J0JTIwTU9ERUxfTkFNRSUzRCUyMkNvbXBWaXMlMkZzdGFibGUtZGlmZnVzaW9uLXYxLTQlMjIlMEFleHBvcnQlMjBkYXRhc2V0X25hbWUlM0QlMjJsYW1iZGFsYWJzJTJGcG9rZW1vbi1ibGlwLWNhcHRpb25zJTIyJTBBJTBBYWNjZWxlcmF0ZSUyMGxhdW5jaCUyMHRyYWluX3RleHRfdG9faW1hZ2UucHklMjAlNUMlMEElMjAlMjAtLXByZXRyYWluZWRfbW9kZWxfbmFtZV9vcl9wYXRoJTNEJTI0TU9ERUxfTkFNRSUyMCU1QyUwQSUyMCUyMC0tZGF0YXNldF9uYW1lJTNEJTI0ZGF0YXNldF9uYW1lJTIwJTVDJTBBJTIwJTIwLS11c2VfZW1hJTIwJTVDJTBBJTIwJTIwLS1yZXNvbHV0aW9uJTNENTEyJTIwLS1jZW50ZXJfY3JvcCUyMC0tcmFuZG9tX2ZsaXAlMjAlNUMlMEElMjAlMjAtLXRyYWluX2JhdGNoX3NpemUlM0QxJTIwJTVDJTBBJTIwJTIwLS1ncmFkaWVudF9hY2N1bXVsYXRpb25fc3RlcHMlM0Q0JTIwJTVDJTBBJTIwJTIwLS1ncmFkaWVudF9jaGVja3BvaW50aW5nJTIwJTVDJTBBJTIwJTIwLS1taXhlZF9wcmVjaXNpb24lM0QlMjJmcDE2JTIyJTIwJTVDJTBBJTIwJTIwLS1tYXhfdHJhaW5fc3RlcHMlM0QxNTAwMCUyMCU1QyUwQSUyMCUyMC0tbGVhcm5pbmdfcmF0ZSUzRDFlLTA1JTIwJTVDJTBBJTIwJTIwLS1tYXhfZ3JhZF9ub3JtJTNEMSUyMCU1QyUwQSUyMCUyMC0tbHJfc2NoZWR1bGVyJTNEJTIyY29uc3RhbnQlMjIlMjAtLWxyX3dhcm11cF9zdGVwcyUzRDAlMjAlNUMlMEElMjAlMjAtLW91dHB1dF9kaXIlM0QlMjJzZC1wb2tlbW9uLW1vZGVsJTIyJTIw",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 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-pokemon-model&quot;</span> `,wrap:!1}}),b=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=h("p"),l.innerHTML=r,e=o(),u(i.$$.fragment),c=o(),Z=h("p"),Z.innerHTML=g,I=o(),_=h("p"),_.innerHTML=N,W=o(),u(b.$$.fragment)},l(m){l=$(m,"P",{"data-svelte-h":!0}),U(l)!=="svelte-18850va"&&(l.innerHTML=r),e=f(m),J(i.$$.fragment,m),c=f(m),Z=$(m,"P",{"data-svelte-h":!0}),U(Z)!=="svelte-19wquqk"&&(Z.innerHTML=g),I=f(m),_=$(m,"P",{"data-svelte-h":!0}),U(_)!=="svelte-i9hrjr"&&(_.innerHTML=N),W=f(m),J(b.$$.fragment,m)},m(m,y){n(m,l,y),n(m,e,y),T(i,m,y),n(m,c,y),n(m,Z,y),n(m,I,y),n(m,_,y),n(m,W,y),T(b,m,y),R=!0},p:mt,i(m){R||(M(i.$$.fragment,m),M(b.$$.fragment,m),R=!0)},o(m){w(i.$$.fragment,m),w(b.$$.fragment,m),R=!1},d(m){m&&(s(l),s(e),s(c),s(Z),s(I),s(_),s(W)),d(i,m),d(b,m)}}}function ne(j){let l,r;return l=new Rt({props:{$$slots:{default:[se]},$$scope:{ctx:j}}}),{c(){u(l.$$.fragment)},l(e){J(l.$$.fragment,e)},m(e,i){T(l,e,i),r=!0},p(e,i){const c={};i&2&&(c.$$scope={dirty:i,ctx:e}),l.$set(c)},i(e){r||(M(l.$$.fragment,e),r=!0)},o(e){w(l.$$.fragment,e),r=!1},d(e){d(l,e)}}}function pe(j){let l,r='<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="스크립트를 실행하기 전에 요구 사항이 설치되어 있는지 확인하십시오:",Z,g,I,_,N='그러면 다음과 같이 <a href="https://github.com/huggingface/diffusers/blob/main/examples/text_to_image/train_text_to_image_flax.py" rel="nofollow">Flax 학습 스크립트</a>를 실행할 수 있습니다.',W,b,R,m,y='자체 데이터셋으로 파인튜닝하려면 🤗 <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)할 수 있습니다.',G,C,it="사용자 커스텀 loading logic을 사용하려면 스크립트를 수정하십시오. 도움이 되도록 코드의 적절한 위치에 포인터를 남겼습니다. 🤗 아래 예제 스크립트는 <code>TRAIN_DIR</code>의 로컬 데이터셋으로를 파인튜닝하는 방법을 보여줍니다:",F,X,V;return g=new B({props:{code:"cGlwJTIwaW5zdGFsbCUyMC1VJTIwLXIlMjByZXF1aXJlbWVudHNfZmxheC50eHQ=",highlighted:"pip install -U -r requirements_flax.txt",wrap:!1}}),b=new B({props:{code:"ZXhwb3J0JTIwTU9ERUxfTkFNRSUzRCUyMnJ1bndheW1sJTJGc3RhYmxlLWRpZmZ1c2lvbi12MS01JTIyJTBBZXhwb3J0JTIwZGF0YXNldF9uYW1lJTNEJTIybGFtYmRhbGFicyUyRnBva2Vtb24tYmxpcC1jYXB0aW9ucyUyMiUwQSUwQXB5dGhvbiUyMHRyYWluX3RleHRfdG9faW1hZ2VfZmxheC5weSUyMCU1QyUwQSUyMCUyMC0tcHJldHJhaW5lZF9tb2RlbF9uYW1lX29yX3BhdGglM0QlMjRNT0RFTF9OQU1FJTIwJTVDJTBBJTIwJTIwLS1kYXRhc2V0X25hbWUlM0QlMjRkYXRhc2V0X25hbWUlMjAlNUMlMEElMjAlMjAtLXJlc29sdXRpb24lM0Q1MTIlMjAtLWNlbnRlcl9jcm9wJTIwLS1yYW5kb21fZmxpcCUyMCU1QyUwQSUyMCUyMC0tdHJhaW5fYmF0Y2hfc2l6ZSUzRDElMjAlNUMlMEElMjAlMjAtLW1heF90cmFpbl9zdGVwcyUzRDE1MDAwJTIwJTVDJTBBJTIwJTIwLS1sZWFybmluZ19yYXRlJTNEMWUtMDUlMjAlNUMlMEElMjAlMjAtLW1heF9ncmFkX25vcm0lM0QxJTIwJTVDJTBBJTIwJTIwLS1vdXRwdXRfZGlyJTNEJTIyc2QtcG9rZW1vbi1tb2RlbCUyMiUyMA==",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> `,wrap:!1}}),X=new B({props:{code:"ZXhwb3J0JTIwTU9ERUxfTkFNRSUzRCUyMmR1b25nbmElMkZzdGFibGUtZGlmZnVzaW9uLXYxLTQtZmxheCUyMiUwQWV4cG9ydCUyMFRSQUlOX0RJUiUzRCUyMnBhdGhfdG9feW91cl9kYXRhc2V0JTIyJTBBJTBBcHl0aG9uJTIwdHJhaW5fdGV4dF90b19pbWFnZV9mbGF4LnB5JTIwJTVDJTBBJTIwJTIwLS1wcmV0cmFpbmVkX21vZGVsX25hbWVfb3JfcGF0aCUzRCUyNE1PREVMX05BTUUlMjAlNUMlMEElMjAlMjAtLXRyYWluX2RhdGFfZGlyJTNEJTI0VFJBSU5fRElSJTIwJTVDJTBBJTIwJTIwLS1yZXNvbHV0aW9uJTNENTEyJTIwLS1jZW50ZXJfY3JvcCUyMC0tcmFuZG9tX2ZsaXAlMjAlNUMlMEElMjAlMjAtLXRyYWluX2JhdGNoX3NpemUlM0QxJTIwJTVDJTBBJTIwJTIwLS1taXhlZF9wcmVjaXNpb24lM0QlMjJmcDE2JTIyJTIwJTVDJTBBJTIwJTIwLS1tYXhfdHJhaW5fc3RlcHMlM0QxNTAwMCUyMCU1QyUwQSUyMCUyMC0tbGVhcm5pbmdfcmF0ZSUzRDFlLTA1JTIwJTVDJTBBJTIwJTIwLS1tYXhfZ3JhZF9ub3JtJTNEMSUyMCU1QyUwQSUyMCUyMC0tb3V0cHV0X2RpciUzRCUyMnNkLXBva2Vtb24tbW9kZWwlMjI=",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>`,wrap:!1}}),{c(){l=h("p"),l.innerHTML=r,e=o(),i=h("p"),i.textContent=c,Z=o(),u(g.$$.fragment),I=o(),_=h("p"),_.innerHTML=N,W=o(),u(b.$$.fragment),R=o(),m=h("p"),m.innerHTML=y,G=o(),C=h("p"),C.innerHTML=it,F=o(),u(X.$$.fragment)},l(p){l=$(p,"P",{"data-svelte-h":!0}),U(l)!=="svelte-c7loxj"&&(l.innerHTML=r),e=f(p),i=$(p,"P",{"data-svelte-h":!0}),U(i)!=="svelte-1w9ydbl"&&(i.textContent=c),Z=f(p),J(g.$$.fragment,p),I=f(p),_=$(p,"P",{"data-svelte-h":!0}),U(_)!=="svelte-16f5q4a"&&(_.innerHTML=N),W=f(p),J(b.$$.fragment,p),R=f(p),m=$(p,"P",{"data-svelte-h":!0}),U(m)!=="svelte-19wquqk"&&(m.innerHTML=y),G=f(p),C=$(p,"P",{"data-svelte-h":!0}),U(C)!=="svelte-3igbkc"&&(C.innerHTML=it),F=f(p),J(X.$$.fragment,p)},m(p,x){n(p,l,x),n(p,e,x),n(p,i,x),n(p,Z,x),T(g,p,x),n(p,I,x),n(p,_,x),n(p,W,x),T(b,p,x),n(p,R,x),n(p,m,x),n(p,G,x),n(p,C,x),n(p,F,x),T(X,p,x),V=!0},p:mt,i(p){V||(M(g.$$.fragment,p),M(b.$$.fragment,p),M(X.$$.fragment,p),V=!0)},o(p){w(g.$$.fragment,p),w(b.$$.fragment,p),w(X.$$.fragment,p),V=!1},d(p){p&&(s(l),s(e),s(i),s(Z),s(I),s(_),s(W),s(R),s(m),s(G),s(C),s(F)),d(g,p),d(b,p),d(X,p)}}}function ie(j){let l,r;return l=new Rt({props:{$$slots:{default:[pe]},$$scope:{ctx:j}}}),{c(){u(l.$$.fragment)},l(e){J(l.$$.fragment,e)},m(e,i){T(l,e,i),r=!0},p(e,i){const c={};i&2&&(c.$$scope={dirty:i,ctx:e}),l.$set(c)},i(e){r||(M(l.$$.fragment,e),r=!0)},o(e){w(l.$$.fragment,e),r=!1},d(e){d(l,e)}}}function re(j){let l,r;return l=new B({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMFN0YWJsZURpZmZ1c2lvblBpcGVsaW5lJTBBJTBBbW9kZWxfcGF0aCUyMCUzRCUyMCUyMnBhdGhfdG9fc2F2ZWRfbW9kZWwlMjIlMEFwaXBlJTIwJTNEJTIwU3RhYmxlRGlmZnVzaW9uUGlwZWxpbmUuZnJvbV9wcmV0cmFpbmVkKG1vZGVsX3BhdGglMkMlMjB0b3JjaF9kdHlwZSUzRHRvcmNoLmZsb2F0MTYpJTBBcGlwZS50byglMjJjdWRhJTIyKSUwQSUwQWltYWdlJTIwJTNEJTIwcGlwZShwcm9tcHQlM0QlMjJ5b2RhJTIyKS5pbWFnZXMlNUIwJTVEJTBBaW1hZ2Uuc2F2ZSglMjJ5b2RhLXBva2Vtb24ucG5nJTIyKQ==",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-pokemon.png&quot;</span>)`,wrap:!1}}),{c(){u(l.$$.fragment)},l(e){J(l.$$.fragment,e)},m(e,i){T(l,e,i),r=!0},p:mt,i(e){r||(M(l.$$.fragment,e),r=!0)},o(e){w(l.$$.fragment,e),r=!1},d(e){d(l,e)}}}function me(j){let l,r;return l=new Rt({props:{$$slots:{default:[re]},$$scope:{ctx:j}}}),{c(){u(l.$$.fragment)},l(e){J(l.$$.fragment,e)},m(e,i){T(l,e,i),r=!0},p(e,i){const c={};i&2&&(c.$$scope={dirty:i,ctx:e}),l.$set(c)},i(e){r||(M(l.$$.fragment,e),r=!0)},o(e){w(l.$$.fragment,e),r=!1},d(e){d(l,e)}}}function oe(j){let l,r;return l=new B({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>)`,wrap:!1}}),{c(){u(l.$$.fragment)},l(e){J(l.$$.fragment,e)},m(e,i){T(l,e,i),r=!0},p:mt,i(e){r||(M(l.$$.fragment,e),r=!0)},o(e){w(l.$$.fragment,e),r=!1},d(e){d(l,e)}}}function fe(j){let l,r;return l=new Rt({props:{$$slots:{default:[oe]},$$scope:{ctx:j}}}),{c(){u(l.$$.fragment)},l(e){J(l.$$.fragment,e)},m(e,i){T(l,e,i),r=!0},p(e,i){const c={};i&2&&(c.$$scope={dirty:i,ctx:e}),l.$set(c)},i(e){r||(M(l.$$.fragment,e),r=!0)},o(e){w(l.$$.fragment,e),r=!1},d(e){d(l,e)}}}function ce(j){let l,r,e,i,c,Z,g,I,_,N='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>에서 자세히 찾을 수 있습니다.',W,b,R="스크립트를 실행하기 전에, 라이브러리의 학습 dependency들을 설치해야 합니다:",m,y,G,C,it='그리고 <a href="https://github.com/huggingface/accelerate/" rel="nofollow">🤗Accelerate</a> 환경을 초기화합니다:',F,X,V,p,x="리포지토리를 이미 복제한 경우, 이 단계를 수행할 필요가 없습니다. 대신, 로컬 체크아웃 경로를 학습 스크립트에 명시할 수 있으며 거기에서 로드됩니다.",ot,L,ft,E,Bt='<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>를 참조하세요.',ct,S,Gt='xFormers로 memory efficient attention을 활성화하여 메모리 사용량 훨씬 더 줄일 수 있습니다. <a href="./optimization/xformers">xFormers가 설치</a>되어 있는지 확인하고 <code>--enable_xformers_memory_efficient_attention</code>를 학습 스크립트에 명시합니다.',ut,Y,Ft="xFormers는 Flax에 사용할 수 없습니다.",Jt,Q,Tt,H,Vt="학습 스크립트에 다음 인수를 추가하여 모델을 허브에 저장합니다:",Mt,z,wt,A,dt,q,Nt="학습 중 발생할 수 있는 일에 대비하여 정기적으로 체크포인트를 저장해 두는 것이 좋습니다. 체크포인트를 저장하려면 학습 스크립트에 다음 인수를 명시합니다.",ht,D,$t,P,vt="500스텝마다 전체 학습 state가 ‘output_dir’의 하위 폴더에 저장됩니다. 체크포인트는 ‘checkpoint-‘에 지금까지 학습된 step 수입니다. 예를 들어 ‘checkpoint-1500’은 1500 학습 step 후에 저장된 체크포인트입니다.",_t,K,kt="학습을 재개하기 위해 체크포인트를 불러오려면 ‘—resume_from_checkpoint’ 인수를 학습 스크립트에 명시하고 재개할 체크포인트를 지정하십시오. 예를 들어 다음 인수는 1500개의 학습 step 후에 저장된 체크포인트에서부터 훈련을 재개합니다.",bt,O,Ut,tt,yt,v,gt,et,jt,lt,Lt='Text-to-image 모델 파인튜닝을 위해, 대규모 모델 학습을 가속화하기 위한 파인튜닝 기술인 LoRA(Low-Rank Adaptation of Large Language Models)를 사용할 수 있습니다. 자세한 내용은 <a href="lora#text-to-image">LoRA 학습</a> 가이드를 참조하세요.',xt,at,Zt,st,Et="허브의 모델 경로 또는 모델 이름을 <code>StableDiffusionPipeline</code>에 전달하여 추론을 위해 파인 튜닝된 모델을 불러올 수 있습니다:",Ct,k,Xt,nt,It,rt,Wt;return c=new pt({props:{title:"Text-to-image",local:"text-to-image",headingTag:"h1"}}),g=new ee({props:{warning:!0,$$slots:{default:[ae]},$$scope:{ctx:j}}}),y=new B({props:{code:"cGlwJTIwaW5zdGFsbCUyMGdpdCUyQmh0dHBzJTNBJTJGJTJGZ2l0aHViLmNvbSUyRmh1Z2dpbmdmYWNlJTJGZGlmZnVzZXJzLmdpdCUwQXBpcCUyMGluc3RhbGwlMjAtVSUyMC1yJTIwcmVxdWlyZW1lbnRzLnR4dA==",highlighted:`pip install git+https://github.com/huggingface/diffusers.git
pip install -U -r requirements.txt`,wrap:!1}}),X=new B({props:{code:"YWNjZWxlcmF0ZSUyMGNvbmZpZw==",highlighted:"accelerate config",wrap:!1}}),L=new pt({props:{title:"하드웨어 요구 사항",local:"하드웨어-요구-사항",headingTag:"h3"}}),Q=new pt({props:{title:"Hub에 모델 업로드하기",local:"hub에-모델-업로드하기",headingTag:"h2"}}),z=new B({props:{code:"JTIwJTIwLS1wdXNoX3RvX2h1Yg==",highlighted:"  --push_to_hub",wrap:!1}}),A=new pt({props:{title:"체크포인트 저장 및 불러오기",local:"체크포인트-저장-및-불러오기",headingTag:"h2"}}),D=new B({props:{code:"JTIwJTIwLS1jaGVja3BvaW50aW5nX3N0ZXBzJTNENTAw",highlighted:"  --checkpointing_steps=500",wrap:!1}}),O=new B({props:{code:"JTIwJTIwLS1yZXN1bWVfZnJvbV9jaGVja3BvaW50JTNEJTIyY2hlY2twb2ludC0xNTAwJTIy",highlighted:'  --resume_from_checkpoint=<span class="hljs-string">&quot;checkpoint-1500&quot;</span>',wrap:!1}}),tt=new pt({props:{title:"파인튜닝",local:"파인튜닝",headingTag:"h2"}}),v=new At({props:{pytorch:!0,tensorflow:!1,jax:!0,$$slots:{jax:[ie],pytorch:[ne]},$$scope:{ctx:j}}}),et=new pt({props:{title:"LoRA",local:"lora",headingTag:"h2"}}),at=new pt({props:{title:"추론",local:"추론",headingTag:"h2"}}),k=new At({props:{pytorch:!0,tensorflow:!1,jax:!0,$$slots:{jax:[fe],pytorch:[me]},$$scope:{ctx:j}}}),nt=new le({props:{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/ko/training/text2image.md"}}),{c(){l=h("meta"),r=o(),e=h("p"),i=o(),u(c.$$.fragment),Z=o(),u(g.$$.fragment),I=o(),_=h("p"),_.innerHTML=N,W=o(),b=h("p"),b.textContent=R,m=o(),u(y.$$.fragment),G=o(),C=h("p"),C.innerHTML=it,F=o(),u(X.$$.fragment),V=o(),p=h("p"),p.textContent=x,ot=o(),u(L.$$.fragment),ft=o(),E=h("p"),E.innerHTML=Bt,ct=o(),S=h("p"),S.innerHTML=Gt,ut=o(),Y=h("p"),Y.textContent=Ft,Jt=o(),u(Q.$$.fragment),Tt=o(),H=h("p"),H.textContent=Vt,Mt=o(),u(z.$$.fragment),wt=o(),u(A.$$.fragment),dt=o(),q=h("p"),q.textContent=Nt,ht=o(),u(D.$$.fragment),$t=o(),P=h("p"),P.textContent=vt,_t=o(),K=h("p"),K.textContent=kt,bt=o(),u(O.$$.fragment),Ut=o(),u(tt.$$.fragment),yt=o(),u(v.$$.fragment),gt=o(),u(et.$$.fragment),jt=o(),lt=h("p"),lt.innerHTML=Lt,xt=o(),u(at.$$.fragment),Zt=o(),st=h("p"),st.innerHTML=Et,Ct=o(),u(k.$$.fragment),Xt=o(),u(nt.$$.fragment),It=o(),rt=h("p"),this.h()},l(t){const a=Ot("svelte-u9bgzb",document.head);l=$(a,"META",{name:!0,content:!0}),a.forEach(s),r=f(t),e=$(t,"P",{}),Ht(e).forEach(s),i=f(t),J(c.$$.fragment,t),Z=f(t),J(g.$$.fragment,t),I=f(t),_=$(t,"P",{"data-svelte-h":!0}),U(_)!=="svelte-6focsf"&&(_.innerHTML=N),W=f(t),b=$(t,"P",{"data-svelte-h":!0}),U(b)!=="svelte-d6uma"&&(b.textContent=R),m=f(t),J(y.$$.fragment,t),G=f(t),C=$(t,"P",{"data-svelte-h":!0}),U(C)!=="svelte-1q84qbk"&&(C.innerHTML=it),F=f(t),J(X.$$.fragment,t),V=f(t),p=$(t,"P",{"data-svelte-h":!0}),U(p)!=="svelte-9go34t"&&(p.textContent=x),ot=f(t),J(L.$$.fragment,t),ft=f(t),E=$(t,"P",{"data-svelte-h":!0}),U(E)!=="svelte-1x90o2u"&&(E.innerHTML=Bt),ct=f(t),S=$(t,"P",{"data-svelte-h":!0}),U(S)!=="svelte-yc0tb6"&&(S.innerHTML=Gt),ut=f(t),Y=$(t,"P",{"data-svelte-h":!0}),U(Y)!=="svelte-1ksou9j"&&(Y.textContent=Ft),Jt=f(t),J(Q.$$.fragment,t),Tt=f(t),H=$(t,"P",{"data-svelte-h":!0}),U(H)!=="svelte-1cshqoz"&&(H.textContent=Vt),Mt=f(t),J(z.$$.fragment,t),wt=f(t),J(A.$$.fragment,t),dt=f(t),q=$(t,"P",{"data-svelte-h":!0}),U(q)!=="svelte-dt8b2s"&&(q.textContent=Nt),ht=f(t),J(D.$$.fragment,t),$t=f(t),P=$(t,"P",{"data-svelte-h":!0}),U(P)!=="svelte-1rb33uz"&&(P.textContent=vt),_t=f(t),K=$(t,"P",{"data-svelte-h":!0}),U(K)!=="svelte-19yki7i"&&(K.textContent=kt),bt=f(t),J(O.$$.fragment,t),Ut=f(t),J(tt.$$.fragment,t),yt=f(t),J(v.$$.fragment,t),gt=f(t),J(et.$$.fragment,t),jt=f(t),lt=$(t,"P",{"data-svelte-h":!0}),U(lt)!=="svelte-1dpocf9"&&(lt.innerHTML=Lt),xt=f(t),J(at.$$.fragment,t),Zt=f(t),st=$(t,"P",{"data-svelte-h":!0}),U(st)!=="svelte-1an9epu"&&(st.innerHTML=Et),Ct=f(t),J(k.$$.fragment,t),Xt=f(t),J(nt.$$.fragment,t),It=f(t),rt=$(t,"P",{}),Ht(rt).forEach(s),this.h()},h(){zt(l,"name","hf:doc:metadata"),zt(l,"content",ue)},m(t,a){te(document.head,l),n(t,r,a),n(t,e,a),n(t,i,a),T(c,t,a),n(t,Z,a),T(g,t,a),n(t,I,a),n(t,_,a),n(t,W,a),n(t,b,a),n(t,m,a),T(y,t,a),n(t,G,a),n(t,C,a),n(t,F,a),T(X,t,a),n(t,V,a),n(t,p,a),n(t,ot,a),T(L,t,a),n(t,ft,a),n(t,E,a),n(t,ct,a),n(t,S,a),n(t,ut,a),n(t,Y,a),n(t,Jt,a),T(Q,t,a),n(t,Tt,a),n(t,H,a),n(t,Mt,a),T(z,t,a),n(t,wt,a),T(A,t,a),n(t,dt,a),n(t,q,a),n(t,ht,a),T(D,t,a),n(t,$t,a),n(t,P,a),n(t,_t,a),n(t,K,a),n(t,bt,a),T(O,t,a),n(t,Ut,a),T(tt,t,a),n(t,yt,a),T(v,t,a),n(t,gt,a),T(et,t,a),n(t,jt,a),n(t,lt,a),n(t,xt,a),T(at,t,a),n(t,Zt,a),n(t,st,a),n(t,Ct,a),T(k,t,a),n(t,Xt,a),T(nt,t,a),n(t,It,a),n(t,rt,a),Wt=!0},p(t,[a]){const St={};a&2&&(St.$$scope={dirty:a,ctx:t}),g.$set(St);const Yt={};a&2&&(Yt.$$scope={dirty:a,ctx:t}),v.$set(Yt);const Qt={};a&2&&(Qt.$$scope={dirty:a,ctx:t}),k.$set(Qt)},i(t){Wt||(M(c.$$.fragment,t),M(g.$$.fragment,t),M(y.$$.fragment,t),M(X.$$.fragment,t),M(L.$$.fragment,t),M(Q.$$.fragment,t),M(z.$$.fragment,t),M(A.$$.fragment,t),M(D.$$.fragment,t),M(O.$$.fragment,t),M(tt.$$.fragment,t),M(v.$$.fragment,t),M(et.$$.fragment,t),M(at.$$.fragment,t),M(k.$$.fragment,t),M(nt.$$.fragment,t),Wt=!0)},o(t){w(c.$$.fragment,t),w(g.$$.fragment,t),w(y.$$.fragment,t),w(X.$$.fragment,t),w(L.$$.fragment,t),w(Q.$$.fragment,t),w(z.$$.fragment,t),w(A.$$.fragment,t),w(D.$$.fragment,t),w(O.$$.fragment,t),w(tt.$$.fragment,t),w(v.$$.fragment,t),w(et.$$.fragment,t),w(at.$$.fragment,t),w(k.$$.fragment,t),w(nt.$$.fragment,t),Wt=!1},d(t){t&&(s(r),s(e),s(i),s(Z),s(I),s(_),s(W),s(b),s(m),s(G),s(C),s(F),s(V),s(p),s(ot),s(ft),s(E),s(ct),s(S),s(ut),s(Y),s(Jt),s(Tt),s(H),s(Mt),s(wt),s(dt),s(q),s(ht),s($t),s(P),s(_t),s(K),s(bt),s(Ut),s(yt),s(gt),s(jt),s(lt),s(xt),s(Zt),s(st),s(Ct),s(Xt),s(It),s(rt)),s(l),d(c,t),d(g,t),d(y,t),d(X,t),d(L,t),d(Q,t),d(z,t),d(A,t),d(D,t),d(O,t),d(tt,t),d(v,t),d(et,t),d(at,t),d(k,t),d(nt,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 Je(j){return Dt(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class _e extends Pt{constructor(l){super(),Kt(this,l,Je,ce,qt,{})}}export{_e as component};
