fix ds3.2 nsa backend prefill TBO (#14901)

This commit is contained in:
Jincong Chen
2025-12-22 05:16:46 +08:00
committed by GitHub
parent a39126672a
commit 350fbbf4dc
5 changed files with 76 additions and 2 deletions

View File

@@ -185,6 +185,9 @@ class TboAttnBackend(AttentionBackend):
def forward_decode(self, *args, **kwargs):
return self.primary.forward_decode(*args, **kwargs)
def get_indexer_metadata(self, layer_id: int, forward_batch: "ForwardBatch"):
return self.primary.get_indexer_metadata(layer_id, forward_batch)
def _init_forward_metadata_cuda_graph_split(
fn_name: str,

View File

@@ -67,6 +67,7 @@ from sglang.srt.layers.attention.nsa.utils import (
is_nsa_enable_prefill_cp,
prepare_input_dp_with_cp_dsa,
)
from sglang.srt.layers.attention.tbo_backend import TboAttnBackend
from sglang.srt.layers.attention.utils import concat_and_cast_mha_k_triton
from sglang.srt.layers.communicator import (
LayerCommunicator,
@@ -425,7 +426,10 @@ def handle_attention_nsa(attn, forward_batch):
Dispatch logic is centralized in NativeSparseAttnBackend.set_nsa_prefill_impl and executed
in init_forward_metadata. Read the decision from backend.use_mha.
"""
backend = forward_batch.attn_backend
if isinstance(backend, TboAttnBackend): # if enable tbo, get primary backend
backend = backend.primary
if hasattr(backend, "use_mha") and backend.use_mha:
return AttnForwardMethod.MHA_ONE_SHOT
return AttnForwardMethod.MLA
@@ -2670,7 +2674,10 @@ class DeepseekV2AttentionMLA(nn.Module):
Returns: (kv_a, k_pe) both in BF16
"""
kv_indices = forward_batch.attn_backend.forward_metadata.page_table_1_flattened
backend = forward_batch.attn_backend
if isinstance(backend, TboAttnBackend): # if enable tbo, get primary backend
backend = backend.primary
kv_indices = backend.forward_metadata.page_table_1_flattened
assert (
kv_indices is not None
), "page_table_1_flattened should have been generated for FP8 MHA path"

View File

@@ -727,6 +727,9 @@ class ServerArgs:
# Handle any other necessary validations.
self._handle_other_validations()
# Handle two-batch overlap settings.
self._handle_two_batch_overlap()
def _handle_deprecated_args(self):
# Handle deprecated tool call parsers
deprecated_tool_call_parsers = {"qwen25": "qwen", "glm45": "glm"}
@@ -2392,6 +2395,12 @@ class ServerArgs:
self.preferred_sampling_params
)
def _handle_two_batch_overlap(self):
if self.enable_two_batch_overlap and self.moe_a2a_backend == "none":
raise ValueError(
"When enabling two batch overlap, moe_a2a_backend cannot be 'none'."
)
@staticmethod
def add_cli_args(parser: argparse.ArgumentParser):