From 26627e999ded02398a7337697e7281c9b8c567fa Mon Sep 17 00:00:00 2001 From: Liangsheng Yin Date: Wed, 12 Aug 2026 20:50:46 -0700 Subject: [PATCH] [Fix] Snapshot `req.prefix_indices` when the prefix cache is disabled (#34644) --- python/sglang/srt/mem_cache/swa_radix_cache.py | 2 +- python/sglang/srt/mem_cache/unified_radix_cache.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/python/sglang/srt/mem_cache/swa_radix_cache.py b/python/sglang/srt/mem_cache/swa_radix_cache.py index 4268130e9..01c8814db 100644 --- a/python/sglang/srt/mem_cache/swa_radix_cache.py +++ b/python/sglang/srt/mem_cache/swa_radix_cache.py @@ -519,7 +519,7 @@ class SWARadixCache(KVCacheEventMixin, BasePrefixCache): ] # `req.prefix_indices` will be used in `PrefillAdder::add_chunked_req` later - req.prefix_indices = kv_indices + req.prefix_indices = kv_indices.to(dtype=torch.int64, copy=True) return token_ids = req.get_fill_ids() diff --git a/python/sglang/srt/mem_cache/unified_radix_cache.py b/python/sglang/srt/mem_cache/unified_radix_cache.py index 375c17832..597de340d 100644 --- a/python/sglang/srt/mem_cache/unified_radix_cache.py +++ b/python/sglang/srt/mem_cache/unified_radix_cache.py @@ -749,7 +749,7 @@ class UnifiedRadixCache(BasePrefixCache): kv_indices = self.req_to_token_pool.req_to_token[ req.req_pool_idx, : len(token_ids) ] - req.prefix_indices = kv_indices + req.prefix_indices = kv_indices.to(dtype=torch.int64, copy=True) return kv_indices_orig = self.req_to_token_pool.req_to_token[