[Feature] Radix Tree in C++ (#7369)

This commit is contained in:
DarkSharpness
2025-08-02 19:50:14 -07:00
committed by GitHub
parent 828a4fe944
commit e273aa6dcf
12 changed files with 1466 additions and 1 deletions

View File

@@ -569,7 +569,23 @@ class Scheduler(
page_size=self.page_size,
)
else:
if self.enable_hierarchical_cache:
if os.environ.get("SGLANG_EXPERIMENTAL_CPP_RADIX_TREE") == "1":
# lazy import to avoid JIT overhead
from sglang.srt.mem_cache.radix_cache_cpp import RadixCacheCpp
self.tree_cache = RadixCacheCpp(
disable=False,
use_hicache=self.enable_hierarchical_cache,
req_to_token_pool=self.req_to_token_pool,
token_to_kv_pool=self.token_to_kv_pool_allocator,
tp_cache_group=self.tp_cpu_group,
page_size=self.page_size,
hicache_ratio=server_args.hicache_ratio,
hicache_size=server_args.hicache_size,
hicache_write_policy=server_args.hicache_write_policy,
enable_kv_cache_events=self.enable_kv_cache_events,
)
elif self.enable_hierarchical_cache:
self.tree_cache = HiRadixCache(
req_to_token_pool=self.req_to_token_pool,
token_to_kv_pool_allocator=self.token_to_kv_pool_allocator,