| ggml_flash_attn_back | R Documentation |
Backward pass for ggml_flash_attn_ext: given the gradient of
the attention output, produces the gradients of Q, K and V in one pass.
ggml_flash_attn_back(ctx, q, k, v, mask, d, scale)
ctx |
GGML context |
q |
Query tensor |
k |
Key tensor |
v |
Value tensor |
mask |
Attention mask |
d |
Gradient of the forward output, shape |
scale |
Softmax scale used in the forward pass (e.g. |
Upstream ggml ships this operation as a stub that aborts, left behind when
flash_attn was replaced by flash_attn_ext; ggmlR implements it
so attention can be trained through the fused op. It is also wired into the
graph autodiff, so ggml_build_backward_expand reaches it on its
own — calling this directly is only needed when building a backward graph
by hand.
The three gradients come back packed head to tail in one contiguous 1D
tensor: grad_q, then grad_k, then grad_v, each padded to
GGML_MEM_ALIGN. Take a view of the slice you need.
Not supported: max_bias (ALiBi), logit_softcap and attention
sinks. Q, K, V and d must be F32.
Tensor holding grad_q, grad_k and grad_v packed contiguously
ggml_flash_attn_ext for the forward pass.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.