Skip to content

Commit f1c57d6

Browse files
authored
Enhance error message of prefetch_op, proximal_adagrad_op, proximal_gd_op (#24436)
1 parent 8b79448 commit f1c57d6

File tree

3 files changed

+56
-36
lines changed

3 files changed

+56
-36
lines changed

paddle/fluid/operators/distributed_ops/prefetch_op.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,13 @@ class PrefetchOp : public framework::OperatorBase {
5757
}
5858
}
5959
for (size_t i = 0; i < rets.size(); i++) {
60-
PADDLE_ENFORCE(rets[i]->Wait(), "internal error in RPCClient");
60+
PADDLE_ENFORCE_EQ(
61+
rets[i]->Wait(), true,
62+
platform::errors::Fatal(
63+
"It's a fatal error of RPCClient that RPCClient can't "
64+
"get the wait result. It may happen when trainers or "
65+
"parameter servers exit un normally or the network "
66+
"issue!"));
6167
}
6268
}
6369
};

paddle/fluid/operators/optimizers/proximal_adagrad_op.cc

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,34 +24,42 @@ class ProximalAdagradOp : public framework::OperatorWithKernel {
2424

2525
protected:
2626
void InferShape(framework::InferShapeContext *ctx) const override {
27-
PADDLE_ENFORCE(ctx->HasInput("Param"),
28-
"Input(Param) of ProximalAdagradOp should not be null.");
29-
PADDLE_ENFORCE(ctx->HasInput("Moment"),
30-
"Input(Moment) of ProximalAdagradOp should not be null.");
31-
PADDLE_ENFORCE(ctx->HasInput("Grad"),
32-
"Input(Grad) of ProximalAdagradOp should not be null.");
33-
PADDLE_ENFORCE(
34-
ctx->HasInput("LearningRate"),
35-
"Input(LearningRate) of ProximalAdagradOp should not be null.");
36-
37-
PADDLE_ENFORCE(ctx->HasOutput("ParamOut"),
38-
"Output(ParamOut) of ProximalAdagradOp should not be null.");
39-
PADDLE_ENFORCE(
40-
ctx->HasOutput("MomentOut"),
41-
"Output(MomentOut) of ProximalAdagradOp should not be null.");
27+
OP_INOUT_CHECK(ctx->HasInput("Param"), "Input", "Param",
28+
"ProximalAdagradOp");
29+
OP_INOUT_CHECK(ctx->HasInput("Moment"), "Input", "Moment",
30+
"ProximalAdagradOp");
31+
OP_INOUT_CHECK(ctx->HasInput("Grad"), "Input", "Grad", "ProximalAdagradOp");
32+
OP_INOUT_CHECK(ctx->HasInput("LearningRate"), "Input", "LearningRate",
33+
"ProximalAdagradOp");
34+
35+
OP_INOUT_CHECK(ctx->HasOutput("ParamOut"), "Output", "ParamOut",
36+
"ProximalAdagradOp");
37+
OP_INOUT_CHECK(ctx->HasOutput("MomentOut"), "Output", "MomentOut",
38+
"ProximalAdagradOp");
4239

4340
auto param_dim = ctx->GetInputDim("Param");
44-
PADDLE_ENFORCE_EQ(
45-
param_dim, ctx->GetInputDim("Grad"),
46-
"Param and Grad of ProximalAdagrad Op must have same dimension.");
47-
48-
PADDLE_ENFORCE_EQ(
49-
param_dim, ctx->GetInputDim("Moment"),
50-
"Param and Moment of ProximalAdagrad Op must have same dimension.");
41+
PADDLE_ENFORCE_EQ(param_dim, ctx->GetInputDim("Grad"),
42+
platform::errors::InvalidArgument(
43+
"The shape of Intput(Param) should be equal to the "
44+
"Input(Grad) of ProximalAdagrad Op. But received "
45+
"Input(Param).dimensions=[%s], "
46+
"Input(Grad).dimensions=[%s]",
47+
param_dim, ctx->GetInputDim("Grad")));
48+
49+
PADDLE_ENFORCE_EQ(param_dim, ctx->GetInputDim("Moment"),
50+
platform::errors::InvalidArgument(
51+
"The shape of Intput(Param) should be equal to the "
52+
"Input(Moment) of ProximalAdagrad Op. But received "
53+
"Input(Param).dimensions=[%s], "
54+
"Input(Moment).dimensions=[%s]",
55+
param_dim, ctx->GetInputDim("Moment")));
5156

5257
auto lr_dim = ctx->GetInputDim("LearningRate");
53-
PADDLE_ENFORCE_EQ(framework::product(lr_dim), 1,
54-
"Learning Rate should be a scalar.");
58+
PADDLE_ENFORCE_EQ(
59+
framework::product(lr_dim), 1,
60+
platform::errors::InvalidArgument(
61+
"Learning Rate should be a scalar. But received dimension[%s]",
62+
lr_dim));
5563

5664
ctx->SetOutputDim("ParamOut", param_dim);
5765
ctx->SetOutputDim("MomentOut", param_dim);

paddle/fluid/operators/optimizers/proximal_gd_op.cc

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,29 @@ class ProximalGDOp : public framework::OperatorWithKernel {
2424

2525
protected:
2626
void InferShape(framework::InferShapeContext *ctx) const override {
27-
PADDLE_ENFORCE(ctx->HasInput("Param"),
28-
"Input(Param) of ProximalGDOp should not be null.");
29-
PADDLE_ENFORCE(ctx->HasInput("Grad"),
30-
"Input(Grad) of ProximalGDOp should not be null.");
31-
PADDLE_ENFORCE(ctx->HasInput("LearningRate"),
32-
"Input(LearningRate) of ProximalGDOp should not be null.");
27+
OP_INOUT_CHECK(ctx->HasInput("Param"), "Input", "Param", "ProximalGDOp");
28+
OP_INOUT_CHECK(ctx->HasInput("Grad"), "Input", "Grad", "ProximalGDOp");
29+
OP_INOUT_CHECK(ctx->HasInput("LearningRate"), "Input", "LearningRate",
30+
"ProximalGDOp");
3331

34-
PADDLE_ENFORCE(ctx->HasOutput("ParamOut"),
35-
"Output(ParamOut) of ProximalGDOp should not be null.");
32+
OP_INOUT_CHECK(ctx->HasOutput("ParamOut"), "Output", "Paramout",
33+
"ProximalGDOp");
3634

3735
auto param_dim = ctx->GetInputDim("Param");
3836
PADDLE_ENFORCE_EQ(param_dim, ctx->GetInputDim("Grad"),
39-
"Two input of ProximalGD Op's dimension must be same.");
37+
platform::errors::InvalidArgument(
38+
"The shape of Intput(Param) should be equal to the "
39+
"Input(Grad) of ProximalGD Op. But received "
40+
"Input(Param).dimensions=[%s], "
41+
"Input(Grad).dimensions=[%s]",
42+
param_dim, ctx->GetInputDim("Grad")));
4043

4144
auto lr_dim = ctx->GetInputDim("LearningRate");
42-
PADDLE_ENFORCE_EQ(framework::product(lr_dim), 1,
43-
"Learning Rate should be a scalar.");
45+
PADDLE_ENFORCE_EQ(
46+
framework::product(lr_dim), 1,
47+
platform::errors::InvalidArgument(
48+
"Learning Rate should be a scalar. But received dimmensions:[%s]",
49+
lr_dim));
4450

4551
ctx->SetOutputDim("ParamOut", param_dim);
4652
}

0 commit comments

Comments
 (0)