Skip to content

[BugFix][PD Disaggregation] Fix garbled text in PD disaggregation by adding early return in prefix cache insertion#7797

Merged
Jiang-Jia-Jun merged 1 commit into
PaddlePaddle:developfrom
kevincheng2:bugfix/pd-prefix-cache-garbled-text
May 13, 2026
Merged

[BugFix][PD Disaggregation] Fix garbled text in PD disaggregation by adding early return in prefix cache insertion#7797
Jiang-Jia-Jun merged 1 commit into
PaddlePaddle:developfrom
kevincheng2:bugfix/pd-prefix-cache-garbled-text

Conversation

@kevincheng2
Copy link
Copy Markdown
Collaborator

@kevincheng2 kevincheng2 commented May 12, 2026

Motivation

修复 PD 分离场景下前缀缓存插入条件缺失导致的乱码问题。当 can_cache_computed_tokens <= num_cached_tokens 时,没有新的 token 需要缓存,但仍会执行后续的缓存插入操作,导致block错乱。

Modifications

  • fastdeploy/cache_manager/prefix_cache_manager.py: 在 insert_prefix_cache 方法中新增提前返回判断,当 can_cache_computed_tokens <= num_cached_tokens 时直接返回,避免无新 token 可缓存时的多余缓存操作。

Usage or Command

启动 PD 分离服务进行测试:

# 启动 router
bash run_router.sh
# 启动 P 节点
bash run_p.sh
# 启动 D 节点
bash run_d.sh

Checklist

  • Add at least a tag in the PR title.
  • Format your code, run pre-commit before commit.
  • Add unit tests. No unit tests added as this is a guard condition that is covered by existing integration 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.

…rn when no new tokens to cache

- Add early return check when can_cache_computed_tokens <= num_cached_tokens
- Avoid unnecessary cache insertion operations that cause garbled output
- Only affects PD disaggregation scenarios
@paddle-bot
Copy link
Copy Markdown

paddle-bot Bot commented May 12, 2026

Thanks for your contribution!

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-12 21:11:52

📋 Review 摘要

PR 概述:在 update_cache_blocks 方法中添加提前返回判断,修复 PD 分离场景下前缀缓存插入条件缺失导致的 block 错乱(乱码)问题。
变更范围fastdeploy/cache_manager/prefix_cache_manager.py
影响面 Tag[KVCache] [PD Disaggregation]

📝 PR 规范检查

PR 存在以下规范问题:

  1. 标题含多个 Tag[BugFix][PD Disaggregation] 包含两个 Tag,规范要求仅包含一个官方 Tag。
  2. 描述模板缺少 ## Accuracy Tests 段落:PR body 缺失该必填 section。

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

  • [BugFix] Fix garbled text in PD disaggregation by adding early return in prefix cache insertion

PR 描述建议(可直接复制,必须复刻 checklist §D2 模板的完整结构):

## Motivation
修复 PD 分离场景下前缀缓存插入条件缺失导致的乱码问题。当 `can_cache_computed_tokens <= num_cached_tokens` 时,没有新的 token 需要缓存,但仍会执行后续的缓存插入操作,导致 block 错乱。

## Modifications
- `fastdeploy/cache_manager/prefix_cache_manager.py`: 在 `update_cache_blocks` 方法中新增提前返回判断,当 `can_cache_computed_tokens <= num_cached_tokens` 时直接返回,避免无新 token 可缓存时的多余缓存操作。

## Usage or Command
启动 PD 分离服务进行测试:
```bash
# 启动 router
bash run_router.sh
# 启动 P 节点
bash run_p.sh
# 启动 D 节点
bash run_d.sh
```

## 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.
- [x] Add unit tests. No unit tests added as this is a guard condition that is covered by existing integration 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.

问题

未发现阻塞性问题。

总体评价

修复逻辑准确,提前返回判断有效防止了 can_cache_computed_tokens <= num_cached_tokens 时的冗余缓存操作,解决了 PD 分离场景下的 block 错乱问题。建议调整标题 Tag 数量并补充 ## Accuracy Tests 段落。

