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

[Dy2Stat]Enhance nonlocal mechanism while nonlocal vars is empty #43848

Merged
merged 1 commit into from
Jun 27, 2022

Conversation

Aurelius84
Copy link
Contributor

@Aurelius84 Aurelius84 commented Jun 27, 2022

PR types

Bug fixes

PR changes

Others

Describe

[Dy2Stat] Enhance nonlocal machanism while nonlocal vars is empty.

修复了当if-else的body函数中nonlocal names为空时,AST语法解析错误的问题,原始报错信息如下:

  File "/workspace/env3.7/lib/python3.7/site-packages/paddle/fluid/dygraph/dygraph_to_static/ifelse_transformer.py", line 60, in transform
    self.visit(self.root)
  File "/usr/lib/python3.7/ast.py", line 271, in visit
    return visitor(node)
  File "/usr/lib/python3.7/ast.py", line 326, in generic_visit
    value = self.visit(value)
  File "/usr/lib/python3.7/ast.py", line 271, in visit
    return visitor(node)
  File "/usr/lib/python3.7/ast.py", line 326, in generic_visit
    value = self.visit(value)
  File "/usr/lib/python3.7/ast.py", line 271, in visit
    return visitor(node)
  File "/workspace/env3.7/lib/python3.7/site-packages/paddle/fluid/dygraph/dygraph_to_static/ifelse_transformer.py", line 65, in visit_If
    node, self.root)
  File "/workspace/env3.7/lib/python3.7/site-packages/paddle/fluid/dygraph/dygraph_to_static/ifelse_transformer.py", line 527, in transform_if_else
    import pdb;pdb.set_trace()
  File "/workspace/env3.7/lib/python3.7/site-packages/paddle/fluid/dygraph/dygraph_to_static/variable_trans_func.py", line 85, in create_nonlocal_stmt_node
    return gast.parse(func_code).body[0]
  File "/workspace/env3.7/lib/python3.7/site-packages/paddle/utils/gast/gast.py", line 613, in parse
    return ast_to_gast(_ast.parse(*args, **kwargs))
  File "/usr/lib/python3.7/ast.py", line 35, in parse
    return compile(source, filename, mode, PyCF_ONLY_AST)
  File "<unknown>", line 1
    nonlocal
            ^
SyntaxError: invalid syntax

Copy link
Contributor

@0x45f 0x45f left a comment

Choose a reason for hiding this comment

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

LGTM

@Aurelius84 Aurelius84 changed the title [Dy2Stat]Enhance nonlocal machanism while nonlocal vars is empty [Dy2Stat]Enhance nonlocal mechanism while nonlocal vars is empty Jun 27, 2022
@Aurelius84 Aurelius84 merged commit 40a7731 into PaddlePaddle:develop Jun 27, 2022
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.

2 participants