From 38cd5fb1e06ccfc64ccaa07a0a735093fb91ecad Mon Sep 17 00:00:00 2001 From: hzh0425 Date: Fri, 29 Aug 2025 09:29:47 +0800 Subject: [PATCH] bugfix(hicache): Move exists check before key suffixing (#9749) --- python/sglang/srt/mem_cache/hicache_storage.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/python/sglang/srt/mem_cache/hicache_storage.py b/python/sglang/srt/mem_cache/hicache_storage.py index c142a59bd..aaaee0262 100644 --- a/python/sglang/srt/mem_cache/hicache_storage.py +++ b/python/sglang/srt/mem_cache/hicache_storage.py @@ -175,11 +175,12 @@ class HiCacheFile(HiCacheStorage): target_location: Optional[Any] = None, target_sizes: Optional[Any] = None, ) -> bool: - key = self._get_suffixed_key(key) - tensor_path = os.path.join(self.file_path, f"{key}.bin") if self.exists(key): logger.debug(f"Key {key} already exists. Skipped.") return True + + key = self._get_suffixed_key(key) + tensor_path = os.path.join(self.file_path, f"{key}.bin") try: value.contiguous().view(dtype=torch.uint8).numpy().tofile(tensor_path) return True