The recurrent core of a Mamba block: a linear state-space recurrence whose
transition is modulated per token by dt, B and C.
ids selects which state row each sequence continues from, so several
sequences can share one state buffer.
ggml_ssm_scan(ctx, s, x, dt, A, B, C, ids)A flat tensor: outputs followed by final states
GGML context
Initial states, [d_state, head_dim, n_head, n_seqs_total]
Inputs, [head_dim, n_head, n_seq_tokens, n_seqs]
Per-token timestep, [n_head, n_seq_tokens, n_seqs]
State decay, [1 or d_state, n_head]
Input projection, [d_state, n_group, n_seq_tokens, n_seqs]
Output projection, same shape as B
Sequence-to-state mapping, [n_seqs] I32, 0-based
With d_state the state width, head_dim the per-head channel
count, n_head heads, n_seq_tokens tokens and n_seqs
sequences:
s — [d_state, head_dim, n_head, n_seqs_total], contiguous
x — [head_dim, n_head, n_seq_tokens, n_seqs]
dt — [n_head, n_seq_tokens, n_seqs], contiguous
A — [1, n_head] (Mamba-2) or [d_state, n_head] (Mamba-1)
B, C — [d_state, n_group, n_seq_tokens, n_seqs], same shape
ids — [n_seqs], type GGML_TYPE_I32, 0-based
The result is a flat tensor holding the outputs followed by the final
states: ggml_nelements(x) output elements, then
d_state * head_dim * n_head * n_seqs state elements. Use
ggml_ssm_scan_output and ggml_ssm_scan_state to
view either half rather than computing the offsets by hand -- getting them
wrong silently reads the state as output.
GGML_OP_SSM_SCAN has no backward pass in ggml. A graph containing it
runs forward on CPU and Vulkan, but cannot be trained: ggml_fit() and
the autograd engine will not produce gradients for it.
ggml_ssm_scan_output, ggml_ssm_scan_state,
ggml_ssm_conv
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_back(),
ggml_ssm_scan_output()