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

Offen
#15,321 1 Kommentar 0 Reaktionen 1 zugewiesene Person Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

@sayakpaul arbeitet bereits daran.

Seit 17.11.2026.

  • #15328 von @sayakpaul — offen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Beschreibung

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

Vorherrschende Sprache
Python
Sterne
34.9k
Forks
7.5k
Ø Merge
3 T. 16 Std.
Gemergte PRs (30 T.)
65

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus huggingface/diffusers

Alle Issues in huggingface/diffusers

Ähnliche Issues

Weitere Issues zu Python

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.