vllm.model_executor.kernels.linear.scaled_mm.flashinfer
¶
Classes:
-
FlashInferFp8DeepGEMMDynamicBlockScaledKernel–Conditional FlashInfer / DeepGEMM FP8 block-scaled GEMM.
FlashInferFp8DeepGEMMDynamicBlockScaledKernel
¶
Bases: Fp8BlockScaledDynamicMMLinearKernel
Conditional FlashInfer / DeepGEMM FP8 block-scaled GEMM.
Dispatches between two kernels based on input batch size: - Small batches (M < 32): FlashInfer's swapAB trick for better utilisation. - Large batches (M >= 32): DeepGEMM for peak throughput.
apply_input_quant is False because FlashInfer accepts BF16 input and handles FP8 conversion internally. The DeepGEMM branch therefore quantises BF16→FP8 inside apply_mm via a closure before dispatching to the DeepGEMM kernel — keeping both branches compatible with the single BF16 tensor operand list passed by torch.cond.
_dynamic_flashinfer_deepgemm_blockscale_gemm_fake(input, weight, weight_scale, group_size, use_deep_gemm_e8m0)
¶
Required fake/meta implementation for torch.compile graph tracing.
_dynamic_flashinfer_deepgemm_blockscale_gemm_impl(input, weight, weight_scale, group_size, use_deep_gemm_e8m0)
¶
Conditional FlashInfer FP8 blockscale GEMM with batch-size-dependent selection.
This function switches between two optimized kernels based on the input batch size: - For small batches (M < 32): Uses FlashInfer's DeepGEMM swapAB optimization. - For larger batches (M >= 32): Uses the official DeepGEMM kernel.
The conditional logic must use torch.cond() instead of a simple if-else statement to maintain compatibility with torch.compile graph compilation.
This batch-size-dependent selection is essential for maintaining model accuracy. Benchmarks on GSM8K show a significant accuracy gap (88% vs 95%) for DeepSeek-V3.1 when using FlashInfer's DeepGEMM on M>=32. The M < 32 strategy fixes the accuracy drop.
Parameters:
-
(input¶Tensor) –Input tensor of shape (batch_size, input_dim) in FP8 format
-
(weight¶Tensor) –Weight tensor of shape (output_dim, input_dim) in FP8 format
-
(weight_scale¶Tensor) –Scale factors for weight quantization (per-group)
-
(group_size¶int) –Quantization group size for the weight tensor
-
(use_deep_gemm_e8m0¶bool) –Whether to use the E8M0 format in DeepGEMM quantization
Returns:
-
Tensor–Output tensor of shape (batch_size, output_dim) in bfloat16 format
_flashinfer_fp8_blockscale_gemm_fake(input, weight, weight_scale)
¶
Required fake/meta implementation for torch.compile graph tracing.