vllm.v1.attention.ops.turboquant_soa.triton_turboquant_decode_v2 ¶
Optimized Triton TurboQuant decode attention (v2).
FLUTE-paper optimizations applied
- Grouped Q heads: grid over (B, Hk, splits) instead of (B, Hq, splits). Each program loads BLOCK_M Q heads sharing a KV head into a 2D tile, enabling tl.dot on tensor cores (MFMA/WMMA) for both Q·K and P·V.
- Vectorized pair LUT: precompute
pair_table[i][j] = (T[i], T[j])offline. At runtime, extract adjacent index pairs and fetch two dequantized centroids with a single gather, halving LUT lookups. - exp2 instead of exp: scores pre-scaled by log2(e) so the hardware- native exp2 instruction replaces the more expensive exp.
- Wider index extraction: for 4-bit MSE, two adjacent 4-bit indices share a byte. One byte load yields both, eliminating redundant loads.
- Centroids pre-warmed in L1 at kernel start.
- BLOCK_KV = TILE_SIZE raised to 16-32 (from 4), reducing loop iterations and softmax rescaling overhead.
Stage 2 is reused unchanged from triton_decode_attention.py.
Functions:
-
build_pair_lut–Build vectorized pair lookup table.
-
triton_turboquant_decode_attention_v2–Launch optimized TQ decode attention (v2 stage1 + shared stage2).
_get_pair_lut(centroids) ¶
Return a fresh pair-LUT for centroids on each call.
The LUT is tiny (NN2 fp32, e.g. 2KB for 4-bit MSE) so the build cost is negligible compared to attention. We avoid caching by data_ptr() because CUDA allocator memory reuse across different centroid tensors can silently return a stale LUT (subtle correctness bug). If this ever shows up on a profile, cache by a hash-of-values fingerprint instead.
Source code in vllm/v1/attention/ops/turboquant_soa/triton_turboquant_decode_v2.py
build_pair_lut(centroids) ¶
Build vectorized pair lookup table.
For N centroids, returns a [N, N, 2] float32 tensor where pair_lut[i, j] = (centroids[i], centroids[j]). Flattened to [NN, 2] for kernel indexing: pair_lut[iN + j].
For 4-bit MSE (N=16): 161624 = 2048 bytes — fits in L1/smem. For 3-bit MSE (N=8): 8824 = 512 bytes.
Source code in vllm/v1/attention/ops/turboquant_soa/triton_turboquant_decode_v2.py
triton_turboquant_decode_attention_v2(query, kv_cache, block_table, seq_lens, Pi, centroids, scale, mse_bits, key_packed_size, value_quant_bits, value_packed_size, max_seq_len=0, key_fp8=False, norm_correction=False, PiT=None, mid_o_buf=None, output_buf=None, lse_buf=None, buf_holder=None, max_num_kv_splits=32) ¶
Launch optimized TQ decode attention (v2 stage1 + shared stage2).
Follows the same buffer-reuse + fixed-grid contract as the v1 launcher (triton_turboquant_decode_attention) so the backend can capture a CUDA graph across both versions.
Source code in vllm/v1/attention/ops/turboquant_soa/triton_turboquant_decode_v2.py
485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 | |