diff --git a/python/sglang/srt/mem_cache/hiradix_cache.py b/python/sglang/srt/mem_cache/hiradix_cache.py index 34d5b3b11..856204279 100644 --- a/python/sglang/srt/mem_cache/hiradix_cache.py +++ b/python/sglang/srt/mem_cache/hiradix_cache.py @@ -1167,6 +1167,7 @@ class HiRadixCache(RadixCache): self._update_host_leaf_status(node) # update leaf status for the parent because the node is evicted self._update_leaf_status(node.parent) + self._update_host_leaf_status(node.parent) return num_evicted def _evict_regular(self, node: TreeNode): @@ -1233,6 +1234,9 @@ class HiRadixCache(RadixCache): break if not x.evicted: continue + parent_key = self.get_child_key_fn(x.key) + if x.parent is None or x.parent.children.get(parent_key) is not x: + continue if not self._node_backuped(x): if len(x.children) == 0: @@ -1944,6 +1948,7 @@ class HiRadixCache(RadixCache): self._update_host_leaf_status(node) # update parent status as a new leaf is added into device self._update_leaf_status(node.parent) + self._update_host_leaf_status(node.parent) else: self._inc_hit_count(node, chunked) total_prefix_length += prefix_len @@ -1959,6 +1964,7 @@ class HiRadixCache(RadixCache): self._update_host_leaf_status(new_node) # update parent status as a new leaf is added into device self._update_leaf_status(new_node.parent) + self._update_host_leaf_status(new_node.parent) else: self._inc_hit_count(new_node, chunked) total_prefix_length += prefix_len