import{s as Oe,n as et,o as tt}from"../chunks/scheduler.23542ac5.js";import{S as lt,i as st,e as p,s as i,c as m,h as it,a,d as l,b as n,f as Qe,g as f,j as o,k as Ae,l as nt,m as s,n as r,t as u,o as c,p as b}from"../chunks/index.9b1f405b.js";import{C as pt,H as Ke,E as at}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.5bcbaa63.js";import{C as F}from"../chunks/CodeBlock.e82446dd.js";import{D as ot}from"../chunks/DocNotebookDropdown.68a629d2.js";function mt(Ue){let d,Q,D,A,h,K,g,O,M,ee,w,Ge=`텍스트 가이드 기반의 diffusion 모델은 주어진 텍스트 프롬프트를 기반으로 이미지를 생성합니다.
텍스트 프롬프트에는 모델이 생성해야 하는 여러 개념이 포함될 수 있으며 프롬프트의 특정 부분에 가중치를 부여하는 것이 바람직한 경우가 많습니다.`,te,T,Ve=`Diffusion 모델은 문맥화된 텍스트 임베딩으로 diffusion 모델의 cross attention 레이어를 조절함으로써 작동합니다.
(<a href="https://huggingface.co/docs/optimum-neuron/main/en/package_reference/modeling#stable-diffusion" rel="nofollow">더 많은 정보를 위한 Stable Diffusion Guide</a>를 참고하세요).
따라서 프롬프트의 특정 부분을 강조하는(또는 강조하지 않는) 간단한 방법은 프롬프트의 관련 부분에 해당하는 텍스트 임베딩 벡터의 크기를 늘리거나 줄이는 것입니다.
이것은 “프롬프트 가중치 부여” 라고 하며, 커뮤니티에서 가장 요구하는 기능입니다.(<a href="https://github.com/huggingface/diffusers/issues/2431" rel="nofollow">이곳</a>의 issue를 보세요 ).`,le,$,se,y,He=`우리는 <code>diffusers</code>의 역할이 다른 프로젝트를 가능하게 하는 필수적인 기능을 제공하는 toolbex라고 생각합니다.
<a href="https://github.com/invoke-ai/InvokeAI" rel="nofollow">InvokeAI</a> 나 <a href="https://github.com/abhishekkrthakur/diffuzers" rel="nofollow">diffuzers</a> 같은 강력한 UI를 구축할 수 있습니다.
프롬프트를 조작하는 방법을 지원하기 위해, <code>diffusers</code> 는
<a href="https://huggingface.co/docs/diffusers/v0.18.2/en/api/pipelines/stable_diffusion/text2img#diffusers.StableDiffusionPipeline" rel="nofollow">StableDiffusionPipeline</a>와 같은
많은 파이프라인에 <a href="https://huggingface.co/docs/diffusers/v0.14.0/en/api/pipelines/stable_diffusion/text2img#diffusers.StableDiffusionPipeline.__call__.prompt_embeds" rel="nofollow">prompt_embeds</a>
인수를 노출시켜, “prompt-weighted”/축척된 텍스트 임베딩을 파이프라인에 바로 전달할 수 있게 합니다.`,ie,v,Ie=`<a href="https://github.com/damian0815/compel" rel="nofollow">Compel 라이브러리</a>는 프롬프트의 일부를 강조하거나 강조하지 않을 수 있는 쉬운 방법을 제공합니다.
임베딩을 직접 준비하는 것 대신 이 방법을 사용하는 것을 강력히 추천합니다.`,ne,_,je=`간단한 예제를 살펴보겠습니다.
다음과 같이 <code>&quot;공을 갖고 노는 붉은색 고양이&quot;</code> 이미지를 생성하고 싶습니다:`,pe,J,ae,C,Be="생성된 이미지:",oe,Z,Xe='<img src="https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/compel/forest_0.png" alt="img"/>',me,k,We="사진에서 알 수 있듯이, “공”은 이미지에 없습니다. 이 부분을 강조해 볼까요!",fe,x,Ne="먼저 <code>compel</code> 라이브러리를 설치해야합니다:",re,U,ue,G,Le="그런 다음에는 <code>Compel</code> 오브젝트를 생성합니다:",ce,V,be,H,Ee="이제 <code>&quot;++&quot;</code> 를 사용해서 “공” 을 강조해 봅시다:",de,I,he,j,Pe="그리고 이 프롬프트를 파이프라인에 바로 전달하지 않고, <code>compel_proc</code> 를 사용하여 처리해야합니다:",ge,B,Me,X,ze="파이프라인에 <code>prompt_embeds</code> 를 바로 전달할 수 있습니다:",we,W,Te,N,Re="이제 “공”이 있는 그림을 출력할 수 있습니다!",$e,L,Se='<img src="https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/compel/forest_1.png" alt="img"/>',ye,E,Ye="마찬가지로 <code>--</code> 접미사를 단어에 사용하여 문장의 일부를 강조하지 않을 수 있습니다. 한번 시도해 보세요!",ve,P,Fe=`즐겨찾는 파이프라인에 <code>prompt_embeds</code> 입력이 없는 경우 issue를 새로 만들어주세요.
Diffusers 팀은 최대한 대응하려고 노력합니다.`,_e,z,De=`Compel 1.1.6 는 textual inversions을 사용하여 단순화하는 유티릴티 클래스를 추가합니다.
<code>DiffusersTextualInversionManager</code>를 인스턴스화 한 후 이를 Compel init에 전달합니다:`,Je,R,Ce,S,qe='더 많은 정보를 얻고 싶다면 <a href="https://github.com/damian0815/compel" rel="nofollow">compel</a> 라이브러리 문서를 참고하세요.',Ze,Y,ke,q,xe;return h=new pt({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),g=new ot({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;",options:[{label:"Mixed",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers_doc/ko/weighted_prompts.ipynb"},{label:"PyTorch",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers_doc/ko/pytorch/weighted_prompts.ipynb"},{label:"TensorFlow",value:"https://colab.research.google.com/github/huggingface/notebooks/blob/main/diffusers_doc/ko/tensorflow/weighted_prompts.ipynb"},{label:"Mixed",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/diffusers_doc/ko/weighted_prompts.ipynb"},{label:"PyTorch",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/diffusers_doc/ko/pytorch/weighted_prompts.ipynb"},{label:"TensorFlow",value:"https://studiolab.sagemaker.aws/import/github/huggingface/notebooks/blob/main/diffusers_doc/ko/tensorflow/weighted_prompts.ipynb"}]}}),M=new Ke({props:{title:"프롬프트에 가중치 부여하기",local:"프롬프트에-가중치-부여하기",headingTag:"h1"}}),$=new Ke({props:{title:"Diffusers에서 프롬프트 가중치 부여하는 방법",local:"diffusers에서-프롬프트-가중치-부여하는-방법",headingTag:"h2"}}),J=new F({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMFN0YWJsZURpZmZ1c2lvblBpcGVsaW5lJTJDJTIwVW5pUENNdWx0aXN0ZXBTY2hlZHVsZXIlMEElMEFwaXBlJTIwJTNEJTIwU3RhYmxlRGlmZnVzaW9uUGlwZWxpbmUuZnJvbV9wcmV0cmFpbmVkKCUyMkNvbXBWaXMlMkZzdGFibGUtZGlmZnVzaW9uLXYxLTQlMjIpJTBBcGlwZS5zY2hlZHVsZXIlMjAlM0QlMjBVbmlQQ011bHRpc3RlcFNjaGVkdWxlci5mcm9tX2NvbmZpZyhwaXBlLnNjaGVkdWxlci5jb25maWcpJTBBJTBBcHJvbXB0JTIwJTNEJTIwJTIyYSUyMHJlZCUyMGNhdCUyMHBsYXlpbmclMjB3aXRoJTIwYSUyMGJhbGwlMjIlMEElMEFnZW5lcmF0b3IlMjAlM0QlMjB0b3JjaC5HZW5lcmF0b3IoZGV2aWNlJTNEJTIyY3B1JTIyKS5tYW51YWxfc2VlZCgzMyklMEElMEFpbWFnZSUyMCUzRCUyMHBpcGUocHJvbXB0JTJDJTIwZ2VuZXJhdG9yJTNEZ2VuZXJhdG9yJTJDJTIwbnVtX2luZmVyZW5jZV9zdGVwcyUzRDIwKS5pbWFnZXMlNUIwJTVEJTBBaW1hZ2U=",highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> StableDiffusionPipeline, UniPCMultistepScheduler

pipe = StableDiffusionPipeline.from_pretrained(<span class="hljs-string">&quot;CompVis/stable-diffusion-v1-4&quot;</span>)
pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config)

prompt = <span class="hljs-string">&quot;a red cat playing with a ball&quot;</span>

generator = torch.Generator(device=<span class="hljs-string">&quot;cpu&quot;</span>).manual_seed(<span class="hljs-number">33</span>)

image = pipe(prompt, generator=generator, num_inference_steps=<span class="hljs-number">20</span>).images[<span class="hljs-number">0</span>]
image`,wrap:!1}}),U=new F({props:{code:"cGlwJTIwaW5zdGFsbCUyMGNvbXBlbA==",highlighted:"pip install compel",wrap:!1}}),V=new F({props:{code:"ZnJvbSUyMGNvbXBlbCUyMGltcG9ydCUyMENvbXBlbCUwQSUwQWNvbXBlbF9wcm9jJTIwJTNEJTIwQ29tcGVsKHRva2VuaXplciUzRHBpcGUudG9rZW5pemVyJTJDJTIwdGV4dF9lbmNvZGVyJTNEcGlwZS50ZXh0X2VuY29kZXIp",highlighted:`<span class="hljs-keyword">from</span> compel <span class="hljs-keyword">import</span> Compel

compel_proc = Compel(tokenizer=pipe.tokenizer, text_encoder=pipe.text_encoder)`,wrap:!1}}),I=new F({props:{code:"cHJvbXB0JTIwJTNEJTIwJTIyYSUyMHJlZCUyMGNhdCUyMHBsYXlpbmclMjB3aXRoJTIwYSUyMGJhbGwlMkIlMkIlMjI=",highlighted:'prompt = <span class="hljs-string">&quot;a red cat playing with a ball++&quot;</span>',wrap:!1}}),B=new F({props:{code:"cHJvbXB0X2VtYmVkcyUyMCUzRCUyMGNvbXBlbF9wcm9jKHByb21wdCk=",highlighted:"prompt_embeds = compel_proc(prompt)",wrap:!1}}),W=new F({props:{code:"Z2VuZXJhdG9yJTIwJTNEJTIwdG9yY2guR2VuZXJhdG9yKGRldmljZSUzRCUyMmNwdSUyMikubWFudWFsX3NlZWQoMzMpJTBBJTBBaW1hZ2VzJTIwJTNEJTIwcGlwZShwcm9tcHRfZW1iZWRzJTNEcHJvbXB0X2VtYmVkcyUyQyUyMGdlbmVyYXRvciUzRGdlbmVyYXRvciUyQyUyMG51bV9pbmZlcmVuY2Vfc3RlcHMlM0QyMCkuaW1hZ2VzJTVCMCU1RCUwQWltYWdl",highlighted:`generator = torch.Generator(device=<span class="hljs-string">&quot;cpu&quot;</span>).manual_seed(<span class="hljs-number">33</span>)

images = pipe(prompt_embeds=prompt_embeds, generator=generator, num_inference_steps=<span class="hljs-number">20</span>).images[<span class="hljs-number">0</span>]
image`,wrap:!1}}),R=new F({props:{code:"dGV4dHVhbF9pbnZlcnNpb25fbWFuYWdlciUyMCUzRCUyMERpZmZ1c2Vyc1RleHR1YWxJbnZlcnNpb25NYW5hZ2VyKHBpcGUpJTBBY29tcGVsJTIwJTNEJTIwQ29tcGVsKCUwQSUyMCUyMCUyMCUyMHRva2VuaXplciUzRHBpcGUudG9rZW5pemVyJTJDJTBBJTIwJTIwJTIwJTIwdGV4dF9lbmNvZGVyJTNEcGlwZS50ZXh0X2VuY29kZXIlMkMlMEElMjAlMjAlMjAlMjB0ZXh0dWFsX2ludmVyc2lvbl9tYW5hZ2VyJTNEdGV4dHVhbF9pbnZlcnNpb25fbWFuYWdlcik=",highlighted:`<span class="hljs-attr">textual_inversion_manager</span> = DiffusersTextualInversionManager(pipe)
<span class="hljs-attr">compel</span> = Compel(
    <span class="hljs-attr">tokenizer</span>=pipe.tokenizer,
    <span class="hljs-attr">text_encoder</span>=pipe.text_encoder,
    <span class="hljs-attr">textual_inversion_manager</span>=textual_inversion_manager)`,wrap:!1}}),Y=new at({props:{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/ko/using-diffusers/weighted_prompts.md"}}),{c(){d=p("meta"),Q=i(),D=p("p"),A=i(),m(h.$$.fragment),K=i(),m(g.$$.fragment),O=i(),m(M.$$.fragment),ee=i(),w=p("p"),w.textContent=Ge,te=i(),T=p("p"),T.innerHTML=Ve,le=i(),m($.$$.fragment),se=i(),y=p("p"),y.innerHTML=He,ie=i(),v=p("p"),v.innerHTML=Ie,ne=i(),_=p("p"),_.innerHTML=je,pe=i(),m(J.$$.fragment),ae=i(),C=p("p"),C.textContent=Be,oe=i(),Z=p("p"),Z.innerHTML=Xe,me=i(),k=p("p"),k.textContent=We,fe=i(),x=p("p"),x.innerHTML=Ne,re=i(),m(U.$$.fragment),ue=i(),G=p("p"),G.innerHTML=Le,ce=i(),m(V.$$.fragment),be=i(),H=p("p"),H.innerHTML=Ee,de=i(),m(I.$$.fragment),he=i(),j=p("p"),j.innerHTML=Pe,ge=i(),m(B.$$.fragment),Me=i(),X=p("p"),X.innerHTML=ze,we=i(),m(W.$$.fragment),Te=i(),N=p("p"),N.textContent=Re,$e=i(),L=p("p"),L.innerHTML=Se,ye=i(),E=p("p"),E.innerHTML=Ye,ve=i(),P=p("p"),P.innerHTML=Fe,_e=i(),z=p("p"),z.innerHTML=De,Je=i(),m(R.$$.fragment),Ce=i(),S=p("p"),S.innerHTML=qe,Ze=i(),m(Y.$$.fragment),ke=i(),q=p("p"),this.h()},l(e){const t=it("svelte-u9bgzb",document.head);d=a(t,"META",{name:!0,content:!0}),t.forEach(l),Q=n(e),D=a(e,"P",{}),Qe(D).forEach(l),A=n(e),f(h.$$.fragment,e),K=n(e),f(g.$$.fragment,e),O=n(e),f(M.$$.fragment,e),ee=n(e),w=a(e,"P",{"data-svelte-h":!0}),o(w)!=="svelte-6zgx2k"&&(w.textContent=Ge),te=n(e),T=a(e,"P",{"data-svelte-h":!0}),o(T)!=="svelte-jymdy2"&&(T.innerHTML=Ve),le=n(e),f($.$$.fragment,e),se=n(e),y=a(e,"P",{"data-svelte-h":!0}),o(y)!=="svelte-1tfiuem"&&(y.innerHTML=He),ie=n(e),v=a(e,"P",{"data-svelte-h":!0}),o(v)!=="svelte-3a9pj9"&&(v.innerHTML=Ie),ne=n(e),_=a(e,"P",{"data-svelte-h":!0}),o(_)!=="svelte-sndxnq"&&(_.innerHTML=je),pe=n(e),f(J.$$.fragment,e),ae=n(e),C=a(e,"P",{"data-svelte-h":!0}),o(C)!=="svelte-1kk09o0"&&(C.textContent=Be),oe=n(e),Z=a(e,"P",{"data-svelte-h":!0}),o(Z)!=="svelte-lhtk1n"&&(Z.innerHTML=Xe),me=n(e),k=a(e,"P",{"data-svelte-h":!0}),o(k)!=="svelte-1j2une0"&&(k.textContent=We),fe=n(e),x=a(e,"P",{"data-svelte-h":!0}),o(x)!=="svelte-1uy3q6o"&&(x.innerHTML=Ne),re=n(e),f(U.$$.fragment,e),ue=n(e),G=a(e,"P",{"data-svelte-h":!0}),o(G)!=="svelte-1181b2z"&&(G.innerHTML=Le),ce=n(e),f(V.$$.fragment,e),be=n(e),H=a(e,"P",{"data-svelte-h":!0}),o(H)!=="svelte-1ilrue"&&(H.innerHTML=Ee),de=n(e),f(I.$$.fragment,e),he=n(e),j=a(e,"P",{"data-svelte-h":!0}),o(j)!=="svelte-1fd9ba2"&&(j.innerHTML=Pe),ge=n(e),f(B.$$.fragment,e),Me=n(e),X=a(e,"P",{"data-svelte-h":!0}),o(X)!=="svelte-s5my9t"&&(X.innerHTML=ze),we=n(e),f(W.$$.fragment,e),Te=n(e),N=a(e,"P",{"data-svelte-h":!0}),o(N)!=="svelte-1szos4z"&&(N.textContent=Re),$e=n(e),L=a(e,"P",{"data-svelte-h":!0}),o(L)!=="svelte-rm5ydw"&&(L.innerHTML=Se),ye=n(e),E=a(e,"P",{"data-svelte-h":!0}),o(E)!=="svelte-1cz1utb"&&(E.innerHTML=Ye),ve=n(e),P=a(e,"P",{"data-svelte-h":!0}),o(P)!=="svelte-1837j6q"&&(P.innerHTML=Fe),_e=n(e),z=a(e,"P",{"data-svelte-h":!0}),o(z)!=="svelte-1te8sqt"&&(z.innerHTML=De),Je=n(e),f(R.$$.fragment,e),Ce=n(e),S=a(e,"P",{"data-svelte-h":!0}),o(S)!=="svelte-1n4pw6m"&&(S.innerHTML=qe),Ze=n(e),f(Y.$$.fragment,e),ke=n(e),q=a(e,"P",{}),Qe(q).forEach(l),this.h()},h(){Ae(d,"name","hf:doc:metadata"),Ae(d,"content",ft)},m(e,t){nt(document.head,d),s(e,Q,t),s(e,D,t),s(e,A,t),r(h,e,t),s(e,K,t),r(g,e,t),s(e,O,t),r(M,e,t),s(e,ee,t),s(e,w,t),s(e,te,t),s(e,T,t),s(e,le,t),r($,e,t),s(e,se,t),s(e,y,t),s(e,ie,t),s(e,v,t),s(e,ne,t),s(e,_,t),s(e,pe,t),r(J,e,t),s(e,ae,t),s(e,C,t),s(e,oe,t),s(e,Z,t),s(e,me,t),s(e,k,t),s(e,fe,t),s(e,x,t),s(e,re,t),r(U,e,t),s(e,ue,t),s(e,G,t),s(e,ce,t),r(V,e,t),s(e,be,t),s(e,H,t),s(e,de,t),r(I,e,t),s(e,he,t),s(e,j,t),s(e,ge,t),r(B,e,t),s(e,Me,t),s(e,X,t),s(e,we,t),r(W,e,t),s(e,Te,t),s(e,N,t),s(e,$e,t),s(e,L,t),s(e,ye,t),s(e,E,t),s(e,ve,t),s(e,P,t),s(e,_e,t),s(e,z,t),s(e,Je,t),r(R,e,t),s(e,Ce,t),s(e,S,t),s(e,Ze,t),r(Y,e,t),s(e,ke,t),s(e,q,t),xe=!0},p:et,i(e){xe||(u(h.$$.fragment,e),u(g.$$.fragment,e),u(M.$$.fragment,e),u($.$$.fragment,e),u(J.$$.fragment,e),u(U.$$.fragment,e),u(V.$$.fragment,e),u(I.$$.fragment,e),u(B.$$.fragment,e),u(W.$$.fragment,e),u(R.$$.fragment,e),u(Y.$$.fragment,e),xe=!0)},o(e){c(h.$$.fragment,e),c(g.$$.fragment,e),c(M.$$.fragment,e),c($.$$.fragment,e),c(J.$$.fragment,e),c(U.$$.fragment,e),c(V.$$.fragment,e),c(I.$$.fragment,e),c(B.$$.fragment,e),c(W.$$.fragment,e),c(R.$$.fragment,e),c(Y.$$.fragment,e),xe=!1},d(e){e&&(l(Q),l(D),l(A),l(K),l(O),l(ee),l(w),l(te),l(T),l(le),l(se),l(y),l(ie),l(v),l(ne),l(_),l(pe),l(ae),l(C),l(oe),l(Z),l(me),l(k),l(fe),l(x),l(re),l(ue),l(G),l(ce),l(be),l(H),l(de),l(he),l(j),l(ge),l(Me),l(X),l(we),l(Te),l(N),l($e),l(L),l(ye),l(E),l(ve),l(P),l(_e),l(z),l(Je),l(Ce),l(S),l(Ze),l(ke),l(q)),l(d),b(h,e),b(g,e),b(M,e),b($,e),b(J,e),b(U,e),b(V,e),b(I,e),b(B,e),b(W,e),b(R,e),b(Y,e)}}}const ft='{"title":"프롬프트에 가중치 부여하기","local":"프롬프트에-가중치-부여하기","sections":[{"title":"Diffusers에서 프롬프트 가중치 부여하는 방법","local":"diffusers에서-프롬프트-가중치-부여하는-방법","sections":[],"depth":2}],"depth":1}';function rt(Ue){return tt(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class gt extends lt{constructor(d){super(),st(this,d,rt,mt,Oe,{})}}export{gt as component};
