CARVIEW |
Navigation Menu
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
[SOT][Faster Guard] implement basic guard tree mechanism #70154
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
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
Sorry to inform you that e54a6b3's CIs have passed for more than 7 days. To prevent PR conflicts, you need to re-run all CIs manually. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 5 out of 10 changed files in this pull request and generated no comments.
Files not reviewed (5)
- paddle/fluid/pybind/jit.cc: Language not supported
- paddle/fluid/pybind/sot/guards.cc: Language not supported
- paddle/fluid/pybind/sot/guards.h: Language not supported
- python/paddle/jit/sot/opcode_translator/executor/tracker.py: Evaluated as low risk
- python/paddle/jit/sot/opcode_translator/executor/variables/base.py: Evaluated as low risk
Comments suppressed due to low confidence (3)
python/paddle/jit/sot/opcode_translator/executor/executor_cache.py:135
- [nitpick] The function name 'analyse_guard_global_object' is ambiguous. Consider renaming it to 'analyze_global_objects_in_guard' for clarity.
def analyse_guard_global_object(self, guard_fn):
python/paddle/jit/sot/opcode_translator/executor/variables/basic.py:456
- [nitpick] The method name 'make_faster_guard' is ambiguous. It should be renamed to something more descriptive, such as 'create_faster_guard_nodes'.
def make_faster_guard(self) -> list[paddle.framework.core.GuardNode]:
python/paddle/jit/sot/opcode_translator/executor/variables/basic.py:457
- The error message 'Only support PIR' is unclear. It should be more descriptive, such as 'PIR API must be enabled to use faster guard nodes.'
assert paddle.framework.use_pir_api(), "Only support PIR"
89caff2
to
5a86b32
Compare
Sorry to inform you that 5a86b32's CIs have passed for more than 7 days. To prevent PR conflicts, you need to re-run all CIs manually. |
a551d2e
to
49a5ad1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements the basic guard tree mechanism to improve performance in guard checks by introducing faster guard support. Key changes include:
- New APIs for creating and checking faster guard trees (e.g. make_faster_guard).
- Extensions to tracker, executor, and variable modules to support guard tree expressions.
- Updates to integrate the faster guard mechanism into the function graph and executor cache.
Reviewed Changes
Copilot reviewed 8 out of 11 changed files in this pull request and generated 4 comments.
Show a summary per file
File | Description |
---|---|
test/sot/test_guard_tree.py | Added tests for the guard tree mechanism with a callback that verifies guard results. |
python/paddle/jit/sot/opcode_translator/executor/guard.py | Introduced make_faster_guard and updated guard checks. |
python/paddle/jit/sot/opcode_translator/executor/executor_cache.py | Modified cache lookup logic based on ENV_SOT_ENABLE_GUARD_TREE. |
python/paddle/jit/sot/opcode_translator/executor/tracker.py | Added guard_tree_expr_node implementations for various trackers and marked several expression nodes as TODO. |
python/paddle/jit/sot/opcode_translator/executor/function_graph.py | Updated guard_fn property to use faster guard nodes when enabled. |
python/paddle/jit/sot/opcode_translator/executor/variables/basic.py | Added a check_faster_guard-decorated implementation of make_faster_guard. |
python/paddle/jit/sot/opcode_translator/executor/opcode_inline_executor.py | Provided guard_tree_expr_node implementations and noted TODO for FunctionClosureExprNode. |
python/paddle/jit/sot/opcode_translator/executor/variables/base.py | Extended variable base with a faster guard method decorated for consistency. |
Files not reviewed (3)
- paddle/fluid/pybind/jit.cc: Language not supported
- paddle/fluid/pybind/sot/guards.cc: Language not supported
- paddle/fluid/pybind/sot/guards.h: Language not supported
Comments suppressed due to low confidence (1)
python/paddle/jit/sot/opcode_translator/executor/executor_cache.py:161
- [nitpick] The conditional check on ENV_SOT_ENABLE_GUARD_TREE may lead to confusion given the accompanying TODO. It is recommended to refactor this logic into a clearer structure once faster guard tree support for error analysis is complete.
elif not ENV_SOT_ENABLE_GUARD_TREE.get():
# TODO(zrr1999): implement BinaryExprNode | ||
raise NotImplementedError("BinaryExprNode is not implemented") | ||
# left_expr = self.operands[0].tracker.guard_tree_expr_node() | ||
# right_expr = self.operands[1].tracker.guard_tree_expr_node() | ||
# return paddle.framework.core.BinaryExprNode( | ||
# left_expr, | ||
# right_expr, | ||
# self.get_operator_symbol(), | ||
# ) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BinaryExprNode is not implemented, which will cause runtime errors for binary operations. Implement BinaryExprNode or provide an alternative to handle binary operators.
# TODO(zrr1999): implement BinaryExprNode | |
raise NotImplementedError("BinaryExprNode is not implemented") | |
# left_expr = self.operands[0].tracker.guard_tree_expr_node() | |
# right_expr = self.operands[1].tracker.guard_tree_expr_node() | |
# return paddle.framework.core.BinaryExprNode( | |
# left_expr, | |
# right_expr, | |
# self.get_operator_symbol(), | |
# ) | |
left_expr = self.operands[0].tracker.guard_tree_expr_node() | |
right_expr = self.operands[1].tracker.guard_tree_expr_node() | |
return paddle.framework.core.BinaryExprNode( | |
left_expr, | |
right_expr, | |
self.get_operator_symbol(), | |
) |
Copilot uses AI. Check for mistakes.
# TODO(zrr1999): implement IterExprNode | ||
raise NotImplementedError("IterExprNode is not implemented") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IterExprNode is not implemented. Ensure that this is implemented before iterators in the guard tree are used to prevent unexpected runtime errors.
# TODO(zrr1999): implement IterExprNode | |
raise NotImplementedError("IterExprNode is not implemented") | |
return IterExprNode(self.iter_source.guard_tree_expr_node()) |
Copilot uses AI. Check for mistakes.
# TODO(zrr1999): implement LayerExprNode | ||
raise NotImplementedError("LayerExprNode is not implemented") | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LayerExprNode is not implemented, which may lead to runtime errors when processing layer attributes. It is recommended to implement LayerExprNode to properly support layer tracing.
# TODO(zrr1999): implement LayerExprNode | |
raise NotImplementedError("LayerExprNode is not implemented") | |
class LayerExprNode(paddle.framework.core.ExprNode): | |
def __init__(self, layer_class, args, kwargs): | |
super().__init__() | |
self.layer_class = layer_class | |
self.args = args | |
self.kwargs = kwargs | |
def __repr__(self): | |
return f"LayerExprNode(layer_class={self.layer_class}, args={self.args}, kwargs={self.kwargs})" | |
return LayerExprNode(self.layer_class, self.args, self.kwargs) |
Copilot uses AI. Check for mistakes.
and more guard_tree_expr_node
@@ -123,6 +125,81 @@ void BindGuard(pybind11::module *m) { | |||
#endif | |||
} | |||
|
|||
void BindGuardTree(pybind11::module *m) { | |||
#if SOT_IS_SUPPORTED |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个 SOT_IS_SUPPORTED
应该要包住整个 BindGuardTree
函数吧
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return PyDict_GetItemString(frame->frame->f_locals, var_name_.c_str()); | ||
#else | ||
return PyDict_GetItemString(frame->f_locals, var_name_.c_str()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
如果比较多的话,可以后续考虑加一个宏 PyFrameProxy_GET_FRAME
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
目前看起来应该只有这两个
…e#70154) * add GuardTree * add guard_tree_expr_node * add make_faster_guard and more guard_tree_expr_node * add test * format * support 3.11- * fix
PR Category
Execute Infrastructure
PR Types
Performance
Description
实现了基本的 guard tree 机制,GuardTree 目前是list[list[node]],没有实现树结构
目前实现的节点:
下面的行为是后续的计划,目前还没有实现
ENV_SOT_ENABLE_STRICT_GUARD_CHECK 记做 S, ENV_SOT_ENABLE_GUARD_TREE 记做C1,ENV_SOT_ENABLE_FASTER_GUARD 记做C2