class
Hardswish
extends
ModuleHardswish()Hard Swish activation function.
Applies element-wise:
which is equivalent to:
Hard Swish approximates the SiLU (Swish) activation using only integer arithmetic-friendly piecewise-linear operations, making it particularly efficient on hardware without native sigmoid support (e.g. mobile NPUs). It was introduced in MobileNetV3.
Notes
- Input: — any shape.
- Output: — same shape as input.
Examples
>>> import lucid
>>> import lucid.nn as nn
>>> m = nn.Hardswish()
>>> x = lucid.tensor([-4.0, -1.5, 0.0, 1.5, 4.0])
>>> m(x)
tensor([0. , -0.375, 0. , 1.125, 4. ])
>>> # Efficient mobile backbone activation
>>> x = lucid.randn(1, 96, 28, 28)
>>> out = m(x)
>>> out.shape
(1, 96, 28, 28)Methods (1)
fn
forward
→Tensorforward(x: Tensor)Apply the activation function element-wise.
Parameters
inputTensorInput tensor of arbitrary shape.
Returns
TensorOutput tensor of the same shape as input.