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.
Source code in vllm/model_executor/layers/fused_moe/fused_moe_method_base.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 | |
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)
Returns:
-
Tensor–Output tensor from routed experts
Source code in vllm/model_executor/layers/fused_moe/fused_moe_method_base.py
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)
Returns:
-
Tensor–Output tensor from routed experts
Source code in vllm/model_executor/layers/fused_moe/fused_moe_method_base.py
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.
Source code in vllm/model_executor/layers/fused_moe/fused_moe_method_base.py
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.