import{s as qe,n as Qe,o as Ae}from"../chunks/scheduler.6e0d5ff7.js";import{S as Ke,i as Oe,g as p,s as n,r as m,E as et,h as a,f as l,c as i,j as Se,u as f,x as o,k as Fe,y as tt,a as s,v as r,d as u,t as c,w as b}from"../chunks/index.d7c1b260.js";import{C as Y}from"../chunks/CodeBlock.09a08494.js";import{D as lt}from"../chunks/DocNotebookDropdown.0647ce65.js";import{H as De}from"../chunks/Heading.30a009b0.js";function st(Ce){let d,D,S,q,h,Q,M,A,g,Ze=`텍스트 가이드 기반의 diffusion 모델은 주어진 텍스트 프롬프트를 기반으로 이미지를 생성합니다.
텍스트 프롬프트에는 모델이 생성해야 하는 여러 개념이 포함될 수 있으며 프롬프트의 특정 부분에 가중치를 부여하는 것이 바람직한 경우가 많습니다.`,K,w,ke=`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를 보세요 ).`,O,T,ee,y,Ue=`우리는 <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”/축척된 텍스트 임베딩을 파이프라인에 바로 전달할 수 있게 합니다.`,te,v,Ve=`<a href="https://github.com/damian0815/compel" rel="nofollow">Compel 라이브러리</a>는 프롬프트의 일부를 강조하거나 강조하지 않을 수 있는 쉬운 방법을 제공합니다.
임베딩을 직접 준비하는 것 대신 이 방법을 사용하는 것을 강력히 추천합니다.`,le,_,Ge=`간단한 예제를 살펴보겠습니다.
다음과 같이 <code>&quot;공을 갖고 노는 붉은색 고양이&quot;</code> 이미지를 생성하고 싶습니다:`,se,$,ne,J,He="생성된 이미지:",ie,C,xe='<img src="https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/compel/forest_0.png" alt="img"/>',pe,Z,Ie="사진에서 알 수 있듯이, “공”은 이미지에 없습니다. 이 부분을 강조해 볼까요!",ae,k,je="먼저 <code>compel</code> 라이브러리를 설치해야합니다:",oe,U,me,V,Be="그런 다음에는 <code>Compel</code> 오브젝트를 생성합니다:",fe,G,re,H,Xe="이제 <code>&quot;++&quot;</code> 를 사용해서 “공” 을 강조해 봅시다:",ue,x,ce,I,We="그리고 이 프롬프트를 파이프라인에 바로 전달하지 않고, <code>compel_proc</code> 를 사용하여 처리해야합니다:",be,j,de,B,Ne="파이프라인에 <code>prompt_embeds</code> 를 바로 전달할 수 있습니다:",he,X,Me,W,Le="이제 “공”이 있는 그림을 출력할 수 있습니다!",ge,N,Pe='<img src="https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/compel/forest_1.png" alt="img"/>',we,L,Ee="마찬가지로 <code>--</code> 접미사를 단어에 사용하여 문장의 일부를 강조하지 않을 수 있습니다. 한번 시도해 보세요!",Te,P,ze=`즐겨찾는 파이프라인에 <code>prompt_embeds</code> 입력이 없는 경우 issue를 새로 만들어주세요.
Diffusers 팀은 최대한 대응하려고 노력합니다.`,ye,E,Re=`Compel 1.1.6 는 textual inversions을 사용하여 단순화하는 유티릴티 클래스를 추가합니다.
<code>DiffusersTextualInversionManager</code>를 인스턴스화 한 후 이를 Compel init에 전달합니다:`,ve,z,_e,R,Ye='더 많은 정보를 얻고 싶다면 <a href="https://github.com/damian0815/compel" rel="nofollow">compel</a> 라이브러리 문서를 참고하세요.',$e,F,Je;return h=new De({props:{title:"프롬프트에 가중치 부여하기",local:"프롬프트에-가중치-부여하기",headingTag:"h1"}}),M=new lt({props:{classNames:"absolute z-10 right-0 top-0",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"}]}}),T=new De({props:{title:"Diffusers에서 프롬프트 가중치 부여하는 방법",local:"diffusers에서-프롬프트-가중치-부여하는-방법",headingTag:"h2"}}),$=new Y({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 Y({props:{code:"cGlwJTIwaW5zdGFsbCUyMGNvbXBlbA==",highlighted:'pip <span class="hljs-keyword">install</span> compel',wrap:!1}}),G=new Y({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}}),x=new Y({props:{code:"cHJvbXB0JTIwJTNEJTIwJTIyYSUyMHJlZCUyMGNhdCUyMHBsYXlpbmclMjB3aXRoJTIwYSUyMGJhbGwlMkIlMkIlMjI=",highlighted:'prompt = <span class="hljs-string">&quot;a red cat playing with a ball++&quot;</span>',wrap:!1}}),j=new Y({props:{code:"cHJvbXB0X2VtYmVkcyUyMCUzRCUyMGNvbXBlbF9wcm9jKHByb21wdCk=",highlighted:"prompt_embeds = compel_proc(prompt)",wrap:!1}}),X=new Y({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}}),z=new Y({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}}),{c(){d=p("meta"),D=n(),S=p("p"),q=n(),m(h.$$.fragment),Q=n(),m(M.$$.fragment),A=n(),g=p("p"),g.textContent=Ze,K=n(),w=p("p"),w.innerHTML=ke,O=n(),m(T.$$.fragment),ee=n(),y=p("p"),y.innerHTML=Ue,te=n(),v=p("p"),v.innerHTML=Ve,le=n(),_=p("p"),_.innerHTML=Ge,se=n(),m($.$$.fragment),ne=n(),J=p("p"),J.textContent=He,ie=n(),C=p("p"),C.innerHTML=xe,pe=n(),Z=p("p"),Z.textContent=Ie,ae=n(),k=p("p"),k.innerHTML=je,oe=n(),m(U.$$.fragment),me=n(),V=p("p"),V.innerHTML=Be,fe=n(),m(G.$$.fragment),re=n(),H=p("p"),H.innerHTML=Xe,ue=n(),m(x.$$.fragment),ce=n(),I=p("p"),I.innerHTML=We,be=n(),m(j.$$.fragment),de=n(),B=p("p"),B.innerHTML=Ne,he=n(),m(X.$$.fragment),Me=n(),W=p("p"),W.textContent=Le,ge=n(),N=p("p"),N.innerHTML=Pe,we=n(),L=p("p"),L.innerHTML=Ee,Te=n(),P=p("p"),P.innerHTML=ze,ye=n(),E=p("p"),E.innerHTML=Re,ve=n(),m(z.$$.fragment),_e=n(),R=p("p"),R.innerHTML=Ye,$e=n(),F=p("p"),this.h()},l(e){const t=et("svelte-u9bgzb",document.head);d=a(t,"META",{name:!0,content:!0}),t.forEach(l),D=i(e),S=a(e,"P",{}),Se(S).forEach(l),q=i(e),f(h.$$.fragment,e),Q=i(e),f(M.$$.fragment,e),A=i(e),g=a(e,"P",{"data-svelte-h":!0}),o(g)!=="svelte-6zgx2k"&&(g.textContent=Ze),K=i(e),w=a(e,"P",{"data-svelte-h":!0}),o(w)!=="svelte-jymdy2"&&(w.innerHTML=ke),O=i(e),f(T.$$.fragment,e),ee=i(e),y=a(e,"P",{"data-svelte-h":!0}),o(y)!=="svelte-1tfiuem"&&(y.innerHTML=Ue),te=i(e),v=a(e,"P",{"data-svelte-h":!0}),o(v)!=="svelte-3a9pj9"&&(v.innerHTML=Ve),le=i(e),_=a(e,"P",{"data-svelte-h":!0}),o(_)!=="svelte-sndxnq"&&(_.innerHTML=Ge),se=i(e),f($.$$.fragment,e),ne=i(e),J=a(e,"P",{"data-svelte-h":!0}),o(J)!=="svelte-1kk09o0"&&(J.textContent=He),ie=i(e),C=a(e,"P",{"data-svelte-h":!0}),o(C)!=="svelte-lhtk1n"&&(C.innerHTML=xe),pe=i(e),Z=a(e,"P",{"data-svelte-h":!0}),o(Z)!=="svelte-1j2une0"&&(Z.textContent=Ie),ae=i(e),k=a(e,"P",{"data-svelte-h":!0}),o(k)!=="svelte-1uy3q6o"&&(k.innerHTML=je),oe=i(e),f(U.$$.fragment,e),me=i(e),V=a(e,"P",{"data-svelte-h":!0}),o(V)!=="svelte-1181b2z"&&(V.innerHTML=Be),fe=i(e),f(G.$$.fragment,e),re=i(e),H=a(e,"P",{"data-svelte-h":!0}),o(H)!=="svelte-1ilrue"&&(H.innerHTML=Xe),ue=i(e),f(x.$$.fragment,e),ce=i(e),I=a(e,"P",{"data-svelte-h":!0}),o(I)!=="svelte-1fd9ba2"&&(I.innerHTML=We),be=i(e),f(j.$$.fragment,e),de=i(e),B=a(e,"P",{"data-svelte-h":!0}),o(B)!=="svelte-s5my9t"&&(B.innerHTML=Ne),he=i(e),f(X.$$.fragment,e),Me=i(e),W=a(e,"P",{"data-svelte-h":!0}),o(W)!=="svelte-1szos4z"&&(W.textContent=Le),ge=i(e),N=a(e,"P",{"data-svelte-h":!0}),o(N)!=="svelte-rm5ydw"&&(N.innerHTML=Pe),we=i(e),L=a(e,"P",{"data-svelte-h":!0}),o(L)!=="svelte-1cz1utb"&&(L.innerHTML=Ee),Te=i(e),P=a(e,"P",{"data-svelte-h":!0}),o(P)!=="svelte-1837j6q"&&(P.innerHTML=ze),ye=i(e),E=a(e,"P",{"data-svelte-h":!0}),o(E)!=="svelte-1te8sqt"&&(E.innerHTML=Re),ve=i(e),f(z.$$.fragment,e),_e=i(e),R=a(e,"P",{"data-svelte-h":!0}),o(R)!=="svelte-1n4pw6m"&&(R.innerHTML=Ye),$e=i(e),F=a(e,"P",{}),Se(F).forEach(l),this.h()},h(){Fe(d,"name","hf:doc:metadata"),Fe(d,"content",nt)},m(e,t){tt(document.head,d),s(e,D,t),s(e,S,t),s(e,q,t),r(h,e,t),s(e,Q,t),r(M,e,t),s(e,A,t),s(e,g,t),s(e,K,t),s(e,w,t),s(e,O,t),r(T,e,t),s(e,ee,t),s(e,y,t),s(e,te,t),s(e,v,t),s(e,le,t),s(e,_,t),s(e,se,t),r($,e,t),s(e,ne,t),s(e,J,t),s(e,ie,t),s(e,C,t),s(e,pe,t),s(e,Z,t),s(e,ae,t),s(e,k,t),s(e,oe,t),r(U,e,t),s(e,me,t),s(e,V,t),s(e,fe,t),r(G,e,t),s(e,re,t),s(e,H,t),s(e,ue,t),r(x,e,t),s(e,ce,t),s(e,I,t),s(e,be,t),r(j,e,t),s(e,de,t),s(e,B,t),s(e,he,t),r(X,e,t),s(e,Me,t),s(e,W,t),s(e,ge,t),s(e,N,t),s(e,we,t),s(e,L,t),s(e,Te,t),s(e,P,t),s(e,ye,t),s(e,E,t),s(e,ve,t),r(z,e,t),s(e,_e,t),s(e,R,t),s(e,$e,t),s(e,F,t),Je=!0},p:Qe,i(e){Je||(u(h.$$.fragment,e),u(M.$$.fragment,e),u(T.$$.fragment,e),u($.$$.fragment,e),u(U.$$.fragment,e),u(G.$$.fragment,e),u(x.$$.fragment,e),u(j.$$.fragment,e),u(X.$$.fragment,e),u(z.$$.fragment,e),Je=!0)},o(e){c(h.$$.fragment,e),c(M.$$.fragment,e),c(T.$$.fragment,e),c($.$$.fragment,e),c(U.$$.fragment,e),c(G.$$.fragment,e),c(x.$$.fragment,e),c(j.$$.fragment,e),c(X.$$.fragment,e),c(z.$$.fragment,e),Je=!1},d(e){e&&(l(D),l(S),l(q),l(Q),l(A),l(g),l(K),l(w),l(O),l(ee),l(y),l(te),l(v),l(le),l(_),l(se),l(ne),l(J),l(ie),l(C),l(pe),l(Z),l(ae),l(k),l(oe),l(me),l(V),l(fe),l(re),l(H),l(ue),l(ce),l(I),l(be),l(de),l(B),l(he),l(Me),l(W),l(ge),l(N),l(we),l(L),l(Te),l(P),l(ye),l(E),l(ve),l(_e),l(R),l($e),l(F)),l(d),b(h,e),b(M,e),b(T,e),b($,e),b(U,e),b(G,e),b(x,e),b(j,e),b(X,e),b(z,e)}}}const nt='{"title":"프롬프트에 가중치 부여하기","local":"프롬프트에-가중치-부여하기","sections":[{"title":"Diffusers에서 프롬프트 가중치 부여하는 방법","local":"diffusers에서-프롬프트-가중치-부여하는-방법","sections":[],"depth":2}],"depth":1}';function it(Ce){return Ae(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class rt extends Ke{constructor(d){super(),Oe(this,d,it,st,qe,{})}}export{rt as component};
