Learn R Programming

ggmlR (version 0.6.1)

ggml_permute: Permute Tensor Dimensions (Graph)

Description

Permutes the tensor dimensions according to specified axes. CRITICAL for attention mechanisms in transformers.

Usage

ggml_permute(ctx, a, axis0, axis1, axis2, axis3)

Value

Permuted tensor

Arguments

ctx

GGML context

a

Input tensor

axis0

New position for axis 0

axis1

New position for axis 1

axis2

New position for axis 2

axis3

New position for axis 3

Examples

Run this code
# \donttest{
ctx <- ggml_init(16 * 1024 * 1024)
# Create 4D tensor: (2, 3, 4, 5)
t <- ggml_new_tensor_4d(ctx, GGML_TYPE_F32, 2, 3, 4, 5)
# Swap axes 0 and 1: result shape (3, 2, 4, 5)
t_perm <- ggml_permute(ctx, t, 1, 0, 2, 3)
ggml_free(ctx)
# }

Run the code above in your browser using DataLab