LazyConvTranspose2d
ConvTranspose2dLazyConvTranspose2d(out_channels: int, kernel_size: _Size2d, stride: _Size2d = 1, padding: _Size2d = 0, output_padding: _Size2d = 0, groups: int = 1, bias: bool = True, dilation: _Size2d = 1, device: DeviceLike = None, dtype: DTypeLike = None)A ConvTranspose2d that infers in_channels from the first input.
Lazy version of the 2D transposed convolution. Weight allocation is
deferred until the first forward call, making it easy to
compose upsampling decoder networks without manually tracking the
channel dimension through each block.
Parameters
out_channelsintkernel_sizeint or tuple[int, int]strideint or tuple[int, int]= 11.paddingint or tuple[int, int]= 0dilation * (kernel_size - 1) - padding zero-padding applied
on each side. String padding is not supported. Default: 0.output_paddingint or tuple[int, int]= 00.groupsint= 11.biasbool= TrueTrue, a learnable bias is added after materialization.
Default: True.dilationint or tuple[int, int]= 11.deviceDeviceLike= NoneNone.dtypeDTypeLike= NoneNone.Attributes
Notes
Input:
— is
inferred automatically.
Output:
—
same formula as ConvTranspose2d.
State-dict loading. A 4-D weight tensor (shape
(in_channels, out_channels // groups, K_H, K_W)) triggers
materialization before parameter copying.
Symmetric encoder–decoder pairs. Pair each LazyConv2d
encoder stride with a LazyConvTranspose2d of matching
kernel_size, stride, and padding to reconstruct exact
spatial dimensions.
Examples
Lazy VAE decoder:
>>> import lucid
>>> import lucid.nn as nn
>>> decoder = nn.LazyConvTranspose2d(
... out_channels=64, kernel_size=4, stride=2, padding=1
... )
>>> z = lucid.zeros(4, 128, 8, 8) # in_channels=128 inferred
>>> y = decoder(z)
>>> y.shape
(4, 64, 16, 16)
Verify inference:
>>> import lucid
>>> import lucid.nn as nn
>>> lazy = nn.LazyConvTranspose2d(out_channels=32, kernel_size=3)
>>> _ = lazy(lucid.zeros(1, 64, 4, 4))
>>> print(lazy.in_channels)
64Used by 1
Constructors
1__init__
→None__init__(out_channels: int, kernel_size: _Size2d, stride: _Size2d = 1, padding: _Size2d = 0, output_padding: _Size2d = 0, groups: int = 1, bias: bool = True, dilation: _Size2d = 1, device: DeviceLike = None, dtype: DTypeLike = None)Initialise the LazyConvTranspose2d module. See the class docstring for parameter semantics.
Instance methods
2Return a string representation of the layer's configuration.