Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
5067e3a8
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2299
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
5067e3a8
编写于
1月 20, 2021
作者:
A
Aurelius84
提交者:
GitHub
1月 20, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[Dy2Static]Enhance check of TracedLayers out vars (#30576)
上级
d1b25ed9
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
46 addition
and
24 deletion
+46
-24
python/paddle/fluid/dygraph/jit.py
python/paddle/fluid/dygraph/jit.py
+21
-21
python/paddle/fluid/tests/unittests/test_traced_layer_err_msg.py
...paddle/fluid/tests/unittests/test_traced_layer_err_msg.py
+25
-3
未找到文件。
python/paddle/fluid/dygraph/jit.py
浏览文件 @
5067e3a8
...
@@ -53,21 +53,21 @@ def create_program_from_desc(program_desc):
...
@@ -53,21 +53,21 @@ def create_program_from_desc(program_desc):
return
program
return
program
def
_extract_vars
(
inputs
,
result_list
):
def
_extract_vars
(
inputs
,
result_list
,
err_tag
=
'inputs'
):
if
isinstance
(
inputs
,
Variable
):
if
isinstance
(
inputs
,
Variable
):
result_list
.
append
(
inputs
)
result_list
.
append
(
inputs
)
elif
isinstance
(
inputs
,
(
list
,
tuple
)):
elif
isinstance
(
inputs
,
(
list
,
tuple
)):
for
var
in
inputs
:
for
var
in
inputs
:
_extract_vars
(
var
,
result_list
)
_extract_vars
(
var
,
result_list
,
err_tag
)
else
:
else
:
raise
TypeError
(
raise
TypeError
(
"The type of 'each element of
inputs
' in fluid.dygraph.jit.TracedLayer.trace must be fluid.Variable, but received {}."
.
"The type of 'each element of
{}
' in fluid.dygraph.jit.TracedLayer.trace must be fluid.Variable, but received {}."
.
format
(
type
(
inputs
)))
format
(
err_tag
,
type
(
inputs
)))
def
extract_vars
(
inputs
):
def
extract_vars
(
inputs
,
err_tag
=
'inputs'
):
result_list
=
[]
result_list
=
[]
_extract_vars
(
inputs
,
result_list
)
_extract_vars
(
inputs
,
result_list
,
err_tag
)
return
result_list
return
result_list
...
@@ -1032,7 +1032,7 @@ def _trace(layer,
...
@@ -1032,7 +1032,7 @@ def _trace(layer,
outputs
=
[
original_outputs
]
outputs
=
[
original_outputs
]
else
:
else
:
outputs
=
original_outputs
outputs
=
original_outputs
out_vars
=
[
var
for
var
in
outputs
]
out_vars
=
extract_vars
(
outputs
,
err_tag
=
'outputs'
)
program_desc
,
feed_names
,
fetch_names
,
parameters
=
tracer
.
create_program_desc
(
program_desc
,
feed_names
,
fetch_names
,
parameters
=
tracer
.
create_program_desc
(
var_list
,
feed_prefix
,
out_vars
,
fetch_prefix
,
tmp_prefix
)
var_list
,
feed_prefix
,
out_vars
,
fetch_prefix
,
tmp_prefix
)
...
...
python/paddle/fluid/tests/unittests/test_traced_layer_err_msg.py
浏览文件 @
5067e3a8
...
@@ -13,16 +13,18 @@
...
@@ -13,16 +13,18 @@
# limitations under the License.
# limitations under the License.
import
numpy
as
np
import
numpy
as
np
import
paddle
import
paddle.fluid
as
fluid
import
paddle.fluid
as
fluid
import
six
import
six
import
unittest
import
unittest
import
paddle.nn
as
nn
class
SimpleFCLayer
(
fluid
.
dygraph
.
Layer
):
class
SimpleFCLayer
(
nn
.
Layer
):
def
__init__
(
self
,
feature_size
,
batch_size
,
fc_size
):
def
__init__
(
self
,
feature_size
,
batch_size
,
fc_size
):
super
(
SimpleFCLayer
,
self
).
__init__
()
super
(
SimpleFCLayer
,
self
).
__init__
()
self
.
_linear
=
fluid
.
dygraph
.
Linear
(
feature_size
,
fc_size
)
self
.
_linear
=
nn
.
Linear
(
feature_size
,
fc_size
)
self
.
_offset
=
fluid
.
dygraph
.
to_variable
(
self
.
_offset
=
paddle
.
to_tensor
(
np
.
random
.
random
((
batch_size
,
fc_size
)).
astype
(
'float32'
))
np
.
random
.
random
((
batch_size
,
fc_size
)).
astype
(
'float32'
))
def
forward
(
self
,
x
):
def
forward
(
self
,
x
):
...
@@ -30,6 +32,17 @@ class SimpleFCLayer(fluid.dygraph.Layer):
...
@@ -30,6 +32,17 @@ class SimpleFCLayer(fluid.dygraph.Layer):
return
fc
+
self
.
_offset
return
fc
+
self
.
_offset
class
LinearNetWithNone
(
nn
.
Layer
):
def
__init__
(
self
,
feature_size
,
fc_size
):
super
(
LinearNetWithNone
,
self
).
__init__
()
self
.
_linear
=
nn
.
Linear
(
feature_size
,
fc_size
)
def
forward
(
self
,
x
):
fc
=
self
.
_linear
(
x
)
return
[
fc
,
[
None
,
2
]]
class
TestTracedLayerErrMsg
(
unittest
.
TestCase
):
class
TestTracedLayerErrMsg
(
unittest
.
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
self
.
batch_size
=
4
self
.
batch_size
=
4
...
@@ -152,5 +165,14 @@ class TestTracedLayerErrMsg(unittest.TestCase):
...
@@ -152,5 +165,14 @@ class TestTracedLayerErrMsg(unittest.TestCase):
return
layer
return
layer
class
TestOutVarWithNoneErrMsg
(
unittest
.
TestCase
):
def
test_linear_net_with_none
(
self
):
model
=
LinearNetWithNone
(
100
,
16
)
in_x
=
paddle
.
to_tensor
(
np
.
random
.
random
((
4
,
100
)).
astype
(
'float32'
))
with
self
.
assertRaises
(
TypeError
):
dygraph_out
,
traced_layer
=
fluid
.
dygraph
.
TracedLayer
.
trace
(
model
,
[
in_x
])
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
unittest
.
main
()
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录