[BugFix] Fix import compatibility for paddlefleet.ops and paddlefleet_ops#7873
Conversation
PaddlePaddle-bot
left a comment
There was a problem hiding this comment.
🤖 Paddle-CI-Agent | pr_review |
2026-05-21 12:01:24
📋 Review 摘要
PR 概述:修复 paddlefleet 包路径变更导致的 deep_ep 和 deep_gemm 导入兼容性问题,新增对 paddlefleet.ops 新路径的支持,同时保留对旧路径 paddlefleet_ops 的回退
变更范围:model_executor/layers/moe/ep.py、model_executor/layers/quantization/fp8_utils.py
影响面 Tag:[OP] [Quantization]
问题
| 级别 | 文件 | 概述 |
|---|---|---|
| 🟡 建议 | ep.py:48 |
裸 except: 应改为 except ImportError:,避免误吞关键异常 |
| 🟡 建议 | fp8_utils.py:50 |
裸 except: 应改为 except ImportError:,避免误吞关键异常 |
| 📝 PR 规范 | — | 标题缺少官方 [Tag],PR 描述各段均为占位符未填写 |
📝 PR 规范检查
标题无官方 [Tag];PR 描述中 Motivation / Modifications / Usage or Command / Accuracy Tests 各段内容均为空/占位符,Checklist 条目全部未勾选。
标题建议(可直接复制):
[BugFix] Fix import compatibility for paddlefleet.ops and paddlefleet_ops
PR 描述建议(可直接复制,必须复刻 checklist §D2 模板的完整结构):
## Motivation
修复 `paddlefleet` 包路径变更导致的兼容性问题:新版 `paddlefleet` 将 ops 子模块路径从 `paddlefleet_ops.deep_ep`/`paddlefleet_ops.deep_gemm` 迁移至 `paddlefleet.ops.deep_ep`/`paddlefleet.ops.deep_gemm`,旧路径导致 ImportError。本 PR 在 `ep.py` 和 `fp8_utils.py` 中同时兼容两种路径,优先尝试新路径,失败时回退到旧路径。
## Modifications
- `fastdeploy/model_executor/layers/moe/ep.py`:移除模块级 `try_import(["paddlefleet.ops"])` 调用;在 `load_deep_ep()` 内新增内层 try/except,优先 `import paddlefleet.ops.deep_ep`,回退 `import paddlefleet_ops.deep_ep`
- `fastdeploy/model_executor/layers/quantization/fp8_utils.py`:更新模块级 `try_import` 同时检测 `paddlefleet.ops` 和 `paddlefleet_ops`;在 `load_deep_gemm()` 内新增内层 try/except,优先 `import paddlefleet.ops.deep_gemm`,回退 `import paddlefleet_ops.deep_gemm`
## 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.
- [ ] Format your code, run `pre-commit` before commit.
- [ ] Add unit tests. Please write the reason in this PR if no unit tests.
- [ ] 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.总体评价
兼容性修复逻辑清晰,能正确处理包路径迁移场景。建议将两处裸 except: 改为 except ImportError: 以避免误吞 KeyboardInterrupt 等关键异常;PR 标题和描述规范需同步补充。
| import paddlefleet_ops.deep_ep as deep_ep # type: ignore | ||
| try: | ||
| import paddlefleet.ops.deep_ep as deep_ep # type: ignore | ||
| except: |
There was a problem hiding this comment.
🟡 建议 裸 except: 捕获范围过宽
当前 except: 会捕获所有异常(包括 KeyboardInterrupt、SystemExit),若 paddlefleet.ops 已安装但因非导入原因(如内部初始化错误)抛出非 ImportError 异常,将被静默吞掉并错误地回退到旧路径,导致难以排查的问题。
建议修复方式:
try:
import paddlefleet.ops.deep_ep as deep_ep # type: ignore
except ImportError:
import paddlefleet_ops.deep_ep as deep_ep # type: ignore| import paddlefleet_ops.deep_gemm as deep_gemm | ||
| try: | ||
| import paddlefleet.ops.deep_gemm as deep_gemm | ||
| except: |
There was a problem hiding this comment.
🟡 建议 裸 except: 捕获范围过宽
同 ep.py 问题:当前 except: 捕获所有异常,若 paddlefleet.ops 包存在但初始化时抛出非 ImportError 异常,将被静默吞掉并错误回退。
建议修复方式:
try:
import paddlefleet.ops.deep_gemm as deep_gemm
except ImportError:
import paddlefleet_ops.deep_gemm as deep_gemm
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #7873 +/- ##
==========================================
Coverage ? 63.58%
==========================================
Files ? 462
Lines ? 64490
Branches ? 9887
==========================================
Hits ? 41006
Misses ? 20705
Partials ? 2779
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:
|
EmmonsCurse
left a comment
There was a problem hiding this comment.
LGTM~ Skip coverage check as it mainly relies on tests with paddlefleet.
Motivation
Modifications
Usage or Command
Accuracy Tests
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.