import{s as el,n as ll,o as tl}from"../chunks/scheduler.5c93273d.js";import{S as sl,i as nl,g as i,s as n,r as d,A as al,h as p,f as t,c as a,j as K,u as M,x as o,k as ve,y as c,a as s,v as U,d as T,t as r,w as m}from"../chunks/index.e43dd92b.js";import{C as ee}from"../chunks/CodeBlock.6896320e.js";import{H as Ve,E as il}from"../chunks/getInferenceSnippets.7a494bf3.js";function pl(Se){let J,se,le,ne,h,ae,j,Oe='<code>ModularPipelineBlocks</code> 是构建 <code>ModularPipeline</code> 的基本块。它定义了管道中特定步骤应执行的组件、输入/输出和计算。一个 <code>ModularPipelineBlocks</code> 与其他块连接，使用 <a href="./modular_diffusers_states">状态</a>，以实现工作流的模块化构建。',ie,_,Ye="单独的 <code>ModularPipelineBlocks</code> 无法执行。它是管道中步骤应执行的操作的蓝图。要实际运行和执行管道，需要将 <code>ModularPipelineBlocks</code> 转换为 <code>ModularPipeline</code>。",pe,R,Ze="本指南将向您展示如何创建 <code>ModularPipelineBlocks</code>。",ce,V,oe,C,He='<p>如果您不熟悉Modular Diffusers中状态的工作原理，请参考 <a href="./modular_diffusers_states">States</a> 指南。</p>',de,$,Ge="一个 <code>ModularPipelineBlocks</code> 需要 <code>inputs</code> 和 <code>intermediate_outputs</code>。",Me,u,y,N,Xe="<code>inputs</code> 是由用户提供并从 <code>PipelineState</code> 中检索的值。这很有用，因为某些工作流会调整图像大小，但仍需要原始图像。 <code>PipelineState</code> 维护原始图像。",$e,L,Ne="使用 <code>InputParam</code> 定义 <code>inputs</code>。",be,b,ke,f,P,Le="<code>intermediate_inputs</code> 通常由前一个块创建的值，但如果前面的块没有生成它们，也可以直接提供。与 <code>inputs</code> 不同，<code>intermediate_inputs</code> 可以被修改。",Ie,W,Pe="使用 <code>InputParam</code> 定义 <code>intermediate_inputs</code>。",ge,k,Be,w,F,We="<code>intermediate_outputs</code> 是由块创建并添加到 <code>PipelineState</code> 的新值。<code>intermediate_outputs</code> 可作为后续块的 <code>intermediate_inputs</code> 使用，或作为运行管道的最终输出使用。",Qe,x,Fe="使用 <code>OutputParam</code> 定义 <code>intermediate_outputs</code>。",Ee,I,Ue,g,xe="中间输入和输出共享数据以连接块。它们可以在任何时候访问，允许你跟踪工作流的进度。",Te,B,re,Q,ze="一个块执行的计算在<code>__call__</code>方法中定义，它遵循特定的结构。",me,E,De="<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>",ue,v,Je,S,ye,O,Ae="块需要的组件和管道级别的配置在<code>ComponentSpec</code>和<code>ConfigSpec</code>中指定。",fe,Y,qe="<li><code>ComponentSpec</code>包含块使用的预期组件。你需要组件的<code>name</code>和理想情况下指定组件确切是什么的<code>type_hint</code>。</li> <li><code>ConfigSpec</code>包含控制所有块行为的管道级别设置。</li>",we,Z,Ce,H,Ke="当块被转换为管道时，组件作为<code>__call__</code>中的第一个参数对块可用。",he,G,je,X,_e,te,Re;return h=new Ve({props:{title:"ModularPipelineBlocks",local:"modularpipelineblocks",headingTag:"h1"}}),V=new Ve({props:{title:"输入和输出",local:"输入和输出",headingTag:"h2"}}),b=new ee({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}}),k=new ee({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}}),I=new ee({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}}),B=new Ve({props:{title:"计算逻辑",local:"计算逻辑",headingTag:"h2"}}),v=new ee({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}}),S=new Ve({props:{title:"组件和配置",local:"组件和配置",headingTag:"h3"}}),Z=new ee({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}}),G=new ee({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}}),X=new il({props:{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/zh/modular_diffusers/pipeline_block.md"}}),{c(){J=i("meta"),se=n(),le=i("p"),ne=n(),d(h.$$.fragment),ae=n(),j=i("p"),j.innerHTML=Oe,ie=n(),_=i("p"),_.innerHTML=Ye,pe=n(),R=i("p"),R.innerHTML=Ze,ce=n(),d(V.$$.fragment),oe=n(),C=i("blockquote"),C.innerHTML=He,de=n(),$=i("p"),$.innerHTML=Ge,Me=n(),u=i("ul"),y=i("li"),N=i("p"),N.innerHTML=Xe,$e=n(),L=i("p"),L.innerHTML=Ne,be=n(),d(b.$$.fragment),ke=n(),f=i("li"),P=i("p"),P.innerHTML=Le,Ie=n(),W=i("p"),W.innerHTML=Pe,ge=n(),d(k.$$.fragment),Be=n(),w=i("li"),F=i("p"),F.innerHTML=We,Qe=n(),x=i("p"),x.innerHTML=Fe,Ee=n(),d(I.$$.fragment),Ue=n(),g=i("p"),g.textContent=xe,Te=n(),d(B.$$.fragment),re=n(),Q=i("p"),Q.innerHTML=ze,me=n(),E=i("ol"),E.innerHTML=De,ue=n(),d(v.$$.fragment),Je=n(),d(S.$$.fragment),ye=n(),O=i("p"),O.innerHTML=Ae,fe=n(),Y=i("ul"),Y.innerHTML=qe,we=n(),d(Z.$$.fragment),Ce=n(),H=i("p"),H.innerHTML=Ke,he=n(),d(G.$$.fragment),je=n(),d(X.$$.fragment),_e=n(),te=i("p"),this.h()},l(e){const l=al("svelte-u9bgzb",document.head);J=p(l,"META",{name:!0,content:!0}),l.forEach(t),se=a(e),le=p(e,"P",{}),K(le).forEach(t),ne=a(e),M(h.$$.fragment,e),ae=a(e),j=p(e,"P",{"data-svelte-h":!0}),o(j)!=="svelte-ia629y"&&(j.innerHTML=Oe),ie=a(e),_=p(e,"P",{"data-svelte-h":!0}),o(_)!=="svelte-1iy83e1"&&(_.innerHTML=Ye),pe=a(e),R=p(e,"P",{"data-svelte-h":!0}),o(R)!=="svelte-1iqsqut"&&(R.innerHTML=Ze),ce=a(e),M(V.$$.fragment,e),oe=a(e),C=p(e,"BLOCKQUOTE",{class:!0,"data-svelte-h":!0}),o(C)!=="svelte-147vo9k"&&(C.innerHTML=He),de=a(e),$=p(e,"P",{"data-svelte-h":!0}),o($)!=="svelte-4t39eh"&&($.innerHTML=Ge),Me=a(e),u=p(e,"UL",{});var z=K(u);y=p(z,"LI",{});var D=K(y);N=p(D,"P",{"data-svelte-h":!0}),o(N)!=="svelte-14ix9s6"&&(N.innerHTML=Xe),$e=a(D),L=p(D,"P",{"data-svelte-h":!0}),o(L)!=="svelte-kp439e"&&(L.innerHTML=Ne),be=a(D),M(b.$$.fragment,D),D.forEach(t),ke=a(z),f=p(z,"LI",{});var A=K(f);P=p(A,"P",{"data-svelte-h":!0}),o(P)!=="svelte-15syp6"&&(P.innerHTML=Le),Ie=a(A),W=p(A,"P",{"data-svelte-h":!0}),o(W)!=="svelte-ud88be"&&(W.innerHTML=Pe),ge=a(A),M(k.$$.fragment,A),A.forEach(t),Be=a(z),w=p(z,"LI",{});var q=K(w);F=p(q,"P",{"data-svelte-h":!0}),o(F)!=="svelte-oj0y2l"&&(F.innerHTML=We),Qe=a(q),x=p(q,"P",{"data-svelte-h":!0}),o(x)!=="svelte-1rxoqz2"&&(x.innerHTML=Fe),Ee=a(q),M(I.$$.fragment,q),q.forEach(t),z.forEach(t),Ue=a(e),g=p(e,"P",{"data-svelte-h":!0}),o(g)!=="svelte-1yjw1jp"&&(g.textContent=xe),Te=a(e),M(B.$$.fragment,e),re=a(e),Q=p(e,"P",{"data-svelte-h":!0}),o(Q)!=="svelte-11d6loh"&&(Q.innerHTML=ze),me=a(e),E=p(e,"OL",{"data-svelte-h":!0}),o(E)!=="svelte-1rg0xza"&&(E.innerHTML=De),ue=a(e),M(v.$$.fragment,e),Je=a(e),M(S.$$.fragment,e),ye=a(e),O=p(e,"P",{"data-svelte-h":!0}),o(O)!=="svelte-s5fthu"&&(O.innerHTML=Ae),fe=a(e),Y=p(e,"UL",{"data-svelte-h":!0}),o(Y)!=="svelte-1hm5d38"&&(Y.innerHTML=qe),we=a(e),M(Z.$$.fragment,e),Ce=a(e),H=p(e,"P",{"data-svelte-h":!0}),o(H)!=="svelte-cww9le"&&(H.innerHTML=Ke),he=a(e),M(G.$$.fragment,e),je=a(e),M(X.$$.fragment,e),_e=a(e),te=p(e,"P",{}),K(te).forEach(t),this.h()},h(){ve(J,"name","hf:doc:metadata"),ve(J,"content",cl),ve(C,"class","tip")},m(e,l){c(document.head,J),s(e,se,l),s(e,le,l),s(e,ne,l),U(h,e,l),s(e,ae,l),s(e,j,l),s(e,ie,l),s(e,_,l),s(e,pe,l),s(e,R,l),s(e,ce,l),U(V,e,l),s(e,oe,l),s(e,C,l),s(e,de,l),s(e,$,l),s(e,Me,l),s(e,u,l),c(u,y),c(y,N),c(y,$e),c(y,L),c(y,be),U(b,y,null),c(u,ke),c(u,f),c(f,P),c(f,Ie),c(f,W),c(f,ge),U(k,f,null),c(u,Be),c(u,w),c(w,F),c(w,Qe),c(w,x),c(w,Ee),U(I,w,null),s(e,Ue,l),s(e,g,l),s(e,Te,l),U(B,e,l),s(e,re,l),s(e,Q,l),s(e,me,l),s(e,E,l),s(e,ue,l),U(v,e,l),s(e,Je,l),U(S,e,l),s(e,ye,l),s(e,O,l),s(e,fe,l),s(e,Y,l),s(e,we,l),U(Z,e,l),s(e,Ce,l),s(e,H,l),s(e,he,l),U(G,e,l),s(e,je,l),U(X,e,l),s(e,_e,l),s(e,te,l),Re=!0},p:ll,i(e){Re||(T(h.$$.fragment,e),T(V.$$.fragment,e),T(b.$$.fragment,e),T(k.$$.fragment,e),T(I.$$.fragment,e),T(B.$$.fragment,e),T(v.$$.fragment,e),T(S.$$.fragment,e),T(Z.$$.fragment,e),T(G.$$.fragment,e),T(X.$$.fragment,e),Re=!0)},o(e){r(h.$$.fragment,e),r(V.$$.fragment,e),r(b.$$.fragment,e),r(k.$$.fragment,e),r(I.$$.fragment,e),r(B.$$.fragment,e),r(v.$$.fragment,e),r(S.$$.fragment,e),r(Z.$$.fragment,e),r(G.$$.fragment,e),r(X.$$.fragment,e),Re=!1},d(e){e&&(t(se),t(le),t(ne),t(ae),t(j),t(ie),t(_),t(pe),t(R),t(ce),t(oe),t(C),t(de),t($),t(Me),t(u),t(Ue),t(g),t(Te),t(re),t(Q),t(me),t(E),t(ue),t(Je),t(ye),t(O),t(fe),t(Y),t(we),t(Ce),t(H),t(he),t(je),t(_e),t(te)),t(J),m(h,e),m(V,e),m(b),m(k),m(I),m(B,e),m(v,e),m(S,e),m(Z,e),m(G,e),m(X,e)}}}const cl='{"title":"ModularPipelineBlocks","local":"modularpipelineblocks","sections":[{"title":"输入和输出","local":"输入和输出","sections":[],"depth":2},{"title":"计算逻辑","local":"计算逻辑","sections":[{"title":"组件和配置","local":"组件和配置","sections":[],"depth":3}],"depth":2}],"depth":1}';function ol(Se){return tl(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class rl extends sl{constructor(J){super(),nl(this,J,ol,pl,el,{})}}export{rl as component};
