vllm.models.muse_spark.nvidia.specialized_decode.cutedsl.draft.markov
¶
CuTe DSL kernels of the fused DSpark Markov sampling loop.
Per draft step the Markov w2 GEMV runs unchanged, then markov_step
(bias, output transform, cache store, Gumbel block argmax, and in the row's
last block the final argmax, token and next w1 row). With a vocab-parallel w2
each rank works on its vocab range, its last block writes a packet instead of
the token, and markov_pick picks the winner from the gathered per-rank
packets; cache_fill scatters the gathered draft-logits shards after the
loop. anchor_embed starts a call.
The arithmetic is bit for bit that of the speculator's eager loop: its
output transform (BF16 add, multiplier, optional soft cap
cap * tanh(x * inv_cap)) and the stock gumbel_noised_argmax and
gumbel_block_argmax of vllm/v1/worker/gpu/sample/gumbel.py
(MurmurHash3 noise of seed, step, position and global vocab id). It is written
as explicit PTX, the instructions Triton 3.8 emits for those kernels on
SM 10.x, including libdevice tanhf and logf under FTZ.
Every argmax takes the first NaN, else the first maximum (the order of
torch.argmax). That is a total order on (value, index), so the block
argmax, the argmax over the blocks and the pick over the ranks give the same
id in any reduction order: the lowest vocab id whose noised logit is NaN, else
the lowest id of the maximum, at every block size, layout and vocab shard. On
rows without NaN this is the eager loop's id; on a row with a NaN the eager
loop's Triton block argmax can differ, and is not reproduced.
Each step's blocks count their arrivals; the row's last block reduces the blocks' (value, id) results with the same combine.
A token's w1 row is read at the token clamped to the table's last row, so a corrupt id never reads past the table; valid ids are unchanged. Fixed pointers and host grids keep the loop capturable. Where the GPU has programmatic dependent launch, the step and pick kernels can launch with it: until the dependency wait they read only inputs written before the loop and store nothing; they never trigger their dependents early.
Classes:
-
MarkovKernels–The kernels of one loop over the BF16 Markov w1 table
w1``[V, -
Operand–Where a BF16 operand of the step lies: its byte address and element
Functions:
-
anchor_embed–emb[r] = w1[input_ids[anchor_idx[r]]]andarrivals[r] = 0for -
cache_fill–Scatter the gathered
[tp, rows, steps, shard]BF16 draft logits -
compile_step–cute.compile one step kernel (before CUDA graph capture).
-
copy_chunk–Bytes per access of a row copy by
threadsthreads: up to 16, no -
fill_vectorized–Whether the cache fill copies 16-byte vectors: the shard, the vocab,
-
finish_warps–Warps of a step's last block that reduce its
blocksresults: -
markov_pick–tokens[r, step]andemb[r](its w1 row) of the winner over the -
markov_step–One step over
widthvocab entries fromvocab_offsetfor the -
vector_bytes–The bytes of one thread's
block / 128elements where a step at -
vectorized–Whether a step at
blockreads and writes its base, bias and cache
MarkovKernels
¶
The kernels of one loop over the BF16 Markov w1 table w1 [V,
R] with Markov embedding rows in embeds and width vocab entries
per rank (a shard over tp ranks, or the whole vocab with tp
None), compiled here, before CUDA graph capture: the anchor, the step at
each (block, PDL, vector) of steps, and with a vocab shard
the pick (pick_pdl) and the cache fill (fill_vector). A step at
another (block, PDL, vector) compiles when it first runs (never under
capture).
Methods:
-
pick–markov_pickover this loop's w1,emba row view of -
step–markov_stepover this loop's w1 and width,emba row view
Attributes:
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/draft/markov.py
1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 | |
step_variants
property
¶
The (block, PDL, vector) of the compiled steps.
pick(packets, rows, tokens, step, emb)
¶
markov_pick over this loop's w1, emb a row view of
embeds.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/draft/markov.py
step(base, bias, cache, col, idx_map, pos, seeds, temperature, block_argmax, block_max, arrivals, tokens, emb, packets, vocab_offset, mult, inv_cap, cap, *, block, pdl)
¶
markov_step over this loop's w1 and width, emb a row view
of embeds; the caller checks the operands' dtypes.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/draft/markov.py
Operand
¶
Bases: NamedTuple
Where a BF16 operand of the step lies: its byte address and element
strides, which decide whether the step moves it in vectors
(vectorized).
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/draft/markov.py
_AnchorKernel
¶
Grid (rows,), THREADS threads: step 0's Markov embedding (the w1 row of the anchor token) and the row's arrival count reset.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/draft/markov.py
_CacheFillKernel
¶
Grid (rows * steps, vocab blocks), THREADS threads of FILL_BLOCK //
THREADS consecutive entries: scatter the gathered [tp, rows, steps,
shard] draft logits (rank stride src_s0) into the full-vocab
cache. vectorized: one 16-byte copy per thread (shard, vocab,
strides and pointers 16-byte aligned).
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/draft/markov.py
1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 | |
_PickKernel
¶
Grid (rows,), one warp: the winner over the gathered [tp, rows, 4]
packets (the first NaN, else the first maximum, by global id: with
shard k holding the ids above shard k - 1's, the unsharded argmax).
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/draft/markov.py
1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 | |
_StepKernel
¶
Grid (rows, blocks), THREADS threads, block vocab entries per CTA;
blocks (the vocab width's) is a compile-time constant.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/draft/markov.py
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 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 | |
_finish(tidx, warp, lane, warp_values, warp_indices, row, col, block_argmax, block_max, tokens, tokens_s0, w1, emb, packets)
¶
The first finish_warps warps of the row's last block: the
first NaN, else the first maximum, over the blocks' (value, global
id) results (a global id rises with the block), then the token and
next w1 row, or the packet [value bits, global id, 0, 0]. Every
thread loads its share of the results at once, then reduces them,
then the warps, then (several warps) their results in shared
memory; the combine is a total order, so every lane ends with the
winner and no load waits for it.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/draft/markov.py
968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 | |
_combine(v1, i1, v2, i2, *, loc=None, ip=None)
¶
The first pair if v1 > v2, or v1 == v2 with i1 < i2
(ordered compares), or v1 is NaN and v2 is not or i1 < i2;
else the second.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/draft/markov.py
_combine_in_order(v1, i1, v2, i2, *, loc=None, ip=None)
¶
_combine of two pairs with i1 < i2: the first if v1 is NaN
or v1 >= v2 (ordered), else the second.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/draft/markov.py
_copy(copies, nbytes)
¶
Copy nbytes (2, 4, 8 or 16, aligned) for each (source,
destination, predicate): every load issued before the first store
(traced inline).
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/draft/markov.py
_copy_row(source, destination, tidx, threads, row_bytes, chunk)
¶
Copy row_bytes from source to destination with threads
threads in chunk-byte accesses.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/draft/markov.py
_fill_entries(src, src_s0, row, target, first, shard, vocab)
¶
The cache fill's one-entry copies of a thread (traced inline).
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/draft/markov.py
_gumbel(logit, temp, prefix, gid, mask, *, loc=None, ip=None)
¶
logit / temp plus the Gumbel noise of vocab id gid
(gumbel_noised_argmax with fp32 noise while drafting), or -inf off
the mask. prefix is _murmur_prefix of the row.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/draft/markov.py
_lane_results(block_max, block_argmax, lane, blocks, threads)
¶
The (FP32 value, global id) results lane, lane + threads, ... of
blocks, all loaded at once (traced inline); an id is the low word of
its int64. Past the last block a lane loads (-inf, BIG_INDEX): its id is
above every block's, so a block's -inf wins over it.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/draft/markov.py
_ld_volatile_b32_or(address, predicate, other, *, loc=None, ip=None)
¶
A volatile load if predicate, else other.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/draft/markov.py
_load_bf16(row, offset, mask, vector)
¶
A thread's BF16 elements of a row (the bits in a 32-bit word each),
one load per element, or with vector (consecutive elements, which
share a mask) one load of all of them (traced inline).
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/draft/markov.py
_load_words(source, nbytes, predicate, *, loc=None, ip=None)
¶
nbytes (2, 4, 8 or 16, aligned) as 32-bit words if predicate
(else zeros).
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/draft/markov.py
_logf(x, out, tag, addend)
¶
Libdevice logf under FTZ of the normal-or-special x (the exponent
term addend added), into out; NaN, +-inf and negatives through
fma(x, inf, inf).
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/draft/markov.py
_logit(a_bits, b_bits, mult, inv_cap, cap, mask, has_cap, *, loc=None, ip=None)
¶
(BF16 bits of the cached logit, the logit as FP32 or -inf off the mask)
of BF16 a (base) and b (bias).
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/draft/markov.py
_murmur_prefix(seed_lo, seed_hi, pos_lo, *, loc=None, ip=None)
¶
MurmurHash3 state after the request's three words (seed low, seed high, position), from 0.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/draft/markov.py
_nonzero_f32(value, *, loc=None, ip=None)
¶
1 where value != 0.0 (ordered, as Triton's temp != 0.0).
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/draft/markov.py
_store_bf16(row, offset, store, bits, vector)
¶
Store a thread's BF16 elements as _load_bf16 loads them.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/draft/markov.py
_store_words(destination, words, nbytes, predicate, *, loc=None, ip=None)
¶
Store the words of _load_words if predicate.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/draft/markov.py
_tree_argmax(pairs, combine)
¶
The first NaN, else the first maximum, of (value, index) pairs,
reduced level by level as a tree (traced inline); combine is
_combine_in_order when the pairs are in index order.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/draft/markov.py
_w1_row(token, last, *, loc=None, ip=None)
¶
The w1 row a token's embedding is copied from: the token, clamped to
last (the table's last row) as an unsigned value, so an id outside
the table (negative included) reads its last row instead of memory
around it. A valid id is unchanged.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/draft/markov.py
_warp_argmax(value, index, top)
¶
Butterfly over the warp's lanes (top .. 1): every lane ends with
the first NaN, else the first maximum, of the lanes' pairs.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/draft/markov.py
anchor_embed(input_ids, anchor_idx, w1, emb, arrivals)
¶
emb[r] = w1[input_ids[anchor_idx[r]]] and arrivals[r] = 0 for
the arrivals.numel() rows (int32 ids, int64 anchors, rows of emb
contiguous).
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/draft/markov.py
cache_fill(gathered, src_s0, cache, idx_map, rows, steps, shard, vocab)
¶
Scatter the gathered [tp, rows, steps, shard] BF16 draft logits
(rank stride src_s0) into the full-vocab cache rows idx_map
names (int64, one per row and step; negative: skipped).
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/draft/markov.py
compile_step(*, block, blocks, vector, has_cap, sharded, pdl, row_bytes, chunk, w1_rows)
cached
¶
cute.compile one step kernel (before CUDA graph capture).
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/draft/markov.py
copy_chunk(row_bytes, threads, *tensors)
¶
Bytes per access of a row copy by threads threads: up to 16, no
more than a thread's share (2 when a row is narrower than the threads),
within the alignment of every row pointer. The chunk divides the row
bytes (both powers of two), so it is the same for every row of a
row-major table.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/draft/markov.py
fill_vectorized(*, gathered, src_s0, cache, shard, vocab)
¶
Whether the cache fill copies 16-byte vectors: the shard, the vocab,
the strides and the pointers (gathered the address of the gathered
logits) 16-byte aligned.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/draft/markov.py
finish_warps(blocks)
¶
Warps of a step's last block that reduce its blocks results:
warp 0 up to four results per lane, else all four warps.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/draft/markov.py
markov_pick(packets, rows, tokens, step, w1, emb, *, tp, pdl)
¶
tokens[r, step] and emb[r] (its w1 row) of the winner over the
gathered int32 [tp, rows, 4] packets.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/draft/markov.py
markov_step(base, bias, cache, col, idx_map, pos, seeds, temperature, block_argmax, block_max, arrivals, tokens, w1, emb, packets, width, vocab_offset, mult, inv_cap, cap, *, has_cap, sharded, block, pdl)
¶
One step over width vocab entries from vocab_offset for the
base.shape[0] rows: base and bias BF16 rows, cache the
draft-logits cache [req, step, vocab] or, sharded, [row, step,
width], idx_map and pos the step's int64 columns,
block_argmax int64 and block_max FP32 with rows * blocks
elements, packets int32 [rows, 4], w1 and emb BF16.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/draft/markov.py
1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 | |
vector_bytes(block)
¶
The bytes of one thread's block / 128 elements where a step at
block may move them as one 8- or 16-byte access, else 0.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/draft/markov.py
vectorized(block, *, width, col, base, bias, cache)
¶
Whether a step at block reads and writes its base, bias and cache
rows a thread's block / 128 elements at a time (vector_bytes):
every such group then starts aligned to its bytes and lies wholly inside
or outside the width. The values are the same either way.