Hard Sigmoid#

API#

class warp_nn.modules.activations.HardSigmoid(
*,
alpha: float = 0.16666666666666666,
beta: float = 0.5,
requires_grad: bool = True,
)[source]#

Bases: Module

Hard Sigmoid activation function.

This class computes the element-wise Hard Sigmoid activation function:

\[\text{HardSigmoid}(x) = \max(0, \min(1, \alpha \, x + \beta))\]

Note

The default values match PyTorch’s Hardsigmoid (the default alpha value of the ONNX HardSigmoid operator is 0.2).

Parameters:
  • alpha – The slope of the linear region.

  • beta – The offset of the linear region.

  • requires_grad – Whether the cached output arrays of the module require gradients.

__call__(
input: array,
) → array[source]#

Forward pass of the activation function.

Parameters:

input – The input array, with up to 3 dimensions.

Returns:

The output array, with same shape as the input array.

Raises:

TypeError – If the input array’s data type or number of dimensions is not supported.

property alpha: float[source]#

The slope of the linear region.

property beta: float[source]#

The offset of the linear region.