Skip to content
class

ELU

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

Quantized lucid.nn.ELU — elu(x, alpha) then output fake-quant.

The inference-time replacement for a calibrated float nn.ELU, installed by lucid.quantization.convert / from_float. Under the sidecar representation (design B) the quantized layer is the float ELU followed by a fake-quantize to the calibrated output grid. Unlike the bounded activations, ELU is unbounded above and saturates to −α-\alpha below, so its range is data-dependent and must be calibrated with a real observer rather than a lucid.quantization.FixedQParamsObserver.

The negative-branch scale α\alpha is a parameter of the activation, not a learned weight; from_float copies it from the source nn.ELU (via the internal _configure hook) so the quantized layer reproduces the exact float curve before snapping the output to the grid.

y=fake_quant⁡(elu⁡(x)),elu⁡(x)={xx>0α (ex−1)x≤0y = \operatorname{fake\_quant}\bigl(\operatorname{elu}(x)\bigr), \qquad \operatorname{elu}(x) = \begin{cases} x & x > 0 \\ \alpha\,(e^{x} - 1) & x \le 0 \end{cases}

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 the calibrated output (scale, zero_point) S,ZS, Z.

Parameters

scaleTensor
Per-tensor output scale from the calibrating observer. Supplied by from_float; construct directly only with qparams in hand.
zero_pointTensor
Per-tensor output zero-point from the calibrating observer.
qdtypeQDtype= quint8
Quantized dtype bounding the grid. Defaults to lucid.quantization.quint8 ([0, 255]).

Attributes

alphafloat
The negative-branch scale α\alpha in α (ex−1)\alpha\,(e^{x} - 1), copied from the source nn.ELU by from_float. Defaults to 1.0 on a bare instance.

Notes

  • Built via convert / from_float, which reads the output observer and copies alpha from the float module.
  • Range is data-dependent (unbounded above), so calibrate through the prepared model before convert; a fixed grid would clip the upper tail.
  • The forward is float elu(x, alpha) → fake-quant; only the output is snapped to the grid.

Examples

>>> import lucid, lucid.nn as nn
>>> import lucid.quantization as Q
>>> model = nn.Sequential(nn.ELU(alpha=1.5))
>>> model.qconfig = Q.get_default_qconfig()
>>> prepared = Q.prepare(model)               # attach the output observer
>>> _ = prepared(lucid.randn(32, 8))          # calibrate its range
>>> qelu = Q.convert(prepared)[0]             # from_float reads the observer
>>> type(qelu).__name__, qelu.alpha
('ELU', 1.5)

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.