已合并
[bugfix]cpu/disk命中根据parent_hash + token_hash查找 #601
[bugfix]cpu/disk命中根据parent_hash + token_hash查找 #601
已合并
ganglv创建于 20 天前
ganglv成员
20 天前

1. 合入背景

请描述为什么要做这个PR内的改动。
如涉及,请关联前序PR或同特性/需求下的其他PR。
如果是修复之前PR引入的问题,请关联引入问题的PR。
请通过#ISSUE ID关联issue。
注意:Fixes #ISSUE ID会自动关闭issue,如问题部分解决请不要使用Fixes,可以用Fix part of #ISSUE ID替代.

完善 KV Conductor 多级缓存亲和性匹配,支持 HBM、CPU、Disk 间连续前缀查询,提升匹配准确性。

#386 #387

2. 修改内容

描述修改内容的具体实现,涉及哪些组件之间进行交互,可以用1、2、3、...进行罗列。
如果是需求或者重构类的PR,需要补充详细设计文档(说明上下游组件关系、时序图、类图、DFX能力等内容)。

  • 重构多级缓存索引及跨介质断点续查逻辑。
  • bugfix for dsv4 flash
  • 支持disk查询
  • 按实例和 DP 聚合各介质命中块数,移除加权评分。
  • 完善事件兼容、测试、设计文档及第三方许可证声明。
  • 修复log monitor收集日志有重复的问题
  • 修改rust precommit失败问题 & rust commit执行慢问题

3. 资料变更

请确认是否涉及资料变更
如涉及,需要在PR中体现,并简要说明修改内容。
如不涉及,需填写“不涉及”。

不涉及

4. 接口变更

请确认是否涉及跨代码仓或者客户面可见的接口变更
如涉及,需详细说明接口以及对应的变更内容,同时需要在资料中体现。
如不涉及,需填写“不涉及”。

  • 配置项 xpu_endpoint 更名为 gpu_endpoint。
  • 注册接口介质名称由 xpu 调整为 gpu,仍兼容旧名称。
  • 查询结果由 XPU/CPU/DISK/total 加权分数调整为 gpu_blocks/cpu_blocks/disk_blocks/matched_tokens。

5. 测试结果

需体现测试场景,测试方法以及测试结果
测试用例设计时需考虑硬件、部署方式、功能、性能、精度、显存等维度。

dsv4_flash
image.png

qwen
image.png

disk
image.png

rename to npu
image.png

6. CheckList

PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]

[ ] 代码注释完备

[ ] 正确记录维测日志

[ ] 是否有UT用例

[ ] 若涉及多线程场景,考虑了并发场景,不存在死锁问题

likedislike
Pull Request已成功合入, 合并人@wangyang
(感谢 ganglv 的贡献)
atomgit-bot
atomgit-bot
20 天前 评论:

变更摘要

该 PR 修复了 CPU/Disk 缓存命中查找未遵循延续边(continuation-edge)语义的问题。原先 CPU/Disk 采用扁平 tokens_hash → workers 映射,按单个块独立匹配,无法识别跨块的连续链。此次重构将 CPU/Disk 索引替换为受 Dynamo 启发的 LowerTierIndexer,以 (parent_hash, tokens_hash) → child_hash 边结构存储块,并在查询时从 HBM 匹配断点(或根节点)沿边连续遍历。同时修正了两阶段 offload/pool 确认协议中 parent_hash 丢失的问题:每个块现在携带自身的 parent_hash,逐块应用 Stored 事件,确保跨批次确认时延续链完整。

主要改动

  • 新增 lower_tier 模块与 LowerTierIndexer: 新增 motor/kv_conductor/src/lower_tier.rs,实现基于 (parent_hash, local_hash) 转移键的延续边索引,支持 store_blocksremove_blocksclear_worker 以及 query_contiguous_hits 连续命中计数,替代原有的扁平哈希映射方案。

  • 重构 IndexerEntry 结构: 将 cpu_blocks/cpu_lookupsdisk_blocks/disk_lookups 扁平存储替换为 cpu_tiersdisk_tiersLowerTierIndexer 实例),移除 flat_store/flat_remove/flat_clear 及并行扁平查找逻辑,新增 lower_tier_lookup 方法实现从 HBM 断点向低层索引的连续遍历。

  • 引入 PrefixMatch 以传递 HBM 断点信息: 在 concurrent_tree.rs 中新增 PrefixMatch 结构体(含 depth 与可选的 last_seq_hash),find_matches_detailed 方法在匹配时记录最后一个匹配的序列哈希,供低层索引从断点继续查询。

  • 修正 offload/pool 两阶段确认的 parent_hash 传递: 将 OffloadPoolState::offload 的值从简单 u64 替换为 OffloadCacheEntry(含 tokens_hashparent_hash),ingest_offload_blocksingest_pool_blocks 的返回值均携带 parent_hash,调用方(vllm.rspool.rs)逐块应用 Stored 事件而非批量应用,避免 parent_hash: None 导致的链断裂。

  • vLLM 卸载事件中构建链内 parent_hash: apply_vllm_event 在遍历卸载块时,第一个块使用事件的 parent_block_hash,后续块依次使用前一个块的哈希,形成正确的链内父子关系后传入 ingest_offload_blocks

