vllm.model_executor.layers.fused_moe ¶
Modules:
-
activation–MoE activation function enum and utilities.
-
all2all_utils– -
config– -
cpu_fused_moe– -
deep_gemm_utils–Taken from https://github.com/ModelTC/LightLLM/blob/8ed97c74c18f11505b048b1ba00ba5c0cef8bff6/lightllm/common/fused_moe/deepep_scatter_gather.py
-
expert_map_manager–Expert Map Manager for MoE layers.
-
experts– -
fused_moe–Fused MoE Triton kernels.
-
fused_moe_method_base– -
layer– -
modular_kernel– -
moe_align_block_size– -
moe_fused_mul_sum– -
moe_permute_unpermute– -
oracle– -
prepare_finalize– -
routed_experts– -
routed_experts_capturer– -
router– -
runner– -
topk_weight_and_reduce– -
unquantized_fused_moe_method– -
utils–
Classes:
-
BatchedDeepGemmExperts– -
BatchedTritonExperts–A Triton based MoE expert class that operates on expert batched format,
-
CutlassBatchedExpertsFp8–Batched CUTLASS FP8 fused MoE expert implementation.
-
CutlassExpertsFp8–CUTLASS FP8 fused MoE expert implementation.
-
DeepGemmExperts–DeepGemm-based fused MoE expert implementation.
-
FusedMoEActivationFormat–The standard activation format (num_tokens, hidden dim).
-
FusedMoEExpertsModular–An abstract base class for the [Permute-Experts-Unpermute] step described
-
FusedMoEMethodBase– -
FusedMoEParallelConfig– -
FusedMoEPrepareAndFinalizeModular–An abstract base class for the [Quantize-Prepare] and [Finalize] steps
-
FusedMoEQuantConfig–The FusedMoEQuantConfig contains all the quantization parameters for
-
FusedMoERouter–FusedMoERouter is an abstract class that provides a 'select_experts'
-
GateLinear–MoE gate linear layer with multi-tier GEMM dispatch:
-
GroupedTopk–GroupedTopk used by the Deepseek-V2 and Deepseek-V3 model.
-
MoEActivation–Activation functions for MoE layers.
-
MoERunner–Standard MoE runner implementation for executing Mixture of Experts layers.
-
RoutedExperts–Container for routed expert weights and execution logic.
-
TritonExperts–Triton-based fused MoE expert implementation.
-
TritonOrDeepGemmExperts–DeepGemm with fallback to Triton for low latency shapes.
-
UnquantizedFusedMoEMethod–MoE method without quantization.
Functions:
-
FusedMoE–Factory function for creating MoE execution pipeline.
-
activation_without_mul–Get the non-gated variant of an activation function.
-
apply_moe_activation–Apply MoE activation function.
-
fused_experts–Run fused MoE expert computation using Triton kernels.
-
fused_moe_make_expert_params_mapping–Delegate to EPLB manager.
BatchedDeepGemmExperts ¶
Bases: FusedMoEExpertsModular
Methods:
-
__init__–max_num_tokens: Maximum number of tokens from a DP Rank
-
supports_packed_ue8m0_act_scales–DeepGemm supports packed ue8m0 activation scales format in devices == sm100
Source code in vllm/model_executor/layers/fused_moe/experts/batched_deep_gemm_moe.py
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 | |
__init__(moe_config, quant_config, max_num_tokens, num_dispatchers) ¶
max_num_tokens: Maximum number of tokens from a DP Rank num_dispatchers: The number of DP dispatchers. quant_config: Quantization configuration
Source code in vllm/model_executor/layers/fused_moe/experts/batched_deep_gemm_moe.py
supports_packed_ue8m0_act_scales() ¶
DeepGemm supports packed ue8m0 activation scales format in devices == sm100
Source code in vllm/model_executor/layers/fused_moe/experts/batched_deep_gemm_moe.py
BatchedTritonExperts ¶
Bases: FusedMoEExpertsModular
A Triton based MoE expert class that operates on expert batched format, i.e. E x max_num_tokens x K. This is the format that the batched dispatch/combine kernels use.
Source code in vllm/model_executor/layers/fused_moe/experts/fused_batched_moe.py
717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 | |
CutlassBatchedExpertsFp8 ¶
Bases: CutlassExpertsFp8Base
Batched CUTLASS FP8 fused MoE expert implementation.
Source code in vllm/model_executor/layers/fused_moe/experts/cutlass_moe.py
CutlassExpertsFp8 ¶
Bases: CutlassExpertsFp8Base
CUTLASS FP8 fused MoE expert implementation.
Source code in vllm/model_executor/layers/fused_moe/experts/cutlass_moe.py
DeepGemmExperts ¶
Bases: FusedMoEExpertsModular
DeepGemm-based fused MoE expert implementation.
Source code in vllm/model_executor/layers/fused_moe/experts/deep_gemm_moe.py
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 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 | |
FusedMoEActivationFormat ¶
Bases: Enum
The standard activation format (num_tokens, hidden dim).
Attributes:
-
Standard–The batched experts format (num experts, max tokens per expert, hidden dim)
Source code in vllm/model_executor/layers/fused_moe/modular_kernel.py
Standard = ('standard',) class-attribute instance-attribute ¶
The batched experts format (num experts, max tokens per expert, hidden dim)
FusedMoEExpertsModular ¶
Bases: FusedMoEExperts
An abstract base class for the [Permute-Experts-Unpermute] step described above.
Methods:
-
adjust_N_for_activation–Calculate the output dimension for the activation function.
-
apply–This function computes the intermediate result of a Mixture of Experts
-
moe_problem_size–Extract the MoE problem size from the given tensor arguments:
-
workspace_dtype–Workspace type: The dtype to use for the workspace tensors.
-
workspace_shapes–Compute the shapes for the temporary and final outputs of the two gemms
Source code in vllm/model_executor/layers/fused_moe/modular_kernel.py
762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 | |
adjust_N_for_activation(N, activation) staticmethod ¶
Calculate the output dimension for the activation function.
For *_no_mul activations (e.g. relu2_no_mul), there's no gate/up split, so output size equals input size (N).
For regular gated activations (e.g., silu, gelu, swigluoai), output size is N // 2 due to gate × activation(up) multiplication.
Parameters:
-
(N¶int) –The intermediate size (width of w1/w3 weights).
-
(activation¶MoEActivation) –The activation function enum.
Returns:
-
int–The output dimension after activation.
Source code in vllm/model_executor/layers/fused_moe/modular_kernel.py
apply(output, hidden_states, w1, w2, topk_weights, topk_ids, activation, global_num_experts, expert_map, a1q_scale, a2_scale, workspace13, workspace2, expert_tokens_meta, apply_router_weight_on_input) abstractmethod ¶
This function computes the intermediate result of a Mixture of Experts (MoE) layer using two sets of weights, w1 and w2.
Parameters: - output: (torch.Tensor): The unweighted, unreduced output tensor. - hidden_states: (torch.Tensor): The (quantized) input tensor to the MoE layer. - w1 (torch.Tensor): The first set of expert weights. - w2 (torch.Tensor): The second set of expert weights. - topk_weights: A map of row to expert weights. Some implementations choose to do weight application. - topk_ids (torch.Tensor): A map of row to expert id. - activation (str): The activation function to apply after the first MoE layer. - global_num_experts (int): The total number of experts in the global expert space. - 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. - a1q_scale (Optional[torch.Tensor]): Optional quantized scale to be used for a1. Result of quantization from prepare/finalize and not from the FusedMoEQuantConfig. - workspace13 (torch.Tensor): A scratch tensor used for gemm outputs must be large enough to hold output of either MoE gemm. - workspace2 (torch.Tensor): A scratch tensor used for the activation function. - expert_tokens_meta (Optional[ExpertTokensMetadata]) - An optional ExpertTokensMetadata object containing gpu/cpu tensors as big as the number of local experts with the information about the number of tokens assigned to each local expert. - apply_router_weight_on_input: True if router weights are already applied on the input. This is relevant if the implementation chooses to do weight application.
Source code in vllm/model_executor/layers/fused_moe/modular_kernel.py
moe_problem_size(a1, w1, w2, topk_ids) ¶
Extract the MoE problem size from the given tensor arguments: - a: The hidden states, input to the MoE layer. - w1: The first set of expert weights. - w2: The second set of expert weights. - topk_ids: The topk ids.
Note: extracting the problem shape from the weight and activation tensors is not obvious. It needs to be done this way specifically due to subtle issues with particular kernels, e.g. the int4 kernels divide the trailing dimension by two, so it's not "correct" to extract N or K from the trailing dimension of w1 or w2. Similarly, some kernels transpose the weights, so this needs to be kept in mind.
Note: This implementation covers most cases. However, if experts require a specialized implementation, like MarlinExperts, they are free to override this function.
Source code in vllm/model_executor/layers/fused_moe/modular_kernel.py
workspace_dtype(act_dtype) ¶
workspace_shapes(M, N, K, topk, global_num_experts, local_num_experts, expert_tokens_meta, activation) abstractmethod ¶
Compute the shapes for the temporary and final outputs of the two gemms and activation in the fused expert function. Since the gemms are independent, the workspace for the first gemm can be shared with the workspace for the last gemm.
Inputs: - M: number of tokens. - N: Row (or column) dimension of expert weights. - K: hidden dimension - topk: The number of top-k experts to select. - global_num_experts: global number of experts. - local_num_experts: local number of experts due to DP/EP. - expert_tokens_meta: number of tokens per expert metadata for batched format.
Returns a tuple of: - workspace13 shape tuple: must be large enough to hold the result of either expert gemm. - workspace2 shape tuple: must be large enough to hold the result of the activation function. - output shape tuple: must be exact size of the final gemm output. - Note: workspace shapes can be 0 if the workspace is not needed. But in order for activation chunking to work, the first dimension of each tuple must be the number of tokens when the shape is not 0.
Source code in vllm/model_executor/layers/fused_moe/modular_kernel.py
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.
Source code in vllm/model_executor/layers/fused_moe/fused_moe_method_base.py
FusedMoEParallelConfig dataclass ¶
Methods:
-
make–Determine MoE parallel configuration. Based on the input
tp_size_, -
make_no_parallel–For usage in CI/CD and testing.
Source code in vllm/model_executor/layers/fused_moe/config.py
998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 | |
make(tp_size_, pcp_size_, dp_size_, sp_size_, vllm_parallel_config) staticmethod ¶
Determine MoE parallel configuration. Based on the input tp_size_, dp_size_ and vllm's parallel config, determine what level's of parallelism to use in the fused moe layer.
Parameters:
-
(tp_size_¶int) –tp_sizepassed into the FusedMoE constructor. -
(pcp_size_¶int) –pcp_sizepassed into the FusedMoE constructor. -
(dp_size_¶int) –dp_sizepassed into the FusedMoE constructor. -
(vllm_parallel_config¶ParallelConfig) –vLLM's parallel config object which contains the
enable_expert_parallelflag.
Examples:
When there is no parallelism requested, i.e. tp_size_ = pcp_size_ = dp_size_ = 1, we simply return the sizes unaltered and the ranks set to 0.
Expert Parallelism is considered only when either dp_size_, pcp_size_ or tp_size_ is non trivial.
Note that PCP serves the same function as DP here.
When TP = 2, DP(PCP) = 1 and EP = False, the configuration on different devices:
- device 0 : TP = {2, 0} DP = {1, 0} EP = {1, 0} // legend : {size, rank}
- device 1 : TP = {2, 1} DP = {1, 0} EP = {1, 0}
- Comment : Tensors are sharded across 2 devices.
When TP = 1, DP(PCP) = 2 and EP = False, the configuration on different devices:
- device 0 : TP = {2, 0} DP = {2, 0} EP = {1, 0}
- device 1 : TP = {2, 1} DP = {2, 1} EP = {1, 0}
- Comment: There are 2 engine instances and the tensors are sharded across 2 decvices.
When TP = 2, DP(PCP) = 2 and EP = False, the configuration on different devices:
- device 0: TP = {4, 0} DP = {2, 0} EP = {1, 0}
- device 1: TP = {4, 1} DP = {2, 0} EP = {1, 0}
- device 2: TP = {4, 2} DP = {2, 1} EP = {1, 0}
- device 3: TP = {4, 3} DP = {2, 1} EP = {1, 0}
- Comment: There are 2 engine instances and the tensors are sharded across 4 devices.
When, TP = 2, DP(PCP) = 1 and EP = True, the configuration on different devices:
- device 0: TP = {1, 0} DP = {1, 0} EP = {2, 0}
- device 1: TP = {1, 0} DP = {1, 0} EP = {2, 1}
- Comment: The experts are split between the 2 devices.
When, TP = 1, DP(PCP) = 2 and EP = True, the configuration on different devices:
- device 0: TP = {1, 0} DP = {2, 0} EP = {2, 0}
- device 1: TP = {1, 0} DP = {2, 1} EP = {2, 1}
- Comment: There are 2 engine instances and the experts are split between the 2 devices.
When TP = 2, DP(PCP) = 2 and EP = True, the configuration on different devices:
- device 0: TP = {1, 0} DP = {2, 0} EP = {4, 0}
- device 1: TP = {1, 0} DP = {2, 0} EP = {4, 1}
- device 2: TP = {1, 0} DP = {2, 1} EP = {4, 2}
- device 3: TP = {1, 0} DP = {2, 1} EP = {4, 3}
- Comment: There are 2 engine instances and the experts are split between the 4 devices.
Source code in vllm/model_executor/layers/fused_moe/config.py
1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 | |
make_no_parallel() classmethod ¶
For usage in CI/CD and testing.
Source code in vllm/model_executor/layers/fused_moe/config.py
FusedMoEPrepareAndFinalizeModular ¶
Bases: FusedMoEPrepareAndFinalize
An abstract base class for the [Quantize-Prepare] and [Finalize] steps described above for the Modular case.
Methods:
-
finalize–Perform any combine plus apply weights and perform a reduction on the
-
finalize_async–Perform any combine plus apply weights and perform a reduction on the
-
prepare–Perform any quantization (and/or) dispatching needed for this kernel.
-
prepare_async–Perform any quantization (and/or) dispatching needed for this kernel
Source code in vllm/model_executor/layers/fused_moe/modular_kernel.py
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 | |
finalize(output, fused_expert_output, topk_weights, topk_ids, apply_router_weight_on_input, weight_and_reduce_impl) abstractmethod ¶
Perform any combine plus apply weights and perform a reduction on the fused experts output. - output: The output tensor, written in place. Must be (M, K) shape. - fused_expert_output: The unweighted, unreduced output of the fused experts, it will have (M, topk, K) shape. - topk_weights: The weights to be applied to the fused_experts_output. - topk_ids: The topk_ids. - apply_router_weight_on_input: When False, apply the weights to fused_expert_output. - weight_and_reduce_impl: An optional TopKWeightAndReduce implementation.
Source code in vllm/model_executor/layers/fused_moe/modular_kernel.py
finalize_async(output, fused_expert_output, topk_weights, topk_ids, apply_router_weight_on_input, weight_and_reduce_impl) ¶
Perform any combine plus apply weights and perform a reduction on the fused experts output but do not wait for results from other workers. - output: The output tensor, written in place. Must be (M, K) shape. - fused_expert_output: The unweighted, unreduced output of the fused experts, it will have (M, topk, K) shape. - topk_weights: The weights to be applied to the fused_experts_output. - topk_ids: The topk_ids. - apply_router_weight_on_input: When False, apply the weights to fused_expert_output. - weight_and_reduce_impl: An optional TopKWeightAndReduce implementation.
Returns a callback or a hook callback pair that when invoked waits for results from other workers and has the same return signature as finalize, if a hook is returned this is more lightweight check that the recv is complete without doing extra work (used by DBO, will be refactored in the very near future)
ret = obj.finalize_async(output, ...) ... output not valid yet ... if isinstance(ret, tuple): hook, receiver = ret hook() receiver() ... output valid here ...
is equivalent to:
obj.finalize(output, ...)
Source code in vllm/model_executor/layers/fused_moe/modular_kernel.py
prepare(a1, topk_weights, topk_ids, num_experts, expert_map, apply_router_weight_on_input, quant_config, defer_input_quant) abstractmethod ¶
Perform any quantization (and/or) dispatching needed for this kernel. - a1: The (unquantized) input to the MoE layer. - topk_ids: The topk ids. - topk_weights: The topk weights. - num_experts: The total number of experts in the global expert space. - expert_map: A tensor mapping expert indices from the global expert space to the local expert space of the expert parallel shard. - apply_router_weight_on_input: When True, apply the weights to the activations, before quantization + dispatching. - quant_config: Quantization info provided by the fused experts. - defer_input_quant: Runtime parameter indicating whether or not to defer input quantization to the FusedMoEExpertsModular in cases where the compute kernel expects unquantized inputs
Returns a tuple of: - quantized + dispatched a. - Optional quantized + dispatched a1_scales. - Optional ExpertTokensMetadata containing gpu/cpu tensors as big as the number of local experts with the information about the number of tokens assigned to each local expert. - Optional dispatched expert topk IDs - Optional dispatched expert topk weight
Source code in vllm/model_executor/layers/fused_moe/modular_kernel.py
prepare_async(a1, topk_weights, topk_ids, num_experts, expert_map, apply_router_weight_on_input, quant_config, defer_input_quant) ¶
Perform any quantization (and/or) dispatching needed for this kernel but do not wait for results from other workers. - a1: The (unquantized) input to the MoE layer. - a1_scale: Optional scales for a1 - a2_scale: Optional scales for the second MoE gemm. Required to make sure the quantization is consistent for both gemms. - topk_ids: The topk ids. - topk_weights: The topk weights. - num_experts: The total number of experts in the global expert space. - expert_map: A tensor mapping expert indices from the global expert space to the local expert space of the expert parallel shard. - apply_router_weight_on_input: When True, apply the weights to the activations, before quantization + dispatching. - defer_input_quant: Runtime parameter indicating whether or not to defer input quantization to the FusedMoEExpertsModular in cases where the compute kernel expects unquantized inputs
Returns a callback or a hook callback pair that when invoked waits for results from other workers and has the same return signature as prepare, if a hook is returned this is more lightweight check that the recv is complete without doing extra work (used by DBO, will be refactored in the very near future)
e.g.
ret = obj.prepare_async(...)
if isinstance(ret, tuple): hook, receiver = ret hook()
if hook is not None: a, a_scales, expert_meta, topk_ids, topk_weights = receiver()
is equivalent to:
a, a_scales, expert_meta, topk_ids, topk_weights = obj.prepare(...)
Source code in vllm/model_executor/layers/fused_moe/modular_kernel.py
FusedMoEQuantConfig dataclass ¶
The FusedMoEQuantConfig contains all the quantization parameters for a single FusedMoEMethodBase operation. It consists of four FusedMoEQuantDescs, one for each activation and set of weights.
Each FusedMoEMethodBase must implement a get_fused_moe_quant_config method to construct a FusedMoEQuantConfig for use with that class.
FusedMoEQuant configs are only used for modular kernels, fused_experts (from fused_moe.py), cutlass_moe_fp[48], rocm_aiter_fused_experts and triton_kernel_moe_forward. Other MoE methods can ignore the FusedMoEQuantConfig (for now) and hardcode it to None.
There are currently some restrictions on what can be expressed: - Most MoE ops only support similar quantization strategies for each parameter, e.g. both weights must have the same GroupShape and both activations must share the same GroupShape. One exception to this is the cutlass moe which allows per channel quantization on the outputs. Note: this restrictions are not always rigorously checked. - Not all fused MoE functions support all the parameters, e.g. zero points, global scales, alphas and biases are not universally supported. - Fully general GroupShapes are not allowed. Activations only support per token, per tensor or K-blocked. - Weights are not required to have a GroupShape since they have already been quantized.
Other notes: - PrecisionConfigs are specific to GPT OSS Triton. - As a follow up it would probably make sense to subclass FusedMoEQuantDesc or FusedMoEQuantConfig for particular FusedMoEMethodBase subclasses so that only the required quantization parameters are used/stored.
Methods:
-
batched_scale_shape–Construct the proper activation batched scale shape for this
-
config_name–Return a string used to construct the filename that contains the
-
make–General builder function for a FusedMoEQuantConfig.
-
scale_shape–Construct the proper activation scale shape for this
Source code in vllm/model_executor/layers/fused_moe/config.py
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 | |
batched_scale_shape(num_experts, max_tokens, hidden_dim) ¶
Construct the proper activation batched scale shape for this config, e.g. (num experts, *scale_shape).
Source code in vllm/model_executor/layers/fused_moe/config.py
config_name(dtype) ¶
Return a string used to construct the filename that contains the tuning info for a particular quantization scheme. See try_get_optimal_moe_config in fused_moe.py.
Source code in vllm/model_executor/layers/fused_moe/config.py
make(quant_dtype=None, per_act_token_quant=False, per_out_ch_quant=False, block_shape=None, w1_scale=None, w2_scale=None, a1_scale=None, a2_scale=None, g1_alphas=None, g2_alphas=None, a1_gscale=None, a2_gscale=None, w1_bias=None, w2_bias=None, w1_zp=None, w2_zp=None, weight_dtype=None, is_scale_swizzled=True, gemm1_alpha=None, gemm1_beta=None, gemm1_clamp_limit=None) staticmethod ¶
General builder function for a FusedMoEQuantConfig. - quant_dtype: Optional quantization type. None if activations are unquantized or quantized prior to calling. Note: "nvfp4", "mxfp4", "mxfp6_e3m2", "mxfp6_e2m3" are the only valid string values for quant_dtype. - per_act_token_quant: Activations have per token quantization. - per_out_ch_quant: Outputs have per channel quantization. (only for cutlass). - block_shape: Optional block size for block-wise quantization. Incompatible with per_act_token and per_out_ch quant. - w1_scale: Optional scale to be used for w1. - w2_scale: Optional scale to be used for w2. - a1_scale: Optional scale to be used for a1. - a2_scale: Optional scale to be used for a2. - g1_alphas: Optional global quantization scales for w1 (for nvfp4). Optional per-channel scales for w1 (for W4A8 FP8). Optional dq scale i.e. w_scale * a_scale (for W8A8 fp8). - g2_alphas: Optional global quantization scales for w2 (for nvfp4). Optional per-channel scales for w2 (for W4A8 FP8). Optional dq scale i.e. w_scale * a_scale (for W8A8 fp8). - a1_gscale: Optional global quantization scales for a1 (1.0 /a2_scale). - a2_gscale: Optional global quantization scales for a2 (1.0 /a2_scale).
- w1_bias: Optional biases for w1 (GPT OSS Triton).
- w2_bias: Optional biases for w1 (GPT OSS Triton).
- w1_zp: Optional w1 zero points for int4/int8 quantization.
- w2_zp: Optional w2 zero points for int4/int8 quantization.
- is_scale_swizzled: Whether the activation scale-factor layout is swizzled. Pass through to the underlying quantization kernel for dtypes that distinguish layouts (nvfp4, mxfp8). Defaults to True.
- gemm1_alpha: Optional MXFP4 TRTLLM SwiGLU alpha parameter.
- gemm1_beta: Optional MXFP4 TRTLLM SwiGLU beta parameter.
- gemm1_clamp_limit: Optional MXFP4 TRTLLM SwiGLU clamp limit.
Source code in vllm/model_executor/layers/fused_moe/config.py
491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 | |
scale_shape(max_tokens, hidden_dim) ¶
Construct the proper activation scale shape for this config.
Source code in vllm/model_executor/layers/fused_moe/config.py
FusedMoERouter ¶
Bases: ABC
FusedMoERouter is an abstract class that provides a 'select_experts' method that is used for routing hidden states based on router logits.
Methods:
-
select_experts–Route the input hidden states to the top-k experts based on the
Source code in vllm/model_executor/layers/fused_moe/router/fused_moe_router.py
select_experts(hidden_states, router_logits, topk_indices_dtype=None, *, input_ids=None) ¶
Route the input hidden states to the top-k experts based on the router logits.
Returns:
-
Tensor–(topk_weights, topk_ids)
-
tuple[Tensor, Tensor]– -
tuple[Tensor, Tensor]–The weights and expert ids computation result.
-
tuple[Tensor, Tensor]–Compatibility: When EPLB is not enabled, the returned ids are
-
tuple[Tensor, Tensor]–equivalent to global logical ids, so should be compatible with
-
tuple[Tensor, Tensor]–plain MoE implementations without redundant experts.
Source code in vllm/model_executor/layers/fused_moe/router/fused_moe_router.py
GateLinear ¶
Bases: ReplicatedLinear
MoE gate linear layer with multi-tier GEMM dispatch:
- DSV3 specialized kernel (SM90+, fp32 out, M<=16, H=7168, E=256/384)
- fp32 specialized kernel (SM90+, bf16/fp32 in, fp32 out, M<=32, H=3072, E=256)
- cuBLAS bf16×bf16→fp32 (SM90+ + bf16 weight + fp32 out_dtype)
- F.linear via ReplicatedLinear (ultimate fallback)
The out_dtype attribute is mutable and can be set after init (e.g. when the required dtype depends on the expert quantization method which is only known later).
Methods:
-
set_out_dtype–Set output dtype for the router logits after init.
Source code in vllm/model_executor/layers/fused_moe/router/gate_linear.py
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 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 | |
set_out_dtype(out_dtype) ¶
Set output dtype for the router logits after init.
Useful when the required dtype depends on the expert quantization method which is only known after the gate is constructed.
Source code in vllm/model_executor/layers/fused_moe/router/gate_linear.py
GroupedTopk ¶
Bases: CustomOp
GroupedTopk used by the Deepseek-V2 and Deepseek-V3 model.
Source code in vllm/model_executor/layers/fused_moe/router/grouped_topk_router.py
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 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 | |
MoEActivation ¶
Bases: Enum
Activation functions for MoE layers.
Methods:
-
from_str–Parse from string for backward compatibility.
-
without_mul–Get the non-gated variant of this activation.
Attributes:
-
custom_op_name(str) –Maps to the CustomOp name of activations
-
is_gated(bool) –Returns True if activation expects gate*activation(up) pattern.
Source code in vllm/model_executor/layers/fused_moe/activation.py
custom_op_name property ¶
Maps to the CustomOp name of activations in vllm/model_executor/layers/activation.py.
is_gated property ¶
Returns True if activation expects gate*activation(up) pattern.
Gated activations expect input tensor with 2x the output size, where the first half is the gate and second half is the up projection.
from_str(s) classmethod ¶
Parse from string for backward compatibility.
Source code in vllm/model_executor/layers/fused_moe/activation.py
without_mul() ¶
Get the non-gated variant of this activation.
For activations that have a _no_mul variant, returns that variant. For activations without a _no_mul variant (or already _no_mul), returns self.
Source code in vllm/model_executor/layers/fused_moe/activation.py
MoERunner ¶
Bases: MoERunnerInterface
Standard MoE runner implementation for executing Mixture of Experts layers.
This is the primary concrete implementation of MoE execution logic, providing comprehensive support for standard MoE operations. It handles: - Expert routing and token dispatching using various routing strategies - Shared experts computation with optional parallel execution using CUDA streams - Tensor model parallel and expert parallel operations - Multiple quantization methods and optimized kernel selection - Both monolithic and decomposed expert execution paths - Integration with various parallel execution modes (TP, EP, DP)
The runner orchestrates the complete MoE forward pass including routing tokens to experts, executing expert computations in parallel, and combining results. It supports advanced features like overlapped execution of shared experts, optimized kernels for different parallel configurations, and seamless integration with vLLM's distributed execution framework.
Eventually, this class may be split into more specialized implementations for different configurations (e.g., with/without shared experts, gates, etc.).
Methods:
-
apply_routed_input_transform–Apply transform for routed experts (e.g., latent projection).
-
apply_routed_output_transform–Apply transform to routed expert output (e.g., latent to full dim).
-
forward–Invoke the fused moe layer.
-
set_eplb_state–Register the EPLB state in this layer.
Attributes:
-
expert_local_to_global(Tensor | None) –Routing table: local expert ID to global expert ID.
-
expert_map_manager–Forward to routed_experts.expert_map_manager for backward compatibility.
-
expert_physical_to_global(Tensor | None) –Routing table: physical expert ID to global expert ID.
Source code in vllm/model_executor/layers/fused_moe/runner/moe_runner.py
221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 | |
expert_local_to_global property ¶
Routing table: local expert ID to global expert ID.
expert_map_manager property ¶
Forward to routed_experts.expert_map_manager for backward compatibility.
expert_physical_to_global property ¶
Routing table: physical expert ID to global expert ID.
_apply_quant_method(hidden_states, router_logits, shared_experts_input, input_ids=None) ¶
Run expert routing and the fused MoE kernel via the quant method.
Orchestrates shared expert execution (before/after), expert selection via the router, and the actual fused MoE computation. Returns (shared_expert_output, fused_expert_output).
Source code in vllm/model_executor/layers/fused_moe/runner/moe_runner.py
_forward_impl(hidden_states, router_logits, shared_experts_input, input_ids=None) ¶
Entry point called by the custom op to run the MoE computation.
Handles pre-dispatch setup (gate application, external shared expert triggering, quant config init) then performs the following steps within the sequence-parallel context.
- Performs expert routing
- fused MoE kernel execution
- shared expert computation.
Returns a single tensor of combined fused and shared output (if present).
Source code in vllm/model_executor/layers/fused_moe/runner/moe_runner.py
_map_global_expert_id_to_local_expert_id(expert_id) ¶
Map global expert ID to local expert ID.
_maybe_add_zero_expert_output(result) ¶
Add the zero expert's contribution to the final result.
When a ZeroExpertRouter is used, it computes a bias-like output from the "zero expert" that is added to the combined routed+shared expert output.
Source code in vllm/model_executor/layers/fused_moe/runner/moe_runner.py
_maybe_apply_routed_scale_to_output(shared_output, fused_output) ¶
Apply routed_scaling_factor to the output with FP16 overflow protection.
Scale the fused expert output by routed_scaling_factor. For FP16, avoid overflow by dividing shared_output by the scale instead (the decoder layer compensates with matching divisions).
Source code in vllm/model_executor/layers/fused_moe/runner/moe_runner.py
_maybe_fuse_gate_weights() ¶
Fuse router and shared expert gate weights on first call.
Cannot be done at init because gate weights are loaded after module construction (via weight_loader). Called once from _forward_impl before the first forward pass.
Source code in vllm/model_executor/layers/fused_moe/runner/moe_runner.py
_maybe_pad_hidden_states(shared_experts_input, hidden_states) ¶
Pad hidden_states to moe_config.hidden_dim and compute the original dimension for later truncation.
For latent MoE, the routed hidden_states may be smaller than hidden_dim. Padding ensures uniform tensor sizes through the fused MoE kernel. The returned trunc_size is used by _maybe_reduce_final_output to strip the padding from the result.
Source code in vllm/model_executor/layers/fused_moe/runner/moe_runner.py
_maybe_reduce_final_output(states, trunc_size) ¶
All-reduce the combined output if needed.
This is the "late" all-reduce path. When neither fused nor shared output was individually reduced, the combined sum is all-reduced here. Skipped when sequence-parallel is active (SP handles its own reduction) or when the early path already reduced both outputs.
Source code in vllm/model_executor/layers/fused_moe/runner/moe_runner.py
_maybe_reduce_shared_expert_output(shared_output) ¶
All-reduce shared expert output when the combine kernel already reduced fused output.
- If the combine kernel does the reduction for fused_output, reduce shared_output separately. O.w, reduce fused_output+shared_output later.
- If we have SP (TP=N, DP=M, EP), there is a separate AG step handled in the model.
Source code in vllm/model_executor/layers/fused_moe/runner/moe_runner.py
_sequence_parallel_context() ¶
Return a context manager for sequence-parallel token redistribution.
When sequence parallelism is active, returns a context that handles local size tracking for proper token scatter/gather. Otherwise returns a no-op context.
Source code in vllm/model_executor/layers/fused_moe/runner/moe_runner.py
apply_routed_input_transform(hidden_states) ¶
Apply transform for routed experts (e.g., latent projection).
This is called by FusedMoE.forward_native. The original hidden_states is saved separately so shared experts get [S, hidden_size] while routed experts get the transformed [S, moe_latent_size].
Returns (possibly transformed) hidden states and the input for shared experts (or None if there are no shared experts).
Source code in vllm/model_executor/layers/fused_moe/runner/moe_runner.py
apply_routed_output_transform(fused_output) ¶
Apply transform to routed expert output (e.g., latent to full dim).
Used by latent MoE models (e.g., NemotronH) where routed experts operate in a compressed latent space and need projection back to the full hidden dimension before combining with shared expert output.
Source code in vllm/model_executor/layers/fused_moe/runner/moe_runner.py
forward(hidden_states, router_logits, input_ids=None) ¶
Invoke the fused moe layer.
Input: - hidden_states - router_logits
Output: - The new hidden_states.
Calling sequence - forward - self._forward_entry (_moe_forward or _moe_forward_shared custom op) - _forward_impl
Note: The existence of _moe_forward and _moe_forward_shared custom ops are due to the following reason: 1. pytorch cannot handle union types in custom op signatures so _moe_forward and _moe_forward_shared must be split.
Source code in vllm/model_executor/layers/fused_moe/runner/moe_runner.py
626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 | |
set_eplb_state(moe_layer_idx, expert_load_view, logical_to_physical_map, logical_replica_count) ¶
Register the EPLB state in this layer.
This is used later in forward pass, where we get the expert mapping and record the load metrics in expert_load_view.
Source code in vllm/model_executor/layers/fused_moe/runner/moe_runner.py
RoutedExperts ¶
Bases: PluggableLayer
Container for routed expert weights and execution logic.
This module owns the expert weight parameters (w13_weight, w2_weight, scales, etc.) and handles: - Loading checkpoint weights into parameters - Executing routed experts via quant_method.apply()
Methods:
-
forward_modular–Execute routed experts using the quantization method's apply function.
-
forward_monolithic–Execute routed experts using the quantization method's apply function.
-
make_expert_params_mapping–Create expert parameter mapping for weight loading with redundant experts.
Source code in vllm/model_executor/layers/fused_moe/routed_experts.py
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 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 | |
_get_hidden_dim(shard_dim, ndim) staticmethod ¶
Compute the hidden dimension index from the shard (intermediate) dimension and tensor rank.
For 2D weight tensors the two data dims are (0, 1). For 3D tensors with an expert dimension at dim 0, they are (1, 2). shard_dim occupies one of these; the hidden dimension is the other. For 1D tensors (e.g. per-channel scales) returns 0.
Source code in vllm/model_executor/layers/fused_moe/routed_experts.py
_get_quant_method(prefix, quant_config, moe_config) ¶
Helper method to ensure quant_method is never None and of the proper type.
Source code in vllm/model_executor/layers/fused_moe/routed_experts.py
_load_combined_w13_weight_scale(shard_dim, loaded_weight, param, tp_rank) ¶
Load w13 weight scales assuming that w1 weight scales and w3 weight scales are stored in the same loaded_weight tensor.
Source code in vllm/model_executor/layers/fused_moe/routed_experts.py
_load_model_weight_or_group_weight_scale(shard_dim, expert_data, shard_id, loaded_weight, tp_rank, load_full_w2=False) ¶
Load grouped weight scales for group quantization or model weights
Parameters:
-
(shard_dim¶int) –dimension to shard
-
(expert_data¶Tensor) –parameter for a particular expert
-
(shard_id¶str) –either w1, w2, or w3
-
(loaded_weight¶Tensor) –checkpoint weight to load into the param
-
(tp_rank¶int) –tensor parallel rank
-
(load_full_w2¶bool, default:False) –whether or not the w2 loaded should be sharded.
Source code in vllm/model_executor/layers/fused_moe/routed_experts.py
_map_global_expert_id_to_local_expert_id(expert_id) ¶
Map global expert ID to local expert ID.
_narrow_expert_data_for_padding(expert_data, loaded_weight, hidden_dim, shard_dim=None) staticmethod ¶
Narrow expert_data to match loaded_weight for padded dimensions.
When backends (e.g., DeepEP) round up hidden_size, weight parameters are larger than checkpoint weights. Narrow the padded hidden dimension before copying. Similarly, when padding occurs on the shard (intermediate) dimension (e.g. for MXFP4 GEMM), narrow that dimension as well.
Parameters:
-
(expert_data¶Tensor) –The (possibly padded) parameter tensor to narrow.
-
(loaded_weight¶Tensor) –The checkpoint weight tensor with original size.
-
(hidden_dim¶int) –The dimension index corresponding to hidden_size. Must be non-negative.
-
(shard_dim¶int | None, default:None) –The dimension index corresponding to the shard (intermediate) dimension. Defaults to
None.
Source code in vllm/model_executor/layers/fused_moe/routed_experts.py
forward_modular(x, topk_weights, topk_ids, shared_experts=None, shared_experts_input=None) ¶
Execute routed experts using the quantization method's apply function.
This is called by the runner after router selection (for modular kernels) quant_method.apply() which accesses the weights on this RoutedExperts instance.
Parameters:
-
(x¶Tensor) –Input tensor after any transforms
-
(topk_weights¶Tensor) –Routing weights from router (for modular kernels)
-
(topk_ids¶Tensor) –Selected expert IDs from router (for modular kernels)
-
(shared_experts¶SharedExperts | None, default:None) –The shared experts (if any)
-
(shared_experts_input¶Tensor | None, default:None) –Input for shared experts (if any)
Returns:
-
Tensor–Output tensor from routed experts
Source code in vllm/model_executor/layers/fused_moe/routed_experts.py
forward_monolithic(x, router_logits=None, input_ids=None) ¶
Execute routed experts using the quantization method's apply function.
This is called by the runner after router selection (for modular kernels) or with router logits (for monolithic kernels). It delegates to quant_method.apply() which accesses the weights on this RoutedExperts instance.
Parameters:
-
(x¶Tensor) –Input tensor after any transforms
-
(router_logits¶Tensor | None, default:None) –Router logits (for monolithic kernels)
-
(input_ids¶Tensor | None, default:None) –input ids for DeepSeek V4
Returns:
-
Tensor–Output tensor from routed experts
Source code in vllm/model_executor/layers/fused_moe/routed_experts.py
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') staticmethod ¶
Create expert parameter mapping for weight loading with redundant experts.
This mapping handles the physical-to-logical expert ID conversion needed when loading weights with EPLB redundant experts.
Parameters:
-
(model¶Module) –The model containing the MoE layer
-
(ckpt_gate_proj_name¶str) –Name of gate projection in checkpoint
-
(ckpt_down_proj_name¶str) –Name of down projection in checkpoint
-
(ckpt_up_proj_name¶str) –Name of up projection in checkpoint
-
(num_experts¶int) –Number of logical (non-redundant) experts
-
(num_redundant_experts¶int, default:0) –Number of redundant experts
Returns:
-
list[tuple[str, str, int, str]]–List of tuples (param_name, weight_name, expert_id, shard_id)
-
where(list[tuple[str, str, int, str]]) – -
list[tuple[str, str, int, str]]–- param_name: Parameter name in the layer
-
list[tuple[str, str, int, str]]–- weight_name: Weight name in checkpoint
-
list[tuple[str, str, int, str]]–- expert_id: Physical expert ID
-
list[tuple[str, str, int, str]]–- shard_id: Shard identifier (w1, w2, w3)
Source code in vllm/model_executor/layers/fused_moe/routed_experts.py
TritonExperts ¶
Bases: LoRAExpertsMixin, FusedMoEExpertsModular
Triton-based fused MoE expert implementation.
Source code in vllm/model_executor/layers/fused_moe/experts/triton_moe.py
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 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 | |
TritonOrDeepGemmExperts ¶
Bases: FallbackExperts
DeepGemm with fallback to Triton for low latency shapes.
Source code in vllm/model_executor/layers/fused_moe/experts/triton_deep_gemm_moe.py
UnquantizedFusedMoEMethod ¶
Bases: FusedMoEMethodBase, CustomOp
MoE method without quantization.
Source code in vllm/model_executor/layers/fused_moe/unquantized_fused_moe_method.py
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 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 | |
FusedMoE(num_experts, top_k, hidden_size, intermediate_size, 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, 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, expert_mapping=None, n_shared_experts=None, router_logits_dtype=None, gate=None, shared_experts=None, shared_expert_gate=None, routed_input_transform=None, routed_output_transform=None, apply_routed_scale_to_output=False, zero_expert_type=None, hash_indices_table=None, runner_cls=None, runner_args=None, routed_experts_cls=None, routed_experts_args=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:
-
(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
-
(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
-
(expert_mapping¶list[tuple[str, str, int, str]] | None, default:None) –Expert parameter mapping for weight loading
-
(n_shared_experts¶int | None, default:None) –Number of shared experts (ROCm aiter only)
-
(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
-
(apply_routed_scale_to_output¶bool, default:False) –Whether to apply routed_scaling_factor to output instead of topk_weights
-
(zero_expert_type¶str | None, default:None) –Type of zero expert handling
-
(hash_indices_table¶Tensor | None, default:None) –Hash table for expert indices
-
(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)
-
(routed_experts_args¶dict[str, Any] | None, default:None) –Additional arguments for routed_experts constructor
Returns:
-
MoERunner(MoERunner) –Configured MoE execution pipeline ready for forward passes
Source code in vllm/model_executor/layers/fused_moe/layer.py
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 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 | |
activation_without_mul(activation) ¶
Get the non-gated variant of an activation function.
Parameters:
Returns:
-
str–The non-gated activation name (e.g., "silu_no_mul", "gelu_no_mul")
Source code in vllm/model_executor/layers/fused_moe/activation.py
apply_moe_activation(activation, output, input) ¶
Apply MoE activation function.
Source code in vllm/model_executor/layers/fused_moe/activation.py
fused_experts(hidden_states, w1, w2, topk_weights, topk_ids, activation=MoEActivation.SILU, apply_router_weight_on_input=False, global_num_experts=-1, expert_map=None, quant_config=None) ¶
Run fused MoE expert computation using Triton kernels.
Source code in vllm/model_executor/layers/fused_moe/fused_moe.py
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.