@PaddlePaddle-bot
Copy link
Copy Markdown

🤖 Paddle-CI-Agent | ci_status_monitor | 2026-05-12 21:36:09

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


1 任务总览

⚠️ CI 尚未完成:有 1 个 required 任务失败,2 个 required 任务运行中,需关注。

总执行(rerun次数) 总任务 ✅ 通过 ❌ 失败 ⏳ 运行中 ⏸️ 等待中 跳过
38(0) 38 30 3 3 1 1

2 任务状态汇总

2.1 Required任务 : 7/10 通过

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

状态 任务 耗时 根因 修复建议 日志 重跑
Run Base Tests / base_tests 12m41s PR问题:早返回逻辑可能致基础测试失败(日志获取失败) 查看Job日志确认失败用例与改动的关系 Job -
Run FastDeploy Unit Tests and Coverage / run_tests_with_coverage - 运行中 - Job -
xpu_4cards_case_test / run_xpu_4cards_cases - 运行中 - Job -
其余 7 个必选任务通过 - - - - -

2.2 可选任务 — 23/27 通过

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

状态 任务 耗时 日志 重跑
Check PR Template 11s Job -
Trigger Jenkins for PR (CI_METAX) 23m43s Job -
Run iluvatar Tests / run_iluvatar_cases - - -
⏸️ CI_HPU - - -
其余 23 个可选任务通过 - - -

3 失败详情(仅 required)

Run Base Tests / base_tests — 用例失败(置信度: 低)

Run Base Tests / base_tests

  • 状态: ❌ 失败
  • 错误类型: 用例失败(推测,日志获取失败)
  • 置信度: 低
  • 根因摘要: 早返回逻辑可能影响基础测试,日志获取失败无法确认
  • 分析器: 通用分析(fallback)

根因详情:
本次PR在 fastdeploy/cache_manager/prefix_cache_manager.pyupdate_cache_blocks 方法新增早返回逻辑:当 can_cache_computed_tokens <= num_cached_tokens 时直接返回,跳过后续的缓存插入操作。失败步骤为 "Run FastDeploy Base Tests",运行约12分钟后以退出码1退出。由于日志拉取时发生TLS握手超时,无法确认具体失败用例与本次变更的关联性。

关键日志:

(日志获取失败,无法提取错误信息)
失败步骤: Run FastDeploy Base Tests
退出码: 1

修复建议:

  1. 手动查看 Job 日志 确认具体失败用例
  2. 检查 update_cache_blocks 早返回是否跳过了某些状态更新,导致后续基础测试断言失败
  3. 若与PR变更无关(环境抖动),请 rerun 此任务

修复建议摘要: 查看Job日志确认失败用例是否与早返回改动相关

关联变更: fastdeploy/cache_manager/prefix_cache_manager.py 约701行新增早返回条件
链接: 查看日志

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented May 12, 2026

Codecov Report

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

Additional details and impacted files
@@            Coverage Diff             @@
##             develop    #7797   +/-   ##
==========================================
  Coverage           ?   63.22%           
==========================================
  Files              ?      459           
  Lines              ?    64104           
  Branches           ?     9824           
==========================================
  Hits               ?    40532           
  Misses             ?    20795           
  Partials           ?     2777           
Flag Coverage Δ
GPU 72.36% <100.00%> (?)
XPU 7.13% <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.

@Jiang-Jia-Jun Jiang-Jia-Jun merged commit a0141b9 into PaddlePaddle:develop May 13, 2026
56 of 61 checks passed
@EmmonsCurse
Copy link
Copy Markdown
Collaborator

✅ Cherry-pick successful! Created PR: #7802

kevincheng2 added a commit that referenced this pull request May 13, 2026
…rn when no new tokens to cache (#7797) (#7802)

- Add early return check when can_cache_computed_tokens <= num_cached_tokens
- Avoid unnecessary cache insertion operations that cause garbled output
- Only affects PD disaggregation scenarios

Co-authored-by: kevin <chengyf112@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants