vllm.models.muse_spark.nvidia.specialized_decode.cutedsl.attention.attn2
¶
Muse Spark paged decode attention of the 8-token verify step, fused with the per-head output RMS norm (no weight) and the sigmoid gate, as one CuTe kernel.
head_dim 64, 8 query heads per KV head, BF16 paged cache [pages, HKV, 16, 128] (K in columns 0:64, V in 64:128), 8 query rows per request (the last 8 cache entries of the request), any context length L >= 8, optionally a sliding window. One launch covers the rank's KV heads (grid y); the heads are independent.
Two variants, picked on the host from the deployment's maximum length:
- One cluster (max_seq_len <= 2048, no window): a cluster of 16 CTAs of 4 warps owns 16 query-head rows of one request and one KV head. Warp w of CTA r attends pages 4 r + w + 64 i (the next page's registers load while one is attended) with an online softmax: mma.sync m16n8k16 BF16 -> FP32 for Q K^T and P V, the softmax weights rounded to BF16, V transposed in registers by movmatrix (head dims permuted: logical (j, 2 t + e) = 16 t + 2 j + e). The warps merge in shared memory, each CTA pushes its merged rows to the CTA that owns them over distributed shared memory (st.async, mbarrier transaction bytes), and the owner merges the 16 CTAs in rank order, rounds o / l to BF16 and applies the RMS norm and the gate.
- Split (longer contexts or a window): a request within 8 rounds of the cluster's warps (512 pages from row 0's first visible key) takes the path above in z slice 0, the other slices exit at once; a longer one spreads its pages over 4 num_splits clusters, each CTA streaming its pages through an 8-page cp.async ring, merges in the cluster over distributed shared memory and across clusters through a global workspace in cluster order (an arrival counter per row: the last arriver merges, then resets the counter to zero). The launch shape depends on the deployment only, so a captured graph serves every step. With window W, row t sees keys [L - 8 + t - W + 1, L - 8 + t].
Every FP32 operation is explicit PTX in the fast-math forms (subnormals flushed, ex2.approx, rcp.approx, rsqrt.approx) in a fixed order, so the result depends neither on the launch's timing nor on the device. Not bitwise to the stock decode + rmsnorm_sigmoid_gate pair: the softmax weights are rounded to BF16 before P V and the partials merge in FP32.
Functions:
-
attn2–``out [8 R, 512 kv_heads] = sigmoid(gate) * rmsnorm(attention(q,
-
compile_attn2–cute.compile one variant of the kernel for
kv_headsKV heads, -
counters_bytes–The workspace's uint32 counters, one per row, 16-byte padded.
-
prepare–Compile the variant a deployment's layer launches (build time).
-
split_forms–(merge form, rolled short-path loop) of the split kernel.
-
split_kernel–Whether a deployment of
max_seq_lenlaunches the split kernel. -
window_pages–The most pages from row 0's first visible key to a request's last
-
workspace_bytes–Workspace bytes of a split launch over
rows(request, KV head,
_Attn2Kernel
¶
Grid (16 * 4 R, kv_heads, num_splits), cluster (16, 1, 1), 128 threads: cluster b * 4 + rg of KV head blockIdx.y computes rows 16 rg + [0, 16) of request b's 64 (token = row // 8, head = row % 8). The variant, PDL, the KV heads, the z slices and the window are compile-time; shapes, strides and addresses are read at the call.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/attention/attn2.py
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 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 | |
_attend_group(group, npages, page0, qf_frag, g, t, lim0, lim1, low0, low1, sl2, m0, m1, l0, l1, o, s, windowed)
¶
_attend_page for up to GROUP_PAGES pages staged in the ring (the
slots from shared address group, pages page0 + p) in one
online-softmax step.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/attention/attn2.py
_attend_page(cur, qf, pos, lim0, lim1, low0, low1, sl2, state, o, windowed)
¶
One page (16 keys) of online-softmax attention of the warp's rows g and g + 8 from registers; pos is the lane's first key, a row sees keys low <= key <= lim.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/attention/attn2.py
_check(q, kv_cache, block_table, seq_lens, gate, out, kv_heads, max_seq_len, window, num_splits, workspace)
¶
Raise ValueError naming the first condition the call fails, of those the kernel needs beyond the compiled call's own checks (dtypes, ranks, extents, unit strides, row strides, alignment); returns whether the split kernel runs.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/attention/attn2.py
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 1644 1645 1646 1647 1648 1649 1650 1651 1652 | |
_finish_row(ox, oy, ls, gate2, eps, out_row, lane)
¶
The epilogue of one row (lane: dims 2 lane, 2 lane + 1): o / l rounded to BF16, RMS norm without weight, sigmoid gate, BF16 store.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/attention/attn2.py
_issue_step(ring, step, count, first, bt_row, kv_base, kv_page_stride, tid)
¶
Copy the pages of ring step step (pages first + 4 step + [0, 4) of
this CTA's count; none past it) into ring slots 4 (step % 2) + [0, 4):
thread i the 16-byte chunks i and i + 128 of each page. The block-table
entries load first, then the copies issue (traced inline).
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/attention/attn2.py
_load_page(regs, kv_base, page_stride, entry, g, t)
¶
One KV page as a lane holds it: words 8 j .. 8 j + 7 the key slot 8 j + g, words 16 + 8 j .. the value slot 8 j + g, head dims [16 t, 16 t + 16).
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/attention/attn2.py
_load_rows(q_base, q_stride, token0, head0, token1, head1, t)
¶
A lane's query dims [16 t, 16 t + 16) of two query-head rows.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/attention/attn2.py
_long_cluster(q_base, q_stride, gate_base, gate_stride, kv_base, kv_page_stride, bt_row, out_base, out_stride, sl2, eps, window, counters, partials, smem, seq_len, first, n, b, rank, warp, lane, tid, kvh, kv_heads, slots, split, active, per, merge)
¶
Cluster split of active of a long request: pages
first + split * per + [0, per) (clipped to the request).
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/attention/attn2.py
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 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 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 | |
_long_context(q_base, q_stride, gate_base, gate_stride, kv_base, kv_page_stride, bt_row, out_base, out_stride, sl2, eps, window, counters, partials, smem, seq_len, first, n, b, rg, rank, warp, lane, tid, kvh, kv_heads, z, num_z, merge)
¶
A request of n pages from page first (more than SHORT_ROUNDS
rounds of a cluster's warps): the GROUPS * num_z clusters of the
(request, KV head) each take an equal contiguous page range; CTA r streams
its sixteenth of the range through the ring and warp w attends the 16 rows
of group w, so each page is read once per KV head. CTA r owns row
16 w + r of every group w, gathers the cluster's partials of it over
distributed shared memory and merges the clusters through the workspace.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/attention/attn2.py
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 1035 1036 1037 | |
_merge_cluster_long(recv, n_active, lane)
¶
The owner's merge of its row's partials from the cluster's first
n_active CTAs at recv (stride WARPS slots) in rank order:
(m, l, o[2 lane], o[2 lane + 1]).
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/attention/attn2.py
_merge_cluster_one(recv, n_active, lane)
¶
The owner's merge of its row's CLUSTER partials at recv in rank
order (ranks below n_active hold pages): (l, o[2 lane], o[2 lane + 1]).
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/attention/attn2.py
_merge_partials(counters, partials, row_id, slots, split, active, lane, m, ls, ox, oy, merge)
¶
Publish this cluster's (o, m, l) of a row, one of active; the warp
that completes the row's count returns (1, l, o[2 lane], o[2 lane + 1]),
the merge of every partial in cluster order (whichever warp is last,
loading them as merge says), after resetting the counter for the next
launch; the others return 0.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/attention/attn2.py
_merge_rows(row_partials, active, lane)
¶
(l, o[2 lane], o[2 lane + 1]) of a row's active cross-cluster
partials, merged in cluster order.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/attention/attn2.py
_merge_rows_batched(row_partials, slots, active, lane)
¶
_merge_rows with every partial's loads issued at once: (m, l) and
the o pair of each of the slots partials (those from active on
read partial active - 1 and are not merged).
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/attention/attn2.py
_merge_rows_m(row_partials, slots, active, lane)
¶
_merge_rows with the m of each of the slots partials loaded at
once (those from active on read partial active - 1 and are not
merged).
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/attention/attn2.py
_merge_warps_and_push(smem, mbar, tid, rank)
¶
Merge the CTA's four warp partials (8 lanes a row, lane i8 dims [4 i8, 4 i8 + 4) and [32 + 4 i8, ...)) and push row r to CTA r.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/attention/attn2.py
_online_step(s0, s1, state, o)
¶
One online-softmax step of rows g (scores s0) and g + 8 (s1): rescales o, returns the weights and the new (m0, m1, l0, l1).
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/attention/attn2.py
_page_round(cur, nxt, pg, qf_frag, num_pages, first_page, gw, e_second, bt_row, kv_base, kv_page_stride, g, t, lim0, lim1, low0, low1, sl2, m0, m1, l0, l1, o, windowed)
¶
One round of the warp's page loop: page pg (in cur) attended while
page pg + 64 loads into nxt, which then becomes cur.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/attention/attn2.py
_push_rows(smem, mbar, warp, lane, rank)
¶
The long path's push: warp w's row r (8 lanes a row, 4 rows a lane group) to CTA r.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/attention/attn2.py
_pv(o, p0, p1, vlo, vhi)
¶
O += P V for one page: p0 / p1 the BF16-rounded weights of rows g and g + 8 (keys 2 t, 2 t + 1, 8 + 2 t, 9 + 2 t), vlo / vhi the value words of slots g and 8 + g.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/attention/attn2.py
_qf(qr)
¶
The four A fragments of the queries, from a lane's 16-byte loads of rows g (qr[0], qr[1]) and g + 8 (qr[2], qr[3]).
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/attention/attn2.py
_scores(kw, qf)
¶
Q K^T of a lane's rows g, g + 8 and keys 2 t, 2 t + 1 of eight slots (kw: their key words): (g, k0), (g, k1), (g + 8, k0), (g + 8, k1).
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/attention/attn2.py
_short_path(q_base, q_stride, gate_base, gate_stride, kv_base, kv_page_stride, bt_row, out_base, out_stride, sl2, eps, window, smem, seq_len, b, rg, rank, warp, lane, tid, first_page, num_pages, e_first, e_second, split, rolled, rounds)
¶
The one-cluster computation of the cluster's 16 rows: pages
first_page + [0, num_pages) of the request (their first two
block-table entries of this warp read: e_first, e_second), at most two
rounds of the cluster's warps in the one-cluster kernel, SHORT_ROUNDS in
the split kernel (rounds > 0: a window's at most rounds rounds,
straight-line; else a loop the compiler unrolls, or a rolled loop in the
one-cluster kernel or with rolled).
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/attention/attn2.py
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 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 | |
_stash_partial(so, sm, sl, g, t, o, m0, m1, l0, l1)
¶
A warp's softmax state (lane: dims [16 t, 16 t + 16) of rows g and
g + 8) as rows of logical dims at so, with the row maxima at sm
and sums at sl.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/attention/attn2.py
_wait_phase0(mbar)
¶
Spin until the mbarrier's phase 0 completes (cluster-scope acquire), one bounded wait per iteration.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/attention/attn2.py
attn2(q, kv_cache, block_table, seq_lens, gate, out, kv_heads, enable_pdl=True, max_seq_len=SHORT_MAX_LEN, window=0, num_splits=1, workspace=None)
¶
out [8 R, 512 kv_heads] = sigmoid(gate) * rmsnorm(attention(q,
kv_cache)) per query head for R = q.shape[0] / 8 requests whose 8 query
rows are the last 8 of their seq_lens cache entries.
q, gate and out hold the heads of each KV head contiguously (8 x 64
columns per KV head); their rows may be strided (q and gate are column
views of the attention front's output, split_qkv). kv_cache is the
layer's BF16 [pages, kv_heads, 16, 128] cache. Lengths must be
8..max_seq_len and covered by the first ceil(L / 16) block_table entries
(device values, not checked here). max_seq_len is the deployment's maximum
length: above 2048, or with window > 0 (row t of a request sees keys
[L - 8 + t - window + 1, L - 8 + t]), the split kernel runs over
num_splits z slices and needs workspace, uint8 of at least
workspace_bytes whose counters are zero before the first call (every
call leaves them zero). Launched on the current stream of the inputs'
device (the compiled call switches to q's device and back), with PDL when
enable_pdl. Raises ValueError on inputs outside this contract (some
through the compiled call's own checks); allocates nothing, so a call is
graph-capturable once prepare has compiled its variant.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/attention/attn2.py
compile_attn2(split, enable_pdl, kv_heads, num_splits, window, options='')
cached
¶
cute.compile one variant of the kernel for kv_heads KV heads,
num_splits z slices (1 for the one-cluster kernel) and window (0:
none), with these extra compile options, before CUDA graph capture.
The result takes q, gate, kv_cache, block_table, seq_lens, out and the
workspace (None for the one-cluster kernel), checks their dtypes, ranks,
the static extents, unit strides, row-stride divisibility and alignment,
and launches on the current stream.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/attention/attn2.py
1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 | |
counters_bytes(rows)
¶
The workspace's uint32 counters, one per row, 16-byte padded.
prepare(max_seq_len, window, kv_heads, num_splits, enable_pdl=True)
¶
Compile the variant a deployment's layer launches (build time).
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/attention/attn2.py
split_forms(kv_heads, num_splits)
¶
(merge form, rolled short-path loop) of the split kernel.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/attention/attn2.py
split_kernel(max_seq_len, window)
¶
Whether a deployment of max_seq_len launches the split kernel.
window_pages(window)
¶
The most pages from row 0's first visible key to a request's last
with window (0: no window, no bound): ceil(L / 16) - (L - 7 - W) // 16
at most.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/attention/attn2.py
workspace_bytes(rows, num_splits)
¶
Workspace bytes of a split launch over rows (request, KV head,
query-head) rows: the counters, then a partial of SLOT floats per row and
cluster of its (request, KV head).