SwapAB + Async Load Cache#794
Conversation
| } | ||
|
|
||
| torch::Tensor | ||
| deep_gemm_fp8(torch::Tensor lhs_bf16, torch::Tensor rhs_data, torch::Tensor rhs_scale, int user_deep_gemm_num_sm) { |
| @@ -148,7 +148,34 @@ void DeviceBase::updateCurrentTorchStream() { | |||
| } | |||
|
|
|||
| void DeviceBase::setCacheStore(std::shared_ptr<rtp_llm::CacheStore> cache_store) { | |||
There was a problem hiding this comment.
那几个wrapper函数删掉了,但是unique_ptr还得在devicebase里,当全局变量用
| { | ||
| std::lock_guard<std::mutex> ex_lock(exception_mutex_); | ||
| if (!stored_exception_) { | ||
| stored_exception_ = std::current_exception(); |
695c94d to
3d3bcfb
Compare
LLLLKKKK
left a comment
There was a problem hiding this comment.
Code Review
两个独立特性打包:(1) SM90 小 M FP8 GEMM 的 swap_ab 优化;(2) CacheStoreAsyncWriter 异步写入线程池。
问题 1: cache_store_async_writer_ 缺少 null 检查 ⚠️
WriteCacheStoreOp.cc 中直接调用 device->cache_store_async_writer_->submit(...) 没有 null 检查。如果 pd_separation 为 true 但 setCacheStore 未被调用(或传入 nullptr),会通过 null unique_ptr 崩溃。
问题 2: 测试 MultipleTaskOrdering 存在 data race
测试向 3 线程池推送 20 个任务并断言严格顺序执行。多线程下执行顺序不确定,且多个线程对共享 std::vector 做无同步 push_back,是未定义行为。这个测试天然 flaky。
问题 3: .bazelrc 硬编码 PATH 覆盖
会清除用户/系统自定义 PATH(如自定义 CUDA toolkit 路径、ccache),可能在非标准环境下静默破坏构建。
000990d to
5f0a91c
Compare
|
🤖 AI Code Review 概述四合一 PR:(1) DeepGEMM Swap-AB 优化(SM90 小 M 场景);(2) FakeBalanceExpert 从 SelectTopkOp 拆分为独立 Op;(3) PD 分离场景下 KV Cache 异步写入;(4) 格式化清理。+1915/-185, 38 files。 优点
建议改进P1 - 重要
P2 - 建议
总结建议拆分为独立 PR 以降低 review 和回滚风险。最关键的是 HWKernelConfig pickle 兼容性和 SelectTopkOp API 变更需要处理。Async writer 和 Swap-AB 功能实现质量不错。 |
|
🤖 AI Code Review 概述将 logprobs 功能从传输完整 vocab-size 概率向量优化为仅传输 top-k 结果,显著降低内存和带宽开销。改动覆盖了完整数据流路径(采样 -> stream -> RPC -> 渲染),并保留了 speculative decoding 所需的 优点
建议改进P1 - 重要
P2 - 建议
总结建议在合并前修复 selected token logprob 为 -inf 和 |
5f0a91c to
98b6019
Compare
|
🤖 AI Code Review (v2 — 增量审查) 概述PR 更新后(98b6019c),上次 P0 编译阻塞问题已修复。四合一 PR 结构不变:DeepGEMM Swap-AB、FakeBalanceExpert 拆分、Async KV Cache Write、小改动。 上次问题跟踪
新发现P1 - 重要
P2 - 建议
总结P0 编译问题已修复,FakeBalanceExpert 拆分质量好。仍需关注 HWKernelConfig pickle 兼容性(P1)和 TMA 对齐行为变更确认。 |
|
🤖 AI Code Review (修正版 — 之前的评论误贴了其他 PR 的内容,非常抱歉) 概述四合一 PR:(1) DeepGEMM Swap-AB 优化(SM90 小 M 场景);(2) FakeBalanceExpert 从 SelectTopkOp 拆分为独立 Op;(3) PD 分离场景下 KV Cache 异步写入;(4) 小改动。规模较大(+1915/-185, 38 files),建议拆分。 优点
建议改进P1 - 重要
P2 - 建议
总结建议修复 pickle 兼容性问题后合入。四合一 PR 建议未来拆分为独立 PR。 |
PR #794: SwapAB + Async Load Cache — Code Review v3Head SHA: 上次 P1 问题跟踪
Commit
|
3dda277 to
de70370
Compare
5ca27ab to
e34d812
Compare
|
🤖 AI Code Review — PR #794 — SwapAB + Async Load Cache 概述本 PR 包含四个改动:(1) DeepGEMM Swap-AB 优化(SM90 小 M decode 加速);(2) FakeBalanceExpert 拆分为独立 Op;(3) Async KV Cache Write(PD 分离场景消除 CPU 阻塞);(4) 格式化及小修。代码质量整体不错,测试覆盖较好。 优点
建议改进P0 - Bug
P1 - 重要
P2 - 建议
总结三个核心功能(SwapAB、FakeBalanceExpert 解耦、Async Cache Write)设计合理,测试覆盖好。P0 的 pickle 兼容性问题必须修复,否则旧版本序列化数据无法在新版本反序列化。其余为封装性和可配置性改进建议。修复 P0 后可以合入。 |
e34d812 to
abac886
Compare
|
🤖 AI Code Review — PR #794 SwapAB + Async Load Cache (v2 incremental, commit abac886) 概述v2 修复了 PPU 环境下 v2 新增问题P2 - 建议
v1 遗留问题(未修复)P1 - 重要
P2 - 建议
总结v2 修复合理。v1 P0 已撤回。剩余 2 P1(public 成员 + 硬编码线程数)建议后续改进。 |
|
🤖 AI Code Review — PR #794 — SwapAB + Async Load Cache (v2 incremental) 概述增量 review(v1: e34d812 → v2: abac886)。新增 1 个 commit:修复 PPU 环境下 v1 的 P0 pickle 兼容性问题经确认为误报(pybind struct 仅内部使用,不存在跨版本反序列化),已撤回。 优点
建议改进P1 - 重要
P2 - 建议
总结v2 修复了一个实际 crash bug,修复方式合理。v1 的 P0 已撤回。剩余 P1 问题(public 成员暴露、硬编码线程数)是架构层面的改进建议,可在后续 PR 中处理。调试残留代码(P2 #4)建议在合并前清理。整体 LGTM with minor suggestions。 |
abac886 to
92bf2e5
Compare
|
🤖 AI Code Review — PR #794 — SwapAB + Async Load Cache (v3 incremental) 概述v3 在 v2 基础上新增了大量 swap-AB 相关代码:C++ DeepGemmPlugin pybind op、Python wrapper 集成、FakeBalanceExpert 独立 Op 拆分、以及完善的 async cache writer 重构。38 个文件变更,测试覆盖显著改善。 优点
建议改进P1 - 重要
P2 - 建议
总结v3 将 swap-AB 优化从概念落地到完整的 C++ plugin + Python 集成 + 测试,代码质量整体不错。P1 #1 需确认 SelectTopkOp 签名变更的兼容性,P1 #2/#3 是架构债务可后续改进。Conditional LGTM。 |
|
🤖 AI Code Review — PR #794 SwapAB + Async Load Cache (v3 incremental, commit 92bf2e5) 概述v3 新增 commit 修复了 v2 问题状态
v3 新发现
总结Conditional LGTM — P1 签名变更需确认兼容性,P1 public 成员和硬编码线程数可后续改进。 |
92bf2e5 to
cfc9bb0
Compare
|
🤖 AI Code Review — PR #794 PR 概述Title: 核心目标三项性能优化:(1) DeepGEMM Swap-AB(SM90 小 M 场景 FP8 GEMM 吞吐提升);(2) FakeBalanceExpert 拆分为独立 Op;(3) PD 分离场景下 KV Cache 异步写入(消除主线程 CPU 阻塞)。 改动逻辑拆解1. CacheStoreAsyncWriter(核心)
2. DeepGEMM Swap-AB
3. FakeBalanceExpert 拆分
Review 意见问题
整体评价三项优化都有明确性能收益。CacheStoreAsyncWriter 状态机设计严谨,torch::Tensor 按值捕获确保异步安全。PR description 含架构图,测试覆盖充分。 ✅ LGTM ready to ci |
93609d4 to
7a7163e
Compare
|
🤖 AI Code Review — PR #794 PR 概述Title: 核心目标本 PR 包含四项改动:(1) 为 DeepGEMM FP8 GEMM 添加 swap-AB 优化(SM90 Hopper),小 M 场景下提升 decode 吞吐;(2) 将 FakeBalanceExpert 从 SelectTopkOp 拆分为独立 Op,改善关注点分离;(3) 将 PD 分离场景的 KV Cache 写入从同步改为异步线程池,消除主线程 CPU 阻塞;(4) 内源 smoke 测试 golden 数据更新。 改动逻辑拆解GitHub 开源仓库变更(主要代码)1. DeepGEMM Swap-AB 优化
2. FakeBalanceExpert 拆分
3. Async KV Cache Write
4. 配置与格式化
内源仓库变更1. Smoke 测试 Golden 数据
Checklist 检查结果通用原则软件工程原则
架构审视
测试
代码质量与文档
领域检查A. 兼容性与配置 — 全部 ✅B. 正确性与逻辑
C. 线程安全与并发
D. 性能 — 全部 ✅E. 分布式 — 全部 ✅F. 跨平台
G-I — 全部 ✅Review 意见问题
小问题
整体评价PR 整体质量良好,架构设计清晰。SwapAB 优化有完整的性能测试和正确性验证,FakeBalanceExpert 拆分改善了代码结构,Async Cache Write 的线程池设计合理且有充分的单元测试。主要风险点在于 P0: 0, P1: 1, P2: 5, P3: 3 ❌ 存在重要问题,建议处理 P1 后合入 |
7a7163e to
fa51037
Compare
|
🤖 AI Code Review — PR #794 PR 概述Title: 核心目标本 PR 包含四项改动:(1) 为 DeepGEMM FP8 GEMM 添加 swap-AB 优化(SM90 Hopper),小 M 场景下提升 decode 吞吐;(2) 将 FakeBalanceExpert 从 SelectTopkOp 拆分为独立 Op,改善关注点分离;(3) 将 PD 分离场景的 KV Cache 写入从同步改为异步线程池,消除主线程 CPU 阻塞;(4) 内源 smoke 测试 golden 数据更新。 与上次 Review 的差异新增 1 个 commit(
改动逻辑拆解GitHub 开源仓库变更(主要代码)1. DeepGEMM Swap-AB 优化
2. FakeBalanceExpert 拆分
3. Async KV Cache Write
4. 配置与格式化
内源仓库变更
Checklist 检查结果通用原则软件工程原则
架构审视
测试
代码质量与文档
领域检查A. 兼容性与配置 — 全部 ✅B. 正确性与逻辑 — 全部 ✅C. 线程安全与并发
D. 性能 — 全部 ✅E. 分布式 — 全部 ✅F. 跨平台 — 全部 ✅G. 语言与框架特有 — 全部 ✅H. 测试与 CI — 全部 ✅I. 代码质量 — 全部 ✅Review 意见上次 P1 跟踪上次 P1: WriteCacheStoreOp 无条件走异步路径 → 降级为 P2-2 上次指出 经重新评估,降级为 P2,理由:
问题
小问题
整体评价上次 P1 的核心风险——空指针——已通过构造函数始终创建 writer 解决。IDLE 状态的隐式依赖经重新评估,调用链保证可靠,降级为 P2。新增的 P0: 0, P1: 0, P2: 5, P3: 3 ✅ LGTM ready to ci |
47e4dd1 to
083563d
Compare
083563d to
d4eaf8b
Compare
d4eaf8b to
fff236e
Compare
Summary
This PR includes three improvements targeting MoE inference performance and PD-separation KV cache write efficiency.
1. Support DeepGEMM Swap-AB Optimization
Add swap-AB mode for DeepGEMM FP8 GEMM kernels on SM90 (Hopper) GPUs. For small-M scenarios (common in decode phase), swapping the A/B operands yields better tiling and higher throughput.
Changes:
deep_gemm_fp8(normal GEMM) anddeep_gemm_grouped_fp8_masked(grouped masked GEMM) that handle quantization + padding + GEMM in a single call.deep_gemm_use_swap_ab(defaulttrue) with runtime capability check (SM90 only).fp8_gemm_nt_swapabandm_grouped_fp8_gemm_nt_masked_swapab.2. Split FakeBalanceExpert into a Standalone Op
Decouple the
FakeBalanceExpertlogic fromSelectTopkOpinto its own independent operator.Changes:
FakeBalanceExpertOp(C++ + pybind): takesexpert_idsandexpert_scalesas input.SelectTopkis now pure top-k selection; balance rewriting happens as a separate, optional post-step.3. Async KV Cache Write for PD Separation
Replace synchronous per-layer
writeCacheStorecalls with an async thread-pool-based writer, eliminating CPU stalls on the main forward thread.Changes:
CacheStoreAsyncWriterclass: a lock-free thread pool (30 threads, queue size 10000) with strict lifecycle (init → submit* → waitAllDone).DeviceBasegainsinitCacheStoreWrite(),submitAsyncCacheStoreTask(),waitCacheStoreComplete()APIs.WriteCacheStoreOpnow captures torch::Tensors by value (cheap refcount bump) and submits work to the async writer instead of running inline.PyWrappedModel::forwardcallsinitbefore the layer loop andwaitAllDoneafter — the main thread keeps launching CUDA kernels without blocking.Architecture:

4. using torch::tensor instead of std::vectorstd::string to avoid value-copy
Test Plan
CacheStoreAsyncWriterTest— unit tests for lifecycle, concurrent submit, and exception propagationSelectTopkOpTest— updated for the split op interfaceDeepGemmMaskedExecutorTest— swap-AB grouped GEMM correctness