From d6b28b4a69621c478544782c45419e98b9ff9adc Mon Sep 17 00:00:00 2001 From: shuwenn <47200617+alphabetc1@users.noreply.github.com> Date: Thu, 14 May 2026 04:54:36 +0800 Subject: [PATCH] [Refactor] Remove dead key_convert_fn / convert_to_bigram_key (#25161) Co-authored-by: Claude Opus 4.7 (1M context) --- python/sglang/srt/mem_cache/swa_radix_cache.py | 7 +------ python/sglang/srt/mem_cache/unified_radix_cache.py | 5 ----- python/sglang/srt/mem_cache/utils.py | 10 ---------- 3 files changed, 1 insertion(+), 21 deletions(-) diff --git a/python/sglang/srt/mem_cache/swa_radix_cache.py b/python/sglang/srt/mem_cache/swa_radix_cache.py index ed436b7e1..af2d99e96 100644 --- a/python/sglang/srt/mem_cache/swa_radix_cache.py +++ b/python/sglang/srt/mem_cache/swa_radix_cache.py @@ -44,7 +44,7 @@ from sglang.srt.mem_cache.cache_init_params import CacheInitParams from sglang.srt.mem_cache.events import KVCacheEventMixin from sglang.srt.mem_cache.radix_cache import RadixKey from sglang.srt.mem_cache.swa_memory_pool import SWATokenToKVPoolAllocator -from sglang.srt.mem_cache.utils import convert_to_bigram_key, split_node_hash_value +from sglang.srt.mem_cache.utils import split_node_hash_value if TYPE_CHECKING: from sglang.srt.managers.schedule_batch import Req @@ -353,11 +353,6 @@ class SWARadixCache(KVCacheEventMixin, BasePrefixCache): else: self.device = torch.device("cpu") - if self.is_eagle: - self.key_convert_fn = convert_to_bigram_key - else: - self.key_convert_fn = lambda key: key - if params.enable_metrics: self.init_metrics_collector() diff --git a/python/sglang/srt/mem_cache/unified_radix_cache.py b/python/sglang/srt/mem_cache/unified_radix_cache.py index c1618f6a4..80a3da5bb 100644 --- a/python/sglang/srt/mem_cache/unified_radix_cache.py +++ b/python/sglang/srt/mem_cache/unified_radix_cache.py @@ -37,7 +37,6 @@ from sglang.srt.mem_cache.unified_cache_components import ( TreeComponent, get_and_increase_time_counter, ) -from sglang.srt.mem_cache.utils import convert_to_bigram_key from sglang.srt.session.streaming_session import StreamingSession if TYPE_CHECKING: @@ -225,10 +224,6 @@ class UnifiedRadixCache(BasePrefixCache): self.hicache_anchor_kv_shared_indices_pools: list[ tuple[PoolName, PoolHitPolicy] ] = [] - if self.is_eagle: - self.key_convert_fn = convert_to_bigram_key - else: - self.key_convert_fn = lambda key: key # Streaming session: embedded StreamingSession with self as inner. # Always on -- zero overhead when no streaming session is open (the diff --git a/python/sglang/srt/mem_cache/utils.py b/python/sglang/srt/mem_cache/utils.py index bf443661d..03e426cdc 100644 --- a/python/sglang/srt/mem_cache/utils.py +++ b/python/sglang/srt/mem_cache/utils.py @@ -373,16 +373,6 @@ def maybe_init_custom_mem_pool( return False, None, None -def convert_to_bigram_key(tokens: List[int]) -> List[Tuple[int, int]]: - # EAGLE uses bigram keys in the radix tree since draft sequence is the one-token-shifted version of target - # [1, 2, 3, 4] -> [(1,2), (2,3), (3,4)] - if len(tokens) and isinstance(tokens[0], tuple): - return tokens - if len(tokens) < 2: - return [] - return [(tokens[i], tokens[i + 1]) for i in range(len(tokens) - 1)] - - def get_hash_str(token_ids: List[int], prior_hash: Optional[str] = None) -> str: hasher = hashlib.sha256()