vllm.model_executor.layers.fused_moe.config ¶
Classes:
-
FusedMoEConfig– -
FusedMoEParallelConfig– -
FusedMoEQuantConfig–The FusedMoEQuantConfig contains all the quantization parameters for
-
FusedMoEQuantDesc–A quantization descriptor for fused MoE ops. This class can describe
Functions:
-
biased_moe_quant_config–Construct a quant config for unquantized activations with biases.
-
fp8_w8a16_moe_quant_config–Construct a quant config for 16-bit float activations and fp8 weights.
-
fp8_w8a8_moe_quant_config–Construct a quant config for fp8 activations and fp8 weights.
-
gptq_marlin_moe_quant_config–Construct a quant config for gptq marlin quantization.
-
int4_w4a16_moe_quant_config–Construct a quant config for 16-bit float activations and int4 weights.
-
int4_w4afp8_moe_quant_config–Construct a quant config for fp8 activations and int4 weights.
-
int8_w8a16_moe_quant_config–Construct a quant config for 16-bit float activations and int8 weights.
-
int8_w8a8_moe_quant_config–Construct a quant config for int8 activations and int8 weights.
-
mxfp4_moe_quant_config–Construct a quant config for MXFP4 x MXFP4 MoE.
-
mxfp4_mxfp8_moe_quant_config–Construct a quant config for mxfp4 activations and mxfp4 weights.
-
mxfp4_w4a16_moe_quant_config–Construct a quant config for unquantized activations and mxfp4 weights.
-
mxfp4_w4a8_moe_quant_config–Construct a quant config for fp8 activations and mxfp4 weights.
-
nvfp4_moe_quant_config–Construct a quant config for mxfp4 activations and nvp4 weights.
-
nvfp4_w4a16_moe_quant_config–Construct a quant config for 16-but activations and nvp4 weights.
-
ocp_mx_moe_quant_config–Construct a quant config for mxfp4 activations and mxfp4 weights.
FusedMoEConfig dataclass ¶
Methods:
-
should_defer_moe_finalize–Return whether this invocation may defer the top-k reduction.
Attributes:
-
use_deferred_moe_finalize(bool) –Whether experts may return an unfinalized output on this deployment.
-
w13_num_shards(int) –Number of shards fused into w13: gate and up for gated, up only.
Source code in vllm/model_executor/layers/fused_moe/config.py
1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 | |
use_deferred_moe_finalize property ¶
Whether experts may return an unfinalized output on this deployment.
Evaluated on read rather than in __post_init__ because defer_moe_finalize is set after construction, like skip_final_all_reduce.
w13_num_shards property ¶
Number of shards fused into w13: gate and up for gated, up only.
should_defer_moe_finalize(num_tokens) ¶
Return whether this invocation may defer the top-k reduction.
Source code in vllm/model_executor/layers/fused_moe/config.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
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 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 | |
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 FusedMoEFactory constructor. -
(pcp_size_¶int) –pcp_sizepassed into the FusedMoEFactory constructor. -
(dp_size_¶int) –dp_sizepassed into the FusedMoEFactory 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
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 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 | |
make_no_parallel() classmethod ¶
For usage in CI/CD and testing.
Source code in vllm/model_executor/layers/fused_moe/config.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
FusedMoEQuantDesc dataclass ¶
A quantization descriptor for fused MoE ops. This class can describe either activations or weights.
Source code in vllm/model_executor/layers/fused_moe/config.py
_get_config_dtype_str(dtype, use_fp8_w8a8=False, use_fp8_w8a16=False, use_int8_w8a16=False, use_int4_w4a16=False, ocp_mx_scheme=None) ¶
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
_quant_flags_to_group_shape(quant_dtype, per_act_token_quant, per_out_ch_quant, block_shape) ¶
Convert MoE quantization flags into more generic GroupShapes.
Source code in vllm/model_executor/layers/fused_moe/config.py
biased_moe_quant_config(w1_bias, w2_bias, gemm1_alpha=None, gemm1_beta=None, gemm1_clamp_limit=None) ¶
Construct a quant config for unquantized activations with biases.
gemm1_alpha/gemm1_beta/gemm1_clamp_limit carry the SwiGLU gate params through to the fused activation kernel (e.g. swigluoai_uninterleave).
Source code in vllm/model_executor/layers/fused_moe/config.py
fp8_w8a16_moe_quant_config(w1_scale, w2_scale, w1_bias=None, w2_bias=None, block_shape=None, gemm1_alpha=None, gemm1_beta=None, gemm1_clamp_limit=None) ¶
Construct a quant config for 16-bit float activations and fp8 weights.
Source code in vllm/model_executor/layers/fused_moe/config.py
fp8_w8a8_moe_quant_config(w1_scale, w2_scale, a1_scale=None, a2_scale=None, w1_bias=None, w2_bias=None, per_act_token_quant=False, per_out_ch_quant=False, block_shape=None, a1_gscale=None, a2_gscale=None, g1_alphas=None, g2_alphas=None, gemm1_alpha=None, gemm1_beta=None, gemm1_clamp_limit=None) ¶
Construct a quant config for fp8 activations and fp8 weights.
Source code in vllm/model_executor/layers/fused_moe/config.py
gptq_marlin_moe_quant_config(w1_scale, w2_scale, weight_bits, group_size, w1_zp=None, w2_zp=None, w1_bias=None, w2_bias=None) ¶
Construct a quant config for gptq marlin quantization.
Source code in vllm/model_executor/layers/fused_moe/config.py
int4_w4a16_moe_quant_config(w1_scale, w2_scale, w1_zp=None, w2_zp=None, w1_bias=None, w2_bias=None, block_shape=None, a1_gscale=None, a2_gscale=None, gemm1_clamp_limit=None, gemm1_alpha=None, gemm1_beta=None) ¶
Construct a quant config for 16-bit float activations and int4 weights.
Source code in vllm/model_executor/layers/fused_moe/config.py
int4_w4afp8_moe_quant_config(w1_scale, w2_scale, g1_alphas, g2_alphas, per_act_token_quant=False, per_out_ch_quant=False, block_shape=None) ¶
Construct a quant config for fp8 activations and int4 weights.
Source code in vllm/model_executor/layers/fused_moe/config.py
int8_w8a16_moe_quant_config(w1_scale, w2_scale, w1_zp=None, w2_zp=None, w1_bias=None, w2_bias=None, block_shape=None, a1_gscale=None, a2_gscale=None, gemm1_clamp_limit=None, gemm1_alpha=None, gemm1_beta=None) ¶
Construct a quant config for 16-bit float activations and int8 weights.
Source code in vllm/model_executor/layers/fused_moe/config.py
int8_w8a8_moe_quant_config(w1_scale, w2_scale, a1_scale, a2_scale, w1_bias=None, w2_bias=None, per_act_token_quant=False) ¶
Construct a quant config for int8 activations and int8 weights.
Source code in vllm/model_executor/layers/fused_moe/config.py
mxfp4_moe_quant_config(w1_scale, w2_scale) ¶
Construct a quant config for MXFP4 x MXFP4 MoE. MXFP4 uses block scaling only (E8M0 scales, 32-element groups), with no separate alphas / global activation scales in this config.
Source code in vllm/model_executor/layers/fused_moe/config.py
mxfp4_mxfp8_moe_quant_config(w1_scale, w2_scale, a1_scale=None, a2_scale=None, w1_bias=None, w2_bias=None, block_shape=None, gemm1_alpha=None, gemm1_beta=None, gemm1_clamp_limit=None, mx_alignment=0, is_scale_swizzled=True) ¶
Construct a quant config for mxfp4 activations and mxfp4 weights.
Source code in vllm/model_executor/layers/fused_moe/config.py
mxfp4_w4a16_moe_quant_config(w1_scale, w2_scale, w1_bias=None, w2_bias=None, gemm1_alpha=None, gemm1_beta=None, gemm1_clamp_limit=None) ¶
Construct a quant config for unquantized activations and mxfp4 weights.
Source code in vllm/model_executor/layers/fused_moe/config.py
mxfp4_w4a8_moe_quant_config(w1_scale, w2_scale, a1_scale=None, a2_scale=None, w1_bias=None, w2_bias=None, block_shape=None, gemm1_clamp_limit=None) ¶
Construct a quant config for fp8 activations and mxfp4 weights.
Source code in vllm/model_executor/layers/fused_moe/config.py
nvfp4_moe_quant_config(g1_alphas, g2_alphas, a1_gscale, a2_gscale, w1_scale, w2_scale, w1_bias=None, w2_bias=None, is_scale_swizzled=True, gemm1_alpha=None, gemm1_beta=None, gemm1_clamp_limit=None) ¶
Construct a quant config for mxfp4 activations and nvp4 weights.
Source code in vllm/model_executor/layers/fused_moe/config.py
nvfp4_w4a16_moe_quant_config(g1_alphas, g2_alphas, w1_scale, w2_scale, gemm1_alpha=None, gemm1_beta=None, gemm1_clamp_limit=None) ¶
Construct a quant config for 16-but activations and nvp4 weights.
Source code in vllm/model_executor/layers/fused_moe/config.py
ocp_mx_moe_quant_config(quant_dtype, w1_scale, w2_scale, weight_dtype=None, a1_scale=None, a2_scale=None, w1_bias=None, w2_bias=None, block_shape=None, gemm1_alpha=None, gemm1_beta=None, gemm1_clamp_limit=None) ¶
Construct a quant config for mxfp4 activations and mxfp4 weights.