Skip to content

vllm.model_executor.layers.fused_moe.layer

Functions:

FusedMoEFactory(num_experts, top_k, hidden_size, intermediate_size, intermediate_pad=None, params_dtype=None, renormalize=True, use_grouped_topk=False, num_expert_group=None, topk_group=None, quant_config=None, tp_size=None, dp_size=None, pcp_size=None, prefix='', custom_routing_function=None, router=None, scoring_func='softmax', routed_scaling_factor=1.0, swiglu_limit=None, swiglu_alpha=None, swiglu_beta=None, activation_situ_beta=None, activation_situ_linear_beta=None, qat_activation_key=None, e_score_correction_bias=None, apply_router_weight_on_input=False, activation='silu', enable_eplb=False, num_redundant_experts=0, has_bias=False, is_sequence_parallel=False, reduce_results=True, ckpt_names=('gate_proj', 'down_proj', 'up_proj'), is_fused_checkpoint_transposed=False, n_shared_experts=None, fuse_shared_experts=False, shared_expert_prefix=None, router_logits_dtype=None, gate=None, shared_experts=None, shared_expert_gate=None, routed_input_transform=None, routed_output_transform=None, routed_scale_mode=RoutedScaleMode.ROUTER, zero_expert_type=None, hash_indices_table=None, bias_vl=None, image_sentinel_lo=0, runner_cls=None, runner_args=None, routed_experts_cls=None, moe_config_cls=None, routed_experts_args=None, skip_padding=False, intermediate_size_unpadded=None)

Factory function for creating MoE execution pipeline.

Creates and configures a complete MoE execution pipeline including: - Router (for token-to-expert assignment) - RoutedExperts (containing expert weight parameters) - MoERunner (orchestrates the complete forward pass)

The experts contain both MergedColumnParallel weights (gate_up_proj/w13) and RowParallelLinear weights (down_proj/w2).

Note: Mixtral uses w1, w2, and w3 for gate, up, and down_proj. We copy that naming convention here and handle any remapping in the load_weights function in each model implementation.

Parameters:

  • intermediate_pad

    (int | None, default: None ) –

    Padding added to the intermediate size, if any.

  • swiglu_alpha

    (float | None, default: None ) –

    Optional alpha parameter for the SwiGLU activation.

  • swiglu_beta

    (float | None, default: None ) –

    Optional beta parameter for the SwiGLU activation.

