CARVIEW |
Navigation Menu
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
[SOT] Move Internal Function to External Scope #71144
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提交成功,感谢你对开源项目的贡献! |
python/paddle/jit/sot/opcode_translator/executor/function_graph.py
Outdated
Show resolved
Hide resolved
python/paddle/jit/sot/opcode_translator/executor/function_graph.py
Outdated
Show resolved
Hide resolved
if self.is_graph_output(var): | ||
return [var] | ||
else: | ||
retval = [] | ||
for inp in var.tracker.inputs: | ||
retval.extend(self.collect_related_dummy_tensor(inp)) | ||
return retval |
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.
if self.is_graph_output(var): | |
return [var] | |
else: | |
retval = [] | |
for inp in var.tracker.inputs: | |
retval.extend(self.collect_related_dummy_tensor(inp)) | |
return retval | |
if self.is_graph_output(var): | |
return [var] | |
retval = [] | |
for inp in var.tracker.inputs: | |
retval.extend(self.collect_related_dummy_tensor(inp)) | |
return retval |
在有 early return 的情况下不需要写 else 分支,可以大幅减少缩进
以下是一些常见 pattern:
if cond:
short_branch_stmts
return
else:
long_branch_stmts
return
# ->
if cond:
short_branch_stmts
return
long_branch_stmts
return
# ---
if cond:
long_branch_stmts
return
else:
short_branch_stmts
return
# ->
if not cond:
short_branch_stmts
return
long_branch_stmts
return
# ---
while cond1:
if cond2:
short_branch_stmts
else:
long_branch_stmts
# ->
while cond1:
if cond2:
short_branch_stmts
continue
long_branch_stmts
这个函数看起来可以应用两次这个 rule
python/paddle/jit/sot/opcode_translator/executor/function_graph.py
Outdated
Show resolved
Hide resolved
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.
PR Category
Execute Infrastructure
PR Types
Improvements
Description
Move the internally defined function
is_graph_output
&collect_related_dummy_tensor
to external scope for better organization and reusability.PCard-66972