Skip to content

[Cherry-Pick][Feature] support decode unified attention(#7688)#7850

Merged
freeliuzc merged 3 commits into
PaddlePaddle:release/online/20260415from
lizhenyun01:dec_attn_0415
May 20, 2026
Merged

[Cherry-Pick][Feature] support decode unified attention(#7688)#7850
freeliuzc merged 3 commits into
PaddlePaddle:release/online/20260415from
lizhenyun01:dec_attn_0415

Conversation

@lizhenyun01
Copy link
Copy Markdown
Collaborator

Motivation

C16/动态/静态C8 decode unified attention支持,使用方式:
集中式:flash_attn开启情况下export USE_DECODE_UNIFIED_ATTENTION=1
PD分离:D节点export FD_ATTENTION_BACKEND=DECODE_UNIFIED_ATTN

Modifications

Usage or Command

Accuracy Tests

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.

@paddle-bot
Copy link
Copy Markdown

paddle-bot Bot commented May 19, 2026

Thanks for your contribution!

PaddlePaddle-bot

This comment was marked as outdated.

Copy link
Copy Markdown

@PaddlePaddle-bot PaddlePaddle-bot left a comment

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-05-20 10:29:59

📋 Review 摘要

PR 概述:新增 Decode Unified Attention 支持(C16/动态/静态C8),适用于集中式(USE_DECODE_UNIFIED_ATTENTION=1)与 PD 分离(FD_ATTENTION_BACKEND=DECODE_UNIFIED_ATTN)两种场景。
变更范围custom_ops/gpu_ops/(新增 CUDA kernels)、fastdeploy/model_executor/layers/attention/(新增 backend)、fastdeploy/worker/gpu_model_runner.pyfastdeploy/spec_decode/mtp.pyfastdeploy/envs.pyfastdeploy/platforms/cuda.py
影响面 Tag[OP] [Feature] [Speculative Decoding]

问题

级别 文件 概述
🟡 建议 custom_ops/setup_ops.py decode_unified_attention 仅在 cc>=90 下编译,但 PR 描述未说明硬件限制,A100 用户启用后会运行时报错
🟡 建议 fastdeploy/model_executor/layers/attention/decode_unified_attention_backend.py DecodeUnifiedAttentionMetadata dataclass 中 _dtype 字段重复定义两次,应删除冗余定义
❓ 疑问 fastdeploy/envs.py USE_DECODE_UNIFIED_ATTENTION 命名缺 FD_ 前缀;PR 描述中提到用此变量,但代码实际通过 FD_ATTENTION_BACKEND 控制,两者联动逻辑不明确
❓ 疑问 fastdeploy/platforms/cuda.py ValueError 错误信息未包含 DECODE_UNIFIED_ATTN,会误导用户
📝 PR 规范 PR 描述 ModificationsUsage or CommandAccuracy Tests 三个 section 均为空占位符

📝 PR 规范检查

标题格式 [Cherry-Pick][Feature] support decode unified attention(#7688) 符合 Cherry-Pick 规范。但 PR 描述的 ModificationsUsage or CommandAccuracy Tests 三个 section 均为空(仅保留了注释占位符),checklist 各项均未勾选。

标题建议(合规,可直接使用):

  • [Cherry-Pick][Feature] support decode unified attention(#7688)

PR 描述建议(可直接复制):

## Motivation
C16/动态/静态C8 decode unified attention 支持,解决 decode 阶段 attention 计算的统一化问题。
- 集中式:flash_attn 开启情况下 `export USE_DECODE_UNIFIED_ATTENTION=1`(待确认与 `FD_ATTENTION_BACKEND` 的联动关系)
- PD 分离:D 节点 `export FD_ATTENTION_BACKEND=DECODE_UNIFIED_ATTN`
- 注意:当前仅支持 SM90+(Hopper,如 H100)及以上架构,最低需要 CUDA 12.0

## Modifications
- `custom_ops/gpu_ops/decode_unified_attention/`:新增 decode unified attention CUDA kernels,支持 C16(FP16/BF16)和 C8(FP8/INT8/动态量化)
- `custom_ops/gpu_ops/decoder_write_cache_with_rope.cu`:新增 decoder write cache with RoPE kernel
- `custom_ops/gpu_ops/decode_unified_attention/config_for_attention.cu`:新增 block/chunk 配置计算 kernel
- `custom_ops/setup_ops.py`:将上述 kernel 注册进编译流程(cc>=90 分支)
- `fastdeploy/model_executor/layers/attention/decode_unified_attention_backend.py`:新增 `DecodeUnifiedAttentionBackend` attention backend 实现
- `fastdeploy/model_executor/layers/attention/ops/`:新增对应 Python wrapper(decode_unified_attention、decoder_write_cache_with_rope、config_for_attention)
- `fastdeploy/worker/gpu_model_runner.py`:在 `FD_ATTENTION_BACKEND=DECODE_UNIFIED_ATTN` 时分配对应 buffer
- `fastdeploy/spec_decode/mtp.py`:适配 MTP 投机解码路径,复用 target_model 的 workspace tensor
- `fastdeploy/platforms/cuda.py`:注册新 backend 类型
- `fastdeploy/envs.py`:新增 `USE_DECODE_UNIFIED_ATTENTION` 环境变量

## Usage or Command
```bash
# 集中式(需开启 flash_attn)
export USE_DECODE_UNIFIED_ATTENTION=1

# PD 分离部署(D 节点)
export FD_ATTENTION_BACKEND=DECODE_UNIFIED_ATTN
```

## Accuracy Tests
N/A(Cherry-Pick 自 #7688,精度验证见原 PR)

## 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.
- [x] Add unit tests. Please write the reason in this PR if no unit tests.
- [ ] Provide accuracy results.
- [x] 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.

总体评价

本 PR 实现了 Decode Unified Attention 功能(C16/C8),新增了约 2500 行 CUDA kernel 代码和对应的 Python 接入层,测试文件也有补充。主要建议:明确声明 SM90+ 硬件要求、厘清 USE_DECODE_UNIFIED_ATTENTIONFD_ATTENTION_BACKEND 的关系、补全 PR 描述中缺失的 section。

@PaddlePaddle-bot
Copy link
Copy Markdown

PaddlePaddle-bot commented May 20, 2026

🤖 Paddle-CI-Agent | ci_status_monitor | 2026-05-20 12:24:44

CI报告基于以下代码生成(30分钟更新一次):


1 任务总览

存在 3 个 required 任务失败,阻塞合并,需优先处理。

总执行(rerun次数) 总任务 ✅ 通过 ❌ 失败 ⏳ 运行中 ⏸️ 等待中 跳过
32(0) 32 27 5 0 0 0

2 任务状态汇总

2.1 Required任务 : 5/8 通过

必选任务阻塞合并,失败需优先处理。

状态 任务 耗时 根因 修复建议 日志 重跑
Run FastDeploy Unit Tests and Coverage / run_tests_with_coverage 1h17m PR问题:新增use_fused_cast参数,测试mock未更新 更新测试mock,添加use_fused_cast和fd_config字段 Job -
xpu_4cards_case_test / run_xpu_4cards_cases 30m51s PR问题:decode attention变更致XPU服务连接失败 检查XPU decode attention兼容性,查服务崩溃日志 Job -
xpu_8cards_case_test / run_xpu_8cards_cases 20m3s PR问题:XPU PD分离4测试返回500,服务崩溃 检查gpu_model_runner中XPU PD分离初始化逻辑 Job -
其余 5 个必选任务通过 - - - - -

2.2 可选任务 — 22/24 通过

可选任务不阻塞合并,失败仅供参考。

状态 任务 耗时 日志 重跑
Run iluvatar Tests / run_iluvatar_cases 2m2s Job -
Trigger Jenkins for PR 1m5s Job -
其余 22 个可选任务通过 - - -

3 失败详情(仅 required)

Run FastDeploy Unit Tests and Coverage / run_tests_with_coverage — 测试失败(置信度: 高)

Run FastDeploy Unit Tests and Coverage / run_tests_with_coverage

  • 状态: ❌ 失败
  • 错误类型: 测试失败
  • 置信度: 高
  • 根因摘要: PR新增use_fused_cast参数和fd_config访问,测试mock未同步更新
  • 分析器: ci_analyze_unittest_fastdeploy

失败用例:

测试 错误 根因
layers/test_fused_moe_cutlass_backend.py::test_apply_tp_with_dispatch_and_reduce TypeError: unexpected keyword argument 'use_fused_cast' PR在get_moe_scores调用中新增use_fused_cast参数,mock未更新
model_executor/test_ep.py::test_eprunner_moe_select_noaux_tc_without_redundant AttributeError: SimpleNamespace无fd_config属性 PR在ep.py:534新增fd_config访问,测试mock未包含该字段
layers/test_speculative_sampler.py::test_speculative_sampler_logprobs ValueError: int64 vs int32 dtype不匹配 sampler.py中build_sampling_params张量类型不一致
input/test_process_stop_token_ids.py 无pytest错误日志 疑为崩溃或超时,无法深入分析

根因详情:
本 PR 引入 decode unified attention 功能,在 fused_moe_cutlass_backend.py:400ep.py:534 中为 get_moe_scores 调用新增了 use_fused_cast 参数,并新增了 layer.fd_config.scheduler_config.enable_moe_scores_elementwise_fuse 访问,但对应的单元测试 mock 未同步更新。test_speculative_sampler 的 dtype 不匹配(int64 vs int32)也疑似由本 PR 修改的 sampler 路径引入。

关键日志:

TypeError: fake_get_moe_scores() got an unexpected keyword argument 'use_fused_cast'
fused_moe_cutlass_backend.py:400: gate_out, topk_weights, topk_idx = get_moe_scores(..., use_fused_cast=use_fused)
AttributeError: 'types.SimpleNamespace' object has no attribute 'fd_config'
ep.py:534: layer.fd_config.scheduler_config.enable_moe_scores_elementwise_fuse
ValueError: dtype(int64) != phi::CppTypeToDataType<T>::Type()(int32)

修复建议:

  1. tests/layers/test_fused_moe_cutlass_backend.py:在 fake_get_moe_scores 函数签名中添加 use_fused_cast=False 参数
  2. tests/model_executor/test_ep.py layer = SimpleNamespace(...) 处:添加 fd_config mock,包含 scheduler_config.enable_moe_scores_elementwise_fuse=False
  3. 检查 fastdeploy/model_executor/layers/sample/sampler.pybuild_sampling_params 的张量数据类型,确保 int32/int64 一致性

修复建议摘要: 更新测试mock,添加use_fused_cast和fd_config字段

关联变更: fastdeploy/model_executor/layers/moe/fused_moe_cutlass_backend.pyfastdeploy/model_executor/layers/moe/ep.pyfastdeploy/model_executor/layers/sample/sampler.py

链接: 查看日志

xpu_4cards_case_test / run_xpu_4cards_cases — 测试失败(置信度: 中)

xpu_4cards_case_test / run_xpu_4cards_cases

  • 状态: ❌ 失败
  • 错误类型: 测试失败
  • 置信度: 中
  • 根因摘要: decode unified attention变更致XPU推理服务连接失败,15测试全败
  • 分析器: ci_analyze_unittest_fastdeploy

失败用例:

测试 错误 根因
test_ep4tp4_all2all.py::test_ep4tp4_all2all APIConnectionError: Connection error XPU服务连接被拒绝
test_ep4tp4_online.py::test_ep4tp4_online APIConnectionError: Connection error XPU服务连接被拒绝
test_pd_03b_tp1.py::test_pd_separation 连接失败 decode侧服务未启动
test_w4a8.py::test_w4a8 Failed: W4A8测试失败: Connection error XPU服务连接被拒绝
共15个测试全部失败 Connection refused / APIConnectionError XPU推理服务启动或运行异常

根因详情:
15个 XPU 4卡测试(覆盖 ep4tp4、pd分离、mtp、w4a8、w16a16、vl 等场景)全部以 openai.APIConnectionError: Connection error / httpcore.ConnectError: [Errno 111] Connection refused 失败,表明 XPU 推理服务在本 PR 变更后无法正常启动或运行中崩溃。结合 XPU 8卡测试的缓存分析(decode attention修改致服务返回500),本 PR 引入的 decode unified attention 功能与 XPU 平台存在兼容性问题。

关键日志:

openai.APIConnectionError: Connection error.
httpcore.ConnectError: [Errno 111] Connection refused
FAILED tests/xpu_ci/4cards_cases/test_ep4tp4_all2all.py::test_ep4tp4_all2all
FAILED tests/xpu_ci/4cards_cases/test_pd_03b_tp1.py::test_pd_separation
============================4卡cases测试失败,请检查日志!============================

修复建议:

  1. 下载 CI artifact xpu-4cards-case-logs.zip 查看服务侧日志(launch_worker/fastdeploy.log),定位 XPU 服务崩溃堆栈
  2. 检查 fastdeploy/worker/gpu_model_runner.py 中 decode unified attention 在 XPU 平台的条件判断,确保 XPU 不走新的 unified attention 路径或做好兼容

修复建议摘要: 检查XPU decode attention兼容性,下载artifact查服务日志

关联变更: fastdeploy/worker/gpu_model_runner.pyfastdeploy/model_executor/layers/attention/append_attn_backend.py

链接: 查看日志

xpu_8cards_case_test / run_xpu_8cards_cases — 测试失败(置信度: 中)

xpu_8cards_case_test / run_xpu_8cards_cases

  • 状态: ❌ 失败
  • 错误类型: 测试失败
  • 置信度: 中
  • 根因摘要: XPU PD分离4个测试均返回500,疑为decode attention修改致服务崩溃
  • 分析器: ci_analyze_unittest_fastdeploy

失败用例:

测试 错误 根因
test_pd_21b_ep4tp1.py::test_pd_separation openai.InternalServerError decode侧服务返回500
test_pd_21b_ep4tp4.py::test_pd_separation openai.InternalServerError decode侧服务返回500
test_pd_21b_ep4tp4_cudagraph.py::test_pd_separation openai.InternalServerError decode侧服务返回500
test_pd_p_tp4ep4_d_tp1ep4.py::test_pd_separation openai.InternalServerError decode侧服务返回500

根因详情:
本 PR 引入 decode unified attention 功能,修改了 gpu_model_runner.pyappend_attn_backend.pyflash_attn_backend.py 等核心 attention 执行路径。4 个 XPU 8 卡 PD 分离测试(覆盖 ep4tp1、ep4tp4、ep4tp4_cudagraph、p_tp4ep4_d_tp1ep4 共 4 种配置)全部在 client.chat.completions.create() 时收到 Internal Server Error,表明 decode 节点推理服务在处理请求时异常退出。PR 说明中明确提到 PD 分离场景需设置 FD_ATTENTION_BACKEND=DECODE_UNIFIED_ATTN,该功能修改直接涉及 PD 分离的 decode 执行路径。

修复建议:

  1. 检查 fastdeploy/worker/gpu_model_runner.py 中 attention backend 在 XPU PD 分离模式下的初始化逻辑,确认 decode unified attention 与 XPU 平台的兼容性
  2. 下载 CI artifact xpu-8cards-case-logs.zip 中 decode 节点的服务日志,定位 Internal Server Error 的具体堆栈

修复建议摘要: 检查gpu_model_runner中XPU PD分离attention初始化逻辑

关联变更: fastdeploy/worker/gpu_model_runner.pyfastdeploy/model_executor/layers/attention/append_attn_backend.pyfastdeploy/model_executor/layers/attention/flash_attn_backend.py

链接: 查看日志

@codecov-commenter
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 40.00000% with 150 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (release/online/20260415@55eb3a6). Learn more about missing BASE report.

Files with missing lines Patch % Lines
...yers/attention/decode_unified_attention_backend.py 20.93% 101 Missing and 1 partial ⚠️
fastdeploy/spec_decode/mtp.py 48.71% 17 Missing and 3 partials ⚠️
...l_executor/layers/attention/append_attn_backend.py 0.00% 10 Missing and 1 partial ⚠️
...el_executor/layers/attention/flash_attn_backend.py 46.66% 6 Missing and 2 partials ⚠️
fastdeploy/platforms/cuda.py 0.00% 2 Missing and 1 partial ⚠️
fastdeploy/worker/gpu_model_runner.py 72.72% 1 Missing and 2 partials ⚠️
...cutor/layers/attention/ops/config_for_attention.py 85.71% 0 Missing and 1 partial ⚠️
...r/layers/attention/ops/decode_unified_attention.py 88.88% 0 Missing and 1 partial ⚠️
...ers/attention/ops/decoder_write_cache_with_rope.py 88.88% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@                    Coverage Diff                     @@
##             release/online/20260415    #7850   +/-   ##
==========================================================
  Coverage                           ?   73.82%           
==========================================================
  Files                              ?      387           
  Lines                              ?    54014           
  Branches                           ?     8467           
==========================================================
  Hits                               ?    39875           
  Misses                             ?    11415           
  Partials                           ?     2724           
Flag Coverage Δ
GPU 73.82% <40.00%> (?)

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

☔ View full report in Codecov by Sentry.
📢 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.

@freeliuzc freeliuzc merged commit 15aed4f into PaddlePaddle:release/online/20260415 May 20, 2026
28 of 33 checks passed
@lizhenyun01 lizhenyun01 deleted the dec_attn_0415 branch May 20, 2026 07:37
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