Skip to content
fn

conv1d

→Tensor
conv1d(input: Tensor, weight: Tensor, bias: Tensor | None = None, stride: int | tuple[int, ...] = 1, padding: str | int | tuple[int, ...] = 0, dilation: int | tuple[int, ...] = 1, groups: int = 1)

Implementing kernel

C++ engine symbols that back this Python API.

1-D cross-correlation over a 3-D (or unbatched 2-D) input.

Slides a learned filter along a single spatial axis. As with every major deep-learning framework, the operation is technically cross-correlation rather than strict mathematical convolution (no kernel flip), but the "conv" name is kept for familiarity. Channel mixing happens through the in_channels dimension of weight.

Parameters

inputTensor
Input of shape (N, C_in, L), or (C_in, L) unbatched.
weightTensor
Filters of shape (C_out, C_in/groups, kL).
biasTensor= None
Per-output-channel bias of shape (C_out,).
strideint or tuple of int= 1
Step between adjacent kernel positions (default 1).
paddingint, tuple of int, or {'valid', 'same'}= 0
Zero padding applied to both sides of the spatial axis. "valid" is no padding; "same" pads so the output is as long as the input, which needs stride=1 — an odd total puts the extra element at the end.
dilationint or tuple of int= 1
Spacing between kernel taps (atrous convolution). Default 1.
groupsint= 1
Split the channel dimension into groups independent groups.

Returns

Tensor

Output of shape (N, C_out, L_out) where

Lout=⌊L+2p−d(k−1)−1s+1⌋L_{\text{out}} = \left\lfloor \frac{L + 2p - d(k - 1) - 1}{s} + 1 \right\rfloor

Notes

Math:

yi, co, l=bco+∑ci,mwco, ci, m⋅xi, ci, sl+dmy_{i,\,c_o,\,l} = b_{c_o} + \sum_{c_i, m} w_{c_o,\,c_i,\,m} \cdot x_{i,\,c_i,\,s l + d m}

Backward is registered automatically; gradients flow to input, weight, and bias. Set groups == C_in and C_out == C_in for a depthwise convolution. Using dilation > 1 enlarges the receptive field without increasing parameter count — common in speech / audio models (WaveNet) and 1-D temporal CNNs.

Examples

>>> import lucid
>>> from lucid.nn.functional import conv1d
>>> x = lucid.randn(2, 4, 50)
>>> w = lucid.randn(8, 4, 3)
>>> y = conv1d(x, w, padding=1)
>>> y.shape
(2, 8, 50)

Used by 1