Skip to content

[Graph Optimization]Revert blockwise CUDAGraph and support piecewise CUDAGraph in prefill#7969

Merged
Jiang-Jia-Jun merged 8 commits into
PaddlePaddle:developfrom
ZhangX-21:piecewise_cudagraph
Jul 15, 2026
Merged

[Graph Optimization]Revert blockwise CUDAGraph and support piecewise CUDAGraph in prefill#7969
Jiang-Jia-Jun merged 8 commits into
PaddlePaddle:developfrom
ZhangX-21:piecewise_cudagraph

Conversation

@ZhangX-21

Copy link
Copy Markdown
Contributor

Motivation

This PR reverts the previous blockwise CUDAGraph implementation and adds support for piecewise CUDAGraph in the prefill phase.

Modifications

  • Revert blockwise CUDAGraph related logic.
  • Support piecewise CUDAGraph for prefill.
  • Capture reusable graph segments inside the prefill phase.
  • Refactor prefill CUDAGraph capture/replay control flow.
  • Keep decode CUDAGraph behavior unchanged.

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.

@PaddlePaddle-bot

PaddlePaddle-bot commented Jun 2, 2026

Copy link
Copy Markdown

🤖 Paddle-CI-Agent | ci_status_monitor | 2026-07-10 17:26:33 UTC+08:00

CI报告基于以下代码生成(30分钟更新一次):
PR commit: 8bd2e90 | Merge base: 9a48fab (branch: develop)


1 Required任务 : 4/10 通过

总执行(rerun次数) 总任务 ✅ 通过 ❌ 失败 ⏳ 运行中 ⏸️ 等待中 跳过
42(0) 42 32 9 0 0 0
任务 错误类型 置信度 日志
Run FastDeploy Unit Tests and Coverage / run_tests_with_coverage PR问题 Job
Run Stable Tests / stable_tests PR问题 Job
Extracted partial CE model tasks to run in CI. / run_ce_cases PR问题 Job
Approval 需要 Approval Job
xpu_8cards_case_test / run_xpu_8cards_cases PR问题 Job

2 失败详情

🔴 Run FastDeploy Unit Tests and Coverage / run_tests_with_coverage — PR问题(置信度: 高)

分析器: ci_analyze_unittest_fastdeploy

失败用例:

用例 错误摘要
test_fp8_ue8m0.py::test_fleet_fp8_quant_single_chunk, test_model_executor_utils.py::test_gdr_dynamic_transpose_preserves_loading_attrs_for_future_updates, test_rollout_model.py::test_rollout_model_with_distributed_launch 访问已删除的 FD_USE_GDR_CHECKPOINT_TRANSFER env,触发 AttributeError
test_kv_cache_int8_dynamic_quant_backend.py::test_block_wise_fp8_layer_id_1 FlashAttentionBackend 新增读取 graph_opt_config.full_cuda_graph,测试 Dummy config 未同步
test_ep.py::test_eprunner_moe_select_noaux_tc_without_redundant get_moe_scores 顶层导入后测试 monkeypatch 未命中,真实 noaux_tc 路径对 None bias 相加

关键日志:

AttributeError: module 'fastdeploy.envs' has no attribute 'FD_USE_GDR_CHECKPOINT_TRANSFER'
AttributeError: 'GraphOptConfig' object has no attribute 'full_cuda_graph'
TypeError: __add__(): argument (position 1) must be int, float, bool or Tensor, but got NoneType
  • 根因摘要: PR变更未同步 env/config/test 依赖
    fastdeploy/envs.py 删除了 FD_USE_GDR_CHECKPOINT_TRANSFER,但 fastdeploy/model_executor/utils.py:138 仍直接读取该 env,导致 FP8、动态权重和 rollout 相关用例失败。fastdeploy/model_executor/layers/attention/flash_attn_backend.py:776 新增直接访问 full_cuda_graph,而 tests/layers/test_kv_cache_int8_dynamic_quant_backend.py:103-107 的 Dummy GraphOptConfig 未提供该字段。fastdeploy/model_executor/layers/moe/ep.pyget_moe_scores 提升为模块顶层导入后,tests/model_executor/test_ep.py:401-403 对原模块的 monkeypatch 不再影响 ep.get_moe_scores,进而调用真实函数并在 fastdeploy/model_executor/layers/moe/moe.py:118None bias 相加。

