diff --git a/paddle/operators/rowwise_add_op.cc b/paddle/operators/rowwise_add_op.cc index 82e5df591d0e596831d409aadbc816bb8e59d18e..f07dd8f602cda2ba1ef02e6c6b736018288bbd9f 100644 --- a/paddle/operators/rowwise_add_op.cc +++ b/paddle/operators/rowwise_add_op.cc @@ -63,6 +63,7 @@ class RowwiseAddGradOp : public framework::OperatorWithKernel { "Input(Out@GRAD) should not be null"); auto dims0 = ctx.Input("X")->dims(); auto dims1 = ctx.Input("b")->dims(); + PADDLE_ENFORCE_EQ(1, framework::product(dims1), "b dims should be 1") ctx.Output(framework::GradVarName("X"))->Resize(dims0); ctx.Output(framework::GradVarName("b"))->Resize(dims1); } diff --git a/python/paddle/v2/framework/tests/test_rowwise_add_op.py b/python/paddle/v2/framework/tests/test_rowwise_add_op.py index 8118d2d7418ed74dea6cf03bf820f97d17b8995d..29d72e850099734a9828ccceed47cc0a57fc3d6b 100644 --- a/python/paddle/v2/framework/tests/test_rowwise_add_op.py +++ b/python/paddle/v2/framework/tests/test_rowwise_add_op.py @@ -21,12 +21,10 @@ class RowwiseAddGradOpTest(GradientChecker): op = create_op("rowwise_add") inputs = { "X": np.random.uniform(0.1, 1, [10, 10]).astype("float32"), - "b": np.random.uniform(0.1, 1, [10, 1]).astype("float32") + "b": np.random.uniform(0.1, 1, [10]).astype("float32") } self.check_grad(op, inputs, set(["X", "b"]), "Out") -#TODO(dzh): rowwise_grad check - if __name__ == '__main__': unittest.main()