[MemCache] Skip KV events and eviction config on a disabled radix cache (#43253)

This commit is contained in:
Liangsheng Yin
2026-10-08 19:27:39 -07:00
committed by GitHub
parent e54f08c860
commit f6569bce4d
4 changed files with 69 additions and 3 deletions
+6 -2
View File
@@ -287,8 +287,11 @@ class RadixCache(BasePrefixCache):
self.is_eagle = params.is_eagle
self.eviction_policy = params.eviction_policy.lower()
# A disabled tree holds nothing, so it reports no KV events and never
# evicts; its eviction policy config is not built or validated.
self.kv_events = KVCacheEventRecorder(
enabled=params.enable_kv_cache_events, page_size=self.page_size
enabled=params.enable_kv_cache_events and not self.disable,
page_size=self.page_size,
)
if params.enable_metrics:
@@ -304,7 +307,8 @@ class RadixCache(BasePrefixCache):
self.device = torch.device("cpu")
self.eviction_strategy = get_eviction_strategy(
self.eviction_policy, params.eviction_policy_config
"lru" if self.disable else self.eviction_policy,
None if self.disable else params.eviction_policy_config,
)
self.evictable_leaves = set()
@@ -216,9 +216,21 @@ class UnifiedRadixCache(BasePrefixCache):
# The TreeCore owns the tree member-var state (structure, LRUs, sizes,
# evictable leaves) and drives the components' tree-level hooks.
self._tree_core_backend = select_tree_core_backend(params)
# A disabled tree holds nothing, so it reports no KV events and never
# evicts; its eviction policy config is not built or validated.
tree_params = (
replace(
params,
enable_kv_cache_events=False,
eviction_policy="lru",
eviction_policy_config=None,
)
if self.disable
else params
)
self.tree_core = create_tree_core(
name=self._tree_core_backend,
params=params,
params=tree_params,
components=self.components,
)
# Components execute boundary actions through the tree core.