Gradients of ggml_ssm_scan with respect to all six of its
differentiable inputs, given grad, the gradient of the loss with
respect to the scan's packed forward result.
ggml_ssm_scan_back(ctx, s, x, dt, A, B, C, ids, grad)A flat tensor holding the six gradients, concatenated
GGML context
Initial states, as passed to the forward scan
Inputs, as passed to the forward scan
Per-token timestep, as passed to the forward scan
State decay, as passed to the forward scan
Input projection, as passed to the forward scan
Output projection, as passed to the forward scan
Sequence-to-state mapping, as passed to the forward scan
Gradient w.r.t. the packed forward result
All six gradients come back in one flat tensor, in the same order the scan
takes its inputs: [d_s | d_x | d_dt | d_A | d_B | d_C]. ids is
integer and has no gradient. A single op returns a single tensor, and packing
them keeps the recurrence from being replayed once per input.
The forward pass does not keep its intermediate states, so this replays the recurrence before walking it back -- roughly twice the forward work, and no extra memory beyond one state buffer.
Training reaches this automatically through the backward graph. It is exported so the gradient can be checked directly against a numeric one.
ggml_ssm_scan
Other state-space:
ggml_gated_linear_attn(),
ggml_gated_linear_attn_back(),
ggml_rwkv_output(),
ggml_rwkv_wkv6(),
ggml_rwkv_wkv6_back(),
ggml_rwkv_wkv7(),
ggml_rwkv_wkv7_back(),
ggml_ssm_conv(),
ggml_ssm_conv_back(),
ggml_ssm_scan(),
ggml_ssm_scan_output()