import{s as Ke,o as el,n as ll}from"../chunks/scheduler.5c93273d.js";import{S as tl,i as sl,g as i,s as n,r as M,A as nl,h as p,f as t,c as a,j as te,u as U,x as d,k as qe,y as c,a as s,v as r,d as T,t as m,w as u}from"../chunks/index.e43dd92b.js";import{T as al}from"../chunks/Tip.1cbfe904.js";import{C as se}from"../chunks/CodeBlock.6896320e.js";import{H as Ve,E as il}from"../chunks/getInferenceSnippets.d410b42d.js";function pl(ae){let o,h='如果您不熟悉Modular Diffusers中状态的工作原理，请参考 <a href="./modular_diffusers_states">States</a> 指南。';return{c(){o=i("p"),o.innerHTML=h},l(J){o=p(J,"P",{"data-svelte-h":!0}),d(o)!=="svelte-7qic07"&&(o.innerHTML=h)},m(J,L){s(J,o,L)},p:ll,d(J){J&&t(o)}}}function cl(ae){let o,h,J,L,j,ie,R,Se='<code>ModularPipelineBlocks</code> 是构建 <code>ModularPipeline</code> 的基本块。它定义了管道中特定步骤应执行的组件、输入/输出和计算。一个 <code>ModularPipelineBlocks</code> 与其他块连接，使用 <a href="./modular_diffusers_states">状态</a>，以实现工作流的模块化构建。',pe,V,Ye="单独的 <code>ModularPipelineBlocks</code> 无法执行。它是管道中步骤应执行的操作的蓝图。要实际运行和执行管道，需要将 <code>ModularPipelineBlocks</code> 转换为 <code>ModularPipeline</code>。",ce,b,Ze="本指南将向您展示如何创建 <code>ModularPipelineBlocks</code>。",oe,g,de,$,Me,k,He="一个 <code>ModularPipelineBlocks</code> 需要 <code>inputs</code> 和 <code>intermediate_outputs</code>。",Ue,y,f,F,Oe="<code>inputs</code> 是由用户提供并从 <code>PipelineState</code> 中检索的值。这很有用，因为某些工作流会调整图像大小，但仍需要原始图像。 <code>PipelineState</code> 维护原始图像。",be,x,Ge="使用 <code>InputParam</code> 定义 <code>inputs</code>。",ge,I,ke,w,z,Xe="<code>intermediate_inputs</code> 通常由前一个块创建的值，但如果前面的块没有生成它们，也可以直接提供。与 <code>inputs</code> 不同，<code>intermediate_inputs</code> 可以被修改。",Ie,D,Ne="使用 <code>InputParam</code> 定义 <code>intermediate_inputs</code>。",Be,B,Qe,C,A,Pe="<code>intermediate_outputs</code> 是由块创建并添加到 <code>PipelineState</code> 的新值。<code>intermediate_outputs</code> 可作为后续块的 <code>intermediate_inputs</code> 使用，或作为运行管道的最终输出使用。",Ee,q,We="使用 <code>OutputParam</code> 定义 <code>intermediate_outputs</code>。",ve,Q,re,E,Le="中间输入和输出共享数据以连接块。它们可以在任何时候访问，允许你跟踪工作流的进度。",Te,v,me,S,Fe="一个块执行的计算在<code>__call__</code>方法中定义，它遵循特定的结构。",ue,Y,xe="<li>检索<code>BlockState</code>以获取<code>inputs</code>和<code>intermediate_inputs</code>的局部视图。</li> <li>在<code>inputs</code>和<code>intermediate_inputs</code>上实现计算逻辑。</li> <li>更新<code>PipelineState</code>以将局部<code>BlockState</code>的更改推送回全局<code>PipelineState</code>。</li> <li>返回对下一个块可用的组件和状态。</li>",Je,Z,ye,H,fe,O,ze="块需要的组件和管道级别的配置在<code>ComponentSpec</code>和<code>ConfigSpec</code>中指定。",we,G,De="<li><code>ComponentSpec</code>包含块使用的预期组件。你需要组件的<code>name</code>和理想情况下指定组件确切是什么的<code>type_hint</code>。</li> <li><code>ConfigSpec</code>包含控制所有块行为的管道级别设置。</li>",Ce,X,_e,N,Ae="当块被转换为管道时，组件作为<code>__call__</code>中的第一个参数对块可用。",$e,P,he,W,je,ne,Re;return j=new Ve({props:{title:"ModularPipelineBlocks",local:"modularpipelineblocks",headingTag:"h1"}}),g=new Ve({props:{title:"输入和输出",local:"输入和输出",headingTag:"h2"}}),$=new al({props:{warning:!1,$$slots:{default:[pl]},$$scope:{ctx:ae}}}),I=new se({props:{code:"ZnJvbSUyMGRpZmZ1c2Vycy5tb2R1bGFyX3BpcGVsaW5lcyUyMGltcG9ydCUyMElucHV0UGFyYW0lMEElMEF1c2VyX2lucHV0cyUyMCUzRCUyMCU1QiUwQSUyMCUyMCUyMCUyMElucHV0UGFyYW0obmFtZSUzRCUyMmltYWdlJTIyJTJDJTIwdHlwZV9oaW50JTNEJTIyUElMLkltYWdlJTIyJTJDJTIwZGVzY3JpcHRpb24lM0QlMjIlRTglQTYlODElRTUlQTQlODQlRTclOTAlODYlRTclOUElODQlRTUlOEUlOUYlRTUlQTclOEIlRTglQkUlOTMlRTUlODUlQTUlRTUlOUIlQkUlRTUlODMlOEYlMjIpJTBBJTVE",highlighted:`<span class="hljs-keyword">from</span> diffusers.modular_pipelines <span class="hljs-keyword">import</span> InputParam

user_inputs = [
    InputParam(name=<span class="hljs-string">&quot;image&quot;</span>, type_hint=<span class="hljs-string">&quot;PIL.Image&quot;</span>, description=<span class="hljs-string">&quot;要处理的原始输入图像&quot;</span>)
]`,wrap:!1}}),B=new se({props:{code:"dXNlcl9pbnRlcm1lZGlhdGVfaW5wdXRzJTIwJTNEJTIwJTVCJTBBJTIwJTIwJTIwJTIwSW5wdXRQYXJhbShuYW1lJTNEJTIycHJvY2Vzc2VkX2ltYWdlJTIyJTJDJTIwdHlwZV9oaW50JTNEJTIydG9yY2guVGVuc29yJTIyJTJDJTIwZGVzY3JpcHRpb24lM0QlMjJpbWFnZSUyMHRoYXQlMjBoYXMlMjBiZWVuJTIwcHJlcHJvY2Vzc2VkJTIwYW5kJTIwbm9ybWFsaXplZCUyMiklMkMlMEElNUQ=",highlighted:`user_intermediate_inputs = [
    InputParam(name=<span class="hljs-string">&quot;processed_image&quot;</span>, type_hint=<span class="hljs-string">&quot;torch.Tensor&quot;</span>, description=<span class="hljs-string">&quot;image that has been preprocessed and normalized&quot;</span>),
]`,wrap:!1}}),Q=new se({props:{code:"ZnJvbSUyMGRpZmZ1c2Vycy5tb2R1bGFyX3BpcGVsaW5lcyUyMGltcG9ydCUyME91dHB1dFBhcmFtJTBBJTBBJTIwJTIwJTIwJTIwdXNlcl9pbnRlcm1lZGlhdGVfb3V0cHV0cyUyMCUzRCUyMCU1QiUwQSUyMCUyMCUyMCUyME91dHB1dFBhcmFtKG5hbWUlM0QlMjJpbWFnZV9sYXRlbnRzJTIyJTJDJTIwZGVzY3JpcHRpb24lM0QlMjJsYXRlbnRzJTIwcmVwcmVzZW50aW5nJTIwdGhlJTIwaW1hZ2UlMjIpJTBBJTVE",highlighted:`<span class="hljs-keyword">from</span> diffusers.modular_pipelines <span class="hljs-keyword">import</span> OutputParam

    user_intermediate_outputs = [
    OutputParam(name=<span class="hljs-string">&quot;image_latents&quot;</span>, description=<span class="hljs-string">&quot;latents representing the image&quot;</span>)
]`,wrap:!1}}),v=new Ve({props:{title:"计算逻辑",local:"计算逻辑",headingTag:"h2"}}),Z=new se({props:{code:"ZGVmJTIwX19jYWxsX18oc2VsZiUyQyUyMGNvbXBvbmVudHMlMkMlMjBzdGF0ZSklM0ElMEElMjAlMjAlMjAlMjAlMjMlMjAlRTglOEUlQjclRTUlOEYlOTYlRTglQUYlQTUlRTUlOUQlOTclRTklOUMlODAlRTglQTYlODElRTclOUElODQlRTclOEElQjYlRTYlODAlODElRTUlOEYlOTglRTklODclOEYlRTclOUElODQlRTUlQjElODAlRTklODMlQTglRTglQTclODYlRTUlOUIlQkUlMEElMjAlMjAlMjAlMjBibG9ja19zdGF0ZSUyMCUzRCUyMHNlbGYuZ2V0X2Jsb2NrX3N0YXRlKHN0YXRlKSUwQSUwQSUyMCUyMCUyMCUyMCUyMyUyMCVFNCVCRCVBMCVFNyU5QSU4NCVFOCVBRSVBMSVFNyVBRSU5NyVFOSU4MCVCQiVFOCVCRSU5MSVFNSU5QyVBOCVFOCVCRiU5OSVFOSU4NyU4QyUwQSUyMCUyMCUyMCUyMCUyMyUyMGJsb2NrX3N0YXRlJUU1JThDJTg1JUU1JTkwJUFCJUU0JUJEJUEwJUU2JTg5JTgwJUU2JTlDJTg5JUU3JTlBJTg0aW5wdXRzJUU1JTkyJThDaW50ZXJtZWRpYXRlX2lucHV0cyUwQSUyMCUyMCUyMCUyMCUyMyUyMCVFNSU4MyU4RiVFOCVCRiU5OSVFNiVBMCVCNyVFOCVBRSVCRiVFOSU5NyVBRSVFNSVBRSU4MyVFNCVCQiVBQyUzQSUyMGJsb2NrX3N0YXRlLmltYWdlJTJDJTIwYmxvY2tfc3RhdGUucHJvY2Vzc2VkX2ltYWdlJTBBJTBBJTIwJTIwJTIwJTIwJTIzJTIwJUU3JTk0JUE4JUU0JUJEJUEwJUU2JTlCJUI0JUU2JTk2JUIwJUU3JTlBJTg0YmxvY2tfc3RhdGVzJUU2JTlCJUI0JUU2JTk2JUIwJUU3JUFFJUExJUU5JTgxJTkzJUU3JThBJUI2JUU2JTgwJTgxJTBBJTIwJTIwJTIwJTIwc2VsZi5zZXRfYmxvY2tfc3RhdGUoc3RhdGUlMkMlMjBibG9ja19zdGF0ZSklMEElMjAlMjAlMjAlMjByZXR1cm4lMjBjb21wb25lbnRzJTJDJTIwc3RhdGU=",highlighted:`<span class="hljs-keyword">def</span> <span class="hljs-title function_">__call__</span>(<span class="hljs-params">self, components, state</span>):
    <span class="hljs-comment"># 获取该块需要的状态变量的局部视图</span>
    block_state = self.get_block_state(state)

    <span class="hljs-comment"># 你的计算逻辑在这里</span>
    <span class="hljs-comment"># block_state包含你所有的inputs和intermediate_inputs</span>
    <span class="hljs-comment"># 像这样访问它们: block_state.image, block_state.processed_image</span>

    <span class="hljs-comment"># 用你更新的block_states更新管道状态</span>
    self.set_block_state(state, block_state)
    <span class="hljs-keyword">return</span> components, state`,wrap:!1}}),H=new Ve({props:{title:"组件和配置",local:"组件和配置",headingTag:"h3"}}),X=new se({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMENvbXBvbmVudFNwZWMlMkMlMjBDb25maWdTcGVjJTBBJTBBZXhwZWN0ZWRfY29tcG9uZW50cyUyMCUzRCUyMCU1QiUwQSUyMCUyMCUyMCUyMENvbXBvbmVudFNwZWMobmFtZSUzRCUyMnVuZXQlMjIlMkMlMjB0eXBlX2hpbnQlM0RVTmV0MkRDb25kaXRpb25Nb2RlbCklMkMlMEElMjAlMjAlMjAlMjBDb21wb25lbnRTcGVjKG5hbWUlM0QlMjJzY2hlZHVsZXIlMjIlMkMlMjB0eXBlX2hpbnQlM0RFdWxlckRpc2NyZXRlU2NoZWR1bGVyKSUwQSU1RCUwQSUwQWV4cGVjdGVkX2NvbmZpZyUyMCUzRCUyMCU1QiUwQSUyMCUyMCUyMCUyMENvbmZpZ1NwZWMoJTIyZm9yY2VfemVyb3NfZm9yX2VtcHR5X3Byb21wdCUyMiUyQyUyMFRydWUpJTBBJTVE",highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> ComponentSpec, ConfigSpec

expected_components = [
    ComponentSpec(name=<span class="hljs-string">&quot;unet&quot;</span>, type_hint=UNet2DConditionModel),
    ComponentSpec(name=<span class="hljs-string">&quot;scheduler&quot;</span>, type_hint=EulerDiscreteScheduler)
]

expected_config = [
    ConfigSpec(<span class="hljs-string">&quot;force_zeros_for_empty_prompt&quot;</span>, <span class="hljs-literal">True</span>)
]`,wrap:!1}}),P=new se({props:{code:"ZGVmJTIwX19jYWxsX18oc2VsZiUyQyUyMGNvbXBvbmVudHMlMkMlMjBzdGF0ZSklM0ElMEElMjAlMjAlMjAlMjAlMjMlMjAlRTQlQkQlQkYlRTclOTQlQTglRTclODIlQjklRTclQUMlQTYlRTUlOEYlQjclRTglQUUlQkYlRTklOTclQUUlRTclQkIlODQlRTQlQkIlQjYlMEElMjAlMjAlMjAlMjB1bmV0JTIwJTNEJTIwY29tcG9uZW50cy51bmV0JTBBJTIwJTIwJTIwJTIwdmFlJTIwJTNEJTIwY29tcG9uZW50cy52YWUlMEElMjAlMjAlMjAlMjBzY2hlZHVsZXIlMjAlM0QlMjBjb21wb25lbnRzLnNjaGVkdWxlcg==",highlighted:`<span class="hljs-keyword">def</span> <span class="hljs-title function_">__call__</span>(<span class="hljs-params">self, components, state</span>):
    <span class="hljs-comment"># 使用点符号访问组件</span>
    unet = components.unet
    vae = components.vae
    scheduler = components.scheduler`,wrap:!1}}),W=new il({props:{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/zh/modular_diffusers/pipeline_block.md"}}),{c(){o=i("meta"),h=n(),J=i("p"),L=n(),M(j.$$.fragment),ie=n(),R=i("p"),R.innerHTML=Se,pe=n(),V=i("p"),V.innerHTML=Ye,ce=n(),b=i("p"),b.innerHTML=Ze,oe=n(),M(g.$$.fragment),de=n(),M($.$$.fragment),Me=n(),k=i("p"),k.innerHTML=He,Ue=n(),y=i("ul"),f=i("li"),F=i("p"),F.innerHTML=Oe,be=n(),x=i("p"),x.innerHTML=Ge,ge=n(),M(I.$$.fragment),ke=n(),w=i("li"),z=i("p"),z.innerHTML=Xe,Ie=n(),D=i("p"),D.innerHTML=Ne,Be=n(),M(B.$$.fragment),Qe=n(),C=i("li"),A=i("p"),A.innerHTML=Pe,Ee=n(),q=i("p"),q.innerHTML=We,ve=n(),M(Q.$$.fragment),re=n(),E=i("p"),E.textContent=Le,Te=n(),M(v.$$.fragment),me=n(),S=i("p"),S.innerHTML=Fe,ue=n(),Y=i("ol"),Y.innerHTML=xe,Je=n(),M(Z.$$.fragment),ye=n(),M(H.$$.fragment),fe=n(),O=i("p"),O.innerHTML=ze,we=n(),G=i("ul"),G.innerHTML=De,Ce=n(),M(X.$$.fragment),_e=n(),N=i("p"),N.innerHTML=Ae,$e=n(),M(P.$$.fragment),he=n(),M(W.$$.fragment),je=n(),ne=i("p"),this.h()},l(e){const l=nl("svelte-u9bgzb",document.head);o=p(l,"META",{name:!0,content:!0}),l.forEach(t),h=a(e),J=p(e,"P",{}),te(J).forEach(t),L=a(e),U(j.$$.fragment,e),ie=a(e),R=p(e,"P",{"data-svelte-h":!0}),d(R)!=="svelte-ia629y"&&(R.innerHTML=Se),pe=a(e),V=p(e,"P",{"data-svelte-h":!0}),d(V)!=="svelte-1iy83e1"&&(V.innerHTML=Ye),ce=a(e),b=p(e,"P",{"data-svelte-h":!0}),d(b)!=="svelte-1iqsqut"&&(b.innerHTML=Ze),oe=a(e),U(g.$$.fragment,e),de=a(e),U($.$$.fragment,e),Me=a(e),k=p(e,"P",{"data-svelte-h":!0}),d(k)!=="svelte-4t39eh"&&(k.innerHTML=He),Ue=a(e),y=p(e,"UL",{});var _=te(y);f=p(_,"LI",{});var K=te(f);F=p(K,"P",{"data-svelte-h":!0}),d(F)!=="svelte-14ix9s6"&&(F.innerHTML=Oe),be=a(K),x=p(K,"P",{"data-svelte-h":!0}),d(x)!=="svelte-kp439e"&&(x.innerHTML=Ge),ge=a(K),U(I.$$.fragment,K),K.forEach(t),ke=a(_),w=p(_,"LI",{});var ee=te(w);z=p(ee,"P",{"data-svelte-h":!0}),d(z)!=="svelte-15syp6"&&(z.innerHTML=Xe),Ie=a(ee),D=p(ee,"P",{"data-svelte-h":!0}),d(D)!=="svelte-ud88be"&&(D.innerHTML=Ne),Be=a(ee),U(B.$$.fragment,ee),ee.forEach(t),Qe=a(_),C=p(_,"LI",{});var le=te(C);A=p(le,"P",{"data-svelte-h":!0}),d(A)!=="svelte-oj0y2l"&&(A.innerHTML=Pe),Ee=a(le),q=p(le,"P",{"data-svelte-h":!0}),d(q)!=="svelte-1rxoqz2"&&(q.innerHTML=We),ve=a(le),U(Q.$$.fragment,le),le.forEach(t),_.forEach(t),re=a(e),E=p(e,"P",{"data-svelte-h":!0}),d(E)!=="svelte-1yjw1jp"&&(E.textContent=Le),Te=a(e),U(v.$$.fragment,e),me=a(e),S=p(e,"P",{"data-svelte-h":!0}),d(S)!=="svelte-11d6loh"&&(S.innerHTML=Fe),ue=a(e),Y=p(e,"OL",{"data-svelte-h":!0}),d(Y)!=="svelte-1rg0xza"&&(Y.innerHTML=xe),Je=a(e),U(Z.$$.fragment,e),ye=a(e),U(H.$$.fragment,e),fe=a(e),O=p(e,"P",{"data-svelte-h":!0}),d(O)!=="svelte-s5fthu"&&(O.innerHTML=ze),we=a(e),G=p(e,"UL",{"data-svelte-h":!0}),d(G)!=="svelte-1hm5d38"&&(G.innerHTML=De),Ce=a(e),U(X.$$.fragment,e),_e=a(e),N=p(e,"P",{"data-svelte-h":!0}),d(N)!=="svelte-cww9le"&&(N.innerHTML=Ae),$e=a(e),U(P.$$.fragment,e),he=a(e),U(W.$$.fragment,e),je=a(e),ne=p(e,"P",{}),te(ne).forEach(t),this.h()},h(){qe(o,"name","hf:doc:metadata"),qe(o,"content",ol)},m(e,l){c(document.head,o),s(e,h,l),s(e,J,l),s(e,L,l),r(j,e,l),s(e,ie,l),s(e,R,l),s(e,pe,l),s(e,V,l),s(e,ce,l),s(e,b,l),s(e,oe,l),r(g,e,l),s(e,de,l),r($,e,l),s(e,Me,l),s(e,k,l),s(e,Ue,l),s(e,y,l),c(y,f),c(f,F),c(f,be),c(f,x),c(f,ge),r(I,f,null),c(y,ke),c(y,w),c(w,z),c(w,Ie),c(w,D),c(w,Be),r(B,w,null),c(y,Qe),c(y,C),c(C,A),c(C,Ee),c(C,q),c(C,ve),r(Q,C,null),s(e,re,l),s(e,E,l),s(e,Te,l),r(v,e,l),s(e,me,l),s(e,S,l),s(e,ue,l),s(e,Y,l),s(e,Je,l),r(Z,e,l),s(e,ye,l),r(H,e,l),s(e,fe,l),s(e,O,l),s(e,we,l),s(e,G,l),s(e,Ce,l),r(X,e,l),s(e,_e,l),s(e,N,l),s(e,$e,l),r(P,e,l),s(e,he,l),r(W,e,l),s(e,je,l),s(e,ne,l),Re=!0},p(e,[l]){const _={};l&2&&(_.$$scope={dirty:l,ctx:e}),$.$set(_)},i(e){Re||(T(j.$$.fragment,e),T(g.$$.fragment,e),T($.$$.fragment,e),T(I.$$.fragment,e),T(B.$$.fragment,e),T(Q.$$.fragment,e),T(v.$$.fragment,e),T(Z.$$.fragment,e),T(H.$$.fragment,e),T(X.$$.fragment,e),T(P.$$.fragment,e),T(W.$$.fragment,e),Re=!0)},o(e){m(j.$$.fragment,e),m(g.$$.fragment,e),m($.$$.fragment,e),m(I.$$.fragment,e),m(B.$$.fragment,e),m(Q.$$.fragment,e),m(v.$$.fragment,e),m(Z.$$.fragment,e),m(H.$$.fragment,e),m(X.$$.fragment,e),m(P.$$.fragment,e),m(W.$$.fragment,e),Re=!1},d(e){e&&(t(h),t(J),t(L),t(ie),t(R),t(pe),t(V),t(ce),t(b),t(oe),t(de),t(Me),t(k),t(Ue),t(y),t(re),t(E),t(Te),t(me),t(S),t(ue),t(Y),t(Je),t(ye),t(fe),t(O),t(we),t(G),t(Ce),t(_e),t(N),t($e),t(he),t(je),t(ne)),t(o),u(j,e),u(g,e),u($,e),u(I),u(B),u(Q),u(v,e),u(Z,e),u(H,e),u(X,e),u(P,e),u(W,e)}}}const ol='{"title":"ModularPipelineBlocks","local":"modularpipelineblocks","sections":[{"title":"输入和输出","local":"输入和输出","sections":[],"depth":2},{"title":"计算逻辑","local":"计算逻辑","sections":[{"title":"组件和配置","local":"组件和配置","sections":[],"depth":3}],"depth":2}],"depth":1}';function dl(ae){return el(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class ul extends tl{constructor(o){super(),sl(this,o,dl,cl,Ke,{})}}export{ul as component};
