Buckets:
| <meta charset="utf-8" /><meta name="hf:doc:metadata" content="{"title":"Components Manager","local":"components-manager","sections":[{"title":"Basic Operations","local":"basic-operations","sections":[],"depth":2},{"title":"Duplicate Detection","local":"duplicate-detection","sections":[],"depth":2},{"title":"Collections","local":"collections","sections":[],"depth":2},{"title":"Retrieving Components","local":"retrieving-components","sections":[],"depth":2},{"title":"Using Components Manager with Modular Pipelines","local":"using-components-manager-with-modular-pipelines","sections":[],"depth":2},{"title":"Automatic Memory Management","local":"automatic-memory-management","sections":[],"depth":2},{"title":"Practical Example: Building Modular Workflows with Component Reuse","local":"practical-example-building-modular-workflows-with-component-reuse","sections":[{"title":"Base Text-to-Image Generation","local":"base-text-to-image-generation","sections":[],"depth":4},{"title":"LoRA","local":"lora","sections":[],"depth":4}],"depth":2}],"depth":1}"> | |
| <link href="/docs/diffusers/pr_11797/en/_app/immutable/assets/0.e3b0c442.css" rel="modulepreload"> | |
| <link rel="modulepreload" href="/docs/diffusers/pr_11797/en/_app/immutable/entry/start.2e1ee9a7.js"> | |
| <link rel="modulepreload" href="/docs/diffusers/pr_11797/en/_app/immutable/chunks/scheduler.8c3d61f6.js"> | |
| <link rel="modulepreload" href="/docs/diffusers/pr_11797/en/_app/immutable/chunks/singletons.702cc21f.js"> | |
| <link rel="modulepreload" href="/docs/diffusers/pr_11797/en/_app/immutable/chunks/index.0997d446.js"> | |
| <link rel="modulepreload" href="/docs/diffusers/pr_11797/en/_app/immutable/chunks/paths.ec7f49a7.js"> | |
| <link rel="modulepreload" href="/docs/diffusers/pr_11797/en/_app/immutable/entry/app.87c95e21.js"> | |
| <link rel="modulepreload" href="/docs/diffusers/pr_11797/en/_app/immutable/chunks/index.da70eac4.js"> | |
| <link rel="modulepreload" href="/docs/diffusers/pr_11797/en/_app/immutable/nodes/0.7e207bc6.js"> | |
| <link rel="modulepreload" href="/docs/diffusers/pr_11797/en/_app/immutable/chunks/each.e59479a4.js"> | |
| <link rel="modulepreload" href="/docs/diffusers/pr_11797/en/_app/immutable/nodes/228.138f1c0f.js"> | |
| <link rel="modulepreload" href="/docs/diffusers/pr_11797/en/_app/immutable/chunks/Tip.1d9b8c37.js"> | |
| <link rel="modulepreload" href="/docs/diffusers/pr_11797/en/_app/immutable/chunks/CodeBlock.a9c4becf.js"> | |
| <link rel="modulepreload" href="/docs/diffusers/pr_11797/en/_app/immutable/chunks/getInferenceSnippets.725ed3d4.js"><!-- HEAD_svelte-u9bgzb_START --><meta name="hf:doc:metadata" content="{"title":"Components Manager","local":"components-manager","sections":[{"title":"Basic Operations","local":"basic-operations","sections":[],"depth":2},{"title":"Duplicate Detection","local":"duplicate-detection","sections":[],"depth":2},{"title":"Collections","local":"collections","sections":[],"depth":2},{"title":"Retrieving Components","local":"retrieving-components","sections":[],"depth":2},{"title":"Using Components Manager with Modular Pipelines","local":"using-components-manager-with-modular-pipelines","sections":[],"depth":2},{"title":"Automatic Memory Management","local":"automatic-memory-management","sections":[],"depth":2},{"title":"Practical Example: Building Modular Workflows with Component Reuse","local":"practical-example-building-modular-workflows-with-component-reuse","sections":[{"title":"Base Text-to-Image Generation","local":"base-text-to-image-generation","sections":[],"depth":4},{"title":"LoRA","local":"lora","sections":[],"depth":4}],"depth":2}],"depth":1}"><!-- HEAD_svelte-u9bgzb_END --> <p></p> <h1 class="relative group"><a id="components-manager" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#components-manager"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Components Manager</span></h1> <div class="course-tip course-tip-orange bg-gradient-to-br dark:bg-gradient-to-r before:border-orange-500 dark:before:border-orange-800 from-orange-50 dark:from-gray-900 to-white dark:to-gray-950 border border-orange-50 text-orange-700 dark:text-gray-400"><p data-svelte-h="svelte-1r0wgxy">🧪 <strong>Experimental Feature</strong>: This is an experimental feature we are actively developing. The API may be subject to breaking changes.</p></div> <p data-svelte-h="svelte-1w209h4">The Components Manager is a central model registry and management system in diffusers. It lets you add models then reuse them across multiple pipelines and workflows. It tracks all models in one place with useful metadata such as model size, device placement and loaded adapters (LoRA, IP-Adapter). It has mechanisms in place to prevent duplicate model instances, enables memory-efficient sharing. Most significantly, it offers offloading that works across pipelines — unlike regular DiffusionPipeline offloading (i.e. <code>enable_model_cpu_offload</code> and <code>enable_sequential_cpu_offload</code>) which is limited to one pipeline with predefined sequences, the Components Manager automatically manages your device memory across all your models and workflows.</p> <h2 class="relative group"><a id="basic-operations" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#basic-operations"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Basic Operations</span></h2> <p data-svelte-h="svelte-1jd1wvz">Let’s start with the most basic operations. First, create a Components Manager:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> ComponentsManager | |
| comp = ComponentsManager()<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-11yvvp9">Use the <code>add(name, component)</code> method to register a component. It returns a unique ID that combines the component name with the object’s unique identifier (using Python’s <code>id()</code> function):</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> AutoModel | |
| text_encoder = AutoModel.from_pretrained(<span class="hljs-string">"stabilityai/stable-diffusion-xl-base-1.0"</span>, subfolder=<span class="hljs-string">"text_encoder"</span>) | |
| <span class="hljs-comment"># Returns component_id like 'text_encoder_139917733042864'</span> | |
| component_id = comp.add(<span class="hljs-string">"text_encoder"</span>, text_encoder)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-5b3kbr">You can view all registered components and their metadata:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><span class="hljs-meta">>>> </span>comp | |
| Components: | |
| =============================================================================================================================================== | |
| Models: | |
| ----------------------------------------------------------------------------------------------------------------------------------------------- | |
| Name_ID | Class | Device: act(<span class="hljs-built_in">exec</span>) | Dtype | Size (GB) | Load ID | Collection | |
| ----------------------------------------------------------------------------------------------------------------------------------------------- | |
| text_encoder_139917733042864 | CLIPTextModel | cpu | torch.float32 | <span class="hljs-number">0.46</span> | N/A | N/A | |
| ----------------------------------------------------------------------------------------------------------------------------------------------- | |
| Additional Component Info: | |
| ==================================================<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-hpt7hf">And remove components using their unique ID:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START -->comp.remove(<span class="hljs-string">"text_encoder_139917733042864"</span>)<!-- HTML_TAG_END --></pre></div> <h2 class="relative group"><a id="duplicate-detection" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#duplicate-detection"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Duplicate Detection</span></h2> <p data-svelte-h="svelte-zjrc8z">The Components Manager automatically detects and prevents duplicate model instances to save memory and avoid confusion. Let’s walk through how this works in practice.</p> <p data-svelte-h="svelte-x2x0fp">When you try to add the same object twice, the manager will warn you and return the existing ID:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><span class="hljs-meta">>>> </span>comp.add(<span class="hljs-string">"text_encoder"</span>, text_encoder) | |
| <span class="hljs-string">'text_encoder_139917733042864'</span> | |
| <span class="hljs-meta">>>> </span>comp.add(<span class="hljs-string">"text_encoder"</span>, text_encoder) | |
| ComponentsManager: component <span class="hljs-string">'text_encoder'</span> already exists <span class="hljs-keyword">as</span> <span class="hljs-string">'text_encoder_139917733042864'</span> | |
| <span class="hljs-string">'text_encoder_139917733042864'</span><!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1fdibg">Even if you add the same object under a different name, it will still be detected as a duplicate:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><span class="hljs-meta">>>> </span>comp.add(<span class="hljs-string">"clip"</span>, text_encoder) | |
| ComponentsManager: adding component <span class="hljs-string">'clip'</span> <span class="hljs-keyword">as</span> <span class="hljs-string">'clip_139917733042864'</span>, but it <span class="hljs-keyword">is</span> duplicate of <span class="hljs-string">'text_encoder_139917733042864'</span> | |
| To remove a duplicate, call `components_manager.remove(<span class="hljs-string">'<component_id>'</span>)`. | |
| <span class="hljs-string">'clip_139917733042864'</span><!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-xjmzxa">However, there’s a more subtle case where duplicate detection becomes tricky. When you load the same model into different objects, the manager can’t detect duplicates unless you use <code>ComponentSpec</code>. For example:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><span class="hljs-meta">>>> </span>text_encoder_2 = AutoModel.from_pretrained(<span class="hljs-string">"stabilityai/stable-diffusion-xl-base-1.0"</span>, subfolder=<span class="hljs-string">"text_encoder"</span>) | |
| <span class="hljs-meta">>>> </span>comp.add(<span class="hljs-string">"text_encoder"</span>, text_encoder_2) | |
| <span class="hljs-string">'text_encoder_139917732983664'</span><!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-x1j705">This creates a problem - you now have two copies of the same model consuming double the memory:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><span class="hljs-meta">>>> </span>comp | |
| Components: | |
| =============================================================================================================================================== | |
| Models: | |
| ----------------------------------------------------------------------------------------------------------------------------------------------- | |
| Name_ID | Class | Device: act(<span class="hljs-built_in">exec</span>) | Dtype | Size (GB) | Load ID | Collection | |
| ----------------------------------------------------------------------------------------------------------------------------------------------- | |
| text_encoder_139917733042864 | CLIPTextModel | cpu | torch.float32 | <span class="hljs-number">0.46</span> | N/A | N/A | |
| clip_139917733042864 | CLIPTextModel | cpu | torch.float32 | <span class="hljs-number">0.46</span> | N/A | N/A | |
| text_encoder_139917732983664 | CLIPTextModel | cpu | torch.float32 | <span class="hljs-number">0.46</span> | N/A | N/A | |
| ----------------------------------------------------------------------------------------------------------------------------------------------- | |
| Additional Component Info: | |
| ==================================================<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-12ddzhy">We recommend using <code>ComponentSpec</code> to load your models. Models loaded with <code>ComponentSpec</code> get tagged with a unique ID that encodes their loading parameters, allowing the Components Manager to detect when different objects represent the same underlying checkpoint:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><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"># Create ComponentSpec for the first text encoder</span> | |
| spec = ComponentSpec(name=<span class="hljs-string">"text_encoder"</span>, repo=<span class="hljs-string">"stabilityai/stable-diffusion-xl-base-1.0"</span>, subfolder=<span class="hljs-string">"text_encoder"</span>, type_hint=AutoModel) | |
| <span class="hljs-comment"># Create ComponentSpec for a duplicate text encoder (it is same checkpoint, from same repo/subfolder)</span> | |
| spec_duplicated = ComponentSpec(name=<span class="hljs-string">"text_encoder_duplicated"</span>, repo=<span class="hljs-string">"stabilityai/stable-diffusion-xl-base-1.0"</span>, subfolder=<span class="hljs-string">"text_encoder"</span>, type_hint=CLIPTextModel) | |
| <span class="hljs-comment"># Load and add both components - the manager will detect they're the same model</span> | |
| comp.add(<span class="hljs-string">"text_encoder"</span>, spec.load()) | |
| comp.add(<span class="hljs-string">"text_encoder_duplicated"</span>, spec_duplicated.load())<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-ai97qv">Now the manager detects the duplicate and warns you:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START -->ComponentsManager: adding component <span class="hljs-string">'text_encoder_duplicated_139917580682672'</span>, but it has duplicate load_id <span class="hljs-string">'stabilityai/stable-diffusion-xl-base-1.0|text_encoder|null|null'</span> with existing components: text_encoder_139918506246832. <span class="hljs-keyword">To</span> <span class="hljs-built_in">remove</span> a duplicate, call `components_manager.<span class="hljs-built_in">remove</span>(<span class="hljs-string">'<component_id>'</span>)`. | |
| <span class="hljs-string">'text_encoder_duplicated_139917580682672'</span><!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-19e2m6t">Both models now show the same <code>load_id</code>, making it clear they’re the same model:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><span class="hljs-meta">>>> </span>comp | |
| Components: | |
| ====================================================================================================================================================================================================== | |
| Models: | |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | |
| Name_ID | Class | Device: act(<span class="hljs-built_in">exec</span>) | Dtype | Size (GB) | Load ID | Collection | |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | |
| text_encoder_139918506246832 | CLIPTextModel | cpu | torch.float32 | <span class="hljs-number">0.46</span> | stabilityai/stable-diffusion-xl-base-<span class="hljs-number">1.0</span>|text_encoder|null|null | N/A | |
| text_encoder_duplicated_139917580682672 | CLIPTextModel | cpu | torch.float32 | <span class="hljs-number">0.46</span> | stabilityai/stable-diffusion-xl-base-<span class="hljs-number">1.0</span>|text_encoder|null|null | N/A | |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | |
| Additional Component Info: | |
| ==================================================<!-- HTML_TAG_END --></pre></div> <h2 class="relative group"><a id="collections" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#collections"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Collections</span></h2> <p data-svelte-h="svelte-ou2ao8">Collections are labels you can assign to components for better organization and management. You add a component under a collection by passing the <code>collection=</code> parameter when you add the component to the manager, i.e. <code>add(name, component, collection=...)</code>. Within each collection, only one component per name is allowed - if you add a second component with the same name, the first one is automatically removed.</p> <p data-svelte-h="svelte-1iqgs84">Here’s how collections work in practice:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START -->comp = ComponentsManager() | |
| <span class="hljs-comment"># Create ComponentSpec for the first UNet (SDXL base)</span> | |
| spec = ComponentSpec(name=<span class="hljs-string">"unet"</span>, repo=<span class="hljs-string">"stabilityai/stable-diffusion-xl-base-1.0"</span>, subfolder=<span class="hljs-string">"unet"</span>, type_hint=AutoModel) | |
| <span class="hljs-comment"># Create ComponentSpec for a different UNet (Juggernaut-XL)</span> | |
| spec2 = ComponentSpec(name=<span class="hljs-string">"unet"</span>, repo=<span class="hljs-string">"RunDiffusion/Juggernaut-XL-v9"</span>, subfolder=<span class="hljs-string">"unet"</span>, type_hint=AutoModel, variant=<span class="hljs-string">"fp16"</span>) | |
| <span class="hljs-comment"># Add both UNets to the same collection - the second one will replace the first</span> | |
| comp.add(<span class="hljs-string">"unet"</span>, spec.load(), collection=<span class="hljs-string">"sdxl"</span>) | |
| comp.add(<span class="hljs-string">"unet"</span>, spec2.load(), collection=<span class="hljs-string">"sdxl"</span>)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1stmhlk">The manager automatically removes the old UNet and adds the new one:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><span class="hljs-symbol">ComponentsManager:</span> removing existing unet <span class="hljs-keyword">from</span> collection <span class="hljs-comment">'sdxl': unet_139917723891888</span> | |
| <span class="hljs-comment">'unet_139917723893136'</span><!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-dmlykf">Only one UNet remains in the collection:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><span class="hljs-meta">>>> </span>comp | |
| Components: | |
| ==================================================================================================================================================================== | |
| Models: | |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
| Name_ID | Class | Device: act(<span class="hljs-built_in">exec</span>) | Dtype | Size (GB) | Load ID | Collection | |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
| unet_139917723893136 | UNet2DConditionModel | cpu | torch.float32 | <span class="hljs-number">9.56</span> | RunDiffusion/Juggernaut-XL-v9|unet|fp16|null | sdxl | |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
| Additional Component Info: | |
| ==================================================<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-m4cg8p">For example, in node-based systems, you can mark all models loaded from one node with the same collection label, automatically replace models when user loads new checkpoints under same name, batch delete all models in a collection when a node is removed.</p> <h2 class="relative group"><a id="retrieving-components" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#retrieving-components"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Retrieving Components</span></h2> <p data-svelte-h="svelte-1004hs3">The Components Manager provides several methods to retrieve registered components.</p> <p data-svelte-h="svelte-1jdz6wh">The <code>get_one()</code> method returns a single component and supports pattern matching for the <code>name</code> parameter. You can use:</p> <ul data-svelte-h="svelte-12ybnqe"><li>exact matches like <code>comp.get_one(name="unet")</code></li> <li>wildcards like <code>comp.get_one(name="unet*")</code> for components starting with “unet”</li> <li>exclusion patterns like <code>comp.get_one(name="!unet")</code> to exclude components named “unet”</li> <li>OR patterns like <code>comp.get_one(name="unet|vae")</code> to match either “unet” OR “vae”.</li></ul> <p data-svelte-h="svelte-xsqm04">Optionally, You can add collection and load_id as filters e.g. <code>comp.get_one(name="unet", collection="sdxl")</code>. If multiple components match, <code>get_one()</code> throws an error.</p> <p data-svelte-h="svelte-147rt0c">Another useful method is <code>get_components_by_names()</code>, which takes a list of names and returns a dictionary mapping names to components. This is particularly helpful with modular pipelines since they provide lists of required component names, and the returned dictionary can be directly passed to <code>pipeline.update_components()</code>.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><span class="hljs-comment"># Get components by name list</span> | |
| component_dict = comp.get_components_by_names(names=[<span class="hljs-string">"text_encoder"</span>, <span class="hljs-string">"unet"</span>, <span class="hljs-string">"vae"</span>]) | |
| <span class="hljs-comment"># Returns: {"text_encoder": component1, "unet": component2, "vae": component3}</span><!-- HTML_TAG_END --></pre></div> <h2 class="relative group"><a id="using-components-manager-with-modular-pipelines" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#using-components-manager-with-modular-pipelines"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Using Components Manager with Modular Pipelines</span></h2> <p data-svelte-h="svelte-100blqs">The Components Manager integrates seamlessly with Modular Pipelines. All you need to do is pass a Components Manager instance to <code>from_pretrained()</code> or <code>init_pipeline()</code> with an optional <code>collection</code> parameter:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><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">"YiYiXu/modular-demo-auto"</span>, components_manager=comp, collection=<span class="hljs-string">"test1"</span>)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1r9a5l6">By default, modular pipelines don’t load components immediately, so both the pipeline and Components Manager start empty:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><span class="hljs-meta">>>> </span>comp | |
| Components: | |
| ================================================== | |
| No components registered. | |
| ==================================================<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1c1n8d7">When you load components on the pipeline, they are automatically registered in the Components Manager:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><span class="hljs-meta">>>> </span>pipe.load_components(names=<span class="hljs-string">"unet"</span>) | |
| <span class="hljs-meta">>>> </span>comp | |
| Components: | |
| ============================================================================================================================================================== | |
| Models: | |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
| Name_ID | Class | Device: act(<span class="hljs-built_in">exec</span>) | Dtype | Size (GB) | Load ID | Collection | |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
| unet_139917726686304 | UNet2DConditionModel | cpu | torch.float32 | <span class="hljs-number">9.56</span> | SG161222/RealVisXL_V4<span class="hljs-number">.0</span>|unet|null|null | test1 | |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
| Additional Component Info: | |
| ==================================================<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-plz8fi">Now let’s load all default components and then create a second pipeline that reuses all components from the first one. We pass the same Components Manager to the second pipeline but with a different collection:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><span class="hljs-comment"># Load all default components </span> | |
| <span class="hljs-meta">>>> </span>pipe.load_default_components() | |
| <span class="hljs-comment"># Create a second pipeline using the same Components Manager but with a different collection</span> | |
| <span class="hljs-meta">>>> </span>pipe2 = ModularPipeline.from_pretrained(<span class="hljs-string">"YiYiXu/modular-demo-auto"</span>, components_manager=comp, collection=<span class="hljs-string">"test2"</span>)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1hkf10a">As mentioned earlier, <code>ModularPipeline</code> has a property <code>null_component_names</code> that returns a list of component names it needs to load. We can conveniently use this list with the <code>get_components_by_names</code> method on the Components Manager:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><span class="hljs-comment"># Get the list of components that pipe2 needs to load</span> | |
| <span class="hljs-meta">>>> </span>pipe2.null_component_names | |
| [<span class="hljs-string">'text_encoder'</span>, <span class="hljs-string">'text_encoder_2'</span>, <span class="hljs-string">'tokenizer'</span>, <span class="hljs-string">'tokenizer_2'</span>, <span class="hljs-string">'image_encoder'</span>, <span class="hljs-string">'unet'</span>, <span class="hljs-string">'vae'</span>, <span class="hljs-string">'scheduler'</span>, <span class="hljs-string">'controlnet'</span>] | |
| <span class="hljs-comment"># Retrieve all required components from the Components Manager</span> | |
| <span class="hljs-meta">>>> </span>comp_dict = comp.get_components_by_names(names=pipe2.null_component_names) | |
| <span class="hljs-comment"># Update the pipeline with the retrieved components</span> | |
| <span class="hljs-meta">>>> </span>pipe2.update_components(**comp_dict)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1s0kisf">The warnings that follow are expected and indicate that the Components Manager is correctly identifying that these components already exist and will be reused rather than creating duplicates:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START -->ComponentsManager: component <span class="hljs-string">'text_encoder'</span> already<span class="hljs-built_in"> exists</span> <span class="hljs-keyword">as</span> <span class="hljs-string">'text_encoder_139917586016400'</span> | |
| ComponentsManager: component <span class="hljs-string">'text_encoder_2'</span> already<span class="hljs-built_in"> exists</span> <span class="hljs-keyword">as</span> <span class="hljs-string">'text_encoder_2_139917699973424'</span> | |
| ComponentsManager: component <span class="hljs-string">'tokenizer'</span> already<span class="hljs-built_in"> exists</span> <span class="hljs-keyword">as</span> <span class="hljs-string">'tokenizer_139917580599504'</span> | |
| ComponentsManager: component <span class="hljs-string">'tokenizer_2'</span> already<span class="hljs-built_in"> exists</span> <span class="hljs-keyword">as</span> <span class="hljs-string">'tokenizer_2_139915763443904'</span> | |
| ComponentsManager: component <span class="hljs-string">'image_encoder'</span> already<span class="hljs-built_in"> exists</span> <span class="hljs-keyword">as</span> <span class="hljs-string">'image_encoder_139917722468304'</span> | |
| ComponentsManager: component <span class="hljs-string">'unet'</span> already<span class="hljs-built_in"> exists</span> <span class="hljs-keyword">as</span> <span class="hljs-string">'unet_139917580609632'</span> | |
| ComponentsManager: component <span class="hljs-string">'vae'</span> already<span class="hljs-built_in"> exists</span> <span class="hljs-keyword">as</span> <span class="hljs-string">'vae_139917722459040'</span> | |
| ComponentsManager: component <span class="hljs-string">'scheduler'</span> already<span class="hljs-built_in"> exists</span> <span class="hljs-keyword">as</span> <span class="hljs-string">'scheduler_139916266559408'</span> | |
| ComponentsManager: component <span class="hljs-string">'controlnet'</span> already<span class="hljs-built_in"> exists</span> <span class="hljs-keyword">as</span> <span class="hljs-string">'controlnet_139917722454432'</span><!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1hje7f8">The pipeline is now fully loaded:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><span class="hljs-comment"># null_component_names return empty list, meaning everything are loaded</span> | |
| <span class="hljs-meta">>>> </span>pipe2.null_component_names | |
| []<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1fm9inz">No new components were added to the Components Manager - we’re reusing everything. All models are now associated with both <code>test1</code> and <code>test2</code> collections, showing that these components are shared across multiple pipelines:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><span class="hljs-meta">>>> </span>comp | |
| Components: | |
| ======================================================================================================================================================================================== | |
| Models: | |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
| Name_ID | Class | Device: act(<span class="hljs-built_in">exec</span>) | Dtype | Size (GB) | Load ID | Collection | |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
| text_encoder_139917586016400 | CLIPTextModel | cpu | torch.float32 | <span class="hljs-number">0.46</span> | SG161222/RealVisXL_V4<span class="hljs-number">.0</span>|text_encoder|null|null | test1 | |
| | | | | | | test2 | |
| text_encoder_2_139917699973424 | CLIPTextModelWithProjection | cpu | torch.float32 | <span class="hljs-number">2.59</span> | SG161222/RealVisXL_V4<span class="hljs-number">.0</span>|text_encoder_2|null|null | test1 | |
| | | | | | | test2 | |
| unet_139917580609632 | UNet2DConditionModel | cpu | torch.float32 | <span class="hljs-number">9.56</span> | SG161222/RealVisXL_V4<span class="hljs-number">.0</span>|unet|null|null | test1 | |
| | | | | | | test2 | |
| controlnet_139917722454432 | ControlNetModel | cpu | torch.float32 | <span class="hljs-number">4.66</span> | diffusers/controlnet-canny-sdxl-<span class="hljs-number">1.0</span>|null|null|null | test1 | |
| | | | | | | test2 | |
| vae_139917722459040 | AutoencoderKL | cpu | torch.float32 | <span class="hljs-number">0.31</span> | SG161222/RealVisXL_V4<span class="hljs-number">.0</span>|vae|null|null | test1 | |
| | | | | | | test2 | |
| image_encoder_139917722468304 | CLIPVisionModelWithProjection | cpu | torch.float32 | <span class="hljs-number">6.87</span> | h94/IP-Adapter|sdxl_models/image_encoder|null|null | test1 | |
| | | | | | | test2 | |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
| Other Components: | |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
| ID | Class | Collection | |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
| tokenizer_139917580599504 | CLIPTokenizer | test1 | |
| | | test2 | |
| scheduler_139916266559408 | EulerDiscreteScheduler | test1 | |
| | | test2 | |
| tokenizer_2_139915763443904 | CLIPTokenizer | test1 | |
| | | test2 | |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
| Additional Component Info: | |
| ==================================================<!-- HTML_TAG_END --></pre></div> <h2 class="relative group"><a id="automatic-memory-management" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#automatic-memory-management"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Automatic Memory Management</span></h2> <p data-svelte-h="svelte-tj9te6">The Components Manager provides a global offloading strategy across all models, regardless of which pipeline is using them:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START -->comp.enable_auto_cpu_offload(device=<span class="hljs-string">"cuda"</span>)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-10kvsgb">When enabled, all models start on CPU. The manager moves models to the device right before they’re used and moves other models back to CPU when GPU memory runs low. You can set your own rules for which models to offload first. This works smoothly as you add or remove components. Once it’s on, you don’t need to worry about device placement - you can focus on your workflow.</p> <h2 class="relative group"><a id="practical-example-building-modular-workflows-with-component-reuse" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#practical-example-building-modular-workflows-with-component-reuse"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Practical Example: Building Modular Workflows with Component Reuse</span></h2> <p data-svelte-h="svelte-1ai6bmw">Now that we’ve covered the basics of the Components Manager, let’s walk through a practical example that shows how to build workflows in a modular setting and use the Components Manager to reuse components across multiple pipelines. This example demonstrates the true power of Modular Diffusers by working with multiple pipelines that can share components.</p> <p data-svelte-h="svelte-1ihez8m">In this example, we’ll generate latents from a text-to-image pipeline, then refine them with an image-to-image pipeline.</p> <p data-svelte-h="svelte-1ktoiwm">Let’s create a modular text-to-image workflow by separating it into three workflows: <code>text_blocks</code> for encoding prompts, <code>t2i_blocks</code> for generating latents, and <code>decoder_blocks</code> for creating final images.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><span class="hljs-keyword">import</span> torch | |
| <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> ALL_BLOCKS | |
| <span class="hljs-comment"># Create modular blocks and separate text encoding and decoding steps</span> | |
| t2i_blocks = SequentialPipelineBlocks.from_blocks_dict(ALL_BLOCKS[<span class="hljs-string">"text2img"</span>]) | |
| text_blocks = t2i_blocks.sub_blocks.pop(<span class="hljs-string">"text_encoder"</span>) | |
| decoder_blocks = t2i_blocks.sub_blocks.pop(<span class="hljs-string">"decode"</span>)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-x1zvdc">Now we will convert them into runnalbe pipelines and set up the Components Manager with auto offloading and organize components under a “t2i” collection</p> <p data-svelte-h="svelte-hnydim">Since we now have 3 different workflows that share components, we create a separate pipeline that serves as a dedicated loader to load all the components, register them to the component manager, and then reuse them across different workflows.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> ComponentsManager, ModularPipeline | |
| <span class="hljs-comment"># Set up Components Manager with auto offloading</span> | |
| components = ComponentsManager() | |
| components.enable_auto_cpu_offload(device=<span class="hljs-string">"cuda"</span>) | |
| <span class="hljs-comment"># Create a new pipeline to load the components</span> | |
| t2i_repo = <span class="hljs-string">"YiYiXu/modular-demo-auto"</span> | |
| t2i_loader_pipe = ModularPipeline.from_pretrained(t2i_repo, components_manager=components, collection=<span class="hljs-string">"t2i"</span>) | |
| <span class="hljs-comment"># convert the 3 blocks into pipelines and attach the same components manager to all 3</span> | |
| text_node = text_blocks.init_pipeline(t2i_repo, components_manager=components) | |
| decoder_node = decoder_blocks.init_pipeline(t2i_repo, components_manager=components) | |
| t2i_pipe = t2i_blocks.init_pipeline(t2i_repo, components_manager=components)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-lrhgu2">Load all components into the loader pipeline, they should all be automatically registered to Components Manager under the “t2i” collection:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><span class="hljs-comment"># Load all components (including IP-Adapter and ControlNet for later use)</span> | |
| t2i_loader_pipe.load_default_components(torch_dtype=torch.float16)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1yc206b">Now distribute the loaded components to each pipeline:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><span class="hljs-comment"># Get VAE for decoder (using get_one since there's only one)</span> | |
| vae = components.get_one(load_id=<span class="hljs-string">"SG161222/RealVisXL_V4.0|vae|null|null"</span>) | |
| decoder_node.update_components(vae=vae) | |
| <span class="hljs-comment"># Get text components for text node (using get_components_by_names for multiple components)</span> | |
| text_components = components.get_components_by_names(text_node.null_component_names) | |
| text_node.update_components(**text_components) | |
| <span class="hljs-comment"># Get remaining components for t2i pipeline</span> | |
| t2i_components = components.get_components_by_names(t2i_pipe.null_component_names) | |
| t2i_pipe.update_components(**t2i_components)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-9f8rck">Now we can generate images using our modular workflow:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><span class="hljs-comment"># Generate text embeddings</span> | |
| prompt = <span class="hljs-string">"an astronaut"</span> | |
| text_embeddings = text_node(prompt=prompt, output=[<span class="hljs-string">"prompt_embeds"</span>,<span class="hljs-string">"negative_prompt_embeds"</span>, <span class="hljs-string">"pooled_prompt_embeds"</span>, <span class="hljs-string">"negative_pooled_prompt_embeds"</span>]) | |
| <span class="hljs-comment"># Generate latents and decode to image</span> | |
| generator = torch.Generator(device=<span class="hljs-string">"cuda"</span>).manual_seed(<span class="hljs-number">0</span>) | |
| latents_t2i = t2i_pipe(**text_embeddings, num_inference_steps=<span class="hljs-number">25</span>, generator=generator, output=<span class="hljs-string">"latents"</span>) | |
| image = decoder_node(latents=latents_t2i, output=<span class="hljs-string">"images"</span>)[<span class="hljs-number">0</span>] | |
| image.save(<span class="hljs-string">"modular_part2_t2i.png"</span>)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1hml0o7">Let’s add a LoRA:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><span class="hljs-comment"># Load LoRA weights </span> | |
| <span class="hljs-meta">>>> </span>t2i_loader_pipe.load_lora_weights(<span class="hljs-string">"CiroN2022/toy-face"</span>, weight_name=<span class="hljs-string">"toy_face_sdxl.safetensors"</span>, adapter_name=<span class="hljs-string">"toy_face"</span>) | |
| <span class="hljs-meta">>>> </span>components | |
| Components: | |
| ============================================================================================================================================================ | |
| ... | |
| Additional Component Info: | |
| ================================================== | |
| unet: | |
| Adapters: [<span class="hljs-string">'toy_face'</span>]<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1rm09xq">You can see that the Components Manager tracks adapters metadata for all models it manages, and in our case, only Unet has lora loaded. This means we can reuse existing text embeddings.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><span class="hljs-comment"># Generate with LoRA (reusing existing text embeddings)</span> | |
| generator = torch.Generator(device=<span class="hljs-string">"cuda"</span>).manual_seed(<span class="hljs-number">0</span>) | |
| latents_lora = t2i_pipe(**text_embeddings, num_inference_steps=<span class="hljs-number">25</span>, generator=generator, output=<span class="hljs-string">"latents"</span>) | |
| image = decoder_node(latents=latents_lora, output=<span class="hljs-string">"images"</span>)[<span class="hljs-number">0</span>] | |
| image.save(<span class="hljs-string">"modular_part2_lora.png"</span>)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-7t7tuj">Now let’s create a refiner pipeline that reuses components from our text-to-image workflow:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><span class="hljs-comment"># Create refiner blocks (removing image_encoder and decode since we work with latents)</span> | |
| refiner_blocks = SequentialPipelineBlocks.from_blocks_dict(ALL_BLOCKS[<span class="hljs-string">"img2img"</span>]) | |
| refiner_blocks.sub_blocks.pop(<span class="hljs-string">"image_encoder"</span>) | |
| refiner_blocks.sub_blocks.pop(<span class="hljs-string">"decode"</span>) | |
| <span class="hljs-comment"># Create refiner pipeline with different repo and collection,</span> | |
| <span class="hljs-comment"># Attach the same component manager to it</span> | |
| refiner_repo = <span class="hljs-string">"YiYiXu/modular_refiner"</span> | |
| refiner_pipe = refiner_blocks.init_pipeline(refiner_repo, components_manager=components, collection=<span class="hljs-string">"refiner"</span>)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1af9qgx">We pass the <strong>same Components Manager</strong> (<code>components</code>) to the refiner pipeline, but with a <strong>different collection</strong> (<code>"refiner"</code>). This allows the refiner to access and reuse components from the “t2i” collection while organizing its own components (like the refiner UNet) under the “refiner” collection.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><span class="hljs-comment"># Load only the refiner UNet (different from t2i UNet)</span> | |
| refiner_pipe.load_components(names=<span class="hljs-string">"unet"</span>, torch_dtype=torch.float16) | |
| <span class="hljs-comment"># Reuse components from t2i pipeline using pattern matching</span> | |
| reuse_components = components.search_components(<span class="hljs-string">"text_encoder_2|scheduler|vae|tokenizer_2"</span>) | |
| refiner_pipe.update_components(**reuse_components)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-1a2xck9">When we reuse components from the “t2i” collection, they automatically get added to the “refiner” collection as well. You can verify this by checking the Components Manager - you’ll see components like <code>vae</code>, <code>scheduler</code>, etc. listed under both collections, indicating they’re shared between workflows.</p> <p data-svelte-h="svelte-znyiac">Now we can refine any of our generated latents:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg class="" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg> <div class="absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0"><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent; "></div> Copied</div></button></div> <pre class=""><!-- HTML_TAG_START --><span class="hljs-comment"># Refine all our different latents</span> | |
| refined_latents = refiner_pipe(image_latents=latents_t2i, prompt=prompt, num_inference_steps=<span class="hljs-number">10</span>, output=<span class="hljs-string">"latents"</span>) | |
| refined_image = decoder_node(latents=refined_latents, output=<span class="hljs-string">"images"</span>)[<span class="hljs-number">0</span>] | |
| refined_image.save(<span class="hljs-string">"modular_part2_t2i_refine_out.png"</span>) | |
| refined_latents = refiner_pipe(image_latents=latents_lora, prompt=prompt, num_inference_steps=<span class="hljs-number">10</span>, output=<span class="hljs-string">"latents"</span>) | |
| refined_image = decoder_node(latents=refined_latents, output=<span class="hljs-string">"images"</span>)[<span class="hljs-number">0</span>] | |
| refined_image.save(<span class="hljs-string">"modular_part2_lora_refine_out.png"</span>)<!-- HTML_TAG_END --></pre></div> <p data-svelte-h="svelte-19x7rhc">Here are the results from our modular pipeline examples.</p> <h4 class="relative group"><a id="base-text-to-image-generation" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#base-text-to-image-generation"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>Base Text-to-Image Generation</span></h4> <table data-svelte-h="svelte-1g0nloy"><thead><tr><th>Base Text-to-Image</th> <th>Base Text-to-Image (Refined)</th></tr></thead> <tbody><tr><td><img src="https://huggingface.co/datasets/YiYiXu/testing-images/resolve/main/modular_quicktour/modular_part2_t2i.png" alt="Base T2I"></td> <td><img src="https://huggingface.co/datasets/YiYiXu/testing-images/resolve/main/modular_quicktour/modular_part2_t2i_refine_out.png" alt="Base T2I Refined"></td></tr></tbody></table> <h4 class="relative group"><a id="lora" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#lora"><span><svg class="" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg></span></a> <span>LoRA</span></h4> <table data-svelte-h="svelte-tl7ulg"><thead><tr><th>LoRA</th> <th>LoRA (Refined)</th></tr></thead> <tbody><tr><td><img src="https://huggingface.co/datasets/YiYiXu/testing-images/resolve/main/modular_quicktour/modular_part2_lora.png" alt="LoRA"></td> <td><img src="https://huggingface.co/datasets/YiYiXu/testing-images/resolve/main/modular_quicktour/modular_part2_lora_refine_out.png" alt="LoRA Refined"></td></tr></tbody></table> <a class="!text-gray-400 !no-underline text-sm flex items-center not-prose mt-4" href="https://github.com/huggingface/diffusers/blob/main/docs/source/en/modular_diffusers/components_manager.md" target="_blank"><span data-svelte-h="svelte-1kd6by1"><</span> <span data-svelte-h="svelte-x0xyl0">></span> <span data-svelte-h="svelte-1dajgef"><span class="underline ml-1.5">Update</span> on GitHub</span></a> <p></p> | |
| <script> | |
| { | |
| __sveltekit_9fqn6m = { | |
| assets: "/docs/diffusers/pr_11797/en", | |
| base: "/docs/diffusers/pr_11797/en", | |
| env: {} | |
| }; | |
| const element = document.currentScript.parentElement; | |
| const data = [null,null]; | |
| Promise.all([ | |
| import("/docs/diffusers/pr_11797/en/_app/immutable/entry/start.2e1ee9a7.js"), | |
| import("/docs/diffusers/pr_11797/en/_app/immutable/entry/app.87c95e21.js") | |
| ]).then(([kit, app]) => { | |
| kit.start(app, element, { | |
| node_ids: [0, 228], | |
| data, | |
| form: null, | |
| error: null | |
| }); | |
| }); | |
| } | |
| </script> | |
Xet Storage Details
- Size:
- 100 kB
- Xet hash:
- c2ab0ee88c97e3366941404ced4934b5e0778b0e040fda13db2fdb4e051113b5
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.