| 142 | |
| 143 | |
| 144 | class HookFunctionReference: |
| 145 | def __init__(self) -> None: |
| 146 | """A container class that maintains mutable references to forward pass functions in a hook chain. |
| 147 | |
| 148 | Its mutable nature allows the hook system to modify the execution chain dynamically without rebuilding the |
| 149 | entire forward pass structure. |
| 150 | |
| 151 | Attributes: |
| 152 | pre_forward: A callable that processes inputs before the main forward pass. |
| 153 | post_forward: A callable that processes outputs after the main forward pass. |
| 154 | forward: The current forward function in the hook chain. |
| 155 | original_forward: The original forward function, stored when a hook provides a custom new_forward. |
| 156 | |
| 157 | The class enables hook removal by allowing updates to the forward chain through reference modification rather |
| 158 | than requiring reconstruction of the entire chain. When a hook is removed, only the relevant references need to |
| 159 | be updated, preserving the execution order of the remaining hooks. |
| 160 | """ |
| 161 | self.pre_forward = None |
| 162 | self.post_forward = None |
| 163 | self.forward = None |
| 164 | self.original_forward = None |
| 165 | |
| 166 | |
| 167 | class HookRegistry: |
no outgoing calls
no test coverage detected
searching dependent graphs…