Skip to content

[Models] support swa for fleet fallback model - #8090

Merged
chang-wenbin merged 4 commits into
PaddlePaddle:developfrom
xiaoguoguo626807:swa
Jul 6, 2026
Merged

[Models] support swa for fleet fallback model#8090
chang-wenbin merged 4 commits into
PaddlePaddle:developfrom
xiaoguoguo626807:swa

Conversation

@xiaoguoguo626807

@xiaoguoguo626807 xiaoguoguo626807 commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Motivation

Support sliding-window attention (SWA) for PaddleFleet fallback MLA models, so SWA layers selected by window_attn_skip_freq can use the DSA attention path.

Modifications

  • fastdeploy/model_executor/models/paddleformers/base_fleet.py: pass window_attn_skip_freq and sliding_window into FastDeployAttention.
  • fastdeploy/model_executor/models/paddleformers/base_fleet.py: add an SWA branch that builds indexer_top_k and calls DSAAttentionBackend.forward_static for MLA attention.
  • fastdeploy/model_executor/models/paddleformers/base_fleet.py: adjust PaddleFleet fallback config/model loading and MoE-related config fields.

Usage or Command

N/A

Accuracy Tests

N/A(当前 PR 未提供 SWA/fallback logits 对齐或精度测试结果)

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.

PaddlePaddle-bot

This comment was marked as outdated.

@codecov-commenter

codecov-commenter commented Jul 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (develop@f4eda5a). Learn more about missing BASE report.

Additional details and impacted files
@@            Coverage Diff             @@
##             develop    #8090   +/-   ##
==========================================
  Coverage           ?   67.52%           
==========================================
  Files              ?      475           
  Lines              ?    66958           
  Branches           ?    10329           
==========================================
  Hits               ?    45213           
  Misses             ?    18874           
  Partials           ?     2871           
Flag Coverage Δ
GPU 77.55% <100.00%> (?)
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.

@xiaoguoguo626807
xiaoguoguo626807 deleted the swa branch July 2, 2026 11:39
@xiaoguoguo626807
xiaoguoguo626807 restored the swa branch July 6, 2026 06:15

@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-06 14:33:48

📋 Review 摘要

PR 概述:为 PaddleFleet fallback MLA 模型新增基于 window_attn_skip_freq 的 SWA/DSA attention 路径,并调整 fallback 初始化/测试。
变更范围base_fleet.py、fallback 单测
影响面 Tag[Models]

问题

级别 文件 概述
🟡 建议 fastdeploy/model_executor/models/paddleformers/base_fleet.py:178 新增 SWA 前向路径缺少 logits/精度对齐证据
🟡 建议 tests/model_executor/fallback/test_fallback_fleet_model_coverge.py:1365 SWA 单测 mock 掉真实 DSA 且未校验真实入参 rank/shape

📝 PR 规范检查

标题包含官方 [Models] Tag,描述包含 checklist.md §D2 要求的 MotivationModificationsUsage or CommandAccuracy TestsChecklist 结构,符合规范。

总体评价

实现方向和 DeepSeek SWA/DSA 路径基本对齐,但当前验证主要停留在控制流/shape mock。建议补齐最小数值对齐和真实后端入参约束后再合入核心模型路径。

forward_meta=forward_meta,
k_pos_emb_sq = k_pos_emb.squeeze(0)

if self.window_attn_skip_freq is not None and self.window_attn_skip_freq[self.layer_id] == 1:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 建议 这里新增了 window_attn_skip_freq 命中的 MLA/SWA 层直接走 DSAAttentionBackend.forward_static 的前向路径,但 PR 只提供了 mock/shape 级单测,Accuracy Tests 也标为 N/A。该分支会改变 prefill/decode 的 mask、indexer、cache 写入和 softmax scale 使用,输出直接影响 logits;没有 fallback logits 或参考实现对齐,后续 get_swa_indexer_top_k、cache layout、V de-absorb 任一错误都不会被发现。

建议修复方式:
补一个小模型/固定 seed 的 PaddleFleet fallback SWA 对齐用例,至少覆盖 window_attn_skip_freq[layer_id] == 1 的 prefill-only 和 mixed prefill+decode,并与 DeepSeek/PaddleFleet 参考路径比较 logits 容差;如果 CI 无法跑真实 GPU kernel,请在 PR 中附可复现命令和对齐结果。

query = paddle.randn([seq_len, num_heads, kv_lora_rank])
key = paddle.randn([seq_len, num_heads, kv_lora_rank])
value = paddle.randn([seq_len, num_heads, kv_lora_rank])
kv_compressed = paddle.randn([1, seq_len, num_heads, kv_lora_rank])

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 建议 这个用例把 DSAAttentionBackend.forward_static 整体替换成 MagicMock,同时构造的 kv_compressed squeeze 后是 3D [seq, heads, rank],但真实 DSA backend 要求 compressed_kv 为 2D、k_pe 为 3D。因此测试会在真实调用会触发 shape/rank 问题时仍然通过。

建议修复方式:
让用例使用真实后端约束的入参形状,例如 kv_compressed squeeze 后为 [seq, kv_lora_rank]k_pos_emb squeeze 后为 [seq, 1, qk_rope_head_dim]q_absorbed 最后一维为 kv_lora_rank + qk_rope_head_dim,并对 mock_dsa.forward_static.call_args 断言 q.ndim == 3compressed_kv.ndim == 2k_pe.ndim == 3

@chang-wenbin
chang-wenbin merged commit bff3f75 into PaddlePaddle:develop Jul 6, 2026
41 of 43 checks passed
@xiaoguoguo626807
xiaoguoguo626807 deleted the swa branch July 6, 2026 08:25
@paddle-bot

paddle-bot Bot commented Jul 14, 2026

Copy link
Copy Markdown

Thanks for your contribution!

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.

4 participants