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 :func:_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]
Source code in vllm/v1/attention/backends/flashinfer_ts.py
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 | |
_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.
Source code in vllm/v1/attention/backends/flashinfer_ts.py
FlashInferTSMetadataBuilder
¶
Bases: AttentionMetadataBuilder[FlashInferTSMetadata]
Source code in vllm/v1/attention/backends/flashinfer_ts.py
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 | |
_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.
Source code in vllm/v1/attention/backends/flashinfer_ts.py
_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.
Source code in vllm/v1/attention/backends/flashinfer_ts.py
_window_pages(query_len)
¶
Page-table width a restricted (windowed) batch needs.
Source code in vllm/v1/attention/backends/flashinfer_ts.py
_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.0.post1 ships prims_ts but calls Task._run_task_body_impl with a
context kwarg that cutlass-dsl 4.8.0 removed, so it raises TypeError
deep inside kernel codegen.
Source code in vllm/v1/attention/backends/flashinfer_ts.py
_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.