Skip to content

[SOT] Allow user specify a region to safe capture control flow#75548

Merged
SigureMo merged 6 commits intoPaddlePaddle:developfrom
cattidea:sot/allow-capture-control-flow-by-using-marker-api
Oct 14, 2025
Merged

[SOT] Allow user specify a region to safe capture control flow#75548
SigureMo merged 6 commits intoPaddlePaddle:developfrom
cattidea:sot/allow-capture-control-flow-by-using-marker-api

Conversation

@SigureMo
Copy link
Copy Markdown
Member

@SigureMo SigureMo commented Sep 26, 2025

PR Category

Execute Infrastructure

PR Types

Bug fixes

Description

允许用户标记局部函数以捕获控制流

@paddle.jit.marker.capture_control_flow # NOTE: fn must not be top level function
def fn(x):
    if x.sum() > 0:
        x += 1
    else:
        x -= 1
    return x

此时 fn 里的 Data Dependent Control Flow 不会再触发打断,因为整个函数已经通过 AST 转写,我们假定经过 AST 转写后的函数总是「动静统一」的

TODOs

  • graph size 计算没考虑过 control flow(加上之后 model benchmark 有问题,暂时先 revert 了)
  • 后续提供 with 形式,避免用户手动提取函数,当然前提是支持 with 语法的模拟

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Oct 13, 2025

Codecov Report

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

Additional details and impacted files
@@             Coverage Diff             @@
##             develop    #75548   +/-   ##
===========================================
  Coverage           ?   100.00%           
===========================================
  Files              ?         4           
  Lines              ?        33           
  Branches           ?         0           
===========================================
  Hits               ?        33           
  Misses             ?         0           
  Partials           ?         0           

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

Comment on lines +34 to +36
def fn_with_control_flow_explicit_capture(x):
x = inner_fn_with_control_flow_explicit_capture(x)
return x + 1
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.

这里要不要加一个 @check_no_breakgraph

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

translate_count 可以保证没有打断,或者说 translate_count 就是为了保证这一点的

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

translate_count 有更强的约束,还能保证确实捕获成了控制流,不会加 x 的 guard

@SigureMo SigureMo merged commit 903f7c7 into PaddlePaddle:develop Oct 14, 2025
89 of 91 checks passed
@SigureMo SigureMo deleted the sot/allow-capture-control-flow-by-using-marker-api branch October 14, 2025 11:52
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