| ggml_layer_permute | R Documentation |
Reorder a sample's axes. The batch axis is not part of dims and is
never moved – dims indexes the per-sample shape, exactly as
input_shape does.
ggml_layer_permute(
model,
dims,
input_shape = NULL,
name = NULL,
trainable = TRUE
)
model |
A ggml_sequential_model object, or a |
dims |
Integer vector, a permutation of |
input_shape |
Input shape, required for the first layer only. |
name |
Optional character name for the layer. |
trainable |
Logical; reserved for API consistency (no weights). |
The model object with the permute layer appended (invisibly), or a
ggml_tensor_node in the functional API.
dims follows base R's aperm: dims[i] names
the source axis that ends up at position i. So
dims = c(2, 1) means "the new first axis is the old second one".
This is deliberately the inverse of the underlying
ggml_permute, whose arguments are destination
positions; the layer converts between the two so that callers can think in
the R idiom. Read ggml_permute itself as "source axis i goes
to position p_i" – mixing the two conventions up silently inverts
every non-trivial permutation.
Reordering a sample's axes to match what the next layer reads: a
c(features, seq_len) tensor into the c(seq_len, features) that
attention and the recurrent layers expect, or the reverse.
Note that ggml_layer_embedding does not need this –
it already reports c(seq_len, dim) and feeds attention, GRU and LSTM
directly. Adding a permute there transposes the underlying tensor and breaks
the graph.
ggml_permute for the low-level op and its
destination-position convention.
# Swap a c(features, seq_len) sample into c(seq_len, features).
model <- ggml_model_sequential() |>
ggml_layer_permute(c(2, 1), input_shape = c(32, 16))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.