| 131 | |
| 132 | |
| 133 | class FeedForwardSkipHook(ModelHook): |
| 134 | def __init__(self, dropout: float): |
| 135 | super().__init__() |
| 136 | self.dropout = dropout |
| 137 | |
| 138 | def new_forward(self, module: torch.nn.Module, *args, **kwargs): |
| 139 | if math.isclose(self.dropout, 1.0): |
| 140 | output = kwargs.get("hidden_states", None) |
| 141 | if output is None: |
| 142 | output = kwargs.get("x", None) |
| 143 | if output is None and len(args) > 0: |
| 144 | output = args[0] |
| 145 | else: |
| 146 | output = self.fn_ref.original_forward(*args, **kwargs) |
| 147 | output = torch.nn.functional.dropout(output, p=self.dropout) |
| 148 | return output |
| 149 | |
| 150 | |
| 151 | class TransformerBlockSkipHook(ModelHook): |
no outgoing calls
no test coverage detected
searching dependent graphs…