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