Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
74c50240
P
Paddle
项目概览
Crayon鑫
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
74c50240
编写于
9月 21, 2022
作者:
F
feifei-111
提交者:
GitHub
9月 21, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[BugFix] fixed a bug that deco_name can't be parsed corrected (#46297)
* use re replace judge by case * simplify re
上级
7d27520a
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
20 addition
and
11 deletion
+20
-11
python/paddle/fluid/dygraph/dygraph_to_static/decorator_transformer.py
.../fluid/dygraph/dygraph_to_static/decorator_transformer.py
+17
-11
python/paddle/fluid/dygraph/dygraph_to_static/utils.py
python/paddle/fluid/dygraph/dygraph_to_static/utils.py
+3
-0
未找到文件。
python/paddle/fluid/dygraph/dygraph_to_static/decorator_transformer.py
浏览文件 @
74c50240
...
@@ -22,6 +22,7 @@ from paddle.fluid.dygraph.dygraph_to_static.utils import create_funcDef_node, as
...
@@ -22,6 +22,7 @@ from paddle.fluid.dygraph.dygraph_to_static.utils import create_funcDef_node, as
import
warnings
import
warnings
import
re
import
re
from
paddle.fluid.dygraph.dygraph_to_static.utils
import
RE_PYNAME
,
RE_PYMODULE
IGNORE_NAMES
=
[
IGNORE_NAMES
=
[
'declarative'
,
'to_static'
,
'dygraph_to_static_func'
,
'wraps'
,
'declarative'
,
'to_static'
,
'dygraph_to_static_func'
,
'wraps'
,
...
@@ -65,17 +66,23 @@ class DecoratorTransformer(BaseTransformer):
...
@@ -65,17 +66,23 @@ class DecoratorTransformer(BaseTransformer):
for
deco
in
reversed
(
deco_list
):
for
deco
in
reversed
(
deco_list
):
# skip INGNORE_NAMES
# skip INGNORE_NAMES
if
isinstance
(
deco
,
gast
.
Attribute
):
deco_full_name
=
ast_to_source_code
(
deco
).
strip
()
deco_name
=
deco
.
attr
if
isinstance
(
deco
,
gast
.
Call
):
elif
isinstance
(
deco
,
gast
.
Call
)
:
# match case like
:
if
hasattr
(
deco
.
func
,
'args'
):
# 1: @_jst.Call(a.b.c.d.deco)()
deco_name
=
deco
.
func
.
args
[
0
].
id
# 2: @q.w.e.r.deco()
elif
hasattr
(
deco
.
func
,
'attr'
):
re_tmp
=
re
.
match
(
deco_name
=
deco
.
func
.
attr
r
'({module})*({name}\(){{0,1}}({module})*({name})(\)){{0,1}}\(.*$'
else
:
.
format
(
name
=
RE_PYNAME
,
module
=
RE_PYMODULE
),
deco_full_name
)
deco_name
=
deco
.
func
.
id
deco_name
=
re_tmp
.
group
(
4
)
else
:
else
:
deco_name
=
deco
.
id
# match case like:
# @a.d.g.deco
re_tmp
=
re
.
match
(
r
'({module})*({name})$'
.
format
(
name
=
RE_PYNAME
,
module
=
RE_PYMODULE
),
deco_full_name
)
deco_name
=
re_tmp
.
group
(
2
)
if
deco_name
in
IGNORE_NAMES
:
if
deco_name
in
IGNORE_NAMES
:
continue
continue
elif
deco_name
==
'contextmanager'
:
elif
deco_name
==
'contextmanager'
:
...
@@ -83,7 +90,6 @@ class DecoratorTransformer(BaseTransformer):
...
@@ -83,7 +90,6 @@ class DecoratorTransformer(BaseTransformer):
"Dy2Static : A context manager decorator is used, this may not work correctly after transform."
"Dy2Static : A context manager decorator is used, this may not work correctly after transform."
)
)
deco_full_name
=
ast_to_source_code
(
deco
).
strip
()
decoed_func
=
'_decoedby_'
+
deco_name
decoed_func
=
'_decoedby_'
+
deco_name
# get function after decoration
# get function after decoration
...
...
python/paddle/fluid/dygraph/dygraph_to_static/utils.py
浏览文件 @
74c50240
...
@@ -93,6 +93,9 @@ FOR_ITER_VAR_LEN_PREFIX = '__for_loop_var_len'
...
@@ -93,6 +93,9 @@ FOR_ITER_VAR_LEN_PREFIX = '__for_loop_var_len'
FOR_ITER_VAR_NAME_PREFIX
=
'__for_loop_iter_var'
FOR_ITER_VAR_NAME_PREFIX
=
'__for_loop_iter_var'
FOR_ITER_ZIP_TO_LIST_PREFIX
=
'__for_loop_iter_zip'
FOR_ITER_ZIP_TO_LIST_PREFIX
=
'__for_loop_iter_zip'
RE_PYNAME
=
'[a-zA-Z0-9_]+'
RE_PYMODULE
=
'[a-zA-Z0-9_]+\.'
# FullArgSpec is valid from Python3. Defined a Namedtuple to
# FullArgSpec is valid from Python3. Defined a Namedtuple to
# to make it available in Python2.
# to make it available in Python2.
FullArgSpec
=
collections
.
namedtuple
(
'FullArgSpec'
,
[
FullArgSpec
=
collections
.
namedtuple
(
'FullArgSpec'
,
[
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录