1
0
mirror of https://github.com/huggingface/diffusers.git synced 2026-10-24 20:59:27 +03:00
Commit Graph

11 Commits

Author SHA1 Message Date
Vinh H. Pham
7c6eb78306 [hooks] Support Flux2 in MagCache (#14756)
* [hooks] Support Flux2 in MagCache

MagCache could not be enabled on `Flux2Transformer2DModel` (Flux2 and Flux2 Klein):

1. `Flux2TransformerBlock` and `Flux2SingleTransformerBlock` were not registered in
   `TransformerBlockRegistry`, so `apply_mag_cache` raised `ValueError: Model class ... not registered`.
2. Once registered, the tail hook raised a shape error. The head hook records the image-only input of
   `transformer_blocks[0]`, but the Flux2 model concatenates the text and image streams before the
   single-stream blocks and calls them with `encoder_hidden_states=None`, so the last single block returns
   the fused `[text; image]` sequence. The residual `tail_output - head_input` could not be formed.

Register the two Flux2 blocks (the single block with `return_encoder_hidden_states_index=None`, matching
how the model calls it) and add `_align_to_hidden_states`, which keeps only the trailing image tokens of
the fused tensor when computing the residual. The cached residual is therefore image-only, which is what
the reference MagCache4FLUX implementation does, and it matches the head input on skipped steps. This also replaces
a dead "fallback" branch in the tail hook that subtracted mismatched shapes anyway.

Tests: `MagCacheTesterMixin` for `Flux2Transformer2DModel`, `Flux2Pipeline` and `Flux2KleinPipeline`.

FirstBlockCache has the same head/tail structure and still fails on Flux2; left for a follow-up.

* [hooks] Slice the fused tail output in the existing mismatch branch

Implement the Flux2 residual fix inside the tail hook's sequence-length mismatch branch instead of a
separate `_align_to_hidden_states` helper. The surrounding structure stays as it was: the `diff == 0`
case still covers a batch-size mismatch via broadcasting, and only the mismatched-length case changes
to subtract the trailing image tokens.

---------

Co-authored-by: Dhruv Nair <dhruv.nair@gmail.com>
2026-10-14 15:21:38 +05:30
yzhautouskay
78405ec9a1 [Cosmos3] Fix Transfer SeaCache artifacts with control CFG (#14897)
* Fix Cosmos 3 Transfer SeaCache indicators

* Clarify SeaCache indicator guidance; tests refactor

---------

Co-authored-by: Sayak Paul <spsayakpaul@gmail.com>
2026-09-30 21:23:20 +05:30
yzhautouskay
344d6e7300 Add SeaCache support for Cosmos3 pipelines (#14663)
* Add optional FP32 sampling state for Cosmos3

* Add cache execution contexts to Cosmos3 pipelines

* Add SeaCache support for Cosmos3

* Cap consecutive SeaCache reuses

* Align SeaCache defaults with Cosmos3 inference

* Enable SeaCache by default for Cosmos3

* Document SeaCache for Cosmos3

* Use FP32 sampling state by default for Cosmos3

* Fix SeaCache reconfiguration, transfer state isolation, and FP32 sampling

* Remove SeaCache stats and ablation instrumentation

* Move SeaCache to transformer-level and disable by default

* Align SeaCache and tests with model-level cache patterns

* Make Cosmos3 sampling state always FP32

* Add pipe definition to the docs snippet

* Remove redundant hook registry cache resets

* Use raw vision latents for SeaCache indicators

* Make Cosmos3 SeaCache safe for regional compilation

* Fix SeaCache with Cosmos3 model parallelism

* Support single-stream models in SeaCache

* Add Wan T2V support to SeaCache

* pass denoising step info to cache hooks via cache_context

Replaces SeaCache's pipeline-state callbacks: the pipeline attaches the loop
coordinates (step_index, sigma, num_inference_steps) to the denoiser call with
`cache_context(name, ...)`, carried by a frozen CacheContext dataclass and stored
on each stateful hook's StateManager (the registry no longer holds context).

Co-Authored-By: Dhruv Nair <dhruv.nair@gmail.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* Fix Wan cache metadata and Cosmos modular cleanup

Pass denoising step metadata to Wan T2V conditional and unconditional cache contexts.

Restore stateful cache reset after Cosmos modular pipeline calls, restore the required Literal import, and update regression tests and documentation.

* Refactor Cosmos3 SeaCache decoder hook

* Apply CI formatting updates

* Fix distilled system prompt fallback

* Preserve Cosmos3 fp32 sampling state

---------

Co-authored-by: yiyixuxu <yixu310@gmail.com>
Co-authored-by: Dhruv Nair <dhruv.nair@gmail.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Co-authored-by: Sayak Paul <spsayakpaul@gmail.com>
2026-09-18 11:25:32 +05:30
kaixuanliu
b9bc22bd57 make examples in docs device agnostic (#14414)
* docs: annotate hardcoded cuda device with alternatives in English docs

* docs: annotate hardcoded device_map="cuda" with alternatives

* update

Signed-off-by: kaixuanliu <kaixuan.liu@intel.com>

---------

Signed-off-by: kaixuanliu <kaixuan.liu@intel.com>
2026-08-25 08:12:22 -07:00
Steven Liu
351de3a6fe [docs] deprecate torch_dtype for dtype (#14313)
* docs

* update

* Revert "docs"

This reverts commit 04ca80543f.

---------

Co-authored-by: Sayak Paul <spsayakpaul@gmail.com>
2026-07-29 08:20:06 +05:30
Sayak Paul
e5cf820fc3 [docs] add magcache to caching api listing (#13714)
add magcache to caching api listing
2026-05-12 06:45:26 +09:00
Alan Ponnachan
430c557b6a Add support for Magcache (#12744)
* add magcache

* formatting

* add magcache support with calibration mode

* add imports

* improvements

* Apply style fixes

* fix kandinsky errors

* add tests and documentation

* Apply style fixes

* improvements

* Apply style fixes

* make fix-copies.

* minor fixes

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Sayak Paul <spsayakpaul@gmail.com>
2026-02-04 13:45:12 +05:30
Sayak Paul
4ac2b4a521 [docs] polish caching docs. (#12684)
* polish caching docs.

* Update docs/source/en/optimization/cache.md

Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com>

* Update docs/source/en/optimization/cache.md

Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com>

* up

---------

Co-authored-by: Steven Liu <59462357+stevhliu@users.noreply.github.com>
2026-01-10 10:09:05 -08:00
Tran Thanh Luan
6290fdfda4 [Feat] TaylorSeer Cache (#12648)
* init taylor_seer cache

* make compatible with any tuple size returned

* use logger for printing, add warmup feature

* still update in warmup steps

* refractor, add docs

* add configurable cache, skip compute module

* allow special cache ids only

* add stop_predicts (cooldown)

* update docs

* apply ruff

* update to handle multple calls per timestep

* refractor to use state manager

* fix format & doc

* chores: naming, remove redundancy

* add docs

* quality & style

* fix taylor precision

* Apply style fixes

* add tests

* Apply style fixes

* Remove TaylorSeerCacheTesterMixin from flux2 tests

* rename identifiers, use more expressive taylor predict loop

* torch compile compatible

* Apply style fixes

* Update src/diffusers/hooks/taylorseer_cache.py

Co-authored-by: Dhruv Nair <dhruv.nair@gmail.com>

* update docs

* make fix-copies

* fix example usage.

* remove tests on flux kontext

---------

Co-authored-by: toilaluan <toilaluan@github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Dhruv Nair <dhruv.nair@gmail.com>
Co-authored-by: Sayak Paul <spsayakpaul@gmail.com>
2025-12-06 05:39:54 +05:30
Aryan
a4df8dbc40 Update more licenses to 2025 (#11746)
update
2025-06-19 07:46:01 +05:30
Steven Liu
9f48394bf7 [docs] Caching methods (#11625)
* cache

* feedback
2025-06-02 10:58:47 -07:00