修复建议:

  1. 恢复 FD_USE_GDR_CHECKPOINT_TRANSFER 的 env 注册,或同步删除/保护 fastdeploy/model_executor/utils.py:138 及其调用链对该 env 的读取。
  2. flash_attn_backend.py:776 使用兼容读取(例如默认 full_cuda_graph=True),或同步更新测试 Dummy GraphOptConfig
  3. 恢复 ep.py 中对 get_moe_scores 的可 patch 查找方式,或将测试 patch 目标改为 fastdeploy.model_executor.layers.moe.ep.get_moe_scores;若 gate_correction_bias=None 是合法输入,需在 get_moe_scores 中显式处理。

关联变更: fastdeploy/envs.py 删除 env;本 PR 修改 flash_attn_backend.pyep.pymoe.py,均与失败栈直接相关。

🔴 Run Stable Tests / stable_tests — PR问题(置信度: 高)

失败用例:

用例 错误摘要
Run FastDeploy Stable Tests 模型加载后动态权重路径访问已删除的 FD_USE_GDR_CHECKPOINT_TRANSFER env

关键日志:

File "/usr/local/lib/python3.10/site-packages/fastdeploy/rl/dynamic_weight_manager.py", line 57
  self.use_gdr_checkpoint_transfer = envs.FD_USE_GDR_CHECKPOINT_TRANSFER
AttributeError: module 'fastdeploy.envs' has no attribute 'FD_USE_GDR_CHECKPOINT_TRANSFER'
  • 根因摘要: env配置被删除但仍被访问
    PR diff 删除了 fastdeploy/envs.pyFD_USE_GDR_CHECKPOINT_TRANSFER 的注册项,但当前代码仍在 fastdeploy/rl/dynamic_weight_manager.py:57 读取该属性。fastdeploy/envs.py 对未注册 env 会在 __getattr__AttributeError,导致 stable 测试进程退出。

修复建议:

  1. 恢复 FD_USE_GDR_CHECKPOINT_TRANSFER env 注册,或同步移除/改造 fastdeploy/rl/dynamic_weight_manager.py:57fastdeploy/model_executor/utils.py:138 的访问;同时检查 FD_USE_BLOCK_WISE_CUDA_GRAPH 的残留访问。

关联变更: 本 PR 修改 fastdeploy/envs.py 删除该 env;当前残留引用位于 fastdeploy/rl/dynamic_weight_manager.py:57fastdeploy/model_executor/utils.py:138

🔴 Extracted partial CE model tasks to run in CI. / run_ce_cases — PR问题(置信度: 高)

失败用例:

用例 错误摘要
test_rollout_model.py::test_rollout_model_with_distributed_launch, test_rollout_model.py::test_rollout_model_with_distributed_launch_mtp rollout 服务加载 GLM-45-AIR 时访问缺失 env,子进程 exit_code=1

关键日志:

process_weight_transpose(layer, "weight")
return envs.FD_USE_GDR_CHECKPOINT_TRANSFER
AttributeError: module 'fastdeploy.envs' has no attribute 'FD_USE_GDR_CHECKPOINT_TRANSFER'
[ERROR] test_rollout_model.py 起服务或执行异常,exit_code=1
  • 根因摘要: rollout加载命中缺失env配置
    CE job 的两个 rollout 用例在 fastdeploy/model_executor/utils.py:138 读取同一个已删除 env,并由 fastdeploy/envs.py::__getattr__ 抛出 AttributeError。这与 stable job 是同一类 PR 引入问题,不是环境下载或 runner 异常。

修复建议:

  1. 与 stable job 相同,恢复 FD_USE_GDR_CHECKPOINT_TRANSFER 配置项,或让 _is_gdr_checkpoint_transfer_dynamic_load_config 在 env 缺失时有兼容默认值,并同步清理相关测试/动态权重逻辑。

关联变更: 本 PR 删除 fastdeploy/envs.py 中该 env;失败调用链落在 fastdeploy/model_executor/utils.py:138

