Skip to content

[PerfSim]Add profiler event code in pp and remove useless pp static scheduler - #80028

Open
Hz188 wants to merge 8 commits into
PaddlePaddle:developfrom
Hz188:develop
Open

Hz188 wants to merge 8 commits into
PaddlePaddle:developfrom
Hz188:develop

Conversation

@Hz188

@Hz188 Hz188 commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

PR Category

User Experience

PR Types

Improvements

Description

清理之前的pp 模拟等无用代码,并合入perfsim支持的pp profiler工具代码

是否引起精度变化

否

Hz188 and others added 4 commits November 27, 2026 15:31
_record_stamp/_flush_records wrote one text file per rank and needed
profiler_helper.py to merge them into pipeline_profile.json for
chrome://tracing. It timestamps with time.time() at millisecond
resolution and does a paddle.device.synchronize() per stamp, so turning
it on perturbs what it measures, and host clocks are not comparable
across ranks. It had also fallen behind the schedulers:
PipelineParallelWithInterleaveFthenB never wired it up at all.

The pipeline_event_hook mechanism covers the same ground with CUDA
events and no synchronization, so drop this one.

_forward_micro_step_counter / _backward_micro_step_counter and
_reset_counter() are kept: static_scheduler reads them too.
pp_configs.profiling stays in the proto but is now unread.
forward_backward_pipeline(static_scheduler=True) skipped every recv /
forward / send and only appended to a string, returning the schedule
("f0_vp0;b0_vp1;...") instead of a loss. get_static_scheduler() was its
only entry point and nothing in the tree called it.

With the chrome-tracing profiler gone this was the last reader of
_forward_micro_step_counter / _backward_micro_step_counter, so those and
_reset_counter() go with it. _rc_forward_count / _rc_backward_count are
unaffected: they are RecomputeStore's chunk identity and are maintained
unconditionally.
NoPipelineParallel (pp_degree = 1) now publishes the same scheduler events as
PipelineParallel through pipeline_event_hook, so a listener (for example a
timeline profiler) sees pp = 1 runs too: one stage, one step of
accumulate_steps forward / backward pairs in a single steady phase, no p2p.

- pipeline_event_hook: add the `step` span kind and PipelineEventHook.step(),
  for a scheduler whose whole step sits in one block
- NoPipelineParallel: set the hook context in __init__ (stage 0 of 1) and wrap
  forward_backward_pipeline in step / phase("steady") / forward(micro) /
  backward(micro) spans. With no listener registered every emit is a no-op.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Paddle-Review-Bot

Paddle-Review-Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Paddle-Bot Review Board (review完成)

序号 位置 优先级 规则来源 状态
1 pipeline_parallel.py:2009 handle_wait 无参调用兼容 P1 仓库规则:功能正确性与兼容性 ✅
2 pipeline_parallel.py:3484 cooldown phase 事件成对发出 P2 仓库规则:功能正确性与兼容性 ✅
3 pipeline_parallel.py:851 pp_configs.profiling 弃用告警 P2 仓库规则:功能正确性与兼容性 ✅
4 新增 pipeline_event_hook 与 P2PReqs 单测 P2 仓库规则:测试质量与验证 ✅

可维护性建议(总分 86.5 / 100,只给建议,不影响评审结论)

序号 位置 维度 状态
1 pipeline_parallel.py:2136 新增中文注释与 docstring 约定偏离 ✅
2 pipeline_parallel.py:467 replica_ranks 推导重复两份 中层优雅度 ✅
3 pipeline_event_hook.py:206 与现有回调机制并存 依赖健康度 ✅
4 pipeline_event_hook.py:382 未使用的公共成员 抽象适配度 ✅
5 pipeline_parallel.py:1242 step 边界手写 emit 错误处理一致性 ✅
6 test_pipeline_parallel_micro_step_hooks.py:339 p2p_issue 事件缺少用例 测试策略 ✅
7 pipeline_parallel.py:2779 step 包裹导致整体缩进 设计一致性 ✅
各维度得分(仅评本 PR 改动,点击展开)
82 测试策略
6
85 AI 生成债务
85 API 表面一致性
85 契约一致性
85 初始化耦合
85 命名质量
85 类型安全
86 跨模块架构
86 未完成迁移
86 中层优雅度
2
86 包组织结构
87 约定偏离
1
87 错误处理一致性
5
87 高层优雅度
88 抽象适配度
4
88 设计一致性
7
88 底层优雅度
90 逻辑清晰度
92 依赖健康度
3
— 鉴权一致性

Powered by Nyanpasu claude with DeepSeek-V4.1-Flash 默认推理级别, please check the suggestions carefully.

@@ -2028,8 +2021,10 @@ class P2PAsyncHandle:
recv_next = None
out_bwd_wait_handles = None

