vllm.models.muse_spark.nvidia.specialized_decode.cutedsl.moe.tail
¶
The MoE tail of the Muse Spark specialized decode.
With expert parallelism every rank holds the GEMM2 rows of its local experts
for the replicated tokens (UnfinalizedMoEOutput). The tail (MoETail)
RMS-normalizes each local route's row over the pooled width (post_expert_norm),
weights it by its route weight, sums a token's routes in FP32, and all-reduces
the per-rank BF16 partial sums (the EP combine). Per token, over the routes
r local to a rank with row x_r and weight w_r::
s_r = x_r * (gamma + gain_center) # weight_before_norm
partial = bf16(sum_r w_r * s_r * rsqrt(mean(s_r**2) + eps))
out = bf16(sum over ranks, in rank order, of partial) # FP32 sum
Without weight_before_norm the weight multiplies after the norm. The output
is bitwise the stock MNNVL MoE finalize's for the same rows, identical on every
rank. It takes two kernels over one Lamport mailbox: a publisher that
multicasts each token's partial, and a reduction that sums the tp slots.
Under expert TP (TpTail) every rank holds a K-partial of every route's
GEMM2 row instead. The rows are summed across ranks before the norm, bitwise
as the stock TP finalize (tp_moe_finalize_rmsnorm) on its single-launch
token-owner path::
x_r = bf16(sum over ranks, in rank order, of the K-partials) # FP32 sum
out = bf16(sum_r fp32(w_r * norm(x_r))) # routes in order, from 0.0
See _TpTailKernel.
Classes:
-
BoundTail–One MoE layer's tail on
tail(aMoETail, or aTpTailfor -
MoETail–The MoE tail of one executor: its Lamport mailbox and compiled kernels.
-
TailConstants–Compile-time constants of one layer's post-expert norm (bound at build).
-
TpTail–The MoE tail of the expert-TP layers of one executor: the route and
Functions:
-
compile_publisher–Compile the finalize publisher for one norm and route-weight dtype.
-
compile_reduce–Compile the reduction for a
[3, tp, capacity, P]mailbox. -
compile_tp_tail–Compile the TP tail for one norm, route-weight dtype and band split.
-
tail_constants–The constants the stock post-expert finalize passes for
norm(a -
tail_weight–The norm weight as the stock finalize hands it to the kernel: BF16 [P],
-
tp_split–H bands per token of the TP tail for
mtokens onnsmSMs, as
BoundTail
¶
One MoE layer's tail on tail (a MoETail, or a TpTail for
the expert-TP layers); run is graph-capturable and allocates nothing.
Methods:
-
run–Finalize the experts' output into
out(BF16 [b, P],
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/moe/tail.py
run(unfinalized, out)
¶
Finalize the experts' output into out (BF16 [b, P],
contiguous): the MoE output, identical on every rank. Every rank of
the group calls it with the same b; b = 0 does nothing on every rank.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/moe/tail.py
MoETail
¶
The MoE tail of one executor: its Lamport mailbox and compiled kernels.
Built once, collectively over the TP group, before CUDA graph capture. Every
MoE layer binds its post-expert norm with :meth:bind; the layers share the
mailbox (their calls are sequential on every rank, as the stock workspace's
are). tp >= 2 (multicast); capacity rows per call at most.
Methods:
-
bind–One layer's tail:
normis its post_expert_norm. Both route-weight -
select–The finalize publisher for one norm and route-weight dtype (cached;
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/moe/tail.py
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 | |
bind(norm)
¶
One layer's tail: norm is its post_expert_norm. Both route-weight
dtypes are compiled here, before capture.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/moe/tail.py
select(constants, weight_dtype, m)
¶
The finalize publisher for one norm and route-weight dtype (cached; every row count takes the same one).
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/moe/tail.py
TailConstants
¶
Bases: NamedTuple
Compile-time constants of one layer's post-expert norm (bound at build).
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/moe/tail.py
TpTail
¶
The MoE tail of the expert-TP layers of one executor: the route and token mailboxes, the generation words and the compiled kernels.
Built once, collectively over the TP group, before CUDA graph capture; the
layers share it (their calls are sequential on every rank). Every rank
holds a K-partial of every route row; the output is bitwise the stock TP
finalize's on its token-owner path for the same partials (tp_split).
tp >= 2 (multicast); capacity tokens per call at most. batches:
the token counts a captured call runs (the executor's), whose band splits
every bind compiles; other counts compile theirs on their first call.
Methods:
-
bind–One layer's tail:
normis its post_expert_norm. The splits of -
select–The tail for one norm and route-weight dtype at
mtokens (cached
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/moe/tail.py
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 | |
bind(norm)
¶
One layer's tail: norm is its post_expert_norm. The splits of
batches are compiled here for both route-weight dtypes, before
capture.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/moe/tail.py
select(constants, weight_dtype, m)
¶
The tail for one norm and route-weight dtype at m tokens (cached
per band split; compiled on a miss, which must precede capture).
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/moe/tail.py
_TailReduceKernel
¶
Sum the tp partials of every token from the mailbox into output.
Each 8-column fragment waits for all tp slots (bounded), adds them in
rank order in FP32 from 0.0 and stores the BF16 sum; then the stage
advances, dependents are released and the slots are re-armed.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/moe/tail.py
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 322 323 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 | |
_TpTailKernel
¶
The expert-TP MoE tail, one launch: grid (split, slots, tp), clusters of
the split H bands of one (slot, d), TOP_K x band_threads
threads; CTA (b, g, d) works on H band b of token t = g * tp + d. Rank
t % tp owns token t.
- Send: every rank sends its K-partial rows of token t's routes to the owner's route mailbox (unicast), -0.0 as +0.0.
- Sum: the owner sums each route's partials across ranks in rank order, RMS-normalizes and weights them, sums the routes in order and multicasts the finished BF16 row to every rank's token mailbox.
- Copy: every rank copies the rows it does not own from its token mailbox into the output.
The sum's arithmetic, order and BF16 roundings are the stock TP
finalize's (tp_split gives its sum-of-squares tree).
Each CTA reads its generation word(s) after griddepcontrol.wait and
advances them at exit; the words are per finest band (TP_MAX_SPLIT),
so every word of a slot advances once per launch whatever the split and
all ranks agree on it. A slot is re-armed by its reader right after the
read, and its next writer is at least one launch later.
Methods:
-
gains–The norm weight's 8 columns plus the gain center, FP32.
-
normalized–One BF16 route row RMS-normalized and scaled by the gains, FP32.
-
warp_sum_of_squares–The warp's sum of squares of one BF16 route row (scaled by the
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/moe/tail.py
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 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 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 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 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 | |
gains(words)
¶
The norm weight's 8 columns plus the gain center, FP32.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/moe/tail.py
normalized(packed, inv_rms, gains)
¶
One BF16 route row RMS-normalized and scaled by the gains, FP32.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/moe/tail.py
warp_sum_of_squares(packed, gains)
¶
The warp's sum of squares of one BF16 route row (scaled by the gains first with weight_before_norm).
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/moe/tail.py
_check_tail_args(capacity, unfinalized, out)
¶
Refuse a call either tail cannot take (before anything launches: the
other ranks would wait for this one). out must be dense: the kernels
write through its flat view.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/moe/tail.py
_route_views(unfinalized)
¶
The routed rows, the route weights and the route-to-row index as the tails' kernels take them.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/moe/tail.py
compile_publisher(constants, weight_dtype, *, tp, rank, capacity, enable_pdl)
¶
Compile the finalize publisher for one norm and route-weight dtype.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/moe/tail.py
compile_reduce(*, tp, capacity, enable_pdl)
¶
Compile the reduction for a [3, tp, capacity, P] mailbox.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/moe/tail.py
compile_tp_tail(constants, weight_dtype, *, tp, rank, split, slots, route_peers, generations, enable_pdl, timeout_ns=SPIN_TIMEOUT_NS)
¶
Compile the TP tail for one norm, route-weight dtype and band split.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/moe/tail.py
tail_constants(norm)
¶
The constants the stock post-expert finalize passes for norm (a
MuseSpark1xRMSNorm over the pooled width).
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/moe/tail.py
tail_weight(norm, device)
¶
The norm weight as the stock finalize hands it to the kernel: BF16 [P], ones without a weight (the gain center is added in FP32 in the kernel).
Source code in vllm/models/muse_spark/nvidia/specialized_decode/cutedsl/moe/tail.py
tp_split(m, tp, nsm)
¶
H bands per token of the TP tail for m tokens on nsm SMs, as
the stock TP finalize picks them; the split fixes the sum-of-squares tree,
so the tails agree bitwise.