Hardswish
_QuantizedActivationHardswish(scale: Tensor, zero_point: Tensor, qdtype: QDtype = quint8)Quantized lucid.nn.Hardswish — hardswish(x) then output fake-quant.
The inference-time replacement for a calibrated float nn.Hardswish,
installed by lucid.quantization.convert / from_float.
Hardswish is the cheap piecewise-linear approximation of x·sigmoid(x)
used throughout MobileNetV3 / EfficientNet-lite, chosen precisely because its
clamp-and-multiply form quantizes cleanly. Under the sidecar representation
(design B) the quantized layer is the float activation followed by a
fake-quantize to the calibrated output grid.
Unlike Sigmoid / Tanh, hardswish is unbounded above
(it grows like for large ), so its output range is not
known a priori — it must be calibrated with a real observer rather than a
lucid.quantization.FixedQParamsObserver.
with and the
calibrated output (scale, zero_point) .
Parameters
Notes
- Built via
convert/from_float, which reads the source module's output observer. - Its range is data-dependent, so calibrate through the prepared model before
convert— a fixed-qparams grid would clip the unbounded upper tail. - The forward is
float hardswish → fake-quant; only the output is snapped.
Examples
>>> import lucid, lucid.nn as nn
>>> qhs = nn.quantized.Hardswish(lucid.tensor(0.05), lucid.tensor(64.0))
>>> qhs(lucid.randn(8)).shape
(8,)See Also
- lucid.nn.quantized.Sigmoid—Bounded
[0, 1](fixed-qparams-friendly). - lucid.nn.quantized.Hardsigmoid—The gate paired with hardswish in SE blocks.
- lucid.quantization.convert—Installs this layer from a calibrated model.