Python class
Conv1D
Conv1D
class max.nn.Conv1D(kernel_size, in_channels, out_channels, dtype, stride=1, padding=0, dilation=1, num_groups=1, device=None, has_bias=False, permute=False, name=None)
Bases: Module
A 1D convolution over an input signal composed of several input planes.
When called, Conv1D accepts a TensorValue of shape
(batch, length, in_channels) and returns a
TensorValue of shape (batch, new_length, out_channels). If permute=True, the input and output follow PyTorch
channel-first layout: (batch, in_channels, length) and (batch, out_channels, new_length).
conv = nn.Conv1D(
kernel_size=3,
in_channels=64,
out_channels=128,
dtype=DType.float32,
stride=1,
padding=0,
has_bias=False,
name="conv1d_weight",
device=DeviceRef.GPU(),
)Initializes the Conv1D layer with weights and optional bias.
-
Parameters:
-
- kernel_size (int) – Size of the convolving kernel (width dimension).
- in_channels (int) – Number of channels in the input signal.
- out_channels (int) – Number of channels produced by the convolution.
- dtype (DType) – The data type for both weights and bias.
- stride (int) – Stride of the convolution. Controls the step size when sliding the kernel. Default: 1
- padding (int | tuple[int, int]) – Padding added to the input sequence. Can be:
- int: symmetric padding applied to both sides (pad_left = pad_right = padding). Default: 0
- tuple[int, int]: asymmetric padding as (pad_left, pad_right) for causal convolutions.
- dilation (int) – Spacing between kernel elements. Controls the kernel dilation rate. Default: 1
- num_groups (int) – Number of blocked connections from input channels to output channels. Input channels and output channels are divided into groups. Default: 1
- device (DeviceRef | None) – The target device for computation. If None, defaults to CPU. Weights are initially stored on CPU and moved to target device during computation.
- name (str | None) – Base name for weights. If provided, weights are named
{name}.weightand{name}.bias(if bias is enabled). If None, uses “weight” and “bias”. - has_bias (bool) – If true, adds a learnable bias vector to the layer.
Defaults to
False. - permute (bool) – If true, permutes weights from PyTorch format to MAX format.
PyTorch order: (out_channels, in_channels / num_groups, kernel_size).
MAX API order: (kernel_size, in_channels / num_groups, out_channels).
Defaults to
False.
bias
The optional bias vector stored on CPU with shape (out_channels,).
Model init moves the bias to device if present.
device
The device where matrix operations are performed.
dilation
dilation: int
Controls the dilation rate.
filter
filter: Weight
The weight matrix stored on CPU with shape (kernel_size, in_channels / num_groups, out_channels).
Model init moves the weight to device.
num_groups
num_groups: int
Number of blocked connections from input channels to output channels.
padding
Controls the amount of padding applied to the input.
If int: symmetric padding applied to both sides (pad_left = pad_right = padding). If tuple[int, int]: asymmetric padding as (pad_left, pad_right).
permute
permute: bool = False
bool controls whether self.filter is permuted from PyTorch order to max order. PyTorch order is: (out_channels, in_channels / num_groups, kernel_size) Max API order: (kernel_size, in_channels / num_groups, out_channels).
stride
stride: int
Controls the stride for the cross-correlation.
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!