import{s as Qt,o as Gt,n as vt}from"../chunks/scheduler.e4ff9b64.js";import{S as Ft,i as Xt,e as c,s,c as d,h as It,a as m,d as l,b as p,f as kt,g as M,j as f,k as it,l as Yt,m as n,n as U,t as u,o as r,p as y}from"../chunks/index.09f1bca0.js";import{C as St,H as N,E as qt}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.2e1a29f5.js";import{C}from"../chunks/CodeBlock.f899176c.js";import{H as Et,a as xt}from"../chunks/HfOption.44827c7f.js";function Ht(V){let o,J;return o=new C({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyME1vZHVsYXJQaXBlbGluZSUyQyUyMENvbXBvbmVudHNNYW5hZ2VyJTBBJTBBY29tcCUyMCUzRCUyMENvbXBvbmVudHNNYW5hZ2VyKCklMEFwaXBlJTIwJTNEJTIwTW9kdWxhclBpcGVsaW5lLmZyb21fcHJldHJhaW5lZCglMjJZaVlpWHUlMkZtb2R1bGFyLWRlbW8tYXV0byUyMiUyQyUyMGNvbXBvbmVudHNfbWFuYWdlciUzRGNvbXAlMkMlMjBjb2xsZWN0aW9uJTNEJTIydGVzdDElMjIp",highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> ModularPipeline, ComponentsManager

