Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
da10c5cf
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看板
未验证
提交
da10c5cf
编写于
3月 16, 2021
作者:
R
ronnywang
提交者:
GitHub
3月 16, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[ROCM] fix softmax_with_cross_entropy_op, test=develop (#31629)
上级
75433126
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
18 addition
and
23 deletion
+18
-23
paddle/fluid/operators/softmax_with_cross_entropy_op.cu
paddle/fluid/operators/softmax_with_cross_entropy_op.cu
+4
-9
python/paddle/fluid/tests/unittests/test_softmax_with_cross_entropy_op.py
...uid/tests/unittests/test_softmax_with_cross_entropy_op.py
+14
-14
未找到文件。
paddle/fluid/operators/softmax_with_cross_entropy_op.cu
浏览文件 @
da10c5cf
...
@@ -452,12 +452,7 @@ struct HardLabelCrossEntropyFunctorWithIgnoreIdx {
...
@@ -452,12 +452,7 @@ struct HardLabelCrossEntropyFunctorWithIgnoreIdx {
// labels, loss view as [n, remain]
// labels, loss view as [n, remain]
int
idx_lbl
=
idx_n
*
remain
+
idx_remain
;
int
idx_lbl
=
idx_n
*
remain
+
idx_remain
;
if
(
idx_axis
==
ignore_idx_
)
{
if
(
idx_axis
==
labels_
[
idx_lbl
]
&&
idx_axis
!=
ignore_idx_
)
{
loss_
[
idx_lbl
]
=
0
;
return
;
}
if
(
idx_axis
==
labels_
[
idx_lbl
])
{
loss_
[
idx_lbl
]
=
-
log_on_device
(
logits_data_
[
idx
]);
loss_
[
idx_lbl
]
=
-
log_on_device
(
logits_data_
[
idx
]);
}
}
}
}
...
@@ -732,7 +727,7 @@ static void SoftmaxWithCrossEntropyFusedKernel(
...
@@ -732,7 +727,7 @@ static void SoftmaxWithCrossEntropyFusedKernel(
template
<
typename
T
>
template
<
typename
T
>
static
void
CrossEntropyFusedKernel
(
const
T
*
logits_data
,
const
T
*
labels_data
,
static
void
CrossEntropyFusedKernel
(
const
T
*
logits_data
,
const
T
*
labels_data
,
T
*
loss_data
,
int
n
,
int
d
,
int
axis_dim
,
T
*
loss_data
,
int
n
,
int
d
,
int
axis_dim
,
cuda
Stream_t
stream
)
{
gpu
Stream_t
stream
)
{
constexpr
int
kMaxBlockDim
=
512
;
constexpr
int
kMaxBlockDim
=
512
;
int
block_dim
=
axis_dim
>=
kMaxBlockDim
int
block_dim
=
axis_dim
>=
kMaxBlockDim
?
kMaxBlockDim
?
kMaxBlockDim
...
@@ -792,11 +787,11 @@ class SoftmaxWithCrossEntropyCUDAKernel : public framework::OpKernel<T> {
...
@@ -792,11 +787,11 @@ class SoftmaxWithCrossEntropyCUDAKernel : public framework::OpKernel<T> {
auto
*
softmax_out_data
=
softmax_out
->
mutable_data
<
T
>
(
context
.
GetPlace
());
auto
*
softmax_out_data
=
softmax_out
->
mutable_data
<
T
>
(
context
.
GetPlace
());
auto
*
loss_data
=
loss
->
mutable_data
<
T
>
(
context
.
GetPlace
());
auto
*
loss_data
=
loss
->
mutable_data
<
T
>
(
context
.
GetPlace
());
math
::
SetConstant
<
platform
::
CUDADeviceContext
,
T
>
set_constant
;
set_constant
(
context
.
cuda_device_context
(),
loss
,
static_cast
<
T
>
(
0
));
if
(
axis_dim
==
1
)
{
if
(
axis_dim
==
1
)
{
math
::
SetConstant
<
platform
::
CUDADeviceContext
,
T
>
set_constant
;
set_constant
(
context
.
cuda_device_context
(),
softmax_out
,
set_constant
(
context
.
cuda_device_context
(),
softmax_out
,
static_cast
<
T
>
(
1
));
static_cast
<
T
>
(
1
));
set_constant
(
context
.
cuda_device_context
(),
loss
,
static_cast
<
T
>
(
0
));
return
;
return
;
}
}
...
...
python/paddle/fluid/tests/unittests/test_softmax_with_cross_entropy_op.py
浏览文件 @
da10c5cf
...
@@ -116,7 +116,7 @@ class TestSoftmaxWithCrossEntropyOp_NotWithSoftmax_SoftLabel_1D(
...
@@ -116,7 +116,7 @@ class TestSoftmaxWithCrossEntropyOp_NotWithSoftmax_SoftLabel_1D(
self
.
shape
=
[
13
,
8
]
self
.
shape
=
[
13
,
8
]
self
.
axis
=
-
1
self
.
axis
=
-
1
self
.
ignore_index
=
-
1
self
.
ignore_index
=
-
1
self
.
dtype
=
np
.
float64
self
.
dtype
=
np
.
float
32
if
core
.
is_compiled_with_rocm
()
else
np
.
float
64
self
.
softmax_switch
=
False
#default is true, means "with softmax"
self
.
softmax_switch
=
False
#default is true, means "with softmax"
...
@@ -129,7 +129,7 @@ class TestSoftmaxWithCrossEntropyOp_NotWithSoftmax_HardLabel_1D(
...
@@ -129,7 +129,7 @@ class TestSoftmaxWithCrossEntropyOp_NotWithSoftmax_HardLabel_1D(
self
.
shape
=
[
13
,
8
]
self
.
shape
=
[
13
,
8
]
self
.
axis
=
-
1
self
.
axis
=
-
1
self
.
ignore_index
=
-
1
self
.
ignore_index
=
-
1
self
.
dtype
=
np
.
float64
self
.
dtype
=
np
.
float
32
if
core
.
is_compiled_with_rocm
()
else
np
.
float
64
self
.
softmax_switch
=
False
#default is true, means "with softmax"
self
.
softmax_switch
=
False
#default is true, means "with softmax"
...
@@ -145,7 +145,7 @@ class TestSoftmaxWithCrossEntropyOp_NotWithSoftmax_SoftLabel_2D(
...
@@ -145,7 +145,7 @@ class TestSoftmaxWithCrossEntropyOp_NotWithSoftmax_SoftLabel_2D(
self
.
shape
=
[
3
,
5
,
7
,
11
]
self
.
shape
=
[
3
,
5
,
7
,
11
]
self
.
axis
=
-
1
self
.
axis
=
-
1
self
.
ignore_index
=
-
1
self
.
ignore_index
=
-
1
self
.
dtype
=
np
.
float64
self
.
dtype
=
np
.
float
32
if
core
.
is_compiled_with_rocm
()
else
np
.
float
64
self
.
softmax_switch
=
False
#default is true, means "with softmax"
self
.
softmax_switch
=
False
#default is true, means "with softmax"
...
@@ -155,7 +155,7 @@ class TestSoftmaxWithCrossEntropyOp_NotWithSoftmax_SoftLabel_2D_Axis2(
...
@@ -155,7 +155,7 @@ class TestSoftmaxWithCrossEntropyOp_NotWithSoftmax_SoftLabel_2D_Axis2(
self
.
op_type
=
"softmax_with_cross_entropy"
self
.
op_type
=
"softmax_with_cross_entropy"
self
.
numeric_stable_mode
=
True
self
.
numeric_stable_mode
=
True
self
.
soft_label
=
True
self
.
soft_label
=
True
self
.
dtype
=
np
.
float64
self
.
dtype
=
np
.
float
32
if
core
.
is_compiled_with_rocm
()
else
np
.
float
64
self
.
axis
=
1
self
.
axis
=
1
self
.
ignore_index
=
-
1
self
.
ignore_index
=
-
1
self
.
shape
=
[
3
,
5
,
7
,
11
]
self
.
shape
=
[
3
,
5
,
7
,
11
]
...
@@ -168,7 +168,7 @@ class TestSoftmaxWithCrossEntropyOp_NotWithSoftmax_SoftLabel_2D_Axis3(
...
@@ -168,7 +168,7 @@ class TestSoftmaxWithCrossEntropyOp_NotWithSoftmax_SoftLabel_2D_Axis3(
self
.
op_type
=
"softmax_with_cross_entropy"
self
.
op_type
=
"softmax_with_cross_entropy"
self
.
numeric_stable_mode
=
True
self
.
numeric_stable_mode
=
True
self
.
soft_label
=
True
self
.
soft_label
=
True
self
.
dtype
=
np
.
float64
self
.
dtype
=
np
.
float
32
if
core
.
is_compiled_with_rocm
()
else
np
.
float
64
self
.
axis
=
2
self
.
axis
=
2
self
.
ignore_index
=
-
1
self
.
ignore_index
=
-
1
self
.
shape
=
[
3
,
5
,
7
,
11
]
self
.
shape
=
[
3
,
5
,
7
,
11
]
...
@@ -181,7 +181,7 @@ class TestSoftmaxWithCrossEntropyOp_NotWithSoftmax_SoftLabel_2D_Axis4(
...
@@ -181,7 +181,7 @@ class TestSoftmaxWithCrossEntropyOp_NotWithSoftmax_SoftLabel_2D_Axis4(
self
.
op_type
=
"softmax_with_cross_entropy"
self
.
op_type
=
"softmax_with_cross_entropy"
self
.
numeric_stable_mode
=
True
self
.
numeric_stable_mode
=
True
self
.
soft_label
=
True
self
.
soft_label
=
True
self
.
dtype
=
np
.
float64
self
.
dtype
=
np
.
float
32
if
core
.
is_compiled_with_rocm
()
else
np
.
float
64
self
.
axis
=
3
self
.
axis
=
3
self
.
ignore_index
=
-
1
self
.
ignore_index
=
-
1
self
.
shape
=
[
3
,
5
,
7
,
11
]
self
.
shape
=
[
3
,
5
,
7
,
11
]
...
@@ -206,7 +206,7 @@ class TestSoftmaxWithCrossEntropyOp_NotWithSoftmax_HardLabel_2D(
...
@@ -206,7 +206,7 @@ class TestSoftmaxWithCrossEntropyOp_NotWithSoftmax_HardLabel_2D(
self
.
shape
=
[
3
,
5
,
7
,
11
]
self
.
shape
=
[
3
,
5
,
7
,
11
]
self
.
axis
=
-
1
self
.
axis
=
-
1
self
.
ignore_index
=
-
1
self
.
ignore_index
=
-
1
self
.
dtype
=
np
.
float64
self
.
dtype
=
np
.
float
32
if
core
.
is_compiled_with_rocm
()
else
np
.
float
64
self
.
softmax_switch
=
False
#default is true, means "with softmax"
self
.
softmax_switch
=
False
#default is true, means "with softmax"
...
@@ -216,7 +216,7 @@ class TestSoftmaxWithCrossEntropyOp_NotWithSoftmax_HardLabel_2D_Axis2(
...
@@ -216,7 +216,7 @@ class TestSoftmaxWithCrossEntropyOp_NotWithSoftmax_HardLabel_2D_Axis2(
self
.
op_type
=
"softmax_with_cross_entropy"
self
.
op_type
=
"softmax_with_cross_entropy"
self
.
numeric_stable_mode
=
True
self
.
numeric_stable_mode
=
True
self
.
soft_label
=
False
self
.
soft_label
=
False
self
.
dtype
=
np
.
float64
self
.
dtype
=
np
.
float
32
if
core
.
is_compiled_with_rocm
()
else
np
.
float
64
self
.
axis
=
1
self
.
axis
=
1
self
.
ignore_index
=
-
1
self
.
ignore_index
=
-
1
self
.
shape
=
[
3
,
5
,
7
,
11
]
self
.
shape
=
[
3
,
5
,
7
,
11
]
...
@@ -229,7 +229,7 @@ class TestSoftmaxWithCrossEntropyOp_NotWithSoftmax_HardLabel_2D_Axis3(
...
@@ -229,7 +229,7 @@ class TestSoftmaxWithCrossEntropyOp_NotWithSoftmax_HardLabel_2D_Axis3(
self
.
op_type
=
"softmax_with_cross_entropy"
self
.
op_type
=
"softmax_with_cross_entropy"
self
.
numeric_stable_mode
=
True
self
.
numeric_stable_mode
=
True
self
.
soft_label
=
False
self
.
soft_label
=
False
self
.
dtype
=
np
.
float64
self
.
dtype
=
np
.
float
32
if
core
.
is_compiled_with_rocm
()
else
np
.
float
64
self
.
axis
=
2
self
.
axis
=
2
self
.
ignore_index
=
-
1
self
.
ignore_index
=
-
1
self
.
shape
=
[
3
,
5
,
7
,
11
]
self
.
shape
=
[
3
,
5
,
7
,
11
]
...
@@ -242,7 +242,7 @@ class TestSoftmaxWithCrossEntropyOp_NotWithSoftmax_HardLabel_2D_Axis4(
...
@@ -242,7 +242,7 @@ class TestSoftmaxWithCrossEntropyOp_NotWithSoftmax_HardLabel_2D_Axis4(
self
.
op_type
=
"softmax_with_cross_entropy"
self
.
op_type
=
"softmax_with_cross_entropy"
self
.
numeric_stable_mode
=
True
self
.
numeric_stable_mode
=
True
self
.
soft_label
=
False
self
.
soft_label
=
False
self
.
dtype
=
np
.
float64
self
.
dtype
=
np
.
float
32
if
core
.
is_compiled_with_rocm
()
else
np
.
float
64
self
.
axis
=
3
self
.
axis
=
3
self
.
ignore_index
=
-
1
self
.
ignore_index
=
-
1
self
.
shape
=
[
3
,
5
,
7
,
11
]
self
.
shape
=
[
3
,
5
,
7
,
11
]
...
@@ -267,7 +267,7 @@ class TestSoftmaxWithCrossEntropyOp_NotWithSoftmax_HardLabel_Ignore(
...
@@ -267,7 +267,7 @@ class TestSoftmaxWithCrossEntropyOp_NotWithSoftmax_HardLabel_Ignore(
self
.
shape
=
[
13
,
8
]
self
.
shape
=
[
13
,
8
]
self
.
axis
=
-
1
self
.
axis
=
-
1
self
.
ignore_index
=
2
self
.
ignore_index
=
2
self
.
dtype
=
np
.
float64
self
.
dtype
=
np
.
float
32
if
core
.
is_compiled_with_rocm
()
else
np
.
float
64
self
.
softmax_switch
=
False
#default is true, means "with softmax"
self
.
softmax_switch
=
False
#default is true, means "with softmax"
...
@@ -280,7 +280,7 @@ class TestSoftmaxWithCrossEntropyOp_NotWithSoftmax_HardLabel_Ignore_Axis(
...
@@ -280,7 +280,7 @@ class TestSoftmaxWithCrossEntropyOp_NotWithSoftmax_HardLabel_Ignore_Axis(
self
.
shape
=
[
13
,
8
]
self
.
shape
=
[
13
,
8
]
self
.
axis
=
1
self
.
axis
=
1
self
.
ignore_index
=
2
self
.
ignore_index
=
2
self
.
dtype
=
np
.
float64
self
.
dtype
=
np
.
float
32
if
core
.
is_compiled_with_rocm
()
else
np
.
float
64
self
.
softmax_switch
=
False
#default is true, means "with softmax"
self
.
softmax_switch
=
False
#default is true, means "with softmax"
...
@@ -293,7 +293,7 @@ class TestSoftmaxWithCrossEntropyOp_NotWithSoftmax_HardLabel_2D_Ignore(
...
@@ -293,7 +293,7 @@ class TestSoftmaxWithCrossEntropyOp_NotWithSoftmax_HardLabel_2D_Ignore(
self
.
shape
=
[
3
,
5
,
7
,
11
]
self
.
shape
=
[
3
,
5
,
7
,
11
]
self
.
axis
=
-
1
self
.
axis
=
-
1
self
.
ignore_index
=
2
self
.
ignore_index
=
2
self
.
dtype
=
np
.
float64
self
.
dtype
=
np
.
float
32
if
core
.
is_compiled_with_rocm
()
else
np
.
float
64
self
.
softmax_switch
=
False
#default is true, means "with softmax"
self
.
softmax_switch
=
False
#default is true, means "with softmax"
...
@@ -303,7 +303,7 @@ class TestSoftmaxWithCrossEntropyOp_NotWithSoftmax_HardLabel_2D_Ignore_Axis3(
...
@@ -303,7 +303,7 @@ class TestSoftmaxWithCrossEntropyOp_NotWithSoftmax_HardLabel_2D_Ignore_Axis3(
self
.
op_type
=
"softmax_with_cross_entropy"
self
.
op_type
=
"softmax_with_cross_entropy"
self
.
numeric_stable_mode
=
True
self
.
numeric_stable_mode
=
True
self
.
soft_label
=
False
self
.
soft_label
=
False
self
.
dtype
=
np
.
float64
self
.
dtype
=
np
.
float
32
if
core
.
is_compiled_with_rocm
()
else
np
.
float
64
self
.
axis
=
2
self
.
axis
=
2
self
.
ignore_index
=
2
self
.
ignore_index
=
2
self
.
shape
=
[
3
,
5
,
7
,
11
]
self
.
shape
=
[
3
,
5
,
7
,
11
]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录