Skip to content

conv1d

conv1d

Downsample1d

Downsample1d(dim)

Bases: Module

Strided 1D convolution halving the temporal length.

Source code in src/versatil/models/layers/convolution/conv1d.py
7
8
9
def __init__(self, dim):
    super().__init__()
    self.conv = nn.Conv1d(dim, dim, 3, 2, 1)

forward

forward(x)

Downsample (B, C, T) to (B, C, T/2).

Source code in src/versatil/models/layers/convolution/conv1d.py
def forward(self, x):
    """Downsample (B, C, T) to (B, C, T/2)."""
    return self.conv(x)

Upsample1d

Upsample1d(dim)

Bases: Module

Transposed 1D convolution doubling the temporal length.

Source code in src/versatil/models/layers/convolution/conv1d.py
def __init__(self, dim):
    super().__init__()
    self.conv = nn.ConvTranspose1d(dim, dim, 4, 2, 1)

forward

forward(x)

Upsample (B, C, T) to (B, C, 2T).

Source code in src/versatil/models/layers/convolution/conv1d.py
def forward(self, x):
    """Upsample (B, C, T) to (B, C, 2T)."""
    return self.conv(x)

Conv1dBlock

Conv1dBlock(input_channels, output_channels, kernel_size, num_groups=8)

Bases: Module

Conv1d followed by group normalization and Mish activation.

Source code in src/versatil/models/layers/convolution/conv1d.py
def __init__(self, input_channels, output_channels, kernel_size, num_groups=8):
    super().__init__()

    self.block = nn.Sequential(
        nn.Conv1d(
            input_channels, output_channels, kernel_size, padding=kernel_size // 2
        ),
        nn.GroupNorm(num_groups, output_channels),
        nn.Mish(),
    )

forward

forward(x)

Apply convolution, normalization, and activation to (B, C, T).

Source code in src/versatil/models/layers/convolution/conv1d.py
def forward(self, x):
    """Apply convolution, normalization, and activation to (B, C, T)."""
    return self.block(x)