feat(npu): Support returning indexer top-k results (#39060)
This commit is contained in:
@@ -23,6 +23,7 @@ from sglang.srt.layers.cp.base import get_cp_strategy
|
||||
from sglang.srt.model_executor.forward_batch_info import DSV4OutCacheLoc, ForwardMode
|
||||
from sglang.srt.model_executor.forward_context import get_attn_backend
|
||||
from sglang.srt.runtime_context import get_parallel
|
||||
from sglang.srt.state_capturer.indexer_topk import maybe_capture_indexer_topk
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from sglang.srt.layers.radix_attention import RadixAttention
|
||||
@@ -899,6 +900,10 @@ class C4IndexerAscendBackendMixin:
|
||||
)
|
||||
topk_idxs = self._forward_indexer(c4_indexer, x, q, weights, forward_batch)
|
||||
self.forward_metadata.c4_topk_indices = topk_idxs
|
||||
compress_layer_id = self.token_to_kv_pool.layer_mapping[
|
||||
c4_indexer.layer_id
|
||||
].compress_layer_id
|
||||
maybe_capture_indexer_topk(compress_layer_id, topk_idxs)
|
||||
|
||||
def _cp_local_positions(self, forward_batch: ForwardBatch) -> torch.Tensor:
|
||||
"""Per-rank positions under CP-v2 (the batch keeps full-length ones)."""
|
||||
|
||||
@@ -18,6 +18,7 @@ from sglang.srt.layers.attention.dsa.utils import (
|
||||
from sglang.srt.layers.communicator import get_attn_tp_context
|
||||
from sglang.srt.model_executor.forward_context import get_token_to_kv_pool
|
||||
from sglang.srt.runtime_context import get_disagg
|
||||
from sglang.srt.state_capturer.indexer_topk import maybe_capture_indexer_topk
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from sglang.srt.model_executor.forward_batch_info import ForwardBatch
|
||||
@@ -490,6 +491,8 @@ def forward_dsa_prepare_npu(
|
||||
else:
|
||||
topk_indices = prev_topk_indices
|
||||
|
||||
topk_indices = maybe_capture_indexer_topk(m.layer_id, topk_indices)
|
||||
|
||||
return (
|
||||
q_pe,
|
||||
k_pe,
|
||||
|
||||
@@ -97,12 +97,11 @@ def create_indexer_capturer(
|
||||
) -> Optional[IndexerTopkCapturer]:
|
||||
|
||||
enable = get_exec().features.enable_return_indexer_topk
|
||||
# Producer wiring is CUDA-only (Indexer.forward_cuda + MLA skip_topk
|
||||
# path); other backends would create a capturer but never feed it.
|
||||
if enable and device != "cuda":
|
||||
# Producer wiring is CUDA/NPU-only; other backends
|
||||
# would create a capturer but never feed it.
|
||||
if enable and device != "cuda" and device != "npu":
|
||||
logger.warning(
|
||||
"indexer-topk capture is CUDA-only; %s backend not yet wired. "
|
||||
"Disabling capturer.",
|
||||
"indexer-topk capture is not wired for %s backend. Disabling capturer.",
|
||||
device,
|
||||
)
|
||||
return None
|
||||
@@ -130,9 +129,14 @@ def _create_indexer_capturer_raw(
|
||||
) -> Optional[IndexerTopkCapturer]:
|
||||
if not enable:
|
||||
return None
|
||||
if num_indexer_layers == 0:
|
||||
if num_indexer_layers <= 0:
|
||||
logger.warning("No indexer layers found, IndexerTopkCapturer disabled")
|
||||
return None
|
||||
if index_topk <= 0:
|
||||
logger.warning(
|
||||
"Invalid index_topk=%s, IndexerTopkCapturer disabled", index_topk
|
||||
)
|
||||
return None
|
||||
return IndexerTopkCapturer(
|
||||
num_tokens=num_tokens,
|
||||
num_indexer_layers=num_indexer_layers,
|
||||
|
||||
@@ -59,6 +59,9 @@ DEEPSEEK_V3_2_EXP_W8A8_WEIGHTS_PATH = os.path.join(
|
||||
DEEPSEEK_V3_2_W8A8_WEIGHTS_PATH = os.path.join(
|
||||
MODEL_WEIGHTS_DIR, "vllm-ascend/DeepSeek-V3.2-W8A8"
|
||||
)
|
||||
DEEPSEEK_V4_FLASH_BF16_MODEL_PATH = os.path.join(
|
||||
MODEL_WEIGHTS_DIR, "deepseek-ai/DeepSeek-V4-Flash-BF16"
|
||||
)
|
||||
DEEPSEEK_CODER_V2_LITE_WEIGHTS_PATH = os.path.join(
|
||||
MODEL_WEIGHTS_DIR, "deepseek-ai/DeepSeek-Coder-V2-Lite-Instruct"
|
||||
)
|
||||
@@ -87,6 +90,7 @@ GEMMA_4_26B_A4B_IT_WEIGHTS_PATH = os.path.join(
|
||||
GEMMA_4_31B_WEIGHTS_PATH = os.path.join(MODEL_WEIGHTS_DIR, "google/gemma-4-31B-it")
|
||||
GLM_4_9B_CHAT_WEIGHTS_PATH = os.path.join(MODEL_WEIGHTS_DIR, "ZhipuAI/glm-4-9b-chat")
|
||||
GLM_5_1_W4A8_MODEL_PATH = os.path.join(MODEL_WEIGHTS_DIR, "Eco-Tech/GLM-5.1-w4a8")
|
||||
GLM_5_2_BF16_MODEL_PATH = os.path.join(MODEL_WEIGHTS_DIR, "ZhipuAI/GLM-5.2")
|
||||
GPT_OSS_120B_BF16_WEIGHTS_PATH = os.path.join(
|
||||
MODEL_WEIGHTS_DIR, "eigen-ai-labs/gpt-oss-120b-bf16"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user