-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
[Dy2Static] Add non-local for while and for. #43864
[Dy2Static] Add non-local for while and for. #43864
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
|
||
return loop_vars | ||
|
||
|
||
def _run_paddle_while_loop(cond, body, loop_vars): | ||
def _run_paddle_while_loop(cond, body, getter, setter): |
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.
def _run_paddle_while_loop(cond, body, getter, setter): | |
def _run_paddle_while(cond, body, getter, setter): |
def _run_py_while(cond, body, getter, setter): | ||
loop_vars = getter() | ||
while cond(): | ||
loop_vars = body() |
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.
这里不需要调用setter来同步body里的修改么?
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.
这个是不需要调用setter的。因为我们的body中的修改是non local的,那么他的修改就是原来的变量。只有的paddle的时候才需要修改。
body_new_vars = set([ | ||
var for var in _vars_with_store(if_vars_dict) | ||
if var not in parent_vars_dict | ||
if var not in parent_vars_dict and var != "__args" |
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 var not in parent_vars_dict and var != "__args" | |
if var not in parent_vars_dict and var != ARGS_NAME |
]) | ||
orelse_new_vars = set([ | ||
var for var in _vars_with_store(else_vars_dict) | ||
if var not in parent_vars_dict | ||
if var not in parent_vars_dict and var != "__args" |
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 var not in parent_vars_dict and var != "__args" | |
if var not in parent_vars_dict and var != ARGS_NAME |
@@ -39,10 +41,11 @@ | |||
FOR_BODY_PREFIX = 'for_loop_body' | |||
GENERATE_VARIABLE_PREFIX = 'generate_variable' | |||
|
|||
ATTRIBUTE_VARIABLE_PREFIX = '__attribute_variable' | |||
ARGS_NAME = '__args' |
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.
ifelse_transformer.py 里有一个ARGS_NAME,可以考虑复用下
PR types
Others
PR changes
Others
Describe
Pass the test_loop.py