Skip to content

vllm.model_executor.layers.fused_moe.router.router_factory

Functions:

create_fused_moe_router(top_k, global_num_experts, renormalize=True, use_grouped_topk=False, num_expert_group=None, topk_group=None, scoring_func='softmax', num_fused_shared_experts=0, shared_expert_weight=1.0, has_shared_expert_gate=False, routed_scaling_factor=1.0, e_score_correction_bias=None, custom_routing_function=None, eplb_state=None, zero_expert_type=None, num_logical_experts=None, hash_indices_table=None, bias_vl=None, image_sentinel_lo=0, skip_padding=False)

Factory function to create the appropriate FusedMoERouter subclass based on the provided parameters.

The selection logic follows this priority order: 1. ZeroExpertRouter - if zero_expert_type is not None 2. CPURouter - on CPU, before scheme-specific routers 3. GroupedTopKRouter - if use_grouped_topk is True and the grouped routing cannot fall through while preserving routing and scaling semantics 4. CustomRoutingRouter - if custom_routing_function is not None 5. FusedTopKBiasRouter - if e_score_correction_bias or hash_indices_table is not None 6. AiterSharedRoutedFusedMoERouter - if num_fused_shared_experts > 0, scoring_func is softmax, and AITER shared-expert fusion is enabled 7. FusedTopKRouter - default fallback

When VLLM_MOE_ROUTING_SIMULATION_STRATEGY is set, the selected router supplies the kernel routing method and is replaced by a RoutingSimulatorRouter.

Common arguments

top_k: Number of experts to select per token global_num_experts: Total number of experts in the model renormalize: Whether to renormalize the routing weights routing_method_type: Optional explicit routing method type

Grouped topk arguments

use_grouped_topk: Whether to use grouped top-k routing num_expert_group: Number of expert groups (for grouped routing) topk_group: Top-k within each group (for grouped routing) scoring_func: Scoring function to use ("softmax" or "sigmoid") num_fused_shared_experts: Number of fused shared experts (for ROCm AITER) shared_expert_weight: Constant routing weight of the fused shared experts (must be 1.0 for the AITER shared-expert router) has_shared_expert_gate: Whether the last num_fused_shared_experts columns of router_logits are shared-expert gate logits skip_padding: With ROCm AITER fused MoE, let grouped routing mask padding rows; otherwise it follows VLLM_MOE_SKIP_PADDING

Grouped topk and fused topk bias arguments

routed_scaling_factor: Scaling factor for routed weights e_score_correction_bias: Optional bias correction for expert scores

Custom routing arguments

custom_routing_function: Optional custom routing function

EPLB arguments

eplb_state: Optional EplbLayerState, None when EPLB is disabled.

Zero expert arguments

zero_expert_type: Type of zero expert (e.g. identity). If not None, creates a ZeroExpertRouter. num_logical_experts: Number of real (non-zero) experts. Required when zero_expert_type is not None.

Hash Indices Table

Used to map input_ids to experts, need for Deepseek V4

Returns:

  • FusedMoERouter –

    An instance of the appropriate FusedMoERouter subclass