MCPcopy Create free account
hub / github.com/huggingface/diffusers / FeedForwardSkipHook

Class FeedForwardSkipHook

src/diffusers/hooks/layer_skip.py:133–148  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

131
132
133class 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
151class TransformerBlockSkipHook(ModelHook):

Callers 1

_apply_layer_skip_hookFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…