🔴 Approval — 需要 Approval(置信度: 高)

该 Job 需要人工 Approval,完成审批后 CI 才会继续执行。

🔴 xpu_8cards_case_test / run_xpu_8cards_cases — PR问题(置信度: 中)

失败用例:

用例 错误摘要
test_pd_21b_ep4tp1.py::test_pd_separation, test_pd_21b_ep4tp4.py::test_pd_separation, test_pd_21b_ep4tp4_cudagraph.py::test_pd_separation 等 4 个 P/D 节点 /health 10 分钟均返回 000,PD 服务启动失败

关键日志:

服务健康检查中... 已等待 420 秒,P节点状态码:000,D节点状态码:000
服务健康检查中... 已等待 591 秒,P节点状态码:000,D节点状态码:000
PD分离服务启动超时:经过 10 分钟服务仍未启动!
pytest.fail("PD分离服务启动失败")
  • 根因摘要: PD服务健康检查超时未启动
    4 个 XPU 8 卡 PD 分离用例都在服务启动阶段失败,尚未进入请求结果断言。主日志未打印 Prefill/Decode worker 的内部 traceback;结合本 PR 修改 splitwise_role == "prefill" 时的 CUDAGraph 开启条件和 prefill/mixed capture 流程,当前更像 PR 改动导致 PD prefill/graph 路径启动失败,置信度为中。

修复建议:

  1. 检查 fastdeploy/config.py:2301-2308fastdeploy/worker/gpu_worker.py:252-262fastdeploy/worker/gpu_model_runner.py:1518-1551 是否在 XPU PD prefill 上误启 piecewise CUDAGraph;如仅支持 CUDA/GPU,应增加平台或配置门控,或回退到 cudagraph_only_prefill 行为。

关联变更: 本 PR 修改 PD prefill piecewise CUDAGraph 控制流;失败测试位于 tests/xpu_ci/8cards_cases/test_pd_21b_ep4tp1.py:254-285 等。

PaddlePaddle-bot

This comment was marked as outdated.

@codecov-commenter

codecov-commenter commented Jun 2, 2026

Copy link
Copy Markdown

Codecov Report

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

Files with missing lines Patch % Lines
...cutor/layers/quantization/ops/cutlass_scaled_mm.py 8.33% 10 Missing and 1 partial ⚠️
...el_executor/layers/attention/flash_attn_backend.py 95.42% 5 Missing and 2 partials ⚠️
...ecutor/layers/quantization/ops/scaled_fp8_quant.py 30.00% 5 Missing and 2 partials ⚠️
...el_executor/layers/moe/fused_moe_triton_backend.py 92.10% 2 Missing and 1 partial ⚠️
fastdeploy/config.py 80.00% 1 Missing and 1 partial ⚠️
fastdeploy/model_executor/layers/normalization.py 71.42% 1 Missing and 1 partial ⚠️
fastdeploy/worker/gpu_model_runner.py 60.00% 2 Missing ⚠️
fastdeploy/worker/gpu_worker.py 71.42% 0 Missing and 2 partials ⚠️
...tdeploy/model_executor/graph_optimization/utils.py 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             develop    #7969   +/-   ##
==========================================
  Coverage           ?   67.45%           
==========================================
  Files              ?      474           
  Lines              ?    66920           
  Branches           ?    10296           
==========================================
  Hits               ?    45138           
  Misses             ?    18891           
  Partials           ?     2891           
Flag Coverage Δ
GPU 77.48% <85.30%> (?)
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.

PaddlePaddle-bot

This comment was marked as outdated.

PaddlePaddle-bot

This comment was marked as outdated.

PaddlePaddle-bot

This comment was marked as outdated.

@ZhangX-21 ZhangX-21 changed the title Revert blockwise CUDAGraph and support piecewise CUDAGraph in prefill [Graph Optimization]Revert blockwise CUDAGraph and support piecewise CUDAGraph in prefill Jul 10, 2026
@paddle-bot

paddle-bot Bot commented Jul 13, 2026

Copy link
Copy Markdown

Thanks for your contribution!

PaddlePaddle-bot

This comment was marked as outdated.

PaddlePaddle-bot

This comment was marked as outdated.

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-15 14:44:32 Asia/Shanghai

