Fix IndexCache PP topk handoff (#28532)
This commit is contained in:
@@ -61,7 +61,9 @@ from sglang.srt.configs.model_config import (
|
||||
AttentionArch,
|
||||
ModelConfig,
|
||||
ModelImpl,
|
||||
dsa_layer_skips_topk,
|
||||
get_num_indexer_layers,
|
||||
is_deepseek_dsa,
|
||||
)
|
||||
from sglang.srt.configs.update_config import adjust_config_with_unaligned_cpu_tp
|
||||
from sglang.srt.constants import GPU_MEMORY_TYPE_WEIGHTS
|
||||
@@ -839,6 +841,17 @@ class ModelRunner(ModelRunnerKVCacheMixin):
|
||||
cpu_group=get_world_group().cpu_group,
|
||||
)
|
||||
|
||||
def get_pp_proxy_topk_size(self) -> Optional[int]:
|
||||
hf_config = self.model_config.hf_text_config
|
||||
if (
|
||||
self.pp_size <= 1
|
||||
or self.pp_rank == 0
|
||||
or not is_deepseek_dsa(hf_config)
|
||||
or not dsa_layer_skips_topk(hf_config, self.start_layer)
|
||||
):
|
||||
return None
|
||||
return getattr(hf_config, "index_topk", None)
|
||||
|
||||
def alloc_memory_pool(self, memory_pool_config: Optional[MemoryPoolConfig] = None):
|
||||
"""Allocate KV cache memory pools only (no backends or cuda graphs)."""
|
||||
if memory_pool_config is not None:
|
||||
@@ -2758,6 +2771,7 @@ class ModelRunner(ModelRunnerKVCacheMixin):
|
||||
cache_loc_dtype=torch.int64,
|
||||
enable_mamba_track=False,
|
||||
hc_hidden_size=getattr(self.model_config, "hc_hidden_size", None),
|
||||
pp_proxy_topk_size=self.get_pp_proxy_topk_size(),
|
||||
)
|
||||
buffers.num_token_non_padded[...] = num_tokens
|
||||
|
||||
|
||||
@@ -182,6 +182,7 @@ def _allocate_decode_buffers(
|
||||
enable_mamba_track: bool,
|
||||
ne_token_table: Optional[torch.Tensor] = None,
|
||||
hc_hidden_size: Optional[int] = None,
|
||||
pp_proxy_topk_size: Optional[int] = None,
|
||||
) -> SimpleNamespace:
|
||||
"""Allocate the FB-shared decode buffers as a namespace adopted by
|
||||
``build_decode_registry(source=...)``."""
|
||||
@@ -220,6 +221,10 @@ def _allocate_decode_buffers(
|
||||
pp_proxy_tensors["residual"] = torch.zeros(
|
||||
(max_bs, hidden_size), dtype=dtype
|
||||
)
|
||||
if pp_proxy_topk_size is not None:
|
||||
pp_proxy_tensors["topk_indices"] = torch.zeros(
|
||||
(max_num_token, pp_proxy_topk_size), dtype=torch.int32
|
||||
)
|
||||
else:
|
||||
pp_proxy_tensors = None
|
||||
|
||||
@@ -450,6 +455,7 @@ class DecodeCudaGraphRunner(BaseCudaGraphRunner):
|
||||
hc_hidden_size=getattr(
|
||||
self.model_runner.model_config, "hc_hidden_size", None
|
||||
),
|
||||
pp_proxy_topk_size=self.model_runner.get_pp_proxy_topk_size(),
|
||||
)
|
||||
self.buffers.share_buffers()
|
||||
# FB-shared slot registry adopting DecodeInputBuffers storage (same
|
||||
|
||||
@@ -107,6 +107,7 @@ class DecodeInputBuffers(ForwardInputBuffers):
|
||||
ne_token_table: Optional[torch.Tensor] = None,
|
||||
is_hybrid_swa: bool = False,
|
||||
hc_hidden_size: Optional[int] = None,
|
||||
pp_proxy_topk_size: Optional[int] = None,
|
||||
) -> DecodeInputBuffers:
|
||||
with torch.device(device):
|
||||
input_ids = torch.zeros((max_num_token,), dtype=torch.int64)
|
||||
@@ -149,6 +150,10 @@ class DecodeInputBuffers(ForwardInputBuffers):
|
||||
pp_proxy_tensors["residual"] = torch.zeros(
|
||||
(max_bs, hidden_size), dtype=dtype
|
||||
)
|
||||
if pp_proxy_topk_size is not None:
|
||||
pp_proxy_tensors["topk_indices"] = torch.zeros(
|
||||
(max_num_token, pp_proxy_topk_size), dtype=torch.int32
|
||||
)
|
||||
else:
|
||||
pp_proxy_tensors = None
|
||||
|
||||
|
||||
Reference in New Issue
Block a user