Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
3f371db8
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
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看板
未验证
提交
3f371db8
编写于
3月 19, 2020
作者:
Z
Zhang Ting
提交者:
GitHub
3月 19, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add op_device attr for backward op_desc, test=develop (#23062)
上级
9ef7f6e8
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
10 addition
and
2 deletion
+10
-2
python/paddle/fluid/backward.py
python/paddle/fluid/backward.py
+3
-0
python/paddle/fluid/tests/unittests/test_device_guard.py
python/paddle/fluid/tests/unittests/test_device_guard.py
+7
-2
未找到文件。
python/paddle/fluid/backward.py
浏览文件 @
3f371db8
...
@@ -273,10 +273,13 @@ def _create_op_desc_(op_type, inputs, outputs, attrs):
...
@@ -273,10 +273,13 @@ def _create_op_desc_(op_type, inputs, outputs, attrs):
args
)))
args
)))
op_role_attr_name
=
core
.
op_proto_and_checker_maker
.
kOpRoleAttrName
()
op_role_attr_name
=
core
.
op_proto_and_checker_maker
.
kOpRoleAttrName
()
op_device_attr_name
=
core
.
op_proto_and_checker_maker
.
kOpDeviceAttrName
()
if
op_role_attr_name
not
in
attrs
:
if
op_role_attr_name
not
in
attrs
:
attrs
[
attrs
[
op_role_attr_name
]
=
core
.
op_proto_and_checker_maker
.
OpRole
.
Backward
op_role_attr_name
]
=
core
.
op_proto_and_checker_maker
.
OpRole
.
Backward
if
op_device_attr_name
not
in
attrs
:
attrs
[
op_device_attr_name
]
=
""
for
name
,
val
in
six
.
iteritems
(
attrs
):
for
name
,
val
in
six
.
iteritems
(
attrs
):
if
isinstance
(
val
,
framework
.
Block
):
if
isinstance
(
val
,
framework
.
Block
):
op_desc
.
set_block_attr
(
name
,
val
.
desc
)
op_desc
.
set_block_attr
(
name
,
val
.
desc
)
...
...
python/paddle/fluid/tests/unittests/test_device_guard.py
浏览文件 @
3f371db8
...
@@ -144,16 +144,19 @@ class TestDeviceGuard(unittest.TestCase):
...
@@ -144,16 +144,19 @@ class TestDeviceGuard(unittest.TestCase):
for
op
in
all_ops
:
for
op
in
all_ops
:
self
.
assertEqual
(
op
.
desc
.
attr
(
device_attr_name
),
"gpu"
)
self
.
assertEqual
(
op
.
desc
.
attr
(
device_attr_name
),
"gpu"
)
def
test_loss_op_desc
(
self
):
# check if op_descs have op_device attr
def
test_op_descs_device_attr
(
self
):
main_program
=
fluid
.
Program
()
main_program
=
fluid
.
Program
()
startup_program
=
fluid
.
Program
()
startup_program
=
fluid
.
Program
()
with
fluid
.
program_guard
(
main_program
,
startup_program
):
with
fluid
.
program_guard
(
main_program
,
startup_program
):
data1
=
fluid
.
layers
.
data
(
name
=
"data_1"
,
shape
=
[
2
],
dtype
=
"float32"
)
data1
=
fluid
.
layers
.
data
(
name
=
"data_1"
,
shape
=
[
2
],
dtype
=
"float32"
)
data2
=
fluid
.
layers
.
data
(
name
=
"data_2"
,
shape
=
[
2
],
dtype
=
"float32"
)
label
=
fluid
.
layers
.
data
(
name
=
"label"
,
shape
=
[
1
],
dtype
=
"int64"
)
label
=
fluid
.
layers
.
data
(
name
=
"label"
,
shape
=
[
1
],
dtype
=
"int64"
)
fc1
=
fluid
.
layers
.
fc
(
input
=
data1
,
size
=
10
)
fc1
=
fluid
.
layers
.
fc
(
input
=
data1
,
size
=
10
)
fc2
=
fluid
.
layers
.
fc
(
input
=
fc1
,
size
=
10
)
with
fluid
.
device_guard
(
"gpu"
):
with
fluid
.
device_guard
(
"gpu"
):
out
=
fluid
.
layers
.
softmax_with_cross_entropy
(
out
=
fluid
.
layers
.
softmax_with_cross_entropy
(
logits
=
fc1
,
label
=
label
)
logits
=
fc1
+
fc2
,
label
=
label
)
loss
=
fluid
.
layers
.
mean
(
out
)
loss
=
fluid
.
layers
.
mean
(
out
)
opt
=
fluid
.
optimizer
.
SGDOptimizer
(
0.1
)
opt
=
fluid
.
optimizer
.
SGDOptimizer
(
0.1
)
opt
.
minimize
(
loss
)
opt
.
minimize
(
loss
)
...
@@ -162,6 +165,8 @@ class TestDeviceGuard(unittest.TestCase):
...
@@ -162,6 +165,8 @@ class TestDeviceGuard(unittest.TestCase):
device_attr_name
=
core
.
op_proto_and_checker_maker
.
kOpDeviceAttrName
()
device_attr_name
=
core
.
op_proto_and_checker_maker
.
kOpDeviceAttrName
()
for
op
in
all_ops
:
for
op
in
all_ops
:
self
.
assertEqual
(
True
,
op
.
desc
.
has_attr
(
device_attr_name
))
self
.
assertEqual
(
True
,
op
.
desc
.
has_attr
(
device_attr_name
))
# fill_constant(backward op) is append to mean op, which should have
# the same op_device value as mean op
if
op
.
desc
==
'fill_constant'
:
if
op
.
desc
==
'fill_constant'
:
self
.
assertEqual
(
op
.
desc
.
attr
(
device_attr_name
),
"gpu"
)
self
.
assertEqual
(
op
.
desc
.
attr
(
device_attr_name
),
"gpu"
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录