[KDA] Default safe-gate Blackwell prefill to FlashInfer (#43246)
This commit is contained in:
@@ -9,6 +9,7 @@ from sglang.srt.arg_groups.overrides import (
|
||||
from sglang.srt.configs.hybrid_arch import (
|
||||
glm5_next_config,
|
||||
hybrid_gdn_config,
|
||||
hybrid_kda_config,
|
||||
hybrid_lightning_config,
|
||||
kimi_linear_config,
|
||||
mamba2_config,
|
||||
@@ -388,7 +389,10 @@ def attn_backend_wrapper(runner: "ModelRunner", full_attn_backend: "AttentionBac
|
||||
)
|
||||
|
||||
from sglang.kernels.ops.attention.fla.utils import check_environments
|
||||
from sglang.srt.layers.attention.linear.kda_backend import KDAAttnBackend
|
||||
from sglang.srt.layers.attention.linear.kda_backend import (
|
||||
KDAAttnBackend,
|
||||
flashinfer_kda_prefill_default,
|
||||
)
|
||||
from sglang.srt.layers.attention.linear.lightning_backend import (
|
||||
LightningAttentionBackend,
|
||||
)
|
||||
@@ -430,6 +434,8 @@ def attn_backend_wrapper(runner: "ModelRunner", full_attn_backend: "AttentionBac
|
||||
prefill_default = None
|
||||
if hybrid_gdn_config(runner.model_config) is not None and not is_npu():
|
||||
prefill_default = flashinfer_gdn_prefill_default(runner)
|
||||
elif hybrid_kda_config(runner.model_config) is not None and not is_npu():
|
||||
prefill_default = flashinfer_kda_prefill_default(runner)
|
||||
runner.linear_attn_backends = resolve_linear_attn_backends(
|
||||
prefill_default=prefill_default
|
||||
)
|
||||
|
||||
@@ -64,6 +64,31 @@ def _validate_flashinfer_kda_prefill(
|
||||
)
|
||||
|
||||
|
||||
def flashinfer_kda_prefill_default(model_runner: ModelRunner) -> Optional[str]:
|
||||
"""Default safe-gate KDA prefill to FlashInfer on SM100/SM103."""
|
||||
from sglang.srt.configs.bailing_hybrid import BailingHybridConfig
|
||||
from sglang.srt.configs.hybrid_arch import hybrid_kda_config
|
||||
|
||||
config = hybrid_kda_config(model_runner.model_config)
|
||||
lower_bound = (
|
||||
config.kda_lower_bound
|
||||
if isinstance(config, BailingHybridConfig)
|
||||
else config.linear_attn_config.get("gate_lower_bound")
|
||||
)
|
||||
execution = get_exec()
|
||||
if (
|
||||
lower_bound is not None
|
||||
and execution.mamba.linear_attn_backend == "triton"
|
||||
and not execution.deterministic.enable_deterministic_inference
|
||||
and not execution.overlap.enable_two_batch_overlap
|
||||
and execution.graph.cuda_graph_config.prefill.backend != CudaGraphBackend.FULL
|
||||
and is_cuda()
|
||||
and torch.cuda.get_device_capability() in ((10, 0), (10, 3))
|
||||
):
|
||||
return "flashinfer"
|
||||
return None
|
||||
|
||||
|
||||
class KDAKernelDispatcher:
|
||||
"""Dispatches KDA kernel calls to the appropriate backend per mode."""
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ class LinearAttnBackends(msgspec.Struct, frozen=True):
|
||||
"""One runner's linear-attn kernel choice, per phase.
|
||||
|
||||
Per runner, not per process: a target and its draft coexist and can want
|
||||
different kernels (only the runner whose model is GDN gets the SM100
|
||||
different kernels (only eligible GDN/KDA runners get the
|
||||
FlashInfer prefill default, and an explicit flag applies to whichever runner
|
||||
was launched with it).
|
||||
"""
|
||||
@@ -83,8 +83,8 @@ def resolve_linear_attn_backends(
|
||||
) -> LinearAttnBackends:
|
||||
"""This runner's kernel choice from the published leaves.
|
||||
|
||||
``prefill_default`` is the caller's own auto-default (the SM100 GDN
|
||||
domain); an explicitly configured ``--linear-attn-prefill-backend`` wins.
|
||||
``prefill_default`` is the caller's own auto-default;
|
||||
an explicitly configured ``--linear-attn-prefill-backend`` wins.
|
||||
"""
|
||||
mamba = get_exec().mamba
|
||||
base = mamba.linear_attn_backend
|
||||
|
||||
Reference in New Issue
Block a user