Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SOT] Collect BreakGraph Reason #71268

Merged
merged 10 commits into from
Feb 27, 2025

Conversation

DrRyanHuang
Copy link
Member

@DrRyanHuang DrRyanHuang commented Feb 25, 2025

PR Category

Execute Infrastructure

PR Types

Improvements

Description

Key Features

  • Implements BreakGraphReasonBase as the base class for all graph break reasons
  • Introduces specialized derived classes for different breaking scenarios
graph LR
    BREAK[BreakGraphReasonBase] ==> DATA[[DataDependencyBreak]]
    BREAK ==> UNSUPPORTED[[UnsupportedOperationBreak]]
    BREAK ==> SIDE[[SideEffectBreak]]
    BREAK --> INLINE[[InlineCallBreak]]
    BREAK --> DYGRAPH[[DygraphInconsistentWithStaticBreak]]
    BREAK --> PSDB[[PsdbBreakReason]]
    BREAK --> INFER[[InferMetaBreak]]
    BREAK --> UNSPECIFIED[[UnspecifiedBreakReason]]

    DATA ==> CONTROL_FLOW[DataDependencyControlFlowBreak]
    DATA ==> DYNAMIC_SHAPE[DataDependencyDynamicShapeBreak]
    DATA ==> OPERATION[DataDependencyOperationBreak]

    UNSUPPORTED ==> API[UnsupportedPaddleAPIBreak]
    UNSUPPORTED ==> BUILTIN[BuiltinFunctionBreak]

    SIDE ==> ITERATOR[UnsupportedIteratorBreak]

    style BREAK fill:#f9f9f9,stroke:#333,stroke-width:2px
    style DATA stroke:#0066cc
    style UNSUPPORTED stroke:#cc3300
    style CONTROL_FLOW stroke:#009973
    style DYNAMIC_SHAPE stroke:#009973
    style OPERATION stroke:#009973
    style API stroke:#cc3300
    style BUILTIN stroke:#cc3300

    classDef base fill:#e6f3ff,stroke:#004c99
    classDef data fill:#e6ffe6,stroke:#006600
    classDef unsupported fill:#ffe6e6,stroke:#660000
    class SIDE,ITERATOR base
    class DATA,CONTROL_FLOW,DYNAMIC_SHAPE,OPERATION data
    class UNSUPPORTED,API,BUILTIN unsupported
Loading

The demo code:

import paddle
import numpy as np

def fn(a):
    print(a)
    b = a + 1
    d = np.array([1, 2.0])
    e = b + d
    "%s" % e
    print(b)
    f = b + 1
    print(f)
    return f

static_fn = paddle.jit.to_static(fn, full_graph=False)
x = paddle.to_tensor([1.0, 2.0])
out = static_fn(x)
print(out)

Set SOT_COLLECT_INFO=breakgraph_reason:

CUDA_VISIBLE_DEVICES=2 PYTHONPATH=/workspace/Paddle/build/python MIN_GRAPH_SIZE=0 SOT_LOG_LEVEL=3 SOT_COLLECT_INFO=breakgraph_reason SOT_EXPORT=true python test_sot.py

The collected break graph information:

BreakGraphReasonInfo (breakgraph_reason):
BuiltinFunctionBreak (5):
        Not support builtin function: print with args: Args(TensorVariable)
        Not support builtin function: array with args: Args(ListVariable)
        Not support builtin function: __add__ with args: Args(TensorVariable, NumpyArrayVariable)
        Not support builtin function: print with args: Args(TensorVariable)
        Not support builtin function: print with args: Args(TensorVariable)
UnsupportedOperationBreak (1):
        Unsupported operator '__rmod__' between ConstantVariable and TensorVariable

PCard-66972

Copy link

paddle-bot bot commented Feb 25, 2025

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@paddle-bot paddle-bot bot added the contributor External developers label Feb 25, 2025
@SigureMo SigureMo requested a review from Copilot February 26, 2025 02:25
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

python/paddle/jit/sot/utils/exceptions.py:117

  • The condition 'if reason_str is not None' forces an override of any provided reason_str in BuiltinFunctionBreak, which may not be intended. Consider changing the check to 'if reason_str is None' so that a custom message can be preserved.
if reason_str is not None:

