nn_stack_time_steps: Stack a recurrent layer's per-step outputs into a sequence...

View source: R/nn_layers.R

nn_stack_time_stepsR Documentation

Stack a recurrent layer's per-step outputs into a sequence tensor

Description

Shared by the LSTM and GRU builds for return_sequences = TRUE.

Usage

nn_stack_time_steps(ctx, h_steps, units, batch_size)

Arguments

ctx

ggml compute context.

h_steps

List of per-step tensors, each [units, N].

units

Integer, the hidden width.

batch_size

Integer, N.

Details

Each step is [units, N], and the result has to be [units, seq_len, N] – the layout every sequence consumer expects. Concatenating the steps directly along dim 1 does not give that: it produces [units, seq_len * N], folding the batch into the sequence axis. Nothing complains at build time, and a consumer that only reads ne[0] (attention) still works, so the mistake surfaces far away – sequence_pooling reduces the wrong axis and its ggml_reshape_2d() aborts the process on the element count.

Giving each step an explicit unit sequence axis first ([units, 1, N]) makes the concatenation grow that axis instead, which is the intended result.

Value

A tensor [units, seq_len, N].


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