comp = ComponentsManager()
pipe = ModularPipeline.from_pretrained(<span class="hljs-string">&quot;YiYiXu/modular-demo-auto&quot;</span>, components_manager=comp, collection=<span class="hljs-string">&quot;test1&quot;</span>)`,wrap:!1}}),{c(){d(o.$$.fragment)},l(a){M(o.$$.fragment,a)},m(a,b){U(o,a,b),J=!0},p:vt,i(a){J||(u(o.$$.fragment,a),J=!0)},o(a){r(o.$$.fragment,a),J=!1},d(a){y(o,a)}}}function zt(V){let o,J;return o=new C({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMENvbXBvbmVudHNNYW5hZ2VyJTBBZnJvbSUyMGRpZmZ1c2Vycy5tb2R1bGFyX3BpcGVsaW5lcyUyMGltcG9ydCUyMFNlcXVlbnRpYWxQaXBlbGluZUJsb2NrcyUwQWZyb20lMjBkaWZmdXNlcnMubW9kdWxhcl9waXBlbGluZXMuc3RhYmxlX2RpZmZ1c2lvbl94bCUyMGltcG9ydCUyMFRFWFQySU1BR0VfQkxPQ0tTJTBBJTBBdDJpX2Jsb2NrcyUyMCUzRCUyMFNlcXVlbnRpYWxQaXBlbGluZUJsb2Nrcy5mcm9tX2Jsb2Nrc19kaWN0KFRFWFQySU1BR0VfQkxPQ0tTKSUwQSUwQW1vZHVsYXJfcmVwb19pZCUyMCUzRCUyMCUyMllpWWlYdSUyRm1vZHVsYXItbG9hZGVyLXQyaS0wNzA0JTIyJTBBY29tcG9uZW50cyUyMCUzRCUyMENvbXBvbmVudHNNYW5hZ2VyKCklMEF0MmlfcGlwZWxpbmUlMjAlM0QlMjB0MmlfYmxvY2tzLmluaXRfcGlwZWxpbmUobW9kdWxhcl9yZXBvX2lkJTJDJTIwY29tcG9uZW50c19tYW5hZ2VyJTNEY29tcG9uZW50cyk=",highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> ComponentsManager
<span class="hljs-keyword">from</span> diffusers.modular_pipelines <span class="hljs-keyword">import</span> SequentialPipelineBlocks
<span class="hljs-keyword">from</span> diffusers.modular_pipelines.stable_diffusion_xl <span class="hljs-keyword">import</span> TEXT2IMAGE_BLOCKS

t2i_blocks = SequentialPipelineBlocks.from_blocks_dict(TEXT2IMAGE_BLOCKS)

modular_repo_id = <span class="hljs-string">&quot;YiYiXu/modular-loader-t2i-0704&quot;</span>
components = ComponentsManager()
t2i_pipeline = t2i_blocks.init_pipeline(modular_repo_id, components_manager=components)`,wrap:!1}}),{c(){d(o.$$.fragment)},l(a){M(o.$$.fragment,a)},m(a,b){U(o,a,b),J=!0},p:vt,i(a){J||(u(o.$$.fragment,a),J=!0)},o(a){r(o.$$.fragment,a),J=!1},d(a){y(o,a)}}}function Lt(V){let o,J,a,b;return o=new xt({props:{id:"create",option:"from_pretrained",$$slots:{default:[Ht]},$$scope:{ctx:V}}}),a=new xt({props:{id:"create",option:"init_pipeline",$$slots:{default:[zt]},$$scope:{ctx:V}}}),{c(){d(o.$$.fragment),J=s(),d(a.$$.fragment)},l(i){M(o.$$.fragment,i),J=p(i),M(a.$$.fragment,i)},m(i,T){U(o,i,T),n(i,J,T),U(a,i,T),b=!0},p(i,T){const $={};T&2&&($.$$scope={dirty:T,ctx:i}),o.$set($);const Z={};T&2&&(Z.$$scope={dirty:T,ctx:i}),a.$set(Z)},i(i){b||(u(o.$$.fragment,i),u(a.$$.fragment,i),b=!0)},o(i){r(o.$$.fragment,i),r(a.$$.fragment,i),b=!1},d(i){i&&l(J),y(o,i),y(a,i)}}}function Ot(V){let o,J,a,b,i,T,$,Z,_,ct="<code>ComponentsManager</code> 是 Modular Diffusers 的模型注册和管理系统。它添加和跟踪模型，存储有用的元数据（模型大小、设备放置、适配器），防止重复模型实例，并支持卸载。",fe,w,mt="本指南将展示如何使用 <code>ComponentsManager</code> 来管理组件和设备内存。",Je,h,be,R,dt="<code>ComponentsManager</code> 应与 <code>ModularPipeline</code> 一起创建，在 <code>from_pretrained()</code> 或 <code>init_pipeline()</code> 中。",Te,j,Mt="<p><code>collection</code> 参数是可选的，但可以更轻松地组织和管理组件。</p>",Ce,g,$e,B,Ut="组件仅在调用 <code>load_components()</code> 或 <code>load_components()</code> 时加载和注册。以下示例使用 <code>load_components()</code> 创建第二个管道，重用第一个管道的所有组件，并将其分配到不同的集合。",Ve,W,je,k,ut="使用 <code>null_component_names</code> 属性来识别需要加载的任何组件，使用 <code>get_components_by_names()</code> 检索它们，然后调用 <code>update_components()</code> 来添加缺失的组件。",ge,x,Ne,v,rt="要添加单个组件，请使用 <code>add()</code> 方法。这会使用唯一 id 注册一个组件。",Ze,Q,_e,G,yt="使用 <code>remove()</code> 通过其 id 移除一个组件。",we,F,he,X,Re,I,ft="<code>ComponentsManager</code> 提供了几种方法来检索已注册的组件。",Be,Y,We,S,Jt="<code>get_one()</code> 方法返回单个组件，并支持对 <code>name</code> 参数进行模式匹配。如果多个组件匹配，<code>get_one()</code> 会返回错误。",ke,q,bt="<thead><tr><th>模式</th> <th>示例</th> <th>描述</th></tr></thead> <tbody><tr><td>exact</td> <td><code>comp.get_one(name=&quot;unet&quot;)</code></td> <td>精确名称匹配</td></tr> <tr><td>wildcard</td> <td><code>comp.get_one(name=&quot;unet*&quot;)</code></td> <td>名称以 “unet” 开头</td></tr> <tr><td>exclusion</td> <td><code>comp.get_one(name=&quot;!unet&quot;)</code></td> <td>排除名为 “unet” 的组件</td></tr> <tr><td>or</td> <td><code>comp.get_one(name=&quot;unet|vae&quot;)</code></td> <td>名称为 “unet” 或 “vae”</td></tr></tbody>",xe,E,Tt="<code>get_one()</code> 还通过 <code>collection</code> 参数或 <code>load_id</code> 参数过滤组件。",ve,H,Qe,z,Ge,L,Ct="<code>get_components_by_names()</code> 方法接受一个名称列表，并返回一个将名称映射到组件的字典。这在 <code>ModularPipeline</code> 中特别有用，因为它们提供了所需组件名称的列表，并且返回的字典可以直接传递给 <code>update_components()</code>。",Fe,O,Xe,D,Ie,A,$t="建议使用 <code>ComponentSpec</code> 加载模型组件，以分配具有唯一 id 的组件，该 id 编码了它们的加载参数。这允许 <code>ComponentsManager</code> 自动检测并防止重复的模型实例，即使不同的对象代表相同的底层检查点。",Ye,P,Se,K,Vt="这会返回一个警告，附带移除重复项的说明。",qe,ee,Ee,te,jt="您也可以不使用 <code>ComponentSpec</code> 添加组件，并且在大多数情况下，即使您以不同名称添加相同组件，重复检测仍然有效。",He,le,gt="然而，当您将相同组件加载到不同对象时，<code>ComponentManager</code> 无法检测重复项。在这种情况下，您应该使用 <code>ComponentSpec</code> 加载模型。",ze,ne,Le,se,Oe,pe,Nt="集合是为组件分配的标签，用于更好的组织和管理。使用 <code>add()</code> 中的 <code>collection</code> 参数将组件添加到集合中。",De,oe,Zt="每个集合中只允许每个名称有一个组件。添加第二个同名组件会自动移除第一个组件。",Ae,ae,Pe,ie,_t="这使得在基于节点的系统中工作变得方便，因为您可以：",Ke,ce,wt="<li>使用 <code>collection</code> 标签标记所有从一个节点加载的模型。</li> <li>当新检查点以相同名称加载时自动替换模型。</li> <li>当节点被移除时批量删除集合中的所有模型。</li>",et,me,tt,de,ht="<code>enable_auto_cpu_offload()</code> 方法是一种全局卸载策略，适用于所有模型，无论哪个管道在使用它们。一旦启用，您无需担心设备放置，如果您添加或移除组件。",lt,Me,nt,Ue,Rt="所有模型开始时都在 CPU 上，<code>ComponentsManager</code> 在需要它们之前将它们移动到适当的设备，并在 GPU 内存不足时将其他模型移回 CPU。",st,ue,Bt="您可以设置自己的规则来决定哪些模型要卸载。",pt,re,ot,ye,at;return i=new St({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),$=new N({props:{title:"组件管理器",local:"组件管理器",headingTag:"h1"}}),h=new N({props:{title:"添加组件",local:"添加组件",headingTag:"h2"}}),g=new Et({props:{id:"create",options:["from_pretrained","init_pipeline"],$$slots:{default:[Lt]},$$scope:{ctx:V}}}),W=new C({props:{code:"cGlwZS5sb2FkX2NvbXBvbmVudHMoKSUwQXBpcGUyJTIwJTNEJTIwTW9kdWxhclBpcGVsaW5lLmZyb21fcHJldHJhaW5lZCglMjJZaVlpWHUlMkZtb2R1bGFyLWRlbW8tYXV0byUyMiUyQyUyMGNvbXBvbmVudHNfbWFuYWdlciUzRGNvbXAlMkMlMjBjb2xsZWN0aW9uJTNEJTIydGVzdDIlMjIp",highlighted:`pipe.load_components()
pipe2 = ModularPipeline.from_pretrained(<span class="hljs-string">&quot;YiYiXu/modular-demo-auto&quot;</span>, components_manager=comp, collection=<span class="hljs-string">&quot;test2&quot;</span>)`,wrap:!1}}),x=new C({props:{code:"cGlwZTIubnVsbF9jb21wb25lbnRfbmFtZXMlMjAlMEElNUIndGV4dF9lbmNvZGVyJyUyQyUyMCd0ZXh0X2VuY29kZXJfMiclMkMlMjAndG9rZW5pemVyJyUyQyUyMCd0b2tlbml6ZXJfMiclMkMlMjAnaW1hZ2VfZW5jb2RlciclMkMlMjAndW5ldCclMkMlMjAndmFlJyUyQyUyMCdzY2hlZHVsZXInJTJDJTIwJ2NvbnRyb2xuZXQnJTVEJTBBJTBBY29tcF9kaWN0JTIwJTNEJTIwY29tcC5nZXRfY29tcG9uZW50c19ieV9uYW1lcyhuYW1lcyUzRHBpcGUyLm51bGxfY29tcG9uZW50X25hbWVzKSUwQXBpcGUyLnVwZGF0ZV9jb21wb25lbnRzKCoqY29tcF9kaWN0KQ==",highlighted:`pipe2.null_component_names 
[<span class="hljs-string">&#x27;text_encoder&#x27;</span>, <span class="hljs-string">&#x27;text_encoder_2&#x27;</span>, <span class="hljs-string">&#x27;tokenizer&#x27;</span>, <span class="hljs-string">&#x27;tokenizer_2&#x27;</span>, <span class="hljs-string">&#x27;image_encoder&#x27;</span>, <span class="hljs-string">&#x27;unet&#x27;</span>, <span class="hljs-string">&#x27;vae&#x27;</span>, <span class="hljs-string">&#x27;scheduler&#x27;</span>, <span class="hljs-string">&#x27;controlnet&#x27;</span>]

comp_dict = comp.get_components_by_names(names=pipe2.null_component_names)
pipe2.update_components(**comp_dict)`,wrap:!1}}),Q=new C({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMEF1dG9Nb2RlbCUwQSUwQXRleHRfZW5jb2RlciUyMCUzRCUyMEF1dG9Nb2RlbC5mcm9tX3ByZXRyYWluZWQoJTIyc3RhYmlsaXR5YWklMkZzdGFibGUtZGlmZnVzaW9uLXhsLWJhc2UtMS4wJTIyJTJDJTIwc3ViZm9sZGVyJTNEJTIydGV4dF9lbmNvZGVyJTIyKSUwQWNvbXBvbmVudF9pZCUyMCUzRCUyMGNvbXAuYWRkKCUyMnRleHRfZW5jb2RlciUyMiUyQyUyMHRleHRfZW5jb2RlciklMEFjb21w",highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> AutoModel

text_encoder = AutoModel.from_pretrained(<span class="hljs-string">&quot;stabilityai/stable-diffusion-xl-base-1.0&quot;</span>, subfolder=<span class="hljs-string">&quot;text_encoder&quot;</span>)
component_id = comp.add(<span class="hljs-string">&quot;text_encoder&quot;</span>, text_encoder)
comp`,wrap:!1}}),F=new C({props:{code:"Y29tcC5yZW1vdmUoJTIydGV4dF9lbmNvZGVyXzEzOTkxNzczMzA0Mjg2NCUyMik=",highlighted:'comp.remove(<span class="hljs-string">&quot;text_encoder_139917733042864&quot;</span>)',wrap:!1}}),X=new N({props:{title:"检索组件",local:"检索组件",headingTag:"h2"}}),Y=new N({props:{title:"get_one",local:"getone",headingTag:"h3"}}),H=new C({props:{code:"Y29tcC5nZXRfb25lKG5hbWUlM0QlMjJ1bmV0JTIyJTJDJTIwY29sbGVjdGlvbiUzRCUyMnNkeGwlMjIp",highlighted:'comp.get_one(name=<span class="hljs-string">&quot;unet&quot;</span>, collection=<span class="hljs-string">&quot;sdxl&quot;</span>)',wrap:!1}}),z=new N({props:{title:"get_components_by_names",local:"getcomponentsbynames",headingTag:"h3"}}),O=new C({props:{code:"Y29tcG9uZW50X2RpY3QlMjAlM0QlMjBjb21wLmdldF9jb21wb25lbnRzX2J5X25hbWVzKG5hbWVzJTNEJTVCJTIydGV4dF9lbmNvZGVyJTIyJTJDJTIwJTIydW5ldCUyMiUyQyUyMCUyMnZhZSUyMiU1RCklMEElN0IlMjJ0ZXh0X2VuY29kZXIlMjIlM0ElMjBjb21wb25lbnQxJTJDJTIwJTIydW5ldCUyMiUzQSUyMGNvbXBvbmVudDIlMkMlMjAlMjJ2YWUlMjIlM0ElMjBjb21wb25lbnQzJTdE",highlighted:`component_dict = comp.get_components_by_names(names=[<span class="hljs-string">&quot;text_encoder&quot;</span>, <span class="hljs-string">&quot;unet&quot;</span>, <span class="hljs-string">&quot;vae&quot;</span>])
{<span class="hljs-string">&quot;text_encoder&quot;</span>: component1, <span class="hljs-string">&quot;unet&quot;</span>: component2, <span class="hljs-string">&quot;vae&quot;</span>: component3}`,wrap:!1}}),D=new N({props:{title:"重复检测",local:"重复检测",headingTag:"h2"}}),P=new C({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMENvbXBvbmVudFNwZWMlMkMlMjBDb21wb25lbnRzTWFuYWdlciUwQWZyb20lMjB0cmFuc2Zvcm1lcnMlMjBpbXBvcnQlMjBDTElQVGV4dE1vZGVsJTBBJTBBY29tcCUyMCUzRCUyMENvbXBvbmVudHNNYW5hZ2VyKCklMEElMEElMjMlMjAlRTQlQjglQkElRTclQUMlQUMlRTQlQjglODAlRTQlQjglQUElRTYlOTYlODclRTYlOUMlQUMlRTclQkMlOTYlRTclQTAlODElRTUlOTklQTglRTUlODglOUIlRTUlQkIlQkElMjBDb21wb25lbnRTcGVjJTBBc3BlYyUyMCUzRCUyMENvbXBvbmVudFNwZWMobmFtZSUzRCUyMnRleHRfZW5jb2RlciUyMiUyQyUyMHJlcG8lM0QlMjJzdGFiaWxpdHlhaSUyRnN0YWJsZS1kaWZmdXNpb24teGwtYmFzZS0xLjAlMjIlMkMlMjBzdWJmb2xkZXIlM0QlMjJ0ZXh0X2VuY29kZXIlMjIlMkMlMjB0eXBlX2hpbnQlM0RBdXRvTW9kZWwpJTBBJTIzJTIwJUU0JUI4JUJBJUU5JTg3JThEJUU1JUE0JThEJUU3JTlBJTg0JUU2JTk2JTg3JUU2JTlDJUFDJUU3JUJDJTk2JUU3JUEwJTgxJUU1JTk5JUE4JUU1JTg4JTlCJUU1JUJCJUJBJTIwQ29tcG9uZW50U3BlYyVFRiVCQyU4OCVFNSVBRSU4MyVFNiU5OCVBRiVFNyU5QiVCOCVFNSU5MCU4QyVFNyU5QSU4NCVFNiVBMyU4MCVFNiU5RiVBNSVFNyU4MiVCOSVFRiVCQyU4QyVFNiU5RCVBNSVFOCU4NyVBQSVFNyU5QiVCOCVFNSU5MCU4QyVFNyU5QSU4NCVFNCVCQiU5MyVFNSVCQSU5MyUyRiVFNSVBRCU5MCVFNiU5NiU4NyVFNCVCQiVCNiVFNSVBNCVCOSVFRiVCQyU4OSUwQXNwZWNfZHVwbGljYXRlZCUyMCUzRCUyMENvbXBvbmVudFNwZWMobmFtZSUzRCUyMnRleHRfZW5jb2Rlcl9kdXBsaWNhdGVkJTIyJTJDJTIwcmVwbyUzRCUyMnN0YWJpbGl0eWFpJTJGc3RhYmxlLWRpZmZ1c2lvbi14bC1iYXNlLTEuMCUyMiUyQyUyMHN1YmZvbGRlciUzRCUyMnRleHRfZW5jb2RlciUyMiUyQyUyMHR5JTBBcGVfaGludCUzRENMSVBUZXh0TW9kZWwpJTBBJTBBJTIzJTIwJUU1JThBJUEwJUU4JUJEJUJEJUU1JUI5JUI2JUU2JUI3JUJCJUU1JThBJUEwJUU0JUI4JUE0JUU0JUI4JUFBJUU3JUJCJTg0JUU0JUJCJUI2JTIwLSUyMCVFNyVBRSVBMSVFNyU5MCU4NiVFNSU5OSVBOCVFNCVCQyU5QSVFNiVBMyU4MCVFNiVCNSU4QiVFNSU4OCVCMCVFNSVBRSU4MyVFNCVCQiVBQyVFNiU5OCVBRiVFNSU5MCU4QyVFNCVCOCU4MCVFNCVCOCVBQSVFNiVBOCVBMSVFNSU5RSU4QiUwQWNvbXAuYWRkKCUyMnRleHRfZW5jb2RlciUyMiUyQyUyMHNwZWMubG9hZCgpKSUwQWNvbXAuYWRkKCUyMnRleHRfZW5jb2Rlcl9kdXBsaWNhdGVkJTIyJTJDJTIwc3BlY19kdXBsaWNhdGVkLmxvYWQoKSk=",highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> ComponentSpec, ComponentsManager
<span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> CLIPTextModel

comp = ComponentsManager()

<span class="hljs-comment"># 为第一个文本编码器创建 ComponentSpec</span>
spec = ComponentSpec(name=<span class="hljs-string">&quot;text_encoder&quot;</span>, repo=<span class="hljs-string">&quot;stabilityai/stable-diffusion-xl-base-1.0&quot;</span>, subfolder=<span class="hljs-string">&quot;text_encoder&quot;</span>, type_hint=AutoModel)
<span class="hljs-comment"># 为重复的文本编码器创建 ComponentSpec（它是相同的检查点，来自相同的仓库/子文件夹）</span>
spec_duplicated = ComponentSpec(name=<span class="hljs-string">&quot;text_encoder_duplicated&quot;</span>, repo=<span class="hljs-string">&quot;stabilityai/stable-diffusion-xl-base-1.0&quot;</span>, subfolder=<span class="hljs-string">&quot;text_encoder&quot;</span>, ty
pe_hint=CLIPTextModel)

<span class="hljs-comment"># 加载并添加两个组件 - 管理器会检测到它们是同一个模型</span>
comp.add(<span class="hljs-string">&quot;text_encoder&quot;</span>, spec.load())
comp.add(<span class="hljs-string">&quot;text_encoder_duplicated&quot;</span>, spec_duplicated.load())`,wrap:!1}}),ee=new C({props:{code:"Q29tcG9uZW50c01hbmFnZXIlM0ElMjBhZGRpbmclMjBjb21wb25lbnQlMjAndGV4dF9lbmNvZGVyX2R1cGxpY2F0ZWRfMTM5OTE3NTgwNjgyNjcyJyUyQyUyMGJ1dCUyMGl0JTIwaGFzJTIwZHVwbGljYXRlJTIwbG9hZF9pZCUyMCdzdGFiaWxpdHlhaSUyRnN0YWJsZS1kaWZmdXNpb24teGwtYmFzZS0xLjAlN0N0ZXh0X2VuY29kZXIlN0NudWxsJTdDbnVsbCclMjB3aXRoJTIwZXhpc3RpbmclMjBjb21wb25lbnRzJTNBJTIwdGV4dF9lbmNvZGVyXzEzOTkxODUwNjI0NjgzMi4lMjBUbyUyMHJlbW92ZSUyMGElMjBkdXBsaWNhdGUlMkMlMjBjYWxsJTIwJTYwY29tcG9uZW50c19tYW5hZ2VyLnJlbW92ZSgnJTNDY29tcG9uZW50X2lkJTNFJyklNjAuJTBBJ3RleHRfZW5jb2Rlcl9kdXBsaWNhdGVkXzEzOTkxNzU4MDY4MjY3Mic=",highlighted:'ComponentsManager: adding component <span class="hljs-string">&#x27;text_encoder_duplicated_139917580682672&#x27;</span>, but it has duplicate load_id <span class="hljs-string">&#x27;stabilityai/stable-diffusion-xl-base-1.0|text_encoder|null|null&#x27;</span> <span class="hljs-keyword">with</span> existing components: text_encoder_139918506246832. To remove a duplicate, call `components_manager.remove(<span class="hljs-string">&#x27;&lt;component_id&gt;&#x27;</span>)`.\n<span class="hljs-string">&#x27;text_encoder_duplicated_139917580682672&#x27;</span>',wrap:!1}}),ne=new C({props:{code:"dGV4dF9lbmNvZGVyXzIlMjAlM0QlMjBBdXRvTW9kZWwuZnJvbV9wcmV0cmFpbmVkKCUyMnN0YWJpbGl0eWFpJTJGc3RhYmxlLWRpZmZ1c2lvbi14bC1iYXNlLTEuMCUyMiUyQyUyMHN1YmZvbGRlciUzRCUyMnRleHRfZW5jb2RlciUyMiklMEFjb21wLmFkZCglMjJ0ZXh0X2VuY29kZXIlMjIlMkMlMjB0ZXh0X2VuY29kZXJfMiklMEEndGV4dF9lbmNvZGVyXzEzOTkxNzczMjk4MzY2NCc=",highlighted:`text_encoder_2 = AutoModel.from_pretrained(<span class="hljs-string">&quot;stabilityai/stable-diffusion-xl-base-1.0&quot;</span>, subfolder=<span class="hljs-string">&quot;text_encoder&quot;</span>)
comp.add(<span class="hljs-string">&quot;text_encoder&quot;</span>, text_encoder_2)
<span class="hljs-string">&#x27;text_encoder_139917732983664&#x27;</span>`,wrap:!1}}),se=new N({props:{title:"集合",local:"集合",headingTag:"h2"}}),ae=new C({props:{code:"ZnJvbSUyMGRpZmZ1c2VycyUyMGltcG9ydCUyMENvbXBvbmVudFNwZWMlMkMlMjBDb21wb25lbnRzTWFuYWdlciUwQSUwQWNvbXAlMjAlM0QlMjBDb21wb25lbnRzTWFuYWdlcigpJTBBJTIzJTIwJUU0JUI4JUJBJUU3JUFDJUFDJUU0JUI4JTgwJUU0JUI4JUFBJTIwVU5ldCUyMCVFNSU4OCU5QiVFNSVCQiVCQSUyMENvbXBvbmVudFNwZWMlMEFzcGVjJTIwJTNEJTIwQ29tcG9uZW50U3BlYyhuYW1lJTNEJTIydW5ldCUyMiUyQyUyMHJlcG8lM0QlMjJzdGFiaWxpdHlhaSUyRnN0YWJsZS1kaWZmdXNpb24teGwtYmFzZS0xLjAlMjIlMkMlMjBzdWJmb2xkZXIlM0QlMjJ1bmV0JTIyJTJDJTIwdHlwZV9oaW50JTNEQXV0b01vZGVsKSUwQSUyMyUyMCVFNCVCOCVCQSVFNSU4RiVBNiVFNCVCOCU4MCVFNCVCOCVBQSUyMFVOZXQlMjAlRTUlODglOUIlRTUlQkIlQkElMjBDb21wb25lbnRTcGVjJTBBc3BlYzIlMjAlM0QlMjBDb21wb25lbnRTcGVjKG5hbWUlM0QlMjJ1bmV0JTIyJTJDJTIwcmVwbyUzRCUyMlJ1bkRpZmZ1c2lvbiUyRkp1Z2dlcm5hdXQtWEwtdjklMjIlMkMlMjBzdWJmb2xkZXIlM0QlMjJ1bmV0JTIyJTJDJTIwdHlwZV9oaW50JTNEQXV0b01vZGVsJTJDJTIwdmFyaWFudCUzRCUyMmZwMTYlMjIpJTBBJTBBJTIzJTIwJUU1JUIwJTg2JUU0JUI4JUE0JUU0JUI4JUFBJTIwVU5ldCUyMCVFNiVCNyVCQiVFNSU4QSVBMCVFNSU4OCVCMCVFNSU5MCU4QyVFNCVCOCU4MCVFNCVCOCVBQSVFOSU5QiU4NiVFNSU5MCU4OCUyMC0lMjAlRTclQUMlQUMlRTQlQkElOEMlRTQlQjglQUElRTUlQjAlODYlRTYlOUIlQkYlRTYlOEQlQTIlRTclQUMlQUMlRTQlQjglODAlRTQlQjglQUElMEFjb21wLmFkZCglMjJ1bmV0JTIyJTJDJTIwc3BlYy5sb2FkKCklMkMlMjBjb2xsZWN0aW9uJTNEJTIyc2R4bCUyMiklMEFjb21wLmFkZCglMjJ1bmV0JTIyJTJDJTIwc3BlYzIubG9hZCgpJTJDJTIwY29sbGVjdGlvbiUzRCUyMnNkeGwlMjIp",highlighted:`<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> ComponentSpec, ComponentsManager

comp = ComponentsManager()
<span class="hljs-comment"># 为第一个 UNet 创建 ComponentSpec</span>
spec = ComponentSpec(name=<span class="hljs-string">&quot;unet&quot;</span>, repo=<span class="hljs-string">&quot;stabilityai/stable-diffusion-xl-base-1.0&quot;</span>, subfolder=<span class="hljs-string">&quot;unet&quot;</span>, type_hint=AutoModel)
<span class="hljs-comment"># 为另一个 UNet 创建 ComponentSpec</span>
spec2 = ComponentSpec(name=<span class="hljs-string">&quot;unet&quot;</span>, repo=<span class="hljs-string">&quot;RunDiffusion/Juggernaut-XL-v9&quot;</span>, subfolder=<span class="hljs-string">&quot;unet&quot;</span>, type_hint=AutoModel, variant=<span class="hljs-string">&quot;fp16&quot;</span>)

<span class="hljs-comment"># 将两个 UNet 添加到同一个集合 - 第二个将替换第一个</span>
comp.add(<span class="hljs-string">&quot;unet&quot;</span>, spec.load(), collection=<span class="hljs-string">&quot;sdxl&quot;</span>)
comp.add(<span class="hljs-string">&quot;unet&quot;</span>, spec2.load(), collection=<span class="hljs-string">&quot;sdxl&quot;</span>)`,wrap:!1}}),me=new N({props:{title:"卸载",local:"卸载",headingTag:"h2"}}),Me=new C({props:{code:"Y29tcC5lbmFibGVfYXV0b19jcHVfb2ZmbG9hZChkZXZpY2UlM0QlMjJjdWRhJTIyKQ==",highlighted:'comp.enable_auto_cpu_offload(device=<span class="hljs-string">&quot;cuda&quot;</span>)',wrap:!1}}),re=new qt({props:{source:"https://github.com/huggingface/diffusers/blob/main/docs/source/zh/modular_diffusers/components_manager.md"}}),{c(){o=c("meta"),J=s(),a=c("p"),b=s(),d(i.$$.fragment),T=s(),d($.$$.fragment),Z=s(),_=c("p"),_.innerHTML=ct,fe=s(),w=c("p"),w.innerHTML=mt,Je=s(),d(h.$$.fragment),be=s(),R=c("p"),R.innerHTML=dt,Te=s(),j=c("blockquote"),j.innerHTML=Mt,Ce=s(),d(g.$$.fragment),$e=s(),B=c("p"),B.innerHTML=Ut,Ve=s(),d(W.$$.fragment),je=s(),k=c("p"),k.innerHTML=ut,ge=s(),d(x.$$.fragment),Ne=s(),v=c("p"),v.innerHTML=rt,Ze=s(),d(Q.$$.fragment),_e=s(),G=c("p"),G.innerHTML=yt,we=s(),d(F.$$.fragment),he=s(),d(X.$$.fragment),Re=s(),I=c("p"),I.innerHTML=ft,Be=s(),d(Y.$$.fragment),We=s(),S=c("p"),S.innerHTML=Jt,ke=s(),q=c("table"),q.innerHTML=bt,xe=s(),E=c("p"),E.innerHTML=Tt,ve=s(),d(H.$$.fragment),Qe=s(),d(z.$$.fragment),Ge=s(),L=c("p"),L.innerHTML=Ct,Fe=s(),d(O.$$.fragment),Xe=s(),d(D.$$.fragment),Ie=s(),A=c("p"),A.innerHTML=$t,Ye=s(),d(P.$$.fragment),Se=s(),K=c("p"),K.textContent=Vt,qe=s(),d(ee.$$.fragment),Ee=s(),te=c("p"),te.innerHTML=jt,He=s(),le=c("p"),le.innerHTML=gt,ze=s(),d(ne.$$.fragment),Le=s(),d(se.$$.fragment),Oe=s(),pe=c("p"),pe.innerHTML=Nt,De=s(),oe=c("p"),oe.textContent=Zt,Ae=s(),d(ae.$$.fragment),Pe=s(),ie=c("p"),ie.textContent=_t,Ke=s(),ce=c("ul"),ce.innerHTML=wt,et=s(),d(me.$$.fragment),tt=s(),de=c("p"),de.innerHTML=ht,lt=s(),d(Me.$$.fragment),nt=s(),Ue=c("p"),Ue.innerHTML=Rt,st=s(),ue=c("p"),ue.textContent=Bt,pt=s(),d(re.$$.fragment),ot=s(),ye=c("p"),this.h()},l(e){const t=It("svelte-u9bgzb",document.head);o=m(t,"META",{name:!0,content:!0}),t.forEach(l),J=p(e),a=m(e,"P",{}),kt(a).forEach(l),b=p(e),M(i.$$.fragment,e),T=p(e),M($.$$.fragment,e),Z=p(e),_=m(e,"P",{"data-svelte-h":!0}),f(_)!=="svelte-1vkk8wr"&&(_.innerHTML=ct),fe=p(e),w=m(e,"P",{"data-svelte-h":!0}),f(w)!=="svelte-btfbdf"&&(w.innerHTML=mt),Je=p(e),M(h.$$.fragment,e),be=p(e),R=m(e,"P",{"data-svelte-h":!0}),f(R)!=="svelte-357gdc"&&(R.innerHTML=dt),Te=p(e),j=m(e,"BLOCKQUOTE",{class:!0,"data-svelte-h":!0}),f(j)!=="svelte-1a3x1t6"&&(j.innerHTML=Mt),Ce=p(e),M(g.$$.fragment,e),$e=p(e),B=m(e,"P",{"data-svelte-h":!0}),f(B)!=="svelte-5zx8o7"&&(B.innerHTML=Ut),Ve=p(e),M(W.$$.fragment,e),je=p(e),k=m(e,"P",{"data-svelte-h":!0}),f(k)!=="svelte-10ue6nx"&&(k.innerHTML=ut),ge=p(e),M(x.$$.fragment,e),Ne=p(e),v=m(e,"P",{"data-svelte-h":!0}),f(v)!=="svelte-1avjawg"&&(v.innerHTML=rt),Ze=p(e),M(Q.$$.fragment,e),_e=p(e),G=m(e,"P",{"data-svelte-h":!0}),f(G)!=="svelte-1xo6ira"&&(G.innerHTML=yt),we=p(e),M(F.$$.fragment,e),he=p(e),M(X.$$.fragment,e),Re=p(e),I=m(e,"P",{"data-svelte-h":!0}),f(I)!=="svelte-1i33j7x"&&(I.innerHTML=ft),Be=p(e),M(Y.$$.fragment,e),We=p(e),S=m(e,"P",{"data-svelte-h":!0}),f(S)!=="svelte-1675jc5"&&(S.innerHTML=Jt),ke=p(e),q=m(e,"TABLE",{"data-svelte-h":!0}),f(q)!=="svelte-154liov"&&(q.innerHTML=bt),xe=p(e),E=m(e,"P",{"data-svelte-h":!0}),f(E)!=="svelte-124kykz"&&(E.innerHTML=Tt),ve=p(e),M(H.$$.fragment,e),Qe=p(e),M(z.$$.fragment,e),Ge=p(e),L=m(e,"P",{"data-svelte-h":!0}),f(L)!=="svelte-1jgc3kd"&&(L.innerHTML=Ct),Fe=p(e),M(O.$$.fragment,e),Xe=p(e),M(D.$$.fragment,e),Ie=p(e),A=m(e,"P",{"data-svelte-h":!0}),f(A)!=="svelte-1fl2c4h"&&(A.innerHTML=$t),Ye=p(e),M(P.$$.fragment,e),Se=p(e),K=m(e,"P",{"data-svelte-h":!0}),f(K)!=="svelte-1lmaszj"&&(K.textContent=Vt),qe=p(e),M(ee.$$.fragment,e),Ee=p(e),te=m(e,"P",{"data-svelte-h":!0}),f(te)!=="svelte-t3wjvs"&&(te.innerHTML=jt),He=p(e),le=m(e,"P",{"data-svelte-h":!0}),f(le)!=="svelte-13lybv6"&&(le.innerHTML=gt),ze=p(e),M(ne.$$.fragment,e),Le=p(e),M(se.$$.fragment,e),Oe=p(e),pe=m(e,"P",{"data-svelte-h":!0}),f(pe)!=="svelte-kru0jg"&&(pe.innerHTML=Nt),De=p(e),oe=m(e,"P",{"data-svelte-h":!0}),f(oe)!=="svelte-o60soj"&&(oe.textContent=Zt),Ae=p(e),M(ae.$$.fragment,e),Pe=p(e),ie=m(e,"P",{"data-svelte-h":!0}),f(ie)!=="svelte-1kgji9x"&&(ie.textContent=_t),Ke=p(e),ce=m(e,"UL",{"data-svelte-h":!0}),f(ce)!=="svelte-8piqdl"&&(ce.innerHTML=wt),et=p(e),M(me.$$.fragment,e),tt=p(e),de=m(e,"P",{"data-svelte-h":!0}),f(de)!=="svelte-gu4wm9"&&(de.innerHTML=ht),lt=p(e),M(Me.$$.fragment,e),nt=p(e),Ue=m(e,"P",{"data-svelte-h":!0}),f(Ue)!=="svelte-1njhi8b"&&(Ue.innerHTML=Rt),st=p(e),ue=m(e,"P",{"data-svelte-h":!0}),f(ue)!=="svelte-1hqy2kb"&&(ue.textContent=Bt),pt=p(e),M(re.$$.fragment,e),ot=p(e),ye=m(e,"P",{}),kt(ye).forEach(l),this.h()},h(){it(o,"name","hf:doc:metadata"),it(o,"content",Dt),it(j,"class","tip")},m(e,t){Yt(document.head,o),n(e,J,t),n(e,a,t),n(e,b,t),U(i,e,t),n(e,T,t),U($,e,t),n(e,Z,t),n(e,_,t),n(e,fe,t),n(e,w,t),n(e,Je,t),U(h,e,t),n(e,be,t),n(e,R,t),n(e,Te,t),n(e,j,t),n(e,Ce,t),U(g,e,t),n(e,$e,t),n(e,B,t),n(e,Ve,t),U(W,e,t),n(e,je,t),n(e,k,t),n(e,ge,t),U(x,e,t),n(e,Ne,t),n(e,v,t),n(e,Ze,t),U(Q,e,t),n(e,_e,t),n(e,G,t),n(e,we,t),U(F,e,t),n(e,he,t),U(X,e,t),n(e,Re,t),n(e,I,t),n(e,Be,t),U(Y,e,t),n(e,We,t),n(e,S,t),n(e,ke,t),n(e,q,t),n(e,xe,t),n(e,E,t),n(e,ve,t),U(H,e,t),n(e,Qe,t),U(z,e,t),n(e,Ge,t),n(e,L,t),n(e,Fe,t),U(O,e,t),n(e,Xe,t),U(D,e,t),n(e,Ie,t),n(e,A,t),n(e,Ye,t),U(P,e,t),n(e,Se,t),n(e,K,t),n(e,qe,t),U(ee,e,t),n(e,Ee,t),n(e,te,t),n(e,He,t),n(e,le,t),n(e,ze,t),U(ne,e,t),n(e,Le,t),U(se,e,t),n(e,Oe,t),n(e,pe,t),n(e,De,t),n(e,oe,t),n(e,Ae,t),U(ae,e,t),n(e,Pe,t),n(e,ie,t),n(e,Ke,t),n(e,ce,t),n(e,et,t),U(me,e,t),n(e,tt,t),n(e,de,t),n(e,lt,t),U(Me,e,t),n(e,nt,t),n(e,Ue,t),n(e,st,t),n(e,ue,t),n(e,pt,t),U(re,e,t),n(e,ot,t),n(e,ye,t),at=!0},p(e,[t]){const Wt={};t&2&&(Wt.$$scope={dirty:t,ctx:e}),g.$set(Wt)},i(e){at||(u(i.$$.fragment,e),u($.$$.fragment,e),u(h.$$.fragment,e),u(g.$$.fragment,e),u(W.$$.fragment,e),u(x.$$.fragment,e),u(Q.$$.fragment,e),u(F.$$.fragment,e),u(X.$$.fragment,e),u(Y.$$.fragment,e),u(H.$$.fragment,e),u(z.$$.fragment,e),u(O.$$.fragment,e),u(D.$$.fragment,e),u(P.$$.fragment,e),u(ee.$$.fragment,e),u(ne.$$.fragment,e),u(se.$$.fragment,e),u(ae.$$.fragment,e),u(me.$$.fragment,e),u(Me.$$.fragment,e),u(re.$$.fragment,e),at=!0)},o(e){r(i.$$.fragment,e),r($.$$.fragment,e),r(h.$$.fragment,e),r(g.$$.fragment,e),r(W.$$.fragment,e),r(x.$$.fragment,e),r(Q.$$.fragment,e),r(F.$$.fragment,e),r(X.$$.fragment,e),r(Y.$$.fragment,e),r(H.$$.fragment,e),r(z.$$.fragment,e),r(O.$$.fragment,e),r(D.$$.fragment,e),r(P.$$.fragment,e),r(ee.$$.fragment,e),r(ne.$$.fragment,e),r(se.$$.fragment,e),r(ae.$$.fragment,e),r(me.$$.fragment,e),r(Me.$$.fragment,e),r(re.$$.fragment,e),at=!1},d(e){e&&(l(J),l(a),l(b),l(T),l(Z),l(_),l(fe),l(w),l(Je),l(be),l(R),l(Te),l(j),l(Ce),l($e),l(B),l(Ve),l(je),l(k),l(ge),l(Ne),l(v),l(Ze),l(_e),l(G),l(we),l(he),l(Re),l(I),l(Be),l(We),l(S),l(ke),l(q),l(xe),l(E),l(ve),l(Qe),l(Ge),l(L),l(Fe),l(Xe),l(Ie),l(A),l(Ye),l(Se),l(K),l(qe),l(Ee),l(te),l(He),l(le),l(ze),l(Le),l(Oe),l(pe),l(De),l(oe),l(Ae),l(Pe),l(ie),l(Ke),l(ce),l(et),l(tt),l(de),l(lt),l(nt),l(Ue),l(st),l(ue),l(pt),l(ot),l(ye)),l(o),y(i,e),y($,e),y(h,e),y(g,e),y(W,e),y(x,e),y(Q,e),y(F,e),y(X,e),y(Y,e),y(H,e),y(z,e),y(O,e),y(D,e),y(P,e),y(ee,e),y(ne,e),y(se,e),y(ae,e),y(me,e),y(Me,e),y(re,e)}}}const Dt='{"title":"组件管理器","local":"组件管理器","sections":[{"title":"添加组件","local":"添加组件","sections":[],"depth":2},{"title":"检索组件","local":"检索组件","sections":[{"title":"get_one","local":"getone","sections":[],"depth":3},{"title":"get_components_by_names","local":"getcomponentsbynames","sections":[],"depth":3}],"depth":2},{"title":"重复检测","local":"重复检测","sections":[],"depth":2},{"title":"集合","local":"集合","sections":[],"depth":2},{"title":"卸载","local":"卸载","sections":[],"depth":2}],"depth":1}';function At(V){return Gt(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class nl extends Ft{constructor(o){super(),Xt(this,o,At,Ot,Qt,{})}}export{nl as component};
