[UnifiedTree]: move /mem_cache/unifed_cache_component dir to /mem_cache/unified_cache (#32484)

This commit is contained in:
Zhangheng
2026-07-28 16:28:21 +08:00
committed by GitHub
parent fc8b328f5c
commit 60d6914f17
23 changed files with 62 additions and 62 deletions
@@ -17,10 +17,10 @@ import torch
from sglang.srt.mem_cache.base_prefix_cache import EvictParams, InsertResult from sglang.srt.mem_cache.base_prefix_cache import EvictParams, InsertResult
from sglang.srt.mem_cache.memory_pool import ReqToTokenPool from sglang.srt.mem_cache.memory_pool import ReqToTokenPool
from sglang.srt.mem_cache.unified_cache_components.mamba_component import ( from sglang.srt.mem_cache.unified_cache.components.mamba_component import (
MambaComponent, MambaComponent,
) )
from sglang.srt.mem_cache.unified_cache_components.tree_component import TreeComponent from sglang.srt.mem_cache.unified_cache.components.tree_component import TreeComponent
_CACHE_ATTRS = ("offset", "lengths", "left_padding") _CACHE_ATTRS = ("offset", "lengths", "left_padding")
_MISSING = object() _MISSING = object()
@@ -31,7 +31,7 @@ if TYPE_CHECKING:
CacheAction, CacheAction,
ComponentAction, ComponentAction,
) )
from sglang.srt.mem_cache.unified_cache_components.tree_component import ( from sglang.srt.mem_cache.unified_cache.components.tree_component import (
ComponentType, ComponentType,
) )
@@ -8,8 +8,8 @@ import torch
if TYPE_CHECKING: if TYPE_CHECKING:
from sglang.srt.mem_cache.allocator import BaseTokenToKVPoolAllocator from sglang.srt.mem_cache.allocator import BaseTokenToKVPoolAllocator
from sglang.srt.mem_cache.memory_pool import ReqToTokenPool from sglang.srt.mem_cache.memory_pool import ReqToTokenPool
from sglang.srt.mem_cache.unified_cache_components import ComponentType from sglang.srt.mem_cache.unified_cache.components import ComponentType
from sglang.srt.mem_cache.unified_cache_components.tree_component import ( from sglang.srt.mem_cache.unified_cache.components.tree_component import (
TreeComponent, TreeComponent,
) )
@@ -27,7 +27,7 @@ from sglang.srt.mem_cache.pool_host.mha import (
get_mha_host_pool_cls, get_mha_host_pool_cls,
) )
from sglang.srt.mem_cache.pool_host.mla import MLATokenToKVPoolHost from sglang.srt.mem_cache.pool_host.mla import MLATokenToKVPoolHost
from sglang.srt.mem_cache.unified_cache_components import ComponentType from sglang.srt.mem_cache.unified_cache.components import ComponentType
if TYPE_CHECKING: if TYPE_CHECKING:
import torch import torch
+1 -1
View File
@@ -166,7 +166,7 @@ def _create_unified_radix_cache(
params: CacheInitParams, params: CacheInitParams,
) -> BasePrefixCache: ) -> BasePrefixCache:
"""Initialize a UnifiedRadixCache with proper components and optional HiCache.""" """Initialize a UnifiedRadixCache with proper components and optional HiCache."""
from sglang.srt.mem_cache.unified_cache_components import ComponentType from sglang.srt.mem_cache.unified_cache.components import ComponentType
from sglang.srt.mem_cache.unified_radix_cache import UnifiedRadixCache from sglang.srt.mem_cache.unified_radix_cache import UnifiedRadixCache
tree_components = [ComponentType.FULL] tree_components = [ComponentType.FULL]
@@ -5,7 +5,7 @@
events -- the only object that touches that state; no scheduling policy or IO, events -- the only object that touches that state; no scheduling policy or IO,
and never touches the cache. References the cache-owned component drivers to and never touches the cache. References the cache-owned component drivers to
drive their tree-level hooks. drive their tree-level hooks.
- **Components** (``unified_cache_components.TreeComponent`` subclasses): the - **Components** (``unified_cache.components.TreeComponent`` subclasses): the
per-component (FULL/SWA/MAMBA) drivers. Built and owned by the Controller; per-component (FULL/SWA/MAMBA) drivers. Built and owned by the Controller;
hold the cache for cache-level logic and the TreeCore for tree state. hold the cache for cache-level logic and the TreeCore for tree state.
- **Controller** (``unified_radix_cache.UnifiedRadixCache``): the scheduling brain - **Controller** (``unified_radix_cache.UnifiedRadixCache``): the scheduling brain
@@ -1,7 +1,7 @@
from sglang.srt.mem_cache.unified_cache_components.full_component import FullComponent from sglang.srt.mem_cache.unified_cache.components.full_component import FullComponent
from sglang.srt.mem_cache.unified_cache_components.mamba_component import MambaComponent from sglang.srt.mem_cache.unified_cache.components.mamba_component import MambaComponent
from sglang.srt.mem_cache.unified_cache_components.swa_component import SWAComponent from sglang.srt.mem_cache.unified_cache.components.swa_component import SWAComponent
from sglang.srt.mem_cache.unified_cache_components.tree_component import ( from sglang.srt.mem_cache.unified_cache.components.tree_component import (
_NUM_COMPONENT_TYPES, _NUM_COMPONENT_TYPES,
BASE_COMPONENT_TYPE, BASE_COMPONENT_TYPE,
CacheTransferPhase, CacheTransferPhase,
@@ -18,7 +18,7 @@ from sglang.srt.mem_cache.hicache_storage import (
PoolTransferResult, PoolTransferResult,
) )
from sglang.srt.mem_cache.unified_cache.cache_action import FreeComponentDeviceSlot from sglang.srt.mem_cache.unified_cache.cache_action import FreeComponentDeviceSlot
from sglang.srt.mem_cache.unified_cache_components.tree_component import ( from sglang.srt.mem_cache.unified_cache.components.tree_component import (
CacheTransferPhase, CacheTransferPhase,
ComponentType, ComponentType,
EvictLayer, EvictLayer,
@@ -25,7 +25,7 @@ from sglang.srt.mem_cache.unified_cache.cache_action import (
FreeComponentHostSlot, FreeComponentHostSlot,
MambaEvictExcessPathStates, MambaEvictExcessPathStates,
) )
from sglang.srt.mem_cache.unified_cache_components.tree_component import ( from sglang.srt.mem_cache.unified_cache.components.tree_component import (
CacheTransferPhase, CacheTransferPhase,
ComponentType, ComponentType,
EvictLayer, EvictLayer,
@@ -27,7 +27,7 @@ from sglang.srt.mem_cache.unified_cache.cache_action import (
RecoverSWAWithLockedFull, RecoverSWAWithLockedFull,
SWARebuild, SWARebuild,
) )
from sglang.srt.mem_cache.unified_cache_components.tree_component import ( from sglang.srt.mem_cache.unified_cache.components.tree_component import (
BASE_COMPONENT_TYPE, BASE_COMPONENT_TYPE,
CacheTransferPhase, CacheTransferPhase,
ComponentType, ComponentType,
@@ -13,10 +13,10 @@ from typing import TYPE_CHECKING, Callable, Optional
if TYPE_CHECKING: if TYPE_CHECKING:
from sglang.srt.mem_cache.cache_init_params import CacheInitParams from sglang.srt.mem_cache.cache_init_params import CacheInitParams
from sglang.srt.mem_cache.unified_cache.component_type import ComponentType from sglang.srt.mem_cache.unified_cache.component_type import ComponentType
from sglang.srt.mem_cache.unified_cache.components import TreeComponent
from sglang.srt.mem_cache.unified_cache.unified_tree_core_interface import ( from sglang.srt.mem_cache.unified_cache.unified_tree_core_interface import (
UnifiedTreeCoreInterface, UnifiedTreeCoreInterface,
) )
from sglang.srt.mem_cache.unified_cache_components import TreeComponent
TreeCoreFactory = Callable[ TreeCoreFactory = Callable[
["CacheInitParams", "dict[ComponentType, TreeComponent]"], ["CacheInitParams", "dict[ComponentType, TreeComponent]"],
@@ -49,6 +49,17 @@ from sglang.srt.mem_cache.unified_cache.cache_action import (
FreeDeviceKV, FreeDeviceKV,
ReplaceWriteThroughOnNodeSplit, ReplaceWriteThroughOnNodeSplit,
) )
from sglang.srt.mem_cache.unified_cache.components import (
_NUM_COMPONENT_TYPES,
BASE_COMPONENT_TYPE,
CacheTransferPhase,
ComponentData,
ComponentType,
EvictLayer,
LRURefreshPhase,
TreeComponent,
get_and_increase_time_counter,
)
from sglang.srt.mem_cache.unified_cache.unified_tree_core_interface import ( from sglang.srt.mem_cache.unified_cache.unified_tree_core_interface import (
DecSwaLockOnlyResult, DecSwaLockOnlyResult,
DemoteResult, DemoteResult,
@@ -61,17 +72,6 @@ from sglang.srt.mem_cache.unified_cache.unified_tree_core_interface import (
RadixCacheWalkResult, RadixCacheWalkResult,
UnifiedTreeCoreInterface, UnifiedTreeCoreInterface,
) )
from sglang.srt.mem_cache.unified_cache_components import (
_NUM_COMPONENT_TYPES,
BASE_COMPONENT_TYPE,
CacheTransferPhase,
ComponentData,
ComponentType,
EvictLayer,
LRURefreshPhase,
TreeComponent,
get_and_increase_time_counter,
)
from sglang.srt.mem_cache.utils import ( from sglang.srt.mem_cache.utils import (
compute_node_hash_values, compute_node_hash_values,
get_eviction_strategy, get_eviction_strategy,
@@ -102,14 +102,14 @@ if TYPE_CHECKING:
CacheAction, CacheAction,
ComponentAction, ComponentAction,
) )
from sglang.srt.mem_cache.unified_cache.components import (
CacheTransferPhase,
ComponentType,
)
from sglang.srt.mem_cache.unified_cache.unified_tree_core import ( from sglang.srt.mem_cache.unified_cache.unified_tree_core import (
StorageBackupSpec, StorageBackupSpec,
UnifiedTreeNode, UnifiedTreeNode,
) )
from sglang.srt.mem_cache.unified_cache_components import (
CacheTransferPhase,
ComponentType,
)
class UnifiedTreeCoreInterface(KVCacheEventMixin, ABC): class UnifiedTreeCoreInterface(KVCacheEventMixin, ABC):
@@ -41,17 +41,10 @@ from sglang.srt.mem_cache.unified_cache.cache_action import (
FreeDeviceKV, FreeDeviceKV,
ReplaceWriteThroughOnNodeSplit, ReplaceWriteThroughOnNodeSplit,
) )
from sglang.srt.mem_cache.unified_cache.tree_core_registry import create_tree_core
from sglang.srt.mem_cache.unified_cache.unified_tree_core import ( # noqa: F401
NodeId,
UnifiedLRUList,
UnifiedTreeCore,
UnifiedTreeNode,
)
# UnifiedTreeNode / UnifiedLRUList live on the tree core; re-exported here # UnifiedTreeNode / UnifiedLRUList live on the tree core; re-exported here
# because other modules and tests import them from this module. # because other modules and tests import them from this module.
from sglang.srt.mem_cache.unified_cache_components import ( from sglang.srt.mem_cache.unified_cache.components import (
BASE_COMPONENT_TYPE, BASE_COMPONENT_TYPE,
CacheTransferPhase, CacheTransferPhase,
ComponentType, ComponentType,
@@ -61,6 +54,13 @@ from sglang.srt.mem_cache.unified_cache_components import (
SWAComponent, SWAComponent,
TreeComponent, TreeComponent,
) )
from sglang.srt.mem_cache.unified_cache.tree_core_registry import create_tree_core
from sglang.srt.mem_cache.unified_cache.unified_tree_core import ( # noqa: F401
NodeId,
UnifiedLRUList,
UnifiedTreeCore,
UnifiedTreeNode,
)
from sglang.srt.observability.metrics_collector import ( from sglang.srt.observability.metrics_collector import (
STAT_LOGGER_ROLE_STORAGE, STAT_LOGGER_ROLE_STORAGE,
StorageMetricsCollector, StorageMetricsCollector,
@@ -10,11 +10,11 @@ from sglang.srt.kv_canary.radix_cache_walker import walk_radix_cache_for_canary
from sglang.srt.mem_cache.cache_init_params import CacheInitParams from sglang.srt.mem_cache.cache_init_params import CacheInitParams
from sglang.srt.mem_cache.radix_cache import RadixKey from sglang.srt.mem_cache.radix_cache import RadixKey
from sglang.srt.mem_cache.swa_radix_cache import SWARadixCache, TreeNode from sglang.srt.mem_cache.swa_radix_cache import SWARadixCache, TreeNode
from sglang.srt.mem_cache.unified_cache.unified_tree_core import UnifiedTreeCore from sglang.srt.mem_cache.unified_cache.components import (
from sglang.srt.mem_cache.unified_cache_components import (
BASE_COMPONENT_TYPE, BASE_COMPONENT_TYPE,
ComponentType, ComponentType,
) )
from sglang.srt.mem_cache.unified_cache.unified_tree_core import UnifiedTreeCore
from sglang.srt.mem_cache.unified_radix_cache import UnifiedRadixCache, UnifiedTreeNode from sglang.srt.mem_cache.unified_radix_cache import UnifiedRadixCache, UnifiedTreeNode
from sglang.test.ci.ci_register import register_amd_ci, register_cuda_ci from sglang.test.ci.ci_register import register_amd_ci, register_cuda_ci
from sglang.test.kv_canary.fixtures import DEFAULT_DEVICE, make_radix_cache from sglang.test.kv_canary.fixtures import DEFAULT_DEVICE, make_radix_cache
@@ -14,13 +14,13 @@ import torch
from test_unified_radix_cache_unittest import CacheConfig, UnifiedRadixCacheSuite from test_unified_radix_cache_unittest import CacheConfig, UnifiedRadixCacheSuite
from sglang.srt.mem_cache.unified_cache.cache_action import MambaEvictExcessPathStates from sglang.srt.mem_cache.unified_cache.cache_action import MambaEvictExcessPathStates
from sglang.srt.mem_cache.unified_cache.unified_tree_core import UnifiedTreeCore from sglang.srt.mem_cache.unified_cache.components.mamba_component import (
from sglang.srt.mem_cache.unified_cache_components.mamba_component import (
MambaComponent, MambaComponent,
) )
from sglang.srt.mem_cache.unified_cache_components.tree_component import ( from sglang.srt.mem_cache.unified_cache.components.tree_component import (
ComponentType, ComponentType,
) )
from sglang.srt.mem_cache.unified_cache.unified_tree_core import UnifiedTreeCore
from sglang.srt.mem_cache.unified_radix_cache import UnifiedLRUList, UnifiedTreeNode from sglang.srt.mem_cache.unified_radix_cache import UnifiedLRUList, UnifiedTreeNode
from sglang.srt.server_args import ServerArgs from sglang.srt.server_args import ServerArgs
from sglang.test.test_utils import CustomTestCase from sglang.test.test_utils import CustomTestCase
@@ -227,7 +227,7 @@ class TestDefaultRadixCacheFactory(CustomTestCase):
patch.dict( patch.dict(
"sys.modules", "sys.modules",
{ {
"sglang.srt.mem_cache.unified_cache_components": fake_components, "sglang.srt.mem_cache.unified_cache.components": fake_components,
"sglang.srt.mem_cache.unified_radix_cache": fake_radix, "sglang.srt.mem_cache.unified_radix_cache": fake_radix,
}, },
), ),
@@ -261,7 +261,7 @@ class TestDefaultRadixCacheFactory(CustomTestCase):
with patch.dict( with patch.dict(
"sys.modules", "sys.modules",
{ {
"sglang.srt.mem_cache.unified_cache_components": fake_components, "sglang.srt.mem_cache.unified_cache.components": fake_components,
"sglang.srt.mem_cache.unified_radix_cache": fake_radix, "sglang.srt.mem_cache.unified_radix_cache": fake_radix,
}, },
): ):
@@ -281,7 +281,7 @@ class TestDefaultRadixCacheFactory(CustomTestCase):
with patch.dict( with patch.dict(
"sys.modules", "sys.modules",
{ {
"sglang.srt.mem_cache.unified_cache_components": fake_components, "sglang.srt.mem_cache.unified_cache.components": fake_components,
"sglang.srt.mem_cache.unified_radix_cache": fake_radix, "sglang.srt.mem_cache.unified_radix_cache": fake_radix,
}, },
): ):
@@ -302,7 +302,7 @@ class TestDefaultRadixCacheFactory(CustomTestCase):
with patch.dict( with patch.dict(
"sys.modules", "sys.modules",
{ {
"sglang.srt.mem_cache.unified_cache_components": fake_components, "sglang.srt.mem_cache.unified_cache.components": fake_components,
"sglang.srt.mem_cache.unified_radix_cache": fake_radix, "sglang.srt.mem_cache.unified_radix_cache": fake_radix,
}, },
): ):
@@ -322,7 +322,7 @@ class TestDefaultRadixCacheFactory(CustomTestCase):
with patch.dict( with patch.dict(
"sys.modules", "sys.modules",
{ {
"sglang.srt.mem_cache.unified_cache_components": fake_components, "sglang.srt.mem_cache.unified_cache.components": fake_components,
"sglang.srt.mem_cache.unified_radix_cache": fake_radix, "sglang.srt.mem_cache.unified_radix_cache": fake_radix,
}, },
): ):
@@ -348,7 +348,7 @@ class TestDefaultRadixCacheFactory(CustomTestCase):
with patch.dict( with patch.dict(
"sys.modules", "sys.modules",
{ {
"sglang.srt.mem_cache.unified_cache_components": fake_components, "sglang.srt.mem_cache.unified_cache.components": fake_components,
"sglang.srt.mem_cache.unified_radix_cache": fake_radix, "sglang.srt.mem_cache.unified_radix_cache": fake_radix,
}, },
): ):
@@ -7,6 +7,10 @@ from sglang.srt.environ import envs
from sglang.srt.mem_cache.cache_init_params import CacheInitParams from sglang.srt.mem_cache.cache_init_params import CacheInitParams
from sglang.srt.mem_cache.memory_pool import ReqToTokenPool from sglang.srt.mem_cache.memory_pool import ReqToTokenPool
from sglang.srt.mem_cache.unified_cache.component_type import ComponentType from sglang.srt.mem_cache.unified_cache.component_type import ComponentType
from sglang.srt.mem_cache.unified_cache.components.tree_component import (
EvictLayer,
TreeComponent,
)
from sglang.srt.mem_cache.unified_cache.tree_core_registry import ( from sglang.srt.mem_cache.unified_cache.tree_core_registry import (
_TREE_CORE_REGISTRY, _TREE_CORE_REGISTRY,
create_tree_core, create_tree_core,
@@ -14,10 +18,6 @@ from sglang.srt.mem_cache.unified_cache.tree_core_registry import (
registered_tree_core_backends, registered_tree_core_backends,
) )
from sglang.srt.mem_cache.unified_cache.unified_tree_core import UnifiedTreeCore from sglang.srt.mem_cache.unified_cache.unified_tree_core import UnifiedTreeCore
from sglang.srt.mem_cache.unified_cache_components.tree_component import (
EvictLayer,
TreeComponent,
)
from sglang.srt.mem_cache.unified_radix_cache import UnifiedRadixCache from sglang.srt.mem_cache.unified_radix_cache import UnifiedRadixCache
from sglang.test.ci.ci_register import register_cpu_ci from sglang.test.ci.ci_register import register_cpu_ci
from sglang.test.test_utils import CustomTestCase from sglang.test.test_utils import CustomTestCase
@@ -34,7 +34,7 @@ from sglang.srt.mem_cache.mamba_radix_cache import MambaRadixCache
from sglang.srt.mem_cache.memory_pool import HybridLinearKVPool, HybridReqToTokenPool from sglang.srt.mem_cache.memory_pool import HybridLinearKVPool, HybridReqToTokenPool
from sglang.srt.mem_cache.radix_cache import RadixKey from sglang.srt.mem_cache.radix_cache import RadixKey
from sglang.srt.mem_cache.swa_radix_cache import SWARadixCache from sglang.srt.mem_cache.swa_radix_cache import SWARadixCache
from sglang.srt.mem_cache.unified_cache_components.tree_component import ComponentType from sglang.srt.mem_cache.unified_cache.components.tree_component import ComponentType
from sglang.srt.mem_cache.unified_radix_cache import UnifiedRadixCache from sglang.srt.mem_cache.unified_radix_cache import UnifiedRadixCache
from sglang.srt.server_args import ServerArgs, set_global_server_args_for_scheduler from sglang.srt.server_args import ServerArgs, set_global_server_args_for_scheduler
from sglang.srt.utils import get_device from sglang.srt.utils import get_device
@@ -59,6 +59,12 @@ from sglang.srt.mem_cache.unified_cache.cache_action import (
ReplaceWriteThroughOnNodeSplit, ReplaceWriteThroughOnNodeSplit,
SWARebuild, SWARebuild,
) )
from sglang.srt.mem_cache.unified_cache.components.tree_component import (
CacheTransferPhase,
ComponentType,
EvictLayer,
TreeComponent,
)
from sglang.srt.mem_cache.unified_cache.unified_tree_core_interface import ( from sglang.srt.mem_cache.unified_cache.unified_tree_core_interface import (
DecSwaLockOnlyResult, DecSwaLockOnlyResult,
DemoteResult, DemoteResult,
@@ -67,12 +73,6 @@ from sglang.srt.mem_cache.unified_cache.unified_tree_core_interface import (
EvictDeviceLeafResult, EvictDeviceLeafResult,
EvictDeviceNextNodeResult, EvictDeviceNextNodeResult,
) )
from sglang.srt.mem_cache.unified_cache_components.tree_component import (
CacheTransferPhase,
ComponentType,
EvictLayer,
TreeComponent,
)
from sglang.srt.mem_cache.unified_radix_cache import ( from sglang.srt.mem_cache.unified_radix_cache import (
COMPONENT_REGISTRY, COMPONENT_REGISTRY,
UnifiedLRUList, UnifiedLRUList,
@@ -17,7 +17,7 @@ from sglang.srt.mem_cache.hybrid_cache.hybrid_pool_assembler import (
_SwaStrategy, _SwaStrategy,
register_stack_strategy, register_stack_strategy,
) )
from sglang.srt.mem_cache.unified_cache_components import ComponentType from sglang.srt.mem_cache.unified_cache.components import ComponentType
from sglang.test.ci.ci_register import register_cpu_ci from sglang.test.ci.ci_register import register_cpu_ci
register_cpu_ci(est_time=2, suite="base-a-test-cpu") register_cpu_ci(est_time=2, suite="base-a-test-cpu")