vllm.model_executor.layers.fused_moe.moe_output
¶
Output contract between a MoE layer and a consumer that fuses its tail.
Classes:
-
MoEOutput–A MoE layer's output with its final reduction still open.
-
UnfinalizedMoEOutput–Unfinalized output of a MoE kernel.
Functions:
-
convert_flashinfer_moe_output–Normalize the two FlashInfer TRTLLM MoE return layouts.
-
route_major_moe_output–Wrap one-row-per-route GEMM2 output; remote routes map to
-1.
MoEOutput
dataclass
¶
A MoE layer's output with its final reduction still open.
Returned by layers whose MoE runs un-reduced (reduce_results=False) so
that the consumer -- typically the next layer's RMSNorm -- can fuse the
tensor-parallel all-reduce into itself instead of paying for a standalone
one. Keeping the shared-expert output and the routed scale separate leaves
that reduction the consumer's to schedule; when the routed output is still
unfinalized, the top-k reduction is open too and can fold into the same
kernel.
Producers only leave the routed output unfinalized when a fused consumer can
actually take that form -- the token ceiling and topology support are theirs
to check -- so an UnfinalizedMoEOutput here means the fused path applies,
and a consumer need not re-derive that.
Source code in vllm/model_executor/layers/fused_moe/moe_output.py
UnfinalizedMoEOutput
dataclass
¶
Unfinalized output of a MoE kernel.
Kernels that can stop after GEMM2 (the TRTLLM-Gen do_finalize=False path)
hand back their permuted, unweighted output plus the routing weights and the
permute map, so that the top-k reduction can be fused with whatever follows
-- the shared-expert add and the tensor-parallel all-reduce -- instead of
running as its own kernel.
The buffers are consumed as-is by the fused kernels, which index
gemm2_permuted by row: it must be densely packed at hidden_dim, and
its row count (an autotuner-dependent padded value) is never referenced.
Source code in vllm/model_executor/layers/fused_moe/moe_output.py
convert_flashinfer_moe_output(flashinfer_output, *, do_finalize, num_tokens, top_k, finalized_output=None)
¶
Normalize the two FlashInfer TRTLLM MoE return layouts.
Parameters:
-
(flashinfer_output¶Tensor | list[Tensor]) –Tensor returned by the FlashInfer BF16 wrapper's legacy finalized path, or its mode-dependent tensor list.
-
(do_finalize¶bool) –Whether FlashInfer ran its top-k finalize step.
-
(num_tokens¶int) –Number of input tokens.
-
(top_k¶int) –Number of routed experts per token.
-
(finalized_output¶Tensor | None, default:None) –Optional destination passed to FlashInfer's
outputargument.
Returns:
-
Tensor | UnfinalizedMoEOutput–A finalized tensor or the structured deferred-finalize output.
Raises:
-
ValueError–If FlashInfer returns an unexpected layout.
Source code in vllm/model_executor/layers/fused_moe/moe_output.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | |
route_major_moe_output(routes, topk_weights, topk_ids, expert_map)
¶
Wrap one-row-per-route GEMM2 output; remote routes map to -1.