Buckets:
| <meta charset="utf-8" /><meta name="hf:doc:metadata" content="{"title":"البدء","local":"getting-started","sections":[{"title":"التكميم على مستوى خط الأنابيب","local":"pipeline-level-quantization","sections":[{"title":"التكميم الأساسي","local":"basic-quantization","sections":[],"depth":3},{"title":"التكميم المتقدم","local":"advanced-quantization","sections":[],"depth":3}],"depth":2},{"title":"تحميل نقاط التفتيش المُسبقة التكميم","local":"loading-prequantized-checkpoints","sections":[],"depth":2},{"title":"الموارد","local":"resources","sections":[],"depth":2}],"depth":1}"/> | |
| <link href="/docs/diffusers/v0.43.0/en/_app/immutable/entry/start.1gaXe03k.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/v0.43.0/en/_app/immutable/chunks/BObs6oQO.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/v0.43.0/en/_app/immutable/chunks/DPnyVmXs.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/v0.43.0/en/_app/immutable/entry/app.BwdYRbCn.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/v0.43.0/en/_app/immutable/chunks/DSGUT_OW.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/v0.43.0/en/_app/immutable/chunks/C045MWWx.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/v0.43.0/en/_app/immutable/chunks/6tuJ3nyi.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/v0.43.0/en/_app/immutable/chunks/DsnmJJEf.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/v0.43.0/en/_app/immutable/nodes/0.CornNeQR.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/v0.43.0/en/_app/immutable/chunks/IaDvMxLQ.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/v0.43.0/en/_app/immutable/nodes/312._S_peb4w.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/v0.43.0/en/_app/immutable/chunks/bKdwVYpU.js" rel="modulepreload"> | |
| <!--cubdu--><meta name="hf:doc:metadata" content="{"title":"Getting started","local":"getting-started","sections":[{"title":"Pipeline-level quantization","local":"pipeline-level-quantization","sections":[{"title":"Basic quantization","local":"basic-quantization","sections":[],"depth":3},{"title":"Advanced quantization","local":"advanced-quantization","sections":[],"depth":3}],"depth":2},{"title":"Loading prequantized checkpoints","local":"loading-prequantized-checkpoints","sections":[],"depth":2},{"title":"Resources","local":"resources","sections":[],"depth":2}],"depth":1}"/><!----> | |
| <link href="/docs/diffusers/v0.43.0/en/_app/immutable/assets/0.tn0RQdqM.css" rel="modulepreload"> <!--[--><!--[0--><!--[--><!--[0--><!--[--><p></p> <div class="items-center shrink-0 min-w-[100px] max-sm:min-w-[50px] justify-end ml-auto flex" style="float: inline-end; margin-inline-start: 10px; display: inline-flex; position: relative; z-index: 10;"><div dir="ltr" class="inline-flex rounded-md max-sm:rounded-sm"><button class="inline-flex items-center gap-1 h-7 max-sm:h-7 px-2 max-sm:px-1.5 text-sm font-medium text-gray-800 border border-r-0 rounded-l-md max-sm:rounded-l-sm border-gray-200 bg-white hover:shadow-inner dark:border-gray-850 dark:bg-gray-950 dark:text-gray-200 dark:hover:bg-gray-800" aria-live="polite"><span class="inline-flex items-center justify-center rounded-md p-0.5 max-sm:p-0 hover:text-gray-800 dark:hover:text-gray-200"><svg class="sm:size-3.5 size-3" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----></span> <span dir="auto">Copy page</span></button> <button class="inline-flex items-center justify-center w-6 max-sm:w-5 h-7 max-sm:h-7 disabled:pointer-events-none text-sm text-gray-500 hover:text-gray-700 dark:hover:text-white rounded-r-md max-sm:rounded-r-sm border border-l transition border-gray-200 bg-white hover:shadow-inner dark:border-gray-850 dark:bg-gray-950 dark:text-gray-200 dark:hover:bg-gray-800" aria-haspopup="menu" aria-expanded="false" aria-label="Open copy menu"><svg class="transition-transform text-gray-400 overflow-visible sm:size-3.5 size-3 rotate-0" width="1em" height="1em" viewBox="0 0 12 7" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1 1L6 6L11 1" stroke="currentColor"></path></svg><!----></button></div> <!--[-1--><!--]--></div><!----> <!--[0--><h1 class="relative group"><a id="getting-started" 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="#getting-started"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span><!---->البدء<!----></span></h1><!--]--><!----> <p>تركز عملية الكمّ (Quantization) على تمثيل البيانات بعدد أقل من البتات مع السعي في الوقت نفسه للحفاظ على دقة البيانات الأصلية. وغالبًا ما يعني ذلك تحويل نوع البيانات لتمثيل المعلومات نفسها بعدد أقل من البتات. على سبيل المثال، إذا كانت أوزان النموذج مخزنة كنقاط عائمة بدقة 32 بت وتم كمّها إلى نقاط عائمة بدقة 16 بت، فإن ذلك يُقلّص حجم النموذج إلى النصف، مما يسهّل تخزينه ويقلّل من استهلاك الذاكرة. كما يمكن أن يؤدي انخفاض الدقة إلى تسريع الاستدلال (Inference) لأن إجراء العمليات الحسابية بعدد أقل من البتات يستغرق وقتًا أقصر.</p> <p>يدعم Diffusers عدة محركات (backends) للكمّية (quantization) لجعل نماذج الانتشار الكبيرة مثل <a href="../api/pipelines/flux">Flux</a> أكثر قابلية للوصول. يوضح هذا الدليل كيفية استخدام فئة <a href="/docs/diffusers/v0.43.0/ar/api/quantization#diffusers.PipelineQuantizationConfig">PipelineQuantizationConfig</a> لكمّية (quantize) خط الأنابيب (pipeline) أثناء تهيئته من نقطة تحقق (checkpoint) مُدرَّبة مسبقًا أو غير مُكمَّاة.</p> <!--[1--><h2 class="relative group"><a id="pipeline-level-quantization" 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="#pipeline-level-quantization"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span><!---->التكميم على مستوى خط الأنابيب<!----></span></h2><!--]--><!----> <p>هناك طريقتان لاستخدام <a href="/docs/diffusers/v0.43.0/ar/api/quantization#diffusers.PipelineQuantizationConfig">PipelineQuantizationConfig</a> اعتمادًا على مقدار التخصيص الذي ترغب في تطبيقه على إعدادات التكميم.</p> <ul><li>لحالات الاستخدام الأساسية، عرّف الحجج <code>quant_backend</code> و<code>quant_kwargs</code> و<code>components_to_quantize</code></li> <li>للحصول على تحكم دقيق في التكميم، عرّف <code>quant_mapping</code> يوفر إعدادات التكميم لمكونات النموذج الفردية</li></ul> <!--[2--><h3 class="relative group"><a id="basic-quantization" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#basic-quantization"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span><!---->التكميم الأساسي<!----></span></h3><!--]--><!----> <p>قم بتهيئة <a href="/docs/diffusers/v0.43.0/ar/api/quantization#diffusers.PipelineQuantizationConfig">PipelineQuantizationConfig</a> باستخدام المعلمات التالية.</p> <ul><li><code>quant_backend</code> يحدد أي خلفية تكميم (quantization backend) يجب استخدامها. تشمل الخلفيات المدعومة حاليًا: <code>bitsandbytes_4bit</code>، <code>bitsandbytes_8bit</code>، <code>gguf</code>، <code>quanto</code>، و<code>torchao</code>.</li> <li><code>quant_kwargs</code> يحدد حُجج التكميم (quantization) التي يجب استخدامها.</li></ul> <blockquote class="tip"><p>تختلف هذه الحجة <code>quant_kwargs</code> باختلاف كل إطار تشغيل. راجع وثائق <a href="../api/quantization">Quantization API</a> للاطلاع على الحجج الخاصة بكل إطار تشغيل.</p></blockquote> <ul><li><p><code>components_to_quantize</code> يحدد المكوّن أو المكوّنات من خط الأنابيب التي يجب تكميمها. عادةً، يجب تكميم المكوّنات الأكثر استهلاكًا للحسابات مثل transformer. يُعدّ text encoder مكوّنًا آخر يُنظر في تكميمه إذا كان خط الأنابيب يحتوي على أكثر من مكوّن واحد، كما هو الحال في <a href="/docs/diffusers/v0.43.0/ar/api/pipelines/flux#diffusers.FluxPipeline">FluxPipeline</a>. يكمّم المثال أدناه text encoder الخاص بـ T5 في <a href="/docs/diffusers/v0.43.0/ar/api/pipelines/flux#diffusers.FluxPipeline">FluxPipeline</a> مع إبقاء نموذج CLIP كما هو.</p> <p>يقبل <code>components_to_quantize</code> إما قائمة لعدة نماذج أو نصًا لنموذج واحد.</p></li></ul> <p>يحمّل المثال أدناه واجهة bitsandbytes باستخدام الحُجج التالية من <a href="/docs/diffusers/v0.43.0/ar/api/quantization#diffusers.BitsAndBytesConfig">BitsAndBytesConfig</a>، وهي <code>load_in_4bit</code> و<code>bnb_4bit_quant_type</code> و<code>bnb_4bit_compute_dtype</code>.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> تم النسخ</div><!----></button><!----></div> <pre class="language-py "><!----><span class="hljs-keyword">import</span> torch | |
| <span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DiffusionPipeline | |
| <span class="hljs-keyword">from</span> diffusers.quantizers <span class="hljs-keyword">import</span> PipelineQuantizationConfig | |
| pipeline_quant_config = PipelineQuantizationConfig( | |
| quant_backend=<span class="hljs-string">"bitsandbytes_4bit"</span>, | |
| quant_kwargs={<span class="hljs-string">"load_in_4bit"</span>: <span class="hljs-literal">True</span>, <span class="hljs-string">"bnb_4bit_quant_type"</span>: <span class="hljs-string">"nf4"</span>, <span class="hljs-string">"bnb_4bit_compute_dtype"</span>: torch.bfloat16}, | |
| components_to_quantize=[<span class="hljs-string">"transformer"</span>, <span class="hljs-string">"text_encoder_2"</span>], | |
| )<!----></pre></div><!----> <p>مرّر <code>pipeline_quant_config</code> إلى <a href="/docs/diffusers/v0.43.0/ar/api/pipelines/overview#diffusers.DiffusionPipeline.from_pretrained">from_pretrained()</a> لتكميم خط الأنابيب.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> تم النسخ</div><!----></button><!----></div> <pre class="language-py "><!---->pipe = DiffusionPipeline.from_pretrained( | |
| <span class="hljs-string">"black-forest-labs/FLUX.1-dev"</span>, | |
| quantization_config=pipeline_quant_config, | |
| dtype=torch.bfloat16, | |
| ).to(<span class="hljs-string">"cuda"</span>) <span class="hljs-comment"># or "mps", "xpu", "cpu"</span> | |
| image = pipe(<span class="hljs-string">"photo of a cute dog"</span>).images[<span class="hljs-number">0</span>]<!----></pre></div><!----> <!--[2--><h3 class="relative group"><a id="advanced-quantization" 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="#advanced-quantization"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span><!---->التكميم المتقدم<!----></span></h3><!--]--><!----> <p>توفر حجة <code>quant_mapping</code> خيارات إضافية لكيفية تكميم كل مكوّن فردي في خط الأنابيب، مثل دمج واجهات تكميم مختلفة.</p> <p>قم بتهيئة <a href="/docs/diffusers/v0.43.0/ar/api/quantization#diffusers.PipelineQuantizationConfig">PipelineQuantizationConfig</a> وقم بتمرير <code>quant_mapping</code> إليه. يتيح لك <code>quant_mapping</code> تحديد خيارات التكميم لكل مكوّن في خط الأنابيب، مثل المحوّل (transformer) ومشفّر النص (text encoder).</p> <p>يستخدم المثال أدناه واجهتي برمجة خلفية (backends) للكمّية، وهما <a href="/docs/diffusers/v0.43.0/ar/api/quantization#diffusers.QuantoConfig">QuantoConfig</a> و<a href="https://huggingface.co/docs/transformers/v5.22.2/en/main_classes/quantization#transformers.BitsAndBytesConfig" rel="nofollow">transformers.BitsAndBytesConfig</a>، للمحوّل (transformer) ومشفّر النص (text encoder).</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> تم النسخ</div><!----></button><!----></div> <pre class="language-py "><!----><span class="hljs-keyword">import</span> torch | |
| <span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DiffusionPipeline | |
| <span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> BitsAndBytesConfig <span class="hljs-keyword">as</span> DiffusersBitsAndBytesConfig | |
| <span class="hljs-keyword">from</span> diffusers.quantizers.quantization_config <span class="hljs-keyword">import</span> QuantoConfig | |
| <span class="hljs-keyword">from</span> diffusers.quantizers <span class="hljs-keyword">import</span> PipelineQuantizationConfig | |
| <span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> BitsAndBytesConfig <span class="hljs-keyword">as</span> TransformersBitsAndBytesConfig | |
| pipeline_quant_config = PipelineQuantizationConfig( | |
| quant_mapping={ | |
| <span class="hljs-string">"transformer"</span>: QuantoConfig(weights_dtype=<span class="hljs-string">"int8"</span>), | |
| <span class="hljs-string">"text_encoder_2"</span>: TransformersBitsAndBytesConfig( | |
| load_in_4bit=<span class="hljs-literal">True</span>, compute_dtype=torch.bfloat16 | |
| ), | |
| } | |
| )<!----></pre></div><!----> <p>يوجد مُنفّذ (backend) منفصل لـ bitsandbytes في <a href="https://huggingface.co/docs/transformers/main_classes/quantization#transformers.BitsAndBytesConfig" rel="nofollow">Transformers</a>. تحتاج إلى استيراد واستخدام <a href="https://huggingface.co/docs/transformers/v5.22.2/en/main_classes/quantization#transformers.BitsAndBytesConfig" rel="nofollow">transformers.BitsAndBytesConfig</a> للمكوّنات القادمة من Transformers. على سبيل المثال، <code>text_encoder_2</code> في <a href="/docs/diffusers/v0.43.0/ar/api/pipelines/flux#diffusers.FluxPipeline">FluxPipeline</a> هو <a href="https://huggingface.co/docs/transformers/v5.22.2/en/model_doc/t5#transformers.T5EncoderModel" rel="nofollow">T5EncoderModel</a> من Transformers، لذا عليك استخدام <a href="https://huggingface.co/docs/transformers/v5.22.2/en/main_classes/quantization#transformers.BitsAndBytesConfig" rel="nofollow">transformers.BitsAndBytesConfig</a> بدلاً من <a href="/docs/diffusers/v0.43.0/ar/api/quantization#diffusers.BitsAndBytesConfig">diffusers.BitsAndBytesConfig</a>.</p> <blockquote class="tip"><p>استخدم طريقة <a href="#basic-quantization">التكميم الأساسية</a> المذكورة أعلاه إذا كنت لا ترغب في إدارة هذه الاستيرادات المختلفة أو إذا لم تكن متأكداً من مصدر كل مكوّن في خط المعالجة.</p></blockquote> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> تم النسخ</div><!----></button><!----></div> <pre class="language-py "><!----><span class="hljs-keyword">import</span> torch | |
| <span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DiffusionPipeline | |
| <span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> BitsAndBytesConfig <span class="hljs-keyword">as</span> DiffusersBitsAndBytesConfig | |
| <span class="hljs-keyword">from</span> diffusers.quantizers <span class="hljs-keyword">import</span> PipelineQuantizationConfig | |
| <span class="hljs-keyword">from</span> transformers <span class="hljs-keyword">import</span> BitsAndBytesConfig <span class="hljs-keyword">as</span> TransformersBitsAndBytesConfig | |
| pipeline_quant_config = PipelineQuantizationConfig( | |
| quant_mapping={ | |
| <span class="hljs-string">"transformer"</span>: DiffusersBitsAndBytesConfig(load_in_4bit=<span class="hljs-literal">True</span>, bnb_4bit_compute_dtype=torch.bfloat16), | |
| <span class="hljs-string">"text_encoder_2"</span>: TransformersBitsAndBytesConfig( | |
| load_in_4bit=<span class="hljs-literal">True</span>, compute_dtype=torch.bfloat16 | |
| ), | |
| } | |
| )<!----></pre></div><!----> <p>مرّر <code>pipeline_quant_config</code> إلى <a href="/docs/diffusers/v0.43.0/ar/api/pipelines/overview#diffusers.DiffusionPipeline.from_pretrained">from_pretrained()</a> لتكميم خط الأنابيب.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> تم النسخ</div><!----></button><!----></div> <pre class="language-py "><!---->pipe = DiffusionPipeline.from_pretrained( | |
| <span class="hljs-string">"black-forest-labs/FLUX.1-dev"</span>, | |
| quantization_config=pipeline_quant_config, | |
| dtype=torch.bfloat16, | |
| ).to(<span class="hljs-string">"cuda"</span>) <span class="hljs-comment"># or "mps", "xpu", "cpu"</span> | |
| image = pipe(<span class="hljs-string">"photo of a cute dog"</span>).images[<span class="hljs-number">0</span>]<!----></pre></div><!----> <!--[1--><h2 class="relative group"><a id="loading-prequantized-checkpoints" class="header-link block pr-1.5 text-lg no-hover:hidden with-hover:absolute with-hover:p-1.5 with-hover:opacity-0 with-hover:group-hover:opacity-100 with-hover:right-full" href="#loading-prequantized-checkpoints"><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>تدعم بعض واجهات التكميم (quantization backends) تحميل نقاط التفتيش (checkpoints) التي تم تكميمها مسبقًا ورفعها إلى الـ Hub. في هذه الحالة، يتم تخزين إعدادات التكميم في ملف <code>config.json</code> الخاص بالنموذج وتُقرأ تلقائيًا — فلا حاجة إلى إنشاء <a href="/docs/diffusers/v0.43.0/ar/api/quantization#diffusers.PipelineQuantizationConfig">PipelineQuantizationConfig</a> أو تمرير معامل <code>quantization_config</code>.</p> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> تم النسخ</div><!----></button><!----></div> <pre class="language-py "><!----><span class="hljs-keyword">import</span> torch | |
| <span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DiffusionPipeline | |
| pipe = DiffusionPipeline.from_pretrained( | |
| <span class="hljs-string">"rootonchair/ERNIE-Image-Turbo-nunchaku-lite-nvfp4"</span>, | |
| dtype=torch.bfloat16, | |
| ).to(<span class="hljs-string">"cuda"</span>) <span class="hljs-comment"># or "mps", "xpu", "cpu"</span><!----></pre></div><!----> <p>تدعم الخوادم الخلفية التالية تحميل نقاط التفتيش المُسبقة الكمّية دون أي إعداد إضافي.</p> <table><thead><tr><th>الواجهة الخلفية</th><th>ملاحظات</th></tr></thead><tbody><tr><td><a href="./bitsandbytes">bitsandbytes</a></td><td>يتم حفظ Config في <code>config.json</code>؛ لا حاجة إلى أي حُجج إضافية. يدعم أيضًا التكميم أثناء التشغيل، وكذلك تحميل نقاط التفتيش المُكمَّمة مسبقًا.</td></tr><tr><td><a href="./torchao">torchao</a></td><td>نفس ما سبق.</td></tr><tr><td><a href="./gguf">GGUF</a></td><td>يستخدم <code>from_single_file</code> مع فئات النموذج؛ ولا يُدعم التحميل على مستوى خط الأنابيب.</td></tr><tr><td><a href="./bfl">BFL</a></td><td>يحمّل نقاط التفتيش أحادية الملف من Black Forest Labs بصيغتي <code>fp8r</code> و<code>nvfp4</code> باستخدام <code>from_single_file</code>؛ ولا يُدعم التحميل على مستوى خط الأنابيب.</td></tr><tr><td><a href="./autoround">AutoRound</a></td><td>يُؤمَّن التحميل فقط؛ قم بتكميم النموذج أولاً باستخدام واجهة سطر الأوامر AutoRound CLI أو واجهة برمجة التطبيقات Python API.</td></tr><tr><td><a href="./nunchaku">نونتشاكو لايت</a></td><td>يُحفظ Config في <code>config.json</code>؛ ويتطلب الحزمة <code>kernels</code>. يتم دعم التحميل فقط.</td></tr><tr><td><a href="./modelopt">ModelOpt</a></td><td>يُؤيَّد تحميل النماذج المُكمَّاة مسبقًا فقط.</td></tr><tr><td><a href="./sdnq">SDNQ</a></td><td>يدعم كلًا من التكميم أثناء التشغيل وتحميل النماذج المُكمَّمة مسبقًا؛ ويتطلب حزمة <code>sdnq</code>.</td></tr></tbody></table> <!--[1--><h2 class="relative group"><a id="resources" 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="#resources"><span><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 256"><path d="M167.594 88.393a8.001 8.001 0 0 1 0 11.314l-67.882 67.882a8 8 0 1 1-11.314-11.315l67.882-67.881a8.003 8.003 0 0 1 11.314 0zm-28.287 84.86l-28.284 28.284a40 40 0 0 1-56.567-56.567l28.284-28.284a8 8 0 0 0-11.315-11.315l-28.284 28.284a56 56 0 0 0 79.196 79.197l28.285-28.285a8 8 0 1 0-11.315-11.314zM212.852 43.14a56.002 56.002 0 0 0-79.196 0l-28.284 28.284a8 8 0 1 0 11.314 11.314l28.284-28.284a40 40 0 0 1 56.568 56.567l-28.285 28.285a8 8 0 0 0 11.315 11.314l28.284-28.284a56.065 56.065 0 0 0 0-79.196z" fill="currentColor"></path></svg><!----></span></a> <span><!---->الموارد<!----></span></h2><!--]--><!----> <p>اطّلع على الموارد أدناه لمعرفة المزيد حول التكميم.</p> <ul><li><p>إذا كنتَ جديدًا في مجال التكميم، فننصحك بالاطلاع على الدورات التعليمية التالية المصممة للمبتدئين والمقدمة بالتعاون مع DeepLearning.AI.</p> <ul><li><a href="https://www.deeplearning.ai/short-courses/quantization-fundamentals-with-hugging-face/" rel="nofollow">أساسيات التكميم مع Hugging Face</a></li> <li><a href="https://www.deeplearning.ai/short-courses/quantization-in-depth/" rel="nofollow">التكميم بالتفصيل</a></li></ul></li> <li><p>راجع <a href="https://huggingface.co/docs/transformers/main/en/quantization/contribute" rel="nofollow">دليل المساهمة في إضافة طريقة تكميم جديدة</a> إذا كنت مهتمًا بإضافة طريقة تكميم جديدة.</p></li> <li><p>توفر نظرة عامة على التكميم في <a href="https://huggingface.co/docs/transformers/quantization/overview#when-to-use-what" rel="nofollow">Transformers</a> نظرة شاملة على مزايا وعيوب مختلف أنظمة التكميم.</p></li> <li><p>اقرأ منشور المدونة <a href="https://huggingface.co/blog/diffusers-quantization" rel="nofollow">استكشاف واجهات التكميم في Diffusers</a> للحصول على مقدمة موجزة لكل واجهة تكميم، وكيفية اختيار واجهة، ودمج التكميم مع تحسينات الذاكرة الأخرى.</p></li></ul> <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/quantization/overview.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_ywq9g6 = { | |
| base: "/docs/diffusers/v0.43.0/en", | |
| assets: "/docs/diffusers/v0.43.0/en" | |
| }; | |
| const element = document.currentScript.parentElement; | |
| Promise.all([ | |
| import("/docs/diffusers/v0.43.0/en/_app/immutable/entry/start.1gaXe03k.js"), | |
| import("/docs/diffusers/v0.43.0/en/_app/immutable/entry/app.BwdYRbCn.js") | |
| ]).then(([kit, app]) => { | |
| kit.start(app, element, { | |
| node_ids: [0, 312], | |
| data: [null,null], | |
| form: null, | |
| error: null | |
| }); | |
| }); | |
| } | |
| </script> | |
Xet Storage Details
- Size:
- 37 kB
- Xet hash:
- c10166dd4ab1765b8152c19be20cc1550a9223048be281d9c4d6f44900f54965
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.