class
Hardsigmoid
extends
_QuantizedActivationHardsigmoid(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 , 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 , pair it with a
lucid.quantization.FixedQParamsObserver (scale ,
zero-point ) to skip calibrating a range known a priori.
with and, for the fixed grid, .
Parameters
scaleTensorPer-tensor output scale — the fixed
1/256 under a
lucid.quantization.FixedQParamsObserver, else calibrated.
Supplied by from_float.zero_pointTensorPer-tensor output zero-point (
0 for the fixed [0, 1] grid).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 withlucid.quantization.FixedQParamsObserveravoids a calibration pass. - Often paired with
Hardswishinside 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]
TrueSee Also
- lucid.nn.quantized.Sigmoid—The smooth
[0, 1]original. - lucid.nn.quantized.Hardswish—Its partner activation in SE blocks.
- lucid.quantization.FixedQParamsObserver—Pins the grid for bounded outputs.