@SigureMo SigureMo requested a review from Copilot February 26, 2025 11:43
@DrRyanHuang DrRyanHuang changed the title [SOT] Add BreakGraph Reason [SOT] Collect BreakGraph Reason Feb 26, 2025

Choose a reason for hiding this comment

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

Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (1)

python/paddle/jit/sot/opcode_translator/executor/variable_dispatch.py:157

  • The error message for the operator registration using 'not in' still mentions 'variable in iterator', which can mislead users. Consider updating the message to reflect a 'not in' scenario (e.g., "Codes like: variable not in iterator.").
create_raise_break_graph_handler(UnsupportedIteratorBreak("Codes like: `variable in iterator`."))
Copy link
Member

@SigureMo SigureMo left a comment

Choose a reason for hiding this comment

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

我是不是来早了,好像还没改完?

SigureMo
SigureMo previously approved these changes Feb 27, 2025
Copy link
Member

@SigureMo SigureMo left a comment

Choose a reason for hiding this comment

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

LGTMeow 🐾


if isinstance(reason, str):
# if reason is a string, then create a UnspecifiedBreakReason object
reason = UnspecifiedBreakReason(reason)
Copy link
Member

Choose a reason for hiding this comment

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

这里还有多少是 UnspecifiedBreakReason?后面是不是不允许传入 str?

Copy link
Member Author

@DrRyanHuang DrRyanHuang Feb 27, 2025

Choose a reason for hiding this comment

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

目前代码里没有使用 UnspecifiedBreakReason 的部分,如果后续传入了str 做参数,则会被封装为 UnspecifiedBreakReason,目前先这样? 后面修改为不允许传入 str ,咱们严格一些吧?

Copy link
Member

@SigureMo SigureMo Feb 27, 2025

Choose a reason for hiding this comment

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

那是不是可以直接禁掉?assert isinstance(reason, Reason)

Copy link
Member Author

Choose a reason for hiding this comment

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

如果直接禁掉,那是否不再需要 UnspecifiedBreakReason 类了

Copy link
Member

Choose a reason for hiding this comment

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

@SigureMo SigureMo requested review from Copilot and removed request for Copilot February 27, 2025 06:46
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

PR Overview

This PR refactors and improves the handling of graph break reasons by introducing a dedicated base class (BreakGraphReasonBase) and specialized derived classes. It also standardizes error messaging across various modules and enhances the info collection mechanism via BreakGraphReasonInfo.

  • Introduces BreakGraphReasonBase and multiple specialized break reason classes to unify and enhance error reporting.
  • Updates error-triggering calls in the SOT infrastructure to use structured break reason objects.
  • Enhances the info collection/reporting mechanism via BreakGraphReasonInfo in the info collector.

Reviewed Changes

File Description
python/paddle/jit/sot/utils/exceptions.py Added BreakGraphReasonBase and its derived classes; refactored BreakGraphError to collect break reasons.
python/paddle/jit/sot/utils/info_collector.py Introduced BreakGraphReasonInfo to integrate with the info collection mechanism.
python/paddle/jit/sot/infer_meta.py Updated name generation logic for better clarity and efficiency.
python/paddle/jit/sot/opcode_translator/executor/variable_dispatch.py Changed error handling to use create_raise_break_graph_handler with specialized break reason classes.
...others Standardized exception wrapping and error messages across opcode translators and variable handling modules.

Copilot reviewed 12 out of 12 changed files in this pull request and generated 1 comment.

@SigureMo SigureMo changed the title [SOT] Collect BreakGraph Reason [SOT][3.13] Collect BreakGraph Reason Feb 27, 2025
@DrRyanHuang DrRyanHuang changed the title [SOT][3.13] Collect BreakGraph Reason [SOT] Collect BreakGraph Reason Feb 27, 2025
@DrRyanHuang DrRyanHuang requested a review from SigureMo February 27, 2025 12:04
Copy link
Member

@SigureMo SigureMo left a comment

Choose a reason for hiding this comment

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

LGTMeow 🐾

@SigureMo SigureMo merged commit 6800335 into PaddlePaddle:develop Feb 27, 2025
34 checks passed
@DrRyanHuang DrRyanHuang deleted the add_breakgraph_reason branch February 28, 2025 02:25
Enigmatisms pushed a commit to Enigmatisms/Paddle that referenced this pull request Mar 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor External developers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants