Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
1f28968b
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 2 年 前同步成功
通知
2325
Star
20933
Fork
5424
代码
文件
提交
分支
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看板
未验证
提交
1f28968b
编写于
7月 09, 2021
作者:
L
Leo Chen
提交者:
GitHub
7月 09, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[NPU] Fix vector overflow in slice grad npu op (#34032)
* fix vector overflow * refine code * refine ut
上级
fd85be80
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
14 addition
and
14 deletion
+14
-14
paddle/fluid/operators/slice_op_npu.cc
paddle/fluid/operators/slice_op_npu.cc
+6
-6
python/paddle/fluid/tests/unittests/npu/test_slice_op_npu.py
python/paddle/fluid/tests/unittests/npu/test_slice_op_npu.py
+8
-8
未找到文件。
paddle/fluid/operators/slice_op_npu.cc
浏览文件 @
1f28968b
...
@@ -25,15 +25,16 @@ namespace operators {
...
@@ -25,15 +25,16 @@ namespace operators {
using
Tensor
=
framework
::
Tensor
;
using
Tensor
=
framework
::
Tensor
;
void
UpdateAttr
(
const
framework
::
DDim
in_dims
,
const
std
::
vector
<
int
>
axes
,
void
UpdateAttr
(
const
framework
::
DDim
&
in_dims
,
const
std
::
vector
<
int
>
axes
,
const
std
::
vector
<
int
>
starts
,
const
std
::
vector
<
int
>
ends
,
const
std
::
vector
<
int
>
starts
,
const
std
::
vector
<
int
>
ends
,
std
::
vector
<
int
>*
offsets
,
std
::
vector
<
int
>*
size
)
{
std
::
vector
<
int
>*
offsets
,
std
::
vector
<
int
>*
size
)
{
int
cnt
=
0
;
int
cnt
=
0
;
for
(
int
i
=
0
;
i
<
in_dims
.
size
();
++
i
)
{
for
(
int
i
=
0
;
i
<
in_dims
.
size
();
++
i
)
{
int
start
=
0
;
int
start
=
0
;
int
end
=
in_dims
[
i
];
int
end
=
in_dims
[
i
];
int
axis
=
axes
[
cnt
];
// NOTE(zhiqiu): Becareful that cnt may > axes.size() and result in
// overflow.
int
axis
=
cnt
<
static_cast
<
int
>
(
axes
.
size
())
?
axes
[
cnt
]
:
-
1
;
if
(
axis
==
i
)
{
if
(
axis
==
i
)
{
start
=
starts
[
cnt
];
start
=
starts
[
cnt
];
if
(
start
<
0
)
{
if
(
start
<
0
)
{
...
@@ -63,10 +64,10 @@ class SliceNPUKernel : public framework::OpKernel<T> {
...
@@ -63,10 +64,10 @@ class SliceNPUKernel : public framework::OpKernel<T> {
auto
axes
=
ctx
.
Attr
<
std
::
vector
<
int
>>
(
"axes"
);
auto
axes
=
ctx
.
Attr
<
std
::
vector
<
int
>>
(
"axes"
);
auto
starts
=
ctx
.
Attr
<
std
::
vector
<
int
>>
(
"starts"
);
auto
starts
=
ctx
.
Attr
<
std
::
vector
<
int
>>
(
"starts"
);
auto
ends
=
ctx
.
Attr
<
std
::
vector
<
int
>>
(
"ends"
);
auto
ends
=
ctx
.
Attr
<
std
::
vector
<
int
>>
(
"ends"
);
const
auto
&
in_dims
=
input
->
dims
();
out
->
mutable_data
<
T
>
(
ctx
.
GetPlace
());
out
->
mutable_data
<
T
>
(
ctx
.
GetPlace
());
auto
in_dims
=
input
->
dims
();
std
::
vector
<
int
>
offsets
(
in_dims
.
size
());
std
::
vector
<
int
>
offsets
(
in_dims
.
size
());
std
::
vector
<
int
>
size
(
in_dims
.
size
());
std
::
vector
<
int
>
size
(
in_dims
.
size
());
...
@@ -93,8 +94,7 @@ class SliceGradNPUKernel : public framework::OpKernel<T> {
...
@@ -93,8 +94,7 @@ class SliceGradNPUKernel : public framework::OpKernel<T> {
auto
axes
=
ctx
.
Attr
<
std
::
vector
<
int
>>
(
"axes"
);
auto
axes
=
ctx
.
Attr
<
std
::
vector
<
int
>>
(
"axes"
);
auto
starts
=
ctx
.
Attr
<
std
::
vector
<
int
>>
(
"starts"
);
auto
starts
=
ctx
.
Attr
<
std
::
vector
<
int
>>
(
"starts"
);
auto
ends
=
ctx
.
Attr
<
std
::
vector
<
int
>>
(
"ends"
);
auto
ends
=
ctx
.
Attr
<
std
::
vector
<
int
>>
(
"ends"
);
const
auto
&
in_dims
=
input
->
dims
();
auto
in_dims
=
input
->
dims
();
int
rank
=
in_dims
.
size
();
int
rank
=
in_dims
.
size
();
std
::
vector
<
int
>
offsets
(
rank
);
std
::
vector
<
int
>
offsets
(
rank
);
...
...
python/paddle/fluid/tests/unittests/npu/test_slice_op_npu.py
浏览文件 @
1f28968b
...
@@ -71,12 +71,12 @@ class TestSliceOp(OpTest):
...
@@ -71,12 +71,12 @@ class TestSliceOp(OpTest):
class
TestSliceOp2
(
TestSliceOp
):
class
TestSliceOp2
(
TestSliceOp
):
def
config
(
self
):
def
config
(
self
):
self
.
input
=
np
.
random
.
random
([
3
,
4
,
5
,
6
]).
astype
(
self
.
dtype
)
self
.
input
=
np
.
random
.
random
([
10
,
5
,
6
]).
astype
(
self
.
dtype
)
self
.
starts
=
[
1
,
0
,
-
3
]
self
.
starts
=
[
0
]
self
.
ends
=
[
3
,
3
,
-
1
]
self
.
ends
=
[
1
]
self
.
axes
=
[
0
,
1
,
2
]
self
.
axes
=
[
1
]
self
.
infer_flags
=
[
1
,
1
,
1
]
self
.
infer_flags
=
[
1
]
self
.
out
=
self
.
input
[
1
:
3
,
0
:
3
,
-
3
:
-
1
,
:]
self
.
out
=
self
.
input
[
:,
0
:
1
,
:]
@
unittest
.
skipIf
(
not
paddle
.
is_compiled_with_npu
(),
@
unittest
.
skipIf
(
not
paddle
.
is_compiled_with_npu
(),
...
@@ -118,8 +118,8 @@ class TestSliceNet(unittest.TestCase):
...
@@ -118,8 +118,8 @@ class TestSliceNet(unittest.TestCase):
prediction
=
paddle
.
static
.
nn
.
fc
(
z
,
size
=
2
,
activation
=
'softmax'
)
prediction
=
paddle
.
static
.
nn
.
fc
(
z
,
size
=
2
,
activation
=
'softmax'
)
cost
=
paddle
.
nn
.
functional
.
cross_entropy
(
cost
=
paddle
.
fluid
.
layers
.
softmax_with_
cross_entropy
(
input
=
prediction
,
label
=
label
)
logits
=
prediction
,
label
=
label
)
loss
=
paddle
.
mean
(
cost
)
loss
=
paddle
.
mean
(
cost
)
sgd
=
paddle
.
optimizer
.
SGD
(
learning_rate
=
0.01
)
sgd
=
paddle
.
optimizer
.
SGD
(
learning_rate
=
0.01
)
sgd
.
minimize
(
loss
)
sgd
.
minimize
(
loss
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录