Buckets:

mishig's picture
download
raw
103 kB
<meta charset="utf-8" /><meta name="hf:doc:metadata" content="{&quot;title&quot;:&quot;ModularPipeline&quot;,&quot;local&quot;:&quot;modularpipeline&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;إنشاء خط أنابيب&quot;,&quot;local&quot;:&quot;creating-a-pipeline&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;init_pipeline&quot;,&quot;local&quot;:&quot;initpipeline&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;from_pretrained&quot;,&quot;local&quot;:&quot;frompretrained&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3}],&quot;depth&quot;:2},{&quot;title&quot;:&quot;تحميل المكونات&quot;,&quot;local&quot;:&quot;loading-components&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;تحديث المكونات&quot;,&quot;local&quot;:&quot;updating-components&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;من AutoModel&quot;,&quot;local&quot;:&quot;from-automodel&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;من ComponentSpec&quot;,&quot;local&quot;:&quot;from-componentspec&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3}],&quot;depth&quot;:2},{&quot;title&quot;:&quot;تقسيم خط الأنابيب إلى مراحل&quot;,&quot;local&quot;:&quot;splitting-a-pipeline-into-stages&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;مستودع معياري&quot;,&quot;local&quot;:&quot;modular-repository&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;حفظ نسخة مستقلة&quot;,&quot;local&quot;:&quot;save-a-self-contained-copy&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;المرجع إلى المكونات في مستودعات أخرى&quot;,&quot;local&quot;:&quot;referencing-components-in-other-repositories&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;تحديث فهرس معياري موجود&quot;,&quot;local&quot;:&quot;update-an-existing-modular-index&quot;,&quot;sections&quot;:[],&quot;depth&quot;:4}],&quot;depth&quot;:3},{&quot;title&quot;:&quot;كود مخصص&quot;,&quot;local&quot;:&quot;custom-code&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3}],&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/325.DCs_o4tp.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">
<!--10zod39--><meta name="hf:doc:metadata" content="{&quot;title&quot;:&quot;ModularPipeline&quot;,&quot;local&quot;:&quot;modularpipeline&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;Creating a pipeline&quot;,&quot;local&quot;:&quot;creating-a-pipeline&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;init_pipeline&quot;,&quot;local&quot;:&quot;initpipeline&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;from_pretrained&quot;,&quot;local&quot;:&quot;frompretrained&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3}],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Loading components&quot;,&quot;local&quot;:&quot;loading-components&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Updating components&quot;,&quot;local&quot;:&quot;updating-components&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;From AutoModel&quot;,&quot;local&quot;:&quot;from-automodel&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;From ComponentSpec&quot;,&quot;local&quot;:&quot;from-componentspec&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3}],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Splitting a pipeline into stages&quot;,&quot;local&quot;:&quot;splitting-a-pipeline-into-stages&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Modular repository&quot;,&quot;local&quot;:&quot;modular-repository&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;Save a self-contained copy&quot;,&quot;local&quot;:&quot;save-a-self-contained-copy&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3},{&quot;title&quot;:&quot;Referencing components in other repositories&quot;,&quot;local&quot;:&quot;referencing-components-in-other-repositories&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;Update an existing modular index&quot;,&quot;local&quot;:&quot;update-an-existing-modular-index&quot;,&quot;sections&quot;:[],&quot;depth&quot;:4}],&quot;depth&quot;:3},{&quot;title&quot;:&quot;Custom code&quot;,&quot;local&quot;:&quot;custom-code&quot;,&quot;sections&quot;:[],&quot;depth&quot;:3}],&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="modularpipeline" 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="#modularpipeline"><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><!---->ModularPipeline<!----></span></h1><!--]--><!----> <p>يحوّل <a href="/docs/diffusers/v0.43.0/ar/api/modular_diffusers/pipeline#diffusers.ModularPipeline">ModularPipeline</a> الكتل <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/pipelines/overview#diffusers.DiffusionPipeline">DiffusionPipeline</a> مع وجود بعض الفروقات الجوهرية.</p> <ul><li><p><strong>Loading is lazy.</strong> With <a href="/docs/diffusers/v0.43.0/ar/api/pipelines/overview#diffusers.DiffusionPipeline">DiffusionPipeline</a>, <a href="/docs/diffusers/v0.43.0/ar/api/pipelines/overview#diffusers.DiffusionPipeline.from_pretrained">from_pretrained()</a> creates the pipeline and loads all models at the same time. With <a href="/docs/diffusers/v0.43.0/ar/api/modular_diffusers/pipeline#diffusers.ModularPipeline">ModularPipeline</a>, creating and loading are two separate steps: <a href="/docs/diffusers/v0.43.0/ar/api/modular_diffusers/pipeline#diffusers.ModularPipeline.from_pretrained">from_pretrained()</a> reads the configuration and knows where to load each component from, but doesn’t actually load the model weights. You load the models later with <a href="/docs/diffusers/v0.43.0/ar/api/modular_diffusers/pipeline#diffusers.ModularPipeline.load_components">load_components()</a>, which is where you pass loading arguments like <code>dtype</code> and <code>quantization_config</code>.</p></li> <li><p><strong>طريقتان لإنشاء خط أنابيب.</strong> يمكنك استخدام <a href="/docs/diffusers/v0.43.0/ar/api/modular_diffusers/pipeline#diffusers.ModularPipeline.from_pretrained">from_pretrained()</a> مع مستودع نموذج diffusers موجود مسبقًا — حيث يقوم تلقائيًا بالربط مع كتل خط الأنابيب الافتراضية ثم التحويل إلى <a href="/docs/diffusers/v0.43.0/ar/api/modular_diffusers/pipeline#diffusers.ModularPipeline">ModularPipeline</a> دون أي إعداد إضافي. يمكنك الاطلاع على <a href="https://github.com/huggingface/diffusers/tree/main/src/diffusers/modular_pipelines" rel="nofollow">modular_pipelines_directory</a> لمعرفة النماذج المدعومة حاليًا. كما يمكنك تجميع خط أنابيب خاص بك من <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_blocks#diffusers.ModularPipelineBlocks.init_pipeline">init_pipeline()</a> (راجع <a href="#creating-a-pipeline">إنشاء خط أنابيب</a> لمزيد من التفاصيل).</p></li> <li><p><strong>تشغيل خط الأنابيب هو نفسه.</strong> بمجرد تحميله، تستدعي خط الأنابيب بنفس الحجة التي اعتدت عليها. يمكن لـ <a href="/docs/diffusers/v0.43.0/ar/api/modular_diffusers/pipeline#diffusers.ModularPipeline">ModularPipeline</a> واحد دعم عدة مسارات عمل (نص إلى صورة، صورة إلى صورة، inpainting، إلخ) عندما تستخدم كتل خط الأنابيب <a href="./auto_pipeline_blocks"><code>AutoPipelineBlocks</code></a> لاختيار مسار العمل تلقائيًا بناءً على مدخلاتك.</p></li></ul> <p>فيما يلي أمثلة كاملة لتوليد الصور من النص، وتحويل الصورة إلى صورة، والتلوين الداخلي باستخدام SDXL.</p> <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> <div class="language-select"><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="language-py "><!----><span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> ModularPipeline
pipeline = ModularPipeline.from_pretrained(<span class="hljs-string">&quot;stabilityai/stable-diffusion-xl-base-1.0&quot;</span>)
pipeline.load_components(dtype=torch.float16)
pipeline.to(<span class="hljs-string">&quot;cuda&quot;</span>) <span class="hljs-comment"># or &quot;mps&quot;, &quot;xpu&quot;, &quot;cpu&quot;</span>
image = pipeline(prompt=<span class="hljs-string">&quot;Astronaut in a jungle, cold color palette, muted colors, detailed, 8k&quot;</span>).images[<span class="hljs-number">0</span>]
image.save(<span class="hljs-string">&quot;modular_t2i_out.png&quot;</span>)<!----></pre></div><!----></div><!----> <div hidden=""><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
<span class="hljs-keyword">from</span> diffusers.utils <span class="hljs-keyword">import</span> load_image
pipeline = ModularPipeline.from_pretrained(<span class="hljs-string">&quot;stabilityai/stable-diffusion-xl-base-1.0&quot;</span>)
pipeline.load_components(dtype=torch.float16)
pipeline.to(<span class="hljs-string">&quot;cuda&quot;</span>) <span class="hljs-comment"># or &quot;mps&quot;, &quot;xpu&quot;, &quot;cpu&quot;</span>
url = <span class="hljs-string">&quot;https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/sdxl-text2img.png&quot;</span>
init_image = load_image(url)
prompt = <span class="hljs-string">&quot;a dog catching a frisbee in the jungle&quot;</span>
image = pipeline(prompt=prompt, image=init_image, strength=<span class="hljs-number">0.8</span>).images[<span class="hljs-number">0</span>]
image.save(<span class="hljs-string">&quot;modular_i2i_out.png&quot;</span>)<!----></pre></div><!----></div><!----> <div hidden=""><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
<span class="hljs-keyword">from</span> diffusers.utils <span class="hljs-keyword">import</span> load_image
pipeline = ModularPipeline.from_pretrained(<span class="hljs-string">&quot;stabilityai/stable-diffusion-xl-base-1.0&quot;</span>)
pipeline.load_components(dtype=torch.float16)
pipeline.to(<span class="hljs-string">&quot;cuda&quot;</span>) <span class="hljs-comment"># or &quot;mps&quot;, &quot;xpu&quot;, &quot;cpu&quot;</span>
img_url = <span class="hljs-string">&quot;https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/sdxl-text2img.png&quot;</span>
mask_url = <span class="hljs-string">&quot;https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/sdxl-inpaint-mask.png&quot;</span>
init_image = load_image(img_url)
mask_image = load_image(mask_url)
prompt = <span class="hljs-string">&quot;A deep sea diver floating&quot;</span>
image = pipeline(prompt=prompt, image=init_image, mask_image=mask_image, strength=<span class="hljs-number">0.85</span>).images[<span class="hljs-number">0</span>]
image.save(<span class="hljs-string">&quot;modular_inpaint_out.png&quot;</span>)<!----></pre></div><!----></div><!----><!----></div><!----> <p>ستُظهر لك هذه الدليل كيفية إنشاء <a href="/docs/diffusers/v0.43.0/ar/api/modular_diffusers/pipeline#diffusers.ModularPipeline">ModularPipeline</a>، وإدارة مكوّناته، وتشغيل خط الأنابيب.</p> <!--[1--><h2 class="relative group"><a id="creating-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="#creating-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>There are two ways to create a <a href="/docs/diffusers/v0.43.0/ar/api/modular_diffusers/pipeline#diffusers.ModularPipeline">ModularPipeline</a>. Assemble and create a pipeline from <a href="/docs/diffusers/v0.43.0/ar/api/modular_diffusers/pipeline_blocks#diffusers.ModularPipelineBlocks">ModularPipelineBlocks</a> with <a href="/docs/diffusers/v0.43.0/ar/api/modular_diffusers/pipeline_blocks#diffusers.ModularPipelineBlocks.init_pipeline">init_pipeline()</a>, or load an existing pipeline with <a href="/docs/diffusers/v0.43.0/ar/api/modular_diffusers/pipeline#diffusers.ModularPipeline.from_pretrained">from_pretrained()</a>.</p> <p>يمكنك أيضًا تهيئة <a href="./components_manager"><code>ComponentsManager</code></a> للتعامل مع توزيع الأجهزة وإدارة الذاكرة. إذا لم تكن بحاجة إلى التفريغ التلقائي، يمكنك تجاوز هذه الخطوة ونقل خط الأنابيب إلى جهازك يدويًا باستخدام <code>pipeline.to("cuda")</code>.</p> <blockquote class="tip"><p>راجع وثيقة <a href="./components_manager">ComponentsManager</a> لمزيد من التفاصيل حول كيفية مساعدتها في إدارة المكونات عبر سير عمل مختلفة.</p></blockquote> <!--[2--><h3 class="relative group"><a id="initpipeline" 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="#initpipeline"><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><!---->init_pipeline<!----></span></h3><!--]--><!----> <p>يحوّل <a href="/docs/diffusers/v0.43.0/ar/api/modular_diffusers/pipeline_blocks#diffusers.ModularPipelineBlocks.init_pipeline">init_pipeline()</a> أي <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>لنعرّف كتلةً دنياً لنرى كيف تعمل:</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> transformers <span class="hljs-keyword">import</span> CLIPTextModel
<span class="hljs-keyword">from</span> diffusers.modular_pipelines <span class="hljs-keyword">import</span> (
ComponentSpec,
ModularPipelineBlocks,
PipelineState,
)
<span class="hljs-keyword">class</span> <span class="hljs-title class_">MyBlock</span>(<span class="hljs-title class_ inherited__">ModularPipelineBlocks</span>):
<span class="hljs-meta"> @property</span>
<span class="hljs-keyword">def</span> <span class="hljs-title function_">expected_components</span>(<span class="hljs-params">self</span>):
<span class="hljs-keyword">return</span> [
ComponentSpec(
name=<span class="hljs-string">&quot;text_encoder&quot;</span>,
type_hint=CLIPTextModel,
pretrained_model_name_or_path=<span class="hljs-string">&quot;openai/clip-vit-large-patch14&quot;</span>,
),
]
<span class="hljs-keyword">def</span> <span class="hljs-title function_">__call__</span>(<span class="hljs-params">self, components, state: PipelineState</span>) -&gt; PipelineState:
<span class="hljs-keyword">return</span> components, state<!----></pre></div><!----> <p>استدعِ <a href="/docs/diffusers/v0.43.0/ar/api/modular_diffusers/pipeline_blocks#diffusers.ModularPipelineBlocks.init_pipeline">init_pipeline()</a> لتحويله إلى خط أنابيب. الخاصية <code>blocks</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 "><!---->block = MyBlock()
pipe = block.init_pipeline()
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=" "><!----><span class="hljs-title class_">MyBlock</span> <span class="hljs-punctuation">{</span>
<span class="hljs-string">&quot;_class_name&quot;</span>: <span class="hljs-string">&quot;MyBlock&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-punctuation">}</span><!----></pre></div><!----> <blockquote class="warning"><p>المكعبات قابلة للتغيير — يمكنك بحرية إضافة مكعبات أو إزالتها أو استبدالها قبل إنشاء خط أنابيب. ومع ذلك، بمجرد إنشاء خط أنابيب، فإن تعديل <code>pipeline.blocks</code> لن يؤثر على خط الأنابيب لأنه يعيد نسخة. إذا كنت ترغب في بنية مكعبات مختلفة، فأنشئ خط أنابيب جديدًا بعد تعديل المكعبات.</p></blockquote> <p>عند استدعاء <a href="/docs/diffusers/v0.43.0/ar/api/modular_diffusers/pipeline_blocks#diffusers.ModularPipelineBlocks.init_pipeline">init_pipeline()</a> دون مستودع، فإنه يستخدم <code>pretrained_model_name_or_path</code> المعرّف في <a href="/docs/diffusers/v0.43.0/ar/api/modular_diffusers/pipeline_components#diffusers.ComponentSpec">ComponentSpec</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 "><!---->pipe
ModularPipeline {
<span class="hljs-string">&quot;_blocks_class_name&quot;</span>: <span class="hljs-string">&quot;MyBlock&quot;</span>,
<span class="hljs-string">&quot;_class_name&quot;</span>: <span class="hljs-string">&quot;ModularPipeline&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;text_encoder&quot;</span>: [
null,
null,
{
<span class="hljs-string">&quot;pretrained_model_name_or_path&quot;</span>: <span class="hljs-string">&quot;openai/clip-vit-large-patch14&quot;</span>,
<span class="hljs-string">&quot;revision&quot;</span>: null,
<span class="hljs-string">&quot;subfolder&quot;</span>: <span class="hljs-string">&quot;&quot;</span>,
<span class="hljs-string">&quot;type_hint&quot;</span>: [
<span class="hljs-string">&quot;transformers&quot;</span>,
<span class="hljs-string">&quot;CLIPTextModel&quot;</span>
],
<span class="hljs-string">&quot;variant&quot;</span>: null
}
]
}<!----></pre></div><!----> <p>عند تمرير مستودع إلى <a href="/docs/diffusers/v0.43.0/ar/api/modular_diffusers/pipeline_blocks#diffusers.ModularPipelineBlocks.init_pipeline">init_pipeline()</a>، فإنه يتجاوز مسار التحميل عن طريق مطابقة مكونات كتلتك مع إعدادات خط الأنابيب في ذلك المستودع (<code>model_index.json</code> أو <code>modular_model_index.json</code>). راجع <a href="#modular-repository">Modular repository</a> لمعرفة كيفية تسجيل مواصفات التحميل وحفظها.</p> <p>في المثال أدناه، سيتم تحديث <code>pretrained_model_name_or_path</code> إلى <code>"stabilityai/stable-diffusion-xl-base-1.0"</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 "><!---->pipe = block.init_pipeline(<span class="hljs-string">&quot;stabilityai/stable-diffusion-xl-base-1.0&quot;</span>)
pipe
ModularPipeline {
<span class="hljs-string">&quot;_blocks_class_name&quot;</span>: <span class="hljs-string">&quot;MyBlock&quot;</span>,
<span class="hljs-string">&quot;_class_name&quot;</span>: <span class="hljs-string">&quot;ModularPipeline&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;text_encoder&quot;</span>: [
null,
null,
{
<span class="hljs-string">&quot;pretrained_model_name_or_path&quot;</span>: <span class="hljs-string">&quot;stabilityai/stable-diffusion-xl-base-1.0&quot;</span>,
<span class="hljs-string">&quot;revision&quot;</span>: null,
<span class="hljs-string">&quot;subfolder&quot;</span>: <span class="hljs-string">&quot;text_encoder&quot;</span>,
<span class="hljs-string">&quot;type_hint&quot;</span>: [
<span class="hljs-string">&quot;transformers&quot;</span>,
<span class="hljs-string">&quot;CLIPTextModel&quot;</span>
],
<span class="hljs-string">&quot;variant&quot;</span>: null
}
]
}<!----></pre></div><!----> <p>إذا لم يوجد مكوّن في كتلتك في المستودع، يبقى <code>null</code> ويُتخطى أثناء <a href="/docs/diffusers/v0.43.0/ar/api/modular_diffusers/pipeline#diffusers.ModularPipeline.load_components">load_components()</a>.</p> <!--[2--><h3 class="relative group"><a id="frompretrained" 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="#frompretrained"><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><!---->from_pretrained<!----></span></h3><!--]--><!----> <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">ModularPipeline</a> دون الحاجة إلى تعريف الكتل بنفسك.</p> <p>يعمل مع ثلاثة أنواع من المستودعات.</p> <p><strong>مستودع diffusers عادي.</strong> مرّر أي مستودع نموذج مدعوم وسيتم تعيينه تلقائيًا إلى كتل خط المعالجة الافتراضي. تشمل النماذج المدعومة حاليًا SDXL وWan وQwen وZ-Image وFlux وFlux2.</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 <span class="hljs-keyword">import</span> ModularPipeline, ComponentsManager
components = ComponentsManager()
pipeline = ModularPipeline.from_pretrained(
<span class="hljs-string">&quot;stabilityai/stable-diffusion-xl-base-1.0&quot;</span>, components_manager=components
)<!----></pre></div><!----> <p><strong>مستودع معياري.</strong> تحتوي هذه المستودعات على <code>modular_model_index.json</code> يحدد فئة كل مكوّن ومن أين يتم تحميله، مع تخزين المكوّنات إلى جانبه. راجع <a href="#modular-repository">مستودع معياري</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 <span class="hljs-keyword">import</span> ModularPipeline, ComponentsManager
components = ComponentsManager()
pipeline = ModularPipeline.from_pretrained(
<span class="hljs-string">&quot;MiniMaxAI/MiniMax-H3&quot;</span>, components_manager=components
)<!----></pre></div><!----> <p><strong>مستودع معياري يحتوي على مكوّنات مخصصة.</strong> تتضمن بعض المستودعات مكوّنات خط أنابيب مخصصة إلى جانب إعدادات التحميل. أضف <code>trust_remote_code=True</code> لتحميلها. راجع <a href="./custom_blocks">المكوّنات المخصصة</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 <span class="hljs-keyword">import</span> ModularPipeline, ComponentsManager
components = ComponentsManager()
pipeline = ModularPipeline.from_pretrained(
<span class="hljs-string">&quot;diffusers/Florence2-image-Annotator&quot;</span>, trust_remote_code=<span class="hljs-literal">True</span>, components_manager=components
)<!----></pre></div><!----> <p>عندما تُعرّف كتل خط الأنابيب سير عمل (راجع <code>pipeline.blocks.available_workflows</code>)، مرّر <code>workflow=</code> للاحتفاظ بكتل سير العمل ذلك فقط — وهو نفس التقليم الذي يؤديه <a href="/docs/diffusers/v0.43.0/ar/api/modular_diffusers/pipeline_blocks#diffusers.ModularPipelineBlocks.get_workflow">get_workflow()</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 = ModularPipeline.from_pretrained(<span class="hljs-string">&quot;Qwen/Qwen-Image&quot;</span>, workflow=<span class="hljs-string">&quot;inpainting&quot;</span>)<!----></pre></div><!----> <!--[1--><h2 class="relative group"><a id="loading-components" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#loading-components"><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> تلقائياً مع المكونات. فهو يقوم فقط بتحميل التكوين ومواصفات المكونات. يمكنك تحميل المكونات باستخدام <a href="/docs/diffusers/v0.43.0/ar/api/modular_diffusers/pipeline#diffusers.ModularPipeline.load_components">load_components()</a>.</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-keyword">import</span> torch
pipeline.load_components(dtype=torch.float16)<!----></pre></div><!----> <p>يمكنك أيضًا تحميل مكوّنات محددة بالاسم. المثال أدناه يحمّل <code>text_encoder</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 "><!---->pipeline.load_components(names=[<span class="hljs-string">&quot;text_encoder&quot;</span>], dtype=torch.float16)<!----></pre></div><!----> <p>في خط أنابيب تُعرّف كتله عملياته، يُحمّل <code>workflow=</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 "><!---->pipeline.load_components(workflow=<span class="hljs-string">&quot;inpainting&quot;</span>, dtype=torch.float16)<!----></pre></div><!----> <p>بعد التحميل، يُظهر طباعة خط الأنابيب المكوّنات المحمّلة — حيث تتغيّر الحقلان الأولان من <code>null</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 "><!---->pipeline<!----></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-comment"># text_encoder is loaded - shows library and class</span>
<span class="hljs-string">&quot;text_encoder&quot;</span>: [
<span class="hljs-string">&quot;transformers&quot;</span>,
<span class="hljs-string">&quot;CLIPTextModel&quot;</span>,
{ ... }
]
<span class="hljs-comment"># unet is not loaded yet - still null</span>
<span class="hljs-string">&quot;unet&quot;</span>: [
<span class="hljs-literal">null</span>,
<span class="hljs-literal">null</span>,
{ ... }
]<!----></pre></div><!----> <p>تُمرَّر حُجج الكلمات المفتاحية مثل <code>dtype</code> و<code>variant</code> و<code>revision</code> و<code>quantization_config</code> إلى <code>from_pretrained()</code> لكل مكوّن. يمكنك تمرير قيمة واحدة لتطبيقها على جميع المكوّنات، أو تمرير قاموس (dict) لضبط قيم لكل مكوّن على حدة.</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"># apply bfloat16 to all components</span>
pipeline.load_components(dtype=torch.bfloat16)
<span class="hljs-comment"># different dtypes per component</span>
pipeline.load_components(dtype={<span class="hljs-string">&quot;transformer&quot;</span>: torch.bfloat16, <span class="hljs-string">&quot;default&quot;</span>: torch.float32})<!----></pre></div><!----> <p><a href="/docs/diffusers/v0.43.0/ar/api/modular_diffusers/pipeline#diffusers.ModularPipeline.load_components">load_components()</a> لا يحمّل سوى المكوّنات التي لم تُحمَّل بعد ولديها مواصفة تحميل صالحة. وهذا يعني أنه إذا كنت قد ضبطت مكوّناً مسبقاً على خطّ الأنابيب، فإن استدعاء <a href="/docs/diffusers/v0.43.0/ar/api/modular_diffusers/pipeline#diffusers.ModularPipeline.load_components">load_components()</a> مرة أخرى لن يُعيد تحميله.</p> <!--[1--><h2 class="relative group"><a id="updating-components" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#updating-components"><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.update_components">update_components()</a> مكوّنًا في خط المعالجة بمكوّن جديد. عند تحديث مكوّن، يتم أيضًا تحديث مواصفات التحميل في إعدادات خط المعالجة، وسيتم تجاوز <a href="/docs/diffusers/v0.43.0/ar/api/modular_diffusers/pipeline#diffusers.ModularPipeline.load_components">load_components()</a> في الاستدعاءات اللاحقة.</p> <!--[2--><h3 class="relative group"><a id="from-automodel" 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="#from-automodel"><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><!---->من AutoModel<!----></span></h3><!--]--><!----> <p>يمكنك تمرير كائن نموذج محمّل باستخدام <code>AutoModel.from_pretrained()</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-keyword">from</span> diffusers <span class="hljs-keyword">import</span> AutoModel
unet = AutoModel.from_pretrained(
<span class="hljs-string">&quot;RunDiffusion/Juggernaut-XL-v9&quot;</span>, subfolder=<span class="hljs-string">&quot;unet&quot;</span>, variant=<span class="hljs-string">&quot;fp16&quot;</span>, dtype=torch.float16
)
pipeline.update_components(unet=unet)<!----></pre></div><!----> <!--[2--><h3 class="relative group"><a id="from-componentspec" 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="#from-componentspec"><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><!---->من ComponentSpec<!----></span></h3><!--]--><!----> <p>استخدم <a href="/docs/diffusers/v0.43.0/ar/api/modular_diffusers/pipeline#diffusers.ModularPipeline.get_component_spec">get_component_spec()</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 "><!---->unet_spec = pipeline.get_component_spec(<span class="hljs-string">&quot;unet&quot;</span>)
<span class="hljs-comment"># modify to load from a different repository</span>
unet_spec.pretrained_model_name_or_path = <span class="hljs-string">&quot;RunDiffusion/Juggernaut-XL-v9&quot;</span>
<span class="hljs-comment"># load and update</span>
unet = unet_spec.load(dtype=torch.float16)
pipeline.update_components(unet=unet)<!----></pre></div><!----> <p>يمكنك أيضًا إنشاء <a href="/docs/diffusers/v0.43.0/ar/api/modular_diffusers/pipeline_components#diffusers.ComponentSpec">ComponentSpec</a> من الصفر.</p> <p>لا يتم تحميل جميع المكونات من أوزان مُسبقة التدريب — فبعضها يُنشأ من ملف تكوين (مُدرج تحت <code>pipeline.config_component_names</code>). لهذه المكونات، استخدم <a href="/docs/diffusers/v0.43.0/ar/api/modular_diffusers/pipeline_components#diffusers.ComponentSpec.create">create()</a> بدلاً من <a href="/docs/diffusers/v0.43.0/ar/api/modular_diffusers/pipeline_components#diffusers.ComponentSpec.load">load()</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 "><!---->guider_spec = pipeline.get_component_spec(<span class="hljs-string">&quot;guider&quot;</span>)
guider_spec.config = {<span class="hljs-string">&quot;guidance_scale&quot;</span>: <span class="hljs-number">5.0</span>}
guider = guider_spec.create()
pipeline.update_components(guider=guider)<!----></pre></div><!----> <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-keyword">from</span> diffusers.guiders <span class="hljs-keyword">import</span> ClassifierFreeGuidance
guider = ClassifierFreeGuidance(guidance_scale=<span class="hljs-number">5.0</span>)
pipeline.update_components(guider=guider)<!----></pre></div><!----> <p>راجع دليل <a href="../using-diffusers/guiders">Guiders</a> لمزيد من التفاصيل حول الأدلة المتاحة وكيفية تكوينها.</p> <!--[1--><h2 class="relative group"><a id="splitting-a-pipeline-into-stages" 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="#splitting-a-pipeline-into-stages"><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>بما أن الكتل قابلة للتركيب، يمكنك تفكيك خط الأنابيب وإعادة بنائه إلى خطوط أنابيب منفصلة لكل مرحلة. يُظهر المثال أدناه كيف يمكننا فصل كتلة مُشفّر النص عن بقية خط الأنابيب، بحيث يمكنك ترميز الأمر بشكل مستقل ثم تمرير التضمينات إلى خط الأنابيب الرئيسي.</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 <span class="hljs-keyword">import</span> ModularPipeline, ComponentsManager
<span class="hljs-keyword">import</span> torch
device = <span class="hljs-string">&quot;cuda&quot;</span> <span class="hljs-comment"># or &quot;mps&quot;, &quot;xpu&quot;, &quot;cpu&quot;</span>
dtype = torch.bfloat16
repo_id = <span class="hljs-string">&quot;black-forest-labs/FLUX.2-klein-4B&quot;</span>
<span class="hljs-comment"># get the blocks and separate out the text encoder</span>
blocks = ModularPipeline.from_pretrained(repo_id).blocks
text_block = blocks.sub_blocks.pop(<span class="hljs-string">&quot;text_encoder&quot;</span>)
<span class="hljs-comment"># use ComponentsManager to handle offloading across multiple pipelines</span>
manager = ComponentsManager()
manager.enable_auto_cpu_offload(device=device)
<span class="hljs-comment"># create separate pipelines for each stage</span>
text_encoder_pipeline = text_block.init_pipeline(repo_id, components_manager=manager)
pipeline = blocks.init_pipeline(repo_id, components_manager=manager)
<span class="hljs-comment"># encode text</span>
text_encoder_pipeline.load_components(dtype=dtype)
text_embeddings = text_encoder_pipeline(prompt=<span class="hljs-string">&quot;a cat&quot;</span>).get_by_kwargs(<span class="hljs-string">&quot;denoiser_input_fields&quot;</span>)
<span class="hljs-comment"># denoise and decode</span>
pipeline.load_components(dtype=dtype)
output = pipeline(
**text_embeddings,
num_inference_steps=<span class="hljs-number">4</span>,
).images[<span class="hljs-number">0</span>]<!----></pre></div><!----> <p>يتولى <a href="/docs/diffusers/v0.43.0/ar/api/modular_diffusers/pipeline_components#diffusers.ComponentsManager">ComponentsManager</a> إدارة الذاكرة عبر خطوط أنابيب متعددة. على عكس استراتيجيات التفريغ في <a href="/docs/diffusers/v0.43.0/ar/api/pipelines/overview#diffusers.DiffusionPipeline">DiffusionPipeline</a> التي تتبع ترتيبًا ثابتًا، يتخذ <a href="/docs/diffusers/v0.43.0/ar/api/modular_diffusers/pipeline_components#diffusers.ComponentsManager">ComponentsManager</a> قرارات التفريغ ديناميكيًا في كل مرة يُنفَّذ فيها تمرير أمامي للنموذج، بناءً على حالة الذاكرة الحالية. وهذا يعني أنه يعمل بغض النظر عن عدد خطوط الأنابيب التي تنشئها أو الترتيب الذي تنفذها به. راجد دليل <a href="./components_manager">ComponentsManager</a> لمزيد من التفاصيل.</p> <p>إذا كانت مراحل خط الأنابيب تتشارك في مكوّنات (مثل استخدام نفس VAE للتشفير وفك التشفير)، يمكنك استخدام <a href="/docs/diffusers/v0.43.0/ar/api/modular_diffusers/pipeline#diffusers.ModularPipeline.update_components">update_components()</a> لتسليم مكوّن محمّل مسبقًا إلى خط أنابيب آخر بدلاً من تحميله مرة أخرى.</p> <!--[1--><h2 class="relative group"><a id="modular-repository" 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="#modular-repository"><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>يُشترط وجود مستودع إذا كانت كتل خط المعالجة تستخدم <em>مكونات مُدرَّبة مسبقًا</em>. يوفّر المستودع مواصفات التحميل والبيانات الوصفية.</p> <p>يعمل <a href="/docs/diffusers/v0.43.0/ar/api/modular_diffusers/pipeline#diffusers.ModularPipeline">ModularPipeline</a> مع مستودعات diffusers العادية دون أي إعداد مسبق. ومع ذلك، يمكنك أيضاً إنشاء <em>مستودع معياري</em> للحصول على مرونة أكبر. يحتوي المستودع المعياري على ملف <code>modular_model_index.json</code> يضم العناصر الثلاثة التالية.</p> <ul><li><code>library</code> و<code>class</code> يُظهران المكتبة التي تم تحميل المكوّن منها وفئته. إذا كانت <code>null</code>، فإن المكوّن لم يتم تحميله بعد.</li> <li><code>loading_specs_dict</code> يحتوي على المعلومات المطلوبة لتحميل المكوّن، مثل المستودع والجزء الفرعي الذي يتم التحميل منه.</li></ul> <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 <span class="hljs-keyword">import</span> ModularPipeline
<span class="hljs-comment"># load from a regular repo</span>
pipeline = ModularPipeline.from_pretrained(<span class="hljs-string">&quot;stabilityai/stable-diffusion-xl-base-1.0&quot;</span>)
pipeline.load_components()
<span class="hljs-comment"># push as a modular repository</span>
pipeline.save_pretrained(<span class="hljs-string">&quot;local/path&quot;</span>, repo_id=<span class="hljs-string">&quot;my-username/sdxl-modular&quot;</span>, push_to_hub=<span class="hljs-literal">True</span>)<!----></pre></div><!----> <p>بشكل افتراضي، يكتب <a href="/docs/diffusers/v0.43.0/ar/api/modular_diffusers/pipeline#diffusers.ModularPipeline.save_pretrained">save_pretrained()</a> كل مكوّن محمّل حاليًا يمكن لـ Diffusers تسلسله. أما المكوّنات غير المحمّلة، أو التي لا يمكن تسلسلها، فلا تُكتب وتحتفظ بمواصفات التحميل الحالية لها.</p> <!--[2--><h3 class="relative group"><a id="save-a-self-contained-copy" 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="#save-a-self-contained-copy"><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>load جميع المكونات، ثم احفظها. يشير كل مواصفة إلى النتيجة، لذا يتم إعادة تحميلها بالكامل من مكان واحد، بما في ذلك دون اتصال.</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 "><!---->pipe = ModularPipeline.from_pretrained(<span class="hljs-string">&quot;MiniMaxAI/MiniMax-H3&quot;</span>)
pipe.load_components()
pipe.save_pretrained(<span class="hljs-string">&quot;path/to/local-copy&quot;</span>)<!----></pre></div><!----> <p>الموقع المُسجَّل في <code>modular_model_index.json</code> هو المكان الذي تكتب إليه <a href="/docs/diffusers/v0.43.0/ar/api/modular_diffusers/pipeline#diffusers.ModularPipeline.save_pretrained">save_pretrained()</a>: وهو <code>save_directory</code> عند الحفظ محليًا، أو <code>repo_id</code> عند تمرير <code>push_to_hub=True</code>.</p> <p>نقل الملفات بأي طريقة أخرى لا يعيد كتابة الفهرس. تبقى نسخة تم تنزيلها باستخدام <code>hf download --local-dir</code> قابلة للاستخدام: عند تحميل خط أنابيب من مجلد محلي، يتم تحميل كل مكوّن توجد ملفاتُه في ذلك المجلد من هناك بدلاً من المستودع المسجَّل. أما النسخة التي تم رفعها باستخدام <code>hf upload</code> فتظل تشير إلى الموقع القديم، لذا يجب تحديث الفهرس يدوياً في هذه الحالة.</p> <p>مع <code>huggingface_hub>=1.32.0</code>، يمكن للملفات المتطابقة المدعومة بتقنية Xet أن تتشارك حمولةً واحدةً مخزنةً مؤقتًا عبر أي مستودعات Hub. ويشمل ذلك الملفات الفردية في نقطة تفتيش مقسمة: يمكن إعادة استخدام شريحة تحمل نفس تجزئة Xet حتى لو اختلفت الشرائح الأخرى. ويجب أن تستخدم عمليات التنزيل كلاهما نفس دليل التخزين المؤقت لـ Hub مع دعم الروابط الرمزية. وقد يؤدي تغيير نوع البيانات (dtype) أو طريقة التسلسل أو حدود الشرائح إلى تغيير تجزئات الملفات ومنع إعادة الاستخدام. وهذا يوفر من حركة التنزيل ومساحة القرص، وليس الذاكرة المستخدمة من قبل المكونات المحمّلة.</p> <p>التخزين المؤقت المشترك يعمل على أساس أفضل جهد. ضبط <code>HF_HUB_DISABLE_SHARED_BLOBS=1</code> لا يزال يدعم التحميل، لكنه يخزّن نسخًا منفصلة. تبقى مراجع المكونات الموجودة في <code>modular_model_index.json</code> دون تغيير؛ احتفظ بالمراجع الخارجية للمكونات غير المخزنة في المستودع المعياري.</p> <!--[2--><h3 class="relative group"><a id="referencing-components-in-other-repositories" 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="#referencing-components-in-other-repositories"><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>modular_model_index.json</code> إلى مستودع مختلف. على سبيل المثال، يحمّل <a href="https://huggingface.co/diffusers/flux2-bnb-4bit-modular" rel="nofollow">diffusers/flux2-bnb-4bit-modular</a> محوّله المُكمَّم من <code>diffusers/FLUX.2-dev-bnb-4bit</code> والمكوّنات المتبقية من <code>black-forest-labs/FLUX.2-dev</code>.</p> <p>نفضّل بشدة المستودعات المستقلة بذاتها: فإبقاء جميع المكونات معًا يجعل تنزيل خط الأنابيب ومشاركته واستخدامه دون اتصال بالإنترنت أسهل دون الاعتماد على مستودعات أخرى. استخدم مراجع المستودعات المتقاطعة فقط عندما ترغب عمدًا في استضافة مكوّن في مكان آخر.</p> <p>مرّر <code>overwrite_modular_index=False</code> للحفاظ على مواصفات التحميل في <code>modular_model_index.json</code> كما هي. لا يزال المكوّن المحفوظ الذي تكون مواصفة تحميله فارغة يُملأ بالوجهة، لأنه لا يوجد شيء يجب الحفاظ عليه.</p> <p>مع <code>huggingface_hub>=1.32.0</code>، يمكن للملفات المتطابقة المدعومة بتقنية Xet مشاركة حمولة واحدة مخزنة مؤقتًا عبر المستودعات من خلال الروابط الرمزية، مما يتجنب التنزيلات المكررة واستهلاك مساحة القرص. لا حاجة إلى مراجع بين المستودعات لهذا الغرض. راجع <a href="#save-a-self-contained-copy">حفظ نسخة ذاتية الاكتفاء</a> لمعرفة متطلبات ومحدوديات التخزين المؤقت المشترك.</p> <!--[3--><h4 class="relative group"><a id="update-an-existing-modular-index" 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="#update-an-existing-modular-index"><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></h4><!--]--><!----> <p>تستمر المراجع الموجودة إلى المستودع الأصلي في العمل. إذا كان المرجع يُستخدم فقط لتجنّب التنزيلات المكررة، فاستبدله بتحميل المكوّنات من المستودع المعياري بمجرد توفّر ملفات المكوّنات هناك.</p> <p>أولاً، تحقق من أن المستودع المعياري يحتوي على تكوين المكونات نفسه وجميع ملفات الأوزان المطلوبة، بما في ذلك فهرس الأوزان وكل شريحة لنقطة تفتيش مقسمة. تحدد تجاوبات Xet أي ملفات الأوزان يمكنها إعادة استخدام ذاكرة التخزين المؤقت المشتركة. احتفظ بالمراجع إلى المكونات غير الموجودة أو التي يتم تحميلها عمدًا من نقطة تفتيش أخرى.</p> <p>حرّر مواصفة التحميل ذات الصلة فقط في نسخة محلية من <code>modular_model_index.json</code>. على سبيل المثال، لاستخدام VAE مخزّن تحت <code>vae/</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-keyword">import</span> json
<span class="hljs-keyword">from</span> pathlib <span class="hljs-keyword">import</span> Path
index_path = Path(<span class="hljs-string">&quot;path/to/local-copy/modular_model_index.json&quot;</span>)
index = json.loads(index_path.read_text())
spec = index[<span class="hljs-string">&quot;vae&quot;</span>][<span class="hljs-number">2</span>]
spec[<span class="hljs-string">&quot;pretrained_model_name_or_path&quot;</span>] = <span class="hljs-string">&quot;my-username/my-modular-repo&quot;</span>
spec.pop(<span class="hljs-string">&quot;repo&quot;</span>, <span class="hljs-literal">None</span>)
spec[<span class="hljs-string">&quot;subfolder&quot;</span>] = <span class="hljs-string">&quot;vae&quot;</span>
spec[<span class="hljs-string">&quot;revision&quot;</span>] = <span class="hljs-literal">None</span>
index_path.write_text(json.dumps(index, indent=<span class="hljs-number">2</span>) + <span class="hljs-string">&quot;\n&quot;</span>)<!----></pre></div><!----> <p>يؤدي هذا أيضًا إلى إزالة حقل <code>repo</code> القديم. لا يُعرّف إصدار من المستودع الأصلي إصدارًا في الوجهة: استخدم <code>None</code> للفرع الافتراضي للوجهة، أو ثبّت إصدارًا في الوجهة يحتوي على المكوّن. عدّل <code>subfolder</code> و<code>variant</code> إذا اختلفت أسماء الملفات.</p> <p>قبل نشر الفهرس المحدّث، حمّله باستخدام <code>ModularPipeline.from_pretrained("path/to/local-copy")</code>، ثم استدعِ <code>load_components(names="vae")</code>، وتحقّق من أن المكوّن يُحمَّل بالباراميترات المتوقعة. ارفع الفهرس المُعدَّل فقط؛ فإعادة حفظ الأوزان قد تُغيّر تجزئاتها (hashes) وتمنع إعادة استخدام ذاكرة التخزين المؤقت.</p> <!--[2--><h3 class="relative group"><a id="custom-code" 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="#custom-code"><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>يمكن أن يتضمن المستودع المعياري أيضًا كتل خطوط أنابيب مخصصة على شكل كود بايثون. وهذا يتيح لك مشاركة كتل متخصصة ليست أصلية في Diffusers. على سبيل المثال، يحتوي <a href="https://huggingface.co/diffusers/Florence2-image-Annotator" rel="nofollow">diffusers/Florence2-image-Annotator</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=" "><!----><span class="hljs-type">Florence2</span>-image-<span class="hljs-type">Annotator</span>/
├── <span class="hljs-keyword">block</span>.py <span class="hljs-comment"># Custom pipeline blocks implementation</span>
├── config.json <span class="hljs-comment"># Pipeline configuration and auto_map</span>
├── mellon_config.json <span class="hljs-comment"># UI configuration for Mellon</span>
└── modular_model_index.json <span class="hljs-comment"># Component loading specifications</span><!----></pre></div><!----> <p>يحتوي ملف <code>config.json</code> على مفتاح <code>auto_map</code> يخبر <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-json "><!----><span class="hljs-punctuation">{</span>
<span class="hljs-attr">&quot;_class_name&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;Florence2AnnotatorBlocks&quot;</span><span class="hljs-punctuation">,</span>
<span class="hljs-attr">&quot;auto_map&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-punctuation">{</span>
<span class="hljs-attr">&quot;ModularPipelineBlocks&quot;</span><span class="hljs-punctuation">:</span> <span class="hljs-string">&quot;block.Florence2AnnotatorBlocks&quot;</span>
<span class="hljs-punctuation">}</span>
<span class="hljs-punctuation">}</span><!----></pre></div><!----> <p>حمّل مستودعات الأكواد المخصصة باستخدام <code>trust_remote_code=True</code> كما هو موضح في <a href="#frompretrained">from_pretrained</a>. راجع <a href="./custom_blocks">Custom blocks</a> لمعرفة كيفية إنشاء كتل خاصة بك ومشاركتها.</p> <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/modular_pipeline.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, 325],
data: [null,null],
form: null,
error: null
});
});
}
</script>

Xet Storage Details

Size:
103 kB
·
Xet hash:
c295782e789919107c0ebc2325b234cf0f39b6b04d6e63d13630b6b797650b58

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