Cache hooks: add `cache_context` to all official pipelines + TaylorSeer fallback when no context is set

未關閉
#15,321 1 則留言 0 個 reaction 已指派 1 人 在 GitHub 檢視

維護者通常 1 天內回覆

@sayakpaul 已經在處理了。

開始於 2026年11月17日。

  • #15328 來自 @sayakpaul —— 未關閉

評估

這個 Issue 還沒有評估資料。

描述

Follow-up from the review discussion on #14923 (comment) by @yiyixuxu, related to #14922.

Context

Stateful cache hooks get their per-call state from StateManager.context (src/diffusers/hooks/hooks.py). If the denoiser runs outside model.cache_context(...), it raises:

ValueError: No cache context is set. Wrap the denoiser call in `model.cache_context(name, ...)` before calling it.

Right now only some pipelines wrap their transformer calls (for example, pipeline_flux.py uses "cond" / "uncond"). The other Flux pipelines don't, so pipe.transformer.enable_cache(TaylorSeerCacheConfig(...)) fails on them (#14922).

Proposal

There are two parts, and they can be done separately:

  1. Add cache_context to all officially supported pipelines. CacheContext now carries more than the name (step_index, num_inference_steps, timestep, sigma), so pipelines should pass that loop information through the context manager in a consistent way.

    • Use accurate names. For example, distilled pipelines with a single model call per step shouldn't label it "cond". They should either leave the name out or use a name that matches what the call actually is.
  2. TaylorSeer should work without a context manager. TaylorSeer doesn't actually need any context, so TaylorSeerCacheConfig should fall back to a default/single state when no cache_context is set, instead of raising. Then it works on any pipeline or a bare model call, whether or not part 1 is done.

Related

  • #14922 (Enable TaylorSeer for all Flux pipelines)
  • #14923 (wraps Flux pipeline transformer calls in cache_context)

cc @sayakpaul


Requested by Sayak Paul - Slack thread - Agent trace

主要語言
Python
星號
34.9k
分支
7.5k
平均合併
3 天 16 小時
30 天內合併 PR
65

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

huggingface/diffusers 的其他 Issue

查看 huggingface/diffusers 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。