Skip to content

Commit

Permalink
Use ACT2FN to fetch ReLU activation (huggingface#16874)
Browse files Browse the repository at this point in the history
- all activations should be fetched through ACT2FN
- it returns ReLU as `nn.Module`, which allows attaching hooks on the activation function and prints it to stdout when `print(model)`
  • Loading branch information
eldarkurtic authored Apr 21, 2022
1 parent cb555af commit bae9b64
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/transformers/models/t5/modeling_t5.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,11 @@ def __init__(self, config: T5Config):
self.wi = nn.Linear(config.d_model, config.d_ff, bias=False)
self.wo = nn.Linear(config.d_ff, config.d_model, bias=False)
self.dropout = nn.Dropout(config.dropout_rate)
self.relu_act = ACT2FN["relu"]

def forward(self, hidden_states):
hidden_states = self.wi(hidden_states)
hidden_states = nn.functional.relu(hidden_states)
hidden_states = self.relu_act(hidden_states)
hidden_states = self.dropout(hidden_states)
hidden_states = self.wo(hidden_states)
return hidden_states
Expand Down

0 comments on commit bae9b64

Please sign in to comment.