vllm.models.glm5next.nvidia.specialized_decode.kpool
¶
The kpool indexer's decode kernels in CuTe DSL, bit for bit with the stock
Triton kernels of ops/kpool_compress.py and as_fp32_logits.
kpool_update is the decode tail stash plus pool compression: one warp per
request walks its tokens in position order (a completing token reads the
stashes of the earlier ones), four dimensions per lane. The softmax, the
Hadamard butterflies (strides 1 and 2 in a lane, 4..64 across lanes, as in
indexer_query), the BF16 roundings, the accurate log2 and the UE8M0 scale
follow the stock kernel's PTX: ex2.approx of (s - max) * log2(e), FMA
accumulation in pool order and div.full divisions.
upcast_logits is as_fp32_logits with 16-byte accesses.
Classes:
-
FusedRemap–A sparse MLA index group's conversion that expands a deferred pool top-k
-
KpoolStage–The kpool indexer decode kernels inside planned steps (stage
Functions:
-
expand_and_remap–triton_convert_req_index_to_global_index(..., return_valid_counts=True) -
expand_pools–expand_pools_and_append_tailintooutfor int32 pool ids. -
kpool_update–kpool_decode_update_and_maybe_write_cache_batchedwith power-of-two -
upcast_logits–as_fp32_logitsfor BF16 logits whose row stride is 16-byte aligned.
FusedRemap
¶
A sparse MLA index group's conversion that expands a deferred pool top-k
and remaps it in one kernel, on the group's side stream as the stock
conversion. Installed as the group's _convert_once; without a deferred
top-k it runs the stock conversion.
Source code in vllm/models/glm5next/nvidia/specialized_decode/kpool.py
KpoolStage
¶
The kpool indexer decode kernels inside planned steps (stage
dsa_kpool), reached from the stock indexer through
sparse_indexer.SPECIALIZED_KPOOL.
With fuse every DSA layer's index group converts through FusedRemap:
the indexer then leaves its uniform decode rows as pool ids (defer) and
skips filling the logical top-k buffer, which no consumer reads.
Methods:
-
defer–Leaves the expansion of
pool_idsto the layer's index remap. -
materialize–The logical top-k rows the stock indexer would have written.
Source code in vllm/models/glm5next/nvidia/specialized_decode/kpool.py
667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 | |
defer(pool_ids, positions, pool_size)
¶
Leaves the expansion of pool_ids to the layer's index remap.
Source code in vllm/models/glm5next/nvidia/specialized_decode/kpool.py
materialize(pending, logical)
staticmethod
¶
The logical top-k rows the stock indexer would have written.
Source code in vllm/models/glm5next/nvidia/specialized_decode/kpool.py
_ExpandKernel
¶
Thread g of row r writes the four token ids of pool
pool_ids[r, g] with one 16-byte store; CTA 0's first pool - 1
threads write the trailing incomplete pool.
Source code in vllm/models/glm5next/nvidia/specialized_decode/kpool.py
_RemapKernel
¶
expand_pools_and_append_tail and the sparse MLA index remap with
COMPACT_TO_FRONT in one CTA per query row.
Thread g maps pool pool_ids[row, g]: its tokens share one KV block,
so the pool is valid or invalid as a whole and every compacted offset is a
multiple of 4 (one 16-byte store). The column order of the stock compaction
is kept: history pools by rank, then the trailing incomplete pool, then -1.
Rows from expanded on hold no indices (the stock path filled them with
-1).
Source code in vllm/models/glm5next/nvidia/specialized_decode/kpool.py
460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 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 | |
_UpcastKernel
¶
CTA (row, split) converts the row's 8-element chunks split,
split + splits, ... below the row end; one chunk per thread.
Source code in vllm/models/glm5next/nvidia/specialized_decode/kpool.py
_UpdateKernel
¶
One warp per request; lane l owns dimensions 4l .. 4l + 3.
Source code in vllm/models/glm5next/nvidia/specialized_decode/kpool.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 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 | |
_div(a, b)
¶
_exp(score, peak)
¶
Triton's tl.exp(score - peak): ex2.approx of the product with
log2(e), each step rounded on its own.
Source code in vllm/models/glm5next/nvidia/specialized_decode/kpool.py
expand_and_remap(pool_ids, positions, pool_size, req_ids, block_table, out, counts, *, block_size, stride_rows, seq_offset=1)
¶
triton_convert_req_index_to_global_index(..., return_valid_counts=True)
of the expand_pools_and_append_tail rows of pool_ids, the rest of the
out.shape[0] rows read as -1. Writes out and counts.
Source code in vllm/models/glm5next/nvidia/specialized_decode/kpool.py
expand_pools(pool_ids, seq_lens, pool_size, *, seq_offset=0, out, threads=EXPAND_THREADS, pdl=True)
¶
expand_pools_and_append_tail into out for int32 pool ids.
Source code in vllm/models/glm5next/nvidia/specialized_decode/kpool.py
kpool_update(kv_cache, tail_kv_cache, tail_slot_mapping, key, slot_score, ape, slot_mapping, positions, pool_size)
¶
kpool_decode_update_and_maybe_write_cache_batched with power-of-two
UE8M0 (MX) scales; the same arguments, head_dim 128.
Source code in vllm/models/glm5next/nvidia/specialized_decode/kpool.py
upcast_logits(logits, row_ends, threads=UPCAST_THREADS, pdl=True, cap=1024)
¶
as_fp32_logits for BF16 logits whose row stride is 16-byte aligned.