From e6692bf4a53780572635f65d524f579f5ce08220 Mon Sep 17 00:00:00 2001 From: luzengxiangcn <60803814+luzengxiangcn@users.noreply.github.com> Date: Tue, 24 Sep 2024 19:58:01 +0800 Subject: [PATCH] debug radixcache stack_overflow (#1499) --- python/sglang/srt/mem_cache/radix_cache.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/python/sglang/srt/mem_cache/radix_cache.py b/python/sglang/srt/mem_cache/radix_cache.py index a1c685405..7690d18b7 100644 --- a/python/sglang/srt/mem_cache/radix_cache.py +++ b/python/sglang/srt/mem_cache/radix_cache.py @@ -291,15 +291,15 @@ class RadixCache(BasePrefixCache): 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