vllm.models.minimax_m3.nvidia.specialized_decode.kernels.moe.host
¶
Host side of the fused MoE engine (kernel.py, 1..8 tokens): router, NVFP4 routed experts, MXFP8 shared expert on extra CTAs, combine and the push into the next layer, in one launch.
Classes:
-
M3MoeLayer–One MoE layer on a
M3MoeState:layer(hidden). The expert buffers are -
M3MoeState–Workspace + compiled kernel of
m3_moe(1..8 tokens per call) on one device,
Functions:
-
build_config–The engine's trace-time config (
M3_CONFIGof kernel.py) for one state; -
make_phase_plan–The work split of
m3_moefor each distinct-expert count G (4 .. 4 m_max): FC2 -
nb2_cap–FC2 output blocks per routed CTA (what make_phase_plan reports): ceil(H / 32 /
-
push_arp–The engine's
arpdescriptor for a push into a boundary exchange
M3MoeLayer
¶
One MoE layer on a M3MoeState: layer(hidden). The expert buffers are
read in place, never copied;
the per-expert scalars are packed once (layer constants: rebuild the layer after
reloading weights).
Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/moe/host.py
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 | |
M3MoeState
¶
Workspace + compiled kernel of m3_moe (1..8 tokens per call) on one device,
shared by the layers that run
on it in one stream order. shared: the shared expert runs on n_shared
dedicated CTAs beside the
num_ctas routed ones and the call returns bf16(shared + routed). push_ws (an
_exchange.PushWorkspace):
build the boundary push in (the call then pushes when given an arp). Build
before CUDA-graph capture; the
first call compiles.
Methods:
-
layer–One MoE layer's operands (the TRT-LLM-layout NVFP4 expert buffers, read in
Attributes:
-
maxnreg(int) –The register cap per thread the kernel is compiled with (0: ptxas
-
smem_bytes_upper_bound(int) –Upper bound of the kernel's shared memory per CTA (the ring + fixed operands
Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/moe/host.py
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 | |
maxnreg
property
¶
The register cap per thread the kernel is compiled with (0: ptxas chooses).
smem_bytes_upper_bound
property
¶
Upper bound of the kernel's shared memory per CTA (the ring + fixed operands + the small-array reserve).
_ext_args(route_lines, rt_tab, rctr=None)
¶
(lgbuf slot, x32 slot) for ext_route: route_lines ride in lgbuf's slot (unused without the router GEMV), rt_tab (ext_route=2) or the post's row counters rctr (ext_route=1) in x32's (unused with the fused router).
Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/moe/host.py
_x4_args(x4, x4sf)
¶
(logits slot, xsf32 slot): b1_x4 builds read the post's x4 values / scales there.
Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/moe/host.py
layer(w3_w1_weight, w3_w1_weight_scale, w2_weight, w2_weight_scale, fc31_alpha, fc31_scale_c, act_alpha, act_beta, act_clamp, fc2_alpha, e_score_correction_bias, router_weight=None, fc31_input_scale=None, shared_weights=None, route_lines=None, rt_tab=None, rctr=None, x4=None, x4sf=None)
¶
One MoE layer's operands (the TRT-LLM-layout NVFP4 expert buffers, read in
place, never copied).
shared_weights (a shared state): (gate_up e4m3 [2 I, 6144], its swizzled
UE8M0 scales, down e4m3
[6144, I], its swizzled UE8M0 scales). ext_route=1: route_lines int64
[route_repl][route_maxt][16] and
rctr int32 [>= M * 32]; ext_route=2: rt_tab int32 [M][4]. b1_x4=1:
x4 uint8 [>= M][3072] /
x4sf uint8 [max(M, 16) + 1][384] (fc1_per_token: row max(M, 16) = fp32
s_t).
Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/moe/host.py
_fine_ranges(weights, total)
¶
Contiguous FC1 item ranges [s_c, e_c) over the CTAs, sized as close to
weights (ideal real-valued item
counts summing to total) as the split-unit protocol allows: every unit (S1
items) has at most one CTA boundary
strictly inside it (its head and tail parts, summed by the tail's holder), so a
range that starts inside a unit
runs at least to that unit's end. Returns the item counts.
Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/moe/host.py
_kernel_module(config, path)
¶
kernel.py executed once per configuration with M3_CONFIG injected (its
constants are trace-time).
Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/moe/host.py
_maxnreg(n)
¶
.maxnreg n on the kernel compiled inside (CuTe DSL has no launch knob for it).
Patches a private CuTe DSL
hook (CuTeDSL._generate_kernel_attrs); verify it still exists in the pinned
nvidia-cutlass-dsl.
Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/moe/host.py
_pretile_shared(gu8, gusf8, dn8, dnsf8, n_cta=24)
¶
The shared expert's weights as m3_moe's shared CTAs stream them (SH_PRETILE): per CTA s, per stage g, the 16 KB shared-memory image (128-byte swizzle: 16-byte chunk j of row r at j ^ (r % 8)) of the stage's 128-row MMA tile and its 512-byte instruction scale atom (row R's 4 codes at word 4 (R % 32) + R / 32). CTA s owns P = SHARED_INTER / 24 = 16 positions in SPLIT = 128 / (2 P) = 4 K slices of GT = 48 / SPLIT = 12 k-tiles. Stages 0..GT-1: MMA row R = P O + i (O = 2 q + u: slice q, u 0 gate / 1 up) = weight row u SHARED_INTER + P s + i at k-tile GT q + g; then down tile j (rows 256 s + 128 j ..) at k-tile kt, j-major (SHARED_INTER / 128 k-tiles each). Built once per layer.
Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/moe/host.py
194 195 196 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 | |
_shared_views(shared_weights, who)
¶
(gate_up, its scales, down, its scales) of the shared expert as flat uint8 views, checked.
Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/moe/host.py
build_config(num_tokens, num_ctas, nb_cap, shared, n_shared, extra_cfg, push_world=0)
¶
The engine's trace-time config (M3_CONFIG of kernel.py) for one state;
pure (no device), so the configurations can be traced and checked without a
GPU.
Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/moe/host.py
make_phase_plan(num_ctas, m_max, lag=2, tail_w=1.0, early0=False, fine=FINE_PLAN, nb2=None, units=U1, ioff=0, boff=0, zero_ok=False)
¶
The work split of m3_moe for each distinct-expert count G (4 .. 4 m_max): FC2
32-row output blocks in
contiguous per-CTA ranges (the same for every group), and per group p (slots 4 p ..)
a range of its unit-major FC1
stages per CTA, balancing the bytes each CTA streams in phase p (FC1 of group p plus
FC2 of group p - lag, and the
trailing FC2s with the last group). Ranges are empty or >= 6 stages (a unit is split
over at most two CTAs); a
group too small for every CTA gets whole units on the CTAs with the least FC2 work,
or (fine) byte-balanced
ranges of any length with at most one CTA boundary inside a unit
(_fine_ranges). Returns int32
[4 m_max + 1, num_ctas, m_max + 1] (per group i0 | i1 << 16, then b0 | nb << 16) and
the largest block count.
Source code in vllm/models/minimax_m3/nvidia/specialized_decode/kernels/moe/host.py
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 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 | |
nb2_cap(num_ctas)
¶
FC2 output blocks per routed CTA (what make_phase_plan reports): ceil(H / 32 / num_ctas).
push_arp(ws, device)
¶
The engine's arp descriptor for a push into a boundary exchange
(_exchange.PushWorkspace):
int64 [1, &peers[0..ndst-1], flags, rank, world, maxt, 0, 0], peers = every rank's
exchange (unicast) or the
exchange's multicast address (ws.multicast, ndst 1). Returns (arp, peers); keep
peers alive as long
as arp.