From 8cd3c494a3aa3ae56dfd76f51bab6912234914dc Mon Sep 17 00:00:00 2001 From: Shuwen Wang <47200617+alphabetc1@users.noreply.github.com> Date: Thu, 22 Oct 2026 22:36:32 +0800 Subject: [PATCH] [Fix] mem_cache: Skip linker L3 lookup on PD decode (#45538) --- .../srt/mem_cache/unified_radix_cache.py | 14 +++++++-- .../mem_cache/test_unified_cache_linker.py | 29 +++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/python/sglang/srt/mem_cache/unified_radix_cache.py b/python/sglang/srt/mem_cache/unified_radix_cache.py index ab59618a5e..0f5eafa338 100644 --- a/python/sglang/srt/mem_cache/unified_radix_cache.py +++ b/python/sglang/srt/mem_cache/unified_radix_cache.py @@ -111,7 +111,12 @@ from sglang.srt.observability.metrics_collector import ( StorageMetrics, StorageMetricsCollector, ) -from sglang.srt.runtime_context import get_memory, get_model, get_observability +from sglang.srt.runtime_context import ( + get_disagg, + get_memory, + get_model, + get_observability, +) from sglang.srt.session.streaming_session import StreamingSession, is_virtual_node from sglang.srt.utils.common import ceil_align from sglang.srt.utils.poll_timer import PollTimer @@ -620,7 +625,12 @@ class UnifiedRadixCache(BasePrefixCache): result = component.finalize_match_result_in_cache(params, result) # Finalizers must not emit actions; the walk's were applied above. assert not result.cache_actions - if self.linker is not None and params.req is not None: + # PD decode has no linker load-back path, so it only offloads. + if ( + self.linker is not None + and params.req is not None + and get_disagg().disaggregation_mode != "decode" + ): result = self.linker.match(params.key, params.req, result) return result diff --git a/test/registered/unit/mem_cache/test_unified_cache_linker.py b/test/registered/unit/mem_cache/test_unified_cache_linker.py index 77fce944ef..604bd03056 100644 --- a/test/registered/unit/mem_cache/test_unified_cache_linker.py +++ b/test/registered/unit/mem_cache/test_unified_cache_linker.py @@ -44,6 +44,7 @@ from sglang.srt.mem_cache.unified_cache.unified_cache_linker import ( UnifiedCacheLinkerWrapper, ) from sglang.srt.mem_cache.unified_radix_cache import UnifiedRadixCache +from sglang.srt.runtime_context import get_disagg from sglang.test.ci.ci_register import register_cpu_ci, register_cuda_ci from sglang.test.kits.unified_radix_cache import fixtures as shared_cache_suite from sglang.test.kits.unified_radix_cache.config import ( @@ -493,6 +494,34 @@ class TestUnifiedCacheLinkerPythonBackend( (kv_lookup,) = transfers self.assertEqual(kv_lookup.keys, kv_offload.keys[2:]) + def test_decode_match_skips_linker_lookup(self): + cfg = CacheConfig(page_size=2, kv_size=64, max_context_len=64) + self.cfg = cfg + stored_keys = defaultdict(set) + producer, producer_allocator, producer_req_pool = build_fixture(cfg) + producer_linker = _InMemoryUnifiedCacheLinker(stored_keys) + producer.init_cache_linker(producer_linker) + tokens = list(range(1, 9)) + self._insert(producer, producer_allocator, producer_req_pool, tokens) + producer_linker.complete_next_offload(True) + producer.check_hicache_events() + + consumer, _, consumer_req_pool = build_fixture(cfg) + consumer_linker = _InMemoryUnifiedCacheLinker(stored_keys) + consumer.init_cache_linker(consumer_linker) + key = RadixKey(array("q", tokens)) + with get_disagg().override(disaggregation_mode="decode"): + req = self._make_req(consumer_req_pool) + match = consumer.match_prefix(MatchPrefixParams(key=key, req=req)) + self.assertEqual(match.host_hit_length, 0) + self.assertEqual(consumer_linker.lookup_calls, []) + self.assertFalse(consumer.linker.has_hit(req.rid)) + + req = self._make_req(consumer_req_pool) + match = consumer.match_prefix(MatchPrefixParams(key=key, req=req)) + self.assertEqual(match.host_hit_length, len(tokens)) + consumer.linker.release_request(req.rid) + def test_failed_split_offload_retries_and_reset_releases_locks(self): cfg = CacheConfig(page_size=1, kv_size=64, max_context_len=64) self.cfg = cfg