Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
781c7e3
base implement teacahce flux; follow original impl
LawJarp-A Nov 13, 2025
549bf97
update cache utils with teacache
LawJarp-A Nov 13, 2025
29d4ffc
change hook to inline transformer processing instead of calling origi…
LawJarp-A Nov 13, 2025
07c6718
add extensive docstring (auto gen); add repr
LawJarp-A Nov 14, 2025
a7598a1
add param validation and error messages
LawJarp-A Nov 14, 2025
d9648e5
add basic logging
LawJarp-A Nov 14, 2025
59cb890
add compatible test
LawJarp-A Nov 14, 2025
5227937
Merge branch 'main' into teacache-flux
LawJarp-A Nov 17, 2025
296aa8d
Merge branch 'main' into teacache-flux
LawJarp-A Nov 26, 2025
44663de
update it to make it model agnostic
LawJarp-A Nov 26, 2025
4d34020
add TeaCache hook tests and ensure cache integration passes style and…
LawJarp-A Nov 26, 2025
9dab52f
Add multi-model TeaCache support for Mochi, Lumina2, and CogVideoX wi…
LawJarp-A Dec 2, 2025
4cb71d6
simplify model extract; use logger
LawJarp-A Dec 8, 2025
ad90044
Merge branch 'main' into teacache-flux
LawJarp-A Dec 8, 2025
f2793fd
Merge branch 'main' into teacache-flux
LawJarp-A Dec 9, 2025
f0abb3c
fix(teacache): fix return_dict handling, CogVideoX fallback bug, add …
LawJarp-A Dec 10, 2025
4a6afef
Fix TeaCache state management and add num_inference_steps param
LawJarp-A Dec 10, 2025
8646908
fixed counter manage, cogvoideox missing norm proj added
LawJarp-A Dec 10, 2025
c62ddc2
Merge branch 'main' into teacache-flux
LawJarp-A Dec 11, 2025
c2c4c76
Merge branch 'huggingface:main' into teacache-flux
LawJarp-A Dec 16, 2025
38effa1
Refactor TeaCache hook into adapters
LawJarp-A Dec 16, 2025
9f0fbff
Merge branch 'huggingface:main' into teacache-flux
LawJarp-A Jan 6, 2026
c605f4d
refactor teacache: replace adapter classes with standalone functions
LawJarp-A Jan 6, 2026
883699e
refactor teacache: remove closure pattern, use standalone utility fun…
LawJarp-A Jan 6, 2026
29110bf
cleanup: remove dead comments
LawJarp-A Jan 6, 2026
308e4c3
Merge branch 'main' into teacache-flux
sayakpaul Jan 8, 2026
e328ccc
cleanup: code quality fixes
LawJarp-A Jan 8, 2026
8946aeb
refactor: improve code quality, type hints
LawJarp-A Jan 8, 2026
abb24e0
fix: move TeaCache context setting to denoising loop for proper state…
LawJarp-A Jan 12, 2026
c45af51
simplify implementation and reduce code duplication
LawJarp-A Jan 12, 2026
90eb746
simplify TeaCache tests with module-level imports and model factory h…
LawJarp-A Jan 12, 2026
c6c5339
Merge branch 'main' into teacache-flux
LawJarp-A Jan 12, 2026
b38315d
refactor: enhance type hints and add ControlNet support in TeaCache f…
LawJarp-A Jan 12, 2026
08deb44
Apply style fixes
github-actions[bot] Jan 20, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/diffusers/hooks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
from .faster_cache import FasterCacheConfig, apply_faster_cache
from .first_block_cache import FirstBlockCacheConfig, apply_first_block_cache
from .group_offloading import apply_group_offloading
from .hooks import HookRegistry, ModelHook
from .hooks import HookRegistry, ModelHook, StateManager
from .layer_skip import LayerSkipConfig, apply_layer_skip
from .layerwise_casting import apply_layerwise_casting, apply_layerwise_casting_hook
from .pyramid_attention_broadcast import PyramidAttentionBroadcastConfig, apply_pyramid_attention_broadcast
from .smoothed_energy_guidance_utils import SmoothedEnergyGuidanceConfig
from .taylorseer_cache import TaylorSeerCacheConfig, apply_taylorseer_cache
from .teacache import TeaCacheConfig, apply_teacache
33 changes: 13 additions & 20 deletions src/diffusers/hooks/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,14 @@ def __init__(self, state_cls: BaseState, init_args=None, init_kwargs=None):
self._current_context = None

def get_state(self):
if self._current_context is None:
raise ValueError("No context is set. Please set a context before retrieving the state.")
if self._current_context not in self._state_cache.keys():
self._state_cache[self._current_context] = self._state_cls(*self._init_args, **self._init_kwargs)
return self._state_cache[self._current_context]
context = self._current_context
if context is None:
# Fallback to default context for backward compatibility with
# pipelines that don't call cache_context()
context = "_default"
Comment on lines +45 to +47
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this branch not error out like previous?

if context not in self._state_cache:
self._state_cache[context] = self._state_cls(*self._init_args, **self._init_kwargs)
return self._state_cache[context]

def set_context(self, name: str) -> None:
self._current_context = name
Expand Down Expand Up @@ -133,7 +136,7 @@ def reset_state(self, module: torch.nn.Module):
return module

def _set_context(self, module: torch.nn.Module, name: str) -> None:
# Iterate over all attributes of the hook to see if any of them have the type `StateManager`. If so, call `set_context` on them.
"""Set context on all StateManager attributes of this hook."""
Comment on lines -136 to +139
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we please revert the changes unrelated to this PR? Makes reviewing a bit easier since the diff becomes smaller.

for attr_name in dir(self):
attr = getattr(self, attr_name)
if isinstance(attr, StateManager):
Expand All @@ -142,22 +145,12 @@ def _set_context(self, module: torch.nn.Module, name: str) -> None:


class HookFunctionReference:
def __init__(self) -> None:
"""A container class that maintains mutable references to forward pass functions in a hook chain.

Its mutable nature allows the hook system to modify the execution chain dynamically without rebuilding the
entire forward pass structure.
"""Mutable container for forward pass function references in a hook chain.

Attributes:
pre_forward: A callable that processes inputs before the main forward pass.
post_forward: A callable that processes outputs after the main forward pass.
forward: The current forward function in the hook chain.
original_forward: The original forward function, stored when a hook provides a custom new_forward.
Enables dynamic modification of the execution chain without rebuilding.
"""

The class enables hook removal by allowing updates to the forward chain through reference modification rather
than requiring reconstruction of the entire chain. When a hook is removed, only the relevant references need to
be updated, preserving the execution order of the remaining hooks.
"""
def __init__(self) -> None:
self.pre_forward = None
self.post_forward = None
self.forward = None
Expand Down
Loading
Loading