Skip to content
class

Hardsigmoid

extends_QuantizedActivation
Hardsigmoid(scale: Tensor, zero_point: Tensor, qdtype: QDtype = quint8)

Quantized lucid.nn.Hardsigmoid — hardsigmoid(x) then fake-quant.

The inference-time replacement for a calibrated float nn.Hardsigmoid, installed by lucid.quantization.convert / from_float. Hardsigmoid is the piecewise-linear approximation of the sigmoid gate used in MobileNetV3's squeeze-and-excitation blocks; like Sigmoid its output is bounded to [0,1][0, 1], so it is a natural fixed-qparams activation. Under the sidecar representation (design B) the quantized layer is the float activation followed by a fake-quantize to the calibrated output grid.

Because the range is fixed to [0,1][0, 1], pair it with a lucid.quantization.FixedQParamsObserver (scale 1/2561/256, zero-point 00) to skip calibrating a range known a priori.

y=fake_quant⁡(hardsigmoid⁡(x)),hardsigmoid⁡(x)=clamp⁡(x+3, 0, 6)6y = \operatorname{fake\_quant}\bigl(\operatorname{hardsigmoid}(x)\bigr), \qquad \operatorname{hardsigmoid}(x) = \frac{\operatorname{clamp}(x + 3,\ 0,\ 6)}{6}

with fake_quant⁡(t)=(clamp⁡(round⁡(t/S)+Z,qmin⁡,qmax⁡)−Z) S\operatorname{fake\_quant}(t) = (\operatorname{clamp}( \operatorname{round}(t/S) + Z, q_{\min}, q_{\max}) - Z)\, S and, for the fixed grid, S=1/256,Z=0S = 1/256,Z = 0.

Parameters

scaleTensor
Per-tensor output scale — the fixed 1/256 under a lucid.quantization.FixedQParamsObserver, else calibrated. Supplied by from_float.
zero_pointTensor
Per-tensor output zero-point (0 for the fixed [0, 1] grid).
qdtypeQDtype= quint8
Quantized dtype bounding the grid. Defaults to lucid.quantization.quint8 ([0, 255]).

Notes

  • Built via convert / from_float, which reads the source module's output observer.
  • Bounded to [0, 1], so pairing with lucid.quantization.FixedQParamsObserver avoids a calibration pass.
  • Often paired with Hardswish inside the same SE block; both are the hardware-friendly piecewise-linear substitutes for their smooth originals.

Examples

>>> import lucid, lucid.nn as nn
>>> qhs = nn.quantized.Hardsigmoid(lucid.tensor(1 / 256), lucid.tensor(0.0))
>>> y = qhs(lucid.randn(8))
>>> bool(((y >= 0) & (y <= 1)).all().item())     # bounded to [0, 1]
True

See Also

Used by 1

Class methods

1
cls

from_float

→Selffrom _QuantizedActivation
from_float(mod: nn.Module)

Build from a calibrated float activation (reads its output observer).

Instance methods

1
fn

forward

→Tensorfrom _QuantizedActivation
forward(input: Tensor)

Activate, then fake-quantize to the calibrated grid.