Skip to content

[models] support fleet fallback with SWA #8101

Open
xiaoguoguo626807 wants to merge 5 commits into
PaddlePaddle:developfrom
xiaoguoguo626807:swa
Open

[models] support fleet fallback with SWA #8101
xiaoguoguo626807 wants to merge 5 commits into
PaddlePaddle:developfrom
xiaoguoguo626807:swa

Conversation

@xiaoguoguo626807

@xiaoguoguo626807 xiaoguoguo626807 commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

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 from window_attn_skip_freq and swa_num_key_value_heads.
  • tests/model_executor/fallback/test_fallback_fleet_model_coverge.py and tests/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

  • 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.

PaddlePaddle-bot

This comment was marked as outdated.

@codecov-commenter

codecov-commenter commented Jul 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.82540% with 2 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (develop@bff3f75). Learn more about missing BASE report.

Files with missing lines Patch % Lines
...l_executor/layers/attention/append_attn_backend.py 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             develop    #8101   +/-   ##
==========================================
  Coverage           ?   67.42%           
==========================================
  Files              ?      474           
  Lines              ?    66946           
  Branches           ?    10302           
==========================================
  Hits               ?    45141           
  Misses             ?    18920           
  Partials           ?     2885           
Flag Coverage Δ
GPU 77.45% <96.82%> (?)
XPU 6.95% <0.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

PaddlePaddle-bot

This comment was marked as outdated.

@paddle-bot

paddle-bot Bot commented Jul 14, 2026

Copy link
Copy Markdown

Thanks for your contribution!

@xiaoguoguo626807 xiaoguoguo626807 changed the title [model] support fleet fallback with SWA [models] support fleet fallback with SWA Jul 15, 2026
PaddlePaddle-bot

This comment was marked as outdated.

@PaddlePaddle-bot PaddlePaddle-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 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):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 建议 这里 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants