From e7bdeb538ee8e53ccd90f3872289212a6fd9bd65 Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 24 Sep 2024 16:47:59 +0800 Subject: [PATCH] debug_radixcache_stack_overflow --- python/sglang/srt/mem_cache/radix_cache.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/python/sglang/srt/mem_cache/radix_cache.py b/python/sglang/srt/mem_cache/radix_cache.py index a1c685405a..2b237c8562 100644 --- a/python/sglang/srt/mem_cache/radix_cache.py +++ b/python/sglang/srt/mem_cache/radix_cache.py @@ -288,18 +288,18 @@ def _total_size_helper(self, node: TreeNode): for child in node.children.values(): x += self._total_size_helper(child) return x - + def _collect_leaves(self): ret_list = [] + stack = [self.root_node] - def dfs_(cur_node): + while stack: + cur_node = stack.pop() if len(cur_node.children) == 0: ret_list.append(cur_node) + else: + stack.extend(cur_node.children.values()) - for x in cur_node.children.values(): - dfs_(x) - - dfs_(self.root_node) return ret_list