Buckets:

mishig's picture
download
raw
57.6 kB
<meta charset="utf-8" /><meta name="hf:doc:metadata" content="{&quot;title&quot;:&quot;البدء السريع&quot;,&quot;local&quot;:&quot;quickstart&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;تشغيل خط أنابيب&quot;,&quot;local&quot;:&quot;run-a-pipeline&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;فهم البنية&quot;,&quot;local&quot;:&quot;understand-the-structure&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;سير العمل&quot;,&quot;local&quot;:&quot;workflows&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;الكتل الفرعية&quot;,&quot;local&quot;:&quot;sub-blocks&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3}],&quot;depth&quot;:2},{&quot;title&quot;:&quot;إنشاء سير عمل جديدة&quot;,&quot;local&quot;:&quot;compose-new-workflows&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;الخطوات التالية&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.0S0_iEoG.js" rel="modulepreload">
<link href="/docs/diffusers/main/en/_app/immutable/chunks/I9eooN77.js" rel="modulepreload">
<link href="/docs/diffusers/main/en/_app/immutable/chunks/Bupkjr9f.js" rel="modulepreload">
<link href="/docs/diffusers/main/en/_app/immutable/entry/app.CPdOxCbw.js" rel="modulepreload">
<link href="/docs/diffusers/main/en/_app/immutable/chunks/CyvZ3FS5.js" rel="modulepreload">
<link href="/docs/diffusers/main/en/_app/immutable/chunks/l0QnnOED.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.DteTvmQZ.js" rel="modulepreload">
<link href="/docs/diffusers/main/en/_app/immutable/chunks/CoSrdQax.js" rel="modulepreload">
<link href="/docs/diffusers/main/en/_app/immutable/nodes/328.g2gShkQF.js" rel="modulepreload">
<link href="/docs/diffusers/main/en/_app/immutable/chunks/DSPDl1gz.js" rel="modulepreload">
<link href="/docs/diffusers/main/en/_app/immutable/chunks/D5eijdnr.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><!---->البدء السريع<!----></span></h1><!--]--><!----> <p>يعتبر Modular Diffusers إطارًا لبناء خطوط أنابيب مرنة وقابلة للتخصيص بسرعة. يمكن لهذه الخطوط أن تتجاوز ما يمكن أن تفعله خطوط <code>DiffusionPipeline</code> القياسية. جوهر Modular Diffusers هو <a href="/docs/diffusers/v0.43.0/ar/api/modular_diffusers/pipeline_blocks#diffusers.ModularPipelineBlocks">ModularPipelineBlocks</a> التي يمكن دمجها مع كتل أخرى للتكيف مع سير عمل جديدة. يتم تحويل هذه الكتل إلى <a href="/docs/diffusers/v0.43.0/ar/api/modular_diffusers/pipeline#diffusers.ModularPipeline">ModularPipeline</a>، وهو واجهة موجهة للمستخدم وسهلة الاستخدام لتنفيذ مهام التوليد.</p> <p>يُظهر لك هذا الدليل كيفية تشغيل خط أنابيب معياري، وفهم بنيته، وتخصيصه من خلال تعديل الوحدات المكوّنة له. إذا كنت على دراية بـ <a href="/docs/diffusers/v0.43.0/ar/api/pipelines/overview#diffusers.DiffusionPipeline">DiffusionPipeline</a>، فاقرأ <a href="./coming_from_diffusion_pipeline">Coming from DiffusionPipeline</a> أولاً لمعرفة ما الذي يعمل بشكل مختلف.</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><!---->تشغيل خط أنابيب<!----></span></h2><!--]--><!----> <p><a href="/docs/diffusers/v0.43.0/ar/api/modular_diffusers/pipeline#diffusers.ModularPipeline">ModularPipeline</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> تم النسخ</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/v0.43.0/ar/api/modular_diffusers/pipeline#diffusers.ModularPipeline.from_pretrained">from_pretrained()</a> التحميل الكسول - إذ يقرأ الإعدادات لمعرفة مكان تحميل كل مكوّن من، لكنه لا يحمّل أوزان النموذج فعليًا حتى تستدعي <a href="/docs/diffusers/v0.43.0/ar/api/modular_diffusers/pipeline#diffusers.ModularPipeline.load_components">load_components()</a>. ومنحًا لك ذلك سيطرة على متى وكيف يتم تحميل المكوّنات.</p> <blockquote class="tip"><p>ينقل <code>ComponentsManager</code> مع <code>enable_auto_cpu_offload</code> النماذج تلقائيًا بين وحدة المعالجة المركزية (CPU) ووحدة معالجة الرسوميات (GPU) حسب الحاجة، مما يقلل من استهلاك الذاكرة للنماذج الكبيرة مثل Qwen-Image. لمعرفة المزيد، راجع دليل <a href="./components_manager">ComponentsManager</a>.</p> <p>إذا لم تكن بحاجة إلى نقل المكونات، احذف معامل <code>components_manager</code> وانقل خط الأنابيب إلى جهازك يدويًا باستخدام <code>to("cuda")</code>.</p></blockquote> <p>تعرّف على المزيد حول إنشاء خطوط الأنابيب وتحميلها في دليلَي <a href="https://huggingface.co/docs/diffusers/modular_diffusers/modular_pipeline#creating-a-pipeline" rel="nofollow">إنشاء خط أنابيب</a> و<a href="https://huggingface.co/docs/diffusers/modular_diffusers/modular_pipeline#loading-components" rel="nofollow">تحميل المكونات</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><!---->فهم البنية<!----></span></h2><!--]--><!----> <p>يتكون <a href="/docs/diffusers/v0.43.0/ar/api/modular_diffusers/pipeline#diffusers.ModularPipeline">ModularPipeline</a> من جزأين: <strong>تعريف</strong> (الكتل) و<strong>حالة</strong> (المكونات والإعدادات المحمّلة).</p> <p>اطبع خط الأنابيب لرؤية حالته — المكونات وحالة تحميلها وإعداداتها.</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> تم النسخ</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> تم النسخ</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>الوصول إلى التعريف عبر <code>pipe.blocks</code> — هذا هو <a href="/docs/diffusers/v0.43.0/ar/api/modular_diffusers/pipeline_blocks#diffusers.ModularPipelineBlocks">ModularPipelineBlocks</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> تم النسخ</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> تم النسخ</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>يعيد المخرَج:</p> <ul><li>سير العمل المدعومة (text2image، image2image، inpainting، إلخ)</li> <li>المكونات الفرعية التي يتكون منها (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><!---->سير العمل<!----></span></h3><!--]--><!----> <p>يدعم هذا الخط أنماط عمل متعددة ويكيّف سلوكه بناءً على المدخلات التي تزوّده بها. فعلى سبيل المثال، إذا مرّرت <code>image</code> إلى الخط، فإنه ينفّذ نمط عمل من صورة إلى صورة بدلاً من النص إلى صورة. تعرّف على المزيد حول آلية العمل الداخلية في دليل <a href="https://huggingface.co/docs/diffusers/modular_diffusers/auto_pipeline_blocks" rel="nofollow">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> تم النسخ</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>استخدم <code>get_workflow()</code> لاستخراج الكتل الخاصة بعملية محددة. مرر اسم العملية (مثل <code>"image2image"</code>، <code>"inpainting"</code>، <code>"controlnet_text2image"</code>) للحصول على الكتل ذات الصلة بتلك العملية فقط. وهذا مفيد عندما تريد تخصيص عملية محددة أو تصحيح أخطائها. يمكنك التحقق من <code>pipe.blocks.available_workflows</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> تم النسخ</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><!---->الكتل الفرعية<!----></span></h3><!--]--><!----> <p>يمكن أن تحتوي الكتل على كتل أخرى. يمنحك <code>pipe.blocks</code> تعريف الكتلة على المستوى الأعلى (وهنا <code>QwenImageAutoBlocks</code>)، بينما يتيح لك <code>sub_blocks</code> الوصول إلى الكتل الأصغر داخلها.</p> <p>يتكوّن <code>QwenImageAutoBlocks</code> من: <code>text_encoder</code>، و<code>vae_encoder</code>، و<code>controlnet_vae_encoder</code>، و<code>denoise</code>، و<code>decode</code>.</p> <p>تعمل هذه الكتل الفرعية تباعًا، ويتدفق الخطر بشكل خطي من كتلة إلى التالية — حيث تصبح <code>intermediate_outputs</code> لكل كتلة متاحة كـ<code>inputs</code> للكتلة التالية. بهذه الطريقة تعمل <a href="./sequential_pipeline_blocks"><code>SequentialPipelineBlocks</code></a>.</p> <p>يمكنك الوصول إليها من خلال خاصية <code>sub_blocks</code>. وتُعد خاصية <code>doc</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> تم النسخ</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>يمكن تحويل هذا الكتلة إلى خط أنابيب بحيث يمكن تشغيله بشكل مستقل باستخدام <a href="/docs/diffusers/v0.43.0/ar/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> تم النسخ</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>يعيد استخدام VAE من خط أنابيبنا الأصلي بدلاً من إعادة تحميله، مما يحافظ على كفاءة استخدام الذاكرة. لمعرفة المزيد، راجع دليل <a href="https://huggingface.co/docs/diffusers/modular_diffusers/modular_pipeline#loading-components" rel="nofollow">تحميل المكونات</a>.</p> <p>بما أن الكتل قابلة للتركيب، يمكنك تعديل تعريف خط الأنابيب عن طريق إضافة كتل أو إزالتها أو استبدالها لإنشاء مسارات عمل جديدة. في القسم التالي، سنضيف كتلة كشف الحواف باستخدام canny إلى خط أنابيب ControlNet، بحيث يمكنك تمرير صورة عادية بدلاً من خريطة حواف canny مُعالجة مسبقًا.</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><!---->إنشاء سير عمل جديدة<!----></span></h2><!--]--><!----> <p>لنقم بإضافة كتلة كشف الحواف باستخدام canny إلى خط أنابيب ControlNet. أولاً، حمّل كتلة canny جاهزة من Hub (انظر <a href="https://huggingface.co/docs/diffusers/modular_diffusers/custom_blocks" rel="nofollow">بناء كتل مخصصة</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> تم النسخ</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> تم النسخ</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>استخدم <code>get_workflow</code> لاستخراج سير عمل ControlNet من <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> تم النسخ</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> تم النسخ</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>السيرورة المستخرجة هي <a href="./sequential_pipeline_blocks"><code>SequentialPipelineBlocks</code></a> وهي تتطلب حاليًا <code>control_image</code> كمدخل. أدرج كتلة canny في البداية بحيث تقبل السيرورة صورة عادية بدلاً من ذلك.</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> تم النسخ</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> تم النسخ</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>الآن يستقبل خط الأنابيب <code>image</code> كمدخل بدلاً من <code>control_image</code>. وبما أن الكتل في تسلسل ما تتشارك البيانات تلقائياً، فإن مخرج كتلة canny (<code>control_image</code>) يتدفق إلى كتلة إزالة الضوضاء التي تحتاج إليه، ويصبح مدخل كتلة canny (<code>image</code>) مدخلاً لخط الأنابيب لأن لا كتلة سابقة توفره.</p> <p>أنشئ خط أنابيب من الكتل المعدّلة ثم حمّل نموذج ControlNet. نظراً لأن ControlNet ليس جزءاً من مستودع النموذج الأصلي، فحمّله بشكل منفصل وأضفه باستخدام <a href="/docs/diffusers/v0.43.0/ar/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> تم النسخ</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>الآن شغّل خط الأنابيب - حيث يعالج كتلة canny الصورة مسبقًا من أجل 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> تم النسخ</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><!---->الخطوات التالية<!----></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">تعلم الأساسيات</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">بناء كتل مخصصة</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">مشاركة المكونات</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">الواجهة البصرية</div><!--]--></div> <div class="language-select"><div><p>افهم العناصر الأساسية المكوِّنة لـ Modular Diffusers:</p> <ul><li><a href="./pipeline_block">ModularPipelineBlocks</a>: الوحدة الأساسية لتحديد خطوة في خط الأنابيب.</li> <li><a href="./sequential_pipeline_blocks">SequentialPipelineBlocks</a>: تسلسل الكتل لتنفيذها بالترتيب.</li> <li><a href="./auto_pipeline_blocks">AutoPipelineBlocks</a>: إنشاء خطوط أنابيب تدعم سير عمل متعددة.</li> <li><a href="./modular_diffusers_states">الحالات</a>: كيفية مشاركة البيانات بين الكتل.</li></ul><!----></div><!----> <div hidden=""><p>تعلّم كيفية إنشاء كتل خاصة بك تحتوي على منطق مخصص في دليل <a href="./custom_blocks">بناء كتل مخصصة</a>.</p><!----></div><!----> <div hidden=""><p>استخدم <a href="./components_manager"><code>ComponentsManager</code></a> لمشاركة النماذج عبر خطوط أنابيب متعددة وإدارة الذاكرة بكفاءة.</p><!----></div><!----> <div hidden=""><p>اربط خطوط الأنابيب المعيارية بـ <a href="https://github.com/cubiq/Mellon" rel="nofollow">Mellon</a>، وهو واجهة بصرية مبنية على العقد لبناء سير العمل. تعمل الكتل المخصصة المبنية باستخدام Modular Diffusers مع Mellon مباشرة دون الحاجة إلى كتابة أي كود للواجهة - اقرأ المزيد في دليل 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_1qsdbwf = {
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.0S0_iEoG.js"),
import("/docs/diffusers/main/en/_app/immutable/entry/app.CPdOxCbw.js")
]).then(([kit, app]) => {
kit.start(app, element, {
node_ids: [0, 328],
data: [null,null],
form: null,
error: null
});
});
}
</script>

Xet Storage Details

Size:
57.6 kB
·
Xet hash:
f7efa6efcc59d952a30c11ed7c92e66a850570993ca5cbec610536051e306514

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