vllm.models.muse_spark.nvidia.specialized_decode.runtime.flashinfer_ops
¶
The specialized decode's only calls into FlashInfer; no other module of the package names the library:
- the routed experts: the TRT-LLM-gen MoE op the stock layer runs, with the stock
layer's own weights and arguments, stopping after GEMM2 (
do_finalize=False) so that the tail kernel finalizes. NVFP4 layers take routing prepared by the caller; the BF16 layers route inside the op from the router logits, as the stock layer does. - on NVFP4 layers, the op's own runner at the op's tactic, run from routing
metadata the routing kernel wrote (
MuseRouting) instead of the op's routing kernel, so the output is the op's bit for bit; a tactic without a prepared body takes the public op. - the TP16 all-reduce, through vLLM's own wrapper (the TP communicator's MNNVL all-reduce). TP4 and TP8 fuse their all-reduce into the attention boundary, summing in the order of the backend vLLM's FlashInfer all-reduce resolved to; across trays (TP8) build() still checks that it is the MNNVL one.
- with expert TP (
build(..., use_expert_tp=True)), the NVFP4 layers' routed op runs on TP experts (all experts at 1/tp of the intermediate width, resharded byexpert_tp) at one pinned tactic (EXPERT_TP_TACTICS); their GEMM2 rows are K-partials, whichTpTailsums across ranks.
The library is imported lazily inside the expert calls, as the stock experts do, so the package imports without it.
Classes:
-
FlashInferOps–RoutedExpertsOps: the routed experts of every MoE layer and the TP16 -
Nvfp4Call–One NVFP4 layer's routed experts op as the op runs them: its runner,
-
Nvfp4Plan–How one NVFP4 call runs below the public op: the op's tactic for these
Functions:
-
bf16_arguments–The per-layer arguments of the BF16 experts op, read from the stock
-
bf16_kv_insert–Whether this attention layer stores K/V with FlashInfer's bf16
-
bind_all_reduce–The TP communicator's FlashInfer all-reduce wrapper, checked to be the MNNVL
-
build–The routed expert ops for
layers(the stock decoder layers), built -
check_attention–Raises unless the stock attention layer runs the FlashInfer backend: the
-
default_tile–The tile the op runs an untuned tactic at (the launcher's
-
expected_calls–The library functions one decode step reaches through this module (NVFP4
-
gemm2_rows–The GEMM2 output rows the op allocates (bf16): the padded permuted rows,
-
library_rope–Whether a rotary embedding runs FlashInfer's RoPE instead of the stock
-
nvfp4_arguments–The per-layer arguments of the NVFP4 routed experts op, read from the stock
-
stock_all_reduce–The TP communicator's FlashInfer all-reduce wrapper, checked to take the
-
stock_experts–The stock experts kernel and RoutedExperts of a MuseSpark1xMoE.
-
stock_shards–One NVFP4 layer's stock EP experts, as
nvfp4_argumentsbound them, -
stock_sum_order–The sum order of the stock TP all-reduce (
stock_all_reduce's backend, -
tactic_key–(tile, config) of the op's tactic as its launcher resolves it: an
-
tp_arguments–args(nvfp4_arguments) on the layer's TP experts: their weights, -
tp_coordinator–The TP GroupCoordinator, given it or its device group.
-
trtllm_decode–Whether a layer's decode metadata is the TRT-LLM form attn2 reads (block
-
unsupported–The deployment requirements that name the library (the attention backend,
FlashInferOps
¶
RoutedExpertsOps: the routed experts of every MoE layer and the TP16
all-reduce.
build() binds every per-layer argument and checks every requirement once, then runs each op once at b = 8 (rank-symmetric; the all-reduce workspace is created lazily otherwise). The calls are graph-capturable and read no per-step state.
Methods:
-
all_reduce–The TP16 all-reduce of bf16 [b <= PREPARED_MAX, HIDDEN]: the stock
-
build–layers: the stock decoder layers (layer_idx, feed_forward). -
expert_tp_tactics–The preferred expert-TP tactics measured on the installed FlashInfer's
-
is_bf16–Whether the layer's experts are BF16 (they take normed BF16 rows and
-
is_expert_tp–Whether the layer's experts are TP (finalized by the TP tail)
-
log_expert_tp–Logs the expert-TP build: what was resharded, its memory, the build
-
nvfp4_plan–Host only, before the routing launches: the tactic for these inputs
-
pin_tp_tactic–The TP experts' tactic: the first of expert_tp_tactics() that the op
-
prepare_from_metadata–Prepares the NVFP4 layers' calls below the public op for 1 to
-
probe–Rel L2 of the layer's TP route rows, summed across ranks, against its
-
probe_inputs–The build probe's input at the decode batch, the same on every rank
-
public_routed_experts–The public routed op on
args. -
routed_experts–The NVFP4 expert input and its routed top-k -> the unfinalized
-
routed_experts_bf16–The normed rows (bf16 [b, POOLED]) + the router logits (fp32
-
routed_experts_from_metadata–The op's GEMMs at its tactic, from the routing metadata, without
-
shard_experts–Replaces every NVFP4 layer's arguments by its TP experts': reshard
-
slot–The op's nine routing metadata tensors, in its order, for the
-
warm_up–One call of each bound op at b = 8 on its first layer.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/flashinfer_ops.py
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 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 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 | |
all_reduce(x)
¶
The TP16 all-reduce of bf16 [b <= PREPARED_MAX, HIDDEN]: the stock layers' MNNVL all-reduce through vLLM's wrapper.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/flashinfer_ops.py
build(group, layers, use_expert_tp=False)
¶
layers: the stock decoder layers (layer_idx, feed_forward).
With use_expert_tp (collective over the TP group, which must equal the
stock layers' EP group), every NVFP4 layer runs on TP experts resharded
from the stock ones (finalized by the package's TP tail); BF16 layers
stay EP (stock weights, the EP tail).
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/flashinfer_ops.py
expert_tp_tactics()
staticmethod
¶
The preferred expert-TP tactics measured on the installed FlashInfer's batched-GEMM cubin package; none for any other package.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/flashinfer_ops.py
is_bf16(layer)
¶
Whether the layer's experts are BF16 (they take normed BF16 rows and
the router logits) rather than NVFP4 (ExpertsInput and
RoutedTopk).
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/flashinfer_ops.py
is_expert_tp(layer)
¶
Whether the layer's experts are TP (finalized by the TP tail) rather than EP (the EP tail).
log_expert_tp(tp, seconds)
¶
Logs the expert-TP build: what was resharded, its memory, the build probes and the tactic the decode batch takes (None: no body prepared for it, so the public op runs).
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/flashinfer_ops.py
nvfp4_plan(layer, inputs, topk)
¶
Host only, before the routing launches: the tactic for these inputs (on an expert-TP layer the pinned one, never the autotuner's; else the one the public op's autotuner takes) and the routing metadata it needs, or None (the public op runs, routing included) when no body was prepared for that tactic.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/flashinfer_ops.py
pin_tp_tactic(tp)
¶
The TP experts' tactic: the first of expert_tp_tactics() that the op
takes for 1 to ROUTING_MAX_TOKENS tokens and that has a prepared body,
on every rank of the TP group, else the op's untuned default.
Collective over tp's CPU group (every rank runs the same FlashInfer
build, so the same list); nothing is timed, so the same weights and
FlashInfer build take the same tactic at every start.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/flashinfer_ops.py
prepare_from_metadata()
¶
Prepares the NVFP4 layers' calls below the public op for 1 to ROUTING_MAX_TOKENS tokens: the routing metadata buffer, the routing scratch and one expert body workspace, each sized for the op's largest tactic, so a captured step's plan builds nothing. One buffer and one workspace serve every layer: a layer's routing waits for the previous layer's tail, the last reader.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/flashinfer_ops.py
probe(layer, tp_args, group, global_scale)
¶
Rel L2 of the layer's TP route rows, summed across ranks, against its stock EP rows on the same stock-quantized input (collective); raises above EXPERT_TP_PROBE_MAX on every rank.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/flashinfer_ops.py
probe_inputs(device, global_scale)
¶
The build probe's input at the decode batch, the same on every rank
(seeded): unit-RMS rows quantized with global_scale (the layer's
NVFP4 input global scale), so they stay in the range the layer's scales
were calibrated for, and routes spread over all experts, so every EP
rank serves some.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/flashinfer_ops.py
public_routed_experts(args, inputs, topk)
¶
The public routed op on args.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/flashinfer_ops.py
routed_experts(layer, inputs, topk, plan=None)
¶
The NVFP4 expert input and its routed top-k -> the unfinalized
expert output, on an NVFP4 layer. With plan (nvfp4_plan for
these inputs), from the metadata the routing wrote for it.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/flashinfer_ops.py
routed_experts_bf16(layer, x, router_logits)
¶
The normed rows (bf16 [b, POOLED]) + the router logits (fp32 [b, NUM_EXPERTS]) -> the unfinalized expert output, on a BF16 layer; the op routes, so its expert weights are bf16.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/flashinfer_ops.py
routed_experts_from_metadata(inputs, topk, plan)
¶
The op's GEMMs at its tactic, from the routing metadata, without its routing kernel. Returns the op's unfinalized output at its extents: the GEMM2 rows it allocates, the routing weights, the permutation.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/flashinfer_ops.py
shard_experts(tp, layers)
¶
Replaces every NVFP4 layer's arguments by its TP experts': reshard
(collective) and a probe against the stock EP op. Collective over
tp: the placement check is agreed across the ranks before any
rank raises, so none is left waiting in the reshard.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/flashinfer_ops.py
slot(metadata, weights)
¶
The op's nine routing metadata tensors, in its order, for the
tokens of weights (fp32 [b, TOP_K], the routing's).
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/flashinfer_ops.py
warm_up()
¶
One call of each bound op at b = 8 on its first layer.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/flashinfer_ops.py
Nvfp4Call
¶
One NVFP4 layer's routed experts op as the op runs them: its runner,
inputs, tuning config and runner kwargs, built as
trtllm_fp4_block_scale_moe_op builds them for the arguments
nvfp4_arguments binds, so the autotuner picks the op's tactic and the
runner launches the op's GEMMs.
Methods:
-
bind–Builds the runner and, for 1 to
max_tokenstokens, the -
prepare–(runner, inputs, tuning config, runner kwargs) for these inputs;
-
runner_kwargs–The runner's keyword arguments, as the op passes them.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/flashinfer_ops.py
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 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 452 453 | |
bind(device, max_tokens)
¶
Builds the runner and, for 1 to max_tokens tokens, the
output placeholder and tuning config, so that prepare only
assembles a call's inputs.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/flashinfer_ops.py
prepare(inputs, topk)
¶
(runner, inputs, tuning config, runner kwargs) for these inputs;
allocates and builds nothing for a token count bind covered.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/flashinfer_ops.py
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 | |
runner_kwargs(enable_pdl)
¶
The runner's keyword arguments, as the op passes them.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/flashinfer_ops.py
Nvfp4Plan
¶
Bases: NamedTuple
How one NVFP4 call runs below the public op: the op's tactic for these inputs as (tile, config), where the routing writes the metadata at that tile, and the prepared call (runner, inputs, runner kwargs).
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/flashinfer_ops.py
_finite(rows)
¶
How finite rows are, and their largest finite magnitude.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/flashinfer_ops.py
bf16_arguments(experts, routed)
¶
The per-layer arguments of the BF16 experts op, read from the stock TrtLlmBf16ExpertsMonolithic and its RoutedExperts as the stock layer passes them (RoutedExperts.forward_monolithic -> apply_monolithic -> apply, with the post-expert-norm hook attached, so do_finalize=False).
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/flashinfer_ops.py
bf16_kv_insert(attn, num_kv_heads, head_dim)
¶
Whether this attention layer stores K/V with FlashInfer's bf16
reshape_and_cache_flash (FlashInferImpl.do_kv_cache_update), whose
HND cache layout the draft's fused context K/V store writes.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/flashinfer_ops.py
bind_all_reduce(communicator)
¶
The TP communicator's FlashInfer all-reduce wrapper, checked to be the MNNVL
all-reduce the stock layers take for [PREPARED_MAX, HIDDEN] bf16
(stock_all_reduce).
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/flashinfer_ops.py
build(group, layers, use_expert_tp=False)
¶
The routed expert ops for layers (the stock decoder layers), built
and warmed up.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/flashinfer_ops.py
check_attention(attention)
¶
Raises unless the stock attention layer runs the FlashInfer backend: the executor reads its decode metadata (block table, sequence lengths) and its KV cache layout.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/flashinfer_ops.py
default_tile(num_tokens, num_local_experts)
¶
The tile the op runs an untuned tactic at (the launcher's selectDefaultTileN): the smallest of its candidates, the first tile that covers the average routes per local expert and its neighbours.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/flashinfer_ops.py
expected_calls(tp, bf16_layers)
¶
The library functions one decode step reaches through this module (NVFP4 layers: the entry below the public op, expert TP or not; the public op only where a tactic has no prepared body, which is logged).
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/flashinfer_ops.py
gemm2_rows(num_tokens, tile, hidden_out)
¶
The GEMM2 output rows the op allocates (bf16): the padded permuted rows, at least 128 KiB.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/flashinfer_ops.py
library_rope(rotary_emb)
¶
Whether a rotary embedding runs FlashInfer's RoPE instead of the stock CUDA op.
nvfp4_arguments(experts, routed)
¶
The per-layer arguments of the NVFP4 routed experts op, read from the stock MuseSparkTrtLlmNvFp4Experts and its RoutedExperts as apply_routed passes them (vllm/models/muse_spark/nvidia/muse_moe_runner.py, apply_routed).
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/flashinfer_ops.py
stock_all_reduce(communicator)
¶
The TP communicator's FlashInfer all-reduce wrapper, checked to take the decode's [PREPARED_MAX, HIDDEN] bf16 rows (so the stock layers' all-reduce is this one), and the backend its workspace resolved to (VLLM_FLASHINFER_ALLREDUCE_BACKEND; auto: MNNVL, on one node TRT-LLM where MNNVL has no multicast). Creates the workspace on first use, collectively over the TP group, as the stock path does; vLLM keeps one per process, so every caller reads the same backend.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/flashinfer_ops.py
stock_experts(moe)
¶
The stock experts kernel and RoutedExperts of a MuseSpark1xMoE.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/flashinfer_ops.py
stock_shards(args, experts)
¶
One NVFP4 layer's stock EP experts, as nvfp4_arguments bound them,
for the expert-TP reshard.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/flashinfer_ops.py
stock_sum_order(communicator)
¶
The sum order of the stock TP all-reduce (stock_all_reduce's backend,
BACKEND_SUM_ORDERS), the one the fused all-reduces over the TP group
take. Raises for a backend whose order they do not reproduce. Collective
over the TP group on the process's first call.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/flashinfer_ops.py
tactic_key(tactic, num_tokens, num_local_experts)
¶
(tile, config) of the op's tactic as its launcher resolves it: an untuned tactic (-1 anywhere) runs its default config at the default tile.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/flashinfer_ops.py
tp_arguments(args, tp)
¶
args (nvfp4_arguments) on the layer's TP experts: their weights,
block scales and per-expert scalars, every expert local, the intermediate
slice, and tune_max_num_tokens at ROUTING_MAX_TOKENS, the most tokens
the executor runs them at. The rest (routing, activation, global expert
count) is the stock layer's.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/flashinfer_ops.py
tp_coordinator(group)
¶
The TP GroupCoordinator, given it or its device group.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/flashinfer_ops.py
trtllm_decode(metadata)
¶
Whether a layer's decode metadata is the TRT-LLM form attn2 reads (block table and sequence lengths), not the native decode wrapper's.
Source code in vllm/models/muse_spark/nvidia/specialized_decode/runtime/flashinfer_ops.py
unsupported(vllm_config)
¶
The deployment requirements that name the library (the attention backend, vLLM's FlashInfer all-reduce and, at TP8/16, its MNNVL backend), or None.