vllm.models.deepseek_v41.nvidia.specialized_decode.sampling.sharded_markov_cute
¶
DSpark's sequential Markov sampling for a small batch, in CuTe DSL.
The kernel samples up to 8 request rows, with the Markov head sharded by
vocabulary across the tensor-parallel ranks (sharded_markov.py explains the
design). It is compiled for a number of draft positions steps (1..8) and
the element types of the base logits and of the draft-logits cache (BF16 or
FP32).
For request r, step i needs r's previous token p (its anchor for
i = 0)::
logits_ri = cache_round(base_ri + bf16(markov_head . markov_embed[p]))
d_r,i+1 = argmax(logits_ri) (temperature 0)
= argmax(logits_ri / T_r + gumbel_ri) (otherwise)
Each rank owns rows [rank * V/world, (rank + 1) * V/world) of the head.
Each warp keeps one 16-row tile of that shard in registers for all steps, so
the head is read once per launch; the m16n8k16 MMA's eight columns carry the
eight request rows' embeddings, so every row's bias comes from the same MMAs.
A step is those MMAs, a CTA reduction and a two-level exchange of 64-bit
candidate keys per request row: the CTAs of a rank fold their best key into a
rank-local maximum, the last CTA to arrive stores that key, tagged with the
launch epoch, into every rank's mailbox, and every CTA waits for the world
records of each row in its own mailbox and takes their maximum. The exchange is
the grid barrier and the cross-rank argmax at once, so the grid must be
co-resident: the kernel is launched cooperatively, and its 512-thread
requirement keeps one CTA per SM within the register file.
The base logits may hold the full vocabulary or only this rank's shard (the
draft LM head's output before its all-gather): base_column is the column of
this rank's first vocabulary entry in them, rank * V/world or 0.
Rows whose request-state index is negative (CUDA-graph padding) are inert, as in the speculator's loop: their tokens are drawn greedily and their logits are not cached.
The draft-logits cache must hold the full vocabulary on every rank. Each rank writes its shard into its own cache and into a staging buffer of every peer; after the last exchange each rank copies the peers' shards from its staging buffer into its cache. Staging and mailbox records alternate between two parities so that a launch never overwrites what a peer may still be reading from the previous launch.
Peer buffer layout (bytes): mailbox records u64
[parity 2][step 8][row 8][source rank 8] (8 KiB), then the staging logits
[parity 2][max_rows][steps][vocab] of the cache type at STAGING_OFFSET.
Local control words (uint32): combine maxima u64 [step 8][row 8] at words
0..127, arrivals [step 8] at 128..135, launches at 136, end arrivals at 137.
Global memory is addressed with 64-bit integers and accessed with explicit PTX, so that each access has the state space, cache operator and memory ordering the protocol needs (relaxed system-scope mailbox records, L2-only staging reads, non-coherent reads of the weights).
Classes:
-
ShardedMarkovSample–The sharded Markov chain kernel for
stepsdraft positions, base
Functions:
-
add_rn–FP32 add, never contracted into a neighbouring multiply.
-
atomic–A global atomic returning the old value (
opcodee.g. -
await_record–Spin until the mailbox record at
addresscarriestag; return -
candidate_key–[48:17] order-preserving score bits, [16:0] inverted index (ties prefer
-
div_full–div.full.f32: Triton's FP32/, as the stock sampler divides. -
fence–membar.gl(__threadfence) ormembar.sys -
float_bits–The bits of an FP32 value.
-
key_index–The vocabulary index of a candidate key.
-
load_bf16_as_f32–A global BF16 value, widened.
-
load_scalar–One 32- or 64-bit global value of DSL type
kind(opcodenames -
load_shared_v4–Four 32-bit words at a 16-byte aligned shared address.
-
load_v4–Four 32-bit words at a 16-byte aligned global address.
-
max_u64–The larger of two keys (unsigned; tensor loads come back signed).
-
mma_16816–mma.sync.aligned.m16n8k16.row.col.f32.bf16.bf16.f32:accfour -
prefetch_row_l2–Pull one 512-byte row into L2.
-
round_bf16–valuerounded to BF16 (nearest even) and widened back. -
shared_address–The shared-window address of a shared-memory pointer.
-
shuffle_idx_u64–__shfl_syncof a 64-bit value from lanesource. -
shuffle_xor_u64–__shfl_xor_syncof a 64-bit value over the full warp. -
store_global_v4–st.global.v4.u32. -
store_scalar–One 32- or 64-bit global store (
opcode, e.g.st.global.u32). -
store_shared_v4–st.shared.v4.u32. -
trap–Abort the kernel.
ShardedMarkovSample
¶
The sharded Markov chain kernel for steps draft positions, base
logits of base_dtype and a draft-logits cache of cache_dtype
(cutlass.BFloat16 or cutlass.Float32).
Methods:
-
__call__–Launch the chain as a cooperative grid of
ctasCTAs. -
kernel–One CTA of 16 warps; see the module docstring.
-
load_base–Base logit of request row
r,stepand shard rowrow. -
load_inputs–Base logits and noise of this lane's resident tile rows and request
-
load_noise–Gumbel noise of request row
r,stepand shard rowrow. -
peer_base–The base address of
peer's buffer.
Source code in vllm/models/deepseek_v41/nvidia/specialized_decode/sampling/sharded_markov_cute.py
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 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 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 | |
__call__(base_logits, base_row_stride, base_step_stride, base_column, embed_table, head, input_ids, query_per_row, idx_mapping, temperature, noise, logits_cache, cache_stride0, cache_stride1, draft_tokens, draft_stride, peers, control, rank, world, vocab_local, rows, max_rows, timeout_ns, ctas, stream)
¶
Launch the chain as a cooperative grid of ctas CTAs.
Source code in vllm/models/deepseek_v41/nvidia/specialized_decode/sampling/sharded_markov_cute.py
kernel(base_logits, base_row_stride, base_step_stride, base_column, embed_table, head, input_ids, query_per_row, idx_mapping, temperature, noise, logits_cache, cache_stride0, cache_stride1, draft_tokens, draft_stride, peers, control, rank, world, vocab_local, rows, max_rows, timeout_ns)
¶
One CTA of 16 warps; see the module docstring.
Source code in vllm/models/deepseek_v41/nvidia/specialized_decode/sampling/sharded_markov_cute.py
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 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 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 | |
load_base(base_logits, row_stride, step_stride, column, r, step, row)
¶
Base logit of request row r, step and shard row row.
Source code in vllm/models/deepseek_v41/nvidia/specialized_decode/sampling/sharded_markov_cute.py
load_inputs(base, gumbel, step, tile, g, t, rows, base_logits, row_stride, step_stride, column, noise, vocab_local)
¶
Base logits and noise of this lane's resident tile rows and request
rows for step: base/gumbel [col * 2 + half].
Source code in vllm/models/deepseek_v41/nvidia/specialized_decode/sampling/sharded_markov_cute.py
load_noise(noise, r, step, row, vocab_local)
¶
Gumbel noise of request row r, step and shard row row.
Source code in vllm/models/deepseek_v41/nvidia/specialized_decode/sampling/sharded_markov_cute.py
peer_base(peers, peer)
¶
The base address of peer's buffer.
_asm(result, operands, text, constraints, effects, loc, ip)
¶
A PTX inline assembly operation; effects keeps it in program order
with the other side-effecting operations.
Source code in vllm/models/deepseek_v41/nvidia/specialized_decode/sampling/sharded_markov_cute.py
_fields(result, count, kind, loc, ip)
¶
The count fields of an inline assembly struct result as kind.
Source code in vllm/models/deepseek_v41/nvidia/specialized_decode/sampling/sharded_markov_cute.py
_values(values, loc, ip)
¶
add_rn(a, b, *, loc=None, ip=None)
¶
FP32 add, never contracted into a neighbouring multiply.
Source code in vllm/models/deepseek_v41/nvidia/specialized_decode/sampling/sharded_markov_cute.py
atomic(address, value, opcode, *, loc=None, ip=None)
¶
A global atomic returning the old value (opcode e.g.
atom.global.add.u32); value is Uint32 or Uint64.
Source code in vllm/models/deepseek_v41/nvidia/specialized_decode/sampling/sharded_markov_cute.py
await_record(address, tag, timeout_ns, step, source)
¶
Spin until the mailbox record at address carries tag; return
its key. With a positive timeout_ns a wait that exceeds it reports and
traps instead of hanging (debug aid for ranks that disagree on the launch
sequence).
Source code in vllm/models/deepseek_v41/nvidia/specialized_decode/sampling/sharded_markov_cute.py
candidate_key(score, index)
¶
[48:17] order-preserving score bits, [16:0] inverted index (ties prefer
the smaller index, as torch.argmax does). Larger is better; 0 means "no
key".
Source code in vllm/models/deepseek_v41/nvidia/specialized_decode/sampling/sharded_markov_cute.py
div_full(a, b, *, loc=None, ip=None)
¶
div.full.f32: Triton's FP32 /, as the stock sampler divides.
Source code in vllm/models/deepseek_v41/nvidia/specialized_decode/sampling/sharded_markov_cute.py
fence(scope, *, loc=None, ip=None)
¶
membar.gl (__threadfence) or membar.sys
(__threadfence_system).
Source code in vllm/models/deepseek_v41/nvidia/specialized_decode/sampling/sharded_markov_cute.py
float_bits(value, *, loc=None, ip=None)
¶
The bits of an FP32 value.
Source code in vllm/models/deepseek_v41/nvidia/specialized_decode/sampling/sharded_markov_cute.py
key_index(key)
¶
The vocabulary index of a candidate key.
load_bf16_as_f32(address, *, loc=None, ip=None)
¶
A global BF16 value, widened.
Source code in vllm/models/deepseek_v41/nvidia/specialized_decode/sampling/sharded_markov_cute.py
load_scalar(address, opcode, kind, effects=False, *, loc=None, ip=None)
¶
One 32- or 64-bit global value of DSL type kind (opcode names
the load, e.g. ld.global.nc.u64).
Source code in vllm/models/deepseek_v41/nvidia/specialized_decode/sampling/sharded_markov_cute.py
load_shared_v4(address, *, loc=None, ip=None)
¶
Four 32-bit words at a 16-byte aligned shared address.
Source code in vllm/models/deepseek_v41/nvidia/specialized_decode/sampling/sharded_markov_cute.py
load_v4(address, opcode, effects, *, loc=None, ip=None)
¶
Four 32-bit words at a 16-byte aligned global address.
Source code in vllm/models/deepseek_v41/nvidia/specialized_decode/sampling/sharded_markov_cute.py
max_u64(a, b)
¶
The larger of two keys (unsigned; tensor loads come back signed).
Source code in vllm/models/deepseek_v41/nvidia/specialized_decode/sampling/sharded_markov_cute.py
mma_16816(acc, a, b, *, loc=None, ip=None)
¶
mma.sync.aligned.m16n8k16.row.col.f32.bf16.bf16.f32: acc four
FP32, a four and b two packed BF16 pairs.
Source code in vllm/models/deepseek_v41/nvidia/specialized_decode/sampling/sharded_markov_cute.py
prefetch_row_l2(address, *, loc=None, ip=None)
¶
Pull one 512-byte row into L2.
Source code in vllm/models/deepseek_v41/nvidia/specialized_decode/sampling/sharded_markov_cute.py
round_bf16(value, *, loc=None, ip=None)
¶
value rounded to BF16 (nearest even) and widened back.
Source code in vllm/models/deepseek_v41/nvidia/specialized_decode/sampling/sharded_markov_cute.py
shared_address(pointer, *, loc=None, ip=None)
¶
The shared-window address of a shared-memory pointer.
Source code in vllm/models/deepseek_v41/nvidia/specialized_decode/sampling/sharded_markov_cute.py
shuffle_idx_u64(value, source)
¶
__shfl_sync of a 64-bit value from lane source.
Source code in vllm/models/deepseek_v41/nvidia/specialized_decode/sampling/sharded_markov_cute.py
shuffle_xor_u64(value, offset)
¶
__shfl_xor_sync of a 64-bit value over the full warp.
Source code in vllm/models/deepseek_v41/nvidia/specialized_decode/sampling/sharded_markov_cute.py
store_global_v4(address, words, *, loc=None, ip=None)
¶
st.global.v4.u32.
Source code in vllm/models/deepseek_v41/nvidia/specialized_decode/sampling/sharded_markov_cute.py
store_scalar(address, value, opcode, *, loc=None, ip=None)
¶
One 32- or 64-bit global store (opcode, e.g. st.global.u32).
Source code in vllm/models/deepseek_v41/nvidia/specialized_decode/sampling/sharded_markov_cute.py
store_shared_v4(address, words, *, loc=None, ip=None)
¶
st.shared.v4.u32.