vllm.models.inkling2.nvidia.ops.moe
¶
Inkling2 MoE kernels: top-k gate, the tile-padded expert row layout of the
expert GEMMs (trtllm_bmm) with the activations quantized into it, and the
top-k combine.
Functions:
-
combine–Sum each token's rows of
down(rows -1 count 0). -
combine_push–combineinto this rank's slots of the token shard owners -
route–Router, top-k and the tile-padded layout of the rows of the local
_group_sum(Partials, rows, cols, mask, T, E, GROUPS)
¶
In-order sum of the K-group partials [GROUPS, T, E] at (rows,
cols).
Source code in vllm/models/inkling2/nvidia/ops/moe.py
_key_values(values, keys, top)
¶
values [R, C] where keys [R, C] equals each of top [R, K].
_load_bias(Bias, E, E_POW2)
¶
The selection bias [1, E_POW2] (padding: 0) for _select_experts; a
weight, so it may load before gdc_wait.
Source code in vllm/models/inkling2/nvidia/ops/moe.py
_load_blocks(X, BLOCK)
¶
fp32 X[:BLOCK] (bf16), loaded so that each thread holds whole
32-column blocks.
Source code in vllm/models/inkling2/nvidia/ops/moe.py
_load_columns(X, blocks, mask)
¶
The 16 columns (a tuple of fp32 [32]) of the 16-column blocks
blocks of the bf16 row X, 16 bytes per load.
Source code in vllm/models/inkling2/nvidia/ops/moe.py
_local_experts(ids, lo, hi, padding)
¶
Local index of the experts ids [R, TOPK] among the local experts
[lo, hi) (-1: not local, or the token is padding; None: none
is).
Source code in vllm/models/inkling2/nvidia/ops/moe.py
_pick(values, index)
¶
values[index] for a small vector values and a scalar index.
_place_experts(Counts, Starts, Tiles, NUM_LOCAL, LOCAL_POW2, TILE, MAX_CTAS)
¶
Lays out the experts' rows (Counts, then reset) in TILE-row
tiles: stores each expert's first layout row, first routed row and end
row (Starts) and the Tiles metadata.
Source code in vllm/models/inkling2/nvidia/ops/moe.py
_place_rows(Starts, Ids, Ranks, Weights, Src2Dst, Gammas, Rows, token, TOPK, LOCAL_POW2)
¶
Places a token's local rows (_place_experts); returns their layout
rows (-1: not local) and local experts.
Source code in vllm/models/inkling2/nvidia/ops/moe.py
_place_token(masks, mine, local, weights, Src2Dst, Gammas, Rows, Tiles, token, TOPK, TILE, MAX_CTAS)
¶
Places the local rows of token token (_place_rows) for batches
of at most TILE tokens, whose experts take one tile each, from the
tokens of each local expert (masks, a bit per token; mine: those
of the token's experts local); stores the token's part of the
route outputs and returns its rows (-1: not local).
Source code in vllm/models/inkling2/nvidia/ops/moe.py
_quantize_row(X, amax, QValues, QScales, rows, H, TILE)
¶
Quantizes the bf16 row X with row amax amax to NVFP4 into each
of the rows rows (a tuple; negative: skipped), in a single-warp
program whose lanes each take whole blocks.
Source code in vllm/models/inkling2/nvidia/ops/moe.py
_quantize_x(X, token, H, NVFP4, HEAD, TAIL)
¶
Quantizes row token of X (columns [0, HEAD) and [HEAD,
HEAD + TAIL)); returns the values and block scales of both and the row
amax (NVFP4).
Source code in vllm/models/inkling2/nvidia/ops/moe.py
_routing_weights(log_probs, route_scale, TOPK)
¶
Renormalized sigmoid probabilities [R, TOPK] of the selected experts from their log-sigmoids.
Source code in vllm/models/inkling2/nvidia/ops/moe.py
_row_amax(X, H)
¶
Max |X[:H]| of a bf16 row, in a single-warp program.
Source code in vllm/models/inkling2/nvidia/ops/moe.py
_row_scales(amax, WAmax, WDenominator, local, NVFP4)
¶
The gate/up output scales of a row with amax amax in experts
local (NVFP4: (x_amax * w_amax) * rcp(1536 * denominator)).
Source code in vllm/models/inkling2/nvidia/ops/moe.py
_select_experts(Partials, bias, tokens, T, route_scale, E, E_POW2, GROUPS, TOPK, SORT)
¶
Top-k ids and routing weights [R, TOPK] of tokens tokens [R] from
the K-group logit partials [GROUPS, T, E] and the _load_bias
bias, by tl.topk (SORT) or k max passes.
Source code in vllm/models/inkling2/nvidia/ops/moe.py
_selection_keys(logits, bias, experts, E)
¶
Sort keys of the experts experts (padding: 0): order-preserving
bits of sigmoid(logit) + bias in the high word and the reversed expert
index in the low bits, so ties prefer the lower expert index.
Source code in vllm/models/inkling2/nvidia/ops/moe.py
_store_rows(Values, Scales, rows, start, values, scales, K, BLOCK, PACK, GROUP, TILE)
¶
Stores the quantized columns [start, start + BLOCK) (PACK per
value, one scale per GROUP) to each of rows (negative: skipped).
Source code in vllm/models/inkling2/nvidia/ops/moe.py
_store_x(QValues, QScales, QRowScales, quantized, dst, row_scales, H, NVFP4, HEAD, TAIL, TILE, BROADCAST)
¶
Stores a _quantize_x row to rows dst (negative: skipped), with
their row_scales (NVFP4). BROADCAST stores to all rows at once
(lower latency); otherwise to one local row after another (fewer
instructions).
Source code in vllm/models/inkling2/nvidia/ops/moe.py
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 | |
_top_keys(Partials, bias, tokens, T, E, E_POW2, GROUPS, TOPK)
¶
The logits and _selection_keys [R, E_POW2] of tokens tokens [R]
and their top-k keys [R, TOPK] (_select_experts).
Source code in vllm/models/inkling2/nvidia/ops/moe.py
_unpack_bf16(words)
¶
The 4 bf16 of each uint64 of words as fp32, lowest first.
Source code in vllm/models/inkling2/nvidia/ops/moe.py
combine(down, src2dst, topk, out_dtype)
¶
Sum each token's rows of down (rows -1 count 0).
Source code in vllm/models/inkling2/nvidia/ops/moe.py
combine_push(down, src2dst, topk, sp)
¶
combine into this rank's slots of the token shard owners
(SeqParallel.pushed), in bf16.
Source code in vllm/models/inkling2/nvidia/ops/moe.py
route(x, gate_weight, bias, counters, counts, topk, route_scale, expert_bounds, plan, weight_amax, weight_denominator, is_padding=None)
¶
Router, top-k and the tile-padded layout of the rows of the local
experts expert_bounds, with x quantized (NVFP4 with
weight_amax, else MXFP8) into it.
Returns (src2dst, gammas, rows, tiles): the layout row of each flat
(token * topk + slot) row (-1: not local), the routing weight of each
layout row, the routed layout rows in expert order and the tiles
metadata of trtllm_bmm.bmm followed by the number of routed rows; and
the quantized rows, their block scales and, for NVFP4, their gate/up
projection output scales. counters (NUM_COUNTERS) and counts
(one per local expert) are zeroed int32s that the kernels reset. Tokens
marked in the bool is_padding have no local rows on any rank: their
src2dst is -1, so they combine to 0.
Source code in vllm/models/inkling2/nvidia/ops/moe.py
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 1049 1050 1051 1052 1053 1054 | |