vllm.model_executor.layers.quantization.utils.mxfp4_utils ¶
Functions:
-
downcast_to_mxfp–Convert the src weights to MXFP4. The src weight is quantized along the
-
mxfp4_quantize–Quantize a bf16/fp16 tensor to MXFP4 along its last dimension.
-
should_use_cdna4_mx_scale_swizzle–Whether to use the CDNA4 swizzled scale layout for mxfp4 on gfx950.
_swizzle_mxfp4(quant_tensor, scale, num_warps=8) ¶
weight swizzle for mxfp4 moe, used for OAI mxfp4 kernel
Source code in vllm/model_executor/layers/quantization/utils/mxfp4_utils.py
downcast_to_mxfp(src_tensor, axis, out_quant_tensor=None, out_scale=None, BLOCK_OUT_DIM=128, BLOCK_QUANT_DIM=32) ¶
Convert the src weights to MXFP4. The src weight is quantized along the axis dimension into packed e2m1 values (torch.uint8, two values per byte), so the size of that dimension in the output is half of the logical (unpacked) size.
Source code in vllm/model_executor/layers/quantization/utils/mxfp4_utils.py
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 | |
mxfp4_quantize(x) ¶
Quantize a bf16/fp16 tensor to MXFP4 along its last dimension.
Dispatches to the fastest backend available on the current platform:
- the native XPU custom op on XPU,
- aiter on ROCm when
aiteris installed, - and the portable Triton kernel (
downcast_to_mxfp) otherwise.
Returns packed FP4 values (uint8, two values per byte) and per-block (group-32) e8m0 scales (uint8).
Source code in vllm/model_executor/layers/quantization/utils/mxfp4_utils.py
should_use_cdna4_mx_scale_swizzle() ¶
Whether to use the CDNA4 swizzled scale layout for mxfp4 on gfx950.
CDNA4 swizzle requires BLOCK_K%256==0; at TP>=4 the A8W4 dispatch picks BK<256 tiles for the smaller per-rank shapes, so swizzle must be off. Used by both the weight-load swizzle in _swizzle_mxfp4 and the kernel-argument gate in aiter_mxfp4_w4a8_moe; they must agree.