@@ -89,41 +89,57 @@ class CRFDecodingOp : public framework::OperatorWithKernel {
89
89
using framework::OperatorWithKernel::OperatorWithKernel;
90
90
91
91
void InferShape (framework::InferShapeContext* ctx) const override {
92
- PADDLE_ENFORCE_EQ (ctx->HasInput (" Emission" ), true ,
93
- " Input(Emission) should be not null." );
94
- PADDLE_ENFORCE_EQ (ctx->HasInput (" Transition" ), true ,
95
- " Input(Transition) should be not null." );
96
-
97
- PADDLE_ENFORCE_EQ (ctx->HasOutput (" ViterbiPath" ), true ,
98
- " Output(ViterbiPath) should be not null." );
92
+ OP_INOUT_CHECK (ctx->HasInput (" Emission" ), " Input" , " Emission" ,
93
+ " CRFDecoding" );
94
+ OP_INOUT_CHECK (ctx->HasInput (" Transition" ), " Input" , " Transition" ,
95
+ " CRFDecoding" );
96
+ OP_INOUT_CHECK (ctx->HasOutput (" ViterbiPath" ), " Output" , " ViterbiPath" ,
97
+ " CRFDecoding" );
99
98
100
99
auto emission_dims = ctx->GetInputDim (" Emission" );
101
100
bool has_length = ctx->HasInput (" Length" );
102
101
103
102
if (has_length) {
104
103
PADDLE_ENFORCE_EQ (emission_dims.size (), 3 ,
105
- " The Input(Emission) should be a 3-D tensor." );
104
+ platform::errors::InvalidArgument (
105
+ " The Input(Emission) should be a 3-D tensor. But "
106
+ " received: input rank %u, input shape [%s]. " ,
107
+ emission_dims.size (), emission_dims));
106
108
} else {
107
109
PADDLE_ENFORCE_EQ (emission_dims.size (), 2 ,
108
- " The Input(Emission) should be a 2-D tensor." );
110
+ platform::errors::InvalidArgument (
111
+ " The Input(Emission) should be a 2-D tensor. But "
112
+ " received: input rank %u, input shape [%s]." ,
113
+ emission_dims.size (), emission_dims));
109
114
}
110
- PADDLE_ENFORCE_NE (emission_dims[0 ], 0 ,
111
- " An empty mini-batch is not allowed." );
112
115
113
116
auto transition_dims = ctx->GetInputDim (" Transition" );
114
117
PADDLE_ENFORCE_EQ (transition_dims.size (), 2UL ,
115
- " The Input(Transition) should be a 2-D tensor." );
118
+ platform::errors::InvalidArgument (
119
+ " The Input(Transition) should be a 2-D tensor. But "
120
+ " received: input rank %u, input shape [%s]." ,
121
+ transition_dims.size (), transition_dims));
116
122
PADDLE_ENFORCE_EQ (
117
123
transition_dims[0 ] - 2 , transition_dims[1 ],
118
- " An invalid dimension for the Input(Transition), which should "
119
- " be a 2-D tensor with shape [(D + 2) x D]." );
124
+ platform::errors::InvalidArgument (
125
+ " An invalid dimension for the Input(Transition), which should "
126
+ " be a 2-D tensor with shape [(D + 2) x D]. But received: input "
127
+ " rank %u, "
128
+ " input shape [%s]." ,
129
+ transition_dims.size (), transition_dims));
120
130
if (ctx->IsRuntime () || (emission_dims[emission_dims.size () - 1 ] > 0 &&
121
131
transition_dims[transition_dims.size () - 1 ] > 0 )) {
122
- PADDLE_ENFORCE_EQ (
123
- emission_dims[emission_dims.size () - 1 ],
124
- transition_dims[transition_dims.size () - 1 ],
125
- " The last dimension of the Input(Emission) and the Input(Transition) "
126
- " should be equal to the tag number." );
132
+ PADDLE_ENFORCE_EQ (emission_dims[emission_dims.size () - 1 ],
133
+ transition_dims[transition_dims.size () - 1 ],
134
+ platform::errors::InvalidArgument (
135
+ " The last dimension of the Input(Emission) and the "
136
+ " Input(Transition) "
137
+ " should be equal to the tag number. But received "
138
+ " Input(Emission): rank "
139
+ " %u, shape [%s]; received Input(Transition): rank "
140
+ " %u, shape [%s]." ,
141
+ emission_dims.size (), emission_dims,
142
+ transition_dims.size (), transition_dims));
127
143
}
128
144
if (ctx->HasInput (" Label" )) {
129
145
auto label_dims = ctx->GetInputDim (" Label" );
@@ -132,20 +148,31 @@ class CRFDecodingOp : public framework::OperatorWithKernel {
132
148
(label_dims.size () == 3UL && label_dims[2 ] == 1 ) ||
133
149
label_dims.size () == 2UL ,
134
150
true ,
135
- " The Input(Label) should be a 3-D tensor with last dimension "
136
- " fixed to 1 or a 2-D tensor in padding mode." );
151
+ platform::errors::InvalidArgument (
152
+ " The Input(Label) should be a 3-D tensor with last dimension "
153
+ " fixed to 1 or a 2-D tensor in padding mode. But received: "
154
+ " input "
155
+ " rank %u, input shape [%s]." ,
156
+ label_dims.size (), label_dims));
137
157
} else {
138
- PADDLE_ENFORCE_EQ ((label_dims.size () == 2UL && label_dims[1 ] == 1 ) ||
139
- label_dims.size () == 1UL ,
140
- true ,
141
- " The Input(Label) should be a 2-D tensor with last "
142
- " dimension fixed to 1 or a 1-D tensor." );
158
+ PADDLE_ENFORCE_EQ (
159
+ (label_dims.size () == 2UL && label_dims[1 ] == 1 ) ||
160
+ label_dims.size () == 1UL ,
161
+ true , platform::errors::InvalidArgument (
162
+ " The Input(Label) should be a 2-D tensor with last "
163
+ " dimension fixed to 1 or a 1-D tensor. But received: "
164
+ " input rank %u, input shape [%s]." ,
165
+ label_dims.size (), label_dims));
143
166
}
144
167
if (ctx->IsRuntime () || (emission_dims[0 ] > 0 && label_dims[0 ] > 0 )) {
145
168
PADDLE_ENFORCE_EQ (
146
169
emission_dims[0 ], label_dims[0 ],
147
- " The first dimension of Input(Emission) and Input(Label) "
148
- " should be the same." );
170
+ platform::errors::InvalidArgument (
171
+ " The first dimension of Input(Emission) and Input(Label) "
172
+ " should be the same. But received Input(Emission): rank %u, "
173
+ " shape [%s]; received Input(Label): rank %u, shape [%s]." ,
174
+ emission_dims.size (), emission_dims, label_dims.size (),
175
+ label_dims));
149
176
}
150
177
}
151
178
0 commit comments