📋 Review 摘要

PR 概述:回退 block-wise CUDAGraph,并为 prefill/mixed 路径接入 piecewise CUDAGraph,同时调整 FlashAttention/MoE custom op 的 SOT 兼容逻辑。

变更范围:CUDAGraph 配置和 worker capture 流程、FlashAttention py-op 包装、MoE/TopK custom op infer_meta、图优化相关测试。

影响面 Tag[Graph Optimization] [OP] [FDConfig]

问题

级别 文件 概述
🔴 Bug custom_ops/gpu_ops/noaux_tc_redundant.cu:81 noaux_tc_redundant 的静态 infer_meta 仍只声明 3 个输出,和 4 输出注册不一致

历史 Findings 修复情况

Finding 问题 状态
F3 PD prefill piecewise 与 CPU cache 兼容性检查 ⚠️ 仍存在
F4 WFP8AFP8 Triton MoE 中 paddle.sum(..., out=...) ⚠️ 仍存在
F5 batch_id_per_token-1 padding sentinel ✅ 已修复
F6 mixed batch 下 merge_prefill_decode_output 结果被丢弃 ⚠️ 仍存在
F7 python_op_wfp8afp8_triton_moe 未加入 CUDA Graph blacklist ⚠️ 仍存在

📝 PR 规范检查

标题缺少官方 Tag,描述结构完整但 Usage or Command 和 Accuracy Tests 仅为占位注释。

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

  • [Graph Optimization] Revert blockwise CUDAGraph and support piecewise CUDAGraph in prefill
PR 描述建议(点击展开,可直接复制)
## Motivation

This PR reverts the previous blockwise CUDAGraph implementation and adds support for piecewise CUDAGraph in the prefill phase. The blockwise approach captured per-layer graphs which fragmented SOT-compiled graphs; the piecewise approach captures reusable sub-graph segments during prefill without graph fragmentation.

## Modifications

- Revert blockwise CUDAGraph related logic (remove `cuda_graph_op.py`, env vars `FD_USE_BLOCK_WISE_CUDA_GRAPH` / `FD_BLOCK_WISE_CUDA_GRAPH_SIZES`).
- Add `prefill_cudagraph_guard` around prefill capture.
- Extend prefill capture sizes up to 8192 tokens in `config.py`.
- Refactor `RMSNorm.forward`: remove dtype cast, use dynamic `max_chunk_tokens` for allreduce fusion.
- Pass `max_token_num` to `flashinfer_allreduce_residual_rmsnorm` to match workspace allocation.
- Keep decode CUDAGraph behavior unchanged.

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

总体评价

本轮按风险优先审查了 CUDAGraph prefill/mixed、FlashAttention Python op、MoE custom python op、noaux_tc static op metadata、GPU worker warmup/config 联动;未全量覆盖纯删除的 block-wise graph tests。当前新增的 static op infer_meta 不一致会阻断 SOT/custom op 构图,需要修复后再合入。

const std::vector<int64_t>&,
const std::vector<int64_t>&,
const int n_group,
const int topk_group,

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 noaux_tc_redundant 的静态 infer_meta 仍只返回 3 个输出。

这次签名补齐了额外输入和 attrs,但 PD_BUILD_STATIC_OP(noaux_tc_redundant) 注册了 4 个输出(包含 inplace 的 tokens_per_expert_stats_list_out),NoauxTcRedundantInferShape 仍只返回 3 个 shape,NoauxTcRedundantInferDtype 也只返回 3 个 dtype 且签名仍只覆盖前两个输入。进入 SOT/static custom op 路径时,infer_meta 和注册输出不一致会导致 op 构图失败或丢失 inplace 输出元信息。

建议把 shape/dtype infer 都补齐到与注册一致,例如返回第四个 tokens_per_expert_stats_list 的 shape/dtype,并让 InferDtype 接收新增 3 个输入 dtype 及 attrs 参数。

@yongqiangma yongqiangma left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@gongshaotian gongshaotian left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@Jiang-Jia-Jun Jiang-Jia-Jun merged commit a7331b5 into PaddlePaddle:develop Jul 15, 2026
38 of 43 checks passed
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.

6 participants