Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Crayon鑫
Paddle
提交
3a6bc9ad
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看板
提交
3a6bc9ad
编写于
9月 27, 2020
作者:
X
xiemoyuan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Optimize the error message for OPs.
上级
9b124014
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
54 addition
and
34 deletion
+54
-34
paddle/fluid/operators/beam_search_decode_op.cc
paddle/fluid/operators/beam_search_decode_op.cc
+2
-1
paddle/fluid/operators/chunk_eval_op.h
paddle/fluid/operators/chunk_eval_op.h
+1
-1
paddle/fluid/operators/cudnn_lstm_op.cc
paddle/fluid/operators/cudnn_lstm_op.cc
+2
-2
paddle/fluid/operators/edit_distance_op.cu
paddle/fluid/operators/edit_distance_op.cu
+3
-2
paddle/fluid/operators/edit_distance_op.h
paddle/fluid/operators/edit_distance_op.h
+8
-6
paddle/fluid/operators/expand_as_op.cc
paddle/fluid/operators/expand_as_op.cc
+3
-2
paddle/fluid/operators/expand_as_op.h
paddle/fluid/operators/expand_as_op.h
+17
-10
paddle/fluid/operators/linear_chain_crf_op.h
paddle/fluid/operators/linear_chain_crf_op.h
+18
-10
未找到文件。
paddle/fluid/operators/beam_search_decode_op.cc
浏览文件 @
3a6bc9ad
...
@@ -117,7 +117,8 @@ void BeamSearchDecodeFunctor::apply() const {
...
@@ -117,7 +117,8 @@ void BeamSearchDecodeFunctor::apply() const {
template
<
>
template
<
>
void
BeamSearchDecodeFunctor
::
apply
<
bool
>
()
const
{
void
BeamSearchDecodeFunctor
::
apply
<
bool
>
()
const
{
PADDLE_THROW
(
"beam search decode op does not support bool!"
);
PADDLE_THROW
(
platform
::
errors
::
InvalidArgument
(
"beam search decode op does not support bool!"
));
}
}
class
BeamSearchDecodeOp
:
public
framework
::
OperatorBase
{
class
BeamSearchDecodeOp
:
public
framework
::
OperatorBase
{
...
...
paddle/fluid/operators/chunk_eval_op.h
浏览文件 @
3a6bc9ad
...
@@ -146,7 +146,7 @@ class ChunkEvalKernel : public framework::OpKernel<T> {
...
@@ -146,7 +146,7 @@ class ChunkEvalKernel : public framework::OpKernel<T> {
tag_end
=
-
1
;
tag_end
=
-
1
;
tag_single
=
-
1
;
tag_single
=
-
1
;
}
else
{
}
else
{
PADDLE_THROW
(
"Unknown chunk scheme."
);
PADDLE_THROW
(
platform
::
errors
::
InvalidArgument
(
"Unknown chunk scheme."
)
);
}
}
other_chunk_type
=
num_chunk_types
=
context
.
Attr
<
int
>
(
"num_chunk_types"
);
other_chunk_type
=
num_chunk_types
=
context
.
Attr
<
int
>
(
"num_chunk_types"
);
excluded_chunk_types
.
insert
(
excluded_chunk_types
.
insert
(
...
...
paddle/fluid/operators/cudnn_lstm_op.cc
浏览文件 @
3a6bc9ad
...
@@ -274,8 +274,8 @@ template <typename T>
...
@@ -274,8 +274,8 @@ template <typename T>
class
NotImpleKernel
:
public
framework
::
OpKernel
<
T
>
{
class
NotImpleKernel
:
public
framework
::
OpKernel
<
T
>
{
public:
public:
void
Compute
(
const
framework
::
ExecutionContext
&
ctx
)
const
override
{
void
Compute
(
const
framework
::
ExecutionContext
&
ctx
)
const
override
{
PADDLE_THROW
(
PADDLE_THROW
(
platform
::
errors
::
Unimplemented
(
"CPU is not support for this kernel now. Will be add in the future"
);
"CPU is not support for this kernel now. Will be add in the future"
)
)
;
}
}
};
};
...
...
paddle/fluid/operators/edit_distance_op.cu
浏览文件 @
3a6bc9ad
...
@@ -111,8 +111,9 @@ class EditDistanceGPUKernel : public framework::OpKernel<T> {
...
@@ -111,8 +111,9 @@ class EditDistanceGPUKernel : public framework::OpKernel<T> {
if
(
normalized
)
{
if
(
normalized
)
{
for
(
size_t
i
=
1
;
i
<
ref_lod
.
size
();
++
i
)
{
for
(
size_t
i
=
1
;
i
<
ref_lod
.
size
();
++
i
)
{
PADDLE_ENFORCE
(
ref_lod
[
i
]
>
ref_lod
[
i
-
1
],
PADDLE_ENFORCE_GT
(
ref_lod
[
i
],
ref_lod
[
i
-
1
],
"Reference string %d is empty."
,
i
);
platform
::
errors
::
InvalidArgument
(
"Reference string %d is empty."
,
i
));
}
}
}
}
...
...
paddle/fluid/operators/edit_distance_op.h
浏览文件 @
3a6bc9ad
...
@@ -58,8 +58,9 @@ class EditDistanceKernel : public framework::OpKernel<T> {
...
@@ -58,8 +58,9 @@ class EditDistanceKernel : public framework::OpKernel<T> {
if
(
normalized
)
{
if
(
normalized
)
{
for
(
size_t
i
=
1
;
i
<
ref_lod
.
size
();
++
i
)
{
for
(
size_t
i
=
1
;
i
<
ref_lod
.
size
();
++
i
)
{
PADDLE_ENFORCE
(
ref_lod
[
i
]
>
ref_lod
[
i
-
1
],
PADDLE_ENFORCE_GT
(
ref_lod
[
i
],
ref_lod
[
i
-
1
],
"Reference string %d is empty."
,
i
);
platform
::
errors
::
InvalidArgument
(
"Reference string %d is empty."
,
i
));
}
}
}
}
auto
num_strs
=
hyp_lod
.
size
()
-
1
;
auto
num_strs
=
hyp_lod
.
size
()
-
1
;
...
@@ -106,10 +107,11 @@ class EditDistanceKernel : public framework::OpKernel<T> {
...
@@ -106,10 +107,11 @@ class EditDistanceKernel : public framework::OpKernel<T> {
}
}
if
(
normalized
)
{
if
(
normalized
)
{
PADDLE_ENFORCE
(
n
>
0
,
PADDLE_ENFORCE_GT
(
n
,
0UL
,
"The reference string (#%d) cannot be empty "
platform
::
errors
::
InvalidArgument
(
"when Attr(normalized) is enabled."
,
"The reference string (#%d) cannot be empty "
n
);
"when Attr(normalized) is enabled."
,
n
));
distance
=
distance
/
n
;
distance
=
distance
/
n
;
}
}
out
[
num
]
=
distance
;
out
[
num
]
=
distance
;
...
...
paddle/fluid/operators/expand_as_op.cc
浏览文件 @
3a6bc9ad
...
@@ -89,8 +89,9 @@ class ExpandAsGradOp : public framework::OperatorWithKernel {
...
@@ -89,8 +89,9 @@ class ExpandAsGradOp : public framework::OperatorWithKernel {
protected:
protected:
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
PADDLE_ENFORCE_EQ
(
ctx
->
HasInput
(
"X"
),
true
);
OP_INOUT_CHECK
(
ctx
->
HasInput
(
"X"
),
"Input"
,
"X"
,
"ExpandAs"
);
PADDLE_ENFORCE_EQ
(
ctx
->
HasInput
(
framework
::
GradVarName
(
"Out"
)),
true
);
OP_INOUT_CHECK
(
ctx
->
HasInput
(
framework
::
GradVarName
(
"Out"
)),
"Input"
,
framework
::
GradVarName
(
"Out"
),
"ExpandAs"
);
auto
x_dims
=
ctx
->
GetInputDim
(
"X"
);
auto
x_dims
=
ctx
->
GetInputDim
(
"X"
);
auto
x_grad_name
=
framework
::
GradVarName
(
"X"
);
auto
x_grad_name
=
framework
::
GradVarName
(
"X"
);
...
...
paddle/fluid/operators/expand_as_op.h
浏览文件 @
3a6bc9ad
...
@@ -61,7 +61,8 @@ class ExpandAsKernel : public framework::OpKernel<T> {
...
@@ -61,7 +61,8 @@ class ExpandAsKernel : public framework::OpKernel<T> {
switch
(
rank
)
{
switch
(
rank
)
{
REP_EXPAND_AS_TEMPLATE
(
MAX_RANK_SUPPORTED
)
REP_EXPAND_AS_TEMPLATE
(
MAX_RANK_SUPPORTED
)
default:
default:
PADDLE_THROW
(
"Only support tensor with rank being between 1 and 6."
);
PADDLE_THROW
(
platform
::
errors
::
InvalidArgument
(
"Only support tensor with rank being between 1 and 6."
));
}
}
}
}
...
@@ -77,13 +78,16 @@ class ExpandAsKernel : public framework::OpKernel<T> {
...
@@ -77,13 +78,16 @@ class ExpandAsKernel : public framework::OpKernel<T> {
auto
x_dims
=
in0
->
dims
();
auto
x_dims
=
in0
->
dims
();
auto
y_dims
=
target_tensor
->
dims
();
auto
y_dims
=
target_tensor
->
dims
();
for
(
int
i
=
0
;
i
<
y_dims
.
size
();
++
i
)
{
for
(
int
i
=
0
;
i
<
y_dims
.
size
();
++
i
)
{
PADDLE_ENFORCE_NE
(
x_dims
[
i
],
0
,
"X(input) should not have 0 dim"
);
PADDLE_ENFORCE_NE
(
x_dims
[
i
],
0UL
,
platform
::
errors
::
InvalidArgument
(
"X(input) should not have 0 dim"
));
bcast_dims
[
i
]
=
y_dims
[
i
]
/
x_dims
[
i
];
bcast_dims
[
i
]
=
y_dims
[
i
]
/
x_dims
[
i
];
bcast_dims_remainder
+=
y_dims
[
i
]
%
x_dims
[
i
];
bcast_dims_remainder
+=
y_dims
[
i
]
%
x_dims
[
i
];
}
}
PADDLE_ENFORCE_EQ
(
bcast_dims_remainder
,
0
,
PADDLE_ENFORCE_EQ
(
"X(input) could not be broadcast together with remapped "
bcast_dims_remainder
,
0UL
,
"shape(expand tensor's shape)"
);
platform
::
errors
::
InvalidArgument
(
"X(input) could not be broadcast together with remapped "
"shape(expand tensor's shape)"
));
framework
::
DDim
out_dims
(
in_dims
);
framework
::
DDim
out_dims
(
in_dims
);
for
(
size_t
i
=
0
;
i
<
bcast_dims
.
size
();
++
i
)
{
for
(
size_t
i
=
0
;
i
<
bcast_dims
.
size
();
++
i
)
{
out_dims
[
i
]
*=
bcast_dims
[
i
];
out_dims
[
i
]
*=
bcast_dims
[
i
];
...
@@ -137,7 +141,8 @@ class ExpandAsGradKernel : public framework::OpKernel<T> {
...
@@ -137,7 +141,8 @@ class ExpandAsGradKernel : public framework::OpKernel<T> {
switch
(
dims
)
{
switch
(
dims
)
{
REP_EXPAND_AS_GRAD_TEMPLATE
(
MAX_RANK_SUPPORTED
)
REP_EXPAND_AS_GRAD_TEMPLATE
(
MAX_RANK_SUPPORTED
)
default:
default:
PADDLE_THROW
(
"Only support tensor with rank being between 1 and 6."
);
PADDLE_THROW
(
platform
::
errors
::
InvalidArgument
(
"Only support tensor with rank being between 1 and 6."
));
}
}
}
}
}
}
...
@@ -150,11 +155,13 @@ class ExpandAsGradKernel : public framework::OpKernel<T> {
...
@@ -150,11 +155,13 @@ class ExpandAsGradKernel : public framework::OpKernel<T> {
size_t
reshape_size
=
reshape_dims_vec
.
size
();
size_t
reshape_size
=
reshape_dims_vec
.
size
();
size_t
reduce_size
=
reduce_dims_vec
.
size
();
size_t
reduce_size
=
reduce_dims_vec
.
size
();
PADDLE_ENFORCE_EQ
(
reshape_size
,
reshape_dims_vec
.
size
(),
PADDLE_ENFORCE_EQ
(
reshape_size
,
reshape_dims_vec
.
size
(),
"Inconsistent size between template Dims and "
platform
::
errors
::
InvalidArgument
(
"reshape dimensions."
);
"Inconsistent size between template Dims and "
"reshape dimensions."
));
PADDLE_ENFORCE_EQ
(
reduce_size
,
reduce_dims_vec
.
size
(),
PADDLE_ENFORCE_EQ
(
reduce_size
,
reduce_dims_vec
.
size
(),
"Inconsistent size between template Dims and "
platform
::
errors
::
InvalidArgument
(
"reduce dimensions."
);
"Inconsistent size between template Dims and "
"reduce dimensions."
));
auto
*
in0
=
context
.
Input
<
Tensor
>
(
framework
::
GradVarName
(
"Out"
));
auto
*
in0
=
context
.
Input
<
Tensor
>
(
framework
::
GradVarName
(
"Out"
));
auto
*
out0
=
context
.
Output
<
Tensor
>
(
framework
::
GradVarName
(
"X"
));
auto
*
out0
=
context
.
Output
<
Tensor
>
(
framework
::
GradVarName
(
"X"
));
out0
->
mutable_data
<
T
>
(
context
.
GetPlace
());
out0
->
mutable_data
<
T
>
(
context
.
GetPlace
());
...
...
paddle/fluid/operators/linear_chain_crf_op.h
浏览文件 @
3a6bc9ad
...
@@ -27,9 +27,10 @@ static inline T NormalizeL1(T* x, size_t len) {
...
@@ -27,9 +27,10 @@ static inline T NormalizeL1(T* x, size_t len) {
// (This comment is from the old LinearChainCRFLayer.)
// (This comment is from the old LinearChainCRFLayer.)
// Right now, we just bet that sum won't be zero. If this really happens, we
// Right now, we just bet that sum won't be zero. If this really happens, we
// will figure out what should be done then.
// will figure out what should be done then.
PADDLE_ENFORCE
(
sum
,
PADDLE_ENFORCE_GT
(
"The unnormalized probabilities of all possible unfinished "
sum
,
0.
,
platform
::
errors
::
InvalidArgument
(
"sequences must be greater than 0."
);
"The unnormalized probabilities of all possible unfinished "
"sequences must be greater than 0."
));
T
s
=
1.
/
sum
;
T
s
=
1.
/
sum
;
for
(
size_t
i
=
0
;
i
<
len
;
++
i
)
x
[
i
]
*=
s
;
for
(
size_t
i
=
0
;
i
<
len
;
++
i
)
x
[
i
]
*=
s
;
return
sum
;
return
sum
;
...
@@ -85,12 +86,14 @@ class LinearChainCRFOpKernel : public framework::OpKernel<T> {
...
@@ -85,12 +86,14 @@ class LinearChainCRFOpKernel : public framework::OpKernel<T> {
length_data
=
label_length
->
data
<
int64_t
>
();
length_data
=
label_length
->
data
<
int64_t
>
();
seq_num
=
label_length
->
numel
();
seq_num
=
label_length
->
numel
();
PADDLE_ENFORCE_EQ
(
seq_num
,
emission_dims
[
0
],
PADDLE_ENFORCE_EQ
(
seq_num
,
emission_dims
[
0
],
"the size of Input(length) must be equal to "
platform
::
errors
::
InvalidArgument
(
"emission_dims[0]."
);
"the size of Input(length) must be equal to "
"emission_dims[0]."
));
auto
label_dims
=
label
->
dims
();
auto
label_dims
=
label
->
dims
();
PADDLE_ENFORCE_EQ
(
seq_num
,
label_dims
[
0
],
PADDLE_ENFORCE_EQ
(
seq_num
,
label_dims
[
0
],
"the size of Input(length) must be equal to "
platform
::
errors
::
InvalidArgument
(
"label_dims[0]."
);
"the size of Input(length) must be equal to "
"label_dims[0]."
));
batch_size
=
emission_dims
[
0
]
*
emission_dims
[
1
];
batch_size
=
emission_dims
[
0
]
*
emission_dims
[
1
];
tag_num
=
emission_dims
[
2
];
tag_num
=
emission_dims
[
2
];
...
@@ -102,7 +105,9 @@ class LinearChainCRFOpKernel : public framework::OpKernel<T> {
...
@@ -102,7 +105,9 @@ class LinearChainCRFOpKernel : public framework::OpKernel<T> {
math
::
set_constant
(
ctx
.
device_context
(),
alpha
,
0.0
);
math
::
set_constant
(
ctx
.
device_context
(),
alpha
,
0.0
);
}
else
{
}
else
{
in_lod
=
ctx
.
Input
<
LoDTensor
>
(
"Label"
)
->
lod
();
in_lod
=
ctx
.
Input
<
LoDTensor
>
(
"Label"
)
->
lod
();
PADDLE_ENFORCE_NE
(
in_lod
.
size
(),
0
,
"Input(Label) must be a sequence."
);
PADDLE_ENFORCE_NE
(
in_lod
.
size
(),
0
,
platform
::
errors
::
InvalidArgument
(
"Input(Label) must be a sequence."
));
seq_num
=
in_lod
[
0
].
size
()
-
1
;
seq_num
=
in_lod
[
0
].
size
()
-
1
;
batch_size
=
emission_dims
[
0
];
batch_size
=
emission_dims
[
0
];
tag_num
=
emission_dims
[
1
];
tag_num
=
emission_dims
[
1
];
...
@@ -204,7 +209,8 @@ class LinearChainCRFOpKernel : public framework::OpKernel<T> {
...
@@ -204,7 +209,8 @@ class LinearChainCRFOpKernel : public framework::OpKernel<T> {
const
int64_t
*
lbl
=
label
.
data
<
int64_t
>
();
const
int64_t
*
lbl
=
label
.
data
<
int64_t
>
();
PADDLE_ENFORCE_LT
(
PADDLE_ENFORCE_LT
(
static_cast
<
size_t
>
(
*
std
::
max_element
(
lbl
,
lbl
+
seq_length
)),
tag_num
,
static_cast
<
size_t
>
(
*
std
::
max_element
(
lbl
,
lbl
+
seq_length
)),
tag_num
,
"An invalid tag label that execesses the largest tag number."
);
platform
::
errors
::
InvalidArgument
(
"An invalid tag label that execesses the largest tag number."
));
// Calculate the nominator part, which depends on the label sequence.
// Calculate the nominator part, which depends on the label sequence.
ll
+=
w
[
lbl
[
0
]]
/*start transition*/
+
x
[
lbl
[
0
]]
+
ll
+=
w
[
lbl
[
0
]]
/*start transition*/
+
x
[
lbl
[
0
]]
+
...
@@ -254,7 +260,9 @@ class LinearChainCRFGradOpKernel : public framework::OpKernel<T> {
...
@@ -254,7 +260,9 @@ class LinearChainCRFGradOpKernel : public framework::OpKernel<T> {
{
emission_dims
[
0
]
*
emission_dims
[
1
],
emission_dims
[
2
]});
{
emission_dims
[
0
]
*
emission_dims
[
1
],
emission_dims
[
2
]});
}
else
{
}
else
{
in_lod
=
ctx
.
Input
<
LoDTensor
>
(
"Label"
)
->
lod
();
in_lod
=
ctx
.
Input
<
LoDTensor
>
(
"Label"
)
->
lod
();
PADDLE_ENFORCE_NE
(
in_lod
.
size
(),
0
,
"Input(Label) must be a sequence."
);
PADDLE_ENFORCE_NE
(
in_lod
.
size
(),
0
,
platform
::
errors
::
InvalidArgument
(
"Input(Label) must be a sequence."
));
seq_num
=
static_cast
<
int64_t
>
(
in_lod
[
0
].
size
()
-
1
);
seq_num
=
static_cast
<
int64_t
>
(
in_lod
[
0
].
size
()
-
1
);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录