flashinfer.attention.prims_ts.prims_ts_batch_decode_with_kv_cache_mla¶
- flashinfer.attention.prims_ts.prims_ts_batch_decode_with_kv_cache_mla(query: Tensor, kv_cache: Tensor, workspace_buffer: Tensor, kv_lora_rank: int, qk_rope_head_dim: int, block_tables: Tensor, seq_lens: Tensor, max_seq_len: int, *, qo_indptr: Tensor | None = None, max_seq_len_q: int | None = None, out: Tensor | None = None, bmm1_scale: float = 1.0, bmm2_scale: float = 1.0, mask_type: Literal['dense', 'causal'] = 'causal', out_dtype: dtype = torch.bfloat16) Tensor¶
Launch fixed or packed-query paged MLA decode with caller-owned scratch.
With
qo_indptr=None,queryhas fixed shape[B, SQ, H, 576]. Otherwisequeryhas compact shape[total_q, H, 576]andqo_indptrcontains theB + 1cumulative Q offsets. Runtime Q lengths are exclusivelyqo_indptr[b + 1] - qo_indptr[b];max_seq_len_qis only the static policy, JIT, and workspace bound and is required for compact launches. Individual packed requests may be empty, and an all-empty launch returns its empty output without dispatching a GPU kernel. The last query dimension concatenates the 512 latent and 64 RoPE dimensions.kv_cacheaccepts compact rank-3[pages, page_size, 576]or rank-4[pages, 1, page_size, 576]storage.block_tablesandseq_lensfollow FlashInfer’s native dense paged-cache ABI;max_seq_lenis the exact static policy/JIT maximum. Causal masking is bottom-right aligned: query rowican attend through KV rowseq_lens[b] - q_len[b] + ifor requestb.The workspace is exclusive to one in-flight launch or captured graph and must not overlap query, K/V cache, metadata, or output storage. Runtime K/V lengths must remain positive and no larger than
max_seq_len; this hot path deliberately performs no device-to-host metadata reads. For packed launches, callers must ensure that offsets start at zero, are nondecreasing, end atquery.shape[0], and have every delta no larger thanmax_seq_len_q. For causal masking, every fixed or packed per-request Q length must also be no greater than the corresponding liveseq_lensvalue. Warm the planned topology before CUDA graph capture and provideoutto avoid an output allocation. Captured graphs must retain stableqo_indptrstorage; its values may change only while that packed-offset contract and the captured query/output extent remain valid. No backend fallback or scheduling knob is exposed.- Parameters:
query (torch.Tensor) – Fixed or packed query tensor with concatenated latent and RoPE heads.
kv_cache (torch.Tensor) – Compact paged latent K/V cache.
workspace_buffer (torch.Tensor) – Caller-owned byte workspace for this planned layout.
kv_lora_rank (int) – Latent and RoPE dimensions.
qk_rope_head_dim (int) – Latent and RoPE dimensions.
block_tables (torch.Tensor) – Dense physical-page table for each request.
seq_lens (torch.Tensor) – Live K/V sequence lengths.
max_seq_len (int) – Static maximum K/V length used for policy selection and JIT caching.
qo_indptr (torch.Tensor, optional) – Cumulative query offsets selecting packed-query mode.
max_seq_len_q (int, optional) – Static packed-query length bound.
out (torch.Tensor, optional) – Caller-owned output tensor.
bmm1_scale (float) – QK and value/output scaling factors.
bmm2_scale (float) – QK and value/output scaling factors.
mask_type ({"dense", "causal"}) – Attention mask mode.
out_dtype (torch.dtype) – Output dtype.