[HiCache] Remove the unused HiRadixCache (#40787)

This commit is contained in:
Liangsheng Yin
2026-09-22 16:17:12 -07:00
committed by GitHub
parent 7b977ce5dc
commit 4ce23542bf
19 changed files with 47 additions and 2450 deletions
@@ -11,5 +11,5 @@ class P2PTag(IntEnum):
"""
DEFAULT = 0
HIRADIX_PP_SYNC = int.from_bytes(b"PpHi", byteorder="big")
HICACHE_PP_SYNC = int.from_bytes(b"PpHi", byteorder="big")
GRAMMAR_PP_SYNC = int.from_bytes(b"PpGr", byteorder="big")
@@ -987,10 +987,6 @@ class HiCacheController:
)
return producer_id
def evict_device(self, device_indices: torch.Tensor) -> int:
self.mem_pool_device_allocator.free(device_indices)
return len(device_indices)
def evict_host(self, host_indices: torch.Tensor, backup_only: bool = True) -> int:
if not backup_only:
raise ValueError("Other eviction policies are not supported yet.")
+1 -1
View File
@@ -38,7 +38,7 @@ to keep. The layout is specified in
Two groups sit outside that stack:
- **Radix cache** is its own axis. The per-model variants (`radix_cache.py`,
`hiradix_cache.py`, `chunk_cache.py`)
`chunk_cache.py`)
are converging onto the **Unified Radix Cache** (`unified_cache/`,
[#20415](https://github.com/sgl-project/sglang/issues/20415)), whose Full/SWA/Mamba
component model is documented in
@@ -406,10 +406,6 @@ class BasePrefixCache(ABC, PrefixCacheTrait):
implementations that shard trees per cache namespace."""
return self.root_node
def is_backuped(self, node: Any) -> bool:
"""Whether the node's Full KV is present on host."""
return node.backuped
def is_root(self, node: Any) -> bool:
"""Whether the node is a tree root."""
return node is self.root_node
@@ -48,15 +48,6 @@ class HiCacheStorageExtraInfo:
extra_info: Optional[dict] = None
@dataclass(frozen=True)
class PrefetchTimeoutConfig:
"""Knobs for the linear prefetch-timeout policy used by HiCache."""
base: float = 2.0 # seconds, fixed overhead unrelated to token count
per_ki_token: float = 0.1 # seconds per 1024 tokens
max: float = 30.0 # seconds, upper bound for the linear timeout
class PoolName(str, Enum):
"""Well-known pool names used as PoolTransfer/PoolEntry identifiers."""
File diff suppressed because it is too large Load Diff
@@ -33,7 +33,6 @@ if TYPE_CHECKING:
import torch
from sglang.srt.mem_cache.cache_init_params import CacheInitParams
from sglang.srt.mem_cache.hiradix_cache import HiRadixCache
from sglang.srt.mem_cache.unified_radix_cache import UnifiedRadixCache
from sglang.srt.server_args import ServerArgs
@@ -2229,7 +2228,7 @@ def build_minimax_sparse_hicache_stack(
"MiniMax-M3 sparse HiCache does not support pipeline parallelism "
"(pp_size>1) yet."
)
# mirror HiRadix's guard, which the Unified-tree strategy path otherwise skips.
# The Unified-tree strategy path does not reject value-bearing index layers.
if sparse_pool.index_kv_pool is not None:
raise ValueError(
"MiniMax sparse HiCache currently supports index-k-only sparse layers; "
@@ -2301,124 +2300,3 @@ def build_minimax_sparse_hicache_stack(
enable_storage_metrics=enable_storage_metrics,
)
return host_pool_group, cache_controller
def attach_hybrid_minimax_sparse_pool_to_hiradix_cache(
radix_cache: HiRadixCache,
params: CacheInitParams,
*,
extra_config: dict,
prefetch_threshold: int,
enable_storage_metrics: bool,
load_cache_event,
) -> None:
"""Attach HostPoolGroup (KV + index K) + HybridCacheController for HiRadixCache."""
from sglang.srt.mem_cache.memory_pool import MiniMaxSparseKVPool
try:
sparse_pool = radix_cache.kv_cache
if not isinstance(sparse_pool, MiniMaxSparseKVPool):
raise TypeError(
f"Expected MiniMaxSparseKVPool, got {type(sparse_pool).__name__}"
)
if sparse_pool.index_kv_pool is not None:
raise ValueError(
"MiniMax M3 HiCache L2 currently supports index-k-only sparse layers "
"(sparse_disable_index_value=1 for all sparse layers). "
"This model has index_kv_pool layers; INDEXER_KV sidecar is not "
"implemented yet."
)
main_pool = sparse_pool.main_pool
if sparse_pool.index_k_pool is None:
host_pool_group, cache_controller = build_kv_only_stack(
params=params,
kv_pool=main_pool,
full_layer_mapping={
layer_id: layer_id for layer_id in range(main_pool.layer_num)
},
load_cache_event=load_cache_event,
storage_backend=get_memory().hicache_storage_backend,
use_mla=False,
prefetch_threshold=prefetch_threshold,
model_name=get_serving().served_model_name,
storage_backend_extra_config=extra_config,
enable_storage_metrics=enable_storage_metrics,
)
pools_desc = "KV"
else:
host_pool_group, cache_controller = build_minimax_sparse_hicache_stack(
params=params,
sparse_pool=sparse_pool,
load_cache_event=load_cache_event,
storage_backend=get_memory().hicache_storage_backend,
prefetch_threshold=prefetch_threshold,
model_name=get_serving().served_model_name,
storage_backend_extra_config=extra_config,
enable_storage_metrics=enable_storage_metrics,
)
pools_desc = "KV + INDEXER(k-only)"
sparse_pool.register_layer_transfer_counter(cache_controller.layer_done_counter)
radix_cache.full_kv_pool_host = host_pool_group.get_pool(PoolName.KV)
radix_cache.token_to_kv_pool_host = host_pool_group
radix_cache.cache_controller = cache_controller
logger.info(
"Attached hybrid MiniMax sparse pool stack to HiRadixCache: pools=%s, "
"transfer_layer_id_max=%s, sparse_index_k_layers=%s",
pools_desc,
main_pool.layer_num,
len(sparse_pool.index_k_layer_id_mapping),
)
except Exception:
logger.exception("attach_hybrid_minimax_sparse_pool_to_hiradix_cache failed")
raise
def attach_hybrid_dsa_pool_to_hiradix_cache(
radix_cache: HiRadixCache,
params: CacheInitParams,
*,
extra_config: dict,
prefetch_threshold: int,
enable_storage_metrics: bool,
load_cache_event,
) -> None:
"""Attach HostPoolGroup (KV + indexer) + HybridCacheController for HiRadixCache.
This entrypoint is currently intended only for HiRadixCache's DSA path.
"""
try:
kv = radix_cache.kv_cache
layer_mapping = {layer_id: layer_id for layer_id in range(kv.layer_num)}
host_pool_group, cache_controller = build_anchor_sidecar_stack(
params=params,
kv_pool=kv,
sidecar_pool_name=PoolName.INDEXER,
full_layer_mapping=layer_mapping,
load_cache_event=load_cache_event,
storage_backend=get_memory().hicache_storage_backend,
use_mla=True,
override_kv_cache_dim=kv.kv_cache_dim,
prefetch_threshold=prefetch_threshold,
sidecar_host_pool_factory=lambda kv_host_pool: DSAIndexerPoolHost(
kv,
kv_host_pool,
get_memory().hicache_mem_layout,
allocator_type=_get_allocator_type(),
),
model_name=get_serving().served_model_name,
storage_backend_extra_config=extra_config,
enable_storage_metrics=enable_storage_metrics,
)
radix_cache.full_kv_pool_host = host_pool_group.get_pool(PoolName.KV)
radix_cache.token_to_kv_pool_host = host_pool_group
radix_cache.cache_controller = cache_controller
logger.info(
"Attached hybrid DSA pool stack to HiRadixCache: pools=KV + INDEXER, "
"transfer_layer_id_max=%s",
len(layer_mapping),
)
except Exception:
logger.exception("attach_hybrid_dsa_pool_to_hiradix_cache failed")
raise
@@ -266,12 +266,6 @@ class TreeNode:
self.creation_time = time.monotonic()
self.hit_count = 0
# indicating the node is locked to protect from eviction
# incremented when the node is referenced by a storage operation
self.host_ref_counter = 0
# store the host indices of KV cache
self.host_value: Optional[torch.Tensor] = None
self.write_through_pending_id: Optional[int] = None
# store hash values of each pages
self.hash_value: Optional[List[str]] = None
# Namespace-aware hashes used only for external KV events.
@@ -286,21 +280,6 @@ class TreeNode:
def evicted(self):
return self.value is None
@property
def backuped(self):
return self.host_value is not None
def protect_host(self):
"""Protect the host value from eviction."""
self.host_ref_counter += 1
def release_host(self):
"""Release the host value, allowing it to be evicted."""
if self.host_ref_counter > 0:
self.host_ref_counter -= 1
else:
raise RuntimeError("Host reference counter is already zero.")
def get_last_hash_value(self) -> Optional[str]:
"""Returns the hash value of the last page in this node."""
if self.hash_value is None or len(self.hash_value) == 0:
@@ -375,7 +354,6 @@ class RadixCache(BasePrefixCache):
self.root_node = TreeNode(priority=-sys.maxsize)
self.root_node.key = RadixKey(token_ids=array("q"), extra_key=None)
self.root_node.value = []
self.root_node.host_value = []
self.root_node.lock_ref = 1
self.root_node.hash_value = []
self.evictable_size_ = 0
@@ -355,7 +355,7 @@ class UnifiedRadixCache(BasePrefixCache):
data,
group_src=self.pp_rank - 1,
group=self.pp_group,
tag=P2PTag.HIRADIX_PP_SYNC,
tag=P2PTag.HICACHE_PP_SYNC,
)
if self.pp_rank + 1 < self.pp_size:
copy_of_data = data.clone()
@@ -363,7 +363,7 @@ class UnifiedRadixCache(BasePrefixCache):
copy_of_data,
group_dst=self.pp_rank + 1,
group=self.pp_group,
tag=P2PTag.HIRADIX_PP_SYNC,
tag=P2PTag.HICACHE_PP_SYNC,
)
self.work_list.append(send_work)
@@ -3477,8 +3477,8 @@ class UnifiedRadixCache(BasePrefixCache):
def is_load_back_event_done(self, consumer_index: int) -> bool:
"""Return True after the local load-back event is complete.
Mirrors ``HiRadixCache`` so the disagg decode restore state machine
(``DecodeHiCacheTransferMixin``) can gate on load-back completion; the
Lets the disagg decode restore state machine
(``DecodeHiCacheTransferMixin``) gate on load-back completion; the
controller-level ``layer_done_counter`` event is shared across cache
implementations, while the tree-side bookkeeping runs in
``loading_check``.