# \donttest{
# A transformer encoder block: attention + residual, then a feed-forward
# sublayer + residual.
x <- ggml_input(shape = c(10L, 32L))
attn <- x |> ggml_layer_attention(d_model = 32L, n_heads = 4L)
h <- ggml_layer_add(list(x, attn))
ff <- h |> ggml_layer_dense(32L, activation = "relu")
out <- ggml_layer_add(list(h, ff))
# GPT-style causal self-attention.
dec <- x |> ggml_layer_attention(32L, n_heads = 4L, causal = TRUE)
# }
Run the code above in your browser using DataLab