Skip to content
class

ConvReLU3d

extendsConv3d
ConvReLU3d(in_channels: int, out_channels: int, kernel_size: _IntTuple, stride: _IntTuple, padding: _IntTuple, dilation: _IntTuple, groups: int, bias: bool)

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

A fused (intrinsic) block for volumetric / video models: the quantized counterpart of the float nn.intrinsic.ConvReLU3d, installed by lucid.quantization.convert / from_float. It behaves exactly like lucid.nn.quantized.Conv3d — int8 per-output-channel kernel, float convolution, output fake-quantized to the calibrated grid — but folds a ReLU into the layer so conv + activation share one quantized output. The 3-D kernel makes int8 storage especially valuable here, since a volumetric filter (out, in/groups, kd, kh, kw) is large.

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⁡(conv3d⁡(x,w^)+b)),w^o,c,d,i,j=(wo,c,d,i,jq−zo) soy = \operatorname{fake\_quant}\!\bigl( \operatorname{relu}(\operatorname{conv3d}(x, \hat{w}) + b)\bigr), \qquad \hat{w}_{o,c,d,i,j} = (w^{q}_{o,c,d,i,j} - 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 volume.
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 each spatial dim.
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, kd, kh, kw).
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.Conv3d 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.ConvReLU3d(2, 4, 3, 1, 1, 1, 1, True)   # via convert()
>>> q(lucid.randn(1, 2, 8, 8, 8)).shape
(1, 4, 8, 8, 8)
>>> bool((q.weight_int8 == 0).all().item())      # zeroed until from_float
True

See Also

Used by 1

Class methods

1
cls

from_float

→ConvReLU3d
from_float(mod: nn.Module)

Quantize a calibrated float convolution module.