Prevent batched CP draft from silently leaving the target path

EAGLE draft shared-KV is supposed to mirror the target CP layout, so bs>1 must not fall back to legacy full-input or padded-hidden behavior when required batch metadata is missing or inconsistent. This change keeps the existing bs=1 compatibility path but makes batched CP draft fail fast on missing/mismatched spec hidden states, embedding pad metadata, or input embed shapes. The docs record the current W7 boundary: draft prefill follows target metadata, while scheduler admission and ETE remain gated.

Constraint: CP draft KV must mirror target layout and must not silently diverge under bs>1 shared-KV.

Rejected: Allow bs>1 to use the old full-input fallback | it can hide wrong owner/page metadata and corrupt accept length.

Confidence: medium

Scope-risk: moderate

Directive: Do not open the scheduler bs>1 CP gate until EAGLE accept length/output length are verified with this fail-fast path enabled.

Tested: Remote g0034 targeted EAGLE fail-fast unit test passed; remote full test/registered/unit/layers/test_nsa_cp_utils.py passed 70 tests.

Not-tested: EAGLE bs>1 ETE, because scheduler CP bs>1 admission gate remains closed.
This commit is contained in:
laoyao0822
2026-06-04 03:47:56 +08:00
parent 3e3f1b776b
commit d7723aca07
4 changed files with 155 additions and 1 deletions
@@ -1,4 +1,5 @@
import ast
import os
from pathlib import Path
import unittest
import sys
@@ -33,6 +34,7 @@ from sglang.srt.layers.attention.nsa.utils import (
split_in_seq_cp_local_pair,
)
from sglang.srt.mem_cache.cp_shared_kv_layout import CpSharedKVLayout
from sglang.srt.models.deepseek_nextn import DeepseekModelNextN
from sglang.test.ci.ci_register import register_cpu_ci
register_cpu_ci(est_time=1, suite="stage-a-test-cpu")
@@ -714,6 +716,42 @@ class TestNSAInSeqCPUtils(unittest.TestCase):
):
cp_collect_last_token_hidden(torch.zeros((8, 1)), forward_batch, 2)
def test_deepseek_nextn_cp_draft_bs_gt1_fails_fast_on_hidden_shape_fallback(
self,
):
import torch
model = DeepseekModelNextN.__new__(DeepseekModelNextN)
model._debug_cp_draft_shared_kv = lambda _message: None
forward_batch = SimpleNamespace(
uses_cp_shared_kv=True,
batch_size=2,
extend_seq_lens_cpu=[4, 9],
nsa_cp_metadata=NSAContextParallelMetadata(batch_size=2),
)
with (
patch.dict(os.environ, {"SGLANG_CP_DRAFT_SHARED_KV": "1"}),
patch(
"sglang.srt.models.deepseek_nextn.get_attention_cp_rank",
return_value=0,
),
patch(
"sglang.srt.models.deepseek_nextn.get_attention_cp_size",
return_value=8,
),
self.assertRaisesRegex(
RuntimeError,
r"\[CP_SHARED_KV_FAIL_FAST\]\[draft_batch_gt1_spec_hidden_shape_mismatch\]",
),
):
model._get_cp_local_spec_hidden_states(
forward_batch,
torch.zeros((3, 2)),
full_num_tokens=13,
local_num_tokens=8,
)
def test_full_rerange_fails_fast_for_batch_metadata(self):
import torch