nn_build_conv_1d: Build conv_1d forward pass

View source: R/nn_layers.R

nn_build_conv_1dR Documentation

Build conv_1d forward pass

Description

The sequential API lays a 3-D input out as [size, seq, N] – the channel on ne[0] – which is what LSTM/GRU and batch_norm expect. The convolution wants the opposite: data as [L, IC, N] against a [K, IC, OC] kernel. So the input is transposed on the way in and the result transposed back, keeping the layer's contract with its neighbours unchanged.

Usage

nn_build_conv_1d(ctx, input_tensor, layer)

Details

The convolution is assembled here rather than via ggml_conv_1d(), which hard-codes an F16 im2col and therefore needs an F16 kernel. Casting the kernel makes the forward pass work but breaks training: the gradient w.r.t. the kernel is an OUT_PROD whose first operand is then F16, and the CPU backend only implements OUT_PROD for F32 and quantized inputs, so the scheduler finds no backend for that node. Building the same im2col + mul_mat in F32 – which is what ggml_conv_2d() does, passing the kernel's own type – keeps the whole path differentiable.

Value

A ggml_tensor [OC, OL, N] holding the 1-D convolution output (with bias and activation applied).


ggmlR documentation built on Oct. 23, 2026, 1:07 a.m.