Buckets:

mishig's picture
download
raw
103 kB
<meta charset="utf-8" /><meta name="hf:doc:metadata" content="{&quot;title&quot;:&quot;FLUX 3 Image Klein&quot;,&quot;local&quot;:&quot;flux-3-image-klein&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;توسيع عينات المحفّز&quot;,&quot;local&quot;:&quot;prompt-upsampling&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;من صورة إلى صورة&quot;,&quot;local&quot;:&quot;image-to-image&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;التحكم في التخطيط&quot;,&quot;local&quot;:&quot;layout-control&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;مقياس التوجيه&quot;,&quot;local&quot;:&quot;guidance-scale&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;نموذج مُقطّر على مستوى الخطوات&quot;,&quot;local&quot;:&quot;step-distilled-model&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;توليد قابل للتكرار&quot;,&quot;local&quot;:&quot;reproducible-generation&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;سير العمل&quot;,&quot;local&quot;:&quot;workflows&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;إجراءات الاستدعاء لكل خطوة&quot;,&quot;local&quot;:&quot;per-step-callbacks&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;الذاكرة&quot;,&quot;local&quot;:&quot;memory&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;التحميل من ملف واحد&quot;,&quot;local&quot;:&quot;single-file-loading&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Flux3ModularPipeline&quot;,&quot;local&quot;:&quot;diffusers.Flux3ModularPipeline&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Flux3AutoBlocks&quot;,&quot;local&quot;:&quot;diffusers.Flux3AutoBlocks&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Flux3DistilledAutoBlocks&quot;,&quot;local&quot;:&quot;diffusers.Flux3DistilledAutoBlocks&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Flux3DistilledModularPipeline&quot;,&quot;local&quot;:&quot;diffusers.Flux3DistilledModularPipeline&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2}],&quot;depth&quot;:1}"/>
<link href="/docs/diffusers/main/en/_app/immutable/entry/start.U6TUchwJ.js" rel="modulepreload">
<link href="/docs/diffusers/main/en/_app/immutable/chunks/yxSHiGDF.js" rel="modulepreload">
<link href="/docs/diffusers/main/en/_app/immutable/chunks/CPfOwUO_.js" rel="modulepreload">
<link href="/docs/diffusers/main/en/_app/immutable/entry/app.3qKhPoX-.js" rel="modulepreload">
<link href="/docs/diffusers/main/en/_app/immutable/chunks/BYe-f74j.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/chunks/D32hXVzh.js" rel="modulepreload">
<link href="/docs/diffusers/main/en/_app/immutable/nodes/0.DqpuBF3n.js" rel="modulepreload">
<link href="/docs/diffusers/main/en/_app/immutable/chunks/Dyp9xKq8.js" rel="modulepreload">
<link href="/docs/diffusers/main/en/_app/immutable/nodes/8.AKHyGgGH.js" rel="modulepreload">
<link href="/docs/diffusers/main/en/_app/immutable/chunks/Dk44y1gU.js" rel="modulepreload">
<!--hchutw--><meta name="hf:doc:metadata" content="{&quot;title&quot;:&quot;FLUX 3 Image Klein&quot;,&quot;local&quot;:&quot;flux-3-image-klein&quot;,&quot;sections&quot;:[{&quot;title&quot;:&quot;Prompt upsampling&quot;,&quot;local&quot;:&quot;prompt-upsampling&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Image-to-image&quot;,&quot;local&quot;:&quot;image-to-image&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Layout control&quot;,&quot;local&quot;:&quot;layout-control&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Guidance scale&quot;,&quot;local&quot;:&quot;guidance-scale&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Step-distilled model&quot;,&quot;local&quot;:&quot;step-distilled-model&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Reproducible generation&quot;,&quot;local&quot;:&quot;reproducible-generation&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Workflows&quot;,&quot;local&quot;:&quot;workflows&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Per-step callbacks&quot;,&quot;local&quot;:&quot;per-step-callbacks&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Memory&quot;,&quot;local&quot;:&quot;memory&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Single-file loading&quot;,&quot;local&quot;:&quot;single-file-loading&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Flux3ModularPipeline&quot;,&quot;local&quot;:&quot;diffusers.Flux3ModularPipeline&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Flux3AutoBlocks&quot;,&quot;local&quot;:&quot;diffusers.Flux3AutoBlocks&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Flux3DistilledAutoBlocks&quot;,&quot;local&quot;:&quot;diffusers.Flux3DistilledAutoBlocks&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2},{&quot;title&quot;:&quot;Flux3DistilledModularPipeline&quot;,&quot;local&quot;:&quot;diffusers.Flux3DistilledModularPipeline&quot;,&quot;sections&quot;:[],&quot;depth&quot;:2}],&quot;depth&quot;:1}"/><!---->
<link href="/docs/diffusers/main/en/_app/immutable/assets/0.tn0RQdqM.css" rel="modulepreload"> <!--[--><!--[0--><!--[--><!--[0--><!--[--><p></p> <!--[0--><h1 class="relative group"><a id="flux-3-image-klein" 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="#flux-3-image-klein"><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><!---->FLUX 3 Image Klein<!----></span></h1><!--]--><!----> <p>FLUX 3 Image Klein هو نموذج لتوليد الصور بحجم 5.6 مليار من Black Forest Labs: يقوم محوّل واحد (<a href="/docs/diffusers/main/ar/api/models/flux3_transformer#diffusers.Flux3Transformer2DModel">Flux3Transformer2DModel</a>) بتوليد الصور من موجه نصي، بمفرده أو مع صورة مرجعية واحدة أو أكثر. يأتي التكييف النصي من Qwen3-VL، بينما تستخدم الصور مُشفِّر/مفكك الترميز التلقائي المعبأ FLUX.2 (<code>AutoencoderKLFlux2</code>).</p> <p>يُطرح FLUX 3 Image Klein على شكل <a href="../../modular_diffusers/overview">خط أنابيب معياري</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-python "><!----><span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> ModularPipeline
pipe = ModularPipeline.from_pretrained(<span class="hljs-string">&quot;black-forest-labs/flux-3-image-klein-base&quot;</span>)
pipe.load_components(dtype={<span class="hljs-string">&quot;vae&quot;</span>: torch.float32, <span class="hljs-string">&quot;default&quot;</span>: torch.bfloat16})
pipe.to(<span class="hljs-string">&quot;cuda&quot;</span>)
image = pipe(
prompt=<span class="hljs-string">&quot;A red fox in a snow-covered forest clearing at golden hour&quot;</span>,
generator=torch.Generator().manual_seed(<span class="hljs-number">0</span>),
output=<span class="hljs-string">&quot;images&quot;</span>,
)[<span class="hljs-number">0</span>]
image.save(<span class="hljs-string">&quot;fox.png&quot;</span>)<!----></pre></div><!----> <p><code>prompt</code> هو المدخل الإلزامي الوحيد: حيث تحمل خط الأنابيب إعدادات العينة الموصى بها (50 خطوة، مقياس التوجيه 3.5، إزاحة المجدول 6.93) وتولّد صورًا بقياس 1024 x 1024 افتراضيًا. يستقبل استدعاءً واحدًا لكل موجه؛ استخدم <code>num_images_per_prompt</code> للحصول على عدة صور لنفس الموجه.</p> <p>كما ترون في المثال أعلاه، يختلف التحميل والتشغيل قليلاً عن <code>DiffusionPipeline</code>. التحميل كسول: <a href="/docs/diffusers/main/ar/api/modular_diffusers/pipeline#diffusers.ModularPipeline.from_pretrained">from_pretrained()</a> يبني خط الأنابيب فقط، وتقوم باستدعاء <a href="/docs/diffusers/main/ar/api/modular_diffusers/pipeline#diffusers.ModularPipeline.load_components">load_components()</a> لتحميل الأوزان. يعيد الاستدعاء حالة خط الأنابيب، وتطلب ما تحتاجه باستخدام <code>output</code>: <code>output="images"</code> هنا، أو <code>output=["images", "prompt"]</code> للحصول أيضاً على الوصف الذي كتبه مُحسِّن المُوجِّه.</p> <blockquote class="tip"><p>إذا كنت تعمل مع <code>ModularPipeline</code> لأول مرة، فاقرأ <a href="../../modular_diffusers/quickstart">البدء السريع</a>، و<a href="../../modular_diffusers/coming_from_diffusion_pipeline">الانتقال من DiffusionPipeline</a> إذا كنت على دراية بالخطوط الأنابيب القياسية. بخلاف التحميل والمخرجات، تختلف بعض الأمور الأخرى: <a href="#guidance-scale">الإرشاد</a>، <a href="#per-step-callbacks">المكالمات العكسية</a> و<a href="#memory">التفريغ</a>.</p></blockquote> <!--[1--><h2 class="relative group"><a id="prompt-upsampling" 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="#prompt-upsampling"><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>تُعدّ الصياغة أمراً بالغ الأهمية: يستقبل نموذج FLUX 3 Image Klein أوصافاً كاملة للمشهد تصف الموضوع، والتكوين، والإضاءة، والأجواء، وليس مجرد أوامر قصيرة؛ فالطلب المُرسَل كما هو دون توسيع يُنتج مخرجات عامة. ولهذا السبب، يعمل خط المعالجة على مُوسّع الأوامر أولاً لكل طلب، سواء كان توليد صورة من نص أو تحرير. وهو نموذج مستقل بحجم 9B من Black Forest Labs (<a href="https://huggingface.co/black-forest-labs/flux-3-image-klein-pup" rel="nofollow">black-forest-labs/flux-3-image-klein-pup</a>) يقوم بتوسيع <code>prompt</code> إلى وصف من هذا القبيل قبل مُشفّر النص، وكافٍ أن يكون الأمر قصيراً.</p> <p>يحوّل مُوسّع المُوجِّه طلبًا قصيرًا، إلى جانب الصور المرجعية عند التحرير، إلى وصف كامل للمشهد الذي يتلقاه النموذج: الوسط والأسلوب، والمشهد، والإضاءة والكاميرا، وكل موضوع مع ألوانه ومواده وموقعه في الإطار. يغطي نموذج واحد توليد الصور من النص، والتحرير باستخدام الصور المرجعية، والتخطيط باستخدام الصناديق. يعود الوصف الذي كتبه كإخراج <code>prompt</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-python "><!---->out = pipe(
prompt=<span class="hljs-string">&quot;A red fox in a snow-covered forest clearing at golden hour&quot;</span>,
generator=torch.Generator().manual_seed(<span class="hljs-number">0</span>),
output=[<span class="hljs-string">&quot;images&quot;</span>, <span class="hljs-string">&quot;prompt&quot;</span>],
)
<span class="hljs-built_in">print</span>(out[<span class="hljs-string">&quot;prompt&quot;</span>])<!----></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=" "><!---->Full-color outdoor wildlife photograph taken <span class="hljs-built_in">from</span> <span class="hljs-keyword">a</span> low eye-level perspective <span class="hljs-keyword">in</span> <span class="hljs-keyword">a</span> snow-covered forest clearing <span class="hljs-keyword">at</span> golden hour. In <span class="hljs-keyword">the</span> center foreground, <span class="hljs-keyword">a</span> red fox stands <span class="hljs-keyword">in</span> profile facing left, its body turned toward <span class="hljs-keyword">the</span> viewer <span class="hljs-keyword">and</span> its head raised <span class="hljs-keyword">as</span> <span class="hljs-keyword">it</span> looks across <span class="hljs-keyword">the</span> clearing. The fox has dense rust-red winter fur, <span class="hljs-keyword">a</span> white throat <span class="hljs-keyword">and</span> chest, <span class="hljs-keyword">black</span> <span class="hljs-built_in">lower</span> legs, pointed ears <span class="hljs-keyword">with</span> dark tips, <span class="hljs-keyword">and</span> <span class="hljs-keyword">a</span> <span class="hljs-keyword">long</span> bushy tail ending <span class="hljs-keyword">in</span> white. ...<!----></pre></div><!----> <p>يصل طول الوصف الكامل إلى حوالي 240 كلمة؛ ويحدد <code>max_new_tokens</code> حدّ طوله (3584 افتراضيًا).</p> <p>يمكنك طباعة <code>doc</code> الخاص بالخطوة لمعرفة ما يستهلكه وما يكتبه:</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> تم النسخ</div><!----></button><!----></div> <pre class="language-python "><!----><span class="hljs-built_in">print</span>(pipe.blocks.sub_blocks[<span class="hljs-string">&quot;prompt_upsampler&quot;</span>].doc)<!----></pre></div><!----> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> تم النسخ</div><!----></button><!----></div> <pre class=" "><!----> <span class="hljs-symbol">Inputs</span>:
prompt (<span class="hljs-string">`str`</span>):
<span class="hljs-symbol">The</span> edit instruction to expand into the full caption (one per call).
image (<span class="hljs-string">`Image | list`</span>, *optional*):
<span class="hljs-symbol">The</span> reference image(s) of the edit, at most <span class="hljs-number">10</span>; the same ones the pipeline receives.
boxes (<span class="hljs-string">`list`</span>, *optional*):
<span class="hljs-symbol">Layout</span> boxes, each {<span class="hljs-string">&#x27;id&#x27;</span>, <span class="hljs-string">&#x27;desc&#x27;</span>, <span class="hljs-string">&#x27;from&#x27;</span>, <span class="hljs-string">&#x27;src_bbox&#x27;</span>, <span class="hljs-string">&#x27;tgt_bbox&#x27;</span>} with the boxes as [y_min, x_min, y_max, x_max] in
<span class="hljs-number">0</span><span class="hljs-number">-1</span>: ...
max_new_tokens (<span class="hljs-string">`int`</span>, *optional*, defaults to <span class="hljs-number">3584</span>):
<span class="hljs-symbol">The</span> most tokens the upsampler may generate for the caption.
<span class="hljs-symbol">Outputs</span>:
prompt (<span class="hljs-string">`str`</span>):
<span class="hljs-symbol">The</span> full caption, replacing the request.<!----></pre></div><!----> <p>كما هو الحال مع الكتل الأخرى في خط المعالجة، يعمل كتلة <code>prompt_upsampler</code> بشكل مستقل. الطريقة الموصى بها هي فصلها عن الكتل: تصبح الكتلة المفصولة مُوسِّعًا مستقلًا، وتصبح الكتل المتبقية خط معالجة يستقبل الوصف الموسَّع بوصفه <code>prompt</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-python "><!---->blocks = ModularPipeline.from_pretrained(<span class="hljs-string">&quot;black-forest-labs/flux-3-image-klein-base&quot;</span>).blocks
pup_block = blocks.sub_blocks.pop(<span class="hljs-string">&quot;prompt_upsampler&quot;</span>)
pup = pup_block.init_pipeline(<span class="hljs-string">&quot;black-forest-labs/flux-3-image-klein-base&quot;</span>)
pup.load_components(dtype=torch.bfloat16)
pup.to(<span class="hljs-string">&quot;cuda&quot;</span>)
caption = pup(prompt=<span class="hljs-string">&quot;A red fox in a snow-covered forest clearing at golden hour&quot;</span>, output=<span class="hljs-string">&quot;prompt&quot;</span>)
pipe = blocks.init_pipeline(<span class="hljs-string">&quot;black-forest-labs/flux-3-image-klein-base&quot;</span>)
pipe.load_components(dtype={<span class="hljs-string">&quot;vae&quot;</span>: torch.float32, <span class="hljs-string">&quot;default&quot;</span>: torch.bfloat16})
pipe.to(<span class="hljs-string">&quot;cuda&quot;</span>)
image = pipe(prompt=caption, generator=torch.Generator().manual_seed(<span class="hljs-number">0</span>), output=<span class="hljs-string">&quot;images&quot;</span>)[<span class="hljs-number">0</span>]<!----></pre></div><!----> <p>بهذه الطريقة يمكن تقديمه كمرحلة مستقلة، على وحدة معالجة رسومية خاصة به أو خلف نقطة نهاية خاصة به، ويمكن لواجهة المستخدم أن تعرض الوصف الذي كتبه وتتيح للمستخدم تعديله قبل التوليد. يمكن لأي نموذج لغوي آخر أن يحل محل مُوسِّع الدقة، مع استخدام نفس أوامر النظام: أعطِه <code>system_prompts["t2i"]</code> من مستودع مُوسِّع الدقة (أو <code>"i2i"</code>، مع وضع المراجع أولاً في رسالة المستخدم) كمرجع للنظام والطلب كرسالة للمستخدم، ثم مرِّر الوصف الذي يعيده كـ<code>prompt</code> إلى <code>pipe</code>.</p> <!--[1--><h2 class="relative group"><a id="image-to-image" 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="#image-to-image"><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>مرّر صورة مرجعية واحدة أو أكثر باستخدام <code>image</code>. تُحافظ الصورة المرجعية الواحدة على شكلها الكامل: فهي تُصغَّر فقط إذا تجاوزت 4 ميغابكسل، وتُملأ لتتوافق مع شبكة البكسلات البالغة 16 بكسل، وتكون القيمة الافتراضية للتوليد مطابقة لحجمها، لذا يعود التعديل بالحجم نفسه الذي دخلت به الصورة. أما الصور المرجعية المتعددة فتُصغَّر كل منها لتبقى تحت 1 ميغابكسل وتُقتطع لتتوافق مع الشبكة، وتكون القيمة الافتراضية للتوليد مطابقة لحجم الصورة الأولى. يمكن تجاوز القيمة الافتراضية بتحديد <code>height</code>/<code>width</code> معين. صف صورة <em>الهدف</em> بوصف كامل للصورة المرجعية مع دمج التعديل المطلوب فيها، بدلاً من تعليمات سطر واحد، أو اترك <a href="#prompt-upsampling">prompt upsampler</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-python "><!---->night = pipe(
prompt=<span class="hljs-string">&quot;the same scene at night under a full moon&quot;</span>,
image=image,
generator=torch.Generator().manual_seed(<span class="hljs-number">0</span>),
output=[<span class="hljs-string">&quot;images&quot;</span>, <span class="hljs-string">&quot;prompt&quot;</span>],
)<!----></pre></div><!----> <p>مع وجود عدة مراجع، يُشار إليها على أنها الصورة الأولى، الصورة الثانية، … بالترتيب الذي تُمرَّر به إلى <code>image</code>؛ حيث تُسمّيها التسمية <code>&lt;ref_image_0></code>، <code>&lt;ref_image_1></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-python "><!---->combined = pipe(
prompt=<span class="hljs-string">&quot;the fox from the first image sitting on the wooden bench from the second image&quot;</span>,
image=[image, bench],
height=<span class="hljs-number">768</span>,
width=<span class="hljs-number">1360</span>,
output=<span class="hljs-string">&quot;images&quot;</span>,
)[<span class="hljs-number">0</span>]<!----></pre></div><!----> <p>مرّر <code>height</code> و/أو <code>width</code> لتجاوز الحجم المستنتج.</p> <!--[1--><h2 class="relative group"><a id="layout-control" 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="#layout-control"><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>لوضع المحتوى بشكل صريح، مرّر <code>boxes</code>: لكل عنصر <code>id</code>، و<code>desc</code> مختصر، و<code>bbox</code> على شكل <code>[y_min, x_min, y_max, x_max]</code> ضمن نطاق 0-1 (المبدأ أعلى اليسار)، بحيث يكون مستقلاً عن حجم المخرجات. يكتب المُوسِّع الوصف حولها، مستشهداً بكل عنصر على شكل <code>&lt;id></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-python "><!---->boxes = [
{<span class="hljs-string">&quot;id&quot;</span>: <span class="hljs-string">&quot;balloon_1&quot;</span>, <span class="hljs-string">&quot;desc&quot;</span>: <span class="hljs-string">&quot;a red and yellow striped hot-air balloon&quot;</span>, <span class="hljs-string">&quot;bbox&quot;</span>: [<span class="hljs-number">0.08</span>, <span class="hljs-number">0.06</span>, <span class="hljs-number">0.48</span>, <span class="hljs-number">0.38</span>]},
{<span class="hljs-string">&quot;id&quot;</span>: <span class="hljs-string">&quot;balloon_2&quot;</span>, <span class="hljs-string">&quot;desc&quot;</span>: <span class="hljs-string">&quot;a small blue hot-air balloon&quot;</span>, <span class="hljs-string">&quot;bbox&quot;</span>: [<span class="hljs-number">0.20</span>, <span class="hljs-number">0.62</span>, <span class="hljs-number">0.42</span>, <span class="hljs-number">0.80</span>]},
]
out = pipe(prompt=<span class="hljs-string">&quot;hot-air balloons over a green valley at sunrise&quot;</span>, boxes=boxes, output=[<span class="hljs-string">&quot;images&quot;</span>, <span class="hljs-string">&quot;prompt&quot;</span>])<!----></pre></div><!----> <p>عند التحرير، يحدد الصندوق مصدره بواسطة <code>from</code>: <code>"target"</code> مع <code>tgt_bbox</code> يضيف عنصراً جديداً في ذلك الموقع، و<code>"ref_image_0"</code> مع <code>src_bbox</code> و<code>tgt_bbox</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-python "><!---->boxes = [{<span class="hljs-string">&quot;id&quot;</span>: <span class="hljs-string">&quot;cactus&quot;</span>, <span class="hljs-string">&quot;desc&quot;</span>: <span class="hljs-string">&quot;a small potted cactus&quot;</span>, <span class="hljs-string">&quot;from&quot;</span>: <span class="hljs-string">&quot;target&quot;</span>, <span class="hljs-string">&quot;src_bbox&quot;</span>: <span class="hljs-literal">None</span>, <span class="hljs-string">&quot;tgt_bbox&quot;</span>: [<span class="hljs-number">0.55</span>, <span class="hljs-number">0.62</span>, <span class="hljs-number">0.85</span>, <span class="hljs-number">0.85</span>]}]
out = pipe(prompt=<span class="hljs-string">&quot;add a small potted cactus in the marked spot&quot;</span>, image=mug, boxes=boxes, output=[<span class="hljs-string">&quot;images&quot;</span>, <span class="hljs-string">&quot;prompt&quot;</span>])
boxes = [{<span class="hljs-string">&quot;id&quot;</span>: <span class="hljs-string">&quot;knight&quot;</span>, <span class="hljs-string">&quot;desc&quot;</span>: <span class="hljs-string">&quot;the knight figure&quot;</span>, <span class="hljs-string">&quot;from&quot;</span>: <span class="hljs-string">&quot;ref_image_0&quot;</span>, <span class="hljs-string">&quot;src_bbox&quot;</span>: [<span class="hljs-number">0.50</span>, <span class="hljs-number">0.15</span>, <span class="hljs-number">0.85</span>, <span class="hljs-number">0.35</span>], <span class="hljs-string">&quot;tgt_bbox&quot;</span>: [<span class="hljs-number">0.19</span>, <span class="hljs-number">0.06</span>, <span class="hljs-number">0.54</span>, <span class="hljs-number">0.26</span>]}]
out = pipe(prompt=<span class="hljs-string">&quot;move the knight up and to the left, keep the rest unchanged&quot;</span>, image=knight, boxes=boxes, output=[<span class="hljs-string">&quot;images&quot;</span>, <span class="hljs-string">&quot;prompt&quot;</span>])<!----></pre></div><!----> <p>يحتوي الوصف الذي يقرأه نموذج الصورة على العناصر الموسومة بـ <code>&lt;id></code> في النص، مع الجدول المضاف بصيغة JSON، حيث تكون الصناديق على لوحة بأبعاد 0-1000؛ اطبع مخرجات <code>prompt</code> لرؤيتها. أما الوصف المكتوب يدوياً بهذه الصيغة فيمر عبر خط الأنابيب دون هذه الخطوة، كما هو الحال في <a href="#prompt-upsampling">توسيع المحفّز</a>.</p> <!--[1--><h2 class="relative group"><a id="guidance-scale" 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="#guidance-scale"><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>يطبّق خطّ الأنابيب التوجيه الحرّ من التصنيف عبر مكوّنه <code>guider</code> ولا يقبل حجة <code>guidance_scale</code> عند الاستدعاء. الموجّه الافتراضي هو <a href="/docs/diffusers/main/ar/api/modular_diffusers/guiders#diffusers.ClassifierFreeGuidance">ClassifierFreeGuidance</a> مع <code>guidance_scale=3.5</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-python "><!---->pipe.guider = pipe.guider.new(guidance_scale=<span class="hljs-number">5.0</span>)<!----></pre></div><!----> <p>راجع <a href="../../using-diffusers/guiders">دليل المرشدين</a> للتبديل إلى طريقة إرشاد مختلفة.</p> <!--[1--><h2 class="relative group"><a id="step-distilled-model" 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="#step-distilled-model"><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>يولّد نقطة الفحص المُقطّرة خطوةً بخطوة في 16 خطوةً دون توجيهٍ حرٍّ من المُصنِّف. محوّله هو خريطة تدفّق: في كل خطوة يُبلَّغ بالخطوة الزمنية الحالية والخطوة التي تقفز إليها الخطوة. يُحمَّل مثل النموذج الأساسي (حيث يحلّ <code>modular_model_index.json</code> في المستودع إلى <a href="/docs/diffusers/main/ar/api/pipelines/flux3#diffusers.Flux3DistilledModularPipeline">Flux3DistilledModularPipeline</a> و<a href="/docs/diffusers/main/ar/api/pipelines/flux3#diffusers.Flux3DistilledAutoBlocks">Flux3DistilledAutoBlocks</a>)؛ ولا يحتوي خطّ الأنابيب على <code>guider</code> ولا يقبل <code>negative_prompt</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-python "><!---->pipe = ModularPipeline.from_pretrained(<span class="hljs-string">&quot;black-forest-labs/flux-3-image-klein&quot;</span>)
pipe.load_components(dtype=torch.bfloat16)
pipe.to(<span class="hljs-string">&quot;cuda&quot;</span>)
image = pipe(prompt=prompt, generator=torch.Generator().manual_seed(<span class="hljs-number">0</span>), output=<span class="hljs-string">&quot;images&quot;</span>)[<span class="hljs-number">0</span>]<!----></pre></div><!----> <p>يخدم نفس مساري العمل اللذين يخدمهما النموذج الأساسي. القيمة الافتراضية لـ<code>num_inference_steps</code> هي 16؛ حيث تم تدريب النموذج على 4 إلى 16 خطوة.</p> <!--[1--><h2 class="relative group"><a id="reproducible-generation" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#reproducible-generation"><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>يُثبّت <code>generator</code> الضوضاء التي يسحبها خط الأنابيب (انظر <a href="../../using-diffusers/reusing_seeds">إعادة الإنتاج</a>). لإعادة استخدام ضوضاء سُحبت في مكان آخر، مرّرها كـ <code>latents</code> بالشكل <code>(batch_size, 128, height // 16, width // 16)</code>. على سبيل المثال، يسحب <a href="https://github.com/black-forest-labs/flux-3-image-klein" rel="nofollow">تنفيذ BFL</a> ضوضاءه كرموز صورة على وحدة المعالجة المركزية (CPU) ويحوّلها إلى bf16؛ وهذا يُعيد إنتاج عيّنته لبذرة محددة:</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-python "><!---->height, width = <span class="hljs-number">1024</span>, <span class="hljs-number">1024</span>
h, w = height // <span class="hljs-number">16</span>, width // <span class="hljs-number">16</span>
noise = torch.randn((h * w, <span class="hljs-number">128</span>), generator=torch.Generator().manual_seed(<span class="hljs-number">0</span>)).to(torch.bfloat16)
latents = noise.T.reshape(<span class="hljs-number">1</span>, <span class="hljs-number">128</span>, h, w)
image = pipe(prompt=prompt, latents=latents, height=height, width=width, output=<span class="hljs-string">&quot;images&quot;</span>)[<span class="hljs-number">0</span>]<!----></pre></div><!----> <!--[1--><h2 class="relative group"><a id="workflows" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#workflows"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span><!---->سير العمل<!----></span></h2><!--]--><!----> <p>تخدم خط المعالجة مساري عمل، هما <code>text2image</code> و<code>image_conditioned</code>؛ ويُختار المسار الذي يُنفَّذ بناءً على المدخلات (حيث يحدد <code>image</code> مسار الصورة إلى الصورة). كما يمكن لـ<a href="/docs/diffusers/main/ar/api/modular_diffusers/pipeline#diffusers.ModularPipeline.from_pretrained">from_pretrained()</a> بناء خط معالجة لمسار عمل واحد باستخدام معامل <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-python "><!----><span class="hljs-keyword">from</span> diffusers.modular_pipelines <span class="hljs-keyword">import</span> Flux3AutoBlocks
<span class="hljs-built_in">print</span>(Flux3AutoBlocks().available_workflows)
<span class="hljs-comment"># [&quot;text2image&quot;, &quot;image_conditioned&quot;]</span>
t2i = ModularPipeline.from_pretrained(<span class="hljs-string">&quot;black-forest-labs/flux-3-image-klein-base&quot;</span>, workflow=<span class="hljs-string">&quot;text2image&quot;</span>)
<span class="hljs-built_in">print</span>(t2i.blocks.doc)<!----></pre></div><!----> <!--[1--><h2 class="relative group"><a id="per-step-callbacks" 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="#per-step-callbacks"><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="../../using-diffusers/callback#modular-pipelines">دليل الاستدعاءات</a> على مثال بسيط باستخدام كتلة <code>CallbackOnStepEnd</code> ودالة المساعدة <code>walk_denoise_loops</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-python "><!---->blocks = Flux3AutoBlocks() <span class="hljs-comment"># or Flux3DistilledAutoBlocks</span>
<span class="hljs-keyword">for</span> loop <span class="hljs-keyword">in</span> walk_denoise_loops(blocks):
loop.sub_blocks[<span class="hljs-string">&quot;callback&quot;</span>] = CallbackOnStepEnd()
pipe = blocks.init_pipeline(<span class="hljs-string">&quot;black-forest-labs/flux-3-image-klein-base&quot;</span>)
image = pipe(prompt=caption, callback_on_step_end=my_callback, output=<span class="hljs-string">&quot;images&quot;</span>)[<span class="hljs-number">0</span>]<!----></pre></div><!----> <p>للتوقف مبكرًا، ارفع استثناءً من الدالة الاستدعائية؛ لا يوجد علم <code>interrupt</code>.</p> <!--[1--><h2 class="relative group"><a id="memory" 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="#memory"><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>تتطلب التحميل الكامل في bf16 حوالي 39 جيجابايت من الأوزان: حيث يتكون الترانسفورمر من 5.5 مليار معلمة، ومشفّر النص Qwen3-VL-4B من 4 مليارات، و<a href="#prompt-upsampling">موسّع الأوامر</a> من 9 مليارات (حوالي 19 جيجابايت بمفرده)، مع استخدام VAE للصور في fp32. أما خط الأنابيب الذي يُبنى دون خطوة الموسّع (انظر هناك) فيحمّل حوالي 20 جيجابايت. بالنسبة للوحدات الرسومية ذات ذاكرة أقل، فعّل تفريغ المكونات؛ حيث يقوم المدير بنقل المكونات بين وحدة المعالجة المركزية والوحدة الرسومية كلما احتاجت كل خطوة إليها، بما في ذلك الموسّع:</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-python "><!----><span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> ComponentsManager, ModularPipeline
manager = ComponentsManager()
pipe = ModularPipeline.from_pretrained(<span class="hljs-string">&quot;black-forest-labs/flux-3-image-klein-base&quot;</span>, components_manager=manager)
pipe.load_components(dtype={<span class="hljs-string">&quot;vae&quot;</span>: torch.float32, <span class="hljs-string">&quot;default&quot;</span>: torch.bfloat16})
manager.enable_auto_cpu_offload(device=<span class="hljs-string">&quot;cuda&quot;</span>)<!----></pre></div><!----> <!--[1--><h2 class="relative group"><a id="single-file-loading" 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="#single-file-loading"><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/main/ar/api/models/flux3_transformer#diffusers.Flux3Transformer2DModel">Flux3Transformer2DModel</a> نموذج التحويل مباشرةً من حزمة نموذج Black Forest Labs باستخدام <a href="/docs/diffusers/main/ar/api/loaders/single_file#diffusers.loaders.FromOriginalModelMixin.from_single_file">from_single_file()</a>. لا يتم قراءة ملف <code>config.json</code> في الحزمة؛ بل مرّر إعدادات diffusers عبر <code>config</code> و<code>subfolder</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-python "><!----><span class="hljs-keyword">import</span> torch
<span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> Flux3Transformer2DModel, ModularPipeline
transformer = Flux3Transformer2DModel.from_single_file(
<span class="hljs-string">&quot;https://huggingface.co/black-forest-labs/flux-3-image-klein-base/blob/main/model.safetensors&quot;</span>,
config=<span class="hljs-string">&quot;black-forest-labs/flux-3-image-klein-base&quot;</span>,
subfolder=<span class="hljs-string">&quot;transformer&quot;</span>,
dtype=torch.bfloat16,
)
pipe = ModularPipeline.from_pretrained(<span class="hljs-string">&quot;black-forest-labs/flux-3-image-klein-base&quot;</span>)
pipe.load_components(dtype={<span class="hljs-string">&quot;vae&quot;</span>: torch.float32, <span class="hljs-string">&quot;default&quot;</span>: torch.bfloat16})
pipe.update_components(transformer=transformer)
pipe.to(<span class="hljs-string">&quot;cuda&quot;</span>)<!----></pre></div><!----> <p>حمّل المكونات الأخرى بالاسم أولاً: <a href="/docs/diffusers/main/ar/api/modular_diffusers/pipeline#diffusers.ModularPipeline.load_components">load_components()</a> بدون <code>names</code> سيؤدي أيضاً إلى تحميل المُحوِّل من مستودع خط المعالجة.</p> <p>تُدعم أيضاً عملية تحميل نقاط التفتيش أحادية الملف الخاصة بـ FP8r وNVFP4. يتم تحميل كلاهما عبر نفس الاستدعاء باستخدام <a href="/docs/diffusers/main/ar/api/quantization#diffusers.BFLQuantizationConfig">BFLQuantizationConfig</a>. راجع <a href="../../quantization/bfl">دليل تكميم BFL</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-python "><!----><span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> BFLQuantizationConfig
transformer = Flux3Transformer2DModel.from_single_file(
<span class="hljs-string">&quot;https://huggingface.co/black-forest-labs/flux-3-image-klein-base/blob/main/variants/nvfp4/model.safetensors&quot;</span>,
config=<span class="hljs-string">&quot;black-forest-labs/flux-3-image-klein-base&quot;</span>,
subfolder=<span class="hljs-string">&quot;transformer&quot;</span>,
quantization_config=BFLQuantizationConfig(compute_dtype=torch.bfloat16),
dtype=torch.bfloat16,
)<!----></pre></div><!----> <p>عند تحميل نقاط التفتيش المُقطّرة خطوة بخطوة، نحتاج إلى إعداداتها (<code>flow_map=True</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-python "><!---->transformer = Flux3Transformer2DModel.from_single_file(
<span class="hljs-string">&quot;https://huggingface.co/black-forest-labs/flux-3-image-klein/blob/main/variants/nvfp4/model.safetensors&quot;</span>,
config=<span class="hljs-string">&quot;black-forest-labs/flux-3-image-klein&quot;</span>,
subfolder=<span class="hljs-string">&quot;transformer&quot;</span>,
quantization_config=BFLQuantizationConfig(compute_dtype=torch.bfloat16),
dtype=torch.bfloat16,
)<!----></pre></div><!----> <!--[1--><h2 class="relative group"><a id="diffusers.Flux3ModularPipeline" 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="#diffusers.Flux3ModularPipeline"><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><!---->Flux3ModularPipeline<!----></span></h2><!--]--><!----> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><div><span class="group flex space-x-1.5 items-center text-gray-800 bg-gradient-to-r rounded-tr-lg -mt-4 -ml-4 pt-3 px-2.5" id="diffusers.Flux3ModularPipeline"><!----><h3 class="!m-0"><span class="flex-1 break-all md:text-lg bg-gradient-to-r px-2.5 py-1.5 rounded-xl from-indigo-50/70 to-white dark:from-gray-900 dark:to-gray-950 dark:text-indigo-300 text-indigo-700"><svg class="mr-1.5 text-indigo-500 inline-block -mt-0.5" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" focusable="false" role="img" width=".8em" height=".8em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 24 24"><path class="uim-quaternary" d="M20.23 7.24L12 12L3.77 7.24a1.98 1.98 0 0 1 .7-.71L11 2.76c.62-.35 1.38-.35 2 0l6.53 3.77c.29.173.531.418.7.71z" opacity=".25" fill="currentColor"></path><path class="uim-tertiary" d="M12 12v9.5a2.09 2.09 0 0 1-.91-.21L4.5 17.48a2.003 2.003 0 0 1-1-1.73v-7.5a2.06 2.06 0 0 1 .27-1.01L12 12z" opacity=".5" fill="currentColor"></path><path class="uim-primary" d="M20.5 8.25v7.5a2.003 2.003 0 0 1-1 1.73l-6.62 3.82c-.275.13-.576.198-.88.2V12l8.23-4.76c.175.308.268.656.27 1.01z" fill="currentColor"></path></svg><span class="font-light">فئة</span> <span class="font-medium">diffusers.</span><span class="font-semibold">Flux3ModularPipeline</span></span></h3><!----> <a id="diffusers.Flux3ModularPipeline" class="header-link invisible with-hover:group-hover:visible pr-2" href="#diffusers.Flux3ModularPipeline"><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><!----></a> <!--[0--><a class="!ml-auto !text-gray-400 !no-underline text-sm flex items-center" href="https://github.com/huggingface/diffusers/blob/main/src/diffusers/modular_pipelines/flux3/modular_pipeline.py#L24" target="_blank"><span>&lt;</span> <span class="hidden md:block mx-0.5 hover:!underline">source</span> <span>></span></a><!--]--></span> <!--[0--><p class="font-mono text-xs md:text-sm !leading-relaxed !my-6"><span>(</span> <!--[--><span class="comma cursor-default"><span class="rounded hover:bg-black hover:text-white dark:hover:bg-white dark:hover:text-black">blocks<span class="opacity-60">: diffusers.modular_pipelines.modular_pipeline.ModularPipelineBlocks | None = None</span></span></span><span class="comma cursor-default"><span class="rounded hover:bg-black hover:text-white dark:hover:bg-white dark:hover:text-black">pretrained_model_name_or_path<span class="opacity-60">: str | os.PathLike | None = None</span></span></span><span class="comma cursor-default"><span class="rounded hover:bg-black hover:text-white dark:hover:bg-white dark:hover:text-black">components_manager<span class="opacity-60">: diffusers.modular_pipelines.components_manager.ComponentsManager | None = None</span></span></span><span class="comma cursor-default"><span class="rounded hover:bg-black hover:text-white dark:hover:bg-white dark:hover:text-black">collection<span class="opacity-60">: str | None = None</span></span></span><span class="comma cursor-default"><span class="rounded hover:bg-black hover:text-white dark:hover:bg-white dark:hover:text-black">workflow<span class="opacity-60">: str | None = None</span></span></span><span class="comma cursor-default"><span class="rounded hover:bg-black hover:text-white dark:hover:bg-white dark:hover:text-black">modular_config_dict<span class="opacity-60">: dict[str, typing.Any] | None = None</span></span></span><span class="comma cursor-default"><span class="rounded hover:bg-black hover:text-white dark:hover:bg-white dark:hover:text-black">config_dict<span class="opacity-60">: dict[str, typing.Any] | None = None</span></span></span><span class="comma cursor-default"><span class="rounded hover:bg-black hover:text-white dark:hover:bg-white dark:hover:text-black">**kwargs<span class="opacity-60"></span></span></span><!--]--> <span>)</span> <!--[-1--><!--]--></p><!--]--> <div class="!mb-10 relative docstring-details "><!--[-1--><!--]--> <!--[-1--><!--]--> <!--[-1--><!--]--> <!--[-1--><!--]--> <!--[-1--><!--]--></div></div><!----> <p>خط أنابيب معياري لـ FLUX.3.</p></div> <!--[1--><h2 class="relative group"><a id="diffusers.Flux3AutoBlocks" 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="#diffusers.Flux3AutoBlocks"><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><!---->Flux3AutoBlocks<!----></span></h2><!--]--><!----> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><div><span class="group flex space-x-1.5 items-center text-gray-800 bg-gradient-to-r rounded-tr-lg -mt-4 -ml-4 pt-3 px-2.5" id="diffusers.Flux3AutoBlocks"><!----><h3 class="!m-0"><span class="flex-1 break-all md:text-lg bg-gradient-to-r px-2.5 py-1.5 rounded-xl from-indigo-50/70 to-white dark:from-gray-900 dark:to-gray-950 dark:text-indigo-300 text-indigo-700"><svg class="mr-1.5 text-indigo-500 inline-block -mt-0.5" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" focusable="false" role="img" width=".8em" height=".8em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 24 24"><path class="uim-quaternary" d="M20.23 7.24L12 12L3.77 7.24a1.98 1.98 0 0 1 .7-.71L11 2.76c.62-.35 1.38-.35 2 0l6.53 3.77c.29.173.531.418.7.71z" opacity=".25" fill="currentColor"></path><path class="uim-tertiary" d="M12 12v9.5a2.09 2.09 0 0 1-.91-.21L4.5 17.48a2.003 2.003 0 0 1-1-1.73v-7.5a2.06 2.06 0 0 1 .27-1.01L12 12z" opacity=".5" fill="currentColor"></path><path class="uim-primary" d="M20.5 8.25v7.5a2.003 2.003 0 0 1-1 1.73l-6.62 3.82c-.275.13-.576.198-.88.2V12l8.23-4.76c.175.308.268.656.27 1.01z" fill="currentColor"></path></svg><span class="font-light">فئة</span> <span class="font-medium">diffusers.</span><span class="font-semibold">Flux3AutoBlocks</span></span></h3><!----> <a id="diffusers.Flux3AutoBlocks" class="header-link invisible with-hover:group-hover:visible pr-2" href="#diffusers.Flux3AutoBlocks"><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><!----></a> <!--[0--><a class="!ml-auto !text-gray-400 !no-underline text-sm flex items-center" href="https://github.com/huggingface/diffusers/blob/main/src/diffusers/modular_pipelines/flux3/modular_blocks_flux3.py#L339" target="_blank"><span>&lt;</span> <span class="hidden md:block mx-0.5 hover:!underline">source</span> <span>></span></a><!--]--></span> <!--[0--><p class="font-mono text-xs md:text-sm !leading-relaxed !my-6"><span>(</span> <!--[--><!--]--> <span>)</span> <!--[-1--><!--]--></p><!--]--> <div class="!mb-10 relative docstring-details "><!--[-1--><!--]--> <!--[-1--><!--]--> <!--[-1--><!--]--> <!--[-1--><!--]--> <!--[-1--><!--]--></div></div><!----> <p>Auto blocks التي تنفّذ توليد الصور من النص وتوليد الصور من الصور باستخدام FLUX.3. يمرّ <code>prompt</code> أولاً عبر مُوسّع المُوجِّه؛ احذف خطوة <code>prompt_upsampler</code> لتشفيره كما هو.</p> <p>سير العمل المدعومة:</p> <ul><li><code>text2image</code>: يتطلب <code>prompt</code></li> <li><code>image_conditioned</code>: يتطلب <code>prompt</code>، <code>image</code></li></ul> <p>المكوّنات:
prompt_upsampler (<code>Qwen3_5ForConditionalGeneration</code>): مُوسّع المُوجّه. prompt_upsampler_processor
(<code>AutoProcessor</code>): مُعالِجه. text_encoder (<code>Qwen3VLForConditionalGeneration</code>) tokenizer
(<code>AutoProcessor</code>) image_processor (<code>Flux3ImageProcessor</code>) vae (<code>AutoencoderKLFlux2</code>) transformer
(<code>Flux3Transformer2DModel</code>) scheduler (<code>FlowMatchEulerDiscreteScheduler</code>) guider (<code>ClassifierFreeGuidance</code>)</p> <p>المدخلات:
prompt (<code>str</code>):
تعليمات التحرير التي سيتم توسيعها إلى وصف كامل (واحدة لكل استدعاء).
image (<code>Image | list</code>, <em>اختياري</em>):
الصورة المرجعية أو الصور المرجعية للتحرير، بحد أقصى 10 صور؛ وهي نفس الصور التي تستقبلها خط المعالجة.
boxes (<code>list</code>, <em>اختياري</em>):
صناديق التخطيط، حيث يحتوي كل صندوق على {‘id’, ‘desc’, ‘from’, ‘src_bbox’, ‘tgt_bbox’} مع تمثيل الصناديق على شكل [y_min, x_min, y_max,
x_max] ضمن نطاق 0-1: ‘from’: ‘target’ مع <code>tgt_bbox</code> يضيف عنصراً في ذلك الموقع، و‘from’: ‘ref_image_0’، … مع <code>src_bbox</code> و<code>tgt_bbox</code> ينقل عنصراً من صورة مرجعية.
max_new_tokens (<code>int</code>, <em>اختياري</em>, القيمة الافتراضية 3584):
أقصى عدد من الرموز التي قد يولدها مُوسّع الوصف.
negative_prompt (<code>str</code>, <em>اختياري</em>):
الموجّه الذي يجب عدم استخدامه لتوجيه التوليد.
max_sequence_length (<code>int</code>, <em>اختياري</em>, القيمة الافتراضية 8192):
الحد الأقصى لعدد رموز الموجّه؛ يتم اقتطاع الموجّهات الأطول من ذلك.
text_encoder_out_layers (<code>tuple</code>, <em>اختياري</em>, القيمة الافتراضية (4, 8, 12, 16, 20, 24, 28, 32)):
فهارس الطبقات المخفية في مُشفّر النص التي تُكدّس حالاتها لتكوين تضمينات النص.
num_images_per_prompt (<code>int</code>, <em>اختياري</em>, القيمة الافتراضية 1):
عدد الصور التي سيتم توليدها لكل موجّه.
image_cond_latents (<code>list</code>, <em>اختياري</em>):
كائنات latents المُجمّعة والمُعايرة للصور المرجعية، حيث يكون لكل صورة كائن واحد بأبعاد (B, C, height_i//16, width_i//16).
height (<code>int</code>, <em>اختياري</em>, القيمة الافتراضية None أو 1024، حسب سير العمل):
ارتفاع الصورة المولّدة بالبكسلات؛ القيمة الافتراضية هي ارتفاع الصورة المرجعية الأولى نفسها.
width (<code>int</code>, <em>اختياري</em>, القيمة الافتراضية None أو 1024، حسب سير العمل):
عرض الصورة المولّدة بالبكسلات؛ القيمة الافتراضية هي عرض الصورة المرجعية الأولى نفسها.
reference_crop (<code>list | NoneType</code>, <em>اختياري</em>):
لكل مرجع، صندوق المرجع داخل لوحته المُبطّنة أو None، من خطوة المعالجة المسبقة.
latents (<code>Tensor</code>):
كائنات latents الضجيج المُولّدة مسبقاً لتوليد الصور.
generator (<code>Generator</code>, <em>اختياري</em>):
مولّد Torch لتوليد حتمي.
num_inference_steps (<code>int</code>):
عدد خطوات إزالة الضجيج.
timesteps (<code>Tensor</code>):
خطوات الزمن لعملية إزالة الضجيج. (تتجاوز <code>num_inference_steps</code> عند تقديمها)
sigmas (<code>list</code>, <em>اختياري</em>):
قيم sigmas مخصصة لعملية إزالة الضجيج. (تتجاوز <code>num_inference_steps</code> عند تقديمها)
*<em>denoiser_input_fields (<code>None</code>,</em>اختياري<em>):
مدخلات النموذج الشرطي لمُزيل الضجيج: مثل prompt_embeds، negative_prompt_embeds، إلخ.
attention_kwargs (<code>dict</code>,</em>اختياري<em>):
معاملات kwargs إضافية لمعالجات الانتباه.
output_type (<code>str</code>,</em>اختياري*، القيمة الافتراضية pil):
صيغة الإخراج: ‘pil’، ‘np’، ‘pt’.</p> <p>المخرجات:
صور (<code>list</code>):
الصور المولّدة.
القيم الكامنة (<code>Tensor</code>):
القيم الكامنة بعد إزالة الضوضاء.</p></div> <!--[1--><h2 class="relative group"><a id="diffusers.Flux3DistilledAutoBlocks" 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="#diffusers.Flux3DistilledAutoBlocks"><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><!---->Flux3DistilledAutoBlocks<!----></span></h2><!--]--><!----> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><div><span class="group flex space-x-1.5 items-center text-gray-800 bg-gradient-to-r rounded-tr-lg -mt-4 -ml-4 pt-3 px-2.5" id="diffusers.Flux3DistilledAutoBlocks"><!----><h3 class="!m-0"><span class="flex-1 break-all md:text-lg bg-gradient-to-r px-2.5 py-1.5 rounded-xl from-indigo-50/70 to-white dark:from-gray-900 dark:to-gray-950 dark:text-indigo-300 text-indigo-700"><svg class="mr-1.5 text-indigo-500 inline-block -mt-0.5" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" focusable="false" role="img" width=".8em" height=".8em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 24 24"><path class="uim-quaternary" d="M20.23 7.24L12 12L3.77 7.24a1.98 1.98 0 0 1 .7-.71L11 2.76c.62-.35 1.38-.35 2 0l6.53 3.77c.29.173.531.418.7.71z" opacity=".25" fill="currentColor"></path><path class="uim-tertiary" d="M12 12v9.5a2.09 2.09 0 0 1-.91-.21L4.5 17.48a2.003 2.003 0 0 1-1-1.73v-7.5a2.06 2.06 0 0 1 .27-1.01L12 12z" opacity=".5" fill="currentColor"></path><path class="uim-primary" d="M20.5 8.25v7.5a2.003 2.003 0 0 1-1 1.73l-6.62 3.82c-.275.13-.576.198-.88.2V12l8.23-4.76c.175.308.268.656.27 1.01z" fill="currentColor"></path></svg><span class="font-light">فئة</span> <span class="font-medium">diffusers.</span><span class="font-semibold">Flux3DistilledAutoBlocks</span></span></h3><!----> <a id="diffusers.Flux3DistilledAutoBlocks" class="header-link invisible with-hover:group-hover:visible pr-2" href="#diffusers.Flux3DistilledAutoBlocks"><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><!----></a> <!--[0--><a class="!ml-auto !text-gray-400 !no-underline text-sm flex items-center" href="https://github.com/huggingface/diffusers/blob/main/src/diffusers/modular_pipelines/flux3/modular_blocks_flux3_distilled.py#L258" target="_blank"><span>&lt;</span> <span class="hidden md:block mx-0.5 hover:!underline">source</span> <span>></span></a><!--]--></span> <!--[0--><p class="font-mono text-xs md:text-sm !leading-relaxed !my-6"><span>(</span> <!--[--><!--]--> <span>)</span> <!--[-1--><!--]--></p><!--]--> <div class="!mb-10 relative docstring-details "><!--[-1--><!--]--> <!--[-1--><!--]--> <!--[-1--><!--]--> <!--[-1--><!--]--> <!--[-1--><!--]--></div></div><!----> <p>Auto blocks التي تنفّذ توليد الصور من النص وتوليد الصور من الصور باستخدام نموذج FLUX.3 المُقطّر على مستوى الخطوات (16 خطوة، بدون إرشاد حر من المُصنِّف). يمرّ <code>prompt</code> أولاً عبر مُوسِّع المُوجِّه؛ لإزالته، احذف خطوة <code>prompt_upsampler</code> ليتمّ ترميزه كما هو.</p> <p>سير العمل المدعومة:</p> <ul><li><code>text2image</code>: يتطلب <code>prompt</code></li> <li><code>image_conditioned</code>: يتطلب <code>prompt</code>، <code>image</code></li></ul> <p>المكوّنات:
prompt_upsampler (<code>Qwen3_5ForConditionalGeneration</code>): مُوسّع المُوجّه. prompt_upsampler_processor
(<code>AutoProcessor</code>): مُعالِجه. text_encoder (<code>Qwen3VLForConditionalGeneration</code>) tokenizer
(<code>AutoProcessor</code>) image_processor (<code>Flux3ImageProcessor</code>) vae (<code>AutoencoderKLFlux2</code>) transformer
(<code>Flux3Transformer2DModel</code>) scheduler (<code>FlowMatchEulerDiscreteScheduler</code>)</p> <p>المدخلات:
prompt (<code>str</code>):
تعليمات التحرير التي سيتم توسيعها إلى الوصف الكامل (واحد لكل استدعاء).
image (<code>Image | list</code>, <em>اختياري</em>):
الصورة المرجعية أو الصور المرجعية للتحرير، بحد أقصى 10 صور؛ وهي نفس الصور التي تستقبلها خط المعالجة.
boxes (<code>list</code>, <em>اختياري</em>):
صناديق التخطيط، حيث يحتوي كل صندوق على {‘id’, ‘desc’, ‘from’, ‘src_bbox’, ‘tgt_bbox’} مع تمثيل الصناديق على شكل [y_min, x_min, y_max,
x_max] ضمن نطاق 0-1: ‘from’: ‘target’ مع <code>tgt_bbox</code> يضيف عنصراً في ذلك الموقع، و‘from’: ‘ref_image_0’، … مع <code>src_bbox</code> و<code>tgt_bbox</code> ينقل عنصراً من صورة مرجعية.
max_new_tokens (<code>int</code>, <em>اختياري</em>, القيمة الافتراضية 3584):
أقصى عدد من الرموز التي قد يولدها مُوسّع الوصف.
max_sequence_length (<code>int</code>, <em>اختياري</em>, القيمة الافتراضية 8192):
الحد الأقصى لعدد رموز الأمر؛ يتم اقتطاع الأوامر الأطول من ذلك.
text_encoder_out_layers (<code>tuple</code>, <em>اختياري</em>, القيمة الافتراضية (4, 8, 12, 16, 20, 24, 28, 32)):
فهارس طبقات المُشفِّر النصي المخفية التي تُكدَّس حالاتها لتشكيل التضمينات النصية
num_images_per_prompt (<code>int</code>, <em>اختياري</em>, القيمة الافتراضية 1):
عدد الصور التي سيتم توليدها لكل أمر.
image_cond_latents (<code>list</code>, <em>اختياري</em>):
متغيرات كسولة مضغوطة ومعايرة للصور المرجعية، حيث يكون لكل صورة متجه واحد بأبعاد (B, C, height_i//16, width_i//16)
height (<code>int</code>, <em>اختياري</em>, القيمة الافتراضية None أو 1024، حسب سير العمل):
ارتفاع الصورة المولدة بالبكسلات؛ القيمة الافتراضية هي ارتفاع الصورة المرجعية الأولى نفسها
width (<code>int</code>, <em>اختياري</em>, القيمة الافتراضية None أو 1024، حسب سير العمل):
عرض الصورة المولدة بالبكسلات؛ القيمة الافتراضية هي عرض الصورة المرجعية الأولى نفسها
reference_crop (<code>list | NoneType</code>, <em>اختياري</em>):
لكل مرجع، صندوق المرجع داخل لوحته المحشوة أو None، من خطوة المعالجة المسبقة
latents (<code>Tensor</code>):
متغيرات كسولة ضجيجية مُولَّدة مسبقاً لتوليد الصور.
generator (<code>Generator</code>, <em>اختياري</em>):
مولِّد Torch لتوليد حتمي.
num_inference_steps (<code>int</code>):
عدد خطوات إزالة الضجيج.
timesteps (<code>Tensor</code>):
خطوات الزمن لعملية إزالة الضجيج. (تتجاوز <code>num_inference_steps</code> عند تقديمها)
sigmas (<code>list</code>, <em>اختياري</em>):
قيم سيجما مخصصة لعملية إزالة الضجيج. (تتجاوز <code>num_inference_steps</code> عند تقديمها)
*<em>denoiser_input_fields (<code>None</code>,</em>اختياري<em>):
مدخلات النموذج الشرطي لمزيل الضجيج: مثل prompt_embeds، negative_prompt_embeds، إلخ.
output_type (<code>str</code>,</em>اختياري*، القيمة الافتراضية pil):
صيغة الإخراج: ‘pil’، ‘np’، ‘pt’.</p> <p>المخرجات:
صور (<code>list</code>):
الصور المولّدة.
القيم الكامنة (<code>Tensor</code>):
القيم الكامنة بعد إزالة الضوضاء.</p></div> <!--[1--><h2 class="relative group"><a id="diffusers.Flux3DistilledModularPipeline" 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="#diffusers.Flux3DistilledModularPipeline"><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><!---->Flux3DistilledModularPipeline<!----></span></h2><!--]--><!----> <div class="docstring border-l-2 border-t-2 pl-4 pt-3.5 border-gray-100 rounded-tl-xl mb-6 mt-8"><div><span class="group flex space-x-1.5 items-center text-gray-800 bg-gradient-to-r rounded-tr-lg -mt-4 -ml-4 pt-3 px-2.5" id="diffusers.Flux3DistilledModularPipeline"><!----><h3 class="!m-0"><span class="flex-1 break-all md:text-lg bg-gradient-to-r px-2.5 py-1.5 rounded-xl from-indigo-50/70 to-white dark:from-gray-900 dark:to-gray-950 dark:text-indigo-300 text-indigo-700"><svg class="mr-1.5 text-indigo-500 inline-block -mt-0.5" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" focusable="false" role="img" width=".8em" height=".8em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 24 24"><path class="uim-quaternary" d="M20.23 7.24L12 12L3.77 7.24a1.98 1.98 0 0 1 .7-.71L11 2.76c.62-.35 1.38-.35 2 0l6.53 3.77c.29.173.531.418.7.71z" opacity=".25" fill="currentColor"></path><path class="uim-tertiary" d="M12 12v9.5a2.09 2.09 0 0 1-.91-.21L4.5 17.48a2.003 2.003 0 0 1-1-1.73v-7.5a2.06 2.06 0 0 1 .27-1.01L12 12z" opacity=".5" fill="currentColor"></path><path class="uim-primary" d="M20.5 8.25v7.5a2.003 2.003 0 0 1-1 1.73l-6.62 3.82c-.275.13-.576.198-.88.2V12l8.23-4.76c.175.308.268.656.27 1.01z" fill="currentColor"></path></svg><span class="font-light">فئة</span> <span class="font-medium">diffusers.</span><span class="font-semibold">Flux3DistilledModularPipeline</span></span></h3><!----> <a id="diffusers.Flux3DistilledModularPipeline" class="header-link invisible with-hover:group-hover:visible pr-2" href="#diffusers.Flux3DistilledModularPipeline"><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><!----></a> <!--[0--><a class="!ml-auto !text-gray-400 !no-underline text-sm flex items-center" href="https://github.com/huggingface/diffusers/blob/main/src/diffusers/modular_pipelines/flux3/modular_pipeline.py#L52" target="_blank"><span>&lt;</span> <span class="hidden md:block mx-0.5 hover:!underline">source</span> <span>></span></a><!--]--></span> <!--[0--><p class="font-mono text-xs md:text-sm !leading-relaxed !my-6"><span>(</span> <!--[--><span class="comma cursor-default"><span class="rounded hover:bg-black hover:text-white dark:hover:bg-white dark:hover:text-black">blocks<span class="opacity-60">: diffusers.modular_pipelines.modular_pipeline.ModularPipelineBlocks | None = None</span></span></span><span class="comma cursor-default"><span class="rounded hover:bg-black hover:text-white dark:hover:bg-white dark:hover:text-black">pretrained_model_name_or_path<span class="opacity-60">: str | os.PathLike | None = None</span></span></span><span class="comma cursor-default"><span class="rounded hover:bg-black hover:text-white dark:hover:bg-white dark:hover:text-black">components_manager<span class="opacity-60">: diffusers.modular_pipelines.components_manager.ComponentsManager | None = None</span></span></span><span class="comma cursor-default"><span class="rounded hover:bg-black hover:text-white dark:hover:bg-white dark:hover:text-black">collection<span class="opacity-60">: str | None = None</span></span></span><span class="comma cursor-default"><span class="rounded hover:bg-black hover:text-white dark:hover:bg-white dark:hover:text-black">workflow<span class="opacity-60">: str | None = None</span></span></span><span class="comma cursor-default"><span class="rounded hover:bg-black hover:text-white dark:hover:bg-white dark:hover:text-black">modular_config_dict<span class="opacity-60">: dict[str, typing.Any] | None = None</span></span></span><span class="comma cursor-default"><span class="rounded hover:bg-black hover:text-white dark:hover:bg-white dark:hover:text-black">config_dict<span class="opacity-60">: dict[str, typing.Any] | None = None</span></span></span><span class="comma cursor-default"><span class="rounded hover:bg-black hover:text-white dark:hover:bg-white dark:hover:text-black">**kwargs<span class="opacity-60"></span></span></span><!--]--> <span>)</span> <!--[-1--><!--]--></p><!--]--> <div class="!mb-10 relative docstring-details "><!--[-1--><!--]--> <!--[-1--><!--]--> <!--[-1--><!--]--> <!--[-1--><!--]--> <!--[-1--><!--]--></div></div><!----> <p>ModularPipeline لنموذج FLUX.3 المُقطّر خطوة بخطوة (16 خطوة، بدون إرشاد حر من المُصنّف).</p></div> <a class="!text-gray-400 !no-underline text-sm flex items-center not-prose mt-4" href="https://github.com/huggingface/diffusers/blob/main/docs/source/en/api/pipelines/flux3.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_gxjg5b = {
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.U6TUchwJ.js"),
import("/docs/diffusers/main/en/_app/immutable/entry/app.3qKhPoX-.js")
]).then(([kit, app]) => {
kit.start(app, element, {
node_ids: [0, 8],
data: [null,null],
form: null,
error: null
});
});
}
</script>

Xet Storage Details

Size:
103 kB
·
Xet hash:
9182d211e74f974eb8780d349fff8db8433bb6c387cd4df8c11cd62d8273ca80

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