Skip to content
class

ConvReLU1d

extends_FusedModule
ConvReLU1d(conv: nn.Conv1d, relu: nn.ReLU)

Fused float Conv1d + ReLU marker — a plain-float lucid.nn.Sequential.

A thin lucid.nn.Sequential of [conv, relu] emitted by lucid.quantization.fuse_modules. It runs as plain float — it carries no observers and no fake-quant, and computing through it is identical to running the conv then the ReLU. Its whole purpose is structural: by packaging the two ops as one unit, it tells the quantization pipeline to place a single activation observer after the ReLU rather than between the conv and the ReLU.

Why fuse for quantization. If an observer sat on the raw conv output it would calibrate a symmetric range that includes values the ReLU is about to discard, wasting half the int8 codes on negatives that never reach inference. Observing the post-ReLU range instead lets the eventual quantized layer pick a grid over [0,max⁡][0, \max], roughly doubling resolution. Fusion also drops the intermediate float tensor between conv and ReLU, so the converted kernel does conv → ReLU → requantize in one step.

Where it sits. This marker is the hand-off point between float and quantized worlds. lucid.quantization.prepare_qat replaces it with a trainable lucid.nn.qat.ConvReLU1d (weight + post-ReLU fake-quant under an STE), and lucid.quantization.convert maps it — or the QAT layer it became — to a fused inference lucid.nn.quantized.ConvReLU1d.

As a plain-float module it simply computes, with ⋆\star the 1-D cross-correlation:

y=ReLU⁡(W⋆x+b)y = \operatorname{ReLU}(W \star x + b)

Downstream, once an observer is attached, that fused output is fake-quantized under a straight-through estimator — rounded in the forward pass, identity in the backward:

fake_quant⁡(t)=(clamp⁡(round⁡(t/s)+z, qmin⁡, qmax⁡)−z) s,∂ fake_quant⁡(t)∂t=1\operatorname{fake\_quant}(t) = \bigl( \operatorname{clamp}(\operatorname{round}(t / s) + z,\ q_{\min},\ q_{\max}) - z\bigr)\, s, \qquad \frac{\partial\, \operatorname{fake\_quant}(t)}{\partial t} = 1

Parameters

The 1-D convolution to run first; kept as the [0] child of the sequential.
The rectifier applied to the convolution output; the [1] child.

Notes

  • Structural tag only. It carries no quantization state — no weight_fake_quant, no activation_post_process. Those are attached later by lucid.quantization.prepare_qat (or by lucid.quantization.prepare for the post-training path).
  • Post-ReLU observer placement. The single reason to fuse is so the downstream activation observer sees the non-negative post-ReLU range.
  • Both directions are wired for you. lucid.quantization.fuse_modules emits this marker in; lucid.quantization.prepare_qat / lucid.quantization.convert map it out to the QAT / quantized fused layer.

Examples

>>> import lucid, lucid.nn as nn
>>> import lucid.quantization as Q
>>> import lucid.nn.intrinsic as nni
>>> m = nn.Sequential(nn.Conv1d(3, 8, 3, padding=1), nn.ReLU())
>>> fused = Q.fuse_modules(m, [["0", "1"]])
>>> isinstance(fused[0], nni.ConvReLU1d)     # [conv, relu] collapsed to one marker
True
>>> fused(lucid.randn(2, 3, 8)).shape         # runs as plain float
(2, 8, 8)

See Also

Used by 1

Constructors

1
dunder

__init__

→None
__init__(conv: nn.Conv1d, relu: nn.ReLU)