diff --git a/python/sglang/srt/mem_cache/hiradix_cache.py b/python/sglang/srt/mem_cache/hiradix_cache.py index 718d186c3..9203e2db2 100644 --- a/python/sglang/srt/mem_cache/hiradix_cache.py +++ b/python/sglang/srt/mem_cache/hiradix_cache.py @@ -1287,9 +1287,17 @@ class HiRadixCache(RadixCache): self.evict_host(prefetch_length) host_indices = self.cache_controller.mem_pool_host.alloc(prefetch_length) if host_indices is None: - last_host_node.release_host() - # no sufficient host memory for prefetch - return + avaliable_size = self.cache_controller.mem_pool_host.available_size() + prefetch_length = avaliable_size - (avaliable_size % self.page_size) + if prefetch_length >= self.prefetch_threshold: + new_input_tokens = new_input_tokens[:prefetch_length] + host_indices = self.cache_controller.mem_pool_host.alloc( + prefetch_length + ) + else: + last_host_node.release_host() + # no sufficient host memory for prefetch + return operation = self.cache_controller.prefetch( req_id, host_indices,