vllm.model_executor.layers.fused_moe.utils ¶
Functions:
-
count_expert_num_tokens–Count the number to tokens assigned to each expert.
-
fi_moe_largest_bucket–Estimate FlashInfer's MoE autotuning maximum token count.
_fp8_quantize(A, A_scale, per_act_token, block_shape=None) ¶
Perform fp8 quantization on the inputs. If a block_shape is provided, the output will be blocked.
Source code in vllm/model_executor/layers/fused_moe/utils.py
_int8_quantize(A, A_scale, per_act_token, block_shape=None) ¶
Perform int8 quantization on the inputs. If a block_shape is provided, the output will be blocked.
Source code in vllm/model_executor/layers/fused_moe/utils.py
_resize_cache(x, v) ¶
Shrink the given tensor and apply the given view to it. This is used to resize the intermediate fused_moe caches.
Source code in vllm/model_executor/layers/fused_moe/utils.py
count_expert_num_tokens(topk_ids, num_local_experts, expert_map) ¶
Count the number to tokens assigned to each expert.
Parameters: - topk_ids (torch.Tensor): Tensor mapping each token to its list of experts. - num_local_experts (int): Number of experts in this rank. - expert_map (Optional[torch.Tensor]): A tensor mapping expert indices from the global expert space to the local expert space of the expert parallel shard.
Returns: A tensor of size num_local_experts, where tensor[i] holds the number of tokens assigned to the ith expert.
Source code in vllm/model_executor/layers/fused_moe/utils.py
fi_moe_largest_bucket(moe_config) ¶
Estimate FlashInfer's MoE autotuning maximum token count.
All DP ranks may contribute max_num_tokens to one invocation. Keep FlashInfer's default moe tune_max_num_tokens=8192 floor to avoid over-underestimation. DeepEP, SP, or PCP may make this underestimate, however overestimation may be dangerous, increasing tuning- cost and memory use.
NOTE: The DP factor applies even when EP is disabled:
Without
--enable-expert-parallel, MoE layers would use tensor parallelism.
For a detailed explanation, see: docs/serving/data_parallel_deployment.md