Buckets:

mishig's picture
download
raw
55.1 kB
<meta charset="utf-8" /><meta name="hf:doc:metadata" content="{&quot;title&quot;:&quot;Início rápido&quot;,&quot;local&quot;:&quot;quickstart&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;Executar um pipeline&quot;,&quot;local&quot;:&quot;run-a-pipeline&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Entender a estrutura&quot;,&quot;local&quot;:&quot;understand-the-structure&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;Fluxos de trabalho&quot;,&quot;local&quot;:&quot;workflows&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;Sub-blocos&quot;,&quot;local&quot;:&quot;sub-blocks&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3}],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Crie novos fluxos de trabalho&quot;,&quot;local&quot;:&quot;compose-new-workflows&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Próximas etapas&quot;,&quot;local&quot;:&quot;next-steps&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2}],&quot;depth&quot;:1}"/>
<link href="/docs/diffusers/main/en/_app/immutable/entry/start.D3LnKZ4R.js" rel="modulepreload">
<link href="/docs/diffusers/main/en/_app/immutable/chunks/BF9UNEM9.js" rel="modulepreload">
<link href="/docs/diffusers/main/en/_app/immutable/chunks/DPnyVmXs.js" rel="modulepreload">
<link href="/docs/diffusers/main/en/_app/immutable/entry/app.C0rBoMxR.js" rel="modulepreload">
<link href="/docs/diffusers/main/en/_app/immutable/chunks/DSGUT_OW.js" rel="modulepreload">
<link href="/docs/diffusers/main/en/_app/immutable/chunks/C045MWWx.js" rel="modulepreload">
<link href="/docs/diffusers/main/en/_app/immutable/chunks/DnVIJfC5.js" rel="modulepreload">
<link href="/docs/diffusers/main/en/_app/immutable/chunks/DsnmJJEf.js" rel="modulepreload">
<link href="/docs/diffusers/main/en/_app/immutable/nodes/0.DTZsP_3B.js" rel="modulepreload">
<link href="/docs/diffusers/main/en/_app/immutable/chunks/IaDvMxLQ.js" rel="modulepreload">
<link href="/docs/diffusers/main/en/_app/immutable/nodes/308.4LFcl_q3.js" rel="modulepreload">
<link href="/docs/diffusers/main/en/_app/immutable/chunks/bKdwVYpU.js" rel="modulepreload">
<link href="/docs/diffusers/main/en/_app/immutable/chunks/DTd9IGSp.js" rel="modulepreload">
<!--1x94atl--><meta name="hf:doc:metadata" content="{&quot;title&quot;:&quot;Quickstart&quot;,&quot;local&quot;:&quot;quickstart&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;Run a pipeline&quot;,&quot;local&quot;:&quot;run-a-pipeline&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Understand the structure&quot;,&quot;local&quot;:&quot;understand-the-structure&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;Workflows&quot;,&quot;local&quot;:&quot;workflows&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;Sub-blocks&quot;,&quot;local&quot;:&quot;sub-blocks&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3}],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Compose new workflows&quot;,&quot;local&quot;:&quot;compose-new-workflows&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Next steps&quot;,&quot;local&quot;:&quot;next-steps&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2}],&quot;depth&quot;:1}"/><!---->
<link href="/docs/diffusers/main/en/_app/immutable/assets/0.tn0RQdqM.css" rel="modulepreload"> <!--[--><!--[0--><!--[--><!--[0--><!--[--><p></p> <div class="items-center shrink-0 min-w-[100px] max-sm:min-w-[50px] justify-end ml-auto flex" style="float: inline-end; margin-inline-start: 10px; display: inline-flex; position: relative; z-index: 10;"><div dir="ltr" class="inline-flex rounded-md max-sm:rounded-sm"><button class="inline-flex items-center gap-1 h-7 max-sm:h-7 px-2 max-sm:px-1.5 text-sm font-medium text-gray-800 border border-r-0 rounded-l-md max-sm:rounded-l-sm border-gray-200 bg-white hover:shadow-inner dark:border-gray-850 dark:bg-gray-950 dark:text-gray-200 dark:hover:bg-gray-800" aria-live="polite"><span class="inline-flex items-center justify-center rounded-md p-0.5 max-sm:p-0 hover:text-gray-800 dark:hover:text-gray-200"><svg class="sm:size-3.5 size-3" 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><!----></span> <span dir="auto">Copy page</span></button> <button class="inline-flex items-center justify-center w-6 max-sm:w-5 h-7 max-sm:h-7 disabled:pointer-events-none text-sm text-gray-500 hover:text-gray-700 dark:hover:text-white rounded-r-md max-sm:rounded-r-sm border border-l transition border-gray-200 bg-white hover:shadow-inner dark:border-gray-850 dark:bg-gray-950 dark:text-gray-200 dark:hover:bg-gray-800" aria-haspopup="menu" aria-expanded="false" aria-label="Open copy menu"><svg class="transition-transform text-gray-400 overflow-visible sm:size-3.5 size-3 rotate-0" width="1em" height="1em" viewBox="0 0 12 7" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1 1L6 6L11 1" stroke="currentColor"></path></svg><!----></button></div> <!--[-1--><!--]--></div><!----> <!--[0--><h1 class="relative group"><a id="quickstart" 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="#quickstart"><span><svg 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><!---->Início rápido<!----></span></h1><!--]--><!----> <p>Modular Diffusers é um framework para construir rapidamente pipelines flexíveis e personalizáveis. Esses pipelines podem ir além do que os <code>DiffusionPipeline</code> padrão conseguem fazer. No núcleo do Modular Diffusers estão os <a href="/docs/diffusers/main/pt/api/modular_diffusers/pipeline_blocks#diffusers.ModularPipelineBlocks">ModularPipelineBlocks</a>, que podem ser combinados com outros blocos para se adaptar a novos fluxos de trabalho. Os blocos são convertidos em um <a href="/docs/diffusers/main/pt/api/modular_diffusers/pipeline#diffusers.ModularPipeline">ModularPipeline</a>, uma interface amigável voltada para o usuário para executar tarefas de geração.</p> <p>Este guia mostra como executar um pipeline modular, entender sua estrutura e personalizá-lo modificando os blocos que o compõem. Se você está familiarizado com <a href="/docs/diffusers/main/pt/api/pipelines/overview#diffusers.DiffusionPipeline">DiffusionPipeline</a>, leia <a href="./coming_from_diffusion_pipeline">Vindo do DiffusionPipeline</a> primeiro para saber o que funciona de forma diferente.</p> <!--[1--><h2 class="relative group"><a id="run-a-pipeline" 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="#run-a-pipeline"><span><svg 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><!---->Executar um pipeline<!----></span></h2><!--]--><!----> <p><a href="/docs/diffusers/main/pt/api/modular_diffusers/pipeline#diffusers.ModularPipeline">ModularPipeline</a> é a interface principal para carregar, executar e gerenciar pipelines modulares.</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 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> Copiado</div><!----></button><!----></div> <pre class="language-py "><!----><span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> ModularPipeline, ComponentsManager
<span class="hljs-comment"># Use ComponentsManager to enable auto CPU offloading for memory efficiency</span>
manager = ComponentsManager()
manager.enable_auto_cpu_offload(device=<span class="hljs-string">&quot;cuda:0&quot;</span>)
pipe = ModularPipeline.from_pretrained(<span class="hljs-string">&quot;Qwen/Qwen-Image&quot;</span>, components_manager=manager)
pipe.load_components(dtype=torch.bfloat16)
image = pipe(
prompt=<span class="hljs-string">&quot;cat wizard with red hat, gandalf, lord of the rings, detailed, fantasy, cute, adorable, Pixar, Disney&quot;</span>,
).images[<span class="hljs-number">0</span>]
image<!----></pre></div><!----> <p><a href="/docs/diffusers/main/pt/api/modular_diffusers/pipeline#diffusers.ModularPipeline.from_pretrained">from_pretrained()</a> usa carregamento preguiçoso - ele lê a configuração para saber de onde carregar cada componente, mas não carrega os pesos do modelo de fato até você chamar <a href="/docs/diffusers/main/pt/api/modular_diffusers/pipeline#diffusers.ModularPipeline.load_components">load_components()</a>. Isso dá a você controle sobre quando e como os componentes são carregados.</p> <blockquote class="tip"><p><code>ComponentsManager</code> com <code>enable_auto_cpu_offload</code> move automaticamente os modelos entre a CPU e a GPU conforme necessário, reduzindo o uso de memória para modelos grandes como Qwen-Image. Saiba mais no guia <a href="./components_manager">ComponentsManager</a>.</p> <p>Se você não precisar de offloading, remova o argumento <code>components_manager</code> e mova o pipeline para o seu dispositivo manualmente com <code>to("cuda")</code>.</p></blockquote> <p>Saiba mais sobre a criação e o carregamento de pipelines nos guias <a href="./modular_pipeline#creating-a-pipeline">Criando um pipeline</a> e <a href="./modular_pipeline#loading-components">Carregando componentes</a>.</p> <!--[1--><h2 class="relative group"><a id="understand-the-structure" 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="#understand-the-structure"><span><svg 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><!---->Entender a estrutura<!----></span></h2><!--]--><!----> <p>A <a href="/docs/diffusers/main/pt/api/modular_diffusers/pipeline#diffusers.ModularPipeline">ModularPipeline</a> tem duas partes: uma <strong>definição</strong> (os blocos) e um <strong>estado</strong> (os componentes e configurações carregados).</p> <p>Imprima o pipeline para ver seu estado — os componentes e seu status de carregamento e configuração.</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 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> Copiado</div><!----></button><!----></div> <pre class="language-py "><!----><span class="hljs-built_in">print</span>(pipe)<!----></pre></div><!----> <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 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> Copiado</div><!----></button><!----></div> <pre class=" "><!----><span class="hljs-symbol">QwenImageModularPipeline</span> {
<span class="hljs-string">&quot;_blocks_class_name&quot;</span>: <span class="hljs-string">&quot;QwenImageAutoBlocks&quot;</span>,
<span class="hljs-string">&quot;_class_name&quot;</span>: <span class="hljs-string">&quot;QwenImageModularPipeline&quot;</span>,
<span class="hljs-string">&quot;_diffusers_version&quot;</span>: <span class="hljs-string">&quot;0.37.0.dev0&quot;</span>,
<span class="hljs-string">&quot;transformer&quot;</span>: [
<span class="hljs-string">&quot;diffusers&quot;</span>,
<span class="hljs-string">&quot;QwenImageTransformer2DModel&quot;</span>,
{
<span class="hljs-string">&quot;pretrained_model_name_or_path&quot;</span>: <span class="hljs-string">&quot;Qwen/Qwen-Image&quot;</span>,
<span class="hljs-string">&quot;revision&quot;</span>: null,
<span class="hljs-string">&quot;subfolder&quot;</span>: <span class="hljs-string">&quot;transformer&quot;</span>,
<span class="hljs-string">&quot;type_hint&quot;</span>: [
<span class="hljs-string">&quot;diffusers&quot;</span>,
<span class="hljs-string">&quot;QwenImageTransformer2DModel&quot;</span>
],
<span class="hljs-string">&quot;variant&quot;</span>: null
}
],
...
}<!----></pre></div><!----> <p>Acesse a definição por meio de <code>pipe.blocks</code> — este é o <a href="/docs/diffusers/main/pt/api/modular_diffusers/pipeline_blocks#diffusers.ModularPipelineBlocks">ModularPipelineBlocks</a> que define os fluxos de trabalho, entradas, saídas e a lógica de computação do 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 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> Copiado</div><!----></button><!----></div> <pre class="language-py "><!----><span class="hljs-built_in">print</span>(pipe.blocks)<!----></pre></div><!----> <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 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> Copiado</div><!----></button><!----></div> <pre class=" "><!---->QwenImageAutoBlocks(
Class: SequentialPipelineBlocks
Description: Auto Modular pipeline <span class="hljs-keyword">for</span> <span class="hljs-keyword">text</span>-to-<span class="hljs-keyword">image</span>, <span class="hljs-keyword">image</span>-to-<span class="hljs-keyword">image</span>, inpainting, and controlnet tasks using QwenImage.
Supported workflows:
- <span class="hljs-string">`text2image`</span>: <span class="hljs-keyword">requires</span> <span class="hljs-string">`prompt`</span>
- <span class="hljs-string">`image2image`</span>: <span class="hljs-keyword">requires</span> <span class="hljs-string">`prompt`</span>, <span class="hljs-string">`image`</span>
- <span class="hljs-string">`inpainting`</span>: <span class="hljs-keyword">requires</span> <span class="hljs-string">`prompt`</span>, <span class="hljs-string">`mask_image`</span>, <span class="hljs-string">`image`</span>
- <span class="hljs-string">`controlnet_text2image`</span>: <span class="hljs-keyword">requires</span> <span class="hljs-string">`prompt`</span>, <span class="hljs-string">`control_image`</span>
...
Components:
text_encoder (<span class="hljs-string">`Qwen2_5_VLForConditionalGeneration`</span>)
vae (<span class="hljs-string">`AutoencoderKLQwenImage`</span>)
transformer (<span class="hljs-string">`QwenImageTransformer2DModel`</span>)
...
Sub-Blocks:
[<span class="hljs-number">0</span>] text_encoder (QwenImageAutoTextEncoderStep)
[<span class="hljs-number">1</span>] vae_encoder (QwenImageAutoVaeEncoderStep)
[<span class="hljs-number">2</span>] controlnet_vae_encoder (QwenImageOptionalControlNetVaeEncoderStep)
[<span class="hljs-number">3</span>] denoise (QwenImageAutoCoreDenoiseStep)
[<span class="hljs-number">4</span>] decode (QwenImageAutoDecodeStep)
)<!----></pre></div><!----> <p>A saída retorna:</p> <ul><li>Os fluxos de trabalho suportados (text2image, image2image, inpainting, etc.)</li> <li>Os Sub-Blocks dos quais é composto (text_encoder, vae_encoder, denoise, decode)</li></ul> <!--[2--><h3 class="relative group"><a id="workflows" 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="#workflows"><span><svg 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><!---->Fluxos de trabalho<!----></span></h3><!--]--><!----> <p>Este pipeline suporta vários fluxos de trabalho e adapta seu comportamento com base nas entradas que você fornece. Por exemplo, se você passar <code>image</code> para o pipeline, ele executa um fluxo de trabalho de imagem para imagem em vez de texto para imagem. Saiba mais sobre como isso funciona por baixo dos panos no guia <a href="./auto_pipeline_blocks">AutoPipelineBlocks</a>.</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 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> Copiado</div><!----></button><!----></div> <pre class="language-py "><!----><span class="hljs-keyword">from</span> diffusers.utils <span class="hljs-keyword">import</span> load_image
input_image = load_image(<span class="hljs-string">&quot;https://github.com/Trgtuan10/Image_storage/blob/main/cute_cat.png?raw=true&quot;</span>)
image = pipe(
prompt=<span class="hljs-string">&quot;cat wizard with red hat, gandalf, lord of the rings, detailed, fantasy, cute, adorable, Pixar, Disney&quot;</span>,
image=input_image,
).images[<span class="hljs-number">0</span>]<!----></pre></div><!----> <p>Use <code>get_workflow()</code> para extrair os blocos de um workflow específico. Passe o nome do workflow (por exemplo, <code>"image2image"</code>, <code>"inpainting"</code>, <code>"controlnet_text2image"</code>) para obter apenas os blocos relevantes para aquele workflow. Isso é útil quando você deseja personalizar ou depurar um workflow específico. Você pode verificar <code>pipe.blocks.available_workflows</code> para ver todos os workflows disponíveis.</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 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> Copiado</div><!----></button><!----></div> <pre class="language-py "><!---->img2img_blocks = pipe.blocks.get_workflow(<span class="hljs-string">&quot;image2image&quot;</span>)<!----></pre></div><!----> <!--[2--><h3 class="relative group"><a id="sub-blocks" 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="#sub-blocks"><span><svg 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><!---->Sub-blocos<!----></span></h3><!--]--><!----> <p>Blocos podem conter outros blocos. <code>pipe.blocks</code> fornece a definição do bloco de nível superior (aqui, <code>QwenImageAutoBlocks</code>), enquanto <code>sub_blocks</code> permite acessar os blocos menores dentro dele.</p> <p><code>QwenImageAutoBlocks</code> é composto por: <code>text_encoder</code>, <code>vae_encoder</code>, <code>controlnet_vae_encoder</code>, <code>denoise</code> e <code>decode</code>.</p> <p>Esses sub-blocos são executados um após o outro e os dados fluem linearmente de um bloco para o próximo — os <code>intermediate_outputs</code> de cada bloco ficam disponíveis como <code>inputs</code> para o bloco seguinte. É assim que o <a href="./sequential_pipeline_blocks"><code>SequentialPipelineBlocks</code></a> funciona.</p> <p>Você pode acessá-los por meio da propriedade <code>sub_blocks</code>. A propriedade <code>doc</code> é útil para ver a documentação completa de qualquer bloco, incluindo suas entradas, saídas e componentes.</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 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> Copiado</div><!----></button><!----></div> <pre class="language-py "><!---->vae_encoder_block = pipe.blocks.sub_blocks[<span class="hljs-string">&quot;vae_encoder&quot;</span>]
<span class="hljs-built_in">print</span>(vae_encoder_block.doc)<!----></pre></div><!----> <p>Este bloco pode ser convertido em um pipeline para que ele possa ser executado de forma independente com <a href="/docs/diffusers/main/pt/api/modular_diffusers/pipeline_blocks#diffusers.ModularPipelineBlocks.init_pipeline">init_pipeline()</a>.</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 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> Copiado</div><!----></button><!----></div> <pre class="language-py "><!---->vae_encoder_pipe = vae_encoder_block.init_pipeline()
<span class="hljs-comment"># Reuse the VAE we already loaded, we can reuse it with update_components() method</span>
vae_encoder_pipe.update_components(vae=pipe.vae)
<span class="hljs-comment"># Run just this block</span>
image_latents = vae_encoder_pipe(image=input_image).image_latents
<span class="hljs-built_in">print</span>(image_latents.shape)<!----></pre></div><!----> <p>Ele reutiliza o VAE do nosso pipeline original em vez de recarregá-lo, mantendo o uso de memória eficiente. Saiba mais no guia <a href="./modular_pipeline#loading-components">Carregando componentes</a>.</p> <p>Como os blocos são composíveis, você pode modificar a definição do pipeline adicionando, removendo ou substituindo blocos para criar novos fluxos de trabalho. Na próxima seção, adicionaremos um bloco de detecção de bordas canny a um pipeline ControlNet, para que você possa passar uma imagem comum em vez de um mapa de bordas canny pré-processado.</p> <!--[1--><h2 class="relative group"><a id="compose-new-workflows" 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="#compose-new-workflows"><span><svg 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><!---->Crie novos fluxos de trabalho<!----></span></h2><!--]--><!----> <p>Vamos adicionar um bloco de detecção de bordas canny a um pipeline do ControlNet. Primeiro, carregue um bloco canny pré-construído do Hub (veja <a href="./custom_blocks">Building Custom Blocks</a> para criar o seu próprio).</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 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> Copiado</div><!----></button><!----></div> <pre class="language-py "><!----><span class="hljs-keyword">from</span> diffusers.modular_pipelines <span class="hljs-keyword">import</span> ModularPipelineBlocks
<span class="hljs-comment"># Load a canny block from the Hub</span>
canny_block = ModularPipelineBlocks.from_pretrained(
<span class="hljs-string">&quot;diffusers-internal-dev/canny-filtering&quot;</span>,
trust_remote_code=<span class="hljs-literal">True</span>,
)
<span class="hljs-built_in">print</span>(canny_block.doc)<!----></pre></div><!----> <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 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> Copiado</div><!----></button><!----></div> <pre class=" "><!---->class CannyBlock
Inputs:
image (`Union[Image, ndarray]`):
Image <span class="hljs-keyword">to</span> compute canny <span class="hljs-built_in">filter</span> <span class="hljs-keyword">on</span>
low_threshold (`<span class="hljs-keyword">int</span>`, *optional*, defaults <span class="hljs-keyword">to</span> <span class="hljs-number">50</span>):
Low threshold <span class="hljs-keyword">for</span> the canny <span class="hljs-built_in">filter</span>.
high_threshold (`<span class="hljs-keyword">int</span>`, *optional*, defaults <span class="hljs-keyword">to</span> <span class="hljs-number">200</span>):
High threshold <span class="hljs-keyword">for</span> the canny <span class="hljs-built_in">filter</span>.
...
Outputs:
control_image (`PIL.Image`):
Canny <span class="hljs-keyword">map</span> <span class="hljs-keyword">for</span> <span class="hljs-built_in">input</span> image<!----></pre></div><!----> <p>Use <code>get_workflow</code> para extrair o workflow do ControlNet de <code>QwenImageAutoBlocks</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 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> Copiado</div><!----></button><!----></div> <pre class="language-py "><!----><span class="hljs-comment"># Get the controlnet workflow that we want to work with</span>
blocks = pipe.blocks.get_workflow(<span class="hljs-string">&quot;controlnet_text2image&quot;</span>)
<span class="hljs-built_in">print</span>(blocks.doc)<!----></pre></div><!----> <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 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> Copiado</div><!----></button><!----></div> <pre class=" "><!---->class <span class="hljs-symbol">SequentialPipelineBlocks</span>
<span class="hljs-symbol">Inputs</span>:
prompt (<span class="hljs-string">`str`</span>):
<span class="hljs-symbol">The</span> prompt or prompts to guide image generation.
control_image (<span class="hljs-string">`Image`</span>):
<span class="hljs-symbol">Control</span> image for <span class="hljs-symbol">ControlNet</span> conditioning.
...<!----></pre></div><!----> <p>O workflow extraído é um <a href="./sequential_pipeline_blocks"><code>SequentialPipelineBlocks</code></a> e atualmente requer <code>control_image</code> como entrada. Insira o bloco canny no início para que o pipeline aceite uma imagem comum.</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 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> Copiado</div><!----></button><!----></div> <pre class="language-py "><!----><span class="hljs-comment"># Insert canny at the beginning</span>
blocks.sub_blocks.insert(<span class="hljs-string">&quot;canny&quot;</span>, canny_block, <span class="hljs-number">0</span>)
<span class="hljs-comment"># Check the updated structure: CannyBlock is now listed as first sub-block</span>
<span class="hljs-built_in">print</span>(blocks)
<span class="hljs-comment"># Check the updated doc</span>
<span class="hljs-built_in">print</span>(blocks.doc)<!----></pre></div><!----> <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 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> Copiado</div><!----></button><!----></div> <pre class=" "><!---->class SequentialPipelineBlocks
Inputs:
image (<span class="hljs-string">`Union[Image, ndarray]`</span>):
Image <span class="hljs-keyword">to</span> compute canny filter <span class="hljs-keyword">on</span>
low_threshold (<span class="hljs-string">`int`</span>, *optional*, defaults <span class="hljs-keyword">to</span> <span class="hljs-number">50</span>):
Low threshold for the canny filter.
high_threshold (<span class="hljs-string">`int`</span>, *optional*, defaults <span class="hljs-keyword">to</span> <span class="hljs-number">200</span>):
High threshold for the canny filter.
prompt (<span class="hljs-string">`str`</span>):
The prompt <span class="hljs-literal">or</span> prompts <span class="hljs-keyword">to</span> guide image generation.
<span class="hljs-params">...</span><!----></pre></div><!----> <p>Agora o pipeline recebe <code>image</code> como entrada em vez de <code>control_image</code>. Como os blocos em uma sequência compartilham dados automaticamente, a saída do bloco canny (<code>control_image</code>) flui para o bloco denoise que precisa dela, e a entrada do bloco canny (<code>image</code>) se torna uma entrada do pipeline, já que nenhum bloco anterior a fornece.</p> <p>Crie um pipeline a partir dos blocos modificados e carregue um modelo ControlNet. O ControlNet não faz parte do repositório original do modelo, portanto, carregue-o separadamente e adicione-o com <a href="/docs/diffusers/main/pt/api/modular_diffusers/pipeline#diffusers.ModularPipeline.update_components">update_components()</a>.</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 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> Copiado</div><!----></button><!----></div> <pre class="language-py "><!---->pipeline = blocks.init_pipeline(<span class="hljs-string">&quot;Qwen/Qwen-Image&quot;</span>, components_manager=manager)
pipeline.load_components(dtype=torch.bfloat16)
<span class="hljs-comment"># Load the ControlNet model</span>
controlnet_spec = pipeline.get_component_spec(<span class="hljs-string">&quot;controlnet&quot;</span>)
controlnet_spec.pretrained_model_name_or_path = <span class="hljs-string">&quot;InstantX/Qwen-Image-ControlNet-Union&quot;</span>
controlnet = controlnet_spec.load(dtype=torch.bfloat16)
pipeline.update_components(controlnet=controlnet)<!----></pre></div><!----> <p>Agora execute o pipeline - o bloco canny pré-processa a imagem para o ControlNet.</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 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> Copiado</div><!----></button><!----></div> <pre class="language-py "><!----><span class="hljs-keyword">from</span> diffusers.utils <span class="hljs-keyword">import</span> load_image
prompt = <span class="hljs-string">&quot;cat wizard with red hat, gandalf, lord of the rings, detailed, fantasy, cute, adorable, Pixar, Disney&quot;</span>
image = load_image(<span class="hljs-string">&quot;https://github.com/Trgtuan10/Image_storage/blob/main/cute_cat.png?raw=true&quot;</span>)
output = pipeline(
prompt=prompt,
image=image,
).images[<span class="hljs-number">0</span>]
output<!----></pre></div><!----> <!--[1--><h2 class="relative group"><a id="next-steps" 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="#next-steps"><span><svg 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><!---->Próximas etapas<!----></span></h2><!--]--><!----> <div class="flex space-x-2 items-center my-1.5 mr-8 h-7 !pl-0 -mx-3 md:mx-0"><!--[--><div class="flex items-center border rounded-lg px-1.5 py-1 leading-none select-none text-smd border-gray-800 bg-black dark:bg-gray-700 text-white">Aprenda os fundamentos</div><div class="flex items-center border rounded-lg px-1.5 py-1 leading-none select-none text-smd text-gray-500 cursor-pointer opacity-90 hover:text-gray-700 dark:hover:text-gray-200 hover:shadow-sm">Crie blocos personalizados</div><div class="flex items-center border rounded-lg px-1.5 py-1 leading-none select-none text-smd text-gray-500 cursor-pointer opacity-90 hover:text-gray-700 dark:hover:text-gray-200 hover:shadow-sm">Compartilhar componentes</div><div class="flex items-center border rounded-lg px-1.5 py-1 leading-none select-none text-smd text-gray-500 cursor-pointer opacity-90 hover:text-gray-700 dark:hover:text-gray-200 hover:shadow-sm">Interface visual</div><!--]--></div> <div class="language-select"><div><p>Entenda os blocos de construção fundamentais do Modular Diffusers:</p> <ul><li><a href="./pipeline_block">ModularPipelineBlocks</a>: a unidade básica para definir uma etapa em um pipeline.</li> <li><a href="./sequential_pipeline_blocks">SequentialPipelineBlocks</a>: Encadeia blocos para executá-los em sequência.</li> <li><a href="./auto_pipeline_blocks">AutoPipelineBlocks</a>: Crie pipelines que suportam múltiplos fluxos de trabalho.</li> <li><a href="./modular_diffusers_states">Estados</a>: Como os dados são compartilhados entre blocos.</li></ul><!----></div><!----> <div hidden=""><p>Aprenda a criar seus próprios blocos com lógica personalizada no guia <a href="./custom_blocks">Building Custom Blocks</a>.</p><!----></div><!----> <div hidden=""><p>Use <a href="./components_manager"><code>ComponentsManager</code></a> para compartilhar modelos entre vários pipelines e gerenciar a memória de forma eficiente.</p><!----></div><!----> <div hidden=""><p>Conecte pipelines modulares ao <a href="https://github.com/cubiq/Mellon" rel="nofollow">Mellon</a>, uma interface visual baseada em nós para a criação de fluxos de trabalho. Blocos personalizados criados com Modular Diffusers funcionam imediatamente com o Mellon - sem necessidade de código de interface. Leia mais no guia do Mellon.</p><!----></div><!----><!----></div><!----> <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/quickstart.md" target="_blank"><svg class="mr-1" 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="M31,16l-7,7l-1.41-1.41L28.17,16l-5.58-5.59L24,9l7,7z"></path><path d="M1,16l7-7l1.41,1.41L3.83,16l5.58,5.59L8,23l-7-7z"></path><path d="M12.419,25.484L17.639,6.552l1.932,0.518L14.351,26.002z"></path></svg><!----> <span><span class="underline">Update</span> on GitHub</span></a><!----> <p></p><!--]--><!----><!--]--><!--]--><!--]--> <!--[-1--><!--]--><!--]-->
<script>
{
__sveltekit_g37pnb = {
base: "/docs/diffusers/main/en",
assets: "/docs/diffusers/main/en"
};
const element = document.currentScript.parentElement;
Promise.all([
import("/docs/diffusers/main/en/_app/immutable/entry/start.D3LnKZ4R.js"),
import("/docs/diffusers/main/en/_app/immutable/entry/app.C0rBoMxR.js")
]).then(([kit, app]) => {
kit.start(app, element, {
node_ids: [0, 308],
data: [null,null],
form: null,
error: null
});
});
}
</script>

Xet Storage Details

Size:
55.1 kB
·
Xet hash:
40c23fd7e6ec4c389b5ccca09ec7f6f4d4181ed1c3f7a808525fb5580ca8ab41

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.