Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wmsofts
Paddle
提交
eec10aab
P
Paddle
项目概览
wmsofts
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
eec10aab
编写于
3月 17, 2020
作者:
Z
Zhang Ting
提交者:
GitHub
3月 17, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
set op_device for loss_op_desc (#23027)
上级
9203aaf1
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
24 addition
and
2 deletion
+24
-2
python/paddle/fluid/backward.py
python/paddle/fluid/backward.py
+2
-0
python/paddle/fluid/optimizer.py
python/paddle/fluid/optimizer.py
+1
-2
python/paddle/fluid/tests/unittests/test_device_guard.py
python/paddle/fluid/tests/unittests/test_device_guard.py
+21
-0
未找到文件。
python/paddle/fluid/backward.py
浏览文件 @
eec10aab
...
...
@@ -295,6 +295,8 @@ def _create_loss_op_desc_(loss):
core
.
op_proto_and_checker_maker
.
kOpRoleAttrName
():
int
(
core
.
op_proto_and_checker_maker
.
OpRole
.
Backward
)
|
int
(
core
.
op_proto_and_checker_maker
.
OpRole
.
Loss
),
core
.
op_proto_and_checker_maker
.
kOpDeviceAttrName
():
loss
.
op
.
attr
(
core
.
op_proto_and_checker_maker
.
kOpDeviceAttrName
())
})
return
op_desc
...
...
python/paddle/fluid/optimizer.py
浏览文件 @
eec10aab
...
...
@@ -484,8 +484,7 @@ class Optimizer(object):
if
param_name
in
input_arg_names
:
self
.
_param_device_map
[
param_name
]
=
op
.
attr
(
device_attr_name
)
else
:
self
.
_param_device_map
[
param_name
]
=
None
break
def
_get_device_for_param
(
self
,
param_name
):
device
=
None
...
...
python/paddle/fluid/tests/unittests/test_device_guard.py
浏览文件 @
eec10aab
...
...
@@ -144,6 +144,27 @@ class TestDeviceGuard(unittest.TestCase):
for
op
in
all_ops
:
self
.
assertEqual
(
op
.
desc
.
attr
(
device_attr_name
),
"gpu"
)
def
test_loss_op_desc
(
self
):
main_program
=
fluid
.
Program
()
startup_program
=
fluid
.
Program
()
with
fluid
.
program_guard
(
main_program
,
startup_program
):
data1
=
fluid
.
layers
.
data
(
name
=
"data_1"
,
shape
=
[
2
],
dtype
=
"float32"
)
label
=
fluid
.
layers
.
data
(
name
=
"label"
,
shape
=
[
1
],
dtype
=
"int64"
)
fc1
=
fluid
.
layers
.
fc
(
input
=
data1
,
size
=
10
)
with
fluid
.
device_guard
(
"gpu"
):
out
=
fluid
.
layers
.
softmax_with_cross_entropy
(
logits
=
fc1
,
label
=
label
)
loss
=
fluid
.
layers
.
mean
(
out
)
opt
=
fluid
.
optimizer
.
SGDOptimizer
(
0.1
)
opt
.
minimize
(
loss
)
all_ops
=
main_program
.
global_block
().
ops
device_attr_name
=
core
.
op_proto_and_checker_maker
.
kOpDeviceAttrName
()
for
op
in
all_ops
:
self
.
assertEqual
(
True
,
op
.
desc
.
has_attr
(
device_attr_name
))
if
op
.
desc
==
'fill_constant'
:
self
.
assertEqual
(
op
.
desc
.
attr
(
device_attr_name
),
"gpu"
)
if
__name__
==
'__main__'
:
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录