From 9cb362f70eb5a81b58dba8c7094d8a6757865800 Mon Sep 17 00:00:00 2001 From: shuwenn <47200617+alphabetc1@users.noreply.github.com> Date: Thu, 2 Apr 2026 08:42:07 +0800 Subject: [PATCH] [HiCache] fix: Clone host indices to avoid memory leak (#21624) Co-authored-by: Zhiqiang Xie --- python/sglang/srt/mem_cache/hi_mamba_radix_cache.py | 4 ++-- python/sglang/srt/mem_cache/hiradix_cache.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/python/sglang/srt/mem_cache/hi_mamba_radix_cache.py b/python/sglang/srt/mem_cache/hi_mamba_radix_cache.py index fafc6d246..a08b2a33c 100644 --- a/python/sglang/srt/mem_cache/hi_mamba_radix_cache.py +++ b/python/sglang/srt/mem_cache/hi_mamba_radix_cache.py @@ -296,7 +296,7 @@ class HiMambaRadixCache(MambaRadixCache): extra_pools=extra_pools, ) if host_indices is not None: - node.host_value = host_indices + node.host_value = host_indices.clone() if extra_pools is not None: self.mamba_backup_commit(node, extra_pools) assert len(node.host_value) > 0 @@ -2044,7 +2044,7 @@ class HiMambaRadixCache(MambaRadixCache): return host_indices = transfers[0].host_indices if node.mamba_host_value is None and host_indices is not None: - node.mamba_host_value = host_indices + node.mamba_host_value = host_indices.clone() self.mamba_host_lru_list.insert_mru(node) def mamba_archive_transfers(self, node: TreeNode) -> Optional[list[PoolTransfer]]: diff --git a/python/sglang/srt/mem_cache/hiradix_cache.py b/python/sglang/srt/mem_cache/hiradix_cache.py index c72556564..3c1e97daa 100644 --- a/python/sglang/srt/mem_cache/hiradix_cache.py +++ b/python/sglang/srt/mem_cache/hiradix_cache.py @@ -619,7 +619,7 @@ class HiRadixCache(RadixCache): node_id=node.id, ) if host_indices is not None: - node.host_value = host_indices + node.host_value = host_indices.clone() assert len(node.host_value) > 0 self.ongoing_write_through[node.id] = node if not write_back: