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

Class ApproximateGELU

src/diffusers/models/activations.py:149–166  ·  view source on GitHub ↗

r""" The approximate form of the Gaussian Error Linear Unit (GELU). For more details, see section 2 of this [paper](https://huggingface.co/papers/1606.08415). Parameters: dim_in (`int`): The number of channels in the input. dim_out (`int`): The number of channels in the

Source from the content-addressed store, hash-verified

147
148
149class ApproximateGELU(nn.Module):
150 r"""
151 The approximate form of the Gaussian Error Linear Unit (GELU). For more details, see section 2 of this
152 [paper](https://huggingface.co/papers/1606.08415).
153
154 Parameters:
155 dim_in (`int`): The number of channels in the input.
156 dim_out (`int`): The number of channels in the output.
157 bias (`bool`, defaults to True): Whether to use a bias in the linear layer.
158 """
159
160 def __init__(self, dim_in: int, dim_out: int, bias: bool = True):
161 super().__init__()
162 self.proj = nn.Linear(dim_in, dim_out, bias=bias)
163
164 def forward(self, x: torch.Tensor) -> torch.Tensor:
165 x = self.proj(x)
166 return x * torch.sigmoid(1.702 * x)
167
168
169class LinearActivation(nn.Module):

Callers 1

__init__Method · 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…