[NVIDIA] Fix use case of SGLANG_ENABLE_FLASHINFER_GEMM (#13274)

Co-authored-by: Baizhou Zhang <sobereddiezhang@gmail.com>
This commit is contained in:
Kaixi Hou
2025-11-14 12:51:11 -08:00
committed by GitHub
parent 22f641ab4f
commit 5ae0ac4244
4 changed files with 13 additions and 7 deletions

View File

@@ -206,7 +206,7 @@ class Envs:
# Flashinfer
SGLANG_IS_FLASHINFER_AVAILABLE = EnvBool(True)
SGLANG_ENABLE_FLASHINFER_GEMM = EnvBool(False)
SGLANG_ENABLE_FLASHINFER_FP8_GEMM = EnvBool(False)
# Default to the pick from flashinfer
SGLANG_FLASHINFER_FP4_GEMM_BACKEND = EnvStr("")
SGLANG_FLASHINFER_WORKSPACE_SIZE = EnvInt(384 * 1024 * 1024)
@@ -307,6 +307,9 @@ def _print_deprecated_env(new_name: str, old_name: str):
def _convert_SGL_to_SGLANG():
_print_deprecated_env("SGLANG_LOG_GC", "SGLANG_GC_LOG")
_print_deprecated_env(
"SGLANG_ENABLE_FLASHINFER_FP8_GEMM", "SGLANG_ENABLE_FLASHINFER_GEMM"
)
for key, value in os.environ.items():
if key.startswith("SGL_"):

View File

@@ -2,6 +2,7 @@ from typing import Callable, List, Optional, Tuple
import torch
from sglang.srt.environ import envs
from sglang.srt.layers import deep_gemm_wrapper
from sglang.srt.layers.quantization.fp8_kernel import sglang_per_token_group_quant_fp8
from sglang.srt.layers.quantization.mxfp4_tensor import MXFP4QuantizeUtil
@@ -127,17 +128,17 @@ def cutlass_block_fp8_supported() -> bool:
CUTLASS_BLOCK_FP8_SUPPORTED = cutlass_block_fp8_supported()
ENABLE_FLASHINFER_GEMM = (
get_bool_env_var("SGLANG_ENABLE_FLASHINFER_GEMM")
ENABLE_FLASHINFER_FP8_GEMM = (
envs.SGLANG_ENABLE_FLASHINFER_FP8_GEMM.get()
and is_blackwell_supported()
and is_flashinfer_available()
)
if ENABLE_FLASHINFER_GEMM:
if ENABLE_FLASHINFER_FP8_GEMM:
from flashinfer.gemm import gemm_fp8_nt_groupwise
def dispatch_w8a8_block_fp8_linear() -> Callable:
if ENABLE_FLASHINFER_GEMM:
if ENABLE_FLASHINFER_FP8_GEMM:
return flashinfer_gemm_w8a8_block_fp8_linear
elif CUTLASS_BLOCK_FP8_SUPPORTED:
return cutlass_w8a8_block_fp8_linear_with_fallback

View File

@@ -89,6 +89,7 @@ from sglang.srt.layers.quantization.fp8_kernel import (
per_token_group_quant_mla_deep_gemm_masked_fp8,
)
from sglang.srt.layers.quantization.fp8_utils import (
ENABLE_FLASHINFER_FP8_GEMM,
block_quant_dequant,
block_quant_to_tensor_quant,
channel_quant_to_tensor_quant,
@@ -3420,7 +3421,8 @@ class DeepseekV2ForCausalLM(nn.Module):
self_attn.use_deep_gemm_bmm = True
if (
deep_gemm_wrapper.ENABLE_JIT_DEEPGEMM
not ENABLE_FLASHINFER_FP8_GEMM
and deep_gemm_wrapper.ENABLE_JIT_DEEPGEMM
and deep_gemm_wrapper.DEEPGEMM_SCALE_UE8M0
and hasattr(self.quant_config, "weight_block_size")
and self.quant_config.weight_block_size is not None