W3cubDocs

/PyTorch 2.9

GLU

class torch.nn.modules.activation.GLU(dim=-1) [source]

Applies the gated linear unit function.

GLU(a,b)=aσ(b){GLU}(a, b)= a \otimes \sigma(b) where aa is the first half of the input matrices and bb is the second half.

Parameters

dim (int) – the dimension on which to split the input. Default: -1

Shape:
  • Input: (1,N,2)(\ast_1, N, \ast_2) where * means, any number of additional dimensions
  • Output: (1,M,2)(\ast_1, M, \ast_2) where M=N/2M=N/2
../_images/GLU.png

Examples:

>>> m = nn.GLU()
>>> input = torch.randn(4, 2)
>>> output = m(input)
extra_repr() [source]

Return the extra representation of the module.

Return type

str

forward(input) [source]

Runs the forward pass.

Return type

Tensor

© 2025, PyTorch Contributors
PyTorch has a BSD-style license, as found in the LICENSE file.
https://docs.pytorch.org/docs/2.9/generated/torch.nn.modules.activation.GLU.html