| nn_build_conv_1d | R Documentation |
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.
nn_build_conv_1d(ctx, input_tensor, layer)
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.
A ggml_tensor [OC, OL, N] holding the 1-D convolution
output (with bias and activation applied).
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.