Inline extend_range accessors and remove the extend_input_len/fill_len properties (#27611)

This commit is contained in:
fzyzcjy
2026-06-25 08:56:44 +08:00
committed by GitHub
parent 9305d10099
commit 7002a37ea1
19 changed files with 87 additions and 97 deletions
@@ -406,9 +406,9 @@ class TestSpecialCaseBasic(ScriptedTestCase):
r.is_chunking
and chunked is not None
and chunked.rid == r.rid
and chunked.extend_input_len > 0
and chunked.extend_range.length > 0
):
deduct = chunked.extend_input_len
deduct = chunked.extend_range.length
base = s.load_inquirer._get_num_pending_tokens()
deducted = s.load_inquirer._get_num_pending_tokens(chunk_deduct=deduct)
assert deducted == base - deduct, (
@@ -473,15 +473,18 @@ class TestSpecialCaseBasic(ScriptedTestCase):
r.is_chunking
and r.chunks_done >= 1
and req is not None
and req.extend_input_len is not None
and req.extend_range is not None
):
saw_mid_chunk = True
assert req.fill_len == len(req.prefix_indices) + req.extend_input_len, (
assert (
req.extend_range.end
== len(req.prefix_indices) + req.extend_range.length
), (
f"init_next_round_input must rebuild fill_ids to the committed "
f"prefix plus the in-flight chunk; "
f"fill_ids_len={req.fill_len}, "
f"fill_ids_len={req.extend_range.end}, "
f"prefix_indices_len={len(req.prefix_indices)}, "
f"extend_input_len={req.extend_input_len}, "
f"extend_input_len={req.extend_range.length}, "
f"chunks_done={r.chunks_done}"
)
if r.finished:
@@ -775,11 +778,11 @@ class TestSpecialCaseDeterministicFlashInfer(ScriptedTestCase):
page_size = 16
saw_chunking = False
for _ in range(DEFAULT_MAX_STEPS):
if r.is_chunking and r.req.extend_input_len is not None:
if r.is_chunking and r.req.extend_range is not None:
saw_chunking = True
assert r.req.extend_input_len % page_size == 0, (
assert r.req.extend_range.length % page_size == 0, (
f"deterministic chunk boundary must be page-aligned; "
f"got extend_input_len={r.req.extend_input_len}, page_size={page_size}"
f"got extend_input_len={r.req.extend_range.length}, page_size={page_size}"
)
if r.finished:
break
@@ -18,17 +18,6 @@ from sglang.srt.utils import is_cuda, is_hip, is_npu, is_xpu
from sglang.srt.utils.common import Range
from sglang.test.ci.ci_register import register_amd_ci, register_cuda_ci
class _FakeReq(SimpleNamespace):
@property
def fill_len(self) -> int:
return self.extend_range.end
@property
def extend_input_len(self) -> int:
return self.extend_range.length
register_cuda_ci(est_time=10, stage="base-b", runner_config="1-gpu-small")
register_amd_ci(est_time=10, suite="stage-b-test-1-gpu-small-amd")
@@ -54,7 +43,7 @@ def _make_req(rid="test-req-0", origin_input_ids=None, output_ids=None):
origin_input_ids = list(range(64))
if output_ids is None:
output_ids = []
req = _FakeReq(
req = SimpleNamespace(
rid=rid,
origin_input_ids=origin_input_ids,
output_ids=output_ids,
@@ -781,7 +770,7 @@ class TestHiSparseUnit(unittest.TestCase):
)
self.assertEqual(req.kv_allocated_len, fill_len)
self.assertEqual(req.kv_committed_len, fill_len)
self.assertEqual(req.extend_input_len, fill_len)
self.assertEqual(req.extend_range.length, fill_len)
rounded_len = (fill_len + self.page_size - 1) // self.page_size * self.page_size
self.assertEqual(
@@ -9,6 +9,7 @@ from sglang.srt.mem_cache.base_prefix_cache import (
IncLockRefResult,
)
from sglang.srt.server_args import ServerArgs, set_global_server_args_for_scheduler
from sglang.srt.utils.common import Range
from sglang.test.ci.ci_register import (
register_amd_ci,
register_cpu_ci,
@@ -471,7 +472,15 @@ class TestPrefillAdder(CustomTestCase):
req = self.create_mock_req("chunked", priority=0, max_new_tokens=128)
req.prefix_indices = []
req.full_untruncated_fill_ids = list(range(extend_input_len))
req.set_extend_range = MagicMock()
# set_extend_range is the only writer of extend_range; the production
# path reads req.extend_range.length right after calling it, so the mock
# must actually set the attribute (a spec=Req mock has the method but
# not the instance attribute).
req.set_extend_range = MagicMock(
side_effect=lambda start, end: setattr(
req, "extend_range", Range(start, end)
)
)
return adder, req
def test_add_chunked_req_hybrid_swa_reserves_page_for_alloc_extend(self):
@@ -84,12 +84,8 @@ class MockReq:
self.kv_allocated_len = len(fill_ids)
self.kv_committed_freed = False
@property
def fill_len(self):
return self.extend_range.end
def get_fill_ids(self):
return self.full_untruncated_fill_ids[: self.fill_len]
return self.full_untruncated_fill_ids[: self.extend_range.end]
def pop_committed_kv_cache(self):
self.kv_committed_freed = True
@@ -927,7 +927,7 @@ class UnifiedRadixCacheSuite:
req.set_extend_range(
len(req.prefix_indices), len(req.full_untruncated_fill_ids)
)
kv_len = req.fill_len
kv_len = req.extend_range.end
kv_indices = self._alloc(allocator, kv_len)
req_to_token_pool.write((req.req_pool_idx, slice(0, kv_len)), kv_indices)
req.kv_committed_len = kv_len
@@ -1815,7 +1815,7 @@ class UnifiedRadixCacheSuite:
req.origin_input_ids = tokens
req.output_ids = []
req.full_untruncated_fill_ids = array("q", tokens)
req.fill_len = len(req.full_untruncated_fill_ids)
req.set_extend_range(0, len(req.full_untruncated_fill_ids))
kv_indices = self._alloc(allocator, pre_len)
req_to_token_pool.write((req.req_pool_idx, slice(0, pre_len)), kv_indices)
req.kv_committed_len = pre_len
@@ -1867,7 +1867,7 @@ class UnifiedRadixCacheSuite:
req.origin_input_ids = tokens
req.output_ids = []
req.full_untruncated_fill_ids = array("q", tokens)
req.fill_len = len(req.full_untruncated_fill_ids)
req.set_extend_range(0, len(req.full_untruncated_fill_ids))
kv_indices = self._alloc(allocator, pre_len)
req_to_token_pool.write((req.req_pool_idx, slice(0, pre_len)), kv_indices)
req.kv_committed_len = pre_len