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. 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 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 strictly increasing, 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 semantic key 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.