From bb43927404076b2935473eb09bc07f07543957fb Mon Sep 17 00:00:00 2001 From: metamergebot Date: Thu, 8 Oct 2026 16:48:31 -0700 Subject: [PATCH] [PD] Charge decode admission the page-rounded allocation when the radix cache is disabled (#43173) Co-authored-by: hanming-lu <69857889+hanming-lu@users.noreply.github.com> Co-authored-by: xiezhq-hermann --- python/sglang/srt/disaggregation/decode.py | 4 +++- .../test_decode_queue_cleanup.py | 3 ++- ...test_priority_scheduling_disaggregation.py | 24 +++++++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/python/sglang/srt/disaggregation/decode.py b/python/sglang/srt/disaggregation/decode.py index aecf19b1ca..bd6419285a 100644 --- a/python/sglang/srt/disaggregation/decode.py +++ b/python/sglang/srt/disaggregation/decode.py @@ -1453,7 +1453,9 @@ class DecodePreallocQueue(DecodeHiCachePreallocMixin): prefix_indices = None prefix_len = 0 total_prefix_len = 0 - required_alloc_tokens = self._pre_alloc_fill_len(decode_req.req) + required_alloc_tokens = self._required_alloc_tokens( + fill_len=self._pre_alloc_fill_len(decode_req.req), prefix_len=0 + ) full_required_for_admission = self._required_admission_tokens( decode_req.req, required_alloc_tokens, prefix_len, retractable_tokens diff --git a/test/registered/unit/disaggregation/test_decode_queue_cleanup.py b/test/registered/unit/disaggregation/test_decode_queue_cleanup.py index c587cba01e..b73f5c059b 100644 --- a/test/registered/unit/disaggregation/test_decode_queue_cleanup.py +++ b/test/registered/unit/disaggregation/test_decode_queue_cleanup.py @@ -251,7 +251,8 @@ class TestDecodeQueueCleanup(CustomTestCase): ) queue._hicache_pending_restore_tokens = MagicMock(return_value=0) queue._pre_alloc = MagicMock() - queue.token_to_kv_pool_allocator = MagicMock() + # SWA tail pre-allocation runs on a paged pool. + queue.token_to_kv_pool_allocator = MagicMock(page_size=64) bind_separate_buffer_capacity(queue.token_to_kv_pool_allocator) queue.tree_cache = MagicMock() queue.req_to_token_pool = MagicMock() diff --git a/test/registered/unit/managers/test_priority_scheduling_disaggregation.py b/test/registered/unit/managers/test_priority_scheduling_disaggregation.py index ad2eab226f..4a6729ea35 100644 --- a/test/registered/unit/managers/test_priority_scheduling_disaggregation.py +++ b/test/registered/unit/managers/test_priority_scheduling_disaggregation.py @@ -628,6 +628,30 @@ class TestDecodePreallocQueuePriority(unittest.TestCase): [failed_low.req], failed_low.req.return_logprob ) + def test_admission_without_radix_cache_charges_the_alloc_hook(self): + """Bug regression: with the decode radix cache disabled, admission + charged the raw fill length while ``_pre_alloc`` allocates the + page-rounded ``_required_alloc_tokens``. On a paged pool a request + could pass admission and then fail allocation; the radix-cache path + already charged the rounded amount. Admission must charge what the + pool will allocate, so the mocked charge decides whether the request + fits.""" + for charge, fits in ((50, True), (200, False)): + with self.subTest(charge=charge): + decode_req = self._new_decode_req("req", 1) + queue = self._new_queue([decode_req]) + queue.token_to_kv_pool_allocator.available_size.return_value = 100 + queue._required_alloc_tokens = MagicMock(return_value=charge) + + preallocated, failed = queue.pop_preallocated() + + queue._required_alloc_tokens.assert_called_once_with( + fill_len=3, prefix_len=0 + ) + self.assertEqual(preallocated, [decode_req] if fits else []) + self.assertEqual(queue.queue, [] if fits else [decode_req]) + self.assertEqual(failed, []) + class TestDecodePreallocQueueRebootstrapPayload(unittest.TestCase): """The decode scheduler builds the rebootstrap ``/generate`` payload; the