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

Class SwiGLU

src/diffusers/models/activations.py:126–146  ·  view source on GitHub ↗

r""" A [variant](https://huggingface.co/papers/2002.05202) of the gated linear unit activation function. It's similar to `GEGLU` but uses SiLU / Swish instead of GeLU. Parameters: dim_in (`int`): The number of channels in the input. dim_out (`int`): The number of channel

Source from the content-addressed store, hash-verified

124
125
126class SwiGLU(nn.Module):
127 r"""
128 A [variant](https://huggingface.co/papers/2002.05202) of the gated linear unit activation function. It's similar to
129 `GEGLU` but uses SiLU / Swish instead of GeLU.
130
131 Parameters:
132 dim_in (`int`): The number of channels in the input.
133 dim_out (`int`): The number of channels in the output.
134 bias (`bool`, defaults to True): Whether to use a bias in the linear layer.
135 """
136
137 def __init__(self, dim_in: int, dim_out: int, bias: bool = True):
138 super().__init__()
139
140 self.proj = nn.Linear(dim_in, dim_out * 2, bias=bias)
141 self.activation = nn.SiLU()
142
143 def forward(self, hidden_states):
144 hidden_states = self.proj(hidden_states)
145 hidden_states, gate = hidden_states.chunk(2, dim=-1)
146 return hidden_states * self.activation(gate)
147
148
149class ApproximateGELU(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…