Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
c376a940
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看板
未验证
提交
c376a940
编写于
4月 12, 2023
作者:
G
gouzil
提交者:
GitHub
4月 12, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[phi] mv sequence_pool to phi - Step 1 : sequence_pooling_test (#52782)
* [phi] mv sequence_pooling_test * [test] fix include
上级
8e7c3789
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
28 addition
and
24 deletion
+28
-24
paddle/fluid/operators/math/CMakeLists.txt
paddle/fluid/operators/math/CMakeLists.txt
+0
-4
test/cpp/phi/kernels/CMakeLists.txt
test/cpp/phi/kernels/CMakeLists.txt
+5
-0
test/cpp/phi/kernels/sequence_pooling_test.cc
test/cpp/phi/kernels/sequence_pooling_test.cc
+23
-20
未找到文件。
paddle/fluid/operators/math/CMakeLists.txt
浏览文件 @
c376a940
...
...
@@ -39,10 +39,6 @@ cc_test(
vol2col_test
SRCS vol2col_test.cc
DEPS vol2col
)
cc_test
(
sequence_pooling_test
SRCS sequence_pooling_test.cc
DEPS sequence_pooling
)
cc_test
(
beam_search_test
SRCS beam_search_test.cc
...
...
test/cpp/phi/kernels/CMakeLists.txt
浏览文件 @
c376a940
...
...
@@ -105,3 +105,8 @@ cc_test(
sequence_padding_test
SRCS sequence_padding_test.cc
DEPS sequence_padding
)
cc_test
(
sequence_pooling_test
SRCS sequence_pooling_test.cc
DEPS sequence_pooling
)
paddle/fluid/operators/math
/sequence_pooling_test.cc
→
test/cpp/phi/kernels
/sequence_pooling_test.cc
浏览文件 @
c376a940
/* Copyright (c) 20
18
PaddlePaddle Authors. All Rights Reserved.
/* Copyright (c) 20
23
PaddlePaddle Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
...
...
@@ -12,13 +12,17 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#include <gtest/gtest.h>
#include "paddle/fluid/operators/math/sequence_pooling.h"
#include <gtest/gtest.h>
#include "paddle/phi/backends/context_pool.h"
#include "paddle/phi/common/place.h"
#include "paddle/phi/core/tensor_utils.h"
template
<
typename
DeviceContext
,
typename
T
>
void
TestSequencePoolingSum
(
const
DeviceContext
&
context
,
const
p
addle
::
framework
::
LoD
&
lod
,
const
p
hi
::
LoD
&
lod
,
const
int64_t
second_dim
)
{
phi
::
DenseTensor
cpu_out_grad
;
phi
::
DenseTensor
cpu_in_grad
;
...
...
@@ -30,17 +34,17 @@ void TestSequencePoolingSum(const DeviceContext &context,
auto
out_dims
=
phi
::
make_ddim
({
static_cast
<
int64_t
>
(
out_first_dim
),
second_dim
});
cpu_out_grad
.
mutable_data
<
T
>
(
out_dims
,
p
addle
::
platform
::
CPUPlace
());
cpu_out_grad
.
mutable_data
<
T
>
(
out_dims
,
p
hi
::
CPUPlace
());
for
(
int64_t
i
=
0
;
i
<
cpu_out_grad
.
numel
();
++
i
)
{
cpu_out_grad
.
data
<
T
>
()[
i
]
=
static_cast
<
T
>
(
i
);
}
// copy to dst out_grad
auto
place
=
context
.
GetPlace
();
if
(
p
addle
::
platform
::
is_cpu_place
(
place
))
{
if
(
p
lace
==
phi
::
CPUPlace
(
))
{
out_grad
=
cpu_out_grad
;
}
else
{
p
addle
::
framework
::
TensorCopySync
(
cpu_out_grad
,
plac
e
,
&
out_grad
);
p
hi
::
Copy
(
context
,
cpu_out_grad
,
place
,
tru
e
,
&
out_grad
);
}
// construct in_grad
...
...
@@ -53,7 +57,7 @@ void TestSequencePoolingSum(const DeviceContext &context,
PADDLE_ENFORCE_EQ
(
in_grad
.
dims
().
size
(),
out_grad
.
dims
().
size
(),
p
addle
::
platform
::
errors
::
InvalidArgument
(
p
hi
::
errors
::
InvalidArgument
(
"The dimension of input and output shall be same. Expected %ld == "
"%ld, but got %ld != %ld. Please check the input value."
,
in_grad
.
dims
().
size
(),
...
...
@@ -64,7 +68,7 @@ void TestSequencePoolingSum(const DeviceContext &context,
PADDLE_ENFORCE_EQ
(
in_grad
.
dims
()[
i
],
out_grad
.
dims
()[
i
],
p
addle
::
platform
::
errors
::
InvalidArgument
(
p
hi
::
errors
::
InvalidArgument
(
"The dimension of input and output shall be same. Expected %ld == "
"%ld, but got %ld != %ld. Please check the input value."
,
in_grad
.
dims
()[
i
],
...
...
@@ -77,18 +81,17 @@ void TestSequencePoolingSum(const DeviceContext &context,
paddle
::
operators
::
math
::
SequencePoolGradFunctor
<
DeviceContext
,
T
>
()(
context
,
"SUM"
,
out_grad
,
&
in_grad
);
if
(
p
addle
::
platform
::
is_cpu_place
(
place
))
{
if
(
p
lace
==
phi
::
CPUPlace
(
))
{
cpu_in_grad
=
in_grad
;
}
else
{
paddle
::
framework
::
TensorCopySync
(
in_grad
,
paddle
::
platform
::
CPUPlace
(),
&
cpu_in_grad
);
phi
::
Copy
(
context
,
in_grad
,
phi
::
CPUPlace
(),
true
,
&
cpu_in_grad
);
cpu_in_grad
.
set_lod
(
in_grad
.
lod
());
}
EXPECT_EQ
(
in_grad
.
numel
(),
static_cast
<
int64_t
>
(
lod
[
0
].
back
()
*
second_dim
));
EXPECT_EQ
(
in_grad
.
lod
(),
lod
);
if
(
p
addle
::
platform
::
is_cpu_place
(
place
))
{
if
(
p
lace
==
phi
::
CPUPlace
(
))
{
for
(
size_t
i
=
0
;
i
<
in_grad
.
lod
()[
0
].
size
()
-
1
;
++
i
)
{
int64_t
begin
=
in_grad
.
lod
()[
0
][
i
];
int64_t
end
=
in_grad
.
lod
()[
0
][
i
+
1
];
...
...
@@ -116,30 +119,30 @@ void TestSequencePoolingSum(const DeviceContext &context,
}
TEST
(
SequencePoolingGrad
,
CPU_SUM
)
{
auto
place
=
p
addle
::
platform
::
CPUPlace
();
auto
place
=
p
hi
::
CPUPlace
();
auto
*
context
=
static_cast
<
phi
::
CPUContext
*>
(
p
addle
::
platform
::
DeviceContextPool
::
Instance
().
Get
(
place
));
p
hi
::
DeviceContextPool
::
Instance
().
Get
(
place
));
p
addle
::
framework
::
LoD
lod1
;
p
hi
::
LoD
lod1
;
lod1
.
push_back
(
std
::
vector
<
size_t
>
{
0
,
10
});
TestSequencePoolingSum
<
phi
::
CPUContext
,
float
>
(
*
context
,
lod1
,
128
);
p
addle
::
framework
::
LoD
lod2
;
p
hi
::
LoD
lod2
;
lod2
.
push_back
(
std
::
vector
<
size_t
>
{
0
,
2
,
7
,
10
});
TestSequencePoolingSum
<
phi
::
CPUContext
,
float
>
(
*
context
,
lod2
,
128
);
}
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
TEST
(
SequencePoolingGrad
,
CUDA_SUM
)
{
auto
place
=
p
addle
::
platform
::
CUDA
Place
(
0
);
auto
place
=
p
hi
::
GPU
Place
(
0
);
auto
*
context
=
static_cast
<
phi
::
GPUContext
*>
(
p
addle
::
platform
::
DeviceContextPool
::
Instance
().
Get
(
place
));
p
hi
::
DeviceContextPool
::
Instance
().
Get
(
place
));
p
addle
::
framework
::
LoD
lod1
;
p
hi
::
LoD
lod1
;
lod1
.
push_back
(
std
::
vector
<
size_t
>
{
0
,
10
});
TestSequencePoolingSum
<
phi
::
GPUContext
,
float
>
(
*
context
,
lod1
,
128
);
p
addle
::
framework
::
LoD
lod2
;
p
hi
::
LoD
lod2
;
lod2
.
push_back
(
std
::
vector
<
size_t
>
{
0
,
2
,
7
,
10
});
TestSequencePoolingSum
<
phi
::
GPUContext
,
float
>
(
*
context
,
lod2
,
128
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录