def forward_handle_wait(self):
self.forward_handle_wait_fn()
def forward_handle_wait(self, recv_micro, send_micro):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P1 P2PAsyncHandle.forward_handle_wait / backward_handle_wait 新增了必填参数 recv_micro、send_micro,这会破坏现有的下游调用。

在 interleave 的 overlap 路径上(第 2682 行),p2p_async_handle 会交给模型的 overlapped_forward_backward。下游实现目前都是无参调用:

  • PaddleFleet:transformer_encoder.py
  • VHA:transformer_encoder.py、gpt_model.py

调用形式都是 p2p_async_handle.forward_handle_wait() 和 p2p_async_handle.backward_handle_wait()。合入后,开启 overlap_p2p_comm 并且模型实现了 overlapped_forward_backward 时,steady 阶段会直接抛 TypeError。

建议:

  • 两个方法的参数都改为可选,recv_micro=None, send_micro=None。
  • 参数缺省时不按 micro 标注,或者按 pipeline_event_hook.py 注释里提到的 role="OL" 标注(目前代码里没有任何地方发出这个 role)。
  • 补一个无参调用的用例。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

已修复:forward/backward handle wait 的 micro 参数均可省略,无参调用不会向旧 callback 传入额外参数。模型 overlap 路径等待顺序不变;没有 micro ID 时跳过该 wait 的埋点,避免下游 listener 收到无法归属的事件。补了无参调用回归测试。

修订提交:f12eedce2f。

_release_output(output_tensor)

