ggml_rwkv_wkv6: RWKV-6 WKV Recurrence

View source: R/operations.R

ggml_rwkv_wkv6R Documentation

RWKV-6 WKV Recurrence

Description

The weighted key-value recurrence of RWKV-6: a linear-attention-style scan whose decay is per-token (td) on top of a per-channel bonus (tf). Runs in O(n_tokens) rather than the O(n_tokens^2) of ordinary attention, which is what makes RWKV a recurrent model at inference time.

Usage

ggml_rwkv_wkv6(ctx, k, v, r, tf, td, state)

Arguments

ctx

GGML context

k

Keys, [S, H, n_tokens]

v

Values, [S, H, n_tokens]

r

Receptance, [S, H, n_tokens]

tf

Per-channel decay bonus, [S, H]

td

Per-token decay, [S, H, n_tokens]

state

Initial state, S * S * H * n_seqs elements

Value

A tensor [S * H, n_tokens + S * n_seqs]

Shapes

With head size S, H heads, n_tokens tokens and n_seqs sequences: k, v, r and td are [S, H, n_tokens], tf is [S, H], and state holds S * S * H * n_seqs elements (typically [S * S * H, n_seqs]). All must be contiguous.

n_tokens counts the tokens of all sequences together, so it must be a multiple of n_seqs: the kernel derives the per-sequence length as n_tokens / n_seqs and restarts the state at each boundary.

Packed result

The result is [S * H, n_tokens + S * n_seqs]: the per-token outputs occupy the first n_tokens columns and the final state the remaining S * n_seqs. ggml_rwkv_output and ggml_rwkv_state view either half.

Inference only

GGML_OP_RWKV_WKV6 has no backward pass in ggml.

See Also

ggml_rwkv_wkv7, ggml_rwkv_output

Other state-space: ggml_gated_linear_attn(), ggml_gated_linear_attn_back(), ggml_rwkv_output(), ggml_rwkv_wkv6_back(), ggml_rwkv_wkv7(), ggml_rwkv_wkv7_back(), ggml_ssm_conv(), ggml_ssm_conv_back(), ggml_ssm_scan(), ggml_ssm_scan_back(), ggml_ssm_scan_output()


ggmlR documentation built on Oct. 23, 2026, 1:07 a.m.