Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
ed292695
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
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看板
未验证
提交
ed292695
编写于
9月 09, 2020
作者:
K
kinghuin
提交者:
GitHub
9月 09, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
optimize the error message for math dir
optimize the error message for math dir
上级
eb276632
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
203 addition
and
62 deletion
+203
-62
paddle/fluid/operators/math/sequence2batch.cc
paddle/fluid/operators/math/sequence2batch.cc
+17
-4
paddle/fluid/operators/math/sequence2batch.cu
paddle/fluid/operators/math/sequence2batch.cu
+17
-4
paddle/fluid/operators/math/sequence2batch.h
paddle/fluid/operators/math/sequence2batch.h
+27
-9
paddle/fluid/operators/math/sequence_padding.cc
paddle/fluid/operators/math/sequence_padding.cc
+13
-4
paddle/fluid/operators/math/sequence_padding.cu
paddle/fluid/operators/math/sequence_padding.cu
+14
-6
paddle/fluid/operators/math/sequence_padding.h
paddle/fluid/operators/math/sequence_padding.h
+18
-7
paddle/fluid/operators/math/sequence_pooling.cc
paddle/fluid/operators/math/sequence_pooling.cc
+70
-23
paddle/fluid/operators/math/sequence_pooling.cu
paddle/fluid/operators/math/sequence_pooling.cu
+8
-2
paddle/fluid/operators/math/sequence_pooling_test.cc
paddle/fluid/operators/math/sequence_pooling_test.cc
+14
-2
paddle/fluid/operators/math/tree2col.cc
paddle/fluid/operators/math/tree2col.cc
+5
-1
未找到文件。
paddle/fluid/operators/math/sequence2batch.cc
浏览文件 @
ed292695
...
...
@@ -29,11 +29,24 @@ class CopyMatrixRowsFunctor<platform::CPUDeviceContext, T> {
auto
src_dims
=
src
.
dims
();
auto
dst_dims
=
dst
->
dims
();
PADDLE_ENFORCE_EQ
(
src_dims
.
size
(),
2UL
,
"The src must be matrix with rank 2."
);
platform
::
errors
::
InvalidArgument
(
"The source tensor must be a matrix with rank 2, but "
"got the source tensor rank is %lu. "
"Please check the rank of the source tensor"
,
src_dims
.
size
()));
PADDLE_ENFORCE_EQ
(
dst_dims
.
size
(),
2UL
,
"The dst must be matrix with rank 2."
);
PADDLE_ENFORCE_EQ
(
src_dims
[
1
],
dst_dims
[
1
],
"The width of src and dst must be same."
);
platform
::
errors
::
InvalidArgument
(
"The destination tensor must be a matrix with rank, "
"but got the destination tensor rank is %lu. "
"Please check the rank of the destination tensor"
,
dst_dims
.
size
()));
PADDLE_ENFORCE_EQ
(
src_dims
[
1
],
dst_dims
[
1
],
platform
::
errors
::
InvalidArgument
(
"The width of the source tensor and the destination tensor must be "
"same. But got %lu != %lu.Please check the rank of the source "
"tensor"
,
src_dims
.
size
(),
dst_dims
.
size
()));
auto
height
=
dst_dims
[
0
];
auto
width
=
dst_dims
[
1
];
auto
*
src_data
=
src
.
data
<
T
>
();
...
...
paddle/fluid/operators/math/sequence2batch.cu
浏览文件 @
ed292695
...
...
@@ -46,11 +46,24 @@ class CopyMatrixRowsFunctor<platform::CUDADeviceContext, T> {
auto
src_dims
=
src
.
dims
();
auto
dst_dims
=
dst
->
dims
();
PADDLE_ENFORCE_EQ
(
src_dims
.
size
(),
2
,
"The src must be matrix with rank 2."
);
platform
::
errors
::
InvalidArgument
(
"The source tensor must be a matrix with rank 2, but "
"got the source tensor rank is %lu. "
"Please check the rank of the source tensor"
,
src_dims
.
size
()));
PADDLE_ENFORCE_EQ
(
dst_dims
.
size
(),
2
,
"The dst must be matrix with rank 2."
);
PADDLE_ENFORCE_EQ
(
src_dims
[
1
],
dst_dims
[
1
],
"The width of src and dst must be same."
);
platform
::
errors
::
InvalidArgument
(
"The destination tensor must be a matrix with rank, "
"but got the destination tensor rank is %lu. "
"Please check the rank of the destination tensor"
,
dst_dims
.
size
()));
PADDLE_ENFORCE_EQ
(
src_dims
[
1
],
dst_dims
[
1
],
platform
::
errors
::
InvalidArgument
(
"The width of the source tensor and the destination tensor must be "
"same. But got %lu != %lu.Please check the rank of the source "
"tensor"
,
src_dims
.
size
(),
dst_dims
.
size
()));
auto
height
=
dst_dims
[
0
];
auto
width
=
dst_dims
[
1
];
auto
*
src_data
=
src
.
data
<
T
>
();
...
...
paddle/fluid/operators/math/sequence2batch.h
浏览文件 @
ed292695
...
...
@@ -64,19 +64,30 @@ class LoDTensor2BatchFunctor {
bool
is_reverse
=
false
)
const
{
if
(
!
is_cal_batch_lod
)
{
auto
lods
=
batch
->
lod
();
PADDLE_ENFORCE_GT
(
lods
.
size
(),
2UL
,
"The LoD of LoDTensor should inlcude at least 2-level "
"sequence information."
);
PADDLE_ENFORCE_GT
(
lods
.
size
(),
2UL
,
platform
::
errors
::
InvalidArgument
(
"The LoD of LoDTensor should inlcude at least 2-level "
"sequence information, but got the LoD level is %lu. Please "
"check the input value."
,
lods
.
size
()));
PADDLE_ENFORCE_EQ
(
lods
[
1
].
size
(),
static_cast
<
size_t
>
(
lod_tensor
.
dims
()[
0
]),
"The LoD information should be consistent with the dims."
);
platform
::
errors
::
InvalidArgument
(
"The LoD information should be consistent with the dims, but got "
"%lu != %lu. Please check the input value."
,
lods
[
1
].
size
(),
static_cast
<
size_t
>
(
lod_tensor
.
dims
()[
0
])));
CopyMatrixRowsFunctor
<
DeviceContext
,
T
>
to_batch
;
to_batch
(
context
,
lod_tensor
,
lods
[
1
],
batch
,
true
);
return
;
}
auto
lods
=
lod_tensor
.
lod
();
PADDLE_ENFORCE_EQ
(
lods
.
size
(),
1UL
,
"Only support one level sequence now."
);
PADDLE_ENFORCE_EQ
(
lods
.
size
(),
1UL
,
platform
::
errors
::
InvalidArgument
(
"Only support one level sequence now, but got the "
"LoD level is %lu. Please check the input value."
,
lods
.
size
()));
const
auto
&
lod
=
lods
[
0
];
...
...
@@ -161,12 +172,19 @@ class Batch2LoDTensorFunctor {
const
framework
::
LoDTensor
&
batch
,
framework
::
LoDTensor
*
lod_tensor
)
const
{
auto
in_lod
=
batch
.
lod
();
PADDLE_ENFORCE_GT
(
in_lod
.
size
(),
2UL
,
"The LoD of LoDTensor should inlcude at least 2-level "
"sequence information."
);
PADDLE_ENFORCE_GT
(
in_lod
.
size
(),
2UL
,
platform
::
errors
::
InvalidArgument
(
"The LoD of LoDTensor should inlcude at least 2-level "
"sequence information, but got the LoD level is %lu. Please check "
"the input value."
,
in_lod
.
size
()));
PADDLE_ENFORCE_EQ
(
in_lod
[
1
].
size
(),
static_cast
<
size_t
>
(
lod_tensor
->
dims
()[
0
]),
"The LoD information should be consistent with the dims."
);
platform
::
errors
::
InvalidArgument
(
"The LoD information should be consistent with the dims, but got "
"%lu != %lu. Please check the input value."
,
in_lod
[
1
].
size
(),
static_cast
<
size_t
>
(
lod_tensor
->
dims
()[
0
])));
CopyMatrixRowsFunctor
<
DeviceContext
,
T
>
to_seq
;
to_seq
(
context
,
batch
,
in_lod
[
1
],
lod_tensor
,
false
);
}
...
...
paddle/fluid/operators/math/sequence_padding.cc
浏览文件 @
ed292695
...
...
@@ -35,7 +35,11 @@ void CopyValidData(framework::Tensor* dst_tensor,
int
valid_seq_len
=
seq_offsets
[
seq_idx
+
1
]
-
seq_offsets
[
seq_idx
];
PADDLE_ENFORCE_GE
(
pad_seq_len
,
valid_seq_len
,
"The padded sequence length can not be less than its original length."
);
platform
::
errors
::
InvalidArgument
(
"The padded sequence length can not "
"be less than its original length. Expected %ld >= %ld, but got "
"%ld < %ld. Please check input value."
,
pad_seq_len
,
valid_seq_len
,
pad_seq_len
,
valid_seq_len
));
int
seq_data_offset
=
seq_offsets
[
seq_idx
]
*
step_width
;
int
pad_data_offset
=
layout
==
kBatchLengthWidth
?
seq_idx
*
pad_seq_len
*
step_width
...
...
@@ -95,9 +99,14 @@ class PaddingLoDTensorFunctor<platform::CPUDeviceContext, T> {
CheckDims
(
seq_tensor_dims
,
pad_tensor_dims
,
seq_offsets
,
pad_seq_len
,
step_width
,
layout
);
PADDLE_ENFORCE
(
pad_value
.
numel
()
==
1
||
pad_value
.
numel
()
==
step_width
,
"The numel of 'pad_value' can only be 1 or be equal to the "
"'step_width'."
);
PADDLE_ENFORCE_EQ
(
pad_value
.
numel
()
==
1
||
pad_value
.
numel
()
==
step_width
,
true
,
platform
::
errors
::
InvalidArgument
(
"The numel of 'pad_value' can only be 1 or be equal to the "
"'step_width', but got %ld != 1 and %ld. Please check the input "
"value."
,
pad_value
.
numel
(),
step_width
));
// fill padding value
T
*
pad_data
=
pad_tensor
->
data
<
T
>
();
...
...
paddle/fluid/operators/math/sequence_padding.cu
浏览文件 @
ed292695
...
...
@@ -66,17 +66,25 @@ class PaddingLoDTensorFunctor<platform::CUDADeviceContext, T> {
if
(
pad_seq_len
==
-
1
)
{
pad_seq_len
=
max_seq_len
;
}
PADDLE_ENFORCE_GE
(
pad_seq_len
,
max_seq_len
,
"The pad_seq_len must be equal to or greater than the "
"original max sequence length."
);
PADDLE_ENFORCE_GE
(
pad_seq_len
,
max_seq_len
,
platform
::
errors
::
InvalidArgument
(
"The pad_seq_len must be equal to or greater than the "
"original max sequence length. Expected %ld >= %ld, but got %ld < "
"%ld. Please check the input value."
,
pad_seq_len
,
max_seq_len
,
pad_seq_len
,
max_seq_len
));
int
step_width
=
seq_tensor
.
numel
()
/
seq_tensor_dims
[
0
];
int
seq_num
=
seq_offsets
.
size
()
-
1
;
CheckDims
(
seq_tensor_dims
,
pad_tensor_dims
,
seq_offsets
,
pad_seq_len
,
step_width
,
layout
);
PADDLE_ENFORCE
(
pad_value
.
numel
()
==
1
||
pad_value
.
numel
()
==
step_width
,
"The numel of 'pad_value' can only be 1 or be equal to the "
"'step_width'."
);
PADDLE_ENFORCE_EQ
(
pad_value
.
numel
()
==
1
||
pad_value
.
numel
()
==
step_width
,
true
,
platform
::
errors
::
InvalidArgument
(
"The numel of 'pad_value' can only be 1 or be equal to "
"the 'step_width', but got %ld != 1 and %ld. Please check the "
"input value."
,
pad_value
.
numel
(),
step_width
));
const
int
kBlockSize
=
512
;
...
...
paddle/fluid/operators/math/sequence_padding.h
浏览文件 @
ed292695
...
...
@@ -52,14 +52,25 @@ inline static void CheckDims(const framework::DDim& seq_tensor_dims,
const
framework
::
Vector
<
size_t
>&
seq_offset
,
int64_t
padded_seq_len
,
int64_t
step_width
,
const
PadLayout
&
layout
)
{
PADDLE_ENFORCE_EQ
(
static_cast
<
size_t
>
(
seq_tensor_dims
[
0
]),
seq_offset
.
back
(),
"Value of 1st dimension of the sequence tensor should be "
"equal to sum of lengths of all sequences."
);
PADDLE_ENFORCE_EQ
(
static_cast
<
size_t
>
(
seq_tensor_dims
[
0
]),
seq_offset
.
back
(),
platform
::
errors
::
InvalidArgument
(
"Value of 1st dimension of the sequence tensor should be "
"equal to sum of lengths of all sequences. Expected %ld == %ld, but "
"got %ld != %ld. Please check the input value."
,
static_cast
<
size_t
>
(
seq_tensor_dims
[
0
]),
seq_offset
.
back
(),
static_cast
<
size_t
>
(
seq_tensor_dims
[
0
]),
seq_offset
.
back
()));
PADDLE_ENFORCE
(
seq_tensor_dims
.
size
()
+
1
==
pad_tensor_dims
.
size
()
||
seq_tensor_dims
.
size
()
==
pad_tensor_dims
.
size
(),
"pad_tensor's rank should be 1 greater than seq_tensor's "
"rank, or be equal with it."
);
PADDLE_ENFORCE_EQ
(
seq_tensor_dims
.
size
()
+
1
==
pad_tensor_dims
.
size
()
||
seq_tensor_dims
.
size
()
==
pad_tensor_dims
.
size
(),
true
,
platform
::
errors
::
InvalidArgument
(
"pad_tensor's rank should be 1 greater than seq_tensor's "
"rank, or be equal with it. The pad_tensor's rank is %ld, "
"expected the seq_tensor's rank is %ld or %ld, but got %ld. "
"Please check the input value."
,
pad_tensor_dims
.
size
(),
pad_tensor_dims
.
size
(),
pad_tensor_dims
.
size
()
-
1
,
seq_tensor_dims
.
size
()));
}
/*
...
...
paddle/fluid/operators/math/sequence_pooling.cc
浏览文件 @
ed292695
...
...
@@ -42,15 +42,29 @@ class MaxSeqPoolFunctor {
auto
out_dims
=
output
->
dims
();
auto
idx_dims
=
index
->
dims
();
PADDLE_ENFORCE_GT
(
in_dims
.
size
(),
1
,
"The rank of input shall be greater than 1."
);
platform
::
errors
::
InvalidArgument
(
"The rank of input shall be greater than 1, but got "
"the rank is %ld. Please check the input value"
,
in_dims
.
size
()));
PADDLE_ENFORCE_GT
(
out_dims
.
size
(),
1
,
"The rank of output shall be greater than 1."
);
platform
::
errors
::
InvalidArgument
(
"The rank of output shall be greater than 1, but got "
"the rank is %ld. Please check the input value"
,
out_dims
.
size
()));
for
(
int64_t
i
=
1
;
i
<
in_dims
.
size
();
++
i
)
{
PADDLE_ENFORCE_EQ
(
in_dims
[
i
],
out_dims
[
i
],
"The dimension of input and output shall be same."
);
PADDLE_ENFORCE_EQ
(
in_dims
[
i
],
out_dims
[
i
],
platform
::
errors
::
InvalidArgument
(
"The dimension of input and output shall be same. Expected %ld "
"== %ld, but got %ld != %ld. Please check the input value."
,
in_dims
[
i
],
out_dims
[
i
],
in_dims
[
i
],
out_dims
[
i
]));
}
PADDLE_ENFORCE_EQ
(
idx_dims
,
out_dims
,
"The dimension of index and output shall be same."
);
PADDLE_ENFORCE_EQ
(
idx_dims
,
out_dims
,
platform
::
errors
::
InvalidArgument
(
"The dimension of index and output shall be same. Expected %ld == "
"%ld, but got %ld != %ld. Please check the input value."
,
idx_dims
,
out_dims
,
idx_dims
,
out_dims
));
auto
lod_level
=
input
.
lod
().
size
();
auto
starts
=
input
.
lod
()[
lod_level
-
1
];
...
...
@@ -94,12 +108,22 @@ class MaxSeqPoolFunctor<T, true> {
auto
in_dims
=
input
.
dims
();
auto
out_dims
=
output
->
dims
();
PADDLE_ENFORCE_GT
(
in_dims
.
size
(),
1
,
"The rank of input shall be greater than 1."
);
platform
::
errors
::
InvalidArgument
(
"The rank of input shall be greater than 1, but got "
"%ld <= 1. Please check the input value."
,
in_dims
.
size
()));
PADDLE_ENFORCE_GT
(
out_dims
.
size
(),
1
,
"The rank of output shall be greater than 1."
);
platform
::
errors
::
InvalidArgument
(
"The rank of output shall be greater than 1, but got "
"%ld <= 1. Please check the input value."
,
out_dims
.
size
()));
for
(
int64_t
i
=
1
;
i
<
in_dims
.
size
();
++
i
)
{
PADDLE_ENFORCE_EQ
(
in_dims
[
i
],
out_dims
[
i
],
"The dimension of input and output shall be same."
);
PADDLE_ENFORCE_EQ
(
in_dims
[
i
],
out_dims
[
i
],
platform
::
errors
::
InvalidArgument
(
"The dimension of input and output shall be same. Expected %ld "
"== %ld, but got %ld != %ld. Please check the input value."
,
in_dims
[
i
],
out_dims
[
i
],
in_dims
[
i
],
out_dims
[
i
]));
}
auto
lod_level
=
input
.
lod
().
size
();
...
...
@@ -139,16 +163,29 @@ class MaxSeqPoolGradFunctor {
auto
ig_dims
=
in_grad
->
dims
();
auto
idx_dims
=
index
.
dims
();
PADDLE_ENFORCE_GT
(
og_dims
.
size
(),
1
,
"The rank of output@Grad shall be greater than 1."
);
platform
::
errors
::
InvalidArgument
(
"The rank of output@Grad shall be greater than 1, "
"but got %ld <= 1. Please check the input value."
,
og_dims
.
size
()));
PADDLE_ENFORCE_GT
(
ig_dims
.
size
(),
1
,
"The rank of input@Grad shall be greater than 1."
);
platform
::
errors
::
InvalidArgument
(
"The rank of input@Grad shall be greater than 1, but "
"got %ld <= 1. Please check the input value."
,
ig_dims
.
size
()));
for
(
int64_t
i
=
1
;
i
<
og_dims
.
size
();
++
i
)
{
PADDLE_ENFORCE_EQ
(
og_dims
[
i
],
ig_dims
[
i
],
"The dimension of input@Grad and output@Grad shall be same."
);
PADDLE_ENFORCE_EQ
(
og_dims
[
i
],
ig_dims
[
i
],
platform
::
errors
::
InvalidArgument
(
"The dimension of input@Grad and output@Grad shall "
"be same. Expected %ld == %ld, but got %ld != %ld. "
"Please check the input value."
,
og_dims
[
i
],
ig_dims
[
i
],
og_dims
[
i
],
ig_dims
[
i
]));
}
PADDLE_ENFORCE_EQ
(
idx_dims
,
og_dims
,
"The dimension of index and output@Grad shall be same."
);
PADDLE_ENFORCE_EQ
(
idx_dims
,
og_dims
,
platform
::
errors
::
InvalidArgument
(
"The dimension of index and output@Grad shall be same. Expected "
"%ld == %ld, but got %ld != %ld. Please check the input value."
,
idx_dims
,
og_dims
,
idx_dims
,
og_dims
));
const
T
*
og_data
=
out_grad
.
data
<
T
>
();
const
int
*
max_index
=
index
.
data
<
int
>
();
...
...
@@ -244,9 +281,12 @@ class SumSeqPoolGradFunctor {
auto
lod
=
in_grad
->
lod
()[
lod_level
-
1
];
int64_t
out_w
=
out_grad
.
numel
()
/
out_grad
.
dims
()[
0
];
int64_t
in_w
=
in_grad
->
numel
()
/
in_grad
->
dims
()[
0
];
PADDLE_ENFORCE_EQ
(
in_w
,
out_w
,
"The feature size of input@Grad and output@Grad shall be same."
);
PADDLE_ENFORCE_EQ
(
in_w
,
out_w
,
platform
::
errors
::
InvalidArgument
(
"The feature size of input@Grad and output@Grad "
"shall be same. Expected %ld == %ld, but got %ld != "
"%ld. Please check the input value."
,
in_w
,
out_w
,
in_w
,
out_w
));
const
T
*
out_g_data
=
out_grad
.
data
<
T
>
();
T
*
in_g_data
=
in_grad
->
mutable_data
<
T
>
(
context
.
GetPlace
());
auto
blas
=
math
::
GetBlas
<
platform
::
CPUDeviceContext
,
T
>
(
context
);
...
...
@@ -298,7 +338,8 @@ class SequencePoolFunctor<platform::CPUDeviceContext, T> {
auto
place
=
context
.
GetPlace
();
PADDLE_ENFORCE_EQ
(
platform
::
is_cpu_place
(
place
),
true
,
"Sequence_pool should run on CPU Device when pooltype is SUM"
);
platform
::
errors
::
InvalidArgument
(
"Sequence_pool should run on CPU Device when pooltype is SUM"
));
const
T
*
src
=
input
.
data
<
T
>
();
T
*
dst
=
output
->
mutable_data
<
T
>
(
place
);
jit
::
seq_pool_attr_t
attr
(
...
...
@@ -342,7 +383,10 @@ class SequencePoolFunctor<platform::CPUDeviceContext, T> {
out_e
.
device
(
place
)
=
in_e
.
sum
(
Eigen
::
array
<
int
,
1
>
({{
0
}}))
/
std
::
sqrt
(
static_cast
<
T
>
(
h
));
}
else
{
PADDLE_THROW
(
"unsupported pooling pooltype"
);
PADDLE_THROW
(
platform
::
errors
::
InvalidArgument
(
"unsupported pooling pooltype: %s. Only support
\"
AVERAGE
\"
and "
"
\"
SQRT
\"
"
,
pooltype
));
}
}
}
...
...
@@ -400,7 +444,10 @@ class SequencePoolGradFunctor<platform::CPUDeviceContext, T> {
}
else
if
(
pooltype
==
"FIRST"
)
{
in_g_e
.
chip
(
0
,
0
).
device
(
place
)
=
out_g_e_v
;
}
else
{
PADDLE_THROW
(
"unsupported pooling pooltype"
);
PADDLE_THROW
(
platform
::
errors
::
InvalidArgument
(
"unsupported pooling pooltype: %s. Only support
\"
AVERAGE
\"
, "
"
\"
SQRT
\"
,
\"
LAST
\"
and
\"
FIRST
\"
"
,
pooltype
));
}
}
}
...
...
paddle/fluid/operators/math/sequence_pooling.cu
浏览文件 @
ed292695
...
...
@@ -205,7 +205,10 @@ class SequencePoolFunctor<platform::CUDADeviceContext, T> {
lod
.
CUDAData
(
context
.
GetPlace
()),
lod
.
size
(),
item_dim
,
output
->
mutable_data
<
T
>
(
context
.
GetPlace
()),
nullptr
);
}
else
{
PADDLE_THROW
(
"unsupported pooling pooltype"
);
PADDLE_THROW
(
platform
::
errors
::
InvalidArgument
(
"unsupported pooling pooltype: %s. Only support
\"
MAX
\"
, "
"
\"
AVERAGE
\"
,
\"
SUM
\"
,
\"
SQRT
\"
,
\"
LAST
\"
and
\"
FIRST
\"
"
,
pooltype
));
}
}
};
...
...
@@ -370,7 +373,10 @@ class SequencePoolGradFunctor<platform::CUDADeviceContext, T> {
in_grad
->
mutable_data
<
T
>
(
context
.
GetPlace
()),
nullptr
);
}
else
{
PADDLE_THROW
(
"unsupported pooling pooltype"
);
PADDLE_THROW
(
platform
::
errors
::
InvalidArgument
(
"unsupported pooling pooltype: %s. Only support
\"
MAX
\"
, "
"
\"
AVERAGE
\"
,
\"
SUM
\"
,
\"
SQRT
\"
,
\"
LAST
\"
and
\"
FIRST
\"
"
,
pooltype
));
}
}
};
...
...
paddle/fluid/operators/math/sequence_pooling_test.cc
浏览文件 @
ed292695
...
...
@@ -50,9 +50,21 @@ void TestSequencePoolingSum(const DeviceContext &context,
in_grad
.
mutable_data
<
T
>
(
in_dims
,
place
);
// check tensor contruction result
PADDLE_ENFORCE_EQ
(
in_grad
.
dims
().
size
(),
out_grad
.
dims
().
size
());
PADDLE_ENFORCE_EQ
(
in_grad
.
dims
().
size
(),
out_grad
.
dims
().
size
(),
paddle
::
platform
::
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
(),
out_grad
.
dims
().
size
(),
in_grad
.
dims
().
size
(),
out_grad
.
dims
().
size
()));
for
(
int64_t
i
=
1
;
i
<
out_grad
.
dims
().
size
();
++
i
)
{
PADDLE_ENFORCE_EQ
(
in_grad
.
dims
()[
i
],
out_grad
.
dims
()[
i
]);
PADDLE_ENFORCE_EQ
(
in_grad
.
dims
()[
i
],
out_grad
.
dims
()[
i
],
paddle
::
platform
::
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
],
out_grad
.
dims
()[
i
],
in_grad
.
dims
()[
i
],
out_grad
.
dims
()[
i
]));
}
// call functor
...
...
paddle/fluid/operators/math/tree2col.cc
浏览文件 @
ed292695
...
...
@@ -55,7 +55,11 @@ void Tree2ColUtil::construct_tree(const paddle::Tensor &EdgeSet,
std
::
vector
<
std
::
vector
<
int
>>
*
tr
,
size_t
*
node_count
)
{
auto
edge_set_dims
=
EdgeSet
.
dims
();
PADDLE_ENFORCE_EQ
(
edge_set_dims
[
1
],
2
);
PADDLE_ENFORCE_EQ
(
edge_set_dims
[
1
],
2
,
platform
::
errors
::
InvalidArgument
(
"The second dimension of the EdgeSet shall be 2, but "
"got %ld != 2. Please check the input value."
,
edge_set_dims
[
1
]));
int64_t
edge_count
=
EdgeSet
.
numel
();
const
int
*
edge_data
=
EdgeSet
.
data
<
int
>
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录