[models] support fleet fallback with SWA #8101
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #8101 +/- ##
==========================================
Coverage ? 67.42%
==========================================
Files ? 474
Lines ? 66946
Branches ? 10302
==========================================
Hits ? 45141
Misses ? 18920
Partials ? 2885
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Thanks for your contribution! |
PaddlePaddle-bot
left a comment
There was a problem hiding this comment.
🤖 Paddle-CI-Agent | pr_review |
2026-07-16 16:55:11
📋 Review 摘要
PR 概述:支持 PaddleFleet fallback 在 SWA、attention sinks、EP idle-rank 等场景下复用 FastDeploy attention。
变更范围:PaddleFleet fallback attention patch、GPUModelRunner per-layer KV head 初始化、fallback/worker 单测。
影响面 Tag:[Models] [OP] [Executor]
问题
| 级别 | 文件 | 概述 |
|---|---|---|
| 🔴 Bug | fastdeploy/model_executor/models/paddleformers/base_fleet.py:49 |
FD_FALLBACK_FLEET_USE_ERNIE=0 仍会被当作开启,普通 fallback 可能误走 Ernie 加载路径 |
| 🟡 建议 | tests/model_executor/fallback/test_fallback_fleet_model_coverge.py:1636 |
新增 patch_paddlefleet_core_attention 测试 patch 了错误的 Attention 符号 |
历史 Findings 修复情况
| Finding | 问题 | 状态 |
|---|---|---|
| F1 | PaddleFleet backend 默认切到 Ernie 专用加载路径 | 🔄 部分修复 |
| F2 | SWA 层未正确使用 swa_num_key_value_heads |
|
| F3 | 混合 KV-head 列表与共享 attention buffer 分配不一致 | |
| F4 | tp_group is None 且 TP>1 时重复初始化 PaddleFleet model parallel |
|
| F5 | zero-size fake token 未同步 forward_meta |
|
| F6 | MLA prefill v padding 后未裁回 v_head_dim |
✅ 已修复 |
📝 PR 规范检查
标题 Tag 仍不符合官方大小写,当前 [models] 应改为 [Models];PR 描述结构已按模板补齐。
标题建议(可直接复制):
[Models] Support PaddleFleet fallback with SWA
总体评价
本轮发现一个新增加载开关解析 bug 和一个新增单测 patch 目标错误;同时多项历史阻塞问题仍未完全修复。建议先修复上述问题,并补强能实际断言 SWA KV-head / sinks wiring 的测试。
| from fastdeploy.model_executor.layers.attention.attention import Attention | ||
|
|
||
| USE_ERNIE = False | ||
| USE_ERNIE = os.environ.get("FD_FALLBACK_FLEET_USE_ERNIE", False) |
There was a problem hiding this comment.
🔴 Bug os.environ.get() 返回的是字符串,FD_FALLBACK_FLEET_USE_ERNIE=0 / false 这类常见关闭值在 Python 中仍然为真,会意外进入 Ernie 专用加载路径。
这会让显式关闭开关的部署仍走 if USE_ERNIE: 分支,破坏普通 PaddleFormers fallback。建议显式解析布尔值,例如只接受 1/true/yes 为开启:
USE_ERNIE = os.environ.get("FD_FALLBACK_FLEET_USE_ERNIE", "0").lower() in {"1", "true", "yes"}| mock_attn_instance.sinks = MagicMock() | ||
| mock_attn_instance.sinks.shape = [4] | ||
|
|
||
| with patch("fastdeploy.model_executor.layers.attention.attention.Attention", mock_attention_cls): |
There was a problem hiding this comment.
🟡 建议 这里 patch 的是 fastdeploy.model_executor.layers.attention.attention.Attention,但被测函数在 base_fleet.py 模块加载时已经把 Attention 导入并绑定为本地符号,调用时实际使用的是 base_fleet.Attention。
因此这些新增断言拿不到 mock_attention_cls.call_args_list,在安装 paddlefleet 的环境里会失败;即使不失败,也没有验证 patch_paddlefleet_core_attention 真正创建的对象。建议改为 patch fastdeploy.model_executor.models.paddleformers.base_fleet.Attention,并为多层场景使用两个 mock instance 后断言 SWA 层的 kv_num_heads。
Motivation
Support PaddleFleet fallback models in SWA, attention sink, and EP idle-rank scenarios.
Modifications
fastdeploy/model_executor/models/paddleformers/base_fleet.py: update PaddleFleet fallback attention patching for SWA, softmax_offset sinks, MLA prefill value padding, and EP idle-rank fake-token forward participation.fastdeploy/worker/gpu_model_runner.py: derive per-layer KV head counts fromwindow_attn_skip_freqandswa_num_key_value_heads.tests/model_executor/fallback/test_fallback_fleet_model_coverge.pyandtests/worker/test_gpu_model_runner.py: add fallback/SWA/sinks/EP idle-rank and per-layer KV head coverage.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.