flashinfer.cake_fused_qk_rope_append.cake_fused_qk_rmsnorm_rope_append_paged_kv_cache

flashinfer.cake_fused_qk_rope_append.cake_fused_qk_rmsnorm_rope_append_paged_kv_cache(qkv: Tensor, cos_sin: Tensor, seq_lens: Tensor, q_indptr: Tensor, page_indices: Tensor, key_cache: Tensor, value_cache: Tensor, *, num_q_heads: int, num_kv_heads: int, qk_norm_policy: int = 0, q_norm_weight: Tensor | None = None, k_norm_weight: Tensor | None = None, eps: float = 1e-06, out_q: Tensor | None = None, out_k: Tensor | None = None, out_v: Tensor | None = None, clear_unused_last_page_rows: bool = True, enable_pdl: bool = False) → Tensor

Fused Q/K RMSNorm + NeoX RoPE + BF16 Q output + paged K/V append in one launch.

Parameters:
  • qkv (torch.Tensor) – BF16 [T, (num_q_heads + 2 * num_kv_heads) * 128], packed Q | K | V.

  • cos_sin (torch.Tensor) – F32 [max_position, 128]; row p is cos(p, 0..63) | sin(p, 0..63).

  • seq_lens (torch.Tensor) – I32 [B] total sequence length of every request after this append.

  • q_indptr (torch.Tensor) – I32 [B + 1]; rows [q_indptr[b], q_indptr[b + 1]) belong to request b.

  • page_indices (torch.Tensor) – I32 [B, max_pages] dense physical page table (entries beyond a request’s pages are ignored).

  • key_cache (torch.Tensor) – BF16 NHD caches [num_pages, page_size, num_kv_heads, 128] (written in place).

  • value_cache (torch.Tensor) – BF16 NHD caches [num_pages, page_size, num_kv_heads, 128] (written in place).

  • num_q_heads (int) – Head configuration; (8, 1) and (64, 8) are supported.

  • num_kv_heads (int) – Head configuration; (8, 1) and (64, 8) are supported.

  • qk_norm_policy (int) – 0 no norm, 1 RoPE then RMSNorm, 2 RMSNorm then RoPE.

  • q_norm_weight (torch.Tensor, optional) – F32 [128] per-head RMSNorm weights (required unless qk_norm_policy == 0).

  • k_norm_weight (torch.Tensor, optional) – F32 [128] per-head RMSNorm weights (required unless qk_norm_policy == 0).

  • eps (float) – RMSNorm epsilon (default 1e-6).

  • out_q (torch.Tensor, optional) – BF16 [T, num_q_heads, 128] output buffer (allocated when None).

  • out_k (torch.Tensor, optional) – BF16 [T, num_kv_heads, 128]; when given, K / V are written there instead of the caches (the last-page clear still runs).

  • out_v (torch.Tensor, optional) – BF16 [T, num_kv_heads, 128]; when given, K / V are written there instead of the caches (the last-page clear still runs).

  • clear_unused_last_page_rows (bool) – Zero rows [(seq_lens[b] - 1) % page_size + 1, page_size) of every request’s last page in both caches (all kv heads).

  • enable_pdl (bool) – Launch with programmatic dependent launch (PDL), so the kernel may start while the immediately preceding kernel on the stream is still running. The kernel then waits for that kernel to complete before it reads qkv and before any store, so qkv may be written by that kernel. q_indptr, seq_lens, page_indices, cos_sin and the norm weights are read before that wait: no kernel that may still be running when this kernel launches may write them. PDL is used only on SM100 / SM103 and only where it was measured to help (PDL_POLICY of the backend package); every other call launches plainly. The outputs are bitwise identical either way. Default False.

Returns:

out_q – BF16 [T, num_q_heads, 128] normalised and rotated queries (the caller’s out_q when given).

Return type:

torch.Tensor