From dae249b1cbb57e1e148788df5fb6b048404a4b00 Mon Sep 17 00:00:00 2001 From: Liu Yiqun Date: Fri, 15 Sep 2017 10:01:11 +0000 Subject: [PATCH] Delete USE_OP statements and add more ENFORCE statements to check the inputs and outputs in FCOp. --- paddle/operators/fc_op.cc | 23 +++++++++++++++++------ paddle/operators/identity_op.cc | 4 ++-- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/paddle/operators/fc_op.cc b/paddle/operators/fc_op.cc index 5549a836c9..e5d0f3c372 100644 --- a/paddle/operators/fc_op.cc +++ b/paddle/operators/fc_op.cc @@ -24,6 +24,15 @@ class FCOp : public NetOp { const framework::VariableNameMap &outputs, const framework::AttributeMap &attrs) : NetOp(type, inputs, outputs, attrs) { + PADDLE_ENFORCE(!Inputs("X").empty(), + "Inputs(X) of FCOp should not be null."); + PADDLE_ENFORCE(!Inputs("W").empty(), + "Inputs(W) of FCOp should not be null."); + PADDLE_ENFORCE(!Outputs("MulOut").empty(), + "Outputs(MulOut) of FCOp should not be null."); + PADDLE_ENFORCE_NE(Output("Out"), framework::kEmptyVarName, + "Output(Out) of FCOp should not be null."); + auto x = Inputs("X"); auto w = Inputs("W"); auto mul_out = Outputs("MulOut"); @@ -68,6 +77,10 @@ class FCOp : public NetOp { // sum_out = X[0] * W[0] + ... + X[n-1] * W[n-1] auto sum_out = mul_out[0]; if (n > 1) { + PADDLE_ENFORCE_NE(Output("SumOut"), framework::kEmptyVarName, + "Output(SumOut) of FCOp should not be null when the " + "size of Inputs(X) > 1."); + sum_out = Output("SumOut"); AppendOp(framework::OpRegistry::CreateOp("sum", {{"X", {mul_out}}}, {{"Out", {sum_out}}}, {})); @@ -81,6 +94,10 @@ class FCOp : public NetOp { auto b = Input("B"); auto add_out = sum_out; if (b != framework::kEmptyVarName) { + PADDLE_ENFORCE_NE( + Output("AddOut"), framework::kEmptyVarName, + "Output(AddOut) of FCOp should not be null when Input(B) is set."); + add_out = Output("AddOut"); AppendOp(framework::OpRegistry::CreateOp( "rowwise_add", {{"X", {sum_out}}, {"b", {Input("B")}}}, @@ -176,11 +193,5 @@ Activation type can be set to `identity` (default), `sigmoid` or `softmax`. } // namespace operators } // namespace paddle -USE_OP(mul); -USE_OP(rowwise_add); -USE_NO_KERNEL_OP(identity); -USE_OP(sigmoid); -USE_OP(softmax); - namespace ops = paddle::operators; REGISTER_OP_WITHOUT_GRADIENT(fc, ops::FCOp, ops::FCOpMaker); diff --git a/paddle/operators/identity_op.cc b/paddle/operators/identity_op.cc index 5ab8c0fadc..2cc632205e 100644 --- a/paddle/operators/identity_op.cc +++ b/paddle/operators/identity_op.cc @@ -44,8 +44,8 @@ class IdentityOp : public NetOp { : NetOp(type, inputs, outputs, attrs) { PADDLE_ENFORCE_NE(Input("X"), framework::kEmptyVarName, "Input(X) of IdentityOp should not be null."); - PADDLE_ENFORCE_NE(Output("Out"), framework::kEmptyVarName, - "Output(Out) of IdentityOp should not be null."); + PADDLE_ENFORCE_NE(Output("Y"), framework::kEmptyVarName, + "Output(Y) of IdentityOp should not be null."); AppendOp(framework::OpRegistry::CreateOp( "scale", {{"X", {Input("X")}}}, {{"Out", {Output("Y")}}}, -- GitLab