[6/n] Fix num_token_non_padded computation in prefill (#14313)

Co-authored-by: Cheng Wan <54331508+ch-wan@users.noreply.github.com>
Co-authored-by: Runkai Tao <rt572@physics.rutger.edu>
This commit is contained in:
yuchengz816-bot
2025-12-10 22:15:19 -05:00
committed by GitHub
parent 8642dbe416
commit e54307f26a
4 changed files with 65 additions and 13 deletions

View File

@@ -84,6 +84,7 @@ from sglang.srt.layers.attention.attention_registry import (
ATTENTION_BACKENDS,
attn_backend_wrapper,
)
from sglang.srt.layers.attention.nsa.utils import is_nsa_enable_prefill_cp
from sglang.srt.layers.attention.tbo_backend import TboAttnBackend
from sglang.srt.layers.dp_attention import (
DpPaddingMode,
@@ -2697,6 +2698,17 @@ class ModelRunner:
else:
forward_batch.prepare_attn_tp_scatter_input(self)
# Normalize num_token_non_padded to be local to this attention TP rank if needed.
if (
forward_batch.num_token_non_padded is not None
and forward_batch.global_num_tokens_gpu is not None
and require_gathered_buffer
and not is_nsa_enable_prefill_cp()
):
forward_batch.adjust_num_token_non_padded_for_attn_tp(
server_args=self.server_args,
)
if forward_batch.forward_mode.is_decode():
ret = self.forward_decode(
forward_batch,