Skip to content

Avoid duplicate history checks in Python stack capture - #79650

Open
Difers wants to merge 1 commit into
PaddlePaddle:developfrom
Difers:fix_alloc_profile
Open

Avoid duplicate history checks in Python stack capture#79650
Difers wants to merge 1 commit into
PaddlePaddle:developfrom
Difers:fix_alloc_profile

Conversation

@Difers

@Difers Difers commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

PR Category

Performance Optimization

PR Types

Performance

Description

优化 memory history Python stack capture 的运行时开销。

当 memory history 关闭时,CaptureCurrentPyStack() 与 MemStackGuard 原本会重复检查 MemHistoryEnabled()。本次修改引入 MemStackCapture 状态快照,由 stack capture 一次性返回 recorder 是否启用及 stack_id,MemStackGuard 复用该状态,避免重复检查。

同时统一更新 eager op、legacy eager op 及 PyLayer 前向/反向调用点,并保留以下语义:

  • recorder 关闭时仅执行一次状态检查并快速返回;
  • recorder 开启但 Python stack capture 关闭时,仍然压入 stack_id = 0,避免错误继承外层 stack;
  • guard 生命周期内 recorder 开关变化时,仍能保证 push/pop 平衡;
  • 补充 MemStackGuard 关闭态、嵌套调用及运行时切换场景测试。

是否引起精度变化

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.

1 participant