LazyConvTranspose1d
ConvTranspose1dLazyConvTranspose1d(out_channels: int, kernel_size: int, stride: int = 1, padding: int = 0, output_padding: int = 0, groups: int = 1, bias: bool = True, dilation: int = 1, device: DeviceLike = None, dtype: DTypeLike = None)A ConvTranspose1d that infers in_channels from the first input.
Combines the fractionally-strided upsampling of
ConvTranspose1d with lazy weight materialization.
in_channels need not be known at construction time; it is read
from x.shape[1] on the first forward call.
Parameters
out_channelsintkernel_sizeintstrideint= 11.paddingint= 0dilation * (kernel_size - 1) - padding zero-padding on each
side. String padding is not supported. Default: 0.output_paddingint= 00.groupsint= 11.biasbool= TrueTrue, a learnable bias is added after materialization.
Default: True.dilationint= 11.deviceDeviceLike= NoneNone.dtypeDTypeLike= NoneNone.Attributes
weightParameter or NoneNone before materialization; shape
(in_channels, out_channels // groups, kernel_size) afterwards.
Note: leading axis is in_channels, not out_channels.biasParameter or NoneNone before materialization; (out_channels,) if
bias=True.in_channelsint or NoneNone before the first forward pass.Notes
Input:
— is
inferred automatically.
Output:
— same formula as
ConvTranspose1d.
State-dict loading. A 3-D weight tensor in the
state_dict whose leading axis equals the inferred in_channels
triggers materialization before parameter copying.
Examples
Lazy transposed conv in a sequence decoder:
>>> import lucid
>>> import lucid.nn as nn
>>> decoder = nn.LazyConvTranspose1d(
... out_channels=16, kernel_size=4, stride=2, padding=1
... )
>>> x = lucid.zeros(2, 32, 10) # in_channels=32 inferred
>>> y = decoder(x)
>>> y.shape
(2, 16, 20)
Inspect pre- and post-materialization state:
>>> import lucid
>>> import lucid.nn as nn
>>> lazy = nn.LazyConvTranspose1d(out_channels=8, kernel_size=3, padding=1)
>>> print(lazy.in_channels)
None
>>> _ = lazy(lucid.zeros(1, 4, 16))
>>> print(lazy.in_channels)
4Methods (3)
__init__
→None__init__(out_channels: int, kernel_size: int, stride: int = 1, padding: int = 0, output_padding: int = 0, groups: int = 1, bias: bool = True, dilation: int = 1, device: DeviceLike = None, dtype: DTypeLike = None)Initialise the LazyConvTranspose1d module. See the class docstring for parameter semantics.
forward
→Tensorforward(x: Tensor)Apply the convolution to the input tensor.
Parameters
inputTensorReturns
TensorOutput tensor of shape with spatial dimensions determined by stride, padding, dilation, and kernel size.
extra_repr
→strextra_repr()Return a string representation of the layer's configuration.