Skip to content

vllm.v1.attention.backends.flashinfer_ts

FlashInfer task-scheduled (prims_ts) paged decode.

Wraps flashinfer.attention.prims_ts.BatchDecodePagedTSWrapper for uniform query-block decode: every request contributes exactly max_query_len query tokens over a paged KV cache. That is the DFlash/DSpark drafter shape, and the reason this backend exists is that mask_type="dense" expresses a non-causal draft block directly -- the trtllm-gen paged decode kernel is bottom-right causal and silently ignores a supplied mask.

Layout. No KV cache change: K and V are the two halves of vLLM's ordinary [pages, Hkv, page_size, 2 * D] page, so their token stride is 2 * D. The kernel builds its TMA descriptors from the tensors' own strides (_validate_native_hnd_tma_strides), so the only requirement is a contiguous head_dim. Verified numerically equal to the same data repacked into compact planes.

Sliding window. prims_ts rejects window_left >= 0 unless the mask is causal, so a non-causal windowed layer cannot be expressed directly. The query block always sits at the end of the sequence, so the symmetric window reduces to a suffix, and we hand the kernel a block table restricted to the window's pages (see _restrict_to_window). Because the restriction is page aligned, each query token sees up to page_size - 1 extra tokens at the old edge, and all query tokens share one window start rather than each having its own (max_query_len - 1 tokens of drift).

Classes:

FlashInferTSImpl

Bases: AttentionImpl[FlashInferTSMetadata]

_kv_views(kv_cache)

HND K/V views of vLLM's [pages, Hkv, page, 2 * D] page.

Their token stride is 2 * D rather than D; the kernel builds its TMA descriptors from the tensor's own strides, so no repacking and no layout change are needed.

FlashInferTSMetadataBuilder

Bases: AttentionMetadataBuilder[FlashInferTSMetadata]

_max_kv_len()

Constant K/V capacity every plan compiles for.

Keeping it constant is what makes one plan per (batch size, query length) safe to replay from a CUDA graph: build() can never pick a differently-compiled plan for a batch the graph already captured.

_restrict_to_window(seq_lens, block_table, query_len)

Cut the page table down to the pages the window can reach.

The query block ends the sequence, so a symmetric window around it is the suffix [L - w - query_len + 1, L). Round that start down to a page so the slice is expressible as a page table, then renumber the lengths relative to the new first page.

_window_pages(query_len)

Page-table width a restricted (windowed) batch needs.

_kv_kernel_dtype(spec)

An FP8 cache is stored as uint8 and viewed as e4m3 at use.

_require_prims_ts()

Import the prims_ts wrapper, or explain which flashinfer is needed.

0.7.4 renamed the plan and run arguments vLLM passes (e.g. q_dtype, softmax_scale); earlier builds reject them with a TypeError.

_ts_output_dtype(q_dtype, model_dtype)

The output dtype the kernel can write for this query dtype.

An FP8 query only yields FP16 or FP8 out, so a bf16 model stages through FP16 and converts; every other combination writes the model dtype directly.