Skip to content
class

ConvTranspose1d

extends_QuantizedConvTransposeNd
ConvTranspose1d(in_channels: int, out_channels: int, kernel_size: _IntTuple, stride: _IntTuple, padding: _IntTuple, output_padding: _IntTuple, dilation: _IntTuple, groups: int, bias: bool)

Implementing kernel

C++ engine symbols that back this Python API.

Quantized 1-D transposed (fractionally-strided) convolution.

The int8-weight, dequantize-to-float replacement that lucid.quantization.convert installs for a calibrated float lucid.nn.ConvTranspose1d. Transposed convolutions upsample — they are the decoder / generator counterpart of lucid.nn.quantized.Conv1d in 1-D signal models — and share the exact sidecar recipe of the quantized lucid.nn.quantized.Conv2d family.

Representation (sidecar design B). The learned float kernel is quantized once, at from_float time, into an int8 code tensor plus a per-output-channel scale / zero_point; the float kernel is then dropped. Only the int8 codes, the qparams, and the (still-float) bias live in the module. Each forward dequantizes the kernel back to float, runs the ordinary F.conv_transpose1d, and finally fake-quantizes the output onto the activation grid that calibration observed. Keeping the transposed convolution itself in float means the result matches a genuine int8 kernel to within a rounding step and the layer runs unchanged on any device.

Per-channel weights (axis 1). The transposed-weight layout (in_channels, out_channels/groups, k) places the output channels on axis 1, not axis 0, so the kernel is quantized per-channel along axis 1 — each output channel gets its own scale, far tighter than one per-tensor scale for wide kernels. The scheme is symmetric (qint8, zero_point = 0), matching the reference default for transposed weights; the bias stays float.

Encoding happens once (at from_float); decode + transposed-convolve run on every forward:

wc,o,kq=clamp⁡ ⁣(round⁡(wc,o,k/so), −128, 127),w^c,o,k=wc,o,kq sow^{q}_{c,o,k} = \operatorname{clamp}\!\bigl( \operatorname{round}(w_{c,o,k}/s_o),\ -128,\ 127\bigr), \qquad \hat{w}_{c,o,k} = w^{q}_{c,o,k}\, s_o y=fake_quant⁡ ⁣(convT1d⁡(x,w^)+b),fake_quant⁡(t)=(clamp⁡(round⁡(t/S)+Z, qmin⁡, qmax⁡)−Z) Sy = \operatorname{fake\_quant}\!\bigl( \operatorname{convT1d}(x, \hat{w}) + b\bigr), \qquad \operatorname{fake\_quant}(t) = \bigl( \operatorname{clamp}(\operatorname{round}(t/S) + Z,\ q_{\min},\ q_{\max}) - Z\bigr)\, S

where sos_o is the per-output-channel (axis-1) weight scale — with a zero zero-point because the weight scheme is symmetric — and S,ZS, Z the scalar calibrated output (scale, zero_point) with grid bounds qmin⁡,qmax⁡q_{\min}, q_{\max} (0, 255 for the default quint8).

Parameters

in_channelsint
Number of channels in the input signal.
out_channelsint
Number of channels produced by the transposed convolution — quantized per-channel (on axis 1 of the transposed weight).
kernel_sizeint or tuple of int
Size of the convolving kernel.
strideint or tuple of int
Stride of the transposed convolution (the upsampling factor).
paddingint or tuple of int
Implicit zero-padding subtracted from both sides of the spatial axis.
output_paddingint or tuple of int
Extra size added to one side of the output to disambiguate its shape.
dilationint or tuple of int
Spacing between kernel elements.
groupsint
Number of blocked connections from input to output channels.
biasbool
Whether a learned float bias term is added after the convolution.

Attributes

weight_int8Tensor
The int8 kernel codes, shape (in_channels, out_channels/groups, k).
weight_scaleTensor
Per-output-channel weight scale, shape (out_channels/groups,).
weight_zero_pointTensor
Per-output-channel weight zero-point, shape (out_channels/groups,) — all zero under the symmetric scheme.
scaleTensor
Scalar output-activation scale, set from the calibrated observer.
zero_pointTensor
Scalar output-activation zero-point, set from the calibrated observer.
biasTensor or None
The float bias of shape (out_channels,), or None.

Notes

  • Instances are normally produced by lucid.quantization.convert (or from_float), not constructed directly: a freshly constructed layer has identity qparams (scale = 1, zero_point = 0) and zeroed kernel codes, and only becomes meaningful once from_float / load_state_dict fills the buffers.
  • Only int8 codes + qparams + float bias enter the state_dict; the float kernel never does — the weight payload shrinks ~3.55x (int8), and a whole conv-heavy checkpoint ~3.97x (measured on resnet_18).
  • The kernel is quantized per-channel on axis 1 (the output-channel axis of the (in, out/groups, k) layout) with a symmetric qint8 scheme (from_float runs a fresh PerChannelMinMaxObserver over the weight); the bias stays float.
  • This layer wins on memory, not compute — the transposed convolution runs in float (CPU stream = Accelerate, GPU stream = MLX), so its speed tracks the float layer's; the payoff is the smaller checkpoint and working set.
  • Device-transparent: because compute stays in float, the layer runs unchanged on CPU or Metal and follows the input tensor's device.
  • Calibration is required — the output (scale, zero_point) come from an activation observer that must see representative data between prepare and convert; an uncalibrated observer keeps its ±inf seed, collapsing the output toward zero (from_float warns).
  • Only integer / tuple padding is supported; string padding raises NotImplementedError at from_float.

Examples

>>> import lucid, lucid.nn as nn
>>> import lucid.quantization as Q
>>> model = nn.Sequential(nn.ConvTranspose1d(8, 4, 3))
>>> model.qconfig = Q.get_default_qconfig()
>>> prepared = Q.prepare(model)             # insert activation/weight observers
>>> _ = prepared(lucid.randn(2, 8, 16))     # calibrate on representative data
>>> qmodel = Q.convert(prepared)            # float -> quantized ConvTranspose1d
>>> type(qmodel[0]).__name__
'ConvTranspose1d'
>>> qmodel(lucid.randn(2, 8, 16)).shape     # int8-weight upsampling
(2, 4, 18)
Constructing the layer directly is **not** a substitute for that workflow — a
bare instance carries zeroed codes and identity qparams, so it returns garbage
until from_float / load_state_dict populates the buffers:
>>> broken = nn.quantized.ConvTranspose1d(
...     8, 4, (3,), (1,), (0,), (0,), (1,), 1, True
... )
>>> bool((broken.weight_int8 == 0).all().item())
True

See Also

Used by 1

Class methods

1
cls

from_float

→Selffrom _QuantizedConvTransposeNd
from_float(mod: nn.Module)

Quantize a calibrated float transposed conv (per-channel int8 weight).

Instance methods

2
fn

extra_repr

→strfrom _QuantizedConvTransposeNd
extra_repr()

Override to add extra repr info (e.g. Linear shows in_features, etc.).

fn

forward

→Tensorfrom _QuantizedConvTransposeNd
forward(input: Tensor)

Dequantize the kernel, transposed-convolve, fake-quantize the output.