Skip to content

Commit

Permalink
Merge pull request PaddlePaddle#4514 from reyoung/feature/remove_add_op
Browse files Browse the repository at this point in the history
Remove add_op since it can be replaced by sum_op
  • Loading branch information
reyoung authored Sep 30, 2017
2 parents f76b38c + 6164b89 commit 0900aed
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 216 deletions.
2 changes: 1 addition & 1 deletion paddle/framework/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ cc_test(operator_test SRCS operator_test.cc DEPS operator op_registry)
cc_library(grad_op_builder SRCS grad_op_builder.cc DEPS operator proto_desc)
cc_library(op_registry SRCS op_registry.cc DEPS grad_op_builder op_proto_maker op_info)
cc_test(op_registry_test SRCS op_registry_test.cc DEPS op_registry)
cc_test(grad_op_builder_test SRCS grad_op_builder_test.cc DEPS grad_op_builder op_registry add_op)
cc_test(grad_op_builder_test SRCS grad_op_builder_test.cc DEPS grad_op_builder op_registry sum_op)

py_proto_compile(framework_py_proto SRCS framework.proto)
# Generate an empty __init__.py to make framework_py_proto as a valid python module.
Expand Down
25 changes: 16 additions & 9 deletions paddle/framework/grad_op_builder_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "paddle/framework/op_registry.h"
#include "paddle/framework/operator.h"

USE_OP(add);
USE_OP(sum);

namespace paddle {
namespace framework {
Expand Down Expand Up @@ -41,17 +41,24 @@ namespace f = paddle::framework;

TEST(GradOpBuilder, AddTwo) {
std::shared_ptr<f::OperatorBase> add_op(f::OpRegistry::CreateOp(
"add", {{"X", {"x"}}, {"Y", {"y"}}}, {{"Out", {"out"}}}, {}));
"sum", {{"X", {"x", "y"}}}, {{"Out", {"out"}}}, {}));
std::shared_ptr<f::OperatorBase> grad_add_op =
f::OpRegistry::CreateGradOp(*add_op);
EXPECT_EQ(grad_add_op->Inputs().size(), 4UL);
EXPECT_EQ(grad_add_op->Outputs().size(), 2UL);
EXPECT_EQ(grad_add_op->Input("X"), "x");
EXPECT_EQ(grad_add_op->Input("Y"), "y");
EXPECT_EQ(grad_add_op->Input("Out"), "out");

EXPECT_EQ(grad_add_op->Inputs().size(), 1UL);
EXPECT_EQ(grad_add_op->Outputs().size(), 1UL);
EXPECT_EQ(grad_add_op->Input(f::GradVarName("Out")), f::GradVarName("out"));
EXPECT_EQ(grad_add_op->Output(f::GradVarName("X")), f::GradVarName("x"));
EXPECT_EQ(grad_add_op->Output(f::GradVarName("Y")), f::GradVarName("y"));
auto &outputs = grad_add_op->Outputs(f::GradVarName("X"));
EXPECT_EQ(2UL, outputs.size());
auto in_output = [&outputs](const std::string &name) {
for (auto &output_name : outputs) {
if (output_name == name) return true;
}
return false;
};

EXPECT_TRUE(in_output(f::GradVarName("x")));
EXPECT_TRUE(in_output(f::GradVarName("y")));
}

REGISTER_OP(mult_io, f::NOP, f::MutiInOutOpMaker, mult_io_grad, f::NOP);
Expand Down
68 changes: 0 additions & 68 deletions paddle/operators/add_op.cc

This file was deleted.

18 changes: 0 additions & 18 deletions paddle/operators/add_op.cu

This file was deleted.

48 changes: 0 additions & 48 deletions paddle/operators/add_op.h

This file was deleted.

6 changes: 4 additions & 2 deletions paddle/operators/sum_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ class SumOpMaker : public framework::OpProtoAndCheckerMaker {
public:
SumOpMaker(framework::OpProto* proto, framework::OpAttrChecker* op_checker)
: OpProtoAndCheckerMaker(proto, op_checker) {
AddInput("X", "the input tensors of sum operator.").AsDuplicable();
AddOutput("Out", "the output tensor of sum operator.");
AddInput("X", "the input tensors of sum operator.")
.AsDuplicable()
.NotInGradient();
AddOutput("Out", "the output tensor of sum operator.").NotInGradient();
AddComment(R"DOC(
Sum the input tensors.
Expand Down
20 changes: 0 additions & 20 deletions python/paddle/v2/framework/tests/test_add_op.py

This file was deleted.

46 changes: 0 additions & 46 deletions python/paddle/v2/framework/tests/test_gradient_checker.py

This file was deleted.

4 changes: 2 additions & 2 deletions python/paddle/v2/framework/tests/test_net.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def fc(X, W, Y):
class TestNet(unittest.TestCase):
def test_net_all(self):
net = core.Net.create()
op1 = Operator("add", X="X", Y="Y", Out="Out")
op1 = Operator("sum", X=["X", "Y"], Out="Out")
net.append_op(op1)

net2 = core.Net.create()
Expand All @@ -26,7 +26,7 @@ def test_net_all(self):

expected = '''
Op(plain_net), inputs:{all[W, X, Y]}, outputs:{all[Out, fc.out, pre_activation]}.
Op(add), inputs:{X[X], Y[Y]}, outputs:{Out[Out]}.
Op(sum), inputs:{X[X, Y]}, outputs:{Out[Out]}.
Op(plain_net), inputs:{all[W, X]}, outputs:{all[fc.out, pre_activation]}.
Op(plain_net), inputs:{all[W, X]}, outputs:{all[fc.out, pre_activation]}.
Op(mul), inputs:{X[X], Y[W]}, outputs:{Out[pre_activation]}.
Expand Down
4 changes: 2 additions & 2 deletions python/paddle/v2/framework/tests/test_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,10 @@ def __add_attr__(name, type):

class TestOpCreations(unittest.TestCase):
def test_all(self):
add_op = op.Operator("add", X="a", Y="b", Out="z")
add_op = op.Operator("sum", X=["a", "b"], Out="z")
self.assertIsNotNone(add_op)
# Invoke C++ DebugString()
self.assertEqual('Op(add), inputs:{X[a], Y[b]}, outputs:{Out[z]}.',
self.assertEqual('Op(sum), inputs:{X[a, b]}, outputs:{Out[z]}.',
str(add_op))


Expand Down

0 comments on commit 0900aed

Please sign in to comment.