vllm.model_executor.layers.fused_moe.fused_moe_method_base
¶
Classes:
FusedMoEMethodBase
¶
Bases: QuantizeMethodBase
Methods:
-
apply–Apply the MoE operation using modular kernels.
-
apply_monolithic–Apply the MoE operation using monolithic kernels.
-
maybe_roundup_sizes–Given layer hidden size and intermediate size per partition and MoE
-
uses_weight_scale_2_pattern–Returns True if this quantization method uses 'weight_scale_2' pattern
Attributes:
-
has_unpadded_output(bool) –Indicates that the hidden_states output might be the unpadded
-
skip_forward_padding(bool) –Whether to skip the padding in the forward before applying the moe method.
has_unpadded_output
property
¶
Indicates that the hidden_states output might be the unpadded hidden_states shape rather than the full padded shape.
skip_forward_padding
property
¶
Whether to skip the padding in the forward before applying the moe method.
apply(layer, x, topk_weights, topk_ids, shared_experts, shared_experts_input)
¶
Apply the MoE operation using modular kernels.
Parameters:
-
(layer¶RoutedExperts) –RoutedExperts instance containing weight parameters
-
(x¶Tensor) –Input tensor
-
(topk_weights¶Tensor) –Expert weights from router
-
(topk_ids¶Tensor) –Selected expert IDs from router
-
(shared_experts_input¶Tensor | None) –Input for shared experts (if any)
-
(shared_experts¶SharedExperts | None) –The shared experts module, if any
Returns:
-
Tensor | UnfinalizedMoEOutput–Finalized routed states or a deferred-finalize output.
apply_monolithic(layer, x, router_logits, input_ids=None)
¶
Apply the MoE operation using monolithic kernels.
Parameters:
-
(layer¶RoutedExperts) –RoutedExperts instance containing weight parameters
-
(x¶Tensor) –Input tensor
-
(router_logits¶Tensor) –Router logits (routing done internally)
-
(input_ids¶Tensor | None, default:None) –Token ids, for routers that condition on them
Returns:
-
Tensor | UnfinalizedMoEOutput–Finalized routed states or a deferred-finalize output.
maybe_roundup_sizes(hidden_size, intermediate_size_per_partition, act_dtype, moe_parallel_config)
¶
Given layer hidden size and intermediate size per partition and MoE configurations, round up hidden_size and intermediate_size_per_partition if necessary.
Parameters:
-
(hidden_size¶int) –Layer hidden-size
-
(intermediate_size_per_partition¶int) –Intermediate size per partition for the layer.
-
(act_dtype¶dtype) –Data type of the layer activations.
-
(moe_parallel_config¶FusedMoEParallelConfig) –Fused MoE parallelization strategy configuration.
Return
A tuple of (rounded_hidden_size, rounded_intermediate_size_per_partition), where: - rounded_hidden_size is the possibly rounded up hidden size. - rounded_intermediate_size_per_partition is the possibly rounded up intermediate size per partition.
uses_weight_scale_2_pattern()
¶
Returns True if this quantization method uses 'weight_scale_2' pattern for per-tensor weight scales (e.g., FP4 variants), False otherwise.
This method should be overridden by subclasses that use the 'weight_scale_2' pattern instead of the standard 'weight_scale' pattern.