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