Skip to content
class

Sigmoid

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

Implementing kernel

C++ engine symbols that back this Python API.

Quantized lucid.nn.Sigmoid — sigmoid(x) then output fake-quant.

The inference-time replacement for a calibrated float nn.Sigmoid sitting inside a quantized region, installed by lucid.quantization.convert / from_float. Under the sidecar representation (design B) a quantized activation is simply the float activation followed by a fake-quantize to the calibrated output grid, so a standalone sigmoid is requantized rather than left at full precision between two int8 layers.

Because σ(x)∈[0,1]\sigma(x) \in [0, 1] the output range is known a priori, this is the archetypal fixed-qparams activation: instead of calibrating the range from data, pair it with a lucid.quantization.FixedQParamsObserver in the qconfig, which pins the grid to the constant [0,1][0, 1] mapping.

y=fake_quant⁡(σ(x)),S=1256,Z=0y = \operatorname{fake\_quant}\bigl(\sigma(x)\bigr), \qquad S = \tfrac{1}{256},\quad Z = 0

so the quint8 codes 0 .. 255 tile [0,1][0, 1] uniformly with step SS. 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.

Parameters

scaleTensor
Per-tensor output scale — the fixed 1/256 when paired with a lucid.quantization.FixedQParamsObserver, else the calibrated value. Supplied by from_float; construct directly only with qparams in hand.
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; a bare nn.Sigmoid is not one of these.
  • Pairing with lucid.quantization.FixedQParamsObserver skips a calibration pass for a range that is fixed by construction.
  • The forward is float sigmoid → fake-quant; the sigmoid itself runs at full float precision, only the output is snapped to the grid.

Examples

>>> import lucid, lucid.nn as nn
>>> qsig = nn.quantized.Sigmoid(lucid.tensor(1 / 256), lucid.tensor(0.0))
>>> y = qsig(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.