[BugFix][Metax][KVCache] fix: resolve None callable error when import fails#7556
Conversation
|
Thanks for your contribution! |
There was a problem hiding this comment.
Pull request overview
该 PR 旨在修复 Metax(MACA) 平台上由于算子导入失败导致 fastdeploy.cache_manager.ops 进入兜底分支,从而出现 get_all_visible_devices 变为 None、下游调用时报 “None callable” 的问题。
Changes:
- 移除 MACA 分支对
swap_cache_per_layer/swap_cache_per_layer_async的直接导入,避免因该导入失败触发整个模块 import 失败。 - 在 MACA 分支为
swap_cache_per_layer/swap_cache_per_layer_async增加占位实现(直接抛错),使模块其余功能可继续加载。
b6bf698 to
5d4baad
Compare
5d4baad to
8fe3ef1
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
fastdeploy/cache_manager/ops.py:61
- 在 current_platform.is_maca() 分支里没有定义/导入 swap_cache_layout,但 fastdeploy/cache_manager/cache_transfer_manager.py 会无条件从 fastdeploy.cache_manager.ops import swap_cache_layout。由于本次改动使 MACA 分支的 try-import 更可能成功,这会导致在 MACA 环境导入 cache_transfer_manager 时直接 ImportError。建议在 MACA 分支显式提供 swap_cache_layout(若平台支持则从 fastdeploy.model_executor.ops.gpu 导入;否则至少定义为 None 或提供 stub 并在调用时报清晰错误)。
from fastdeploy.model_executor.ops.gpu import ( # get_output_kv_signal,; ipc_sent_key_value_cache_by_remote_ptr_block_sync,
cuda_host_alloc,
cuda_host_free,
get_data_ptr_ipc,
ipc_sent_key_value_cache_by_remote_ptr,
set_data_ipc,
share_external_data,
swap_cache_all_layers,
unset_data_ipc,
)
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (1)
fastdeploy/cache_manager/ops.py:55
- 建议补充一个单测覆盖本次修复的关键行为:在 current_platform.is_maca() 分支下,即使 fastdeploy.model_executor.ops.gpu 中缺少 swap_cache_per_layer/swap_cache_per_layer_async 等符号,导入 fastdeploy.cache_manager.ops 也不应落入 except 分支导致 get_all_visible_devices 被置为 None(从而触发 NoneType callable)。可以通过 mock current_platform 与构造缺少属性的假 gpu module 来验证。
elif current_platform.is_maca():
from fastdeploy.model_executor.ops.gpu import ( # get_output_kv_signal,; ipc_sent_key_value_cache_by_remote_ptr_block_sync,
cuda_host_alloc,
cuda_host_free,
get_data_ptr_ipc,
54ff867 to
4791327
Compare
4791327 to
4d9077c
Compare
8a1600c to
ca35035
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #7556 +/- ##
==========================================
Coverage ? 72.78%
==========================================
Files ? 419
Lines ? 57640
Branches ? 9034
==========================================
Hits ? 41956
Misses ? 12846
Partials ? 2838
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
PaddlePaddle-bot
left a comment
There was a problem hiding this comment.
🤖 AI Code Review |
2026-04-23 11:21:37
📋 Review 摘要
PR 概述:修复 Metax/MACA 平台因 swap_cache_per_layer 等算子导入失败导致 get_all_visible_devices 为 None 的 Bug,同时为 MetaxCutlass MoE backend 的 apply_tp 方法补充 fc1_latent_proj/fc2_latent_proj 参数支持。
变更范围:fastdeploy/cache_manager/ops.py、fastdeploy/model_executor/layers/backends/metax/moe/fused_moe_cutlass_metax_backend.py
影响面 Tag:[KVCache] [Metax] [OP]
📝 PR 规范检查
标题包含 [BugFix][Metax][KVCache] 三个官方 Tag,均合规且与 diff 吻合,但未体现对 fused_moe_cutlass_metax_backend.py 的 MoE 层改动(建议可补充 [OP])。Usage or Command 与 Accuracy Tests 段落为空(应填 N/A),Add unit tests 未勾选且未说明原因。
标题建议(可直接复制):
[BugFix][Metax][KVCache][OP] fix: resolve None callable error when import fails and add latent proj support for MoE
PR 描述建议(可直接复制,必须复刻 checklist §D2 模板的完整结构):
## Motivation
在 Metax/MACA 平台上,`fastdeploy/model_executor/ops.gpu` 中未实现 `swap_cache_per_layer` 和 `swap_cache_per_layer_async`,导入时抛出 `ImportError`,中断整个 `elif current_platform.is_maca():` 初始化块,使 `get_all_visible_devices` 等后续变量未被赋值(保持 `None`),进而在调用时触发 `TypeError: 'NoneType' object is not callable`。
同时,`MetaxCutlassMoEMethod.apply_tp` 缺少 `fc1_latent_proj`/`fc2_latent_proj` 参数,无法支持带 latent projection 的 MoE 模型变体。
## Modifications
- `fastdeploy/cache_manager/ops.py`:移除 Metax 分支中对未实现算子的 import,改为定义抛出 `RuntimeError` 的 stub 函数(`swap_cache_per_layer`、`swap_cache_per_layer_async`、`swap_cache_layout`);修正 UNIMPLENENTED 拼写错误。
- `fastdeploy/model_executor/layers/backends/metax/moe/fused_moe_cutlass_metax_backend.py`:为 `MetaxCutlassUnquantizedFusedMoEMethod` 和 `MetaxCutlassMoEMethod` 的 `apply_tp` 方法添加 `fc1_latent_proj`/`fc2_latent_proj` 可选参数;在 `MetaxCutlassMoEMethod.apply_tp` 中将 `gate_out` 计算移至条件块外,并在 `noaux_tc` 路径前/后分别应用 latent projection。
## Usage or Command
N/A
## Accuracy Tests
N/A
## Checklist
- [x] Add at least a tag in the PR title.
- Tag list: [`[FDConfig]`,`[APIServer]`,`[Engine]`, `[Scheduler]`, `[PD Disaggregation]`, `[Executor]`, `[Graph Optimization]`, `[Speculative Decoding]`, `[RL]`, `[Models]`, `[Quantization]`, `[Loader]`, `[OP]`, `[KVCache]`, `[DataProcessor]`, `[BugFix]`, `[Docs]`, `[CI]`, `[Optimization]`, `[Feature]`, `[Benchmark]`, `[Others]`, `[XPU]`, `[HPU]`, `[GCU]`, `[DCU]`, `[Iluvatar]`, `[Metax]`]
- You can add new tags based on the PR content, but the semantics must be clear.
- [x] Format your code, run `pre-commit` before commit.
- [ ] Add unit tests. Please write the reason in this PR if no unit tests.(本次修复为平台兼容性 stub,无需单测;MoE latent proj 逻辑可在已有 Metax CI 中覆盖)
- [ ] Provide accuracy results.
- [ ] If the current PR is submitting to the `release` branch, make sure the PR has been submitted to the `develop` branch, then cherry-pick it to the `release` branch with the `[Cherry-Pick]` PR tag.问题
| 级别 | 文件 | 概述 |
|---|---|---|
| 🟡 建议 | fused_moe_cutlass_metax_backend.py |
fused_moe_triton_metax_backend.py 中 MetaxTritonWeightOnlyMoEMethod 未实现 apply_tp,与 cutlass backend 新增参数不同步 |
| 🟡 建议 | fused_moe_cutlass_metax_backend.py:225 |
gate_out 移至条件块外后,else 分支中该结果未被使用(仅用 gate.weight),存在冗余计算 |
| 📝 PR 规范 | — | Usage or Command、Accuracy Tests 段落为空;Add unit tests 未勾选且未说明原因 |
🟡 建议 1 详情:
fused_moe_triton_metax_backend.py中的MetaxTritonWeightOnlyMoEMethod继承自QuantMethodBase且无apply_tp实现。若在调度时该 backend 也会走apply_tp路径,则缺少fc1_latent_proj/fc2_latent_proj参数会导致签名不匹配错误。建议在 PR 描述中说明 triton backend 是否豁免,或补充同步更新。🟡 建议 2 详情:
else分支(非noaux_tc)调用fused_expert_moe(x, gate.weight, ...)使用gate.weight而非gate_out,但gate_out = gate(x.cast("float32"))已无条件执行,造成一次多余的前向计算。若else分支不需要gate_out,可将其移回if layer.topk_method == "noaux_tc":块内(get_moe_scores调用之前)。
总体评价
ops.py 的修复方向正确,将无法导入的算子改为 stub 函数可有效避免 ImportError 污染后续变量赋值。MoE backend 的 latent proj 参数补充逻辑清晰,但建议确认 triton backend 的同步状态,并修复 else 分支中的冗余 gate_out 计算。
|
hi, @Tryorish
|
PaddlePaddle-bot
left a comment
There was a problem hiding this comment.
🤖 AI Code Review |
2026-04-23 15:02:30
📋 Review 摘要
PR 概述:修复 Metax/MACA 平台因 ImportError 导致变量未赋值引发 TypeError: 'NoneType' object is not callable 的崩溃问题,并对齐 MoE Metax backend 的 apply_tp 签名与逻辑。
变更范围:fastdeploy/cache_manager/ops.py、fastdeploy/model_executor/layers/backends/metax/moe/fused_moe_cutlass_metax_backend.py
影响面 Tag:[KVCache] [Metax] [BugFix]
📝 PR 规范检查
标题格式符合规范(含官方 Tag),但 PR 描述缺少 Usage or Command、Accuracy Tests 和 Checklist 三个必填段落。
标题建议(可直接复制):
[BugFix][Metax][KVCache] Fix None callable error when Metax import fails and align MoE apply_tp
PR 描述建议(可直接复制,必须复刻 checklist §D2 模板的完整结构):
## Motivation
在 Metax/MACA 平台上,`fastdeploy.model_executor.ops.gpu` 模块未实现 `swap_cache_per_layer` 和 `swap_cache_per_layer_async`,导入时抛出 `ImportError`,中断整个 `elif current_platform.is_maca():` 初始化块,使后续变量未被赋值(保持 `None`),进而在调用时触发 `TypeError: 'NoneType' object is not callable`。同时修复 pr#7428 引入的 CI error。
## Modifications
- `fastdeploy/cache_manager/ops.py`:移除对 `swap_cache_per_layer` / `swap_cache_per_layer_async` 的直接 import,改为 Metax 分支内定义 stub 函数(raise RuntimeError),同步补充 `swap_cache_layout` stub;修正多处拼写错误(`UNIMPLENENTED` → `UNIMPLEMENTED`)。
- `fastdeploy/model_executor/layers/backends/metax/moe/fused_moe_cutlass_metax_backend.py`:`apply_tp` 补齐 `fc1_latent_proj` / `fc2_latent_proj` 参数(与基类签名对齐);将 `gate_out = gate(x.cast(float32))` 移出 `noaux_tc` 条件块,对齐 `fused_moe_cutlass_backend.py` 实现。
## Usage or Command
N/A
## Accuracy Tests
N/A
## Checklist
- [x] Add at least a tag in the PR title.问题
| 级别 | 文件 | 概述 |
|---|---|---|
| 📝 PR 规范 | PR 描述 | 缺少 Usage or Command、Accuracy Tests 和 Checklist 段落 |
| ❓ 疑问 | fastdeploy/model_executor/layers/backends/metax/moe/fused_moe_cutlass_metax_backend.py:162 |
gate_out 在非 noaux_tc 路径下被计算但未使用 |
总体评价
修复思路正确,将失败的 import 改为 stub 函数是合理做法,MoE 侧签名补齐也有必要。存在一处轻微冗余计算,不影响正确性,建议后续跟进。
PaddlePaddle-bot
left a comment
There was a problem hiding this comment.
🤖 AI Code Review |
2026-04-23 16:05:19
📋 Review 摘要
PR 概述:修复 Metax/MACA 平台因 ImportError 导致 NoneType callable 错误,同步补全 KVCache ops stub;并对齐 fused_moe_cutlass_metax_backend.py 与基类 apply_tp 签名及 gate_out 逻辑
变更范围:fastdeploy/cache_manager/ops.py、fastdeploy/model_executor/layers/backends/metax/moe/
影响面 Tag:[KVCache] [Metax] [OP]
📝 PR 规范检查
标题:[BugFix][Metax][KVCache] fix: ... 含三个官方 Tag,§D1 要求标题仅含一个官方 Tag,建议保留主题 Tag [BugFix],可在描述中说明涉及 KVCache 和 Metax。
Checklist:[ ] Add unit tests、[ ] Provide accuracy results、[ ] If current PR is submitting to the release branch 三个未勾选项未按 §D3 要求删除;且 Add unit tests 一项未在 PR 中给出不添加单测的原因说明。
标题建议(可直接复制):
[BugFix] Fix None callable error in Metax/MACA when import fails and align apply_tp signature
PR 描述建议(可直接复制,必须复刻 checklist §D2 模板的完整结构):
## Motivation
- 在 Metax/MACA 平台上,`fastdeploy.model_executor.ops.gpu` 未实现 `swap_cache_per_layer`/`swap_cache_per_layer_async`,导入时抛出 `ImportError`,中断整个 `elif current_platform.is_maca():` 初始化块,使 `get_all_visible_devices` 等后续变量保持 `None`,进而在调用时触发 `TypeError: 'NoneType' object is not callable`。
- 同步修复 PR#7428 引起的 CI 错误(`apply_tp` 签名与基类不对齐)。
## Modifications
- `fastdeploy/cache_manager/ops.py`:移除 MACA 分支中对 `swap_cache_per_layer`/`swap_cache_per_layer_async` 的直接 import,改为 Metax 分支内定义 stub 函数(raise RuntimeError);补充缺失的 `swap_cache_layout` stub;修正多处 `UNIMPLENENTED` 拼写为 `UNIMPLEMENTED`。
- `fastdeploy/model_executor/layers/backends/metax/moe/fused_moe_cutlass_metax_backend.py`:`apply_tp` 补齐 `fc1_latent_proj`/`fc2_latent_proj` 参数(与基类签名对齐);将 `gate_out = gate(x.cast("float32"))` 移出 `noaux_tc` 条件块,与 `fused_moe_cutlass_backend.py` 实现对齐。
## Usage or Command
N/A
## Accuracy Tests
N/A
## Checklist
- [x] Add at least a tag in the PR title.
- Tag list: [`[FDConfig]`,`[APIServer]`,`[Engine]`, `[Scheduler]`, `[PD Disaggregation]`, `[Executor]`, `[Graph Optimization]`, `[Speculative Decoding]`, `[RL]`, `[Models]`, `[Quantization]`, `[Loader]`, `[OP]`, `[KVCache]`, `[DataProcessor]`, `[BugFix]`, `[Docs]`, `[CI]`, `[Optimization]`, `[Feature]`, `[Benchmark]`, `[Others]`, `[XPU]`, `[HPU]`, `[GCU]`, `[DCU]`, `[Iluvatar]`, `[Metax]`]
- You can add new tags based on the PR content, but the semantics must be clear.
- [x] Format your code, run `pre-commit` before commit.问题
| 级别 | 文件 | 概述 |
|---|---|---|
| 📝 PR 规范 | 标题 | 含三个官方 Tag([BugFix][Metax][KVCache]),§D1 要求仅含一个 |
| 📝 PR 规范 | Checklist | [ ] Add unit tests 等未勾选项未按 §D3 删除;Add unit tests 未给出不添加原因 |
| ❓ 疑问 | fused_moe_triton_metax_backend.py |
apply 方法(L245)未同步添加 fc1_latent_proj/fc2_latent_proj 参数,若 TP 路径调用到该 backend 可能无法正确处理 latent 投影 |
注:triton backend 问题涉及未变更文件,无行间评论。
总体评价
KVCache 导入修复逻辑清晰正确,MoE cutlass backend 签名对齐与 gate_out 位置调整均与 GPU 参考实现一致。建议确认 triton metax backend 是否需要同步更新 apply 参数签名,并修正 PR 规范细节。
… fails (PaddlePaddle#7556) * [BugFix][Metax][KVCache] fix: resolve None callable error when import fails * Apply suggestion from @Copilot Co-authored-by: Copilot <[email protected]> * [Metax][FIX] fix ci error caused by pr#7428 --------- Co-authored-by: Guanyu Chen (i26275) <[email protected]> Co-authored-by: Copilot <[email protected]>
… fails (PaddlePaddle#7556) * [BugFix][Metax][KVCache] fix: resolve None callable error when import fails * Apply suggestion from @Copilot Co-authored-by: Copilot <[email protected]> * [Metax][FIX] fix ci error caused by pr#7428 --------- Co-authored-by: Guanyu Chen (i26275) <[email protected]> Co-authored-by: Copilot <[email protected]>
Motivation
fastdeploy.model_executor.ops.gpu模块未实现swap_cache_per_layer和swap_cache_per_layer_async,导入时抛出ImportError,中断整个elif current_platform.is_maca():初始化块,使get_all_visible_devices等后续变量未被赋值(保持None),进而在调用时触发TypeError: 'NoneType' object is not callable。Modifications
fastdeploy/cache_manager/ops.py:移除对swap_cache_per_layer/swap_cache_per_layer_async的直接 import,改为 Metax 分支内定义 stub 函数(raise RuntimeError),同步补充swap_cache_layoutstub;修正多处拼写错误(UNIMPLENENTED→UNIMPLEMENTED)。fastdeploy/model_executor/layers/backends/metax/moe/fused_moe_cutlass_metax_backend.py:apply_tp补齐fc1_latent_proj/fc2_latent_proj参数(与基类签名对齐);将gate_out = gate(x.cast("float32"))移出noaux_tc条件块,对齐fused_moe_cutlass_backend.py实现。Usage or Command
N/A
Accuracy Tests
N/A
Checklist
[FDConfig],[APIServer],[Engine],[Scheduler],[PD Disaggregation],[Executor],[Graph Optimization],[Speculative Decoding],[RL],[Models],[Quantization],[Loader],[OP],[KVCache],[DataProcessor],[BugFix],[Docs],[CI],[Optimization],[Feature],[Benchmark],[Others],[XPU],[HPU],[GCU],[DCU],[Iluvatar],[Metax]]pre-commitbefore commit.releasebranch, make sure the PR has been submitted to thedevelopbranch, then cherry-pick it to thereleasebranch with the[Cherry-Pick]PR tag.