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
-
mx_scale_kwargs–PrecisionConfig weight-scale kwargs: 3.8 uses b_mx_scale/b_microblock_size,
-
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.
-
weight_mx_scale–mxfp4 weight scale from a triton_kernels PrecisionConfig: 3.8 exposes it
_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
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 | |
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
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 | |
mx_scale_kwargs(scale)
¶
PrecisionConfig weight-scale kwargs: 3.8 uses b_mx_scale/b_microblock_size, 3.5.1/3.6 use weight_scale.
Source code in vllm/model_executor/layers/quantization/utils/mxfp4_utils.py
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.
Source code in vllm/model_executor/layers/quantization/utils/mxfp4_utils.py
weight_mx_scale(precision_config)
¶
mxfp4 weight scale from a triton_kernels PrecisionConfig: 3.8 exposes it as b_mx_scale, 3.5.1/3.6 as weight_scale.