Buckets:
| <meta charset="utf-8" /><meta name="hf:doc:metadata" content="{"title":"Önbelleğe Alma","local":"caching","sections":[{"title":"Piramit Dikkat Yayınlama","local":"pyramid-attention-broadcast","sections":[],"depth":2},{"title":"FasterCache","local":"fastercache","sections":[],"depth":2},{"title":"SeaCache","local":"seacache","sections":[{"title":"Cosmos 3","local":"cosmos-3","sections":[],"depth":3}],"depth":2},{"title":"FirstBlockCache","local":"firstblockcache","sections":[],"depth":2},{"title":"TaylorSeer Önbellek","local":"taylorseer-cache","sections":[],"depth":2},{"title":"MagCache","local":"magcache","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/327.CutjLhht.js" rel="modulepreload"> | |
| <link href="/docs/diffusers/main/en/_app/immutable/chunks/B4AMoTAu.js" rel="modulepreload"> | |
| <!--fs68f1--><meta name="hf:doc:metadata" content="{"title":"Caching","local":"caching","sections":[{"title":"Pyramid Attention Broadcast","local":"pyramid-attention-broadcast","sections":[],"depth":2},{"title":"FasterCache","local":"fastercache","sections":[],"depth":2},{"title":"SeaCache","local":"seacache","sections":[{"title":"Cosmos 3","local":"cosmos-3","sections":[],"depth":3}],"depth":2},{"title":"FirstBlockCache","local":"firstblockcache","sections":[],"depth":2},{"title":"TaylorSeer Cache","local":"taylorseer-cache","sections":[],"depth":2},{"title":"MagCache","local":"magcache","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="caching" 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="#caching"><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><!---->Önbelleğe Alma<!----></span></h1><!--]--><!----> <p>Önbellekleme, her çıkarım adımında tüm hesaplamanın yapılması yerine, dikkat ve ileri beslemeli katmanlar gibi farklı katmanların ara çıktıları depolanıp yeniden kullanılarak çıkarımı hızlandırır. Daha fazla bellek maliyeti karşılığında üretim hızını önemli ölçüde artırır ve ek eğitim gerektirmez.</p> <p>Bu kılavuz, Diffusers'ta desteklenen önbellekleme yöntemlerini nasıl kullanacağınızı gösterir.</p> <!--[1--><h2 class="relative group"><a id="pyramid-attention-broadcast" 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="#pyramid-attention-broadcast"><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><!---->Piramit Dikkat Yayınlama<!----></span></h2><!--]--><!----> <p><a href="https://huggingface.co/papers/2408.12588" rel="nofollow">Pyramid Attention Broadcast (PAB)</a>, üretim sürecinin ardışık zaman adımları arasında dikkat çıktılarının o kadar da farklı olmadığı gözlemine dayanır. Dikkat farkları çapraz katmanlarda en küçüktür ve genellikle daha uzun bir zaman aralığı boyunca önbelleğe alınır. Bunu zaman ve uzamsal dikkat katmanları izler.</p> <blockquote class="tip"><p>Tüm video modellerinde üç tür dikkat (çapraz, zamansal ve mekânsal) bulunmaz!</p></blockquote> <p>PAB, video üretiminin neredeyse gerçek zamanlı yapılabilmesi için sıralama paralelliği ve sınıflandırıcı-ücretsiz yönlendirme paralelliği (veri paralelliği) gibi diğer tekniklerle birleştirilebilir.</p> <p>Etkinleştirmek için bir <a href="/docs/diffusers/main/tr/api/cache#diffusers.PyramidAttentionBroadcastConfig">PyramidAttentionBroadcastConfig</a> yapılandırmasını oluşturup pipeline’ın transformer’ına iletin. <code>spatial_attention_block_skip_range</code>, uzamsal dikkat bloklarında dikkat hesaplamalarının ne sıklıkla atlanacağını kontrol eder; <code>spatial_attention_timestep_skip_range</code> ise atlanacak zaman adımlarının aralığını belirtir. Daha küçük bir aralık yavaş çıkarım hızlarına, daha büyük bir aralık ise daha düşük üretim kalitesine yol açabileceğinden uygun bir aralık seçmeye özen gösterin.</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-python "><!----><span class="hljs-keyword">import</span> torch | |
| <span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> CogVideoXPipeline, PyramidAttentionBroadcastConfig | |
| pipeline = CogVideoXPipeline.from_pretrained(<span class="hljs-string">"THUDM/CogVideoX-5b"</span>, dtype=torch.bfloat16) | |
| pipeline.to(<span class="hljs-string">"cuda"</span>) <span class="hljs-comment"># or "mps", "xpu", "cpu"</span> | |
| config = PyramidAttentionBroadcastConfig( | |
| spatial_attention_block_skip_range=<span class="hljs-number">2</span>, | |
| spatial_attention_timestep_skip_range=(<span class="hljs-number">100</span>, <span class="hljs-number">800</span>), | |
| current_timestep_callback=<span class="hljs-keyword">lambda</span>: pipe.current_timestep, | |
| ) | |
| pipeline.transformer.enable_cache(config)<!----></pre></div><!----> <!--[1--><h2 class="relative group"><a id="fastercache" 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="#fastercache"><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><!---->FasterCache<!----></span></h2><!--]--><!----> <p><a href="https://huggingface.co/papers/2410.19355" rel="nofollow">FasterCache</a>, ardışık zaman adımları için çıktı farklarının küçük olması nedeniyle <a href="#pyramid-attention-broadcast">PAB</a>'ye benzer şekilde dikkat özelliklerini önbelleğe alır ve yeniden kullanır.</p> <p>Bu yöntem, örneklemeye sınıfsız yönlendirme (classifier-free guidance) kullanıldığında (çoğu temel modelde yaygındır) koşulsuz dalga tahminini atlamayı da tercih edebilir ve ardışık zaman adımları arasında tahmin edilen gizli çıktıların anlamlı bir şekilde örtüşmesi varsa bunu koşullu dalga tahmininden tahmin edebilir.</p> <p>Etkinleştirmek için bir <a href="/docs/diffusers/main/tr/api/cache#diffusers.FasterCacheConfig">FasterCacheConfig</a> oluşturup pipeline'ın transformer'ına iletin.</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-python "><!----><span class="hljs-keyword">import</span> torch | |
| <span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> CogVideoXPipeline, FasterCacheConfig | |
| pipe line= CogVideoXPipeline.from_pretrained(<span class="hljs-string">"THUDM/CogVideoX-5b"</span>, dtype=torch.bfloat16) | |
| pipeline.to(<span class="hljs-string">"cuda"</span>) <span class="hljs-comment"># or "mps", "xpu", "cpu"</span> | |
| config = FasterCacheConfig( | |
| spatial_attention_block_skip_range=<span class="hljs-number">2</span>, | |
| spatial_attention_timestep_skip_range=(-<span class="hljs-number">1</span>, <span class="hljs-number">681</span>), | |
| current_timestep_callback=<span class="hljs-keyword">lambda</span>: pipe.current_timestep, | |
| attention_weight_callback=<span class="hljs-keyword">lambda</span> _: <span class="hljs-number">0.3</span>, | |
| unconditional_batch_skip_range=<span class="hljs-number">5</span>, | |
| unconditional_batch_timestep_skip_range=(-<span class="hljs-number">1</span>, <span class="hljs-number">781</span>), | |
| tensor_format=<span class="hljs-string">"BFCHW"</span>, | |
| ) | |
| pipeline.transformer.enable_cache(config)<!----></pre></div><!----> <!--[1--><h2 class="relative group"><a id="seacache" 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="#seacache"><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><!---->SeaCache<!----></span></h2><!--]--><!----> <p><a href="https://huggingface.co/papers/2602.18993" rel="nofollow">SeaCache</a>, ardışık gürültü azaltma adımları arasında Spektral-Evrim-Bilinçli (SEA) göstergelerini karşılaştırır. Birikmiş gösterge değişimi bir eşiğin altında kaldığında, maliyetli transformer blok yığını atlanır ve çıktısı önbellekten alınan artıklardan tahmin edilir. Göstergesi, üretilen çıktıyı oluşturan görsel latentlerden oluşturulur. Görüntüden videoya ve videodan videoya üretimde olduğu gibi, temiz koşullandırma kareleri bu çıktı yörüngesinin bir parçasıysa dahil edilir. Üretimi koşullandıran ancak çıktının bir parçası olmayan ayrı görsel ipuçları hariç tutulur. Metin koşullandırması, görsel latent olmadığı için hariç tutulur.</p> <p>Cosmos 3 Transfer paketleri, kontrol ipuçlarını ayrı görsel diziler olarak yönettiğinden, adaptörü bunları göstergeciden hariç tutar. | |
| Control-CFG dalları, kendi önbelleğe alınmış artıklarını korurken aynı çıktı yörüngesini karşılaştırır. Kontrol ipuçları yine de | |
| transformer'ı koşullandırır.</p> <p>Uygulama, aşağıdaki modeller için yerleşik adaptörler sağlar:</p> <ul><li><strong>Cosmos 3</strong>, birincil optimize edilmiş ve test edilmiş entegrasyondur. Tam kodlayıcı yığını, normalizasyon sonrası sınırından önbelleğe alır.</li> <li><strong>Wan T2V</strong>, eager modda genel tekrarlı blok yolunu kullanır. Bu entegrasyon, başka bir tek akışlı video transformer'ın SeaCache'e ham görme latentlerini nasıl sağlayabileceğini gösterir; aynı önbellek parametrelerinin Wan için optimal olduğu veya Wan'ın diğer varyantlarının desteklendiği iddiası değildir.</li></ul> <p>Diğer video transformer'ları, <code>CacheMixin</code> kullandıklarında, tanınan bir tekrarlanan blok listesini açtıklarında ve blok giriş/çıkış yerleşimini <code>TransformerBlockRegistry</code> içinde kaydettiklerinde genel yol ile entegre edilebilir. Pipeline, her transformer çağrısı için bir <code>cache_context</code> içine girmeli, <code>step_index</code>, <code>sigma</code> ve <code>num_inference_steps</code> değerlerini eklemeli ve koşullu ile koşulsuz yönlendirme gibi bağımsız yörüngeler için ayrı bağlam adları kullanmalıdır. Yerleşik bir adaptör mevcut değilse, üretilen çıktıyı oluşturan görsel latentleri döndüren bir <code>raw_vision_callback</code> geçin. Çıktı kalitesini doğrulayın ve her model ve zamanlayıcı için önbellek parametrelerini ayarlayın; destek ve benchmark sonuçları Cosmos 3'ten otomatik olarak aktarılmaz.</p> <!--[2--><h3 class="relative group"><a id="cosmos-3" 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="#cosmos-3"><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><!---->Cosmos 3<!----></span></h3><!--]--><!----> <p>SeaCache varsayılan olarak devre dışıdır. Transformer üzerinde etkinleştirin; Cosmos 3 gürültü azaltma döngüsü, her <code>cache_context</code> çağrısına etkin zamanlayıcı adımını, sigma değerini ve adım sayısını ekler, bu nedenle ek bir bağlantıya gerek yoktur:</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-python "><!----><span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> Cosmos3OmniPipeline, SeaCacheConfig | |
| pipe = Cosmos3OmniPipeline.from_pretrained(<span class="hljs-string">"nvidia/Cosmos3-Nano"</span>) | |
| pipe.transformer.enable_cache(SeaCacheConfig(threshold=<span class="hljs-number">0.2</span>, max_consecutive_cached=<span class="hljs-number">2</span>))<!----></pre></div><!----> <p>Bu model düzeyindeki API, <a href="/docs/diffusers/main/tr/api/pipelines/cosmos3#diffusers.Cosmos3OmniPipeline">Cosmos3OmniPipeline</a>, <a href="/docs/diffusers/main/tr/api/pipelines/cosmos3#diffusers.Cosmos3OmniModularPipeline">Cosmos3OmniModularPipeline</a> ve <a href="/docs/diffusers/main/tr/api/pipelines/cosmos3#diffusers.Cosmos3DistilledModularPipeline">Cosmos3DistilledModularPipeline</a> ile çalışır. SeaCache yaklaşık bir optimizasyondur ve üretilen çıktıları değiştirebilir. Her gürültü azaltma adımının tam dönüştürücüyü çalıştırması gerektiğinde <code>pipe.transformer.disable_cache()</code> çağrısını yapın.</p> <!--[1--><h2 class="relative group"><a id="firstblockcache" 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="#firstblockcache"><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><!---->FirstBlockCache<!----></span></h2><!--]--><!----> <p><a href="https://huggingface.co/docs/diffusers/main/en/api/cache#diffusers.FirstBlockCacheConfig" rel="nofollow">FirstBlock Cache</a>, denoiser'ın erken katmanlarının bir timestep'ten diğerine ne kadar değiştiğini kontrol eder. Değişim küçükse, model pahalı olan sonraki katmanları atlar ve önceki çıktıyı yeniden kullanı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 | |
| <span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> DiffusionPipeline | |
| <span class="hljs-keyword">from</span> diffusers.hooks <span class="hljs-keyword">import</span> apply_first_block_cache, FirstBlockCacheConfig | |
| pipeline = DiffusionPipeline.from_pretrained( | |
| <span class="hljs-string">"Qwen/Qwen-Image"</span>, dtype=torch.bfloat16 | |
| ) | |
| apply_first_block_cache(pipeline.transformer, FirstBlockCacheConfig(threshold=<span class="hljs-number">0.2</span>))<!----></pre></div><!----> <!--[1--><h2 class="relative group"><a id="taylorseer-cache" 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="#taylorseer-cache"><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><!---->TaylorSeer Önbellek<!----></span></h2><!--]--><!----> <p><a href="https://huggingface.co/papers/2403.06923" rel="nofollow">TaylorSeer Cache</a>, Taylor serisi açılımlarını kullanarak gürültü giderme adımları arasında ara aktivasyonları yaklaşık olarak hesaplayıp önbelleğe alarak difüzyon çıkarımını hızlandırır. Yöntem, geçmiş hesaplama sonuçlarına dayanarak gelecekteki çıktıları tahmin eder ve bunları belirli aralıklarla yeniden kullanarak gereksiz hesaplamaları azaltır.</p> <p>Bu önbellekleme mekanizması, minimal ek bellek yükü ile güçlü sonuçlar sunar. Detaylı performans analizi için <a href="https://github.com/huggingface/diffusers/pull/12648#issuecomment-3610615080" rel="nofollow">buradaki bulgularımıza</a> göz atın.</p> <p>TaylorSeer Cache'i etkinleştirmek için bir <a href="/docs/diffusers/main/tr/api/cache#diffusers.TaylorSeerCacheConfig">TaylorSeerCacheConfig</a> oluşturun ve bunu hattınızdaki dönüştürücüye (transformer) iletin:</p> <ul><li><code>cache_interval</code>: Tam bir ileri geçiş (forward pass) yapılmadan önce önbelleğe alınmış çıktıların yeniden kullanılacağı adım sayısı</li> <li><code>disable_cache_before_step</code>: Yaklaşımlar için veri toplamak amacıyla tam hesaplamalar kullanan ilk adımlar</li> <li><code>max_order</code>: Yaklaşım doğruluğu (teorik olarak daha yüksek değerler kaliteyi artırır ancak bellek kullanımını da artırır; <code>1</code> olarak ayarlanmasını öneririz)</li></ul> <div class="code-block relative "><div class="absolute top-2.5 right-4"><button class="inline-flex items-center relative text-sm focus:text-green-500 cursor-pointer focus:outline-none transition duration-200 ease-in-out opacity-0 mx-0.5 text-gray-600 " title="code excerpt" type="button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" fill="currentColor" focusable="false" role="img" width="1em" height="1em" preserveAspectRatio="xMidYMid meet" viewBox="0 0 32 32"><path d="M28,10V28H10V10H28m0-2H10a2,2,0,0,0-2,2V28a2,2,0,0,0,2,2H28a2,2,0,0,0,2-2V10a2,2,0,0,0-2-2Z" transform="translate(0)"></path><path d="M4,18H2V4A2,2,0,0,1,4,2H18V4H4Z" transform="translate(0)"></path><rect fill="none" width="32" height="32"></rect></svg><!----> <div class=" absolute pointer-events-none transition-opacity bg-black text-white py-1 px-2 leading-tight rounded font-normal shadow left-1/2 top-full transform -translate-x-1/2 translate-y-2 opacity-0 "><div class="absolute bottom-full left-1/2 transform -translate-x-1/2 w-0 h-0 border-black border-4 border-t-0" style="border-left-color: transparent; border-right-color: transparent;"></div> Kopyalandı</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> FluxPipeline, TaylorSeerCacheConfig | |
| pipe = FluxPipeline.from_pretrained( | |
| <span class="hljs-string">"black-forest-labs/FLUX.1-dev"</span>, | |
| dtype=torch.bfloat16, | |
| ).to(<span class="hljs-string">"cuda"</span>) <span class="hljs-comment"># or "mps", "xpu", "cpu"</span> | |
| config = TaylorSeerCacheConfig( | |
| cache_interval=<span class="hljs-number">5</span>, | |
| max_order=<span class="hljs-number">1</span>, | |
| disable_cache_before_step=<span class="hljs-number">10</span>, | |
| taylor_factors_dtype=torch.bfloat16, | |
| ) | |
| pipe.transformer.enable_cache(config)<!----></pre></div><!----> <!--[1--><h2 class="relative group"><a id="magcache" 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="#magcache"><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><!---->MagCache<!----></span></h2><!--]--><!----> <p><a href="https://github.com/Zehong-Ma/MagCache" rel="nofollow">MagCache</a>, kalan güncellemenin büyüklüğüne dayanarak dönüştürücü bloklarını atlayarak çıkarımı hızlandırır. Güncellemelerin (Çıktı - Girdi) büyüklüğünün difüzyon süreci boyunca öngörülebilir bir şekilde azaldığını gözlemler. Ön hesaplanmış büyüklük oranlarına dayalı bir “hata bütçesi” biriktirerek, hesaplamanın ne zaman atlanacağını ve önceki kalanın yeniden kullanılacağını dinamik olarak belirler.</p> <p>MagCache, bu azalma eğrisini tanımlayan <strong>Magnitude Ratios</strong> (<code>mag_ratios</code>) üzerine kuruludur. Bu oranlar, model checkpoint'ine ve zamanlayıcıya (scheduler) özgüdür. Pakette gelen <code>FLUX_MAG_RATIOS</code> değerleri FLUX.1 üzerinde ölçülmüştür; Flux2 ve Flux2 Klein dahil diğer modellerin kendi kalibrasyon çalışmasını yapması gerekir.</p> <p>MagCache'i kullanmak için genellikle iki adımlı bir süreç izlenir: <strong>Kalibrasyon</strong> ve <strong>Çıkarım</strong>.</p> <ol><li><strong>Kalibrasyon</strong>: <code>calibrate=True</code> ile bir kez çıkarım çalıştırın. Hook, kalan büyüklüklerini ölçer ve hesaplanan oranları konsola yazdırır.</li> <li><strong>Çıkarım</strong>: Hızlandırmayı etkinleştirmek için bu oranları <code>MagCacheConfig</code> sınıfına iletin.</li></ol> <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-python "><!----><span class="hljs-keyword">import</span> torch | |
| <span class="hljs-keyword">from</span> diffusers <span class="hljs-keyword">import</span> FluxPipeline, MagCacheConfig | |
| pipe = FluxPipeline.from_pretrained( | |
| <span class="hljs-string">"black-forest-labs/FLUX.1-schnell"</span>, | |
| dtype=torch.bfloat16 | |
| ).to(<span class="hljs-string">"cuda"</span>) <span class="hljs-comment"># or "mps", "xpu", "cpu"</span> | |
| <span class="hljs-comment"># 1. Calibration Step</span> | |
| <span class="hljs-comment"># Run full inference to measure model behavior.</span> | |
| calib_config = MagCacheConfig(calibrate=<span class="hljs-literal">True</span>, num_inference_steps=<span class="hljs-number">4</span>) | |
| pipe.transformer.enable_cache(calib_config) | |
| <span class="hljs-comment"># Run a prompt to trigger calibration</span> | |
| pipe(<span class="hljs-string">"A cat playing chess"</span>, num_inference_steps=<span class="hljs-number">4</span>) | |
| <span class="hljs-comment"># Logs will print something like: "MagCache Calibration Results: [1.0, 1.37, 0.97, 0.87]"</span> | |
| <span class="hljs-comment"># 2. Inference Step</span> | |
| <span class="hljs-comment"># Apply the specific ratios obtained from calibration for optimized speed.</span> | |
| <span class="hljs-comment"># Note: For Flux models, you can also import defaults: </span> | |
| <span class="hljs-comment"># from diffusers.hooks.mag_cache import FLUX_MAG_RATIOS</span> | |
| mag_config = MagCacheConfig( | |
| mag_ratios=[<span class="hljs-number">1.0</span>, <span class="hljs-number">1.37</span>, <span class="hljs-number">0.97</span>, <span class="hljs-number">0.87</span>], | |
| num_inference_steps=<span class="hljs-number">4</span> | |
| ) | |
| pipe.transformer.enable_cache(mag_config) | |
| image = pipe(<span class="hljs-string">"A cat playing chess"</span>, num_inference_steps=<span class="hljs-number">4</span>).images[<span class="hljs-number">0</span>]<!----></pre></div><!----> <blockquote class="note"><p><code>mag_ratios</code>, modelin içsel büyüklük azalma eğrisini temsil eder. Yüksek adım sayıları (ör. 50) için kalibre edilmiş oranlar, daha düşük adım sayılarında (ör. 20) yeniden kullanılabilir. Uygulama, eğriyi mevcut çıkarım adım sayısına eşlemek için interpolasyon kullanır.</p></blockquote> <blockquote class="tip"><p>Sıralı olarak Classifier-Free Guidance çalıştıran pipeline'lar (Kandinsky 5.0 gibi) için kalibrasyon günlüğü iki dizi yazdırabilir: biri Conditional geçişi için, diğeri Unconditional geçişi için. Çoğu durumda, ilk diziyi (Conditional) kullanmanız gerekir.</p></blockquote> <blockquote class="tip"><p><strong>batched</strong> (toplu) biçimde Classifier-Free Guidance çalıştıran pipeline'lar (SDXL veya Flux gibi) için, modelin işlediği <code>hidden_states</code>, birleştirilmiş koşullu ve koşulsuz dalları içerir. Kalibrasyon süreci bunu otomatik olarak hesaba katar ve ortak davranışı temsil eden tek bir oran dizisi üretir. Bu sonucun elde edilen dizisini herhangi bir değişiklik yapmadan doğrudan kullanabilirsiniz.</p></blockquote> <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/cache.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, 327], | |
| data: [null,null], | |
| form: null, | |
| error: null | |
| }); | |
| }); | |
| } | |
| </script> | |
Xet Storage Details
- Size:
- 39.5 kB
- Xet hash:
- f83988ecdfdf1728f266a7385bdf59863c09f6f897166bac45cb6b8866be4094
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.