Prhub

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

原始 PR 作者 hzh0425 合并时间 2026-07-28 16:28 文件变更 23 提交数 2 评论 3 代码增减 +62 / -62

执行摘要

重命名 unified_cache_components 目录为 unified_cache/components

该 PR 主要目的是整理 mem_cache 模块的目录结构,将之前分散在 unified_cache_components 中的组件统一纳入 unified_cache 子目录,减少顶层目录数量,提高代码可维护性。

该 PR 是纯粹的目录结构整理,值得关注的是 unified_cache 模块的内聚设计决策。建议代码审查者确认所有 import 更新无误。

讨论亮点

该 PR 无 review 评论,CI 全部通过。

实现拆解

  1. 创建新目录 python/sglang/srt/mem_cache/unified_cache/components,并将四个文件从旧路径 unified_cache_components 移动过来:full_component.py、mamba_component.py、swa_component.py、tree_component.py(包含核心类型定义)。
  2. 更新每个移动后文件的内部 import,使其指向新的相对路径。
  3. 更新所有引用旧路径的源文件(共 23 个)中的 import 语句,包括 unified_tree_core.py、unified_radix_cache.py、unified_tree_core_interface.py、tree_core_registry.py 以及其他外围模块。
  4. 配套测试文件也进行了相应 import 更新。
  5. 移除旧的 unified_cache_components 目录。
文件 模块 状态 重要度
python/sglang/srt/mem_cache/unified_cache/unified_tree_core.py 缓存层 modified 6.21
python/sglang/srt/mem_cache/unified_cache/components/__init__.py 缓存层 renamed 6.08
python/sglang/srt/mem_cache/unified_radix_cache.py 缓存层 modified 5.49
python/sglang/srt/mem_cache/unified_cache/unified_tree_core_interface.py 缓存层 modified 5.48
python/sglang/srt/mem_cache/unified_cache/components/full_component.py 缓存层 renamed 5.3
python/sglang/srt/mem_cache/unified_cache/components/mamba_component.py 缓存层 renamed 5.3

关键源码片段

python/sglang/srt/mem_cache/unified_cache/unified_tree_core.py dependency-wiring

核心树缓存实现文件,更新了导入 unified_cache_components 的路径,改为从 unified_cache.components 导入。

# 变更前:
# from sglang.srt.mem_cache.unified_cache_components import (
# ...
# )# 变更后:
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,
)
python/sglang/srt/mem_cache/unified_cache/components/__init__.py rename-or-move

新目录的 __init__.py,将四个组件的 import 路径从旧位置更新到新位置。

# 新位置:python/sglang/srt/mem_cache/unified_cache/components/__init__.py
# 所有导入均指向新路径下的模块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.swa_component import SWAComponent
from sglang.srt.mem_cache.unified_cache.components.tree_component import (
    _NUM_COMPONENT_TYPES,
    BASE_COMPONENT_TYPE,
    CacheTransferPhase,
    ComponentData,
    ComponentType,
    EvictLayer,
    LRURefreshPhase,
    PrepareLoadBackResult,
    PreparePrefetchResult,
    TreeComponent,
    get_and_increase_time_counter,
    next_component_uuid,
)__all__ = [
    "BASE_COMPONENT_TYPE",
    "ComponentData",
    "ComponentType",
    "EvictLayer",
    "FullComponent",
    "CacheTransferPhase",
    "LRURefreshPhase",
    "MambaComponent",
    "PrepareLoadBackResult",
    "PreparePrefetchResult",
    "SWAComponent",
    "TreeComponent",
    "_NUM_COMPONENT_TYPES",
    "next_component_uuid",
    "get_and_increase_time_counter",
]

评论区精华

没有提炼出高价值讨论线程

当前评论区没有形成足够清晰的争议点或结论,后续有更多讨论时会体现在这里。

风险与影响

风险极低。所有变更为纯 import 路径调整,无逻辑改动。CI 已验证 4 组 unittest 通过。但若存在未跟踪的 import(如动态加载),可能遗漏,本 PR 未涉及动态加载。

对内部开发者的影响:需要更新开发分支中的 import 路径;对用户无影响,功能行为完全不变。

纯 import 变更 CI 已通过

关联 Issue

未识别关联 Issue

当前没有检测到明确关联的 Issue 链接,后续同步到相关引用后会出现在这里。

完整报告

参与讨论