[Fix] Fix gpt oss triton kernels and upgrade flashinfer back to 0.6.11.post1 (#25335)

Co-authored-by: sglang-bot <sglang-bot@users.noreply.github.com>
Co-authored-by: b8zhong <b8zhong@users.noreply.github.com>
Co-authored-by: mmangkad <mmangkad@users.noreply.github.com>
This commit is contained in:
Baizhou Zhang
2026-05-15 01:04:56 -07:00
committed by GitHub
co-authored by sglang-bot b8zhong mmangkad
parent 4adfc6cf7e
commit 0c19540550
13 changed files with 147 additions and 53 deletions
+2 -2
View File
@@ -1201,7 +1201,7 @@ def _set_envs_and_config(server_args: ServerArgs):
if server_args.attention_backend == "flashinfer":
assert_pkg_version(
"flashinfer_python",
"0.6.8.post1",
"0.6.11.post1",
"Please uninstall the old version and "
"reinstall the latest version by following the instructions "
"at https://docs.flashinfer.ai/installation.html.",
@@ -1209,7 +1209,7 @@ def _set_envs_and_config(server_args: ServerArgs):
if _is_cuda:
assert_pkg_version(
"sglang-kernel",
"0.4.2.post1",
"0.4.2.post2",
"Please reinstall the latest version with `pip install sglang-kernel --force-reinstall`",
)
@@ -383,6 +383,11 @@ class FlashInferWorkspaceManager:
hidden_dim=hidden_dim,
dtype=dtype,
force_oneshot_support=bool(use_oneshot),
# Pin the symmetric-memory rendezvous to the actual
# subgroup. Without this, flashinfer >=0.6.10 falls back
# to WORLD and TP/EP/CP subgroup peers get addressed
# incorrectly (kernel hangs in cuda-graph warmup).
group=device_group,
)
if (
_TorchDistBackend is not None
@@ -515,8 +520,6 @@ def ensure_workspace_initialized(
if not is_flashinfer_available() or _flashinfer_comm is None:
return False
tp_coordinator = get_tp_group()
if use_attn_tp_group:
world_size = get_attn_tensor_model_parallel_world_size()
rank = get_attn_tensor_model_parallel_rank()
@@ -531,17 +534,12 @@ def ensure_workspace_initialized(
rank = get_moe_tensor_parallel_rank()
coordinator = get_moe_tp_group()
# When the sub-group IS the full TP group, pass None so the workspace
# uses the default process group directly (no TorchDistBackend needed).
# For true sub-groups, use NCCL device_group for GPU/device mapping and
# GLOO cpu_group for metadata broadcasts (avoids NCCL collectives that
# interfere with CUDA graph capture).
if coordinator.device_group is tp_coordinator.device_group:
device_group = None
cpu_group = None
else:
device_group = coordinator.device_group
cpu_group = coordinator.cpu_group
# Always pass the coordinator's groups: flashinfer >=0.6.10 reads the
# rendezvous group from `group=...` (falling back to WORLD when None),
# so leaving it None silently rendezvouses on WORLD and the kernel ends
# up addressing the wrong peers in TP/EP/CP subgroup setups.
device_group = coordinator.device_group
cpu_group = coordinator.cpu_group
if world_size <= 1:
return False
@@ -11,11 +11,13 @@ from triton_kernels.matmul_ogs import (
FlexCtx,
FnSpecs,
FusedActivation,
GatherIndx,
PrecisionConfig,
RoutingData,
ScatterIndx,
matmul_ogs,
)
from triton_kernels.numerics import InFlexData
from triton_kernels.routing import GatherIndx, RoutingData, ScatterIndx
from triton_kernels.swiglu import swiglu_fn
from sglang.srt.utils import is_cuda
@@ -297,9 +299,8 @@ def triton_kernel_fused_experts_with_bias(
w2_pcg = PrecisionConfig(flex_ctx=FlexCtx(rhs_data=w2_flex))
act = FusedActivation(
FnSpecs("swiglu", swiglu_fn, ("alpha", "limit")),
FnSpecs("swiglu", swiglu_fn, ("alpha", "limit"), reduction_n=2),
(gemm1_alpha, gemm1_clamp_limit),
2,
)
intermediate_cache = torch.empty(
@@ -19,8 +19,12 @@ from sglang.srt.layers.moe.moe_runner.base import (
from sglang.srt.layers.moe.utils import MoeRunnerBackend
if TYPE_CHECKING:
from triton_kernels.matmul_ogs import PrecisionConfig
from triton_kernels.routing import GatherIndx, RoutingData, ScatterIndx
from triton_kernels.matmul_ogs import (
GatherIndx,
PrecisionConfig,
RoutingData,
ScatterIndx,
)
from sglang.srt.layers.moe.token_dispatcher.standard import (
StandardCombineInput,
+44 -1
View File
@@ -32,7 +32,50 @@ import torch
import torch.nn.functional as F
try:
from triton_kernels.routing import GatherIndx, RoutingData, ScatterIndx, routing
from triton_kernels.matmul_ogs import GatherIndx, RoutingData, ScatterIndx
from triton_kernels.tensor import make_ragged_tensor_metadata
from triton_kernels.topk import topk as triton_kernels_topk
def routing(
logits,
n_expts_act,
sm_first=False,
expt_indx=None,
simulated_ep=1,
n_rows=None,
):
if simulated_ep != 1:
raise NotImplementedError(
"simulated_ep routing is not supported with triton_kernels 3.6.0"
)
if sm_first:
logits = torch.softmax(logits, dim=-1)
sparse_logits = triton_kernels_topk(
logits,
n_expts_act,
apply_softmax=not sm_first,
y_indx=expt_indx,
n_rows=n_rows,
)
dispatch_indx = sparse_logits.mask_metadata.row_sorted_indx
combine_indx = sparse_logits.mask_metadata.col_sorted_indx
ragged_metadata = make_ragged_tensor_metadata(
sparse_logits.mask_metadata.col_sum, dispatch_indx.shape[0]
)
gate_scal = sparse_logits.vals.flatten()[combine_indx]
routing_data = RoutingData(
gate_scal,
ragged_metadata.slice_sizes,
logits.shape[-1],
n_expts_act,
ragged_metadata,
)
gather_indx = GatherIndx(combine_indx, dispatch_indx)
scatter_indx = ScatterIndx(dispatch_indx, combine_indx)
return routing_data, gather_indx, scatter_indx
except ImportError:
pass
@@ -34,13 +34,13 @@ try:
enable_pdl: Optional[bool] = None,
) -> tuple[torch.Tensor, torch.Tensor]:
return _flashinfer_fp4_quantize(
input,
global_scale,
sf_vec_size,
sf_use_ue8m0,
is_sf_swizzled_layout,
is_sf_8x4_layout,
enable_pdl,
input=input,
global_scale=global_scale,
sf_vec_size=sf_vec_size,
sf_use_ue8m0=sf_use_ue8m0,
is_sf_swizzled_layout=is_sf_swizzled_layout,
is_sf_8x4_layout=is_sf_8x4_layout,
enable_pdl=enable_pdl,
backend=_flashinfer_fp4_quantize_backend,
)
+46 -3
View File
@@ -141,6 +141,7 @@ if TYPE_CHECKING:
_is_hip = is_hip()
_use_aiter = get_bool_env_var("SGLANG_USE_AITER") and _is_hip
_is_shuffle_moe_mxfp4 = is_gfx95_supported()
_sm120_mxfp4_min_warps_patched = False
if _is_hip:
# import aiter
@@ -156,6 +157,49 @@ if _is_hip:
dynamic_mxfp4_quant = e8m0_shuffle = err
def _patch_sm120_mxfp4_min_warps():
global _sm120_mxfp4_min_warps_patched
if _sm120_mxfp4_min_warps_patched:
return
import inspect
from triton_kernels.matmul_ogs_details.opt_flags_details import opt_flags_nvidia
from triton_kernels.tensor import get_layout
from triton_kernels.tensor_details.layout import StridedLayout
compute_num_warps = opt_flags_nvidia.compute_num_warps
params = inspect.signature(compute_num_warps).parameters
if "is_persistent" in params and not getattr(
compute_num_warps, "_sglang_sm120_mxfp4_patch", False
):
def _compute_num_warps_sm120_mxfp4(
block_m, block_n, is_persistent, precision_config
):
selected_num_warps = compute_num_warps(
block_m, block_n, is_persistent, precision_config
)
weight_scale = getattr(precision_config, "weight_scale", None)
weight_scale_layout = get_layout(weight_scale)
if (
not is_persistent
and weight_scale is not None
and (
weight_scale_layout is StridedLayout
or isinstance(weight_scale_layout, StridedLayout)
)
):
return max(selected_num_warps, 4)
return selected_num_warps
_compute_num_warps_sm120_mxfp4._sglang_sm120_mxfp4_patch = True
opt_flags_nvidia.compute_num_warps = _compute_num_warps_sm120_mxfp4
_sm120_mxfp4_min_warps_patched = True
def _swizzle_mxfp4(quant_tensor, scale, num_warps):
"""weight swizzle for mxfp4 moe, used for OAI mxfp4 kernel"""
import triton_kernels.matmul_ogs_details.opt_flags as opt_flags
@@ -165,8 +209,8 @@ def _swizzle_mxfp4(quant_tensor, scale, num_warps):
if is_sm120_supported():
# SM120 desktop Blackwell does not support the persistent/TMA MXFP4 path.
# This MXFP4 path uses StridedLayout and the non-persistent kernel with
# block_k=128 so the selected tile stays within the per-block shared-memory budget.
# This MXFP4 path uses StridedLayout and the non-persistent kernel.
_patch_sm120_mxfp4_min_warps()
from triton_kernels.tensor_details.layout import StridedLayout
value_layout = StridedLayout
@@ -175,7 +219,6 @@ def _swizzle_mxfp4(quant_tensor, scale, num_warps):
scale_layout_opts = {}
constraints = {
"is_persistent": False,
"block_k": 128,
"num_stages": 1,
}
opt_flags.update_opt_flags_constraints(constraints)
+10 -2
View File
@@ -1105,7 +1105,7 @@ def check_pkg_version_at_least(pkg: str, min_version: str) -> bool:
Args:
pkg: Package name (distribution name, e.g., "flashinfer-python")
min_version: Minimum version required (e.g., "0.6.8.post1")
min_version: Minimum version required (e.g., "0.6.11.post1")
Returns:
True if package is installed and version >= min_version, False otherwise
@@ -3661,7 +3661,15 @@ class ConcurrentCounter:
@lru_cache(maxsize=1)
def is_triton_kernels_available() -> bool:
return importlib.util.find_spec("triton_kernels") is not None
if importlib.util.find_spec("triton_kernels") is None:
return False
try:
ragged_metadata_spec = importlib.util.find_spec(
"triton_kernels.tensor_details.ragged_tensor"
)
except ModuleNotFoundError:
return False
return ragged_metadata_spec is not None
@lru_cache(maxsize=1)