class
Tanh
extends
_QuantizedActivationTanh(scale: Tensor, zero_point: Tensor, qdtype: QDtype = quint8)Implementing kernel
C++ engine symbols that back this Python API.Quantized lucid.nn.Tanh — tanh(x) then output fake-quant.
The inference-time replacement for a calibrated float nn.Tanh, installed
by lucid.quantization.convert / from_float. Under the sidecar
representation (design B) the quantized layer is the float tanh followed
by a fake-quantize to the calibrated output grid, so a standalone tanh inside
a quantized region is requantized rather than left at full precision.
Because the range is known a priori, making this
another fixed-qparams activation. Since the range is signed, the fixed
grid centres the zero-point in the middle of the quint8 codes so that both
the -1 and +1 extremes are representable.
so codes 0 .. 255 tile with the real value 0 landing
on code 128. .
Parameters
scaleTensorPer-tensor output scale — the fixed
2/256 under a
lucid.quantization.FixedQParamsObserver, else calibrated.
Supplied by from_float.zero_pointTensorPer-tensor output zero-point (
128 for the signed [-1, 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
[-1, 1]; pairing withlucid.quantization.FixedQParamsObserveravoids a calibration pass. - The non-zero zero-point (
128) is what lets a signed range live on the unsignedquint8grid without clipping either sign.
Examples
>>> import lucid, lucid.nn as nn
>>> qtanh = nn.quantized.Tanh(lucid.tensor(2 / 256), lucid.tensor(128.0))
>>> y = qtanh(lucid.randn(8))
>>> bool(((y >= -1) & (y <= 1)).all().item()) # bounded to [-1, 1]
TrueSee Also
- lucid.nn.quantized.Sigmoid—Bounded
[0, 1](unsigned fixed grid). - lucid.quantization.FixedQParamsObserver—Pins the grid for bounded outputs.
- lucid.quantization.convert—Installs this layer from a calibrated model.