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
-
get_aiter_mx_scale_swizzle–AITER
swizzle_mx_scalearg matching the load-time scale swizzle. -
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.
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.
get_aiter_mx_scale_swizzle()
¶
AITER swizzle_mx_scale arg matching the load-time scale swizzle.
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.
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).
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.
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.