Skip to content
class

LazyConvTranspose1d

extends_LazyConvMixinConvTranspose1d
LazyConvTranspose1d(out_channels: int, kernel_size: int | tuple[int], stride: int | tuple[int] = 1, padding: int | tuple[int] = 0, output_padding: int | tuple[int] = 0, groups: int = 1, bias: bool = True, dilation: int | tuple[int] = 1, padding_mode: str = 'zeros', 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_channelsint
Number of output channels after the transposed convolution.
kernel_sizeint
Length of the 1D convolving kernel.
strideint= 1
Stride (upsampling factor). Default: 1.
paddingint= 0
dilation * (kernel_size - 1) - padding zero-padding on each side. String padding is not supported. Default: 0.
output_paddingint= 0
Additional size added to one side of the output. Default: 0.
groupsint= 1
Number of blocked connections. Default: 1.
biasbool= True
If True, a learnable bias is added after materialization. Default: True.
dilationint= 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, kernel_size) afterwards. Note: leading axis is in_channels, not out_channels.
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,L)(N, C_{\text{in}}, L) — CinC_{\text{in}} is inferred automatically. Output: (N,Cout,Lout)(N, C_{\text{out}}, L_{\text{out}}) — 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)
4

Used by 1

Constructors

1
dunder

__init__

→None
__init__(out_channels: int, kernel_size: int | tuple[int], stride: int | tuple[int] = 1, padding: int | tuple[int] = 0, output_padding: int | tuple[int] = 0, groups: int = 1, bias: bool = True, dilation: int | tuple[int] = 1, padding_mode: str = 'zeros', device: DeviceLike = None, dtype: DTypeLike = None)

Initialise the LazyConvTranspose1d 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.