Preserve CP shared-KV cache-hit diagnostics

Warm-cache GSM8K failures needed request-to-log correlation across scheduler, prefill transfer, and Mooncake CP filtering. The added diagnostics are gated by existing CP shared-KV debug envs and include bounded token signatures plus transfer page summaries so future debugging can identify whether a failed request hit L1, L2, or transfer truncation paths.\n\nThe findings document records the ruled-out hypotheses and the RAGGED current-row contract failure, preventing repeated log archaeology after context compaction.\n\nConstraint: Production hot paths must not emit these logs unless SGLANG_CP_SHARED_KV_BS_GT1_DEBUG or existing CP shared-KV debug gates are enabled.\nRejected: Add a new debug env | reuse of existing bs>1 debug gate avoids more runtime switches.\nRejected: Store full token ids in logs | bounded signatures are enough for correlation without huge logs.\nConfidence: medium\nScope-risk: narrow\nDirective: Keep these diagnostics gated and bounded; do not convert them to unconditional INFO logs.\nTested: Remote container py_compile as part of the RAGGED fix validation.\nNot-tested: Long-running production log-volume impact with debug enabled.
This commit is contained in:
laoyao0822
2026-06-08 03:39:50 +08:00
parent 2aa0b7313e
commit fb5ccaff26
5 changed files with 321 additions and 2 deletions
@@ -64,6 +64,21 @@ def _cp_draft_shared_kv_debug(message: str, *args, limit: int = 64) -> None:
logger.info("[CP_DRAFT_SHARED_KV] " + message, *args)
def _cp_shared_kv_bs_gt1_mooncake_debug(
key: str, message: str, *args, limit: Optional[int] = None
) -> None:
if not envs.SGLANG_CP_SHARED_KV_BS_GT1_DEBUG.get():
return
if limit is None:
limit = int(envs.SGLANG_CP_SHARED_KV_BS_GT1_DEBUG_LIMIT.get())
count_key = "bs_gt1:" + key
count = _CP_SHARED_DEBUG_COUNTS.get(count_key, 0)
if limit > 0 and count >= limit:
return
_CP_SHARED_DEBUG_COUNTS[count_key] = count + 1
logger.info("[CP_SHARED_KV_BS_GT1_DEBUG] event=%s " + message, key, *args)
def _mooncake_transfer_stats_enabled() -> bool:
return envs.SGLANG_DISAGGREGATION_TRANSFER_STATS.get()
@@ -1211,6 +1226,19 @@ class MooncakeKVManager(CommonKVManager):
_np_summary(chunked_dst_kv_indice),
kv_chunk.is_last_chunk,
)
_cp_shared_kv_bs_gt1_mooncake_debug(
"transfer_worker_kv",
"cp_rank=%s room=%s prefill_pages=%s "
"logical_positions=%s dst_pages=%s is_last=%s "
"session=%s",
self.attn_cp_rank,
kv_chunk.room,
_np_summary(kv_chunk.prefill_kv_indices),
_np_summary(kv_chunk.logical_page_positions),
_np_summary(chunked_dst_kv_indice),
kv_chunk.is_last_chunk,
req.mooncake_session_id,
)
if envs.SGLANG_DEBUG_CP_SHARED_KV.get():
_cp_shared_debug_log(
"transfer_worker_kv",
@@ -1326,6 +1354,18 @@ class MooncakeKVManager(CommonKVManager):
),
_np_summary(dst_state_indices),
)
_cp_shared_kv_bs_gt1_mooncake_debug(
"transfer_worker_state",
"cp_rank=%s room=%s prefill_state_pages=%s "
"state_positions=%s dst_state_pages=%s "
"session=%s",
self.attn_cp_rank,
kv_chunk.room,
_np_summary(kv_chunk.state_indices),
_np_summary(kv_chunk.state_logical_page_positions),
_np_summary(dst_state_indices),
req.mooncake_session_id,
)
self.maybe_send_extra(
req,
kv_chunk.state_indices,
@@ -1706,6 +1746,22 @@ class MooncakeKVSender(CommonKVSender):
is_last_chunk,
getattr(self.kv_mgr.kv_args, "draft_kv_buffer_count", None),
)
_cp_shared_kv_bs_gt1_mooncake_debug(
"sender_filter",
"cp_rank=%s room=%s page_start=%s orig_kv_pages=%s "
"filtered_kv_pages=%s kv_positions=%s orig_state_pages=%s "
"filtered_state_pages=%s state_positions=%s is_last=%s",
self.kv_mgr.attn_cp_rank,
self.bootstrap_room,
chunk_page_start,
_np_summary(orig_kv_indices),
_np_summary(kv_indices),
_np_summary(logical_page_positions),
_np_summary(orig_state_indices),
_np_summary(state_indices),
_np_summary(state_logical_page_positions),
is_last_chunk,
)
# Special handling for cp
elif self.kv_mgr.enable_all_cp_ranks_for_transfer:
kv_indices, index_slice = filter_kv_indices_for_cp_rank(