braindecode.modules.GatedLinearUnit#
- class braindecode.modules.GatedLinearUnit(activation=<class 'torch.nn.modules.activation.GELU'>)[source]#
Generalized gated linear unit (GLU family).
Splits the last dimension in half into a
valueand agateand returns \(\text{value} \otimes \text{activation}(\text{gate})\). With the defaultactivation=nn.GELUthis is GEGLU (Shazeer, 2020);nn.SiLUgives SwiGLU andnn.Sigmoidthe original GLU. Unliketorch.nn.GLU, the gate nonlinearity is configurable (torch.nn.GLUis hard-wired to the sigmoid).- Parameters:
activation (
type[Module]) – Constructor of the gate activation. The default yields GEGLU.
Examples
>>> import torch >>> from braindecode.modules import GatedLinearUnit >>> module = GatedLinearUnit() >>> outputs = module(torch.randn(2, 10, 16)) >>> outputs.shape torch.Size([2, 10, 8])
Methods
- forward(x)[source]#
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.- Return type: