Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

PyTorch · Class

nn.Conv1d

nn.Conv1d applies learnable one-dimensional filters to multi-channel signals. It converts C_in input channels into C_out output channels while stride, padding, dilation, and groups control how the filters scan and connect.

How it works

Conv1d slides learnable one-dimensional filters across the last dimension of an input with one or optionally two leading dimensions. It produces the requested number of output channels, while stride, padding, dilation, and groups control sampling, boundary extension, receptive-field spacing, and channel connectivity.

Syntax

class torch.nn.modules.conv.Conv1d(in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, groups=1, bias=True, padding_mode='zeros', device=None, dtype=None)

Parameters

NameTypeDescription
in_channelsintNumber of channels in the input image.
out_channelsintNumber of channels produced by the convolution.
kernel_sizeint or tupleSize of the convolving kernel.
strideint or tupleStride of the convolution; default 1.
paddingint, tuple, or strPadding added to both sides of the input; default 0.
dilationint or tupleSpacing between kernel elements; default 1.
groupsintNumber of blocked connections from input channels to output channels; default 1.
biasboolWhether to add a learnable output bias; default True.
padding_modestrPadding mode: zeros, reflect, replicate, or circular; default zeros.
devicetorch.device or NoneOptional device for created parameters.
dtypetorch.dtype or NoneOptional data type for created parameters.

Returns

A tensor with shape (N, C_out, L_out) for batched input or (C_out, L_out) for unbatched input.

Key points

  • The module learns filters that operate along one-dimensional signals with multiple channels.
  • out_channels determines how many channels appear in the result.
  • dilation inserts spacing between neighboring filter elements, enlarging the receptive field.
  • groups controls channel connectivity, enabling grouped or depthwise-style configurations.
  • bias=True adds a trainable per-output-channel offset; disabling it removes that offset.

Common mistakes

  • When using grouped convolution, choose a groups value that divides both channel counts.
  • The default padding mode uses zero values; select another documented mode when boundary behavior requires it.

Example: Basic Conv1d usage

import torch
from torch import nn

layer = nn.Conv1d(in_channels=2, out_channels=4, kernel_size=3, padding=1)
x = torch.randn(5, 2, 16)
y = layer(x)
print(y.shape)  # torch.Size([5, 4, 16])

Creates a one-dimensional convolution that maps two input channels to four output channels while preserving length through padding.

When to use it

Extract local temporal patterns from waveform and time-series channels.

Audio or sensor streams

Build convolutional encoders for fixed-width local patterns in sequences.

Sequence feature extraction

Reduce cross-channel connections with grouped convolution.

Grouped channel processing

Interview questions

QWhat does nn.Conv1d do, and what are its input and output shapes?

Conv1d applies a one-dimensional convolution over an input signal. Its input can have shape (N, C_in, L_in) or (C_in, L_in), and the output has the corresponding channel count C_out.

Follow-up: How do groups change connectivity? They partition input and output channels into independent connection groups, and both channel counts must be divisible by groups.

QExplain the main spatial parameters of Conv1d.

in_channels is the number of input channels, out_channels is the number produced, and kernel_size specifies the filter width. Stride, padding, and dilation respectively control movement, boundary padding, and spacing between kernel elements.

Follow-up: What is the effect of increasing dilation while holding kernel size fixed? It expands the filter's receptive field by spacing its kernel elements farther apart.

QWhat does the bias argument control?

The layer adds a learnable bias by default because bias=True. Setting bias=False omits that additive parameter, which can be useful when another component supplies the offset.

Follow-up: Which padding modes are documented? The supported choices are zeros, reflect, replicate, and circular.

  • torch.nn.Conv1d
  • torch.nn.Conv2d
  • torch.nn.Conv3d
  • torch.nn.ConvTranspose1d
  • torch.nn.functional.conv1d

Source: Conv1d. Checked 2026-10-16.