Skip to content

Commit 9e4fabc

Browse files
authored
test=develop, error info improvement (#24496) (#24572)
1 parent eb0ca3b commit 9e4fabc

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

paddle/fluid/operators/split_selected_rows_op.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,12 @@ class SplitSelectedRowsOp : public framework::OperatorWithKernel {
5454
using framework::OperatorWithKernel::OperatorWithKernel;
5555

5656
void InferShape(framework::InferShapeContext *ctx) const override {
57-
PADDLE_ENFORCE(ctx->HasInput("X"),
58-
"SplitSelectedRowsOp must have input X.");
59-
PADDLE_ENFORCE(ctx->HasOutputs("Out"),
60-
"SplitSelectedRowsOp must have output Out.");
57+
PADDLE_ENFORCE_EQ(ctx->HasInput("X"), true,
58+
platform::errors::InvalidArgument(
59+
"SplitSelectedRowsOp must have input X."));
60+
PADDLE_ENFORCE_EQ(ctx->HasOutputs("Out"), true,
61+
platform::errors::InvalidArgument(
62+
"SplitSelectedRowsOp must have output Out."));
6163
}
6264
};
6365

paddle/fluid/operators/split_selected_rows_op.h

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ class SplitSelectedRowsOpKernel : public framework::OpKernel<T> {
4646
// split rows index into output sparse vars
4747
for (size_t i = 0; i < x_rows.size(); ++i) {
4848
auto& id = x_rows[i];
49-
PADDLE_ENFORCE_LT(id, height);
49+
PADDLE_ENFORCE_LT(id, height,
50+
platform::errors::OutOfRange(
51+
"Each row_id in x.rows must be less than x.height. "
52+
"But received x.rows[%d] = %d, x.height = %d",
53+
i, id, height));
5054
int out_idx = GetSectionIndex(id, abs_sections);
5155
outs_rows_idx[out_idx].push_back(id);
5256
outs_dense_idx[out_idx].push_back(i);
@@ -63,7 +67,12 @@ class SplitSelectedRowsOpKernel : public framework::OpKernel<T> {
6367
if (rows_idx.size() > 0) {
6468
for (auto idx : rows_idx) {
6569
auto id_offset = idx - abs_sections[i];
66-
PADDLE_ENFORCE_LT(id_offset, height_sections[i]);
70+
PADDLE_ENFORCE_LT(
71+
id_offset, height_sections[i],
72+
platform::errors::OutOfRange("Each row_id in out.rows must be "
73+
"less than out.height. But recived "
74+
"out.rows = [%d], out.height = [%d]",
75+
id_offset, height_sections[i]));
6776
outs[i]->mutable_rows()->push_back(id_offset);
6877
}
6978
auto dst = outs[i]->mutable_value()->mutable_data<T>(ctx.GetPlace());
@@ -80,13 +89,17 @@ class SplitSelectedRowsOpKernel : public framework::OpKernel<T> {
8089
src + outs_dense_idx[i][j] * row_numel,
8190
sizeof(T) * row_numel, stream);
8291
#else
83-
PADDLE_THROW("Paddle is not compiled with GPU");
92+
PADDLE_THROW(platform::errors::Unavailable(
93+
"Paddle is not compiled with CUDA. Cannot visit cuda device"));
8494
#endif
8595
}
8696
}
8797
}
8898
PADDLE_ENFORCE_EQ(rows_idx.size(), outs[i]->rows().size(),
89-
"rows should has the same size with tensor dim 0");
99+
platform::errors::InvalidArgument(
100+
"rows should has the same size with tensor dim 0. "
101+
"But received rows = %d, tensor's dim[0] = %d.",
102+
rows_idx.size(), outs[i]->rows().size()));
90103
}
91104
}
92105
};

0 commit comments

Comments
 (0)