# \donttest{
# One attention block shared between two sequences.
attn <- ggml_attention(d_model = 32L, n_heads = 4L)
x1 <- ggml_input(shape = c(10L, 32L))
x2 <- ggml_input(shape = c(10L, 32L))
o1 <- ggml_apply(x1, attn)
o2 <- ggml_apply(x2, attn) # shared weights
stopifnot(identical(o1$layer_id, o2$layer_id))
# Cross-attention: queries from x1, keys/values from a longer context.
ctx <- ggml_input(shape = c(15L, 32L))
o3 <- ggml_apply(list(x1, ctx), ggml_attention(32L, 4L))
# }
Run the code above in your browser using DataLab