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: