vllm.model_executor.layers.fused_moe.moe_fused_mul_sum
¶
Functions:
-
moe_fused_mul_sum–Fused kernel for MoE (Mixture of Experts) to perform weighted summation
moe_fused_mul_sum(inputs, topk_weights, outputs=None, topk_ids=None, expert_map=None, num_valid_tokens=None)
¶
Fused kernel for MoE (Mixture of Experts) to perform weighted summation of expert outputs.
Parameters:
-
(inputs¶Tensor) –The output from experts. Shape: (num_tokens, top_k, hidden_size).
-
(topk_weights¶Tensor) –The weights assigned to each expert for each token. Shape: (num_tokens, top_k).
-
(outputs¶Tensor | None, default:None) –Optional pre-allocated output tensor. Shape: (num_tokens, hidden_size).
-
(topk_ids¶Tensor | None, default:None) –Optional indices of the top-k experts. Shape: (num_tokens, top_k). A value of -1 marks a slot the expert GEMM skipped; those slots are excluded from the sum. When provided, rows with all top ids < 0 (worst-case padding) are skipped and their output rows left untouched. Required when
expert_mapis provided. -
(expert_map¶Tensor | None, default:None) –Optional mapping for Expert Parallelism. A value < 0 indicates an invalid token/expert pair that will be skipped. Only needed when
topk_idsmay contain non-local expert ids; if every non-(-1) id is already a local expert, leave it None to skip the redundant per-slot lookup. -
(num_valid_tokens¶Tensor | None, default:None) –Optional device scalar (1-element tensor) holding the number of real token rows (num_recv for a decode dispatch). When provided, rows past it are left untouched, so the static cudagraph grid never sums stale padding rows. Pass the token count, not token*top_k.
Returns:
Source code in vllm/model_executor/layers/fused_moe/moe_fused_mul_sum.py
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 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 | |