Buckets:
| <meta charset="utf-8" /><meta name="hf:doc:metadata" content="{"title":"Dikkat arka uçları","local":"attention-backends","sections":[{"title":"set_attention_backend","local":"setattentionbackend","sections":[],"depth":2},{"title":"attention_backend bağlam yöneticisi","local":"attentionbackend-context-manager","sections":[],"depth":2},{"title":"Uzak çekirdeklere güvenme","local":"trusting-remote-kernels","sections":[],"depth":2},{"title":"Kontroller","local":"checks","sections":[],"depth":2},{"title":"Kullanılabilir arka uçlar","local":"available-backends","sections":[],"depth":2}],"depth":1}"/> | |
| <link href="/docs/diffusers/main/en/_app/immutable/entry/start.vZc-dOUR.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/main/en/_app/immutable/chunks/Bafuik5c.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/main/en/_app/immutable/chunks/Bupkjr9f.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/main/en/_app/immutable/entry/app.B6c3Ml05.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/main/en/_app/immutable/chunks/CyvZ3FS5.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/main/en/_app/immutable/chunks/l0QnnOED.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/main/en/_app/immutable/chunks/DnVIJfC5.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/main/en/_app/immutable/chunks/DsnmJJEf.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/main/en/_app/immutable/nodes/0.BQlx092V.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/main/en/_app/immutable/chunks/CoSrdQax.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/main/en/_app/immutable/nodes/326.qHPbgXyf.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/main/en/_app/immutable/chunks/B4AMoTAu.js" rel="modulepreload"> | |
| <!--gxcprv--><meta name="hf:doc:metadata" content="{"title":"Attention backends","local":"attention-backends","sections":[{"title":"set_attention_backend","local":"setattentionbackend","sections":[],"depth":2},{"title":"attention_backend context manager","local":"attentionbackend-context-manager","sections":[],"depth":2},{"title":"Trusting remote kernels","local":"trusting-remote-kernels","sections":[],"depth":2},{"title":"Checks","local":"checks","sections":[],"depth":2},{"title":"Available backends","local":"available-backends","sections":[],"depth":2}],"depth":1}"/><!----> | |
| <link href="/docs/diffusers/main/en/_app/immutable/assets/0.tn0RQdqM.css" rel="modulepreload"> <!--[--><!--[0--><!--[--><!--[0--><!--[--><p></p> <div class="items-center shrink-0 min-w-[100px] max-sm:min-w-[50px] justify-end ml-auto flex" style="float: inline-end; margin-inline-start: 10px; display: inline-flex; position: relative; z-index: 10;"><div dir="ltr" class="inline-flex rounded-md max-sm:rounded-sm"><button class="inline-flex items-center gap-1 h-7 max-sm:h-7 px-2 max-sm:px-1.5 text-sm font-medium text-gray-800 border border-r-0 rounded-l-md max-sm:rounded-l-sm border-gray-200 bg-white hover:shadow-inner dark:border-gray-850 dark:bg-gray-950 dark:text-gray-200 dark:hover:bg-gray-800" aria-live="polite"><span class="inline-flex items-center justify-center rounded-md p-0.5 max-sm:p-0 hover:text-gray-800 dark:hover:text-gray-200"><svg class="sm:size-3.5 size-3" xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----></span> <span dir="auto">Copy page</span></button> <button class="inline-flex items-center justify-center w-6 max-sm:w-5 h-7 max-sm:h-7 disabled:pointer-events-none text-sm text-gray-500 hover:text-gray-700 dark:hover:text-white rounded-r-md max-sm:rounded-r-sm border border-l transition border-gray-200 bg-white hover:shadow-inner dark:border-gray-850 dark:bg-gray-950 dark:text-gray-200 dark:hover:bg-gray-800" aria-haspopup="menu" aria-expanded="false" aria-label="Open copy menu"><svg class="transition-transform text-gray-400 overflow-visible sm:size-3.5 size-3 rotate-0" width="1em" height="1em" viewBox="0 0 12 7" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M1 1L6 6L11 1" stroke="currentColor"></path></svg><!----></button></div> <!--[-1--><!--]--></div><!----> <!--[0--><h1 class="relative group"><a id="attention-backends" 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="#attention-backends"><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><!---->Dikkat arka uçları<!----></span></h1><!--]--><!----> <blockquote class="note"><p>Dikkat yönlendirici (attention dispatcher) deneysel bir özelliktir. Herhangi bir geri bildiriminiz varsa veya sorunlarla karşılaşırsanız lütfen bir sorun (issue) açın.</p></blockquote> <p>Diffusers, <em>dikkat yönlendiricisi</em> aracılığıyla daha az bellek ve hesaplama gerektiren çeşitli optimize edilmiş dikkat algoritmaları sunar. Yönlendirici, farklı dikkat uygulamaları arasında yönetimi ve geçişi sağlamak için bir yönlendirici olarak çalışır ve bunlarla etkileşim için birleşik bir arayüz sunar.</p> <p>Mevcut dikkat ailelerinin genel bir bakış için aşağıdaki tabloya, daha eksiksiz bir liste için ise <a href="#available-backends">Mevcut arka uçlar</a> bölümüne başvurun.</p> <table><thead><tr><th>attention ailesi</th><th>ana özellik</th></tr></thead><tbody><tr><td>FlashAttention</td><td>döşeme ve yeniden hesaplama yoluyla bellek okuma/yazma işlemlerini en aza indirir</td></tr><tr><td>ROCm için AI Tensor Motoru</td><td>AMD ROCm hızlandırıcıları için optimize edilmiş FlashAttention uygulaması</td></tr><tr><td>SageAttention</td><td>dikkati int8'e kuantize eder</td></tr><tr><td>PyTorch yerli</td><td><a href="./fp16#scaled-dot-product-attention">scaled_dot_product_attention</a> kullanan yerleşik PyTorch uygulaması</td></tr><tr><td>xFormers</td><td>çeşitli dikkat çekirdekleri için destek içeren bellek-verimli dikkat</td></tr></tbody></table> <p>Bu kılavuz, farklı dikkat (attention) arka uçlarını (backends) nasıl ayarlayıp kullanacağınızı gösterecektir.</p> <!--[1--><h2 class="relative group"><a id="setattentionbackend" 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="#setattentionbackend"><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><!---->set_attention_backend<!----></span></h2><!--]--><!----> <p><a href="/docs/diffusers/main/tr/api/models/overview#diffusers.ModelMixin.set_attention_backend">set_attention_backend()</a> metodu, modeldeki tüm modülleri iterasyonla gezer ve kullanılacak uygun dikkat (attention) arka ucunu ayarlar. Dikkat arka ucu ayarı, <a href="/docs/diffusers/main/tr/api/models/overview#diffusers.ModelMixin.reset_attention_backend">reset_attention_backend()</a> çağrılana kadar geçerliliğini korur.</p> <p>Aşağıdaki örnek, <a href="https://github.com/huggingface/kernels" rel="nofollow"><code>kernels</code></a> kütüphanesinden FlashAttention-3 için <code>_flash_3_hub</code> uygulamasını nasıl etkinleştirebileceğinizi gösterir; bu sayede herhangi bir kurulum gerektirmeden Hub'daki optimize edilmiş hesaplama çekirdeklerini anında kullanabilirsiniz.</p> <blockquote class="note"><p>FlashAttention-3 en az Ampere GPU'ları gerektirir.</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> Kopyalandı</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> QwenImagePipeline | |
| pipeline = QwenImagePipeline.from_pretrained( | |
| <span class="hljs-string">"Qwen/Qwen-Image"</span>, dtype=torch.bfloat16, device_map=<span class="hljs-string">"cuda"</span> <span class="hljs-comment"># or "mps", "xpu", "cpu"</span> | |
| ) | |
| pipeline.transformer.set_attention_backend(<span class="hljs-string">"_flash_3_hub"</span>) | |
| prompt = <span class="hljs-string">""" | |
| cinematic film still of a cat sipping a margarita in a pool in Palm Springs, California | |
| highly detailed, high budget hollywood movie, cinemascope, moody, epic, gorgeous, film grain | |
| """</span> | |
| pipeline(prompt).images[<span class="hljs-number">0</span>]<!----></pre></div><!----> <p>Varsayılan dikkat arka ucunu geri yüklemek için <a href="/docs/diffusers/main/tr/api/models/overview#diffusers.ModelMixin.reset_attention_backend">reset_attention_backend()</a> çağrısını yapın.</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> Kopyalandı</div><!----></button><!----></div> <pre class="language-py "><!---->pipeline.transformer.reset_attention_backend()<!----></pre></div><!----> <!--[1--><h2 class="relative group"><a id="attentionbackend-context-manager" 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="#attentionbackend-context-manager"><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><!---->attention_backend bağlam yöneticisi<!----></span></h2><!--]--><!----> <p><a href="https://github.com/huggingface/diffusers/blob/5e181eddfe7e44c1444a2511b0d8e21d177850a0/src/diffusers/models/attention_dispatch.py#L225" rel="nofollow">attention_backend</a> bağlam yöneticisi, bir model için bir dikkat (attention) arka ucunu bağlam içinde geçici olarak ayarlar. Bağlam dışında, varsayılan dikkat (PyTorch’un yerleşik ölçekli nokta çarpımı dikkati) kullanılır. Bir iş akışının farklı bölümleri için farklı arka uçlar kullanmak veya farklı arka uçları test etmek istiyorsanız bu işe yarar.</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> Kopyalandı</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> QwenImagePipeline | |
| pipeline = QwenImagePipeline.from_pretrained( | |
| <span class="hljs-string">"Qwen/Qwen-Image"</span>, dtype=torch.bfloat16, device_map=<span class="hljs-string">"cuda"</span> <span class="hljs-comment"># or "mps", "xpu", "cpu"</span> | |
| ) | |
| prompt = <span class="hljs-string">""" | |
| cinematic film still of a cat sipping a margarita in a pool in Palm Springs, California | |
| highly detailed, high budget hollywood movie, cinemascope, moody, epic, gorgeous, film grain | |
| """</span> | |
| <span class="hljs-keyword">with</span> attention_backend(<span class="hljs-string">"_flash_3_hub"</span>): | |
| image = pipeline(prompt).images[<span class="hljs-number">0</span>]<!----></pre></div><!----> <blockquote class="tip"><p>Çoğu dikkat (attention) arka ucu, grafik kırılmaları olmadan <code>torch.compile</code> destekler ve çıkarımı (inference) daha da hızlandırmak için kullanılabilir.</p></blockquote> <!--[1--><h2 class="relative group"><a id="trusting-remote-kernels" 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="#trusting-remote-kernels"><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><!---->Uzak çekirdeklere güvenme<!----></span></h2><!--]--><!----> <p>Hub arka uçları ve diğer çekirdek destekli özellikler (örneğin <a href="../quantization/gguf">GGUF</a> ve <a href="../quantization/nunchaku">Nunchaku Lite</a>), hesaplama çekirdeklerini <a href="https://github.com/huggingface/kernels" rel="nofollow"><code>kernels</code></a> ile Hub'dan indirir ve kodlarını yerel olarak çalıştırır.</p> <p>Varsayılan olarak <code>kernels</code>, yalnızca Hub'da güvenilir bir çekirdek yayıncısı tarafından yayınlandığında bir çekirdeği yükler. <a href="https://huggingface.co/kernels-community" rel="nofollow"><code>kernels-community</code></a> kuruluşu altında yayınlanan çekirdekler güvenilirdir, bu nedenle Diffusers bunları ek bir yapılandırma gerektirmeden yükler. <code>_flash_3_hub</code>, <code>flash_hub</code>, <code>sage_hub</code> ve diğer Hub dikkat arka uçlarının tümü <code>kernels-community</code> depolarına çözümlenir.</p> <p>Diğer yayıncılardan gelen çekirdekler denetlenmez. Bunlardan birini yüklemek, Diffusers'ın garantisi olmayan kodu indirir ve çalıştırır; bu nedenle Diffusers, <code>DIFFUSERS_TRUST_REMOTE_KERNELS</code> ortam değişkeniyle açıkça onay vermedikçe bu özelliği devre dışı bırakır. Bu değişken ayarlandığında, Diffusers <code>kernels</code> bileşenine <code>trust_remote_code=True</code> parametresini iletir ve böylece güvenilmeyen yayıncılardan da çekirdekler yüklenir.</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> Kopyalandı</div><!----></button><!----></div> <pre class="language-bash "><!----><span class="hljs-built_in">export</span> DIFFUSERS_TRUST_REMOTE_KERNELS=<span class="hljs-literal">true</span><!----></pre></div><!----> <p>Bu ayarı, çekirdek deposunu inceledikten sonra etkinleştirin; çünkü indirilen kodun makinenizde çalışmasına izin verir. Bu ayar olmadan, güvenilir olmayan bir yayıncıdan çekirdek yüklenmeye çalışıldığında bir hata oluşur. Diffusers bu kontrolü kendisi yaptığından, bu kural <code>trust_remote_code</code> argümanından önce gelen <code>kernels<0.14.0</code> sürümü için de geçerlidir. <code>DIFFUSERS_DISABLE_REMOTE_CODE=true</code> değerini ayarlamak, uzak kodu küresel olarak devre dışı bırakır ve <code>DIFFUSERS_TRUST_REMOTE_KERNELS</code> değişkenine öncelik tanır.</p> <!--[1--><h2 class="relative group"><a id="checks" 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="#checks"><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><!---->Kontroller<!----></span></h2><!--]--><!----> <p>Dikkat yönlendiricisi, sorunlara yol açmadan önce yaygın hataları yakalayan hata ayıklama kontrolleri içerir.</p> <ol><li>Device checks, sorgu, anahtar ve değer tensörlerinin aynı cihazda bulunduğunu doğrular.</li> <li>Veri türü kontrolleri, tensörlerin eşleşen dtypes'a sahip olduğunu ve bfloat16 veya float16 kullanıldığını doğrular.</li> <li>Shape checks, tensor boyutlarını doğrular ve dikkat maskelerinin nedensel bayraklarla karıştırılmasını önler.</li></ol> <p>Bu kontrolleri etkinleştirmek için <code>DIFFUSERS_ATTN_CHECKS</code> ortam değişkenini ayarlayın. Kontroller her dikkat işleminde ek yük oluşturduğundan varsayılan olarak devre dışıdır.</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> Kopyalandı</div><!----></button><!----></div> <pre class="language-bash "><!----><span class="hljs-built_in">export</span> DIFFUSERS_ATTN_CHECKS=<span class="hljs-built_in">yes</span><!----></pre></div><!----> <p>Kontroller artık her dikkat (attention) işleminden önce çalıştırılır.</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> Kopyalandı</div><!----></button><!----></div> <pre class="language-py "><!----><span class="hljs-keyword">import</span> torch | |
| query = torch.randn(<span class="hljs-number">1</span>, <span class="hljs-number">10</span>, <span class="hljs-number">8</span>, <span class="hljs-number">64</span>, dtype=torch.bfloat16, device=<span class="hljs-string">"cuda"</span>) <span class="hljs-comment"># or "mps", "xpu", "cpu"</span> | |
| key = torch.randn(<span class="hljs-number">1</span>, <span class="hljs-number">10</span>, <span class="hljs-number">8</span>, <span class="hljs-number">64</span>, dtype=torch.bfloat16, device=<span class="hljs-string">"cuda"</span>) | |
| value = torch.randn(<span class="hljs-number">1</span>, <span class="hljs-number">10</span>, <span class="hljs-number">8</span>, <span class="hljs-number">64</span>, dtype=torch.bfloat16, device=<span class="hljs-string">"cuda"</span>) | |
| <span class="hljs-keyword">try</span>: | |
| <span class="hljs-keyword">with</span> attention_backend(<span class="hljs-string">"flash"</span>): | |
| output = dispatch_attention_fn(query, key, value) | |
| <span class="hljs-built_in">print</span>(<span class="hljs-string">"✓ Flash Attention works with checks enabled"</span>) | |
| <span class="hljs-keyword">except</span> Exception <span class="hljs-keyword">as</span> e: | |
| <span class="hljs-built_in">print</span>(<span class="hljs-string">f"✗ Flash Attention failed: <span class="hljs-subst">{e}</span>"</span>)<!----></pre></div><!----> <p>Ayrıca kayıt defterini doğrudan yapılandırabilirsiniz.</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> Kopyalandı</div><!----></button><!----></div> <pre class="language-py "><!----><span class="hljs-keyword">from</span> diffusers.models.attention_dispatch <span class="hljs-keyword">import</span> _AttentionBackendRegistry | |
| _AttentionBackendRegistry._checks_enabled = <span class="hljs-literal">True</span><!----></pre></div><!----> <!--[1--><h2 class="relative group"><a id="available-backends" 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="#available-backends"><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><!---->Kullanılabilir arka uçlar<!----></span></h2><!--]--><!----> <p>Mevcut dikkat (attention) arka uçlarının ve varyantlarının tam listesi için aşağıdaki tabloya bakın.</p> <details><summary>Expand</summary> <table><thead><tr><th>Arka Uygulama Adı</th><th>Aile</th><th>Açıklama</th></tr></thead><tbody><tr><td><code>native</code></td><td><a href="https://docs.pytorch.org/docs/stable/generated/torch.nn.attention.SDPBackend.html#torch.nn.attention.SDPBackend" rel="nofollow">PyTorch yerlisi</a></td><td>PyTorch'un scaled_dot_product_attention'ını kullanan varsayılan backend</td></tr><tr><td><code>flex</code></td><td><a href="https://docs.pytorch.org/docs/stable/nn.attention.flex_attention.html#module-torch.nn.attention.flex_attention" rel="nofollow">FlexAttention</a></td><td>PyTorch FlexAttention uygulaması</td></tr><tr><td><code>_native_cudnn</code></td><td><a href="https://docs.pytorch.org/docs/stable/generated/torch.nn.attention.SDPBackend.html#torch.nn.attention.SDPBackend" rel="nofollow">PyTorch yerlisi</a></td><td>CuDNN-optimize edilmiş dikkat</td></tr><tr><td><code>_native_efficient</code></td><td><a href="https://docs.pytorch.org/docs/stable/generated/torch.nn.attention.SDPBackend.html#torch.nn.attention.SDPBackend" rel="nofollow">PyTorch yerlisi</a></td><td>Hafıza-verimli dikkat</td></tr><tr><td><code>_native_flash</code></td><td><a href="https://docs.pytorch.org/docs/stable/generated/torch.nn.attention.SDPBackend.html#torch.nn.attention.SDPBackend" rel="nofollow">PyTorch yerlisi</a></td><td>PyTorch’un FlashAttention’ı</td></tr><tr><td><code>_native_math</code></td><td><a href="https://docs.pytorch.org/docs/stable/generated/torch.nn.attention.SDPBackend.html#torch.nn.attention.SDPBackend" rel="nofollow">PyTorch yerlisi</a></td><td>Matematik tabanlı dikkat (yedek)</td></tr><tr><td><code>_native_npu</code></td><td><a href="https://docs.pytorch.org/docs/stable/generated/torch.nn.attention.SDPBackend.html#torch.nn.attention.SDPBackend" rel="nofollow">PyTorch yerlisi</a></td><td>NPU-optimized dikkat</td></tr><tr><td><code>_native_xla</code></td><td><a href="https://docs.pytorch.org/docs/stable/generated/torch.nn.attention.SDPBackend.html#torch.nn.attention.SDPBackend" rel="nofollow">PyTorch yerlisi</a></td><td>XLA-optimize edilmiş dikkat</td></tr><tr><td><code>flash</code></td><td><a href="https://github.com/Dao-AILab/flash-attention" rel="nofollow">FlashAttention</a></td><td>FlashAttention-2</td></tr><tr><td><code>flash_hub</code></td><td><a href="https://github.com/Dao-AILab/flash-attention" rel="nofollow">FlashAttention</a></td><td>Çekirdeklerden FlashAttention-2</td></tr><tr><td><code>flash_varlen</code></td><td><a href="https://github.com/Dao-AILab/flash-attention" rel="nofollow">FlashAttention</a></td><td>Değişken uzunluklu FlashAttention</td></tr><tr><td><code>flash_varlen_hub</code></td><td><a href="https://github.com/Dao-AILab/flash-attention" rel="nofollow">FlashAttention</a></td><td>Çekirdeklerden değişken uzunluklu FlashAttention</td></tr><tr><td><code>aiter_fa2_hub</code></td><td><a href="https://github.com/ROCm/aiter" rel="nofollow">ROCm için AI Tensor Engine</a></td><td>kernels'ten AMD ROCm için FlashAttention-2</td></tr><tr><td><code>aiter_sage_hub</code></td><td><a href="https://github.com/ROCm/aiter" rel="nofollow">ROCm için AI Tensor Engine</a></td><td>kernels'ten AMD RDNA4 (gfx1201) için kuantize edilmiş dikkat (INT8 QK, FP8 PV)</td></tr><tr><td><code>flash_4_hub</code></td><td><a href="https://github.com/Dao-AILab/flash-attention" rel="nofollow">FlashAttention</a></td><td>FlashAttention-4</td></tr><tr><td><code>_flash_3</code></td><td><a href="https://github.com/Dao-AILab/flash-attention" rel="nofollow">FlashAttention</a></td><td>FlashAttention-3</td></tr><tr><td><code>_flash_varlen_3</code></td><td><a href="https://github.com/Dao-AILab/flash-attention" rel="nofollow">FlashAttention</a></td><td>Değişken uzunluklu FlashAttention-3</td></tr><tr><td><code>_flash_3_hub</code></td><td><a href="https://github.com/Dao-AILab/flash-attention" rel="nofollow">FlashAttention</a></td><td>kernels'ten FlashAttention-3</td></tr><tr><td><code>_flash_3_varlen_hub</code></td><td><a href="https://github.com/Dao-AILab/flash-attention" rel="nofollow">FlashAttention</a></td><td>Çekirdeklerden değişken uzunluklu FlashAttention-3</td></tr><tr><td><code>sage</code></td><td><a href="https://github.com/thu-ml/SageAttention" rel="nofollow">SageAttention</a></td><td>Kantize edilmiş dikkat (INT8 QK)</td></tr><tr><td><code>sage_hub</code></td><td><a href="https://github.com/thu-ml/SageAttention" rel="nofollow">SageAttention</a></td><td>Çekirdeklerden kuantize edilmiş dikkat (INT8 QK)</td></tr><tr><td><code>sage_blackwell_hub</code></td><td><a href="https://github.com/thu-ml/SageAttention" rel="nofollow">SageAttention</a></td><td>kernels'ten SM120 Blackwell GPU'lar için SageAttention3 FP4 dikkati</td></tr><tr><td><code>sage_varlen</code></td><td><a href="https://github.com/thu-ml/SageAttention" rel="nofollow">SageAttention</a></td><td>Değişken uzunluklu SageAttention</td></tr><tr><td><code>_sage_qk_int8_pv_fp8_cuda</code></td><td><a href="https://github.com/thu-ml/SageAttention" rel="nofollow">SageAttention</a></td><td>INT8 QK + FP8 PV (CUDA)</td></tr><tr><td><code>_sage_qk_int8_pv_fp8_cuda_sm90</code></td><td><a href="https://github.com/thu-ml/SageAttention" rel="nofollow">SageAttention</a></td><td>INT8 QK + FP8 PV (SM90)</td></tr><tr><td><code>_sage_qk_int8_pv_fp16_cuda</code></td><td><a href="https://github.com/thu-ml/SageAttention" rel="nofollow">SageAttention</a></td><td>INT8 QK + FP16 PV (CUDA)</td></tr><tr><td><code>_sage_qk_int8_pv_fp16_triton</code></td><td><a href="https://github.com/thu-ml/SageAttention" rel="nofollow">SageAttention</a></td><td>INT8 QK + FP16 PV (Triton)</td></tr><tr><td><code>xformers</code></td><td><a href="https://github.com/facebookresearch/xformers" rel="nofollow">xFormers</a></td><td>Hafıza-verimli dikkat</td></tr></tbody></table></details> <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/optimization/attention_backends.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_1rjuniz = { | |
| 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.vZc-dOUR.js"), | |
| import("/docs/diffusers/main/en/_app/immutable/entry/app.B6c3Ml05.js") | |
| ]).then(([kit, app]) => { | |
| kit.start(app, element, { | |
| node_ids: [0, 326], | |
| data: [null,null], | |
| form: null, | |
| error: null | |
| }); | |
| }); | |
| } | |
| </script> | |
Xet Storage Details
- Size:
- 38 kB
- Xet hash:
- 29f7bee43b9b005300c61d9514bd3378f992a4225f3b5384830c14f82548756e
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.