Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
f3ea6156
P
Paddle
项目概览
机器未来
/
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看板
未验证
提交
f3ea6156
编写于
8月 19, 2020
作者:
L
liym27
提交者:
GitHub
8月 19, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Dy2Stat] Fix bug: unwrap func in dy2Stat. (#26279)
上级
1fbee267
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
41 addition
and
29 deletion
+41
-29
python/paddle/fluid/dygraph/dygraph_to_static/origin_info.py
python/paddle/fluid/dygraph/dygraph_to_static/origin_info.py
+1
-13
python/paddle/fluid/dygraph/dygraph_to_static/program_translator.py
...dle/fluid/dygraph/dygraph_to_static/program_translator.py
+24
-16
python/paddle/fluid/dygraph/dygraph_to_static/utils.py
python/paddle/fluid/dygraph/dygraph_to_static/utils.py
+16
-0
未找到文件。
python/paddle/fluid/dygraph/dygraph_to_static/origin_info.py
浏览文件 @
f3ea6156
...
...
@@ -18,8 +18,8 @@ import collections
import
inspect
import
gast
from
paddle.fluid
import
core
from
paddle.fluid.dygraph.dygraph_to_static.utils
import
unwrap
from
paddle.fluid.framework
import
Program
# NOTE(liym27): Please use `getattr(ast_node, ORIGI_INFO)` instead of . operation to get the original information of ast node.
...
...
@@ -197,18 +197,6 @@ def attach_origin_info(ast_node, func):
return
ast_node
# NOTE: inspect.unwrap() exits in PY3 but not in PY2.
def
unwrap
(
func
):
def
_is_wrapped
(
f
):
return
hasattr
(
f
,
'__wrapped__'
)
unwrapped_f
=
func
while
(
_is_wrapped
(
unwrapped_f
)):
unwrapped_f
=
unwrapped_f
.
__wrapped__
return
unwrapped_f
def
ast_walk
(
transformed_node
,
static_node
):
"""
Recursively yield all descendant nodes in the trees starting at transformed_node and static_node (including itself) in parallel.
...
...
python/paddle/fluid/dygraph/dygraph_to_static/program_translator.py
浏览文件 @
f3ea6156
...
...
@@ -13,32 +13,38 @@
# limitations under the License.
from
__future__
import
print_function
import
gast
import
collections
import
inspect
import
warnings
import
textwrap
import
threading
import
collections
import
warnings
import
gast
import
numpy
as
np
from
paddle.fluid
import
core
,
scope_guard
from
paddle.fluid
import
framework
from
paddle.fluid
import
core
from
paddle.fluid
import
executor
from
paddle.fluid
import
framework
from
paddle.fluid
import
scope_guard
from
paddle.fluid
import
unique_name
from
paddle.fluid.data_feeder
import
check_type
from
paddle.fluid.dygraph
import
layers
from
paddle.fluid.layers.utils
import
flatten
from
paddle.fluid.layers.utils
import
pack_sequence_as
from
paddle.fluid.dygraph.base
import
param_guard
from
paddle.fluid.dygraph.base
import
switch_to_static_graph
from
paddle.fluid.dygraph.dygraph_to_static.ast_transformer
import
DygraphToStaticAst
from
paddle.fluid.dygraph.dygraph_to_static.error
import
ERROR_DATA
from
paddle.fluid.dygraph.dygraph_to_static.error
import
attach_error_data
from
paddle.fluid.dygraph.dygraph_to_static.origin_info
import
attach_origin_info
from
paddle.fluid.dygraph.dygraph_to_static.origin_info
import
create_and_update_origin_info_map
from
paddle.fluid.dygraph.dygraph_to_static.origin_info
import
update_op_callstack_with_origin_info
from
paddle.fluid.dygraph.dygraph_to_static.partial_program
import
partial_program_from
from
paddle.fluid.dygraph.dygraph_to_static.utils
import
ast_to_func
from
paddle.fluid.dygraph.dygraph_to_static.utils
import
ast_to_source_code
from
paddle.fluid.dygraph.dygraph_to_static.utils
import
func_to_source_code
from
paddle.fluid.dygraph.dygraph_to_static.utils
import
ast_to_func
from
paddle.fluid.dygraph.dygraph_to_static.utils
import
unwrap
from
paddle.fluid.layers.utils
import
flatten
from
paddle.fluid.layers.utils
import
pack_sequence_as
from
paddle.fluid.wrapped_decorator
import
signature_safe_contextmanager
from
paddle.fluid.dygraph.base
import
param_guard
from
paddle.fluid.data_feeder
import
check_type
from
paddle.fluid.dygraph.dygraph_to_static.partial_program
import
partial_program_from
from
paddle.fluid.dygraph.dygraph_to_static.origin_info
import
attach_origin_info
,
create_and_update_origin_info_map
from
paddle.fluid.dygraph.dygraph_to_static.origin_info
import
update_op_callstack_with_origin_info
from
paddle.fluid.dygraph.dygraph_to_static.error
import
attach_error_data
,
ERROR_DATA
__all__
=
[
'ProgramTranslator'
,
'convert_to_static'
]
...
...
@@ -89,7 +95,7 @@ class FunctionCache(object):
"""
# Note: In Python2, it will raise OSError when inspect function
# with decorator directly and function.__wrapped__ holds the actual function.
func
=
getattr
(
func
,
'__wrapped__'
,
func
)
func
=
unwrap
(
func
)
source_code
=
func_to_source_code
(
func
)
# TODO(liym27):
...
...
@@ -669,7 +675,9 @@ class ProgramTranslator(object):
dygraph_func
),
"Input dygraph_func is not a callable in ProgramTranslator.get_code"
# Gets AST from dygraph function
raw_code
=
inspect
.
getsource
(
dygraph_func
)
unwrap_func
=
unwrap
(
dygraph_func
)
raw_code
=
inspect
.
getsource
(
unwrap_func
)
code
=
textwrap
.
dedent
(
raw_code
)
root
=
gast
.
parse
(
code
)
...
...
python/paddle/fluid/dygraph/dygraph_to_static/utils.py
浏览文件 @
f3ea6156
...
...
@@ -1052,3 +1052,19 @@ class SplitAssignTransformer(gast.NodeTransformer):
value_node
=
target
return
new_nodes
# NOTE: inspect.unwrap() exits in PY3 but not in PY2.
def
unwrap
(
func
):
"""
Returns the object wrapped by decorators.
"""
def
_is_wrapped
(
f
):
return
hasattr
(
f
,
'__wrapped__'
)
unwrapped_f
=
func
while
(
_is_wrapped
(
unwrapped_f
)):
unwrapped_f
=
unwrapped_f
.
__wrapped__
return
unwrapped_f
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录