likedislike
atomgit-bot
atomgit-bot
20 天前 评论:

代码审查

经过全面深入的分析,我仔细审查了所有 7 个变更文件中的每一个差异块、调用链、并发合约以及边界条件。以下是我的结论:

未发现需要报告的 P0–P2 缺陷。

此 diff 将 CPU/Disk 索引从平坦的 FxHashMap 重构为受 Dynamo 启发的 continuation-edge 索引(LowerTierIndexer),并正确地将 parent_hash 贯穿到两阶段的 offload/pool 确认协议中。关键设计决策——例如将 Ingest_offload_blocks 的三元组 (block_hash, tokens_hash, parent_hash) 以及在确认期间进行逐块 Stored 应用——一致地保留了跨事件拆分传递的 continuation-edge 语义。

以下是我检查的具体内容:

  1. concurrent_tree.rs:新的 PrefixMatch 结构体和 find_matches_detailed 在包括短路(单 worker)和 reconcile 路径在内的所有循环退出路径中,正确捕获了 last_seq_hash(最后匹配节点的 block_hash)。current.read() 的锁范围正确处理。

  2. events/pool.rsevents/vllm.rs:两阶段协议变更是一致的——engine offload 和 pool 确认路径都将 parent_hash 传递到每个单独的 Stored 事件,链构建顺序与 delivery 顺序无关。拆分交付的测试(test_pool_confirm_split_across_events_preserves_chain)覆盖了关键场景。

  3. lower_tier.rs(新文件):store_blocksremove_blocksclear_workerquery_contiguous_hits 中的并发模型正确遵循 worker_blocksedges 的锁顺序(无死锁风险)。EdgeOwnersEntry 中的 Single/Multi 枚举高效处理共享边。TransitionKey 使用 (Option<SequenceBlockHash>, LocalBlockHash) 正确建模了 continuation-edge 语义。

  4. indexer.rsfind_matches_by_hashlower_tier_lookup 流水线通过不重叠的起始位置,正确避免了 HBM 和 lower-tier 命中之间的重复计算。root_workersedge_ownerslower_tier_lookup 中的合并使用 insert 后跟 or_insert_with 是正确的(对于同一 worker 同时拥有 root 和 breakpoint continuation 的极罕见情况,root 获胜,但这在实践中不会导致重复计算,因为跨媒体的 WorkerKey 是不同的)。使用 saturating_sub 没有整数溢出问题。所有旧的平坦查找符号(FLAT_PAR_THRESHOLDflat_lookup_parallelcpu_blocks/cpu_lookups/disk_lookups)均已完全移除,无残留引用。

  5. events/tests.rstest_pool_backend_remove_evicts_cache 中更新后的断言正确反映了新模式(移除根边后,孤立子节点从根不可达,得分为 0)。新测试 test_pool_confirm_split_across_events_preserves_chain 有效验证了拆分交付场景。

  6. lib.rs:仅添加了 pub mod lower_tier; — 无问题。

各文件审查结果:

  • motor/kv_conductor/src/concurrent_tree.rs — 无问题
  • motor/kv_conductor/src/events/pool.rs — 无问题
  • motor/kv_conductor/src/events/tests.rs — 无问题
  • motor/kv_conductor/src/events/vllm.rs — 无问题
  • motor/kv_conductor/src/indexer.rs — 无问题
  • motor/kv_conductor/src/lib.rs — 无问题
  • motor/kv_conductor/src/lower_tier.rs — 无问题

总数:P0: 0, P1: 0, P2: 0, P3: 0

整体风险判断:低。 此变更是一个架构良好的重构,用 continuation-edge 索引替换了平坦的 CPU/Disk 映射,与 PR 描述(parent_hash + token_hash 查找)完全一致。逻辑正确,并发安全,测试覆盖充分。

⚠️ 已识别出整体风险,但无法提取行内评论,请参考整体评估。

likedislike
ascend-robotascend-robot成员
20 天前 添加了label:ascend-cla/yes
ascend-robot
ascend-robot成员
20 天前 评论:

Thanks for your pull-request.
The full list of commands accepted by me can be found at here
You can get sig-info at here


PR Approval Progress

Congratulations! All modules have met the lgtm and approve requirements.

Module Approval Details

module lgtm status approve status
repo-Ascend/MindIE-Motor 王君, 吕有辉 (2/2) 王君 (1/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)

CLA Signature Pass

ganglv, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
ascend-robotascend-robot成员
20 天前 添加了label:ci-pipeline-running
此处折叠了351条消息 查看更多
jason lyujason lyu成员
9 天前 解决了最后一个问题
jason lyu
jason lyu成员
9 天前 评论:

/lgtm

likedislike
ascend-robotascend-robot成员
9 天前 添加了label:lgtm
wangyangwangyang成员
9 天前 关闭了关联的issue
wangyangwangyang成员
9 天前 合入了pull request