[Perf] Enable Flashinfer autotune by default (#14357)

This commit is contained in:
elvischenv
2025-12-17 15:01:39 +08:00
committed by GitHub
parent 2bdbaef18e
commit 435d1c83c1
7 changed files with 20 additions and 8 deletions

View File

@@ -54,6 +54,7 @@ from sglang.srt.utils import (
is_cpu,
is_flashinfer_available,
is_hip,
next_power_of_2,
round_up,
)
@@ -1087,6 +1088,7 @@ class FlashInferFusedMoE(FusedMoE):
local_expert_offset=self.moe_ep_rank * self.num_local_experts,
local_num_experts=self.num_local_experts,
routing_method_type=self.routing_method_type,
tune_max_num_tokens=next_power_of_2(hidden_states.shape[0]),
)
else:
@@ -1228,6 +1230,7 @@ class FlashInferFP4MoE(FusedMoE):
tile_tokens_dim=None,
routing_method_type=routing_method_type,
do_finalize=True,
tune_max_num_tokens=next_power_of_2(hs_fp4.shape[0]),
output=symm_output,
)[0]

View File

@@ -69,6 +69,7 @@ from sglang.srt.utils import (
is_sm90_supported,
is_sm100_supported,
log_info_on_rank0,
next_power_of_2,
print_warning_once,
set_weight_attrs,
use_intel_amx_backend,
@@ -1384,6 +1385,7 @@ class Fp8MoEMethod(FusedMoEMethodBase):
tile_tokens_dim=None,
routing_method_type=routing_method_type,
use_shuffled_weight=False,
tune_max_num_tokens=next_power_of_2(a_q.shape[0]),
)
else:
routing_bias_cast = (
@@ -1415,6 +1417,7 @@ class Fp8MoEMethod(FusedMoEMethodBase):
),
use_routing_scales_on_input=False,
routing_method_type=routing_method_type,
tune_max_num_tokens=next_power_of_2(a_q.shape[0]),
)
def maybe_apply_hip_fused_experts(

View File

@@ -793,6 +793,7 @@ class ModelOptFp8MoEMethod(FusedMoEMethodBase):
use_routing_scales_on_input=use_routing_scales_on_input,
tile_tokens_dim=None,
routing_method_type=routing_method_type,
tune_max_num_tokens=next_power_of_2(x.shape[0]),
)
from sglang.srt.layers.moe.token_dispatcher import StandardCombineInput

View File

@@ -2219,11 +2219,15 @@ class ModelRunner:
def _should_run_flashinfer_autotune(self) -> bool:
"""Check if flashinfer autotune should be run."""
if not self.server_args.enable_flashinfer_autotune:
if self.server_args.disable_flashinfer_autotune:
return False
backend_str = self.server_args.attention_backend
if backend_str not in ["flashinfer", "trtllm_mla", "trtllm_mha"]:
backend_str = self.server_args.moe_runner_backend
if backend_str not in [
"flashinfer_trtllm",
"flashinfer_cutlass",
"flashinfer_mxfp4",
]:
return False
major, _ = torch.cuda.get_device_capability()

View File

@@ -418,7 +418,7 @@ class ServerArgs:
fp8_gemm_runner_backend: str = "auto"
nsa_prefill_backend: str = "flashmla_sparse"
nsa_decode_backend: str = "fa3"
enable_flashinfer_autotune: bool = False
disable_flashinfer_autotune: bool = False
# Speculative decoding
speculative_algorithm: Optional[str] = None
@@ -3313,10 +3313,10 @@ class ServerArgs:
"SGLANG_ENABLE_FLASHINFER_FP8_GEMM and SGLANG_SUPPORT_CUTLASS_BLOCK_FP8.",
)
parser.add_argument(
"--enable-flashinfer-autotune",
default=ServerArgs.enable_flashinfer_autotune,
"--disable-flashinfer-autotune",
default=ServerArgs.disable_flashinfer_autotune,
action="store_true",
help="Enable FlashInfer autotuning for optimal kernel selection.",
help="Disable FlashInfer autotuning.",
)
# Speculative decoding