# remaining backward steps
# remaining backward steps
self._pp_hook.emit(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 cooldown 的 phase 事件在 forward_only=True 时只有 begin,没有 end。

位置:

  • 第 3494 行的 PHASE_BEGIN 在 if not forward_only: 外面,配对的 PHASE_END(第 3623 行)却在分支里面。
  • PipelineParallelWithInterleaveFthenB 也一样:第 3961 行的 begin 在外,第 4014 行的 end 在内。

后果:

  • eval_batch 走 forward_only=True,listener 会收到一个没有闭合的 cooldown 区间。这违反了 pipeline_event_hook.py 里"区间不能只开不合"的约定。
  • begin 和 end 携带的 micro 也不一致,分别是 steady_steps 和 num_steps - 1。

建议:参照第 4535 行,用 with self._pp_hook.phase("cooldown", micro=...): 包住整段 cooldown。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

已修复:两种 interleave 的 cooldown 都在 if not forward_only 内使用 with self._pp_hook.phase(...),训练时成对且 payload 一致,eval 不发 cooldown。CPU 测试覆盖了两种调度的 train/eval。

修订提交:f12eedce2f。

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

已确认:当前 head 中两处 cooldown 都已改为 if not forward_only 内的 with self._pp_hook.phase(...),begin/end 载荷一致,eval 路径不再发出 cooldown;测试同时覆盖了两种调度的 train/eval。该问题已关闭。

# event vocabulary. Set up here rather than lazily because
# _use_batch_p2p_comm is only final at this point (the warning above can
# flip it) and listeners need it to resolve p2p lanes.
self._pp_hook = pp_ev.get_pipeline_event_hook()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 本 PR 删除了 pp_configs.profiling 的全部实现,但配置项还在,而且没有任何提示。

具体变化:

  • 删除了 _record_stamp、_flush_records 和 profiler_helper.py。
  • 删除了 forward_backward_pipeline(static_scheduler=...) 参数和 get_static_scheduler()。
  • paddle/fluid/framework/distributed_strategy.proto:87 的 profiling 字段仍然保留,但现在没有任何代码读取它。

影响:已经设置 profiling=True 的用户不会再得到 profile 记录,也收不到任何提示。显式传入 static_scheduler=True 的调用会直接报 TypeError。

建议:

  • profiling=True 时打印弃用告警,说明改用 pipeline_event_hook 的 listener。
  • 或者同步把该字段标记为弃用,并在 PR 描述里写明迁移方式。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

已补迁移提示:pp_configs.profiling=True 在初始化 PipelineParallel 时发出 FutureWarning,指向 pipeline_event_hook.get_pipeline_event_hook() 的 listener,并说明 get_static_scheduler() / static_scheduler 参数已移除。protobuf 字段保留以便读取旧配置。

修订提交:f12eedce2f。

listener(event, payload)

# ── regions ────────────────────────────────────────────────────────
def span(self, kind: str, **payload):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 新增的事件发布模块和 P2PReqs 都没有单测。

这个模块本身声明了一组约定:

  • begin 和 end 成对出现,payload 一致;
  • 异常路径上也会发出 end;
  • 没有 listener 时返回共享的 NULL_SPAN;
  • P2PReqs.roles 与 handle 列表逐个对齐。

这些约定一旦被后续改动破坏,只有在多卡 trace 里才能看出来。

建议:在 test/collective/fleet/test_pipeline_parallel_micro_step_hooks.py 里沿用 _FakeReq 的写法,补几个不需要 GPU 的用例:

  • span 的配对和 payload;
  • 异常路径上的 end 事件;
  • 无 listener 时返回 NULL_SPAN;
  • P2PReqs 交替调用 add_sends / add_recvs 后的顺序和 roles;
  • _wait_p2p 按 role 选取 micro。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

已在 test_pipeline_parallel_micro_step_hooks.py 新增 12 个 CPU 回归用例,覆盖 payload 配对、异常闭合、共享 NULL_SPAN、P2P 请求与 role 对齐、按 role 选 micro、不改变 wait 顺序及旧无参调用等。该文件 27 个用例均已通过;尚未运行多卡 GPU 测试。

修订提交:f12eedce2f。

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

已确认:新增用例覆盖 span 配对、异常路径闭合、共享 NULL_SPAN、P2PReqs.roles 对齐、按 role 选 micro 以及无参调用兼容;多卡 GPU 路径由 CI 覆盖即可。该问题已关闭。

+ '}'
)
def _wait_p2p(self, direction, reqs, recv_micro, send_micro):
"""等一次 p2p,**一个 handle 一个 span**,span 上标它是 send 还是 recv。

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 可维护性建议(约定偏离,不阻塞合入):本 PR 在 pipeline_parallel.py 和 p2p_communication.py 里新增了大量中文 docstring 和注释,比如这里的 _wait_p2p、P2PReqs、_p2p_span 前的注释块,以及各个 _wait_p2p 调用点的注释。这两个文件原本没有中文注释,同一 PR 新增的 pipeline_event_hook.py 也是全英文。建议统一改写成简短的英文,并把重复的理由只保留在 pipeline_event_hook.py 一处。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

已将新增的中文注释和 docstring 改为简短英文;为什么按 send/recv 分开记录的说明集中在 pipeline_event_hook.py。

修订提交:f12eedce2f。

return False


class PipelineEventHook:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 可维护性建议(依赖健康度,不阻塞合入):pipeline_parallel.py 里已经有公开的 PipelineParallelMicroStepCallback 和 register_global_pipeline_parallel_hook,提供 FORWARD_BEGIN/END、BACKWARD_BEGIN/END、P2P_ISSUED 这些位置。新的 PipelineEventHook 又另起了一套 listener 注册表和同名事件。建议二选一:

  • 在模块 docstring 里说明两者的分工,以及旧接口是否会弃用;
  • 或者让新机制复用已有的注册表。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

已在模块 docstring 中区分两者:原 micro-step callback 是控制接口,可参与张量计算,仍受支持;新 event hook 只发布调度元数据,供观测使用。

修订提交:f12eedce2f。

return _HOOK.span(SPAN_SUB, name=event, which=which, layer=layer)


def pipeline_event_mark(event, phase, which=None, layer=None) -> None:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 可维护性建议(抽象适配度,不阻塞合入):以下新增的公共成员在仓库里都没有调用方:

  • SPAN_KINDS
  • pipeline_event_span 和 pipeline_event_mark(后者已进入 __all__)
  • P2PReqs.sends / P2PReqs.recvs

其中 pipeline_event_mark 的 phase 参数只要不等于 "begin",就会被当成 end 处理,而且没有任何报错。建议先删掉这些没有使用者的成员,等真正有调用方时再加;如果要保留,至少给 phase 加上取值校验。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

已删除未使用的 SPAN_KINDS、pipeline_event_span、pipeline_event_mark 和 P2PReqs.sends / .recvs,保留与请求逐项对齐的 roles。

修订提交:f12eedce2f。

return_micro_batch_loss=False,
):
# use the 1f1b scheduling strategy.
# this strategy is inspired by:
# https://github.com/NVIDIA/Megatron-LM/blob/main/megatron/schedules.py

self._reset_user_hooks_status()
self._pp_hook.emit(pp_ev.STEP_BEGIN)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 可维护性建议(错误处理一致性,不阻塞合入):四个 pipeline 调度器的 step 边界都是用一对 emit(STEP_BEGIN) / emit(STEP_END) 手写的,比如这里和第 1445 行。只要中间抛出异常,STEP_END 就不会发出。NoPipelineParallel 和其他区间用的是 with self._pp_hook.step(),异常路径也能闭合。建议统一改成上下文管理器的写法。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

已把四个调度器的手写 STEP_BEGIN/END 替换为 with self._pp_hook.step(),异常路径也会发出 STEP_END。新增了调度异常的 CPU 回归测试。

修订提交:f12eedce2f。

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

已确认:四个调度器的 step 边界都已改为 with self._pp_hook.step(),异常路径由 _Span.__exit__ 补发 STEP_END,并有调度异常的 CPU 用例覆盖。该建议已关闭。

@codecov-commenter

codecov-commenter commented Nov 27, 2026 •

Copy link
Copy Markdown

Codecov Report

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

Files with missing lines Patch % Lines
.../fleet/meta_parallel/pp_utils/p2p_communication.py 45.57% 80 Missing ⚠️
...ributed/fleet/meta_parallel/pipeline_event_hook.py 94.05% 6 Missing ⚠️

❌ Your patch status has failed because the patch coverage (65.32%) is below the target coverage (90.00%). You can increase the patch coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##             develop   #80028   +/-   ##
==========================================
  Coverage           ?   65.32%           
==========================================
  Files              ?        2           
  Lines              ?      248           
  Branches           ?        0           
==========================================
  Hits               ?      162           
  Misses             ?       86           
  Partials           ?        0           

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

Preserve model-side P2P wait callbacks and omit waits with no scheduler micro ID. Pair step and cooldown boundaries, warn on the removed profiling path, and cover the event contract with CPU tests.

Co-Authored-By: AI Assistant <noreply@example.com>
@Hz188 Hz188 changed the title [PerfSim]Add profiler event code in pp [PerfSim]Add profiler event code in pp and remove useless pp static scheduler Dec 1, 2026
self.assertEqual(self.events, [])


class TestPipelineP2pWait(unittest.TestCase):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 可维护性建议(测试策略,不阻塞合入):新增用例覆盖了 span 配对、P2PReqs.roles 和 _wait_p2p,但 p2p_issue 事件还没有用例:_p2p_span 的 op / micro / is_async 载荷,以及 micro_step_id=None 时不发事件这一约定,目前只能靠读代码确认。建议沿用 _FakeReq 的写法补一个不需要 GPU 的用例,直接调用 p2p_communication 的一个方法(比如 recv_forward),断言收到的事件名、payload 和 None 时不发事件。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

已采纳(e5e970f071)。新增两个 CPU 用例,直接调用 P2pHelper.recv_forward,用假请求验证同步/异步的 p2p_issue_begin/end、op / micro / is_async payload,以及不传 micro_step_id 时仍正常 post、但不发事件。该测试文件的 30 个用例全部通过。

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

已确认。TestPipelineP2pIssue 覆盖了同步/异步的 p2p_issue_begin/end payload 与缺省 micro_step_id 时不发事件但正常 post,测试策略建议已解决。

assert forward_only, (
"compute_loss can only be set to False when forward_only is set to True"
)
with self._pp_hook.step():

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

💡 可维护性建议(设计一致性,不阻塞合入):with self._pp_hook.step(): 直接包住了 forward_backward_pipeline 的全部函数体,四个调度器各自整体缩进一级,本 PR 的 diff 因此膨胀到 3000 行以上,评审和后续 backport 都更难核对。建议保留 step 事件语义,但改用极薄的装饰器(内部 with self._pp_hook.step(): return fn(self, *args, **kwargs))套在四个 forward_backward_pipeline 上,避免重排缩进。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

已采纳(e5e970f071)。用薄装饰器 _with_pipeline_step 保留 step 事件和异常闭合,恢复四种调度主体原有缩进。Balanced-memory 的 eval 继续委托父类,只发一对 step 事件,已有 CPU 用例覆盖 train/eval 的异常路径。对比上一轮评审前,pipeline_parallel.py 的累计 diff 从 3,266 行降为 550 行(增删合计)。

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

已确认。_with_pipeline_step 保证了 step 事件与异常闭合,四种调度主体缩进恢复;balanced-memory 的 eval 委托父类只发一对 step 事件,设计一致性建议已解决。

Hz188 and others added 2 commits December 1, 2026 15:45
Trace scheduler calls with a thin decorator instead of reindenting the bodies. Stay on the parent trace path for balanced-memory eval. Test P2P issue payloads and unknown micro IDs with fake requests on CPU.

Co-Authored-By: AI Assistant <noreply@example.com>
Wrap the no-pipeline microbatch schedule with the same step decorator. Keep dataset preprocessing outside the span and cover event ordering on early failure.

Co-Authored-By: AI Assistant <noreply@example.com>
@Hz188

Hz188 commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

/re-run --all-failed

1 similar comment
@Hz188

Hz188 commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

/re-run --all-failed

Do not export scheduler instrumentation through __all__. The profiler can keep using the same explicit imports and event contract without introducing public Paddle APIs.

Co-Authored-By: AI Assistant <noreply@example.com>

This branch has not been deployed

No deployments
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