Skip to content
class

ConvReLU1d

extendsConv1d
ConvReLU1d(in_channels: int, out_channels: int, kernel_size: _IntTuple, stride: _IntTuple, padding: _IntTuple, dilation: _IntTuple, groups: int, bias: bool)

Quantized 1-D convolution with a fused ReLU — int8 kernel, float compute.

A fused (intrinsic) block: the quantized counterpart of the float nn.intrinsic.ConvReLU1d, installed by lucid.quantization.convert / from_float. It behaves exactly like lucid.nn.quantized.Conv1d — int8 per-output-channel kernel, float convolution, output fake-quantized to the calibrated grid — but folds a ReLU into the layer so the conv and its activation share one quantized output.

Why fuse. During calibration the fused module's activation observer sat after the ReLU, so it recorded the post-ReLU (non-negative) range. To reproduce those numerics at inference the ReLU must run before the output fake-quant — the job of the overridden _activation hook. Requantizing the conv → relu pair once, against the tighter non-negative range, uses the int8 grid more efficiently than quantizing the raw conv output then clamping.

Encoding (int8 kernel) happens once at from_float; decode + convolve + fused ReLU + requantize run on every forward:

y=fake_quant⁡ ⁣(relu⁡(conv1d⁡(x,w^)+b)),w^o,c,k=(wo,c,kq−zo) soy = \operatorname{fake\_quant}\!\bigl( \operatorname{relu}(\operatorname{conv1d}(x, \hat{w}) + b)\bigr), \qquad \hat{w}_{o,c,k} = (w^{q}_{o,c,k} - z_o)\, s_o

where so,zos_o, z_o are the per-output-channel kernel scale / zero-point and the outer fake-quant snaps the post-ReLU result to the scalar calibrated output (scale, zero_point).

Parameters

in_channelsint
Number of channels in the input signal.
out_channelsint
Number of channels produced by the convolution — quantized per-channel.
kernel_sizeint or tuple of int
Size of the convolving kernel.
strideint or tuple of int
Stride of the convolution.
paddingint or tuple of int
Implicit zero-padding added to both sides of the spatial axis.
dilationint or tuple of int
Spacing between kernel elements.
groupsint
Number of blocked connections from input to output channels.
biasbool
Whether a (float) bias term is added before the fused ReLU.

Attributes

weight_int8Tensor
The int8 kernel codes, shape (out_channels, in_channels/groups, k).
weight_scaleTensor
Per-output-channel kernel scale, shape (out_channels,).
weight_zero_pointTensor
Per-output-channel kernel zero-point, shape (out_channels,).
scale, zero_pointTensor
Scalar output-activation qparams (post-ReLU), from the calibrated observer.
biasTensor or None
The float bias of shape (out_channels,), or None.

Notes

  • Produced by convert / from_float, not constructed directly; the constructor is inherited unchanged from lucid.nn.quantized.Conv1d and only the _activation hook differs.
  • from_float accepts a float fused nn.Sequential ([0] is the conv) or a single-layer QAT fused module; the shared wiring copies the fused qconfig / observer onto the weighted child before quantizing.
  • Output is non-negative (ReLU precedes the fake-quant) — calibrate the fused module so the observed grid matches inference.

Examples

>>> import lucid, lucid.nn as nn
>>> q = nn.quantized.ConvReLU1d(4, 8, 3, 1, 1, 1, 1, True)   # via convert()
>>> q(lucid.randn(1, 4, 16)).shape
(1, 8, 16)
>>> bool((q.weight_int8 == 0).all().item())      # zeroed until from_float
True

See Also

Used by 1

Class methods

1
cls

from_float

→ConvReLU1d
from_float(mod: nn.Module)

Quantize a calibrated float convolution module.