flashinfer.cake_fused_qk_rope_fp8_append.cake_fused_qk_rmsnorm_rope_quantize_fp8_append_paged_kv_cache¶
- flashinfer.cake_fused_qk_rope_fp8_append.cake_fused_qk_rmsnorm_rope_quantize_fp8_append_paged_kv_cache(qkv: Tensor, cos_sin_cache: Tensor, seq_lens: Tensor, q_indptr: Tensor, page_indices: Tensor, paged_kv_cache: Tuple[Tensor, Tensor], is_prefill: bool, k_scale: Tensor, v_scale: Tensor, quant_policy: int, max_seqlen: int = 0, upper_max: float = 448.0, q_scale_inv: Tensor | None = None, q_norm_weight: Tensor | None = None, k_norm_weight: Tensor | None = None, qk_norm_policy: int = 0, out_q: Tensor | None = None, out_k: Tensor | None = None, out_v: Tensor | None = None, q_scale: Tensor | None = None, split_k_flag: Tensor | None = None, *, enable_pdl: bool = False) Tuple[Tensor, Tensor, Tensor]¶
Fused Q/K RMSNorm + NeoX RoPE + FP8 quantization + 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. The head configuration is derived from this width and the cache’s kv-head count.cos_sin_cache (torch.Tensor) – F32
[max_position, 128]; rowpiscos(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 requestb.page_indices (torch.Tensor) – I32
[B, max_pages]dense physical page table (entries beyond a request’s pages are ignored).paged_kv_cache ((torch.Tensor, torch.Tensor)) – FP8 E4M3 NHD
(key_cache, value_cache), each[num_pages, page_size, num_kv_heads, 128](written in place).is_prefill (bool) – Selects the
q_scalelayout ofquant_policy=1(see below).k_scale (torch.Tensor) – F32 one-element dequantization scales; the stored payload is
x / scale.v_scale (torch.Tensor) – F32 one-element dequantization scales; the stored payload is
x / scale.quant_policy (int) – 1 = dynamic per-token / per-Q-head scale
max(|q|, 1e-6) / upper_max; 2 = static scale: payloadq * q_scale_invand an emptyq_scale.max_seqlen (int) – Dynamic prefill (
quant_policy=1andis_prefill) only: must cover the longest request;q_scaleis[B, num_q_heads, round_up(max_seqlen, 128)]addressed by the token index inside its request.upper_max (float) – Finite E4M3 magnitude in
(0, 448]used by the dynamic scale.q_scale_inv (torch.Tensor, optional) – F32 one-element static Q multiplier (required for
quant_policy=2).q_norm_weight (torch.Tensor, optional) – F32
[128]per-head RMSNorm weights (required unlessqk_norm_policy == 0).k_norm_weight (torch.Tensor, optional) – F32
[128]per-head RMSNorm weights (required unlessqk_norm_policy == 0).qk_norm_policy (int) – 0 no norm, 1 RoPE then RMSNorm, 2 RMSNorm then RoPE.
out_q (torch.Tensor, optional) – FP8
[T, num_q_heads, 128]output buffer (allocated whenNone).out_k (torch.Tensor, optional) – FP8
[T, num_kv_heads, 128]; when both are given, K / V rows are written there instead of the caches (the last-page tail clear still runs).out_v (torch.Tensor, optional) – FP8
[T, num_kv_heads, 128]; when both are given, K / V rows are written there instead of the caches (the last-page tail clear still runs).q_scale (torch.Tensor, optional) – F32 output buffer: decode
[T, num_q_heads], dynamic prefill[B, num_q_heads, round_up(max_seqlen, 128)],quant_policy=2empty.split_k_flag (torch.Tensor, optional) – I32
[B, num_kv_heads]output buffer; every element is written (0 valid, -1 invalid metadata), no host-side clear is needed.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
qkvand before any store, soqkvmay be written by that kernel.q_indptr,seq_lens,page_indices,cos_sin_cache, the norm weights and the scalesk_scale,v_scaleandq_scale_invare 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_POLICYof the backend package); every other call launches plainly. The outputs are bitwise identical either way. DefaultFalse.
- Returns:
The caller-owned buffers when given, otherwise freshly allocated ones.
- Return type:
(out_q, q_scale, split_k_flag)