Skip to content
class

SiLU

extends_InplaceActivation
SiLU(inplace: bool = False)

Sigmoid Linear Unit (Swish) activation function.

Applies element-wise:

SiLU(x)=x⋅σ(x)=x1+e−x\text{SiLU}(x) = x \cdot \sigma(x) = \frac{x}{1 + e^{-x}}

where σ\sigma is the logistic sigmoid function. The gate σ(x)\sigma(x) smoothly interpolates between 0 (deep negative) and the identity (large positive), producing a non-monotone shape with a small dip below zero near x≈−1.3x \approx -1.3.

Parameters

inplacebool= False
If True, modifies the input tensor in-place. Default: False.

Notes

  • Input: (∗)(*) — any shape.
  • Output: (∗)(*) — same shape as input.

SiLU / Swish is used in EfficientNet, MobileNetV3, and many modern vision backbones as a smooth, self-gated alternative to ReLU. It is differentiable everywhere, including at zero.

Examples

>>> import lucid
>>> import lucid.nn as nn
>>> m = nn.SiLU()
>>> x = lucid.tensor([-2.0, -1.0, 0.0, 1.0, 2.0])
>>> m(x)
tensor([-0.2384, -0.2689, 0., 0.7311, 1.762])
>>> # Common backbone activation — shape-preserving
>>> x = lucid.randn(8, 256)
>>> out = nn.SiLU()(x)
>>> out.shape
(8, 256)

Used by 2

Instance methods

1
fn

forward

→Tensor
forward(input: Tensor)

Apply the activation function element-wise.

Parameters

inputTensor
Input tensor of arbitrary shape.

Returns

Tensor

Output tensor of the same shape as input.