vllm.model_executor.layers.quantization.utils.nvfp4_utils
¶
Functions:
-
csf_weights_transform–Pair CSF scale streams back into canonical E4M3 scale tensors.
-
decode_csf_scale–Rebuild one
[rows, cols]float8_e4m3fn block-scale matrix. -
nvfp4_weight_padding_bytes–Compute K-dim padding (packed bytes) of an NVFP4 weight,
-
pad_nvfp4_activation_for_cutlass–Pad packed FP4 activations to match the K-dimension padding applied to weights.
-
pad_nvfp4_weight_for_cutlass–Pad packed NVFP4 weights so that both N (rows) and K (columns) satisfy
-
slice_nvfp4_output–Slice the output tensor to remove padding in N dimension if weight was padded.
-
swizzle_blockscale–Pad and block-interleave the FP4 block-scales so that they match the data
_csf32_blocks(rows, cols)
cached
¶
Origin, width and page of each 32x2 block in storage order, and the flat
[rows, cols] position of each code.
Source code in vllm/model_executor/layers/quantization/utils/nvfp4_utils.py
csf_weights_transform(encodings)
¶
Pair CSF scale streams back into canonical E4M3 scale tensors.
The returned transform is lazy over a (name, tensor) weight stream:
tensors named <name>.<stream> for a declared encoding are buffered per
scale and, once the encoding's stream set completes, replaced by the
decoded <name> tensor; everything else passes through unchanged.
Source code in vllm/model_executor/layers/quantization/utils/nvfp4_utils.py
decode_csf_scale(encoding, streams)
¶
Rebuild one [rows, cols] float8_e4m3fn block-scale matrix.
Source code in vllm/model_executor/layers/quantization/utils/nvfp4_utils.py
nvfp4_weight_padding_bytes(layer)
¶
Compute K-dim padding (packed bytes) of an NVFP4 weight,
Aligned with pad_nvfp4_weight_for_cutlass above.
Source code in vllm/model_executor/layers/quantization/utils/nvfp4_utils.py
pad_nvfp4_activation_for_cutlass(x_fp4, weights_padding_bytes)
¶
Pad packed FP4 activations to match the K-dimension padding applied to weights. The padding is in bytes (tensor dimension), not FP4 elements.
Source code in vllm/model_executor/layers/quantization/utils/nvfp4_utils.py
pad_nvfp4_weight_for_cutlass(weight, alignment=32)
¶
Pad packed NVFP4 weights so that both N (rows) and K (columns) satisfy the alignment constraints required by CUTLASS / FlashInfer FP4 kernels.
CUTLASS FP4 kernel requires both K and N matrix dimensions to be divisible by 32 for aligned memory access and efficient tensor core operations.
Source code in vllm/model_executor/layers/quantization/utils/nvfp4_utils.py
slice_nvfp4_output(out, output_size)
¶
Slice the output tensor to remove padding in N dimension if weight was padded.
Source code in vllm/model_executor/layers/quantization/utils/nvfp4_utils.py
swizzle_blockscale(scale)
¶
Pad and block-interleave the FP4 block-scales so that they match the data layout expected by the CUTLASS / FlashInfer kernels.
Parameters:
Returns:
-
Tensor–The swizzled tensor with the same logical shape as
scale.