Parameters:

  • num_experts

    (int) –

    Number of experts in the model (global count)

  • top_k

    (int) –

    Number of experts selected for each token

  • hidden_size

    (int) –

    Input hidden state size of the transformer

  • intermediate_size

    (int) –

    Intermediate size of the experts

  • params_dtype

    (dtype | None, default: None ) –

    Data type for the parameters

  • renormalize

    (bool, default: True ) –

    Whether to renormalize the logits in the router

  • use_grouped_topk

    (bool, default: False ) –

    Whether to use grouped top-k routing

  • num_expert_group

    (int | None, default: None ) –

    Number of expert groups for grouped top-k

  • topk_group

    (int | None, default: None ) –

    Top-k value per group for grouped top-k

  • quant_config

    (QuantizationConfig | None, default: None ) –

    Quantization configuration

  • tp_size

    (int | None, default: None ) –

    Tensor parallelism size (None = use global default)

  • dp_size

    (int | None, default: None ) –

    Data parallelism size (None = use global default)

  • pcp_size

    (int | None, default: None ) –

    Pipeline context parallelism size (None = use global default)

  • prefix

    (str, default: '' ) –

    Layer name prefix for weight loading

  • custom_routing_function

    (Callable | None, default: None ) –

    Custom routing function override

  • router

    (FusedMoERouter | None, default: None ) –

    Pre-configured router instance (None = create default)

  • scoring_func

    (str, default: 'softmax' ) –

    Scoring function for routing ("softmax" or others)

  • routed_scaling_factor

    (float, default: 1.0 ) –

    Scaling factor applied to topk_weights or output

  • swiglu_limit

    (float | None, default: None ) –

    SwiGLU activation limit

  • activation_situ_beta

    (float | None, default: None ) –

    SituGLU activation beta

  • activation_situ_linear_beta

    (float | None, default: None ) –

    SituGLU linear beta

  • qat_activation_key

    (QuantKey | None, default: None ) –

    Activation quantization scheme the experts were trained against, for checkpoints that do not record it

  • e_score_correction_bias

    (Tensor | None, default: None ) –

    Expert score correction bias tensor

  • apply_router_weight_on_input

    (bool, default: False ) –

    Whether to apply router weights on input

  • activation

    (str, default: 'silu' ) –

    Activation function name ("silu", "gelu", etc.)

  • enable_eplb

    (bool, default: False ) –

    Whether to enable expert parallelism load balancer

  • num_redundant_experts

    (int, default: 0 ) –

    Number of redundant experts for EPLB

  • has_bias

    (bool, default: False ) –

    Whether expert layers have bias terms

  • is_sequence_parallel

    (bool, default: False ) –

    Whether sequence parallelism is enabled

  • reduce_results

    (bool, default: True ) –

    Whether to all-reduce the final output. Setting this to False (to fuse the all-reduce downstream) is only honored on the late-AR path.

  • ckpt_names

    (tuple[str, str, str | None], default: ('gate_proj', 'down_proj', 'up_proj') ) –

    Checkpoint parameter name tuple (gate_proj, down_proj, up_proj) used for weight loading

  • is_fused_checkpoint_transposed

    (bool, default: False ) –

    Whether fused checkpoint weights and block scales use transposed storage.

  • n_shared_experts

    (int | None, default: None ) –

    Number of shared experts to fuse into the routed grouped GEMM (ROCm; requires aiter FSE or the router-append path)

  • fuse_shared_experts

    (bool, default: False ) –

    Whether to enable shared-expert fusion.

  • shared_expert_prefix

    (str | None, default: None ) –

    Checkpoint prefix for the fused shared expert.

  • router_logits_dtype

    (dtype | None, default: None ) –

    Data type for router logits buffers

  • gate

    (Module | None, default: None ) –

    Pre-configured gate module

  • shared_experts

    (Module | None, default: None ) –

    Pre-configured shared experts module

  • shared_expert_gate

    (Module | None, default: None ) –

    Pre-configured shared expert gate module

  • routed_input_transform

    (Module | None, default: None ) –

    Input transformation module

  • routed_output_transform

    (Module | None, default: None ) –

    Output transformation module

  • routed_scale_mode

    (RoutedScaleMode, default: ROUTER ) –

    Where routed_scaling_factor is applied: folded into the top-k weights (ROUTER), or applied by the runner to the output (OUTPUT, OUTPUT_FP16_GUARD). See RoutedScaleMode.

  • zero_expert_type

    (str | None, default: None ) –

    Type of zero expert handling

  • hash_indices_table

    (Tensor | None, default: None ) –

    Hash table for expert indices

  • bias_vl

    (Tensor | None, default: None ) –

    Vision routing bias for image tokens (Deepseek V4)

  • image_sentinel_lo

    (int, default: 0 ) –

    First of five consecutive in-vocab image sentinel ids (0 = vision routing disabled)

  • runner_cls

    (type[MoERunner] | None, default: None ) –

    Custom MoERunner class (None = use default MoERunner)

  • runner_args

    (dict[str, Any] | None, default: None ) –

    Additional arguments for runner constructor

  • routed_experts_cls

    (type[RoutedExperts] | None, default: None ) –

    Custom RoutedExperts class (None = use default)

  • moe_config_cls

    (type[FusedMoEConfig] | None, default: None ) –

    Custom FusedMoEConfig class (None = use default)

  • routed_experts_args

    (dict[str, Any] | None, default: None ) –

    Additional arguments for routed_experts constructor

  • skip_padding

    (bool, default: False ) –

    With ROCm AITER fused MoE, let grouped routing mask padding rows under DeepEP v2; otherwise it follows VLLM_MOE_SKIP_PADDING.

  • intermediate_size_unpadded

    (int | None, default: None ) –

    Global intermediate size the checkpoint holds, when intermediate_size is padded (None = not padded)

Returns:

  • MoERunner ( MoERunner ) –

    Configured MoE execution pipeline ready for forward passes

fused_moe_make_expert_params_mapping(model, ckpt_gate_proj_name, ckpt_down_proj_name, ckpt_up_proj_name, num_experts, num_redundant_experts=0, routed_experts_prefix='routed_experts')

Delegate to EPLB manager.