[PD] Send DSA indexer state only past decode_prefix_len (#44140)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Shangming Cai <csmthu@gmail.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
Shangming Cai
parent
0cf683ea8d
commit
2528cd2b91
@@ -96,6 +96,7 @@ from sglang.srt.mem_cache.common import (
|
||||
page_align_floor,
|
||||
release_kv_cache,
|
||||
restore_kv_cache,
|
||||
suffix_page_indices,
|
||||
)
|
||||
from sglang.srt.mem_cache.deepseek_v4_memory_pool import DeepSeekV4TokenToKVPool
|
||||
from sglang.srt.mem_cache.hicache_storage import PoolName, PoolTransfer
|
||||
@@ -1659,6 +1660,18 @@ class DecodePreallocQueue(DecodeHiCachePreallocMixin):
|
||||
device_page_size = self.token_to_kv_pool.page_size
|
||||
return kv_to_page_indices(kv_indices_full, device_page_size)
|
||||
|
||||
def _dsa_pages_payload():
|
||||
# Mirror of prefill _dsa_pages_payload: the cached prefix keeps
|
||||
# its own indexer rows, and rows still being restored by
|
||||
# HiCache are not written until the restore commits.
|
||||
return suffix_page_indices(
|
||||
self.req_to_token_pool.req_to_token,
|
||||
decode_req.req.kv.req_pool_idx,
|
||||
total_prefix_len,
|
||||
seq_len,
|
||||
self.token_to_kv_pool.page_size,
|
||||
)
|
||||
|
||||
def _dsa_tail_payload():
|
||||
return get_dsa_tail_state_indices(
|
||||
self.token_to_kv_pool,
|
||||
@@ -1699,7 +1712,7 @@ class DecodePreallocQueue(DecodeHiCachePreallocMixin):
|
||||
StateType.QSA_PENDING: _qsa_pending_payload,
|
||||
StateType.QSA_COMPRESSED: _full_kv_pages_payload,
|
||||
StateType.SWA: _swa_payload,
|
||||
StateType.DSA: _full_kv_pages_payload,
|
||||
StateType.DSA: _dsa_pages_payload,
|
||||
StateType.DSA_TAIL: _dsa_tail_payload,
|
||||
StateType.MINIMAX_INDEX_K: _full_kv_pages_payload,
|
||||
StateType.MINIMAX_DENSE_KV: _full_kv_pages_payload,
|
||||
|
||||
@@ -78,6 +78,7 @@ from sglang.srt.mem_cache.common import (
|
||||
kv_to_page_indices,
|
||||
kv_to_page_num,
|
||||
release_kv_cache,
|
||||
suffix_page_indices,
|
||||
)
|
||||
from sglang.srt.mem_cache.deepseek_v4_memory_pool import DeepSeekV4TokenToKVPool
|
||||
from sglang.srt.mem_cache.memory_pool import HybridLinearKVPool
|
||||
@@ -1549,6 +1550,19 @@ class SchedulerDisaggregationPrefillMixin:
|
||||
]
|
||||
return kv_to_page_indices(kv_indices_full, page_size)
|
||||
|
||||
def _dsa_pages_payload():
|
||||
# Decode already holds the indexer rows of the prefix it cached
|
||||
# (decode_prefix_len, page-aligned), and its rows for a prefix
|
||||
# still being restored point at no page yet: send only the
|
||||
# suffix, positionally matching decode's _dsa_pages_payload.
|
||||
return suffix_page_indices(
|
||||
self.req_to_token_pool.req_to_token,
|
||||
req.kv.req_pool_idx,
|
||||
req.disagg_decode_prefix_len,
|
||||
seq_len,
|
||||
page_size,
|
||||
)
|
||||
|
||||
def _dsa_tail_payload():
|
||||
return get_dsa_tail_state_indices(
|
||||
self.token_to_kv_pool_allocator.get_kvcache(),
|
||||
@@ -1588,7 +1602,7 @@ class SchedulerDisaggregationPrefillMixin:
|
||||
StateType.QSA_PENDING: _qsa_pending_payload,
|
||||
StateType.QSA_COMPRESSED: _full_kv_pages_payload,
|
||||
StateType.SWA: _swa_payload,
|
||||
StateType.DSA: _full_kv_pages_payload,
|
||||
StateType.DSA: _dsa_pages_payload,
|
||||
StateType.DSA_TAIL: _dsa_tail_payload,
|
||||
StateType.MINIMAX_INDEX_K: _full_kv_pages_payload,
|
||||
StateType.MINIMAX_DENSE_KV: _full_kv_pages_payload,
|
||||
|
||||
@@ -47,6 +47,22 @@ def kv_to_page_indices(kv_indices: torch.Tensor, page_size: int) -> np.ndarray:
|
||||
return (kv_indices[::page_size] // page_size).cpu().numpy()
|
||||
|
||||
|
||||
def suffix_page_indices(
|
||||
req_to_token: torch.Tensor,
|
||||
req_pool_idx: int,
|
||||
prefix_len: int,
|
||||
seq_len: int,
|
||||
page_size: int,
|
||||
) -> np.ndarray:
|
||||
"""Pages of a request's tokens [prefix_len, seq_len).
|
||||
|
||||
PD prefill and decode both call this with the same page-aligned prefix
|
||||
(decode_prefix_len), so their lists pair up page by page even though their
|
||||
rows point at different physical pages.
|
||||
"""
|
||||
return kv_to_page_indices(req_to_token[req_pool_idx, prefix_len:seq_len], page_size)
|
||||
|
||||
|
||||
def kv_to_page_num(num_kv_indices: int, page_size: int):
|
||||
return (num_kv_indices + page_size - 1) // page_size
|
||||
|
||||
|
||||
Reference in New Issue
Block a user