Skip to content

Commit 45c2a6d

Browse files
committed
update
1 parent c90a0e2 commit 45c2a6d

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

src/diffusers/hooks/hooks.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,20 @@ def reset_state(self, module: torch.nn.Module):
103103

104104
class HookFunctionReference:
105105
def __init__(self) -> None:
106-
"""
107-
Holding class for forward functions references used in Diffusers hooks. This struct allows you to easily swap
108-
out the forward function in the when a hook is removed from a modules hook registry.
106+
"""A container class that maintains mutable references to forward pass functions in a hook chain.
107+
108+
Its mutable nature allows the hook system to modify the execution chain dynamically without rebuilding the
109+
entire forward pass structure.
110+
111+
Attributes:
112+
pre_forward: A callable that processes inputs before the main forward pass.
113+
post_forward: A callable that processes outputs after the main forward pass.
114+
forward: The current forward function in the hook chain.
115+
original_forward: The original forward function, stored when a hook provides a custom new_forward.
109116
117+
The class enables hook removal by allowing updates to the forward chain through reference modification rather
118+
than requiring reconstruction of the entire chain. When a hook is removed, only the relevant references need to
119+
be updated, preserving the execution order of the remaining hooks.
110120
"""
111121
self.pre_forward = None
112122
self.post_forward = None

0 commit comments

Comments
 (0)