vllm.model_executor.layers.quantization.utils.flashinfer_utils ¶
align_fp8_moe_weights_for_fi ¶
align_fp8_moe_weights_for_fi(
w13: Tensor, w2: Tensor, is_act_and_mul: bool
) -> tuple[Tensor, Tensor, int]
Pad intermediate size so FlashInfer kernels' alignment constraints hold.
Some FlashInfer FP8 MoE kernels require the (gated) intermediate size used for GEMM to be divisible by a small alignment value. When this is not satisfied (e.g. with certain tensor-parallel sizes), we pad the gate/up and down projection weights along the intermediate dim.
Source code in vllm/model_executor/layers/quantization/utils/flashinfer_utils.py
convert_moe_weights_to_flashinfer_trtllm_block_layout ¶
convert_moe_weights_to_flashinfer_trtllm_block_layout(
cache_permute_indices: dict[Size, Tensor],
w13_weight: Tensor,
w2_weight: Tensor,
) -> tuple[Tensor, Tensor]
Convert expert weights to FlashInfer's block layout.
This reorders W13 and W2 into the expected epilogue-tiled block layout and returns the shuffled weight tensors.
Source code in vllm/model_executor/layers/quantization/utils/flashinfer_utils.py
prepare_fp8_moe_layer_for_fi ¶
prepare_fp8_moe_layer_for_fi(
layer: Module,
w13: Tensor,
w2: Tensor,
w13_scale: Tensor,
w13_input_scale: Tensor | None,
w2_scale: Tensor,
w2_input_scale: Tensor | None,
is_trtllm: bool = False,
) -> tuple[Tensor, Tensor, Tensor]
Convert Fp8 MoE weights to flashinfer kernel format
Note that for trtllm we update the model state dict with the scale format needed for these kernels.
Note that for per-tensor, we update the layer's intermediate size if the weights needed padding.
Source code in vllm/model_executor/layers/quantization/utils/flashinfer_utils.py
register_scales_for_trtllm_fp8_per_tensor_moe ¶
register_scales_for_trtllm_fp8_per_tensor_moe(
layer: Module,
w13_scale: Tensor,
w13_input_scale: Tensor,
w2_scale: Tensor,
w2_input_scale: Tensor,
) -> None
Register necessary scales for FlashInfer TRTLLM FP8 MoE kernel
Source code in vllm/model_executor/layers/quantization/utils/flashinfer_utils.py
rotate_weights_for_fi_trtllm_fp8_per_tensor_moe ¶
Shuffle weights for for FI TRT-LLM Format