flashinfer.gdn_paged.chunk_gated_delta_rule_paged

flashinfer.gdn_paged.chunk_gated_delta_rule_paged(q: Tensor, k: Tensor, v: Tensor, g: Tensor | None = None, beta: Tensor | None = None, scale: float | None = None, *, cu_seqlens: Tensor, state_pool: Tensor, page_indices: Tensor, page_indptr: Tensor, page_size: int, last_page_len: Tensor, use_qk_l2norm_in_kernel: bool = False, output: Tensor | None = None, gate_domain: Literal['linear', 'log'] = 'linear', use_gate_in_kernel: bool = False, A_log: Tensor | None = None, dt_bias: Tensor | None = None, beta_is_logit: bool = False, slots: GDNPagedPrefillSlots | None = None) → Tensor

Chunked GDN prefill that reads and writes a paged recurrent-state pool.

For every sequence b the call processes its new tokens q[cu_seqlens[b]:cu_seqlens[b + 1]], which are the last tokens of the sequence’s (num_pages_b - 1) * page_size + last_page_len[b] tokens (num_pages_b = page_indptr[b + 1] - page_indptr[b]). The tokens before them form its prefix. The call

  • reads the initial state from the page that holds the last prefix token (the zero state when the prefix is empty),

  • writes the state at every page boundary it crosses to that page, and

  • writes the final state to the last page.

Pages that end at or before the prefix are only read, so a full-page prefix shared with other sequences is never written. A prefix that ends inside a page continues that (private) page in place. Prefix lengths need not be multiples of the 64-token chunk.

Parameters:
Returns:

The output [total_seq_len, num_o_heads, head_size].

Return type:

torch.Tensor

Notes

A page written by one sequence must not be read or written by another sequence of the same call. The page table and lengths are caller preconditions; they are not validated against each other on the device.