Skip to Content
OchreML
Layers & Activations

Conv2d

2D Convolution over NCHW tensors backed by N10 im2col/col2im and GEMM without cuDNN.

ochreml.nn.Conv2d computes 2D spatial convolution over NCHW tensors (batch, in_channels, height, width) using OchreML's N10 (im2col / col2im) and E1/E2 GEMM primitives — requiring zero cuDNN dependencies.

Import & Signature

import ochreml.nn as nn

conv = nn.Conv2d(
    in_channels,
    out_channels,
    kernel_size,
    stride=1,
    padding=0,
    dilation=1,
    groups=1,
    bias=True,
    dtype="float32",
    device=None,
    seed=42,
)

Parameters

ParameterTypeDefaultDescription
in_channelsintrequiredNumber of input channels.
out_channelsintrequiredNumber of output channels (filters).
kernel_sizeint | tuple[int, int]requiredSpatial kernel height and width.
strideint | tuple[int, int]1Convolution stride (sH, sW).
paddingint | tuple[int, int]0Zero-padding added to both spatial sides (pH, pW).
dilationint | tuple[int, int]1Spacing between kernel elements (dH, dW).
groupsint1Number of blocked connections from input to output channels.
biasboolTrueIf True, adds a learnable bias per output channel.
dtypestr"float32""float32", "bfloat16", or "float16".
devicestr | NoneNoneTarget device.
seedint42Deterministic initialization seed.

Usage Example

import ochreml.nn as nn

conv = nn.Conv2d(3, 16, kernel_size=3, stride=1, padding=1)
x = nn.Tensor.randn([4, 3, 32, 32])
out = conv(x)  # shape: (4, 16, 32, 32)

On this page