vllm.models.deepseek_v41.nvidia.specialized_decode.ampere.all_reduce
¶
The TP all-reduce of DeepSeek-V4.1's decode boundaries on SM80, in CuTe DSL.
Every decode layer of DeepSeek-V4.1 all-reduces two partial sums across the
tensor-parallel ranks: the attention output projection's and the MoE's, one
BF16 row of hidden values per token (24 rows at four requests with five
drafts each, 245 KB at TP8). vLLM's custom all-reduce does it by loading:
below 256 KB at TP8 each rank reads every peer's whole buffer over NVLink
(one-shot), above it a reduce-scatter and an all-gather separated by
barriers (two-shot). On A100 both are latency-bound at decode sizes, about
28 us at 24 rows and 25 us at 48, several times what the bytes need.
TwoShotAllReduce pushes instead of loading, and synchronizes through the
data rather than with barriers (a Lamport mailbox): every slot of a rank's
mailbox holds a sentinel, BF16 negative zero, until a peer's store replaces
it, so a reader polls a slot until none of its values is the sentinel.
Senders turn real negative zeros into positive zeros. One CTA per row, one
16-byte fragment (8 values) per thread, three phases:
- Scatter. Each thread stores its fragment of the local partial into
the mailbox of the rank that owns the fragment's slice of the row (rank
sowns fragmentss * hidden / (8 * world)onward). - Reduce. The row's fragments of this rank's slice, times the
worldsources, are one per thread: groups ofworldlanes poll one fragment from every source, add them in FP32 with a butterfly (every lane gets the same bits), round to BF16, and each lane stores the sum into one rank's mailbox. - Gather. Each thread polls its fragment of the reduced row in its own mailbox and writes it to the output.
Each rank sends 2 (world - 1) / world of the row instead of
world - 1 rows, and no phase waits for anything but its own data.
A reader resets the slots it consumed to the sentinel. The mailbox has three generations, and each row (CTA) keeps the generation its next call uses, advanced modulo three by every call: a peer writes the same generation of a row again three calls later, which needs this rank's push of two calls later, issued after this call completed. All ranks run the same sequence of calls with the same row counts, so a row's generation agrees across ranks; it is per row because a call of fewer rows leaves the other rows' generations alone. The mailbox starts as sentinels and the generations at zero, so the kernel needs no per-launch initialization and is CUDA-graph safe.
A row's CTA waits for the same row's CTA on every peer, so all of a call's
CTAs must be resident at once on every rank. A call therefore launches at
most one CTA per SM, whatever the kernel's registers, and above that many
rows each CTA takes rows ctas apart in increasing order: the lowest
unfinished row is then in progress on every rank, so every call completes.
This also needs every kernel that runs beside a call to finish without
waiting on it, which holds for the only one, the side-stream mHC
coefficients.
TwoShotAllReducePostCollapse is the same all-reduce followed, in the
same CTA, by the mHC boundary's post-mix, collapse and RMSNorm
(mhc.PostCollapse, whose CTAs have the same shape: a row per CTA, eight
values per thread). The loads that do not depend on the sum (the row's
streams, mixes and norm weight) are issued before the scatter, so they
overlap the waits, and the reduced row never goes back to memory: the
boundary saves a launch and a round trip of the sublayer output.
TwoShotAllReduceFinalizePostCollapse takes a MoE output whose top-k
reduction is still open (UnfinalizedMoEOutput with one unweighted GEMM2
row per route, routes of a token adjacent): before the scatter, each thread
forms its fragment of the rank's partial row from the token's top_k
route rows, their routing weights and the shared expert's row. The MoE's
top-k sum and shared-expert add then need no kernels of their own, as on
SM90, whose fused all-reduce does the same.
Numerics: each rank's slice sums the world partials in FP32 in a fixed
butterfly order and rounds once to BF16, so every rank gets the same bits;
the order differs from vLLM's kernels, so results differ from theirs by FP32
rounding of the sum. The fused variant's results are bitwise those of the
all-reduce followed by PostCollapse. The finalize variant forms the
partial row in FP32, a fused multiply-add per route in route order plus the
shared row, rounded once to BF16 (as SM90's kernel), so it differs from
vLLM's own top-k sum by rounding.
Classes:
-
AmpereAllReduce–The mailbox and per-row generations of
TwoShotAllReducefor one TP -
TwoShotAllReduce–The push-based two-shot Lamport all-reduce; see the module docstring.
-
TwoShotAllReduceFinalizePostCollapse–TwoShotAllReducePostCollapseof a MoE output with its top-k -
TwoShotAllReducePostCollapse–TwoShotAllReducefollowed in the same CTA byPostCollapse
Functions:
-
load_fragment–A 16-byte fragment as four words;
volatilefor polling a slot that -
load_u64–One 64-bit word that the kernel only reads (a mailbox base).
-
poll–Wait until the slot at
addressholds no sentinel, read it into -
store_fragment–Store a 16-byte fragment, to this rank's memory or a peer's.
AmpereAllReduce
¶
The mailbox and per-row generations of TwoShotAllReduce for one TP
group; construction is collective over the group.
Parameters:
-
(group¶ProcessGroup) –The TP group's device process group.
-
(hidden¶int) –Values per row.
-
(device¶device) –This rank's device.
-
(capacity¶int, default:MAX_ROWS) –The most rows a call takes (
MAX_ROWSby default). -
(top_k¶int | None, default:None) –Routes a token of the MoE outputs
finalize_post_collapsetakes; None compiles no finalize kernels.
Methods:
-
__call__–The sum of
xover the TP group, as a new tensor. -
finalize_post_collapse–post_collapseof a MoE output with its top-k reduction open: -
post_collapse–The sum of
xover the TP group, post-mixed into the streams, -
supports–Whether a call takes
x: up tocapacitycontiguous BF16
Source code in vllm/models/deepseek_v41/nvidia/specialized_decode/ampere/all_reduce.py
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 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 | |
__call__(x)
¶
The sum of x over the TP group, as a new tensor.
Source code in vllm/models/deepseek_v41/nvidia/specialized_decode/ampere/all_reduce.py
_collapse_args(rows, residual, post_mix, comb_mix, pre_mix, norm_weight, write_aux)
¶
The outputs of a collapsing call of rows rows, its kernel
arguments after the sublayer output up to the CTA count, and the
mixes those point to, which the caller keeps until the launch (they
may be contiguous copies).
Source code in vllm/models/deepseek_v41/nvidia/specialized_decode/ampere/all_reduce.py
finalize_post_collapse(routes, route_weights, shared, residual, post_mix, comb_mix, pre_mix, norm_weight, norm_eps, write_aux=False)
¶
post_collapse of a MoE output with its top-k reduction open:
the sublayer output of token t is shared[t] plus the sum over
k of route_weights[t, k] * routes[t * top_k + k]. routes
holds the unweighted GEMM2 rows, route_weights the FP32 routing
weights [rows, top_k], shared the shared expert's rows.
Source code in vllm/models/deepseek_v41/nvidia/specialized_decode/ampere/all_reduce.py
post_collapse(x, residual, post_mix, comb_mix, pre_mix, norm_weight, norm_eps, write_aux=False)
¶
The sum of x over the TP group, post-mixed into the streams,
collapsed and normalized as mhc.mhc_post_collapse does with the
sum: the new streams, the layer input and the stream mean (empty
without write_aux). post_mix is [rows, 4] or
[rows, 4, 1], comb_mix [rows, 4, 4]; pre_mix None
selects stream zero.
Source code in vllm/models/deepseek_v41/nvidia/specialized_decode/ampere/all_reduce.py
supports(x)
¶
Whether a call takes x: up to capacity contiguous BF16
rows of hidden values, 16-byte aligned.
Source code in vllm/models/deepseek_v41/nvidia/specialized_decode/ampere/all_reduce.py
TwoShotAllReduce
¶
The push-based two-shot Lamport all-reduce; see the module docstring.
world ranks, rows of hidden BF16 values, at most capacity
rows a call.
Methods:
-
gather_slot–Byte offset of a gather slot in a mailbox.
-
mailbox_bytes–Bytes of a rank's mailbox: scatter and gather slots, three
-
reduce_row–The three phases for row
row(one CTA), from threadtid's -
scatter_slot–Byte offset of a scatter slot in a mailbox.
Source code in vllm/models/deepseek_v41/nvidia/specialized_decode/ampere/all_reduce.py
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 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 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 | |
gather_slot(generation, row, fragment)
¶
Byte offset of a gather slot in a mailbox.
Source code in vllm/models/deepseek_v41/nvidia/specialized_decode/ampere/all_reduce.py
mailbox_bytes()
¶
Bytes of a rank's mailbox: scatter and gather slots, three generations each.
reduce_row(partial, peers, rank, generation, row, tid, words)
¶
The three phases for row row (one CTA), from thread tid's
fragment of this rank's partial row (four packed words), leaving its
fragment of the reduced row in words.
Source code in vllm/models/deepseek_v41/nvidia/specialized_decode/ampere/all_reduce.py
scatter_slot(generation, source, row, fragment)
¶
Byte offset of a scatter slot in a mailbox.
Source code in vllm/models/deepseek_v41/nvidia/specialized_decode/ampere/all_reduce.py
TwoShotAllReduceFinalizePostCollapse
¶
Bases: TwoShotAllReducePostCollapse
TwoShotAllReducePostCollapse of a MoE output with its top-k
reduction open, top_k routes a token; see the module docstring.
Source code in vllm/models/deepseek_v41/nvidia/specialized_decode/ampere/all_reduce.py
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 | |
TwoShotAllReducePostCollapse
¶
Bases: TwoShotAllReduce
TwoShotAllReduce followed in the same CTA by PostCollapse
(with the post-mix); see the module docstring.
Source code in vllm/models/deepseek_v41/nvidia/specialized_decode/ampere/all_reduce.py
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 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 | |
_asm(result, operands, text, constraints, side_effects, loc, ip)
¶
One inline PTX statement.
Source code in vllm/models/deepseek_v41/nvidia/specialized_decode/ampere/all_reduce.py
_collapse_kernel(device_index, hidden, world, capacity, write_aux)
cached
¶
TwoShotAllReducePostCollapse compiled for a device and variant.
Source code in vllm/models/deepseek_v41/nvidia/specialized_decode/ampere/all_reduce.py
_finalize_kernel(device_index, hidden, world, capacity, write_aux, top_k)
cached
¶
TwoShotAllReduceFinalizePostCollapse compiled for a device and
variant.
Source code in vllm/models/deepseek_v41/nvidia/specialized_decode/ampere/all_reduce.py
_kernel(device_index, hidden, world, capacity)
cached
¶
TwoShotAllReduce compiled for a device and shape.
Source code in vllm/models/deepseek_v41/nvidia/specialized_decode/ampere/all_reduce.py
load_fragment(address, *, volatile=False, loc=None, ip=None)
¶
A 16-byte fragment as four words; volatile for polling a slot that
peers store into.
Source code in vllm/models/deepseek_v41/nvidia/specialized_decode/ampere/all_reduce.py
load_u64(address, *, loc=None, ip=None)
¶
One 64-bit word that the kernel only reads (a mailbox base).
Source code in vllm/models/deepseek_v41/nvidia/specialized_decode/ampere/all_reduce.py
poll(address, words)
¶
Wait until the slot at address holds no sentinel, read it into
words and reset it to the sentinel.
Source code in vllm/models/deepseek_v41/nvidia/specialized_decode/ampere/all_reduce.py
store_fragment(address, words)
¶
Store a 16-byte fragment, to this rank's memory or a peer's.