Skip to content
class

LazyConvTranspose2d

extends_LazyConvMixinConvTranspose2d
LazyConvTranspose2d(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, padding_mode: str = 'zeros', 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_channelsint
Number of output channels.
kernel_sizeint or tuple[int, int]
Size of the 2D convolving kernel.
strideint or tuple[int, int]= 1
Stride (upsampling factor). Default: 1.
paddingint or tuple[int, int]= 0
dilation * (kernel_size - 1) - padding zero-padding applied on each side. String padding is not supported. Default: 0.
output_paddingint or tuple[int, int]= 0
Additional size added to one side of each output dimension. Default: 0.
groupsint= 1
Number of blocked connections. Default: 1.
biasbool= True
If True, a learnable bias is added after materialization. Default: True.
dilationint or tuple[int, int]= 1
Spacing between kernel elements. Default: 1.
padding_modestr= 'zeros'
"zeros", the only mode; another raises ValueError.
deviceDeviceLike= None
Device used when allocating weights. Default: None.
dtypeDTypeLike= None
Data type used when allocating weights. Default: None.

Attributes

weightParameter or None
None before materialization; shape (in_channels, out_channels // groups, K_H, K_W) afterwards.
biasParameter or None
None before materialization; (out_channels,) if bias=True.
in_channelsint or None
None before the first forward pass.

Notes

Input: (N,Cin,H,W)(N, C_{\text{in}}, H, W) — CinC_{\text{in}} is inferred automatically. Output: (N,Cout,Hout,Wout)(N, C_{\text{out}}, H_{\text{out}}, W_{\text{out}}) — 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)
64

Used by 1

Constructors

1
dunder

__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, padding_mode: str = 'zeros', device: DeviceLike = None, dtype: DTypeLike = None)

Initialise the LazyConvTranspose2d module. See the class docstring for parameter semantics.

Instance methods

4
fn

extra_repr

→strfrom _LazyConvMixin
extra_repr()

Return a string representation of the layer's configuration.

fn

forward

→Tensor
forward(input: Tensor, output_size: Sequence[int] | None = None)

The eager layer's forward; the first call sizes in_channels from input.

fn

initialize_parameters

→Nonefrom _LazyConvMixin
initialize_parameters(input: Tensor, args: object = (), kwargs: object = {})

Size in_channels from input and allocate the weights, if not sized yet.

Takes the extra positional and keyword arguments the reference's lazy convolutions accept, and ignores them, as it does.

Parameters

inputTensor
An input of the shape the layer will see.
*argsobject= ()
Accepted for signature parity; unused.
**kwargsobject= ()
Accepted for signature parity; unused.
fn

reset_parameters

→Nonefrom _LazyConvMixin
reset_parameters()

Re-draw the values; nothing to do until the layer has been sized.