Skip to content

[BugFix] Fix KSM overlap bug#7772

Open
Deleter-D wants to merge 1 commit into
PaddlePaddle:release/2.6from
Deleter-D:2.6_ksm_bug
Open

[BugFix] Fix KSM overlap bug#7772
Deleter-D wants to merge 1 commit into
PaddlePaddle:release/2.6from
Deleter-D:2.6_ksm_bug

Conversation

@Deleter-D
Copy link
Copy Markdown
Collaborator

@Deleter-D Deleter-D commented May 11, 2026

Motivation

Fix a bug in KSM when overlap is enabled. Since KSM itself introduces synchronization under overlap mode, which breaks the overlap, we temporarily do not consider asynchrony here and only ensure functional correctness.

Modifications

  • Changed accept_num_cpu to accept_num to directly use the GPU-side accept_num for calculation

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.

@paddle-bot
Copy link
Copy Markdown

paddle-bot Bot commented May 11, 2026

Thanks for your contribution!

@Deleter-D Deleter-D changed the title fix ksm overlap bugs [BugFix] Fix KSM overlap bug May 11, 2026
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-11 15:36:26

📋 Review 摘要

PR 概述:修复 KSM overlap 模式下 accept_num_cpu 同步问题导致 logprobs 截断不正确的 bug
变更范围fastdeploy/model_executor/pre_and_post_process.pysave_output_speculate 函数)
影响面 Tag[Speculative Decoding] [BugFix]


📝 PR 规范检查

存在以下规范问题:

  1. 标题缺少官方 Tag:当前标题 fix ksm overlap bugs 未包含任何官方 Tag。
  2. 目标分支为 release/2.6:需使用 Cherry-Pick 格式,并确认原 develop 分支 PR 编号。

标题建议(可直接复制):

  • [Cherry-Pick][BugFix][Speculative Decoding] Fix accept_num_cpu sync bug when KSM overlap is enabled (#<原PR号>)

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

## Motivation
修复 KSM overlap 模式下 logprobs 重归一化逻辑中 `accept_num_cpu` 同步问题。当 overlap 启用时,`accept_num_cpu`(D2H 异步拷贝)可能尚未更新,导致 `real_token_num` 取值错误,进而引发 logprobs 截断不正确。直接使用 GPU 侧的 `accept_num` 可规避该竞态。

## Modifications
- `fastdeploy/model_executor/pre_and_post_process.py`:在 `save_output_speculate` 函数的 logprobs 重归一化路径中,将 `share_inputs["accept_num_cpu"].sum()` 替换为 `share_inputs["accept_num"].sum()`,并移除相关 TODO 注释。

## 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.
- [x] 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.

问题

级别 文件 概述
📝 PR 规范 标题缺少官方 Tag,目标 release 分支未使用 Cherry-Pick 格式,描述所有章节均为空占位符
❓ 疑问 pre_and_post_process.py:588 share_inputs["accept_num"].sum() 若返回 GPU 0-dim tensor,用作切片索引时会触发隐式 D2H 同步;建议确认是否需要 .item()

说明:疑问项行内评论因 diff 解析限制未能附加到具体行,请作者参考以上说明确认。

总体评价

代码改动精准,将 overlap 模式下可能过时的 CPU 侧拷贝 accept_num_cpu 替换为直接读取 GPU 侧的 accept_num,修复方向正确;无 P0 阻塞性问题,需补全 PR 标题格式与描述内容后即可合入。

@PaddlePaddle-bot
Copy link
Copy Markdown

🤖 Paddle-CI-Agent | ci_status_monitor | 2026-05-11 16:13:16

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


1 任务总览

当前有 1 个 Required 任务失败Approval),同时有 3 个 Required 任务运行中1 个 Required 任务等待中,需要关注。

总执行(rerun次数) 总任务 ✅ 通过 ❌ 失败 ⏳ 运行中 ⏸️ 等待中 跳过
35(0) 35 26 4 3 2 0

2 任务状态汇总

2.1 Required任务 : 5/10 通过

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

状态 任务 耗时 根因 修复建议 日志 重跑
Approval 10s PR问题:PR未获RD成员(qingqing01等)审批 联系qingqing01/jiangjiajun/heavengate审批 Job -
run_tests_with_coverage - 运行中 - Job -
xpu_4cards_case_test / run_xpu_4cards_cases - 运行中 - Job -
xpu_8cards_case_test / run_xpu_8cards_cases - 运行中 - Job -
⏸️ Run Four Cards Tests / run_4_cards_tests - 等待中 - - -
其余 5 个必选任务通过 - - - - -

2.2 可选任务 — 21/25 通过

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

状态 任务 耗时 日志 重跑
Run iluvatar Tests / run_iluvatar_cases 14m2s Job -
Check PR Template 14s Job -
Trigger Jenkins for PR 40s Job -
⏸️ CI_HPU - - -
其余 21 个可选任务通过 - - -

3 失败详情(仅 required)

Approval — 基础设施(审批门控)(置信度: 高)

Approval

  • 状态: ❌ 失败
  • 错误类型: 基础设施(审批门控)
  • 置信度: 高
  • 根因摘要: PR向release分支提交,缺少RD成员审批
  • 分析器: 通用分析(fallback)

根因详情:
PR 目标分支为 release/2.6,触发了 Approval 审批检查。脚本 scripts/check_approval.sh 输出 "There are 1 approved errors"(退出码6)。根据检查规则,向 release 分支提交的 PR 需要 FastDeploy RD 成员(qingqing01、Jiang-Jia-Jun 或 heavengate)的 GitHub Review Approve 操作方可通过。

关键日志:

==> PR title: fix ksm overlap bugs
0. Cherry-Pick PR must come from develop and the title must contain [Cherry-Pick]
   Approval required from FastDeploy RD: qingqing01(dangqingqing), Jiang-Jia-Jun(jiangjiajun), heavengate(dengkaipeng).
There are 1 approved errors.
##[error]Process completed with exit code 6.

修复建议:

  1. 联系 FastDeploy RD 成员(qingqing01/Jiang-Jia-Jun/heavengate)对本 PR 进行 GitHub Review Approve 操作
  2. 若本 PR 为 cherry-pick,请确认 PR 标题包含 [Cherry-Pick] 前缀和原 PR 编号(如 [Cherry-Pick][#5010] fix ksm overlap bugs

修复建议摘要: 联系RD成员(qingqing01/jiangjiajun/heavengate)进行审批

关联变更: PR 所有变更,目标分支 release/2.6
链接: 查看日志

@codecov-commenter
Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (release/2.6@228987a). Learn more about missing BASE report.

Files with missing lines Patch % Lines
fastdeploy/model_executor/pre_and_post_process.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@              Coverage Diff               @@
##             release/2.6    #7772   +/-   ##
==============================================
  Coverage               ?   71.86%           
==============================================
  Files                  ?      378           
  Lines                  ?    53924           
  Branches               ?     8432           
==============================================
  Hits                   ?    38750           
  Misses                 ?    12409           
  Partials               ?     2765           
Flag Coverage Δ
GPU 71.86% <0.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.

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