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
| Parameter | Type | Default | Description |
|---|---|---|---|
in_channels | int | required | Number of input channels. |
out_channels | int | required | Number of output channels (filters). |
kernel_size | int | tuple[int, int] | required | Spatial kernel height and width. |
stride | int | tuple[int, int] | 1 | Convolution stride (sH, sW). |
padding | int | tuple[int, int] | 0 | Zero-padding added to both spatial sides (pH, pW). |
dilation | int | tuple[int, int] | 1 | Spacing between kernel elements (dH, dW). |
groups | int | 1 | Number of blocked connections from input to output channels. |
bias | bool | True | If True, adds a learnable bias per output channel. |
dtype | str | "float32" | "float32", "bfloat16", or "float16". |
device | str | None | None | Target device. |
seed | int | 42 | Deterministic 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)