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 value and a gate and returns \(\text{value} \otimes \text{activation}(\text{gate})\). With the default activation=nn.GELU this is GEGLU (Shazeer, 2020); nn.SiLU gives SwiGLU and nn.Sigmoid the original GLU. Unlike torch.nn.GLU, the gate nonlinearity is configurable (torch.nn.GLU is 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 Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

Return type:

Tensor