|
|
@ -3,11 +3,6 @@
|
|
|
|
#include <paddle/framework/op_registry.h>
|
|
|
|
#include <paddle/framework/op_registry.h>
|
|
|
|
#include <paddle/framework/operator.h>
|
|
|
|
#include <paddle/framework/operator.h>
|
|
|
|
|
|
|
|
|
|
|
|
USE_OP(add_two);
|
|
|
|
|
|
|
|
USE_OP(mul);
|
|
|
|
|
|
|
|
USE_OP(sigmoid);
|
|
|
|
|
|
|
|
USE_OP(softmax);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace paddle {
|
|
|
|
namespace paddle {
|
|
|
|
namespace framework {
|
|
|
|
namespace framework {
|
|
|
|
|
|
|
|
|
|
|
@ -26,6 +21,13 @@ class TestOp : public OperatorBase {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class EmptyOp : public OperatorBase {
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
void InferShape(const std::shared_ptr<Scope>& scope) const override {}
|
|
|
|
|
|
|
|
void Run(const std::shared_ptr<Scope>& scope,
|
|
|
|
|
|
|
|
const platform::DeviceContext& dev_ctx) const override {}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
template <typename T>
|
|
|
|
void AssertSameVectorWithoutOrder(const std::vector<T>& expected,
|
|
|
|
void AssertSameVectorWithoutOrder(const std::vector<T>& expected,
|
|
|
|
const std::vector<T>& actual) {
|
|
|
|
const std::vector<T>& actual) {
|
|
|
@ -72,20 +74,17 @@ TEST(OpKernel, all) {
|
|
|
|
ASSERT_THROW(net->AddOp(op2), paddle::platform::EnforceNotMet);
|
|
|
|
ASSERT_THROW(net->AddOp(op2), paddle::platform::EnforceNotMet);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//! TODO(yuyang18): Refine Backward Op.
|
|
|
|
TEST(Net, insert_op) {
|
|
|
|
// TEST(AddBackwardOp, TestGradOp) {
|
|
|
|
NetOp net;
|
|
|
|
// auto net = std::make_shared<NetOp>();
|
|
|
|
auto op1 = std::make_shared<EmptyOp>();
|
|
|
|
// ASSERT_NE(net, nullptr);
|
|
|
|
op1->inputs_ = {"x", "w1", "b1"};
|
|
|
|
// net->AddOp(framework::OpRegistry::CreateOp("mul", {"X", "Y"}, {"Out"}, {}));
|
|
|
|
op1->outputs_ = {"y"};
|
|
|
|
// net->AddOp(
|
|
|
|
net.AddOp(op1);
|
|
|
|
// framework::OpRegistry::CreateOp("add_two", {"X", "Y"}, {"Out"}, {}));
|
|
|
|
net.InsertOp(0, op1);
|
|
|
|
// net->AddOp(framework::OpRegistry::CreateOp("add_two", {"X", "Y"}, {""},
|
|
|
|
ASSERT_EQ(2UL, net.ops_.size());
|
|
|
|
// {}));
|
|
|
|
net.InsertOp(2, op1);
|
|
|
|
// auto grad_ops = AddBackwardOp(net);
|
|
|
|
ASSERT_EQ(3UL, net.ops_.size());
|
|
|
|
// for (auto& op : grad_ops->ops_) {
|
|
|
|
}
|
|
|
|
// op->DebugString();
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace framework
|
|
|
|
} // namespace framework
|
|
|
|
} // namespace paddle
|
|
|
|
} // namespace paddle
|
|
|
|