From 79ce3688bb9856b3eacd70dc5c437e50c283c205 Mon Sep 17 00:00:00 2001 From: hzh0425 Date: Wed, 27 Aug 2025 01:42:23 +0800 Subject: [PATCH] BugFix(hicache): Fix host indices out of bound error (#9637) Co-authored-by: Zhiqiang Xie --- python/sglang/srt/managers/cache_controller.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/python/sglang/srt/managers/cache_controller.py b/python/sglang/srt/managers/cache_controller.py index d89d2b634..bcd7940ac 100644 --- a/python/sglang/srt/managers/cache_controller.py +++ b/python/sglang/srt/managers/cache_controller.py @@ -616,12 +616,13 @@ class HiCacheController: f"Prefetch operation {operation.request_id} failed to retrieve page {hash_values[i]}." ) break - self.mem_pool_host.set_from_flat_data_page( - host_indices[operation.completed_tokens], - page_data[i], - ) - if not operation.increment(self.page_size): - break # Operation terminated by controller + if operation.increment(self.page_size): + self.mem_pool_host.set_from_flat_data_page( + host_indices[i * self.page_size], + page_data[i], + ) + else: + break def _page_transfer(self, operation): # Select the get function and batch size