diff --git a/README.md b/README.md index a3b13fe79cc33927e5cc3e091926b111688a941b..8d89c6b1ec9e4aefbd64328dedb4e8c7cc50c21b 100644 --- a/README.md +++ b/README.md @@ -62,9 +62,9 @@ Please refer to our [release announcement](https://github.com/PaddlePaddle/Paddl ## Installation It is recommended to check out the -[Docker installation guide](http://www.paddlepaddle.org/docs/develop/documentation/en/getstarted/build_and_install/docker_install_en.html) +[Docker installation guide](http://www.paddlepaddle.org/docs/develop/documentation/fluid/en/build_and_install/docker_install_en.html) before looking into the -[build from source guide](http://www.paddlepaddle.org/docs/develop/documentation/en/getstarted/build_and_install/build_from_source_en.html). +[build from source guide](http://www.paddlepaddle.org/docs/develop/documentation/fluid/en/build_and_install/build_from_source_en.html). ## Documentation diff --git a/cmake/external/mkldnn.cmake b/cmake/external/mkldnn.cmake index 83c1cf1457dfc2d98039b7a03e8a569a0352991a..966c0bafd3742862e66d7ff36de86190507a6936 100644 --- a/cmake/external/mkldnn.cmake +++ b/cmake/external/mkldnn.cmake @@ -45,9 +45,9 @@ IF(${CBLAS_PROVIDER} STREQUAL "MKLML") ELSE() MESSAGE(FATAL_ERROR "Should enable MKLML when build MKLDNN") ENDIF() - -SET(MKLDNN_CFLAG "${CMAKE_C_FLAGS} -Wno-error=strict-overflow") -SET(MKLDNN_CXXFLAG "${CMAKE_CXX_FLAGS} -Wno-error=strict-overflow") +SET(MKLDNN_FLAG "-Wno-error=strict-overflow -Wno-error=unused-result -Wno-unused-result") +SET(MKLDNN_CFLAG "${CMAKE_C_FLAGS} ${MKLDNN_FLAG}") +SET(MKLDNN_CXXFLAG "${CMAKE_CXX_FLAGS} ${MKLDNN_FLAG}") ExternalProject_Add( ${MKLDNN_PROJECT} ${EXTERNAL_PROJECT_LOG_ARGS} @@ -61,6 +61,7 @@ ExternalProject_Add( CMAKE_ARGS -DMKLROOT=${MKLML_ROOT} CMAKE_ARGS -DCMAKE_C_FLAGS=${MKLDNN_CFLAG} CMAKE_ARGS -DCMAKE_CXX_FLAGS=${MKLDNN_CXXFLAG} + CMAKE_ARGS -DWITH_TEST=OFF -DWITH_EXAMPLE=OFF CMAKE_CACHE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${MKLDNN_INSTALL_DIR} -DMKLROOT:PATH=${MKLML_ROOT} ) diff --git a/cmake/external/mklml.cmake b/cmake/external/mklml.cmake index 796bcf28a1dfb308ccb7a2f839742c5c2fcf2002..cebde2750444c4085ebb7046e8a175cc1cc104d1 100644 --- a/cmake/external/mklml.cmake +++ b/cmake/external/mklml.cmake @@ -27,7 +27,7 @@ ENDIF() INCLUDE(ExternalProject) SET(MKLML_PROJECT "extern_mklml") -SET(MKLML_VER "mklml_lnx_2018.0.1.20171007") +SET(MKLML_VER "mklml_lnx_2018.0.3.20180406") SET(MKLML_URL "http://paddlepaddledeps.bj.bcebos.com/${MKLML_VER}.tgz") SET(MKLML_SOURCE_DIR "${THIRD_PARTY_PATH}/mklml") SET(MKLML_DOWNLOAD_DIR "${MKLML_SOURCE_DIR}/src/${MKLML_PROJECT}") diff --git a/doc/fluid/design/concepts/lod_tensor.md b/doc/fluid/design/concepts/lod_tensor.md index a88292e7888d0ebc64ee89ca315dfea38a12c71d..d606d7a790b4b0dc18553f2220d39cec8aa619ec 100644 --- a/doc/fluid/design/concepts/lod_tensor.md +++ b/doc/fluid/design/concepts/lod_tensor.md @@ -155,7 +155,7 @@ into offsets 3 2+3 4+5 1+9 2+10 3+12 ``` -so we know that the first sentence is from word 0 to word 3, and the second sentence from work 3 to word 5. +so we know that the first sentence is from word 0 to word 3, and the second sentence from word 3 to word 5. Similarly, the lengths in the top level LoD diff --git a/paddle/fluid/framework/CMakeLists.txt b/paddle/fluid/framework/CMakeLists.txt index 340b891e41671df7e61a4a66ec538d4603bb9842..ab71e0e63ce18e4f221a046eeb2c39499c1c3816 100644 --- a/paddle/fluid/framework/CMakeLists.txt +++ b/paddle/fluid/framework/CMakeLists.txt @@ -57,7 +57,7 @@ cc_library(data_transform SRCS data_transform.cc DEPS math_function tensor cc_library(attribute SRCS attribute.cc DEPS framework_proto boost) cc_test(program_desc_test SRCS program_desc_test.cc DEPS proto_desc device_context) -cc_library(op_proto_maker SRCS op_proto_maker.cc DEPS framework_proto attribute) +cc_library(op_proto_maker SRCS op_proto_maker.cc DEPS framework_proto attribute glog) cc_test(op_proto_maker_test SRCS op_proto_maker_test.cc DEPS op_proto_maker) cc_library(op_info SRCS op_info.cc DEPS attribute framework_proto) cc_library(shape_inference SRCS shape_inference.cc DEPS ddim attribute device_context) diff --git a/paddle/fluid/framework/data_device_transform_test.cu b/paddle/fluid/framework/data_device_transform_test.cu index df4caa45eba2470f7528d2fbd99cca39cae0b596..a91fe5c99d397ef1bf04f6d22e988b6d3f33e500 100644 --- a/paddle/fluid/framework/data_device_transform_test.cu +++ b/paddle/fluid/framework/data_device_transform_test.cu @@ -32,8 +32,7 @@ struct AddFunctor { class OpKernelTestProtoAndCheckerMaker : public OpProtoAndCheckerMaker { public: - OpKernelTestProtoAndCheckerMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() { AddInput("input", "input1 of test op"); AddOutput("output", "output of test op"); AddAttr("use_gpu", "force to use gpu kernel").SetDefault(false); diff --git a/paddle/fluid/framework/details/computation_op_handle.h b/paddle/fluid/framework/details/computation_op_handle.h index 36e6f1bf59a7646e1dff6c4844f2a36a5caf363a..f048f973fdeb6cf7d1485cda8cea7d530d9ba465 100644 --- a/paddle/fluid/framework/details/computation_op_handle.h +++ b/paddle/fluid/framework/details/computation_op_handle.h @@ -36,7 +36,7 @@ struct ComputationOpHandle : public OpHandleBase { protected: void RunImpl() override; - virtual bool NeedWait(VarHandleBase *in_var); + bool NeedWait(VarHandleBase *in_var) override; private: std::unique_ptr op_; diff --git a/paddle/fluid/framework/details/fetch_op_handle.h b/paddle/fluid/framework/details/fetch_op_handle.h index e696a7a9ce562e7f1b7fe6633623cb940810fbe1..e09bdd1d3338bb175c1ddae35b53f98197b68e9a 100644 --- a/paddle/fluid/framework/details/fetch_op_handle.h +++ b/paddle/fluid/framework/details/fetch_op_handle.h @@ -42,7 +42,7 @@ struct FetchOpHandle : public OpHandleBase { protected: void RunImpl() override; - virtual void WaitInputVarGenerated(const platform::Place &place); + void WaitInputVarGenerated(const platform::Place &place) override; private: FeedFetchList *data_; diff --git a/paddle/fluid/framework/details/op_registry.h b/paddle/fluid/framework/details/op_registry.h index 06603db31e0092382c0cc05482a038473d647ef1..1c4b059cd0aeff803ca7436d3f198e97a06cd012 100644 --- a/paddle/fluid/framework/details/op_registry.h +++ b/paddle/fluid/framework/details/op_registry.h @@ -95,7 +95,10 @@ struct OpInfoFiller { void operator()(const char* op_type, OpInfo* info) const { info->proto_ = new proto::OpProto; info->checker_ = new OpAttrChecker(); - auto maker = T(info->proto_, info->checker_); + T maker; + maker.SetProto(info->proto_); + maker.SetChecker(info->checker_); + maker.Make(); maker.Validate(); info->proto_->set_type(op_type); PADDLE_ENFORCE( diff --git a/paddle/fluid/framework/op_proto_maker.h b/paddle/fluid/framework/op_proto_maker.h index 0beb57ce1609d2e90c05d3255647bd321bc1f6a9..b01a520bba19c1be32363a1a5c381666c82e6afc 100644 --- a/paddle/fluid/framework/op_proto_maker.h +++ b/paddle/fluid/framework/op_proto_maker.h @@ -14,56 +14,57 @@ limitations under the License. */ #pragma once #include +#include "glog/logging.h" #include "paddle/fluid/framework/attribute.h" #include "paddle/fluid/framework/framework.pb.h" - namespace paddle { namespace framework { // this class not only make proto but also init attribute checkers. class OpProtoAndCheckerMaker { public: - using OpProto = proto::OpProto; - using OpAttrChecker = framework::OpAttrChecker; - OpProtoAndCheckerMaker(OpProto* proto, OpAttrChecker* op_checker) - : proto_(proto), op_checker_(op_checker) {} + virtual void Make() = 0; virtual ~OpProtoAndCheckerMaker() { - PADDLE_ENFORCE(validated_, "should call Validate after build"); + CHECK(validated_) << "should call Validate after build"; } + void SetProto(proto::OpProto *proto) { proto_ = proto; } + + void SetChecker(OpAttrChecker *attr_checker) { op_checker_ = attr_checker; } + void Validate(); protected: struct VariableBuilder { - OpProto::Var* var_; + proto::OpProto::Var *var_; - VariableBuilder& AsDuplicable() { + VariableBuilder &AsDuplicable() { var_->set_duplicable(true); return *this; } - VariableBuilder& AsIntermediate() { + VariableBuilder &AsIntermediate() { var_->set_intermediate(true); return *this; } - VariableBuilder& AsDispensable() { + VariableBuilder &AsDispensable() { var_->set_dispensable(true); return *this; } }; - VariableBuilder AddInput(const std::string& name, const std::string& comment); + VariableBuilder AddInput(const std::string &name, const std::string &comment); - VariableBuilder AddOutput(const std::string& name, - const std::string& comment); + VariableBuilder AddOutput(const std::string &name, + const std::string &comment); template - TypedAttrChecker& AddAttr(const std::string& name, - const std::string& comment, + TypedAttrChecker &AddAttr(const std::string &name, + const std::string &comment, bool generated = false) { - auto* attr = proto_->add_attrs(); + auto *attr = proto_->add_attrs(); attr->set_name(name); attr->set_comment(comment); attr->set_generated(generated); @@ -71,21 +72,14 @@ class OpProtoAndCheckerMaker { return op_checker_->AddAttrChecker(name); } - void AddComment(const std::string& comment) { proto_->set_comment(comment); } + void AddComment(const std::string &comment) { proto_->set_comment(comment); } private: void CheckNoDuplicatedInOutAttrs(); - OpProto* proto_; - OpAttrChecker* op_checker_; + proto::OpProto *proto_; + OpAttrChecker *op_checker_; bool validated_{false}; }; - -class NOPMaker : public OpProtoAndCheckerMaker { - public: - NOPMaker(OpProto* proto, framework::OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) {} -}; - } // namespace framework } // namespace paddle diff --git a/paddle/fluid/framework/op_proto_maker_test.cc b/paddle/fluid/framework/op_proto_maker_test.cc index a8d8c6386af940d4a14016b30de344e1c7877b22..9b5badbc81f9ddf083c81f57f5355e07a8e5e4a2 100644 --- a/paddle/fluid/framework/op_proto_maker_test.cc +++ b/paddle/fluid/framework/op_proto_maker_test.cc @@ -18,9 +18,7 @@ limitations under the License. */ class TestAttrProtoMaker : public paddle::framework::OpProtoAndCheckerMaker { public: - TestAttrProtoMaker(paddle::framework::proto::OpProto* proto, - paddle::framework::OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() { AddAttr("scale", "scale of test op"); AddAttr("scale", "scale of test op"); } @@ -29,15 +27,16 @@ class TestAttrProtoMaker : public paddle::framework::OpProtoAndCheckerMaker { TEST(ProtoMaker, DuplicatedAttr) { paddle::framework::proto::OpProto op_proto; paddle::framework::OpAttrChecker op_checker; - auto proto_maker = TestAttrProtoMaker(&op_proto, &op_checker); + TestAttrProtoMaker proto_maker; + proto_maker.SetProto(&op_proto); + proto_maker.SetChecker(&op_checker); + proto_maker.Make(); ASSERT_THROW(proto_maker.Validate(), paddle::platform::EnforceNotMet); } class TestInOutProtoMaker : public paddle::framework::OpProtoAndCheckerMaker { public: - TestInOutProtoMaker(paddle::framework::proto::OpProto* proto, - paddle::framework::OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() { AddInput("input", "input of test op"); AddInput("input", "input of test op"); } @@ -46,6 +45,9 @@ class TestInOutProtoMaker : public paddle::framework::OpProtoAndCheckerMaker { TEST(ProtoMaker, DuplicatedInOut) { paddle::framework::proto::OpProto op_proto; paddle::framework::OpAttrChecker op_checker; - auto proto_maker = TestInOutProtoMaker(&op_proto, &op_checker); + TestAttrProtoMaker proto_maker; + proto_maker.SetProto(&op_proto); + proto_maker.SetChecker(&op_checker); + proto_maker.Make(); ASSERT_THROW(proto_maker.Validate(), paddle::platform::EnforceNotMet); } diff --git a/paddle/fluid/framework/op_registry_test.cc b/paddle/fluid/framework/op_registry_test.cc index 6dc4cf261bad3c004aa53fba5502fe166e3a47f7..18b1649cc71d5edd5b07740bbad1fe8f81128898 100644 --- a/paddle/fluid/framework/op_registry_test.cc +++ b/paddle/fluid/framework/op_registry_test.cc @@ -33,8 +33,7 @@ class CosineOp : public OperatorBase { class CosineOpProtoAndCheckerMaker : public OpProtoAndCheckerMaker { public: - CosineOpProtoAndCheckerMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() { AddInput("input", "input of cosine op"); AddOutput("output", "output of cosine op"); AddAttr("scale", "scale of cosine op") @@ -55,8 +54,7 @@ class MyTestOp : public OperatorBase { class MyTestOpProtoAndCheckerMaker : public OpProtoAndCheckerMaker { public: - MyTestOpProtoAndCheckerMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() { AddInput("input", "input of cosine op").AsDuplicable(); AddOutput("output", "output of cosine op").AsIntermediate(); auto my_checker = [](int i) { @@ -212,10 +210,7 @@ namespace framework { class OpKernelTestMaker : public OpProtoAndCheckerMaker { public: - OpKernelTestMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { - AddComment("NoGradOp, same input output. no Grad"); - } + void Make() { AddComment("NoGradOp, same input output. no Grad"); } }; class OpWithKernelTest : public OperatorWithKernel { @@ -275,9 +270,9 @@ TEST(OperatorRegistrar, CUDA) { static int op_test_value = 0; -using paddle::platform::DeviceContext; using paddle::platform::CPUDeviceContext; using paddle::platform::CUDADeviceContext; +using paddle::platform::DeviceContext; namespace paddle { namespace framework { diff --git a/paddle/fluid/framework/operator_test.cc b/paddle/fluid/framework/operator_test.cc index 1bf8c81469bb4afdd00921cfa0acf6089dedbbaa..74043b5d7990178976baf2fad991ae03f9c8dd25 100644 --- a/paddle/fluid/framework/operator_test.cc +++ b/paddle/fluid/framework/operator_test.cc @@ -46,8 +46,7 @@ class OpWithoutKernelTest : public OperatorBase { class OpWithoutKernelCheckerMaker : public OpProtoAndCheckerMaker { public: - OpWithoutKernelCheckerMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() { AddInput("input", "input of test op"); AddOutput("output", "output of test op"); AddAttr("scale", "scale of cosine op"); @@ -98,8 +97,7 @@ namespace framework { class OpKernelTestProtoAndCheckerMaker : public OpProtoAndCheckerMaker { public: - OpKernelTestProtoAndCheckerMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() { AddInput("x", "input of test op"); AddOutput("y", "output of test op"); AddAttr("scale", "scale of cosine op") @@ -137,9 +135,7 @@ class CPUKernelTest : public OpKernel { class OpKernelTestMultiInputsProtoAndCheckerMaker : public OpProtoAndCheckerMaker { public: - OpKernelTestMultiInputsProtoAndCheckerMaker(OpProto* proto, - OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() { AddInput("xs", "inputs of test op").AsDuplicable(); AddInput("k", "input of test op"); AddOutput("ys", "outputs of test op").AsDuplicable(); diff --git a/paddle/fluid/framework/var_type_inference_test.cc b/paddle/fluid/framework/var_type_inference_test.cc index 9e33003b442762210c990b35f30bc3524963b8b4..14b81ddfecb8c996ae8709910c022a074e91eb3c 100644 --- a/paddle/fluid/framework/var_type_inference_test.cc +++ b/paddle/fluid/framework/var_type_inference_test.cc @@ -24,8 +24,7 @@ namespace framework { class SumOpMaker : public OpProtoAndCheckerMaker { public: - SumOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() { AddInput("X", "").AsDuplicable(); AddOutput("Out", ""); AddComment(""); diff --git a/paddle/fluid/operators/CMakeLists.txt b/paddle/fluid/operators/CMakeLists.txt index 256aded8ca234a24229e11f27b9e3e25728ad293..fbeacb66cefab84c342ee11bcb7bf0fd55da0645 100644 --- a/paddle/fluid/operators/CMakeLists.txt +++ b/paddle/fluid/operators/CMakeLists.txt @@ -166,6 +166,8 @@ function(op_library TARGET) # NOTE(*): activation use macro to regist the kernels, set use_op manually. if(${TARGET} STREQUAL "activation") file(APPEND ${pybind_file} "USE_OP(relu);\n") + elseif(${TARGET} STREQUAL "reduce") + file(APPEND ${pybind_file} "USE_OP(reduce_sum);\n") else() file(APPEND ${pybind_file} "USE_OP(${TARGET});\n") endif() diff --git a/paddle/fluid/operators/accuracy_op.cc b/paddle/fluid/operators/accuracy_op.cc index ac10d759fecb56635d1303fd383a5f9ea18f0a4d..42fcace17926641b5caf677eb3c8ba5222e37190 100644 --- a/paddle/fluid/operators/accuracy_op.cc +++ b/paddle/fluid/operators/accuracy_op.cc @@ -63,8 +63,7 @@ class AccuracyOp : public framework::OperatorWithKernel { class AccuracyOpMaker : public framework::OpProtoAndCheckerMaker { public: - AccuracyOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { // TODO(typhoonzero): support both inference value and indices. AddInput("Out", "The network output of topk (inferences)"); AddInput("Indices", "The the network output of topk (indices)"); diff --git a/paddle/fluid/operators/activation_op.cc b/paddle/fluid/operators/activation_op.cc index 87ef55c50b0be46492a695928625d140345d415d..55482abdf09516077a94ca99140ae7961f0915aa 100644 --- a/paddle/fluid/operators/activation_op.cc +++ b/paddle/fluid/operators/activation_op.cc @@ -19,19 +19,18 @@ limitations under the License. */ namespace paddle { namespace operators { -#define REGISTER_ACTIVATION_OP_MAKER(OP_NAME, OP_COMMENT) \ - class OP_NAME##OpMaker \ - : public ::paddle::framework::OpProtoAndCheckerMaker { \ - public: \ - OP_NAME##OpMaker(OpProto *proto, OpAttrChecker *op_checker) \ - : ::paddle::framework::OpProtoAndCheckerMaker(proto, op_checker) { \ - AddInput("X", "Input of " #OP_NAME "operator"); \ - AddOutput("Out", "Output of" #OP_NAME "operator"); \ - AddAttr("use_mkldnn", \ - "(bool, default false) Only used in mkldnn kernel") \ - .SetDefault(false); \ - AddComment(#OP_COMMENT); \ - } \ +#define REGISTER_ACTIVATION_OP_MAKER(OP_NAME, OP_COMMENT) \ + class OP_NAME##OpMaker \ + : public ::paddle::framework::OpProtoAndCheckerMaker { \ + public: \ + void Make() override { \ + AddInput("X", "Input of " #OP_NAME "operator"); \ + AddOutput("Out", "Output of" #OP_NAME "operator"); \ + AddAttr("use_mkldnn", \ + "(bool, default false) Only used in mkldnn kernel") \ + .SetDefault(false); \ + AddComment(#OP_COMMENT); \ + } \ } #define REGISTER_ACTIVATION_OP_GRAD_MAKER(OP_NAME, KERNEL_TYPE) \ @@ -204,8 +203,7 @@ $$out = \frac{x}{1 + |x|}$$ class LeakyReluOpMaker : public framework::OpProtoAndCheckerMaker { public: - LeakyReluOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : framework::OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "Input of LeakyRelu operator"); AddOutput("Out", "Output of LeakyRelu operator"); AddAttr("alpha", "The small negative slope").SetDefault(0.02f); @@ -220,8 +218,7 @@ $out = \max(x, \alpha * x)$ class SoftShrinkOpMaker : public framework::OpProtoAndCheckerMaker { public: - SoftShrinkOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : framework::OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "Input of Softshrink operator"); AddOutput("Out", "Output of Softshrink operator"); AddAttr("lambda", "non-negative offset").SetDefault(0.5f); @@ -242,8 +239,7 @@ $$ class HardShrinkOpMaker : public framework::OpProtoAndCheckerMaker { public: - HardShrinkOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : framework::OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "Input of HardShrink operator"); AddOutput("Out", "Output of HardShrink operator"); AddAttr("threshold", "The value of threshold for HardShrink") @@ -265,8 +261,7 @@ $$ class BReluOpMaker : public framework::OpProtoAndCheckerMaker { public: - BReluOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : framework::OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "Input of BRelu operator"); AddOutput("Out", "Output of BRelu operator"); AddAttr("t_min", "The min marginal value of BRelu") @@ -284,8 +279,7 @@ $out = \max(\min(x, t_{min}), t_{max})$ class SoftReluOpMaker : public framework::OpProtoAndCheckerMaker { public: - SoftReluOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : framework::OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "Input of SoftRelu operator"); AddOutput("Out", "Output of SoftRelu operator"); AddAttr("threshold", "The threshold value of SoftRelu") @@ -301,8 +295,7 @@ $out = \ln(1 + \exp(\max(\min(x, threshold), threshold))$ class ELUOpMaker : public framework::OpProtoAndCheckerMaker { public: - ELUOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : framework::OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "Input of ELU operator"); AddOutput("Out", "Output of ELU operator"); AddAttr("alpha", "The alpha value of ELU").SetDefault(1.0f); @@ -320,8 +313,7 @@ $out = \max(0, x) + \min(0, \alpha * (e^x - 1))$ class Relu6OpMaker : public framework::OpProtoAndCheckerMaker { public: - Relu6OpMaker(OpProto *proto, OpAttrChecker *op_checker) - : framework::OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "Input of Relu6 operator"); AddOutput("Out", "Output of Relu6 operator"); AddAttr("threshold", "The threshold value of Relu6") @@ -337,8 +329,7 @@ $out = \min(\max(0, x), 6)$ class PowOpMaker : public framework::OpProtoAndCheckerMaker { public: - PowOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : framework::OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "Input of Pow operator"); AddOutput("Out", "Output of Pow operator"); AddAttr("factor", "The exponential factor of Pow").SetDefault(1.0f); @@ -353,8 +344,7 @@ $out = x^{factor}$ class STanhOpMaker : public framework::OpProtoAndCheckerMaker { public: - STanhOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : framework::OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "Input of STanh operator"); AddOutput("Out", "Output of STanh operator"); AddAttr("scale_a", "The scale parameter of a for the input") @@ -372,8 +362,7 @@ $$out = b * \frac{e^{a * x} - e^{-a * x}}{e^{a * x} + e^{-a * x}}$$ class ThresholdedReluOpMaker : public framework::OpProtoAndCheckerMaker { public: - ThresholdedReluOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : framework::OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "Input of ThresholdedRelu operator"); AddOutput("Out", "Output of ThresholdedRelu operator"); AddAttr("threshold", "The threshold location of activation") @@ -394,8 +383,7 @@ $$ class HardSigmoidOpMaker : public framework::OpProtoAndCheckerMaker { public: - HardSigmoidOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : framework::OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "Input of HardSigmoid operator"); AddOutput("Out", "Output of HardSigmoid operator"); AddAttr("slope", "Slope for linear approximation of sigmoid") @@ -420,8 +408,7 @@ It is recommended to use the defaults for this activation. class SwishOpMaker : public framework::OpProtoAndCheckerMaker { public: - SwishOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : framework::OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "Input of Swish operator"); AddOutput("Out", "Output of Swish operator"); AddAttr("beta", "Constant beta of swish operator").SetDefault(1.0f); diff --git a/paddle/fluid/operators/adadelta_op.cc b/paddle/fluid/operators/adadelta_op.cc index 7bdb3f274aa9bacb6b261e0d0cd00b72f1d409ae..d1970515f58969948b1d2db5847e4344112f77f9 100644 --- a/paddle/fluid/operators/adadelta_op.cc +++ b/paddle/fluid/operators/adadelta_op.cc @@ -66,8 +66,7 @@ class AdadeltaOp : public framework::OperatorWithKernel { class AdadeltaOpMaker : public framework::OpProtoAndCheckerMaker { public: - AdadeltaOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("Param", "(Tensor) Input parameter"); AddInput("Grad", "(Tensor) Input gradient"); AddInput("AvgSquaredGrad", "(Tensor) Input average of squared gradient"); diff --git a/paddle/fluid/operators/adagrad_op.cc b/paddle/fluid/operators/adagrad_op.cc index 1227129429addb0ed412c7f1755fd39c9ca77157..a3ef9ad9f91f1f626bd33876693ecc17ad76b96b 100644 --- a/paddle/fluid/operators/adagrad_op.cc +++ b/paddle/fluid/operators/adagrad_op.cc @@ -67,8 +67,7 @@ class AdagradOp : public framework::OperatorWithKernel { class AdagradOpMaker : public framework::OpProtoAndCheckerMaker { public: - AdagradOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("Param", "(Tensor) Input parameter"); AddInput("Grad", "(Tensor) Input gradient"); AddInput("Moment", "(Tensor) Second moment"); diff --git a/paddle/fluid/operators/adam_op.cc b/paddle/fluid/operators/adam_op.cc index f12f0c6663d1785b8af852244ffe32358fb1b693..99b0239855d6241b064a5883c2be3d58078b3b61 100644 --- a/paddle/fluid/operators/adam_op.cc +++ b/paddle/fluid/operators/adam_op.cc @@ -80,8 +80,7 @@ class AdamOp : public framework::OperatorWithKernel { class AdamOpMaker : public framework::OpProtoAndCheckerMaker { public: - AdamOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("Param", "(Tensor) Input parameter"); AddInput("Grad", "(Tensor) Input gradient"); AddInput("LearningRate", "(Tensor) Learning rate"); diff --git a/paddle/fluid/operators/adamax_op.cc b/paddle/fluid/operators/adamax_op.cc index 608b855d58a2f701fbb8631cb5f24768a61f3deb..32062574bcf71ff96e451eaa6865b6bbfc3b1c80 100644 --- a/paddle/fluid/operators/adamax_op.cc +++ b/paddle/fluid/operators/adamax_op.cc @@ -74,8 +74,7 @@ class AdamaxOp : public framework::OperatorWithKernel { class AdamaxOpMaker : public framework::OpProtoAndCheckerMaker { public: - AdamaxOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("Param", "(Tensor) Input parameter"); AddInput("Grad", "(Tensor) Input gradient"); AddInput("LearningRate", "(Tensor) Learning rate"); diff --git a/paddle/fluid/operators/array_to_lod_tensor_op.cc b/paddle/fluid/operators/array_to_lod_tensor_op.cc index 5db2e4540ef170079328f24ac8d30f7b1901fa1e..149226e92d4d08a25c211bce686ff03c5d7ddf40 100644 --- a/paddle/fluid/operators/array_to_lod_tensor_op.cc +++ b/paddle/fluid/operators/array_to_lod_tensor_op.cc @@ -123,8 +123,7 @@ class ArrayToLoDTensorOp : public framework::OperatorBase { class ArrayToLoDTensorOpProtoMaker : public framework::OpProtoAndCheckerMaker { public: - ArrayToLoDTensorOpProtoMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "(std::vector) A vector of tensors that is going to " "be casted to a big LoDTensor."); diff --git a/paddle/fluid/operators/assign_op.cc b/paddle/fluid/operators/assign_op.cc index d372213e1b6008b0c4227103dd40730f86a84301..d9294048a9e89662958fd5c6af4fcbe5da3814c2 100644 --- a/paddle/fluid/operators/assign_op.cc +++ b/paddle/fluid/operators/assign_op.cc @@ -94,8 +94,7 @@ class AssignOp : public framework::OperatorBase { class AssignOpProtoMaker : public framework::OpProtoAndCheckerMaker { public: - AssignOpProtoMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "(LoDTensor, SelectedRows or LoDTensorArray) The input variable " "could be LoDTensor, SelectedRows or LoDTensorArray.") diff --git a/paddle/fluid/operators/assign_value_op.cc b/paddle/fluid/operators/assign_value_op.cc index 993610fdedde4bafd99f59a0adeeeef4526eb089..4ad6f3443db33fd14b67091d14fd877b951730ff 100644 --- a/paddle/fluid/operators/assign_value_op.cc +++ b/paddle/fluid/operators/assign_value_op.cc @@ -45,8 +45,7 @@ class AssignValueOp : public framework::OperatorWithKernel { class AssignValueOpMaker : public framework::OpProtoAndCheckerMaker { public: - AssignValueOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddOutput("Out", "(Tensor) Output tensor of assign_value operator."); AddAttr>("shape", "(vector) " diff --git a/paddle/fluid/operators/auc_op.cc b/paddle/fluid/operators/auc_op.cc index a168eaeab56128b75bbe97d7ccf843a081b5dced..c9871a9fe6b3b0d0cf671c2d155715f92c94fd8f 100644 --- a/paddle/fluid/operators/auc_op.cc +++ b/paddle/fluid/operators/auc_op.cc @@ -50,8 +50,7 @@ class AucOp : public framework::OperatorWithKernel { class AucOpMaker : public framework::OpProtoAndCheckerMaker { public: - AucOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("Out", "A floating point 2D tensor, values are in the range [0, 1]." "Each row is sorted in descending order. This input should be the" diff --git a/paddle/fluid/operators/average_accumulates_op.cc b/paddle/fluid/operators/average_accumulates_op.cc index b21deaf9258567c05a8816b14ac7d6462964e8ba..25864e95d7e290c7f684501893e99c828c511979 100644 --- a/paddle/fluid/operators/average_accumulates_op.cc +++ b/paddle/fluid/operators/average_accumulates_op.cc @@ -111,8 +111,7 @@ class AverageAccumulatesOp : public framework::OperatorWithKernel { class AverageAccumulatesOpMaker : public framework::OpProtoAndCheckerMaker { public: - AverageAccumulatesOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("param", "(Tensor), The parameter to be accumulated."); AddInput("in_sum_1", "(Tensor), A tensor used to store the parameter " diff --git a/paddle/fluid/operators/batch_norm_op.cc b/paddle/fluid/operators/batch_norm_op.cc index b4bd40d0311bf10ec1fddabab2ee131fe02baf52..6ec8c9d18b466142acdb46b0f46826a2aca7a47e 100644 --- a/paddle/fluid/operators/batch_norm_op.cc +++ b/paddle/fluid/operators/batch_norm_op.cc @@ -126,8 +126,7 @@ class BatchNormOp : public framework::OperatorWithKernel { class BatchNormOpMaker : public framework::OpProtoAndCheckerMaker { public: - BatchNormOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddAttr("is_test", "").SetDefault(false); AddAttr("momentum", "").SetDefault(0.9); AddAttr("epsilon", "") diff --git a/paddle/fluid/operators/batch_size_like.h b/paddle/fluid/operators/batch_size_like.h index dd51a11fbe6ad5e528197b67536518c4b31fa355..483c9f8c2191fa4eb98b91112f9d6753e2fbddc3 100644 --- a/paddle/fluid/operators/batch_size_like.h +++ b/paddle/fluid/operators/batch_size_like.h @@ -53,8 +53,7 @@ class BatchSizeLikeOp : public framework::OperatorWithKernel { class BatchSizeLikeOpMaker : public framework::OpProtoAndCheckerMaker { public: - BatchSizeLikeOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : framework::OpProtoAndCheckerMaker(proto, op_checker) { + void Make() final { AddInput("Input", "(Tensor) Tensor " "whose input_dim_idx'th dimension specifies the batch_size"); @@ -68,7 +67,11 @@ class BatchSizeLikeOpMaker : public framework::OpProtoAndCheckerMaker { AddAttr("output_dim_idx", "(int, default 0) The index of output's batch size dimension") .SetDefault(0); + Apply(); } + + protected: + virtual void Apply() = 0; }; } // namespace operators diff --git a/paddle/fluid/operators/beam_search_decode_op.cc b/paddle/fluid/operators/beam_search_decode_op.cc index 68fb988afd8af4e9ac3acb4506c1c31fcf85e5a3..c3dd22119ddab8ecf9213ee274e4cbd4f05e78fd 100644 --- a/paddle/fluid/operators/beam_search_decode_op.cc +++ b/paddle/fluid/operators/beam_search_decode_op.cc @@ -134,8 +134,7 @@ class BeamSearchDecodeOp : public framework::OperatorBase { class BeamSearchDecodeOpProtoMaker : public framework::OpProtoAndCheckerMaker { public: - BeamSearchDecodeOpProtoMaker(OpProto* proto, OpAttrChecker* op_checker) - : framework::OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("Ids", "(LodTensorArray)" "score of the candidate words in each step"); diff --git a/paddle/fluid/operators/beam_search_op.cc b/paddle/fluid/operators/beam_search_op.cc index cff097cca13f3b92c7efe4b69259fdf7c75b3760..df0b50881f4e3ec6f57bdb2b63033931059c486e 100644 --- a/paddle/fluid/operators/beam_search_op.cc +++ b/paddle/fluid/operators/beam_search_op.cc @@ -197,8 +197,7 @@ std::string ItemToString(const BeamSearch::Item &item) { class BeamSearchOpMaker : public framework::OpProtoAndCheckerMaker { public: - BeamSearchOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { // inputs and outputs stored in proto AddInput("pre_ids", "ids in previous step"); AddInput("ids", "a LoDTensor of shape of [None,k]"); diff --git a/paddle/fluid/operators/bilinear_interp_op.cc b/paddle/fluid/operators/bilinear_interp_op.cc index 69f79bf93be8ac7df9cab43b84cf755f2f3dfeaa..d46fda54e7a9d5bc737a7ec2116daca33ffa015f 100644 --- a/paddle/fluid/operators/bilinear_interp_op.cc +++ b/paddle/fluid/operators/bilinear_interp_op.cc @@ -41,8 +41,7 @@ class BilinearInterpOp : public framework::OperatorWithKernel { class BilinearInterpOpMaker : public framework::OpProtoAndCheckerMaker { public: - BilinearInterpOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "(Tensor) The input tensor of bilinear interpolation, " "This is a 4-D tensor with shape of (N x C x h x w)"); diff --git a/paddle/fluid/operators/bilinear_tensor_product_op.cc b/paddle/fluid/operators/bilinear_tensor_product_op.cc index e910ad92d1051aa89fdb3290a977ff376378a227..8d261a118a75ee16027faf60341cefd30c3cdbba 100644 --- a/paddle/fluid/operators/bilinear_tensor_product_op.cc +++ b/paddle/fluid/operators/bilinear_tensor_product_op.cc @@ -65,8 +65,7 @@ class BilinearTensorProductOp : public framework::OperatorWithKernel { class BilinearTensorProductOpMaker : public framework::OpProtoAndCheckerMaker { public: - BilinearTensorProductOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "The first input of bilinear_tensor_product operator."); AddInput("Y", "The second input of bilinear_tensor_product operator."); AddInput("Weight", diff --git a/paddle/fluid/operators/bipartite_match_op.cc b/paddle/fluid/operators/bipartite_match_op.cc index 1218d9fdc1e6101d17bc09a4ae769f5fbf8e7b15..d437ad5c19828331c749244404ba80d0f3acda2a 100644 --- a/paddle/fluid/operators/bipartite_match_op.cc +++ b/paddle/fluid/operators/bipartite_match_op.cc @@ -182,8 +182,7 @@ class BipartiteMatchKernel : public framework::OpKernel { class BipartiteMatchOpMaker : public framework::OpProtoAndCheckerMaker { public: - BipartiteMatchOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput( "DistMat", "(LoDTensor or Tensor) this input is a 2-D LoDTensor with shape " diff --git a/paddle/fluid/operators/box_coder_op.cc b/paddle/fluid/operators/box_coder_op.cc index ec416f725e75fae57484751ee8a066c0b9da8a70..ce9bf10dc3c4718c5adfc0d5034d06c22f9d54e1 100644 --- a/paddle/fluid/operators/box_coder_op.cc +++ b/paddle/fluid/operators/box_coder_op.cc @@ -60,8 +60,7 @@ class BoxCoderOp : public framework::OperatorWithKernel { class BoxCoderOpMaker : public framework::OpProtoAndCheckerMaker { public: - BoxCoderOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput( "PriorBox", "(Tensor, default Tensor) " diff --git a/paddle/fluid/operators/cast_op.cc b/paddle/fluid/operators/cast_op.cc index dd0068d571f72c9c22334e523cd091fe4c8da5a6..84660d042c7b12283fabc316d29609f5eddb825d 100644 --- a/paddle/fluid/operators/cast_op.cc +++ b/paddle/fluid/operators/cast_op.cc @@ -21,8 +21,7 @@ namespace operators { class CastOpProtoMaker : public framework::OpProtoAndCheckerMaker { public: - CastOpProtoMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "The input tensor of cast op"); AddOutput("Out", "The output tensor of cast op"); AddAttr("out_dtype", "output data type"); diff --git a/paddle/fluid/operators/channel_close_op.cc b/paddle/fluid/operators/channel_close_op.cc index 5892650c49e2e9d7345fb94465d124cff57f0a6f..8e2db250a069c488ee98f618bc03df6485022456 100644 --- a/paddle/fluid/operators/channel_close_op.cc +++ b/paddle/fluid/operators/channel_close_op.cc @@ -50,8 +50,7 @@ class ChannelCloseOpOpInferShape : public framework::InferShapeBase { class ChannelCloseOpMaker : public framework::OpProtoAndCheckerMaker { public: - ChannelCloseOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput(kChannel, "The Channel Variable that should be closed by" " the ChannelClose Op."); diff --git a/paddle/fluid/operators/channel_create_op.cc b/paddle/fluid/operators/channel_create_op.cc index b2fdfd0e1f24ed071bb57b7de8f99b2d5e1d3196..a7f59e4088e3fb328e5b5a83eed65f0f90edb9f0 100644 --- a/paddle/fluid/operators/channel_create_op.cc +++ b/paddle/fluid/operators/channel_create_op.cc @@ -91,8 +91,7 @@ class ChannelCreateOpOpInferShape : public framework::InferShapeBase { class ChannelCreateOpMaker : public framework::OpProtoAndCheckerMaker { public: - ChannelCreateOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddOutput(kOutput, "The object of a Channel type created by ChannelCreate Op."); AddAttr("capacity", "The size of the buffer of Channel.") diff --git a/paddle/fluid/operators/channel_recv_op.cc b/paddle/fluid/operators/channel_recv_op.cc index 25c5c3c95ef6899589c98570df6ecbf9b3241d89..101015e837e28b504b71d919abd5f908a102c812 100644 --- a/paddle/fluid/operators/channel_recv_op.cc +++ b/paddle/fluid/operators/channel_recv_op.cc @@ -72,8 +72,7 @@ class ChannelRecvOp : public framework::OperatorBase { class ChannelRecvOpMaker : public framework::OpProtoAndCheckerMaker { public: - ChannelRecvOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput(Channel, "(Channel) A variable which \"receives\" the a value sent" "to it by a channel_send op.") diff --git a/paddle/fluid/operators/channel_send_op.cc b/paddle/fluid/operators/channel_send_op.cc index 66d33617ede5bef8a95de14f5b447c0910fe3eb4..67d6deb511d883ac69426ddd34be2199367cd4c7 100644 --- a/paddle/fluid/operators/channel_send_op.cc +++ b/paddle/fluid/operators/channel_send_op.cc @@ -57,8 +57,7 @@ class ChannelSendOp : public framework::OperatorBase { class ChannelSendOpMaker : public framework::OpProtoAndCheckerMaker { public: - ChannelSendOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput(Channel, "(Channel) A variable which \"sends\" the passed in value to " "a listening receiver.") diff --git a/paddle/fluid/operators/chunk_eval_op.cc b/paddle/fluid/operators/chunk_eval_op.cc index 95440ff89e883e754795c67cd58a08f1131df368..62636bb2f9078768180ab1e0016e3565617d24d2 100644 --- a/paddle/fluid/operators/chunk_eval_op.cc +++ b/paddle/fluid/operators/chunk_eval_op.cc @@ -66,8 +66,7 @@ class ChunkEvalOp : public framework::OperatorWithKernel { class ChunkEvalOpMaker : public framework::OpProtoAndCheckerMaker { public: - ChunkEvalOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("Inference", "(Tensor, default: Tensor). " "Predictions from the network."); diff --git a/paddle/fluid/operators/clip_by_norm_op.cc b/paddle/fluid/operators/clip_by_norm_op.cc index f43726b4793f284f14226f90c94ac6eebf632bd5..c87bded034e382c981d119e8499d6780e288031f 100644 --- a/paddle/fluid/operators/clip_by_norm_op.cc +++ b/paddle/fluid/operators/clip_by_norm_op.cc @@ -37,8 +37,7 @@ class ClipByNormOp : public framework::OperatorWithKernel { class ClipByNormOpMaker : public framework::OpProtoAndCheckerMaker { public: - ClipByNormOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "(Tensor) The input of clip_by_norm op." "The number of dimensions must be between [1, 9]."); diff --git a/paddle/fluid/operators/clip_op.cc b/paddle/fluid/operators/clip_op.cc index c71139fc7c01a696299296e43d06cf195fb3d03f..a679f7e2536a0a44148193f423f5ffe11b5e35fc 100644 --- a/paddle/fluid/operators/clip_op.cc +++ b/paddle/fluid/operators/clip_op.cc @@ -38,8 +38,7 @@ class ClipOp : public framework::OperatorWithKernel { template class ClipOpMaker : public framework::OpProtoAndCheckerMaker { public: - ClipOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "(Tensor)The input of clip op." "The number of dimensions must be between [1, 9]."); diff --git a/paddle/fluid/operators/compare_op.cc b/paddle/fluid/operators/compare_op.cc index 3a6a357e81949014a70e5bae1ee0e1c8b9d0c2ce..3a4819f3dec9704a4a7c8910dd22e80fda082335 100644 --- a/paddle/fluid/operators/compare_op.cc +++ b/paddle/fluid/operators/compare_op.cc @@ -21,8 +21,7 @@ namespace operators { template class CompareOpProtoMaker : public framework::OpProtoAndCheckerMaker { public: - CompareOpProtoMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { OpComment comment; AddInput("X", string::Sprintf("(LoDTensor) the left hand operand of %s operator", diff --git a/paddle/fluid/operators/concat_op.cc b/paddle/fluid/operators/concat_op.cc index 3bb3bd4eb15881afb5ae42beb944b76b5e8207cb..38337f9aa52435c445420047957500d21069506a 100644 --- a/paddle/fluid/operators/concat_op.cc +++ b/paddle/fluid/operators/concat_op.cc @@ -63,8 +63,7 @@ class ConcatOp : public framework::OperatorWithKernel { class ConcatOpMaker : public framework::OpProtoAndCheckerMaker { public: - ConcatOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "Input tensors of concat operator.").AsDuplicable(); AddOutput("Out", "Output tensor of concat operator."); AddAttr("axis", diff --git a/paddle/fluid/operators/conditional_block_op.cc b/paddle/fluid/operators/conditional_block_op.cc index 27f74a789beef02d31ebceb9b909e97ebd68232a..5984f80d04bdeb232f8e24264ae979725af24ef4 100644 --- a/paddle/fluid/operators/conditional_block_op.cc +++ b/paddle/fluid/operators/conditional_block_op.cc @@ -108,8 +108,7 @@ class ConditionalBlockOp : public ConditionalOp { class ConditionalBlockOpProtoMaker : public framework::OpProtoAndCheckerMaker { public: - ConditionalBlockOpProtoMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "The conditional variable of this operator. If X is empty, the " "whole sub-block will not be executed.") diff --git a/paddle/fluid/operators/conv_op.cc b/paddle/fluid/operators/conv_op.cc index 92748993c32ffb93ae25db8d9916798e657cc804..697d91484257984b104a13b0572cf19b16f8d37e 100644 --- a/paddle/fluid/operators/conv_op.cc +++ b/paddle/fluid/operators/conv_op.cc @@ -106,8 +106,7 @@ framework::OpKernelType ConvOp::GetExpectedKernelType( library); } -Conv2DOpMaker::Conv2DOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { +void Conv2DOpMaker::Make() { AddInput( "Input", "(Tensor) The input tensor of convolution operator. " @@ -200,8 +199,7 @@ $$ )DOC"); } -Conv3DOpMaker::Conv3DOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { +void Conv3DOpMaker::Make() { AddInput( "Input", "(Tensor) The input tensor of convolution operator. " diff --git a/paddle/fluid/operators/conv_op.h b/paddle/fluid/operators/conv_op.h index f462f00c0803c12ee2f2b0f94dc90afdca500da3..b3140116dfe6a17a400bb88219ff43b249ecb32a 100644 --- a/paddle/fluid/operators/conv_op.h +++ b/paddle/fluid/operators/conv_op.h @@ -60,12 +60,12 @@ inline bool IsExpand(const std::vector& filter_dim, // operator implementations can reuse the code. class Conv2DOpMaker : public framework::OpProtoAndCheckerMaker { public: - Conv2DOpMaker(OpProto* proto, OpAttrChecker* op_checker); + void Make() override; }; class Conv3DOpMaker : public framework::OpProtoAndCheckerMaker { public: - Conv3DOpMaker(OpProto* proto, OpAttrChecker* op_checker); + void Make() override; }; class ConvOp : public framework::OperatorWithKernel { diff --git a/paddle/fluid/operators/conv_shift_op.cc b/paddle/fluid/operators/conv_shift_op.cc index 82fdd308207adb159632dbb9decd67fd2d1c4646..f2549e814d6f3b5674fe2eec1139f1c3dc6fa0b4 100644 --- a/paddle/fluid/operators/conv_shift_op.cc +++ b/paddle/fluid/operators/conv_shift_op.cc @@ -75,8 +75,7 @@ class ConvShiftGradOp : public framework::OperatorWithKernel { class ConvShiftOpMaker : public framework::OpProtoAndCheckerMaker { public: - ConvShiftOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : framework::OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "(Tensor, default Tensor), a 2-D tensor with shape B x M, " "where B is the batch size and M is the data dimension."); diff --git a/paddle/fluid/operators/conv_transpose_op.cc b/paddle/fluid/operators/conv_transpose_op.cc index d699dcafa4e2c7e0a3ffb62ec3985e4961fa2133..c27c8e273168407d3aacb05cd6628887cc5760ad 100644 --- a/paddle/fluid/operators/conv_transpose_op.cc +++ b/paddle/fluid/operators/conv_transpose_op.cc @@ -84,9 +84,7 @@ framework::OpKernelType ConvTransposeOp::GetExpectedKernelType( layout_, library_); } -Conv2DTransposeOpMaker::Conv2DTransposeOpMaker(OpProto* proto, - OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { +void Conv2DTransposeOpMaker::Make() { AddInput( "Input", "(Tensor) The input tensor of convolution transpose operator. " @@ -168,9 +166,7 @@ Example: )DOC"); } -Conv3DTransposeOpMaker::Conv3DTransposeOpMaker(OpProto* proto, - OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { +void Conv3DTransposeOpMaker::Make() { AddInput("Input", "(Tensor) The input tensor of convolution transpose operator." "The format of input tensor is NCDHW. Where N is batch size, C is " diff --git a/paddle/fluid/operators/conv_transpose_op.h b/paddle/fluid/operators/conv_transpose_op.h index 898121412b17cd6fbbbeb57e9d63842e592703ac..f9d205a5b5c4cff74d02a6c89b83f7584e4a6824 100644 --- a/paddle/fluid/operators/conv_transpose_op.h +++ b/paddle/fluid/operators/conv_transpose_op.h @@ -30,12 +30,12 @@ using DDim = framework::DDim; // operator implementations can reuse the code. class Conv2DTransposeOpMaker : public framework::OpProtoAndCheckerMaker { public: - Conv2DTransposeOpMaker(OpProto* proto, OpAttrChecker* op_checker); + void Make() override; }; class Conv3DTransposeOpMaker : public framework::OpProtoAndCheckerMaker { public: - Conv3DTransposeOpMaker(OpProto* proto, OpAttrChecker* op_checker); + void Make() override; }; class ConvTransposeOp : public framework::OperatorWithKernel { diff --git a/paddle/fluid/operators/cos_sim_op.cc b/paddle/fluid/operators/cos_sim_op.cc index 04ca878e687f9b8e5239d8c4aad7e5f262fda0fa..046dd11910bb0ff46b567c3b89883582782205d3 100644 --- a/paddle/fluid/operators/cos_sim_op.cc +++ b/paddle/fluid/operators/cos_sim_op.cc @@ -62,8 +62,7 @@ class CosSimOp : public framework::OperatorWithKernel { class CosSimOpMaker : public framework::OpProtoAndCheckerMaker { public: - CosSimOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "The 1st input of cos_sim op."); AddInput("Y", "The 2nd input of cos_sim op."); AddOutput("Out", "The output of cos_sim op."); diff --git a/paddle/fluid/operators/crf_decoding_op.cc b/paddle/fluid/operators/crf_decoding_op.cc index a83013c428a77a0ead545d87852e1017bc927edf..40f43936db662f2b18ffa540da4794755b5d6fc7 100644 --- a/paddle/fluid/operators/crf_decoding_op.cc +++ b/paddle/fluid/operators/crf_decoding_op.cc @@ -18,8 +18,7 @@ namespace paddle { namespace operators { class CRFDecodingOpMaker : public framework::OpProtoAndCheckerMaker { public: - CRFDecodingOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("Emission", "(LoDTensor, default: LoDTensor). A LoDTensor with shape " "[N x D] where N is the size of the mini-batch and D is the total " diff --git a/paddle/fluid/operators/crop_op.cc b/paddle/fluid/operators/crop_op.cc index a8f1fbd529c71d1915c75fa90b7e4e8239d2fa3f..669b3bbe9df4cae1aa381184092dfa51157ab6a3 100644 --- a/paddle/fluid/operators/crop_op.cc +++ b/paddle/fluid/operators/crop_op.cc @@ -52,8 +52,7 @@ class CropOp : public framework::OperatorWithKernel { class CropOpMaker : public framework::OpProtoAndCheckerMaker { public: - CropOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "The input of pad op. " "The input should be a k-D tensor(k > 0 and k < 7)."); diff --git a/paddle/fluid/operators/cross_entropy_op.cc b/paddle/fluid/operators/cross_entropy_op.cc index 2b2a9dc8319f964875371214168ce04cb67fc818..a3bec3da45136bca5cb2763e7ffd6b67703a1813 100644 --- a/paddle/fluid/operators/cross_entropy_op.cc +++ b/paddle/fluid/operators/cross_entropy_op.cc @@ -111,8 +111,7 @@ class CrossEntropyGradientOp : public framework::OperatorWithKernel { class CrossEntropyOpMaker : public framework::OpProtoAndCheckerMaker { public: - CrossEntropyOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "(Tensor, default Tensor), a 2-D tensor with shape [N x D]," " where N is the batch size and D is the number of classes. " diff --git a/paddle/fluid/operators/ctc_align_op.cc b/paddle/fluid/operators/ctc_align_op.cc index 19e7649660edd0bc90bc6a9537b1cdbb2e7e8ebc..d2b440d9d2e50340af7a7bb4e76e55beea1bcb46 100644 --- a/paddle/fluid/operators/ctc_align_op.cc +++ b/paddle/fluid/operators/ctc_align_op.cc @@ -44,8 +44,7 @@ class CTCAlignOp : public framework::OperatorWithKernel { class CTCAlignOpMaker : public framework::OpProtoAndCheckerMaker { public: - CTCAlignOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("Input", "(LodTensor, default: LoDTensor), Its shape is " "[Lp, 1], where Lp is the sum of all input sequences' length."); diff --git a/paddle/fluid/operators/cumsum_op.cc b/paddle/fluid/operators/cumsum_op.cc index f7c516a0ba375a68e3adeb44c99f2808dc0418bb..92bb835e8f18e17ae1355fdec29f43b8ffb70460 100644 --- a/paddle/fluid/operators/cumsum_op.cc +++ b/paddle/fluid/operators/cumsum_op.cc @@ -29,8 +29,7 @@ class CumOp : public framework::OperatorWithKernel { class CumsumOpMaker : public framework::OpProtoAndCheckerMaker { public: - CumsumOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : framework::OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "Input of Cumsum operator"); AddOutput("Out", "Output of Cumsum operator"); AddAttr("axis", diff --git a/paddle/fluid/operators/decayed_adagrad_op.cc b/paddle/fluid/operators/decayed_adagrad_op.cc index 5a1315fb2a80bf7f7f57388d0d6832686442c4ff..c0f2b49a04d9e88502c4b63bca493cd2b7ad1c5c 100644 --- a/paddle/fluid/operators/decayed_adagrad_op.cc +++ b/paddle/fluid/operators/decayed_adagrad_op.cc @@ -62,8 +62,7 @@ class DecayedAdagradOp : public framework::OperatorWithKernel { class DecayedAdagradOpMaker : public framework::OpProtoAndCheckerMaker { public: - DecayedAdagradOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("Param", "(Tensor) Input parameter"); AddInput("Grad", "(Tensor) Input gradient"); AddInput("Moment", "(Tensor) Second moment"); diff --git a/paddle/fluid/operators/delete_var_op.cc b/paddle/fluid/operators/delete_var_op.cc index 1fe9404c00335edbe3594486f8c403e69f2ab08f..d7a9bfbc437dbf4c723b9c87ff62ec6b62c38638 100644 --- a/paddle/fluid/operators/delete_var_op.cc +++ b/paddle/fluid/operators/delete_var_op.cc @@ -34,8 +34,7 @@ class DeleteVarOp : public framework::OperatorBase { class DeleteVarOpInfoMaker : public framework::OpProtoAndCheckerMaker { public: - DeleteVarOpInfoMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "The input of delete op").AsDuplicable(); AddComment(R"DOC( Delete Operator. diff --git a/paddle/fluid/operators/detection_map_op.cc b/paddle/fluid/operators/detection_map_op.cc index 38f43b6d031372948bd82c686a2d9ce5f8ecd07c..0ccf701b61349274ce0627dfeaf7cfad384215cd 100644 --- a/paddle/fluid/operators/detection_map_op.cc +++ b/paddle/fluid/operators/detection_map_op.cc @@ -78,8 +78,7 @@ class DetectionMAPOp : public framework::OperatorWithKernel { class DetectionMAPOpMaker : public framework::OpProtoAndCheckerMaker { public: - DetectionMAPOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("DetectRes", "(LoDTensor) A 2-D LoDTensor with shape [M, 6] represents the " "detections. Each row has 6 values: " diff --git a/paddle/fluid/operators/dropout_op.cc b/paddle/fluid/operators/dropout_op.cc index 4ed1b548840fabd2383632beb5f35fa6aa096443..07322e720f26213ea777be3cd22f2fead28507f0 100644 --- a/paddle/fluid/operators/dropout_op.cc +++ b/paddle/fluid/operators/dropout_op.cc @@ -37,8 +37,7 @@ class DropoutOp : public framework::OperatorWithKernel { class DropoutOpMaker : public framework::OpProtoAndCheckerMaker { public: - DropoutOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "The input of dropout op."); AddOutput("Out", "The output of dropout op."); AddOutput("Mask", "The random sampled dropout mask.").AsIntermediate(); diff --git a/paddle/fluid/operators/edit_distance_op.cc b/paddle/fluid/operators/edit_distance_op.cc index c7f037d2df4372d0c4e3a261c0dff1fd6704d182..de25a3dab53492e38a92fbcf07ccbe43f7546950 100644 --- a/paddle/fluid/operators/edit_distance_op.cc +++ b/paddle/fluid/operators/edit_distance_op.cc @@ -49,8 +49,7 @@ class EditDistanceOp : public framework::OperatorWithKernel { class EditDistanceOpMaker : public framework::OpProtoAndCheckerMaker { public: - EditDistanceOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("Hyps", "(2-D LoDTensor, 2nd dim. equal to 1) " "The indices for hypothesis strings."); diff --git a/paddle/fluid/operators/elementwise_add_op.cc b/paddle/fluid/operators/elementwise_add_op.cc index 4aab54f60236ecc5fa7f70e22f1553c3bfe68198..d2c20537136fc3ac9d1bece24a2238f26215c922 100644 --- a/paddle/fluid/operators/elementwise_add_op.cc +++ b/paddle/fluid/operators/elementwise_add_op.cc @@ -14,26 +14,8 @@ limitations under the License. */ #include "paddle/fluid/operators/elementwise_add_op.h" #include "paddle/fluid/operators/elementwise_op.h" - -namespace paddle { -namespace operators { -class ElementwiseAddOpMaker : public ElementwiseOpMaker { - public: - ElementwiseAddOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : ElementwiseOpMaker(proto, op_checker) { - SetComment("Add", "Out = X + Y"); - AddComment(comment_); - } -}; -} // namespace operators -} // namespace paddle - namespace ops = paddle::operators; -REGISTER_OPERATOR(elementwise_add, ops::ElementwiseOp, - ops::ElementwiseAddOpMaker, ops::ElementwiseOpInferVarType, - paddle::framework::DefaultGradOpDescMaker); -REGISTER_OPERATOR(elementwise_add_grad, ops::ElementwiseOpGrad); - +REGISTER_ELEMWISE_OP(elementwise_add, "Add", "Out = X + Y"); REGISTER_OP_CPU_KERNEL( elementwise_add, ops::ElementwiseAddKernel, diff --git a/paddle/fluid/operators/elementwise_div_op.cc b/paddle/fluid/operators/elementwise_div_op.cc index c7ddafcad1d1f6c14791fde665f43881d6b49836..824b1221e5a77c8799dc34820b7f0db180c2439e 100644 --- a/paddle/fluid/operators/elementwise_div_op.cc +++ b/paddle/fluid/operators/elementwise_div_op.cc @@ -14,26 +14,8 @@ limitations under the License. */ #include "paddle/fluid/operators/elementwise_div_op.h" #include "paddle/fluid/operators/elementwise_op.h" - -namespace paddle { -namespace operators { -class ElementwiseDivOpMaker : public ElementwiseOpMaker { - public: - ElementwiseDivOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : ElementwiseOpMaker(proto, op_checker) { - SetComment("Div", "Out = X / Y"); - AddComment(comment_); - } -}; - -} // namespace operators -} // namespace paddle - namespace ops = paddle::operators; -REGISTER_OPERATOR(elementwise_div, ops::ElementwiseOp, - ops::ElementwiseDivOpMaker, - paddle::framework::DefaultGradOpDescMaker); -REGISTER_OPERATOR(elementwise_div_grad, ops::ElementwiseOpGrad); +REGISTER_ELEMWISE_OP(elementwise_div, "Div", "Out = X / Y"); REGISTER_OP_CPU_KERNEL( elementwise_div, ops::ElementwiseDivKernel, diff --git a/paddle/fluid/operators/elementwise_max_op.cc b/paddle/fluid/operators/elementwise_max_op.cc index a4fe386bb1907bf7c0099d2b1109077b21146948..411671335a19ae2283ca9db8b8f6bcbb6a6b630a 100644 --- a/paddle/fluid/operators/elementwise_max_op.cc +++ b/paddle/fluid/operators/elementwise_max_op.cc @@ -14,25 +14,8 @@ limitations under the License. */ #include "paddle/fluid/operators/elementwise_max_op.h" #include "paddle/fluid/operators/elementwise_op.h" - -namespace paddle { -namespace operators { -class ElementwiseMaxOpMaker : public ElementwiseOpMaker { - public: - ElementwiseMaxOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : ElementwiseOpMaker(proto, op_checker) { - SetComment("Max", "Out = max(X, Y)"); - AddComment(comment_); - } -}; -} // namespace operators -} // namespace paddle - namespace ops = paddle::operators; -REGISTER_OPERATOR(elementwise_max, ops::ElementwiseOp, - ops::ElementwiseMaxOpMaker, - paddle::framework::DefaultGradOpDescMaker); -REGISTER_OPERATOR(elementwise_max_grad, ops::ElementwiseOpGrad); +REGISTER_ELEMWISE_OP(elementwise_max, "Max", "Out = max(X, Y)"); REGISTER_OP_CPU_KERNEL( elementwise_max, ops::ElementwiseMaxKernel, diff --git a/paddle/fluid/operators/elementwise_min_op.cc b/paddle/fluid/operators/elementwise_min_op.cc index 68cd6ddb4a938b2b1c33e3f89c6d1151acb27f48..816192083d2275b26e6dd9afc76f2c021a01cf73 100644 --- a/paddle/fluid/operators/elementwise_min_op.cc +++ b/paddle/fluid/operators/elementwise_min_op.cc @@ -14,25 +14,8 @@ limitations under the License. */ #include "paddle/fluid/operators/elementwise_min_op.h" #include "paddle/fluid/operators/elementwise_op.h" - -namespace paddle { -namespace operators { -class ElementwiseMinOpMaker : public ElementwiseOpMaker { - public: - ElementwiseMinOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : ElementwiseOpMaker(proto, op_checker) { - SetComment("Max", "Out = min(X, Y)"); - AddComment(comment_); - } -}; -} // namespace operators -} // namespace paddle - namespace ops = paddle::operators; -REGISTER_OPERATOR(elementwise_min, ops::ElementwiseOp, - ops::ElementwiseMinOpMaker, - paddle::framework::DefaultGradOpDescMaker); -REGISTER_OPERATOR(elementwise_min_grad, ops::ElementwiseOpGrad); +REGISTER_ELEMWISE_OP(elementwise_min, "Min", "Out = min(X, Y)"); REGISTER_OP_CPU_KERNEL( elementwise_min, ops::ElementwiseMinKernel, diff --git a/paddle/fluid/operators/elementwise_mul_op.cc b/paddle/fluid/operators/elementwise_mul_op.cc index 2dec27136ad57ea032d5abb51799bd04ccc0b2e3..ba343909bb87b4f2efa56c0a4ff664b278e90c60 100644 --- a/paddle/fluid/operators/elementwise_mul_op.cc +++ b/paddle/fluid/operators/elementwise_mul_op.cc @@ -14,27 +14,8 @@ limitations under the License. */ #include "paddle/fluid/operators/elementwise_mul_op.h" #include "paddle/fluid/operators/elementwise_op.h" - -namespace paddle { -namespace operators { - -class ElementwiseMulOpMaker : public ElementwiseOpMaker { - public: - ElementwiseMulOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : ElementwiseOpMaker(proto, op_checker) { - SetComment("Mul", "Out = X \\odot\\ Y"); - AddComment(comment_); - } -}; - -} // namespace operators -} // namespace paddle - namespace ops = paddle::operators; -REGISTER_OPERATOR(elementwise_mul, ops::ElementwiseOp, - ops::ElementwiseMulOpMaker, - paddle::framework::DefaultGradOpDescMaker); -REGISTER_OPERATOR(elementwise_mul_grad, ops::ElementwiseOpGrad); +REGISTER_ELEMWISE_OP(elementwise_mul, "Mul", "Out = X \\odot\\ Y"); REGISTER_OP_CPU_KERNEL( elementwise_mul, ops::ElementwiseMulKernel, diff --git a/paddle/fluid/operators/elementwise_op.h b/paddle/fluid/operators/elementwise_op.h index a33634ab2503f988a8a692682ddb238d4794a3c0..d5b57cc2524efcdee112b2ce41cdcd4697fb79e6 100644 --- a/paddle/fluid/operators/elementwise_op.h +++ b/paddle/fluid/operators/elementwise_op.h @@ -54,8 +54,7 @@ class ElementwiseOpInferVarType : public framework::VarTypeInference { class ElementwiseOpMaker : public framework::OpProtoAndCheckerMaker { public: - ElementwiseOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() final { AddInput("X", "(Tensor), The first input tensor of elementwise op."); AddInput("Y", "(Tensor), The second input tensor of elementwise op."); AddOutput("Out", "The output of elementwise op."); @@ -64,12 +63,12 @@ class ElementwiseOpMaker : public framework::OpProtoAndCheckerMaker { "for broadcasting Y onto X.") .SetDefault(-1) .EqualGreaterThan(-1); - comment_ = R"DOC( -Limited Elementwise {name} Operator. + AddComment(string::Sprintf(R"DOC( +Limited Elementwise %s Operator. The equation is: -$${equation}$$ +$$%s$$ $X$ is a tensor of any dimension and the dimensions of tensor $Y$ must be smaller than or equal to the dimensions of $X$. @@ -100,26 +99,13 @@ For example Either of the inputs $X$ and $Y$ or none can carry the LoD (Level of Details) information. However, the output only shares the LoD information with input $X$. -)DOC"; - AddComment(comment_); +)DOC", + GetName(), GetEquation())); } protected: - std::string comment_; - - void Replace(std::string* src, std::string from, std::string to) { - std::size_t len_from = std::strlen(from.c_str()); - std::size_t len_to = std::strlen(to.c_str()); - for (std::size_t pos = src->find(from); pos != std::string::npos; - pos = src->find(from, pos + len_to)) { - src->replace(pos, len_from, to); - } - } - - void SetComment(std::string name, std::string equation) { - Replace(&comment_, "{name}", name); - Replace(&comment_, "{equation}", equation); - } + virtual std::string GetName() const = 0; + virtual std::string GetEquation() const = 0; }; class ElementwiseOpGrad : public framework::OperatorWithKernel { @@ -152,3 +138,16 @@ class ElementwiseOpGrad : public framework::OperatorWithKernel { }; } // namespace operators } // namespace paddle + +#define REGISTER_ELEMWISE_OP(op_type, op_name, equation) \ + class __ElemwiseOp##op_type##Maker__ \ + : public ::paddle::operators::ElementwiseOpMaker { \ + protected: \ + virtual std::string GetName() const { return op_name; } \ + virtual std::string GetEquation() const { return equation; } \ + }; \ + REGISTER_OPERATOR(op_type, ::paddle::operators::ElementwiseOp, \ + __ElemwiseOp##op_type##Maker__, \ + ::paddle::operators::ElementwiseOpInferVarType, \ + ::paddle::framework::DefaultGradOpDescMaker); \ + REGISTER_OPERATOR(op_type##_grad, ::paddle::operators::ElementwiseOpGrad) diff --git a/paddle/fluid/operators/elementwise_pow_op.cc b/paddle/fluid/operators/elementwise_pow_op.cc index 60302c5e59f8ce595861405713045b05d90002e3..5fd6bde9ba0930e29f2161f1ff23ff9f5e7dc85d 100644 --- a/paddle/fluid/operators/elementwise_pow_op.cc +++ b/paddle/fluid/operators/elementwise_pow_op.cc @@ -13,17 +13,15 @@ See the License for the specific language governing permissions and limitations under the License. */ #include "paddle/fluid/operators/elementwise_pow_op.h" +#include #include "paddle/fluid/operators/elementwise_op.h" namespace paddle { namespace operators { class ElementwisePowOpMaker : public ElementwiseOpMaker { - public: - ElementwisePowOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : ElementwiseOpMaker(proto, op_checker) { - SetComment("Pow", "Out = X ^ Y"); - AddComment(comment_); - } + protected: + std::string GetName() const override { return "Pow"; } + std::string GetEquation() const override { return "Out = X ^ Y"; } }; } // namespace operators } // namespace paddle diff --git a/paddle/fluid/operators/elementwise_sub_op.cc b/paddle/fluid/operators/elementwise_sub_op.cc index 9d0598fc39a3922fa830f18729d90a7dac6a890b..a7562b166b373ee2a8c9b6f379431d88d3e45fcb 100644 --- a/paddle/fluid/operators/elementwise_sub_op.cc +++ b/paddle/fluid/operators/elementwise_sub_op.cc @@ -14,25 +14,8 @@ limitations under the License. */ #include "paddle/fluid/operators/elementwise_sub_op.h" #include "paddle/fluid/operators/elementwise_op.h" - -namespace paddle { -namespace operators { -class ElementwiseSubOpMaker : public ElementwiseOpMaker { - public: - ElementwiseSubOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : ElementwiseOpMaker(proto, op_checker) { - SetComment("Sub", "Out = X - Y"); - AddComment(comment_); - } -}; -} // namespace operators -} // namespace paddle - namespace ops = paddle::operators; -REGISTER_OPERATOR(elementwise_sub, ops::ElementwiseOp, - ops::ElementwiseSubOpMaker, - paddle::framework::DefaultGradOpDescMaker); -REGISTER_OPERATOR(elementwise_sub_grad, ops::ElementwiseOpGrad); +REGISTER_ELEMWISE_OP(elementwise_sub, "Sub", "Out = X - Y"); REGISTER_OP_CPU_KERNEL( elementwise_sub, ops::ElementwiseSubKernel, diff --git a/paddle/fluid/operators/expand_op.cc b/paddle/fluid/operators/expand_op.cc index 4ae91d074d3df8b910a7f5d816a22b6f1d51dff6..5ad0ec251328cc1ba580026bb47bf05316e7dc77 100644 --- a/paddle/fluid/operators/expand_op.cc +++ b/paddle/fluid/operators/expand_op.cc @@ -56,8 +56,7 @@ class ExpandOp : public framework::OperatorWithKernel { class ExpandOpMaker : public framework::OpProtoAndCheckerMaker { public: - ExpandOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "(Tensor, default Tensor). A tensor with rank in [1, 6]." "X is the input to be expanded."); diff --git a/paddle/fluid/operators/fc_op.cc b/paddle/fluid/operators/fc_op.cc index 45e4d5b2b863a55ae0aa0414ff8697141fd2aa6f..8843a1c44b7004ba5d7935f75d3c99d9c30fc6c0 100644 --- a/paddle/fluid/operators/fc_op.cc +++ b/paddle/fluid/operators/fc_op.cc @@ -72,8 +72,7 @@ framework::OpKernelType FCOpGrad::GetExpectedKernelType( layout, library); } -FCOpMaker::FCOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { +void FCOpMaker::Make() { AddInput("Input", "(Tensor) The input tensor of fully connected operator. "); AddInput("W", "(Tensor), The second input tensor of fc op."); AddOutput("Out", "(Tensor) The output tensor of fully connected operator. "); diff --git a/paddle/fluid/operators/fc_op.h b/paddle/fluid/operators/fc_op.h index 70fa96440d344397a7427c1338afee85bde923d4..e1b780fc0c401fbf34a9db03aa31137cbc016939 100644 --- a/paddle/fluid/operators/fc_op.h +++ b/paddle/fluid/operators/fc_op.h @@ -45,7 +45,7 @@ class FCOpGrad : public framework::OperatorWithKernel { class FCOpMaker : public framework::OpProtoAndCheckerMaker { public: - FCOpMaker(OpProto* proto, OpAttrChecker* op_checker); + void Make() override; }; } // namespace operators diff --git a/paddle/fluid/operators/feed_op.cc b/paddle/fluid/operators/feed_op.cc index debacf07c360b9aa69000a0d891f04239ed08807..bcb3e63ed7dbc775c1de6c4522f0548ea48a6cf0 100644 --- a/paddle/fluid/operators/feed_op.cc +++ b/paddle/fluid/operators/feed_op.cc @@ -66,8 +66,7 @@ class FeedOp : public framework::OperatorBase { class FeedOpInfoMaker : public framework::OpProtoAndCheckerMaker { public: - FeedOpInfoMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "The input of feed op"); AddOutput("Out", "The output of feed op"); AddAttr("col", "(int) The column of feed"); diff --git a/paddle/fluid/operators/fetch_op.cc b/paddle/fluid/operators/fetch_op.cc index 18deec58137676a0b2c8d559e49d0f7a840cd5ba..1640a2a22c69a0e3ab81a2889d6105b2cf4162b7 100644 --- a/paddle/fluid/operators/fetch_op.cc +++ b/paddle/fluid/operators/fetch_op.cc @@ -66,8 +66,7 @@ class FetchOp : public framework::OperatorBase { class FetchOpInfoMaker : public framework::OpProtoAndCheckerMaker { public: - FetchOpInfoMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "The input of fetch op"); AddOutput("Out", "The output of fetch op"); AddAttr("col", "(int) The column of fetch"); diff --git a/paddle/fluid/operators/fill_constant_batch_size_like_op.cc b/paddle/fluid/operators/fill_constant_batch_size_like_op.cc index 72da80baaf9bb3286f09b7ae5fcf24326b391906..1ae78675a0cac8a72aeaef1227b631a41e4a10b2 100644 --- a/paddle/fluid/operators/fill_constant_batch_size_like_op.cc +++ b/paddle/fluid/operators/fill_constant_batch_size_like_op.cc @@ -30,9 +30,8 @@ class FillConstantBatchSizeLikeOp : public BatchSizeLikeOp { }; class FillConstantBatchSizeLikeOpMaker : public BatchSizeLikeOpMaker { - public: - FillConstantBatchSizeLikeOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : BatchSizeLikeOpMaker(proto, op_checker) { + protected: + void Apply() override { AddAttr("dtype", "(int, default 5 (FP32)) " "Output data type") diff --git a/paddle/fluid/operators/fill_constant_op.cc b/paddle/fluid/operators/fill_constant_op.cc index 07e0a80f8d644d4d011f2821785d49ece6cecfb5..130f18dde4f979a6a9925ede9cbf745fcec14d48 100644 --- a/paddle/fluid/operators/fill_constant_op.cc +++ b/paddle/fluid/operators/fill_constant_op.cc @@ -59,8 +59,7 @@ class FillConstantOp : public framework::OperatorBase { class FillConstantOpMaker : public framework::OpProtoAndCheckerMaker { public: - FillConstantOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : framework::OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddAttr("dtype", "(int, default 5 (FP32)) " "Output data type") diff --git a/paddle/fluid/operators/fill_op.cc b/paddle/fluid/operators/fill_op.cc index ee8a2fc353f86cdabd35459a9195c3aa35f63e31..925dc19061e2196a40411f415eb6e5ad59ab52ff 100644 --- a/paddle/fluid/operators/fill_op.cc +++ b/paddle/fluid/operators/fill_op.cc @@ -82,8 +82,7 @@ class FillOp : public framework::OperatorBase { class FillOpMaker : public framework::OpProtoAndCheckerMaker { public: - FillOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddComment(R"DOC(Fill operator Fill an tensor with `value` and `shape`. The type of the tensor is specify by diff --git a/paddle/fluid/operators/fill_zeros_like_op.cc b/paddle/fluid/operators/fill_zeros_like_op.cc index 58c814ba6413626a48310da595a13238994f5ef1..d67bec36b3248be8602da562a88aeb58f5effe39 100644 --- a/paddle/fluid/operators/fill_zeros_like_op.cc +++ b/paddle/fluid/operators/fill_zeros_like_op.cc @@ -33,8 +33,7 @@ class FillZerosLikeOp : public framework::OperatorWithKernel { class FillZerosLikeOpMaker : public framework::OpProtoAndCheckerMaker { public: - FillZerosLikeOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : framework::OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "The input of fill-zeros-like op."); AddOutput("Out", "The variable will be filled up with zeros."); AddComment(R"DOC( diff --git a/paddle/fluid/operators/ftrl_op.cc b/paddle/fluid/operators/ftrl_op.cc index cbdcce9beb3fafb0775d0b5fc39cb381ad128d0c..70ba25c213046cc934f46be067080d5fdbb42f9e 100644 --- a/paddle/fluid/operators/ftrl_op.cc +++ b/paddle/fluid/operators/ftrl_op.cc @@ -64,8 +64,7 @@ class FTRLOp : public framework::OperatorWithKernel { class FTRLOpMaker : public framework::OpProtoAndCheckerMaker { public: - FTRLOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("Param", "(Tensor, default Tensor) " "Input parameter value that has to be updated."); diff --git a/paddle/fluid/operators/gather_op.cc b/paddle/fluid/operators/gather_op.cc index 4c82f5c429038504d9876ee240a705911feb0b7a..e21b57258928856a10d6e86c3e2c6e81fb241ee3 100644 --- a/paddle/fluid/operators/gather_op.cc +++ b/paddle/fluid/operators/gather_op.cc @@ -67,8 +67,7 @@ class GatherGradOp : public framework::OperatorWithKernel { class GatherOpMaker : public framework::OpProtoAndCheckerMaker { public: - GatherOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "The source input of gather op"); AddInput("Index", "The index input of gather op"); AddOutput("Out", "The output of gather op"); diff --git a/paddle/fluid/operators/gaussian_random_batch_size_like_op.cc b/paddle/fluid/operators/gaussian_random_batch_size_like_op.cc index 53c706a83e5bfb9e93d485141314e8b652d73593..8050f61d4546f3351645f23ddcc63b2c49f17929 100644 --- a/paddle/fluid/operators/gaussian_random_batch_size_like_op.cc +++ b/paddle/fluid/operators/gaussian_random_batch_size_like_op.cc @@ -32,9 +32,8 @@ class GaussianRandomBatchSizeLikeOp : public BatchSizeLikeOp { }; class GaussianRandomBatchSizeLikeOpMaker : public BatchSizeLikeOpMaker { - public: - GaussianRandomBatchSizeLikeOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : BatchSizeLikeOpMaker(proto, op_checker) { + protected: + void Apply() override { AddAttr("mean", "(float, default 0.0) " "mean of random tensor.") diff --git a/paddle/fluid/operators/gaussian_random_op.cc b/paddle/fluid/operators/gaussian_random_op.cc index 4d197637b3f49f7e63f5b1a5cba212d1bf774f7e..815c1bb50988be49ca9996e368a59344c6583d58 100644 --- a/paddle/fluid/operators/gaussian_random_op.cc +++ b/paddle/fluid/operators/gaussian_random_op.cc @@ -70,8 +70,7 @@ class GaussianRandomOp : public framework::OperatorWithKernel { class GaussianRandomOpMaker : public framework::OpProtoAndCheckerMaker { public: - GaussianRandomOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : framework::OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddOutput("Out", "Output matrix of gaussian random op"); AddAttr>("shape", diff --git a/paddle/fluid/operators/get_places_op.cc b/paddle/fluid/operators/get_places_op.cc index 0d7219ac5c624236b85916d5faf6810dbed2198a..eafc364a15fa17cc5107bba737b0b44e712b0bef 100644 --- a/paddle/fluid/operators/get_places_op.cc +++ b/paddle/fluid/operators/get_places_op.cc @@ -78,8 +78,7 @@ class GetPlacesOp : public framework::OperatorBase { class GetPlacesOpProtoMaker : public framework::OpProtoAndCheckerMaker { public: - GetPlacesOpProtoMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddOutput("Out", "vector of Place"); AddAttr("device_count", "device count").SetDefault(0); AddAttr("device_type", "device type") diff --git a/paddle/fluid/operators/go_op.cc b/paddle/fluid/operators/go_op.cc index b8e1556c23a3b7357ed56d1b83c09622559040a4..48f9d967adc90838dc4c7a09bfaf5a5a1ac9c99b 100644 --- a/paddle/fluid/operators/go_op.cc +++ b/paddle/fluid/operators/go_op.cc @@ -89,8 +89,7 @@ class GoOp : public framework::OperatorBase { class GoOpMaker : public framework::OpProtoAndCheckerMaker { public: - GoOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput(kX, "A set of variables, which are required by operators inside the " "block of Go Op.") diff --git a/paddle/fluid/operators/gru_op.cc b/paddle/fluid/operators/gru_op.cc index 0a524c914d305661745c5d85cbbee2edb57c97ba..5c746878823b3dcde2573feec00d3d9dac5ceab8 100644 --- a/paddle/fluid/operators/gru_op.cc +++ b/paddle/fluid/operators/gru_op.cc @@ -71,8 +71,7 @@ class GRUOp : public framework::OperatorWithKernel { class GRUOpMaker : public framework::OpProtoAndCheckerMaker { public: - GRUOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("Input", "(LoDTensor) The first input is a LodTensor, which supports " "variable-time length input sequence. The underlying tensor in " diff --git a/paddle/fluid/operators/gru_unit_op.cc b/paddle/fluid/operators/gru_unit_op.cc index f8d1d44b5423dd09fe5aad11434911af6f14fe77..82a808b01e99ec33b0ca00a065fb301d3c633b19 100644 --- a/paddle/fluid/operators/gru_unit_op.cc +++ b/paddle/fluid/operators/gru_unit_op.cc @@ -71,8 +71,7 @@ class GRUUnitOp : public framework::OperatorWithKernel { class GRUUnitOpMaker : public framework::OpProtoAndCheckerMaker { public: - GRUUnitOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("Input", "(Tensor) Matrix with shape [batch_size, frame_size * 3] for the " "input."); diff --git a/paddle/fluid/operators/hinge_loss_op.cc b/paddle/fluid/operators/hinge_loss_op.cc index 086b5a97dec9a3d5b8f91b802b92d64ca73bf57c..69e7fa4490b892373d85898b13b976a474a6096a 100644 --- a/paddle/fluid/operators/hinge_loss_op.cc +++ b/paddle/fluid/operators/hinge_loss_op.cc @@ -46,8 +46,7 @@ class HingeLossOp : public framework::OperatorWithKernel { template class HingeLossOpMaker : public framework::OpProtoAndCheckerMaker { public: - HingeLossOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("Logits", "The input value (Logits) of Hinge loss op." "Logits is a 2-D tensor with shape [batch_size, 1]."); diff --git a/paddle/fluid/operators/huber_loss_op.cc b/paddle/fluid/operators/huber_loss_op.cc index 74d8e0e2b76adc7a3e69649f277a8c0df6f38056..4ecd8634ff41ff4eba6b5ed1d0fc78068190dce5 100644 --- a/paddle/fluid/operators/huber_loss_op.cc +++ b/paddle/fluid/operators/huber_loss_op.cc @@ -45,8 +45,7 @@ class HuberLossOp : public framework::OperatorWithKernel { template class HuberLossOpMaker : public framework::OpProtoAndCheckerMaker { public: - HuberLossOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "The input value of huber loss op." "X is a 2-D tensor with shape [batch_size, 1]."); diff --git a/paddle/fluid/operators/im2sequence_op.cc b/paddle/fluid/operators/im2sequence_op.cc index 8c120eec86601146500721bbb4249bc458190093..0669661d225c664010fce97f0a526b62988b92c5 100644 --- a/paddle/fluid/operators/im2sequence_op.cc +++ b/paddle/fluid/operators/im2sequence_op.cc @@ -54,8 +54,7 @@ class Im2SequenceOp : public framework::OperatorWithKernel { class Im2SequenceOpMaker : public framework::OpProtoAndCheckerMaker { public: - Im2SequenceOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "(Tensor) The input tensor has NCHW format." "N: batch size" diff --git a/paddle/fluid/operators/increment_op.cc b/paddle/fluid/operators/increment_op.cc index d8c97b27b328b1470bece4a6c1872b5ccc75115e..f0ffc9706689f5afe4546c3483114b38bc2b7872 100644 --- a/paddle/fluid/operators/increment_op.cc +++ b/paddle/fluid/operators/increment_op.cc @@ -47,8 +47,7 @@ class IncrementOp : public framework::OperatorWithKernel { class IncrementOpMaker : public framework::OpProtoAndCheckerMaker { public: - IncrementOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "(Tensor) The input tensor of increment operator"); AddOutput("Out", "(Tensor) The output tensor of increment operator."); AddAttr("step", diff --git a/paddle/fluid/operators/iou_similarity_op.cc b/paddle/fluid/operators/iou_similarity_op.cc index 4b78ec510d1fb73592ee8af9a641622f4d713f8d..007e0af7a5a9fd8c562218e641e1867388b081f1 100644 --- a/paddle/fluid/operators/iou_similarity_op.cc +++ b/paddle/fluid/operators/iou_similarity_op.cc @@ -42,8 +42,7 @@ class IOUSimilarityOp : public framework::OperatorWithKernel { class IOUSimilarityOpMaker : public framework::OpProtoAndCheckerMaker { public: - IOUSimilarityOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "(LoDTensor, default LoDTensor) " "Box list X is a 2-D LoDTensor with shape [N, 4] holds N boxes, " diff --git a/paddle/fluid/operators/is_empty_op.cc b/paddle/fluid/operators/is_empty_op.cc index 2a7be90dab1cc23ffe5e1c296c37a4bbeacb7d8e..d3f3ad92442cafdd8d4cdc396d89721863d069c2 100644 --- a/paddle/fluid/operators/is_empty_op.cc +++ b/paddle/fluid/operators/is_empty_op.cc @@ -48,8 +48,7 @@ class IsEmptyOp : public framework::OperatorBase { class IsEmptyOpProtoMaker : public framework::OpProtoAndCheckerMaker { public: - IsEmptyOpProtoMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput(kInput, "(Tensor) Tensor which is to be checked."); AddOutput(kOutput, "(Tensor) a boolean Tensor that indicate empty or not."); AddComment(R"DOC( diff --git a/paddle/fluid/operators/l1_norm_op.cc b/paddle/fluid/operators/l1_norm_op.cc index 0c143b7c8aed13a202e2597632d17d8bccc8b66d..bc115090acb473ac3175999ca96c5e00c0aeaeae 100644 --- a/paddle/fluid/operators/l1_norm_op.cc +++ b/paddle/fluid/operators/l1_norm_op.cc @@ -48,8 +48,7 @@ class L1NormGradOp : public framework::OperatorWithKernel { class L1NormOpMaker : public framework::OpProtoAndCheckerMaker { public: - L1NormOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : framework::OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "(Tensor) The input of l1_norm op."); AddOutput("Out", "(Scalar) The output of l1_norm op."); AddComment(R"DOC( diff --git a/paddle/fluid/operators/label_smooth_op.cc b/paddle/fluid/operators/label_smooth_op.cc index a73c626032f3bf6e97ac5974424e76bacb9a0799..da59bd53bce010d0d6ad2ab14acaffb9cc2f99e6 100644 --- a/paddle/fluid/operators/label_smooth_op.cc +++ b/paddle/fluid/operators/label_smooth_op.cc @@ -47,8 +47,7 @@ class LabelSmoothOp : public framework::OperatorWithKernel { class LabelSmoothOpMaker : public framework::OpProtoAndCheckerMaker { public: - LabelSmoothOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "(LoDTensor) The input labels of LabelSmooth operator. This " "input can be batched labels in one-hot encoding or output from " diff --git a/paddle/fluid/operators/layer_norm_op.cc b/paddle/fluid/operators/layer_norm_op.cc index de1056aef7bfa2f53f8a92b262e7d15aa7c2b75c..ab097d31e9ab5eafa788539170e7e405df697625 100644 --- a/paddle/fluid/operators/layer_norm_op.cc +++ b/paddle/fluid/operators/layer_norm_op.cc @@ -61,8 +61,7 @@ class LayerNormOp : public framework::OperatorWithKernel { class LayerNormOpMaker : public framework::OpProtoAndCheckerMaker { public: - LayerNormOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "(LoDTensor) The input tensor."); AddInput("Scale", "(Tensor, optional) Scale is a 1-dimensional tensor of size " diff --git a/paddle/fluid/operators/linear_chain_crf_op.cc b/paddle/fluid/operators/linear_chain_crf_op.cc index 2f29e377fdada918f2c9dca8c2d94eb06278320d..e38525cd7f44de020f364ffd16e71a439048347f 100644 --- a/paddle/fluid/operators/linear_chain_crf_op.cc +++ b/paddle/fluid/operators/linear_chain_crf_op.cc @@ -19,8 +19,7 @@ namespace operators { class LinearChainCRFOpMaker : public framework::OpProtoAndCheckerMaker { public: - LinearChainCRFOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("Emission", "(LoDTensor, default LoDTensor) " "A 2-D LoDTensor with shape [N x D], where N is the size of the " diff --git a/paddle/fluid/operators/listen_and_serv_op.cc b/paddle/fluid/operators/listen_and_serv_op.cc index 8acbf820250957163397342c645b333f0da0801c..a29e0cd52cfccf242a6490822234045e6eb66c0f 100644 --- a/paddle/fluid/operators/listen_and_serv_op.cc +++ b/paddle/fluid/operators/listen_and_serv_op.cc @@ -343,8 +343,7 @@ void ListenAndServOp::RunImpl(const framework::Scope &scope, class ListenAndServOpMaker : public framework::OpProtoAndCheckerMaker { public: - ListenAndServOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() { AddInput("X", "(Tensor) Variables that server recv.").AsDuplicable(); AddComment(R"DOC( ListenAndServ operator diff --git a/paddle/fluid/operators/load_combine_op.cc b/paddle/fluid/operators/load_combine_op.cc index e5353144e91455fc71460459e6e799b54f750f71..b5522dd246f250f02d69c0ba749ae6043eb810d6 100644 --- a/paddle/fluid/operators/load_combine_op.cc +++ b/paddle/fluid/operators/load_combine_op.cc @@ -77,8 +77,7 @@ class LoadCombineOp : public framework::OperatorBase { class LoadCombineOpProtoMaker : public framework::OpProtoAndCheckerMaker { public: - LoadCombineOpProtoMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddOutput( "Out", "(vector) The output LoDTensors that will be read from the input file.") diff --git a/paddle/fluid/operators/load_op.cc b/paddle/fluid/operators/load_op.cc index abf7becb2e7fc134e3a52ec4c118847c14a20b9c..93f45cff8a26201b1fbb1c44141e125a67c44037 100644 --- a/paddle/fluid/operators/load_op.cc +++ b/paddle/fluid/operators/load_op.cc @@ -73,8 +73,7 @@ class LoadOp : public framework::OperatorBase { class LoadOpProtoMaker : public framework::OpProtoAndCheckerMaker { public: - LoadOpProtoMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddOutput("Out", "(Tensor) The tensor need to be loaded"); AddAttr( "load_as_fp16", diff --git a/paddle/fluid/operators/lod_array_length_op.cc b/paddle/fluid/operators/lod_array_length_op.cc index e6212405770093455ec89bde9dc0a092b956fc83..e4551b8ba681fe92ac5f21bb0b509f43439f6b66 100644 --- a/paddle/fluid/operators/lod_array_length_op.cc +++ b/paddle/fluid/operators/lod_array_length_op.cc @@ -40,8 +40,7 @@ class LoDArrayLengthOp : public framework::OperatorBase { class LoDArrayLengthProtoMaker : public framework::OpProtoAndCheckerMaker { public: - LoDArrayLengthProtoMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "(LoDTensorArray) The input tensor array."); AddOutput("Out", "(Tensor) 1x1 CPU Tensor of length, int64_t"); AddComment(R"DOC( diff --git a/paddle/fluid/operators/lod_rank_table_op.cc b/paddle/fluid/operators/lod_rank_table_op.cc index 590b44e14f518c3c60c141c9a0dfe7f2b96f69c6..166952fe23192799443ef9c9d1f7ba5056d19290 100644 --- a/paddle/fluid/operators/lod_rank_table_op.cc +++ b/paddle/fluid/operators/lod_rank_table_op.cc @@ -38,8 +38,7 @@ class LoDRankTableOp : public framework::OperatorBase { class LoDRankTableOpProtoMaker : public framework::OpProtoAndCheckerMaker { public: - LoDRankTableOpProtoMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "(LoDTensor) input lod tensor, must contain lod information."); AddOutput("Out", "(LoDRankTable) The rank table of specific level."); diff --git a/paddle/fluid/operators/lod_reset_op.cc b/paddle/fluid/operators/lod_reset_op.cc index 92ebfc274b84f738f5bd688a9a6d9f437b6318aa..0d4e84e85083399e3803d0648dc7a10aa276d536 100644 --- a/paddle/fluid/operators/lod_reset_op.cc +++ b/paddle/fluid/operators/lod_reset_op.cc @@ -47,8 +47,7 @@ class LoDResetOp : public framework::OperatorWithKernel { class LoDResetOpMaker : public framework::OpProtoAndCheckerMaker { public: - LoDResetOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "(Tensor, LoDTensor) Input variable of LoDResetOp which " "could be a Tensor or LoDTensor, where the data of output " diff --git a/paddle/fluid/operators/lod_tensor_to_array_op.cc b/paddle/fluid/operators/lod_tensor_to_array_op.cc index 543495ce4e66c0955c9ce1b0db480088069b36db..00ba5ce8ee5e4084c8af204cfc37fe80c437f0d7 100644 --- a/paddle/fluid/operators/lod_tensor_to_array_op.cc +++ b/paddle/fluid/operators/lod_tensor_to_array_op.cc @@ -105,8 +105,7 @@ class LoDTensorToArrayOp : public framework::OperatorBase { class LoDTensorToArrayOpProtoMaker : public framework::OpProtoAndCheckerMaker { public: - LoDTensorToArrayOpProtoMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", ""); AddInput("RankTable", ""); AddOutput("Out", ""); diff --git a/paddle/fluid/operators/log_loss_op.cc b/paddle/fluid/operators/log_loss_op.cc index a8258a1afd70574c174abe8d5630ade5d4ac3de6..9d248e03218b83a65b9786cb317aafbe3dbb67ee 100644 --- a/paddle/fluid/operators/log_loss_op.cc +++ b/paddle/fluid/operators/log_loss_op.cc @@ -46,8 +46,7 @@ class LogLossOp : public framework::OperatorWithKernel { template class LogLossOpMaker : public framework::OpProtoAndCheckerMaker { public: - LogLossOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("Predicted", "The input value (Predicted) of Log loss op." "Predicted is a 2-D tensor with shape [batch_size, 1]."); diff --git a/paddle/fluid/operators/logical_op.cc b/paddle/fluid/operators/logical_op.cc index 41aa00ee8ac10e0776c066fc3c37f97b0dd40cc3..db109f5cd053d84718ac85bd4693ecece12ce172 100644 --- a/paddle/fluid/operators/logical_op.cc +++ b/paddle/fluid/operators/logical_op.cc @@ -21,8 +21,7 @@ namespace operators { template class BinaryLogicalOpProtoMaker : public framework::OpProtoAndCheckerMaker { public: - BinaryLogicalOpProtoMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { OpComment comment; AddInput("X", string::Sprintf("(LoDTensor) Left hand operand of %s operator", @@ -45,8 +44,7 @@ Each element of Out is calculated by %s template class UnaryLogicalOpProtoMaker : public framework::OpProtoAndCheckerMaker { public: - UnaryLogicalOpProtoMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { OpComment comment; AddInput("X", string::Sprintf("(LoDTensor) Operand of %s operator", comment.type)); diff --git a/paddle/fluid/operators/lookup_sparse_table_op.cc b/paddle/fluid/operators/lookup_sparse_table_op.cc index 66b626ed792ddec9d57fcf6c81655dffcc23ca99..d07a81968565f095cdb6425d104bc7a11bc9cfad 100644 --- a/paddle/fluid/operators/lookup_sparse_table_op.cc +++ b/paddle/fluid/operators/lookup_sparse_table_op.cc @@ -105,8 +105,7 @@ class LookupSparseTableOp : public framework::OperatorBase { class LookupSparseTableOpMaker : public framework::OpProtoAndCheckerMaker { public: - LookupSparseTableOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : framework::OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("W", "(SelectedRows) The input represents embedding table, " "which is a learnable parameter."); diff --git a/paddle/fluid/operators/lookup_table_op.cc b/paddle/fluid/operators/lookup_table_op.cc index 5e59bd1b178ad1803f6f70c5f3f9fd7af495ac3c..bda499432214b8841c8dfc406ee45ca0367920e7 100644 --- a/paddle/fluid/operators/lookup_table_op.cc +++ b/paddle/fluid/operators/lookup_table_op.cc @@ -58,8 +58,7 @@ class LookupTableOp : public framework::OperatorWithKernel { class LookupTableOpMaker : public framework::OpProtoAndCheckerMaker { public: - LookupTableOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("W", "(Tensor) The input represents embedding tensors, " "which is a learnable parameter."); diff --git a/paddle/fluid/operators/lrn_op.cc b/paddle/fluid/operators/lrn_op.cc index f5c0e47fda913b4635833c31496644b60a0a8504..52b9cd7fb7019b738098a8649f23277afd40e938 100644 --- a/paddle/fluid/operators/lrn_op.cc +++ b/paddle/fluid/operators/lrn_op.cc @@ -169,8 +169,7 @@ class LRNOp : public framework::OperatorWithKernel { template class LRNOpMaker : public framework::OpProtoAndCheckerMaker { public: - LRNOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "(Tensor) The input of LRN operator. " "It must be a 4D tenor with NCHW format."); diff --git a/paddle/fluid/operators/lstm_op.cc b/paddle/fluid/operators/lstm_op.cc index 084ee1cfe602af3622ef2a3f35f2892d5540cec7..4751e3e8025e51a687f8fcfd25e603b61e762f6d 100644 --- a/paddle/fluid/operators/lstm_op.cc +++ b/paddle/fluid/operators/lstm_op.cc @@ -103,8 +103,7 @@ class LSTMOp : public framework::OperatorWithKernel { class LSTMOpMaker : public framework::OpProtoAndCheckerMaker { public: - LSTMOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("Input", "(LoDTensor) the first input is a LodTensor, which support " "variable-time length input sequence. The underlying tensor in " diff --git a/paddle/fluid/operators/lstm_unit_op.cc b/paddle/fluid/operators/lstm_unit_op.cc index e1157ef6c640be17e7f48abe1ab972cf88504526..0895c58f5f58afd444000ebeac7a92e3eb7778d3 100644 --- a/paddle/fluid/operators/lstm_unit_op.cc +++ b/paddle/fluid/operators/lstm_unit_op.cc @@ -48,8 +48,7 @@ class LstmUnitOp : public framework::OperatorWithKernel { class LstmUnitOpMaker : public framework::OpProtoAndCheckerMaker { public: - LstmUnitOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "Lstm unit only applies non-linear activations, please make sure" "that linear tranformation has already been applied to `X`. " diff --git a/paddle/fluid/operators/lstmp_op.cc b/paddle/fluid/operators/lstmp_op.cc index f9261323f0f50c78b3b4b66a9fa8abcdf5ba27e9..e398b51480f6fc0c6c568770b3b2a9746360744e 100644 --- a/paddle/fluid/operators/lstmp_op.cc +++ b/paddle/fluid/operators/lstmp_op.cc @@ -120,8 +120,7 @@ class LSTMPOp : public framework::OperatorWithKernel { class LSTMPOpMaker : public framework::OpProtoAndCheckerMaker { public: - LSTMPOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("Input", "(LoDTensor) the input for sequence data, which supports " "variable-time length input sequence. The underlying tensor in " diff --git a/paddle/fluid/operators/margin_rank_loss_op.cc b/paddle/fluid/operators/margin_rank_loss_op.cc index 0b41a3e1ffdb32d248bb55651aba242336307e74..b643ba9d7fa61d758e871ebe7a463c22e937fa2c 100644 --- a/paddle/fluid/operators/margin_rank_loss_op.cc +++ b/paddle/fluid/operators/margin_rank_loss_op.cc @@ -42,8 +42,7 @@ class MarginRankLossOp : public framework::OperatorWithKernel { template class MarginRankLossOpMaker : public framework::OpProtoAndCheckerMaker { public: - MarginRankLossOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X1", "(2-D tensor with shape [batch_size x 1]) The score for " "one item X1 to be ranked, from pairwise ranking model."); diff --git a/paddle/fluid/operators/matmul_op.cc b/paddle/fluid/operators/matmul_op.cc index 383f0124d9123bcee0719e696771745d74c5f85f..7182149164854038bb67a9f06cdbec8a4a0f1fb2 100644 --- a/paddle/fluid/operators/matmul_op.cc +++ b/paddle/fluid/operators/matmul_op.cc @@ -322,8 +322,7 @@ class MatMulOp : public framework::OperatorWithKernel { class MatMulOpMaker : public framework::OpProtoAndCheckerMaker { public: - MatMulOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "The first input of MatMul op"); AddInput("Y", "The second input of MatMul op"); AddOutput("Out", "The output of MatMul op"); diff --git a/paddle/fluid/operators/max_sequence_len_op.cc b/paddle/fluid/operators/max_sequence_len_op.cc index 4cd7c89b48a2442ee7a5074abbf0f3dd9ea3bcb4..8e508b68eeab69a4595904dcc3ea0a541d9ab6e6 100644 --- a/paddle/fluid/operators/max_sequence_len_op.cc +++ b/paddle/fluid/operators/max_sequence_len_op.cc @@ -41,8 +41,7 @@ class MaxSeqenceLenOp : public framework::OperatorBase { class MaxSeqenceLenOpProtoMaker : public framework::OpProtoAndCheckerMaker { public: - MaxSeqenceLenOpProtoMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("RankTable", "The lod_rank_table."); AddOutput("Out", "The max sequence length."); AddComment( diff --git a/paddle/fluid/operators/maxout_op.cc b/paddle/fluid/operators/maxout_op.cc index e2bcba5a5e15d4d5f10ae4ae64b5262f750137ab..058115cb624627d81b31d0903f7d615d19708c77 100644 --- a/paddle/fluid/operators/maxout_op.cc +++ b/paddle/fluid/operators/maxout_op.cc @@ -22,8 +22,7 @@ using framework::Tensor; class MaxOutOpMaker : public framework::OpProtoAndCheckerMaker { public: - MaxOutOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput( "X", "(Tensor) The input tensor of maxout operator. " diff --git a/paddle/fluid/operators/mean_op.cc b/paddle/fluid/operators/mean_op.cc index a134796bfcaa9dea2483ace9f5045e257916daba..74477eb439dc202c3f5f17fdf3e1647bc5c23512 100644 --- a/paddle/fluid/operators/mean_op.cc +++ b/paddle/fluid/operators/mean_op.cc @@ -32,8 +32,7 @@ class MeanOp : public framework::OperatorWithKernel { class MeanOpMaker : public framework::OpProtoAndCheckerMaker { public: - MeanOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "The input of mean op"); AddOutput("Out", "The output of mean op"); AddComment(R"DOC( diff --git a/paddle/fluid/operators/merge_lod_tensor_op.cc b/paddle/fluid/operators/merge_lod_tensor_op.cc index 4ebf20cbba69bee09dfddb8e928ddc95665e4731..a16861b3b77fc980ab932b9d88859b38ec36108b 100644 --- a/paddle/fluid/operators/merge_lod_tensor_op.cc +++ b/paddle/fluid/operators/merge_lod_tensor_op.cc @@ -121,8 +121,7 @@ class MergeLoDTensorOp : public framework::OperatorBase { class MergeLoDTensorOpProtoMaker : public framework::OpProtoAndCheckerMaker { public: - MergeLoDTensorOpProtoMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "The input LoDTensor, contains complete lod information to " "construct the output"); diff --git a/paddle/fluid/operators/mine_hard_examples_op.cc b/paddle/fluid/operators/mine_hard_examples_op.cc index 277901cff493445e1e85e92e22ea0ada0e1cba43..d4a09bae3a98e4518f9885c1e9182f7033a0d262 100644 --- a/paddle/fluid/operators/mine_hard_examples_op.cc +++ b/paddle/fluid/operators/mine_hard_examples_op.cc @@ -253,8 +253,7 @@ class MineHardExamplesOp : public framework::OperatorWithKernel { class MineHardExamplesOpMaker : public framework::OpProtoAndCheckerMaker { public: - MineHardExamplesOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput( "ClsLoss", "(Tensor, default Tensor), The classification loss with shape " diff --git a/paddle/fluid/operators/minus_op.cc b/paddle/fluid/operators/minus_op.cc index a302b24560e680076d62d02b422c6410467deb1d..34571a38a14795a98ac8454cec606077727b5ffa 100644 --- a/paddle/fluid/operators/minus_op.cc +++ b/paddle/fluid/operators/minus_op.cc @@ -48,8 +48,7 @@ class MinusOp : public framework::OperatorWithKernel { class MinusOpMaker : public framework::OpProtoAndCheckerMaker { public: - MinusOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "The left tensor of minus operator."); AddInput("Y", "The right tensor of minus operator."); AddOutput("Out", "The output tensor of minus operator."); diff --git a/paddle/fluid/operators/modified_huber_loss_op.cc b/paddle/fluid/operators/modified_huber_loss_op.cc index 3a0fc74584391d0441105a8ac7d7ac292e10fb8d..35db4c1ad1f6c6481eca397e99fc8c1f0bc7164c 100644 --- a/paddle/fluid/operators/modified_huber_loss_op.cc +++ b/paddle/fluid/operators/modified_huber_loss_op.cc @@ -39,8 +39,7 @@ class ModifiedHuberLossOp : public framework::OperatorWithKernel { class ModifiedHuberLossOpMaker : public framework::OpProtoAndCheckerMaker { public: - ModifiedHuberLossOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "The input tensor of modified huber loss op. " "X is 2-D tensor with shape [batch_size, 1]."); diff --git a/paddle/fluid/operators/momentum_op.cc b/paddle/fluid/operators/momentum_op.cc index f13ec53905aa3d5b55b865c3514f36211c06a549..dcd73e3c3e40f80e07b73944d1f0cc57fea010d3 100644 --- a/paddle/fluid/operators/momentum_op.cc +++ b/paddle/fluid/operators/momentum_op.cc @@ -62,8 +62,7 @@ class MomentumOp : public framework::OperatorWithKernel { class MomentumOpMaker : public framework::OpProtoAndCheckerMaker { public: - MomentumOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("Param", "(Tensor, default Tensor) " "Input parameter that has to be updated"); diff --git a/paddle/fluid/operators/mul_op.cc b/paddle/fluid/operators/mul_op.cc index 6903cf83b41a54b54382fac2cf58f7bfe192b55f..a43739463c85b38e1dba04c6ec1bfcf4b6cbfa63 100644 --- a/paddle/fluid/operators/mul_op.cc +++ b/paddle/fluid/operators/mul_op.cc @@ -96,8 +96,7 @@ class MulOp : public framework::OperatorWithKernel { class MulOpMaker : public framework::OpProtoAndCheckerMaker { public: - MulOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "(Tensor), The first input tensor of mul op."); AddInput("Y", "(Tensor), The second input tensor of mul op."); AddOutput("Out", "(Tensor), The output tensor of mul op."); diff --git a/paddle/fluid/operators/multiclass_nms_op.cc b/paddle/fluid/operators/multiclass_nms_op.cc index a12b975326519c776c9f4a1d9f2894b4028c2440..60b93efdce810f8552374449fe5a6fc79b1a92c1 100644 --- a/paddle/fluid/operators/multiclass_nms_op.cc +++ b/paddle/fluid/operators/multiclass_nms_op.cc @@ -309,8 +309,7 @@ class MultiClassNMSKernel : public framework::OpKernel { class MultiClassNMSOpMaker : public framework::OpProtoAndCheckerMaker { public: - MultiClassNMSOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("BBoxes", "(Tensor) A 3-D Tensor with shape [N, M, 4] represents the " "predicted locations of M bounding bboxes, N is the batch size. " diff --git a/paddle/fluid/operators/multiplex_op.cc b/paddle/fluid/operators/multiplex_op.cc index b698c1bf8a05e053db07db34712a13c8074ee4d0..a4363fd25d57edb5c2509904a1f55634832613be 100644 --- a/paddle/fluid/operators/multiplex_op.cc +++ b/paddle/fluid/operators/multiplex_op.cc @@ -61,8 +61,7 @@ class MultiplexOp : public framework::OperatorWithKernel { class MultiplexOpMaker : public framework::OpProtoAndCheckerMaker { public: - MultiplexOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("Ids", "The index tensor of multiplex operator."); AddInput("X", "The candidate tensors of multiplex operator.") .AsDuplicable(); diff --git a/paddle/fluid/operators/nccl_op.cc b/paddle/fluid/operators/nccl_op.cc index 5e4ed886b10bd48bf991ce84a9099611cf5d1d26..0018139cb06fe0573565c920849843e674df6f4c 100644 --- a/paddle/fluid/operators/nccl_op.cc +++ b/paddle/fluid/operators/nccl_op.cc @@ -76,8 +76,7 @@ class NCCLInitOpShapeInference : public framework::InferShapeBase { class NCCLInitOpMaker : public framework::OpProtoAndCheckerMaker { public: - NCCLInitOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput(kParallelScopes, "The working place of parallel do."); AddOutput("Communicator", "Create Communicator for communicating between gpus"); @@ -118,8 +117,7 @@ class NCCLAllReduceOp : public framework::OperatorWithKernel { // AllReduceOp class NCCLAllReduceOpMaker : public framework::OpProtoAndCheckerMaker { public: - NCCLAllReduceOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "The input of AllReduce op"); AddInput("Communicator", "Communicator for communicating between gpus"); AddOutput("Out", "The output of AllReduce op"); @@ -165,8 +163,7 @@ class NCCLReduceOp : public framework::OperatorWithKernel { // ReduceOp class NCCLReduceOpMaker : public framework::OpProtoAndCheckerMaker { public: - NCCLReduceOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "The input of Reduce op"); AddInput("Communicator", "Communicator for communicating between gpus"); AddOutput("Out", "The output of Reduce op"); @@ -214,8 +211,7 @@ class NCCLBcastOp : public framework::OperatorWithKernel { // BcastOp class NCCLBcastOpMaker : public framework::OpProtoAndCheckerMaker { public: - NCCLBcastOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "The input of BcastSend op"); AddInput("Communicator", "Communicator for communicating between gpus"); AddOutput("Out", "The output of Bcast"); diff --git a/paddle/fluid/operators/nce_op.cc b/paddle/fluid/operators/nce_op.cc index 192bdf8ea553f3a82066f8562458d286ee15a6ee..06092e680a1efbef379ccf40fdf476769f820429 100644 --- a/paddle/fluid/operators/nce_op.cc +++ b/paddle/fluid/operators/nce_op.cc @@ -75,8 +75,7 @@ class NCEOp : public framework::OperatorWithKernel { class NCEOpMaker : public framework::OpProtoAndCheckerMaker { public: - NCEOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("Input", "(Tensor) A tensor of shape [batch_size, dim]."); AddInput( "Label", diff --git a/paddle/fluid/operators/norm_op.cc b/paddle/fluid/operators/norm_op.cc index 30a991224fa184257a8e59af5e6a27a0b0a4da86..cdbc975c02214721ceae3a338741101ef32d7ee9 100644 --- a/paddle/fluid/operators/norm_op.cc +++ b/paddle/fluid/operators/norm_op.cc @@ -19,8 +19,7 @@ namespace operators { template class NormOpMaker : public framework::OpProtoAndCheckerMaker { public: - NormOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput( "X", "(Tensor) The input tensor of norm operator. " diff --git a/paddle/fluid/operators/one_hot_op.cc b/paddle/fluid/operators/one_hot_op.cc index 1d42dfdd765166c9596abc08ce8abd534453bc63..4fcb1d69935175c3f643db7a4da04db34492f8fb 100644 --- a/paddle/fluid/operators/one_hot_op.cc +++ b/paddle/fluid/operators/one_hot_op.cc @@ -46,8 +46,7 @@ class OneHotOp : public framework::OperatorWithKernel { class OneHotOpMaker : public framework::OpProtoAndCheckerMaker { public: - OneHotOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "(LoDTensor, LoDTensor) Input variable with rank at least 2. " "The last dimension of X should be 1. Each value of X is an index " diff --git a/paddle/fluid/operators/pad_op.cc b/paddle/fluid/operators/pad_op.cc index d2a0106f80144e3550d73ea22f8e012426eb01ae..d4b631a6f5bf9332f4ed1d1a4bda529fbb6ada0a 100644 --- a/paddle/fluid/operators/pad_op.cc +++ b/paddle/fluid/operators/pad_op.cc @@ -48,8 +48,7 @@ class PadOp : public framework::OperatorWithKernel { class PadOpMaker : public framework::OpProtoAndCheckerMaker { public: - PadOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "The input of pad op. " "The input should be a k-D tensor(k > 0 and k < 7)"); diff --git a/paddle/fluid/operators/parallel_do_op.cc b/paddle/fluid/operators/parallel_do_op.cc index ae34fe2184b43cc104c14672dec30efd3b0e9f3b..1012640d5e2052e4f347ad458cea9072a004f334 100644 --- a/paddle/fluid/operators/parallel_do_op.cc +++ b/paddle/fluid/operators/parallel_do_op.cc @@ -196,8 +196,7 @@ class ParallelDoOp : public framework::OperatorBase { class ParallelDoOpProtoMaker : public framework::OpProtoAndCheckerMaker { public: - ParallelDoOpProtoMaker(OpProto *proto, framework::OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput(kInputs, "").AsDuplicable(); AddInput(kParameters, "").AsDuplicable(); AddInput(kPlaces, ""); diff --git a/paddle/fluid/operators/pool_op.cc b/paddle/fluid/operators/pool_op.cc index f2de075e0d82fc5bd0ac41b481ac80314f3857a3..f4fb2b132fe8d59cb50f5a1f7359240ac50445fe 100644 --- a/paddle/fluid/operators/pool_op.cc +++ b/paddle/fluid/operators/pool_op.cc @@ -135,8 +135,7 @@ framework::OpKernelType PoolOpGrad::GetExpectedKernelType( library_); } -Pool2dOpMaker::Pool2dOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { +void Pool2dOpMaker::Make() { AddInput( "X", "(Tensor) The input tensor of pooling operator. " @@ -229,8 +228,7 @@ Example: )DOC"); } -Pool3dOpMaker::Pool3dOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { +void Pool3dOpMaker::Make() { AddInput("X", "(Tensor) The input tensor of pooling operator. " "The format of input tensor is NCDHW, where N is batch size, C is " diff --git a/paddle/fluid/operators/pool_op.h b/paddle/fluid/operators/pool_op.h index a48127ea6983d3d4ea12ec4925f30af233002ef2..a63963ca926bb94ff99e5cfe6dbcb2b15075bcb8 100644 --- a/paddle/fluid/operators/pool_op.h +++ b/paddle/fluid/operators/pool_op.h @@ -50,12 +50,12 @@ class PoolOpGrad : public framework::OperatorWithKernel { class Pool2dOpMaker : public framework::OpProtoAndCheckerMaker { public: - Pool2dOpMaker(OpProto* proto, OpAttrChecker* op_checker); + void Make() override; }; class Pool3dOpMaker : public framework::OpProtoAndCheckerMaker { public: - Pool3dOpMaker(OpProto* proto, OpAttrChecker* op_checker); + void Make() override; }; template diff --git a/paddle/fluid/operators/pool_with_index_op.cc b/paddle/fluid/operators/pool_with_index_op.cc index 848cd61b23c2389d3fe11f585b256d55c1ff177f..873706593e4c856f0079738654a9e7e59a1c0cd8 100644 --- a/paddle/fluid/operators/pool_with_index_op.cc +++ b/paddle/fluid/operators/pool_with_index_op.cc @@ -100,8 +100,7 @@ class MaxPoolWithIndexOpGrad : public framework::OperatorWithKernel { class MaxPool2dWithIndexOpMaker : public framework::OpProtoAndCheckerMaker { public: - MaxPool2dWithIndexOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput( "X", "(Tensor) The input tensor of pooling operator. " @@ -177,8 +176,7 @@ Example: class MaxPool3dWithIndexOpMaker : public framework::OpProtoAndCheckerMaker { public: - MaxPool3dWithIndexOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "(Tensor) The input tensor of pooling operator. " "The format of input tensor is NCDHW, where N is batch size, C is " diff --git a/paddle/fluid/operators/positive_negative_pair_op.cc b/paddle/fluid/operators/positive_negative_pair_op.cc index d237da25a00de13057e009b6705d3241b8b26539..4d865b7f17b050ac6f04addc9949f3f65da06ded 100644 --- a/paddle/fluid/operators/positive_negative_pair_op.cc +++ b/paddle/fluid/operators/positive_negative_pair_op.cc @@ -95,8 +95,7 @@ class PositiveNegativePairOp : public framework::OperatorWithKernel { class PositiveNegativePairOpMaker : public framework::OpProtoAndCheckerMaker { public: - PositiveNegativePairOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("Score", "(Tensor, float) Model Score on an item (with " "respect to QueryID). It's a 2-D tensor with shape [batch_size, " diff --git a/paddle/fluid/operators/precision_recall_op.cc b/paddle/fluid/operators/precision_recall_op.cc index c34b0d072bdb2f5b97dd4615ff9338d98f2bfbe5..e7ce16f33fb5052ffb41fc05bd1538e2f0dc35be 100644 --- a/paddle/fluid/operators/precision_recall_op.cc +++ b/paddle/fluid/operators/precision_recall_op.cc @@ -90,8 +90,7 @@ class PrecisionRecallOp : public framework::OperatorWithKernel { class PrecisionRecallOpMaker : public framework::OpProtoAndCheckerMaker { public: - PrecisionRecallOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("MaxProbs", "(Tensor, default Tensor) A 2-D tensor with shape N x 1, " "where N is the batch size. Each row contains the max probability " diff --git a/paddle/fluid/operators/prefetch_op.cc b/paddle/fluid/operators/prefetch_op.cc index f9ae01ab5d2972d2a74b36ae6035985d1d874bb6..4cfea958e8e50156c90af8806414b043e15f8a9c 100644 --- a/paddle/fluid/operators/prefetch_op.cc +++ b/paddle/fluid/operators/prefetch_op.cc @@ -64,8 +64,7 @@ class PrefetchOp : public framework::OperatorBase { class PrefetchOpMaker : public framework::OpProtoAndCheckerMaker { public: - PrefetchOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() { AddInput("X", "(LoDTensor) Input Id variables to be sent").AsDuplicable(); AddOutput("RPCClient", "(RPCClient) The RPC client object which will be" diff --git a/paddle/fluid/operators/prelu_op.cc b/paddle/fluid/operators/prelu_op.cc index a066b3e06e5eca2661827425b5b2d0059d5bcc3c..db040509bc08c3f6ad031c5b97c93574e31337e0 100644 --- a/paddle/fluid/operators/prelu_op.cc +++ b/paddle/fluid/operators/prelu_op.cc @@ -38,8 +38,7 @@ class PReluOp : public framework::OperatorWithKernel { class PReluOpMaker : public framework::OpProtoAndCheckerMaker { public: - PReluOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "The input tensor of prelu operator."); AddInput("Alpha", "The alpha weight of prelu operator."); AddOutput("Out", "The output tensor of prelu operator."); diff --git a/paddle/fluid/operators/print_op.cc b/paddle/fluid/operators/print_op.cc index fafc7e54d7a44d6bb2dadf67135537dc16430e76..db7634918a5179a61304315ecd08350d23fb4642 100644 --- a/paddle/fluid/operators/print_op.cc +++ b/paddle/fluid/operators/print_op.cc @@ -209,8 +209,7 @@ class TensorPrintOp : public framework::OperatorBase { class PrintOpProtoAndCheckMaker : public framework::OpProtoAndCheckerMaker { public: - PrintOpProtoAndCheckMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("In", "Input tensor to be displayed."); AddAttr("first_n", "Only log `first_n` number of times."); AddAttr("message", "A string message to print as a prefix."); diff --git a/paddle/fluid/operators/prior_box_op.cc b/paddle/fluid/operators/prior_box_op.cc index 058b13eeb872aaa77a88da37db64a6d59fbdd1cf..a0b069da0dda59c769723211533df8c33511fe3f 100644 --- a/paddle/fluid/operators/prior_box_op.cc +++ b/paddle/fluid/operators/prior_box_op.cc @@ -79,8 +79,7 @@ class PriorBoxOp : public framework::OperatorWithKernel { class PriorBoxOpMaker : public framework::OpProtoAndCheckerMaker { public: - PriorBoxOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("Input", "(Tensor, default Tensor), " "the input feature data of PriorBoxOp, The layout is NCHW."); diff --git a/paddle/fluid/operators/proximal_adagrad_op.cc b/paddle/fluid/operators/proximal_adagrad_op.cc index e057244c1e974edea1b9bbc76c0585c295495299..8d8075d76111928ec9855eb0b70fe6dbd90a979b 100644 --- a/paddle/fluid/operators/proximal_adagrad_op.cc +++ b/paddle/fluid/operators/proximal_adagrad_op.cc @@ -66,8 +66,7 @@ class ProximalAdagradOp : public framework::OperatorWithKernel { class ProximalAdagradOpMaker : public framework::OpProtoAndCheckerMaker { public: - ProximalAdagradOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("Param", "(Tensor, default Tensor) " "Input parameter that has to be updated."); diff --git a/paddle/fluid/operators/proximal_gd_op.cc b/paddle/fluid/operators/proximal_gd_op.cc index ed1472631870e5aee6b0e8b8f80bb5e6c84a3851..baf9cbcba2ed89f62afc9816e0ab9e0f112e6008 100644 --- a/paddle/fluid/operators/proximal_gd_op.cc +++ b/paddle/fluid/operators/proximal_gd_op.cc @@ -54,8 +54,7 @@ class ProximalGDOp : public framework::OperatorWithKernel { class ProximalGDOpMaker : public framework::OpProtoAndCheckerMaker { public: - ProximalGDOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("Param", "(Tensor, default Tensor) " "Input parameter value that has to be updated."); diff --git a/paddle/fluid/operators/rank_loss_op.cc b/paddle/fluid/operators/rank_loss_op.cc index eb9ff8de3e4b37ef0bbf7477c1bb62856bdb6310..313cf01541dd88a0f4f8bf54fe4436984c2cbcf8 100644 --- a/paddle/fluid/operators/rank_loss_op.cc +++ b/paddle/fluid/operators/rank_loss_op.cc @@ -46,8 +46,7 @@ class RankLossOp : public framework::OperatorWithKernel { class RankLossOpMaker : public framework::OpProtoAndCheckerMaker { public: - RankLossOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("Label", "(2-D Tensor with shape [batch_size x 1]) " "The label indicating A ranked higher than B or not."); diff --git a/paddle/fluid/operators/read_op.cc b/paddle/fluid/operators/read_op.cc index bf02b9958927580608b95d6b8ecfddc7231a02d4..72a27d43584d55cd0859c63577ae85ff0f5fdfa8 100644 --- a/paddle/fluid/operators/read_op.cc +++ b/paddle/fluid/operators/read_op.cc @@ -79,8 +79,7 @@ class ReadOp : public framework::OperatorBase { class ReadOpMaker : public framework::OpProtoAndCheckerMaker { public: - ReadOpMaker(OpProto* op_proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(op_proto, op_checker) { + void Make() override { AddInput("Reader", "(ReaderHolder) The executed reader."); AddOutput("Out", "(LoDTensor) The output data.").AsDuplicable(); AddComment(R"DOC( diff --git a/paddle/fluid/operators/reader/create_batch_reader_op.cc b/paddle/fluid/operators/reader/create_batch_reader_op.cc index 04c5872bef4600e30ba572a025cc5f0a5e9839ca..4cc7cbc6e89b0712faf9ad9c51480bce00da15f5 100644 --- a/paddle/fluid/operators/reader/create_batch_reader_op.cc +++ b/paddle/fluid/operators/reader/create_batch_reader_op.cc @@ -52,9 +52,8 @@ class CreateBatchReaderOp : public framework::OperatorBase { }; class CreateBatchReaderOpMaker : public DecoratedReaderMakerBase { - public: - CreateBatchReaderOpMaker(OpProto* op_proto, OpAttrChecker* op_checker) - : DecoratedReaderMakerBase(op_proto, op_checker) { + protected: + void Apply() override { AddAttr("batch_size", "How many instances the batch reader yields each time.") .GreaterThan(0); diff --git a/paddle/fluid/operators/reader/create_double_buffer_reader_op.cc b/paddle/fluid/operators/reader/create_double_buffer_reader_op.cc index e5efac461512a9a1869318d6547233589ca45a77..bc830a2b72e657f79f4c94e24428d38ff2b7c42e 100644 --- a/paddle/fluid/operators/reader/create_double_buffer_reader_op.cc +++ b/paddle/fluid/operators/reader/create_double_buffer_reader_op.cc @@ -113,14 +113,13 @@ class CreateDoubleBufferReaderOp : public framework::OperatorBase { }; class CreateDoubleBufferReaderOpMaker : public DecoratedReaderMakerBase { - public: - CreateDoubleBufferReaderOpMaker(OpProto* op_proto, OpAttrChecker* op_checker) - : DecoratedReaderMakerBase(op_proto, op_checker) { + protected: + void Apply() override { AddComment(R"DOC( CreateDoubleBufferReader Operator A double buffer reader takes another reader as its 'underlying reader'. - It launches another thread to execute the 'underlying reader' asynchronously, + It launches another thread to execute the 'underlying reader' asynchronously, which prevents reading process from blocking subsequent training. )DOC"); std::unordered_set enum_range; diff --git a/paddle/fluid/operators/reader/create_multi_pass_reader_op.cc b/paddle/fluid/operators/reader/create_multi_pass_reader_op.cc index 0573345ba502b6a9af35710840d5acf7634f332f..249b0b7c6dbc8b8104bce95562e6e9b2a28c77f8 100644 --- a/paddle/fluid/operators/reader/create_multi_pass_reader_op.cc +++ b/paddle/fluid/operators/reader/create_multi_pass_reader_op.cc @@ -65,20 +65,19 @@ class CreateMultiPassReaderOp : public framework::OperatorBase { }; class CreateMultiPassReaderOpMaker : public DecoratedReaderMakerBase { - public: - CreateMultiPassReaderOpMaker(OpProto* op_proto, OpAttrChecker* op_checker) - : DecoratedReaderMakerBase(op_proto, op_checker) { + protected: + void Apply() override { AddAttr("pass_num", "The number of pass to run.").GreaterThan(0); AddComment(R"DOC( CreateMultiPassReader Operator - This operator creates a multi-pass reader. A multi-pass reader - is used to yield data for several pass training continuously. + This operator creates a multi-pass reader. A multi-pass reader + is used to yield data for several pass training continuously. It takes the number of passes to run as one of its attributes - ('pass_num'), and maintains a pass counter to record how many - passes it has completed. When the underlying reader reaches the - EOF, the multi-pass reader checks whether it has completed training - of the given number of pass. If not, the underlying reader will + ('pass_num'), and maintains a pass counter to record how many + passes it has completed. When the underlying reader reaches the + EOF, the multi-pass reader checks whether it has completed training + of the given number of pass. If not, the underlying reader will be re-initialized and starts a new pass automatically. )DOC"); } diff --git a/paddle/fluid/operators/reader/create_random_data_generator_op.cc b/paddle/fluid/operators/reader/create_random_data_generator_op.cc index d1cb8e47da70cab784858caea7e791151fc104dd..55bb9739e0239d31f63c3d8703bcf1d18bf459dc 100644 --- a/paddle/fluid/operators/reader/create_random_data_generator_op.cc +++ b/paddle/fluid/operators/reader/create_random_data_generator_op.cc @@ -84,9 +84,8 @@ class CreateRandomDataGeneratorOp : public framework::OperatorBase { }; class CreateRandomDataGeneratorOpMaker : public FileReaderMakerBase { - public: - CreateRandomDataGeneratorOpMaker(OpProto* op_proto, OpAttrChecker* op_checker) - : FileReaderMakerBase(op_proto, op_checker) { + protected: + void Apply() override { AddAttr("min", "The lower bound of reader's uniform distribution."); AddAttr("max", "The upper bound of reader's uniform distribution."); AddComment(R"DOC( diff --git a/paddle/fluid/operators/reader/create_recordio_file_reader_op.cc b/paddle/fluid/operators/reader/create_recordio_file_reader_op.cc index 2ae29725561769ebe6428002c9983246b8eec724..282ec3f36b98e7aa62d71fb04f72721a5464e21c 100644 --- a/paddle/fluid/operators/reader/create_recordio_file_reader_op.cc +++ b/paddle/fluid/operators/reader/create_recordio_file_reader_op.cc @@ -76,9 +76,8 @@ class CreateRecordIOReaderOp : public framework::OperatorBase { }; class CreateRecordIOReaderOpMaker : public FileReaderMakerBase { - public: - CreateRecordIOReaderOpMaker(OpProto* op_proto, OpAttrChecker* op_checker) - : FileReaderMakerBase(op_proto, op_checker) { + protected: + void Apply() override { AddAttr("filename", "The filename of record io reader"); AddComment(R"DOC( CreateRecordIOReader Operator diff --git a/paddle/fluid/operators/reader/create_shuffle_reader_op.cc b/paddle/fluid/operators/reader/create_shuffle_reader_op.cc index 13825d65913be95f4f444bd9d5271a036ec8b1e2..fd233be945932eee9f9a3c0c578a43d5b7cc83aa 100644 --- a/paddle/fluid/operators/reader/create_shuffle_reader_op.cc +++ b/paddle/fluid/operators/reader/create_shuffle_reader_op.cc @@ -92,9 +92,8 @@ class CreateShuffleReaderOp : public framework::OperatorBase { }; class CreateShuffleReaderOpMaker : public DecoratedReaderMakerBase { - public: - CreateShuffleReaderOpMaker(OpProto* op_proto, OpAttrChecker* op_checker) - : DecoratedReaderMakerBase(op_proto, op_checker) { + protected: + void Apply() override { AddAttr("buffer_size", "The shuffle buffer size.").GreaterThan(0); AddComment(R"DOC( CreateShuffleReader Operator diff --git a/paddle/fluid/operators/reader/create_threaded_reader_op.cc b/paddle/fluid/operators/reader/create_threaded_reader_op.cc index 1cb9bd36455a2287b8ba4fb4ca14a4c5338da098..1db70f3e9699dba604569c36dc35025dfe2c94fe 100644 --- a/paddle/fluid/operators/reader/create_threaded_reader_op.cc +++ b/paddle/fluid/operators/reader/create_threaded_reader_op.cc @@ -53,17 +53,16 @@ class CreateThreadedReaderOp : public framework::OperatorBase { }; class CreateThreadedReaderOpMaker : public DecoratedReaderMakerBase { - public: - CreateThreadedReaderOpMaker(OpProto* op_proto, OpAttrChecker* op_checker) - : DecoratedReaderMakerBase(op_proto, op_checker) { + protected: + void Apply() override { AddComment(R"DOC( CreateThreadedReader Operator - This operator creates a threaded reader. A threaded reader's - 'ReadNext()' can be invoked by several threads at the same - time. - When the attribute 'safe_mode' is true, the threaded reader's - 'ReInit()' is disabled to avoid unexpected bugs in multi-thread + This operator creates a threaded reader. A threaded reader's + 'ReadNext()' can be invoked by several threads at the same + time. + When the attribute 'safe_mode' is true, the threaded reader's + 'ReInit()' is disabled to avoid unexpected bugs in multi-thread environment. )DOC"); } diff --git a/paddle/fluid/operators/reader/open_files_op.cc b/paddle/fluid/operators/reader/open_files_op.cc index 91ad7d56583446ee4686e74187de166f387125df..8c0dac65dd691954b112bfa61622d399b2b9c3e5 100644 --- a/paddle/fluid/operators/reader/open_files_op.cc +++ b/paddle/fluid/operators/reader/open_files_op.cc @@ -185,9 +185,8 @@ class OpenFilesOp : public framework::OperatorBase { }; class OpenFilesOpMaker : public FileReaderMakerBase { - public: - OpenFilesOpMaker(OpProto* op_proto, OpAttrChecker* op_checker) - : FileReaderMakerBase(op_proto, op_checker) { + protected: + void Apply() override { AddAttr>("file_names", "Files to be read."); AddAttr("thread_num", "The maximal concurrent prefetch thread number.") .GreaterThan(0); @@ -196,7 +195,7 @@ class OpenFilesOpMaker : public FileReaderMakerBase { AddComment(R"DOC( OpenFiles Operator - An OpenFilesOp creates a MultiFileReader, which is able to + An OpenFilesOp creates a MultiFileReader, which is able to read data multi-threaded from multiple files. )DOC"); } diff --git a/paddle/fluid/operators/reader/reader_op_registry.cc b/paddle/fluid/operators/reader/reader_op_registry.cc index 3ff4536819b128d9c593b97f4942a0292a3b6b36..11f1ddebc48134158315ea70a2d2b9e07f2e2469 100644 --- a/paddle/fluid/operators/reader/reader_op_registry.cc +++ b/paddle/fluid/operators/reader/reader_op_registry.cc @@ -53,10 +53,7 @@ std::unique_ptr CreateReaderByFileName( return std::unique_ptr(reader); } -FileReaderMakerBase::FileReaderMakerBase( - framework::OpProtoAndCheckerMaker::OpProto* op_proto, - framework::OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(op_proto, op_checker) { +void FileReaderMakerBase::Make() { AddOutput("Out", "(ReaderHolder) The created random reader.").AsDuplicable(); AddAttr>("shape_concat", "The concat of all data's shapes."); AddAttr>( @@ -68,6 +65,7 @@ FileReaderMakerBase::FileReaderMakerBase( "It means the reader will generate two data each time," "whose shapes are [2,3,4] and [5,6] respectively."); AddAttr>("lod_levels", "The LoD levels of each data."); + Apply(); } void FileReaderInferShape::operator()(framework::InferShapeContext* ctx) const { @@ -127,13 +125,11 @@ void DecoratedReaderInferVarType::operator()( out_reader->SetDataTypes(in_reader->GetDataTypes()); } -DecoratedReaderMakerBase::DecoratedReaderMakerBase( - framework::OpProtoAndCheckerMaker::OpProto* op_proto, - framework::OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(op_proto, op_checker) { +void DecoratedReaderMakerBase::Make() { AddInput("UnderlyingReader", "(ReaderHolder) The underlying reader for creating a batch reader."); AddOutput("Out", "(ReaderHolder) The created batch reader."); + Apply(); } } // namespace reader diff --git a/paddle/fluid/operators/reader/reader_op_registry.h b/paddle/fluid/operators/reader/reader_op_registry.h index ec25f55ef5c3bb691b1213328b996c080656bb7b..244bf15f068a47efc29ee54492cdbdeb10025020 100644 --- a/paddle/fluid/operators/reader/reader_op_registry.h +++ b/paddle/fluid/operators/reader/reader_op_registry.h @@ -47,7 +47,10 @@ extern std::vector RestoreShapes( class FileReaderMakerBase : public framework::OpProtoAndCheckerMaker { public: - FileReaderMakerBase(OpProto* op_proto, OpAttrChecker* op_checker); + void Make() final; + + protected: + virtual void Apply() = 0; }; class FileReaderInferShape : public framework::InferShapeBase { @@ -76,7 +79,10 @@ class DecoratedReaderInferVarType : public framework::VarTypeInference { class DecoratedReaderMakerBase : public framework::OpProtoAndCheckerMaker { public: - DecoratedReaderMakerBase(OpProto* op_proto, OpAttrChecker* op_checker); + void Make() final; + + protected: + virtual void Apply() = 0; }; } // namespace reader diff --git a/paddle/fluid/operators/recurrent_op.cc b/paddle/fluid/operators/recurrent_op.cc index 72c2905872c528a7ed05820744f4031799ad9e46..9c1cee7022a9b9a98f026f7602f0f7badc44a49b 100644 --- a/paddle/fluid/operators/recurrent_op.cc +++ b/paddle/fluid/operators/recurrent_op.cc @@ -508,8 +508,7 @@ class RecurrentGradOp : public RecurrentBase { class RecurrentOpProtoMaker : public framework::OpProtoAndCheckerMaker { public: - RecurrentOpProtoMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput(kInputs, "rnn inputs").AsDuplicable(); AddInput(kInitialStates, "rnn initial states").AsDuplicable(); AddInput(kParameters, diff --git a/paddle/fluid/operators/recv_op.cc b/paddle/fluid/operators/recv_op.cc index a4dcf704a63ae3bad6567ddb042ea23513bccff7..7148bd0e363a71b58581a6c3c5f245d98d5b9d02 100644 --- a/paddle/fluid/operators/recv_op.cc +++ b/paddle/fluid/operators/recv_op.cc @@ -53,8 +53,7 @@ class RecvOp : public framework::OperatorBase { class RecvOpMaker : public framework::OpProtoAndCheckerMaker { public: - RecvOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() { AddOutput("Out", "(Tensor) Variables to get from server.").AsDuplicable(); AddComment(R"DOC( Recv operator diff --git a/paddle/fluid/operators/reduce_op.cc b/paddle/fluid/operators/reduce_op.cc index 093db966472cf100b2f1e4159ce20399cee1f481..eb8c21179db690e20db29c21892fd6258dd75579 100644 --- a/paddle/fluid/operators/reduce_op.cc +++ b/paddle/fluid/operators/reduce_op.cc @@ -90,8 +90,7 @@ class ReduceGradOp : public framework::OperatorWithKernel { class ReduceOpMaker : public framework::OpProtoAndCheckerMaker { public: - ReduceOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() final { AddInput("X", "(Tensor) The input tensor. Tensors with rank at most 6 are " "supported."); @@ -111,78 +110,20 @@ class ReduceOpMaker : public framework::OpProtoAndCheckerMaker { "(bool, default false) " "If true, output a scalar reduced along all dimensions.") .SetDefault(false); - comment_ = R"DOC( -{ReduceOp} Operator. + AddComment(string::Sprintf(R"DOC( +%s Operator. -This operator computes the {reduce} of input tensor along the given dimension. +This operator computes the %s of input tensor along the given dimension. The result tensor has 1 fewer dimension than the input unless keep_dim is true. If reduce_all is true, just reduce along all dimensions and output a scalar. -)DOC"; - AddComment(comment_); +)DOC", + GetOpType(), GetName())); } protected: - std::string comment_; - - void Replace(std::string *src, std::string from, std::string to) { - std::size_t len_from = std::strlen(from.c_str()); - std::size_t len_to = std::strlen(to.c_str()); - for (std::size_t pos = src->find(from); pos != std::string::npos; - pos = src->find(from, pos + len_to)) { - src->replace(pos, len_from, to); - } - } - - void SetComment(std::string name, std::string op) { - Replace(&comment_, "{ReduceOp}", name); - Replace(&comment_, "{reduce}", op); - } -}; - -class ReduceSumOpMaker : public ReduceOpMaker { - public: - ReduceSumOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : ReduceOpMaker(proto, op_checker) { - SetComment("ReduceSum", "sum"); - AddComment(comment_); - } -}; - -class ReduceMeanOpMaker : public ReduceOpMaker { - public: - ReduceMeanOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : ReduceOpMaker(proto, op_checker) { - SetComment("ReduceMean", "mean"); - AddComment(comment_); - } -}; - -class ReduceMaxOpMaker : public ReduceOpMaker { - public: - ReduceMaxOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : ReduceOpMaker(proto, op_checker) { - SetComment("ReduceMax", "max"); - AddComment(comment_); - } -}; - -class ReduceMinOpMaker : public ReduceOpMaker { - public: - ReduceMinOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : ReduceOpMaker(proto, op_checker) { - SetComment("ReduceMin", "min"); - AddComment(comment_); - } -}; - -class ReduceProdOpMaker : public ReduceOpMaker { - public: - ReduceProdOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : ReduceOpMaker(proto, op_checker) { - SetComment("ReduceProd", "production"); - AddComment(comment_); - } + virtual std::string GetName() const = 0; + virtual std::string GetOpType() const = 0; }; } // namespace operators @@ -190,25 +131,21 @@ class ReduceProdOpMaker : public ReduceOpMaker { namespace ops = paddle::operators; -REGISTER_OPERATOR(reduce_sum, ops::ReduceOp, ops::ReduceSumOpMaker, - paddle::framework::DefaultGradOpDescMaker); -REGISTER_OPERATOR(reduce_sum_grad, ops::ReduceGradOp); - -REGISTER_OPERATOR(reduce_mean, ops::ReduceOp, ops::ReduceMeanOpMaker, - paddle::framework::DefaultGradOpDescMaker); -REGISTER_OPERATOR(reduce_mean_grad, ops::ReduceGradOp); - -REGISTER_OPERATOR(reduce_max, ops::ReduceOp, ops::ReduceMaxOpMaker, - paddle::framework::DefaultGradOpDescMaker); -REGISTER_OPERATOR(reduce_max_grad, ops::ReduceGradOp); - -REGISTER_OPERATOR(reduce_min, ops::ReduceOp, ops::ReduceMinOpMaker, - paddle::framework::DefaultGradOpDescMaker); -REGISTER_OPERATOR(reduce_min_grad, ops::ReduceGradOp); - -REGISTER_OPERATOR(reduce_prod, ops::ReduceOp, ops::ReduceProdOpMaker, - paddle::framework::DefaultGradOpDescMaker); -REGISTER_OPERATOR(reduce_prod_grad, ops::ReduceGradOp); +#define REGISTER_REDUCE_OP(op_name) \ + class __##op_name##Maker__ : public ops::ReduceOpMaker { \ + protected: \ + virtual std::string GetName() const { return #op_name; } \ + virtual std::string GetOpType() const { return "Reduce " #op_name; } \ + }; \ + REGISTER_OPERATOR(reduce_##op_name, ops::ReduceOp, __##op_name##Maker__, \ + paddle::framework::DefaultGradOpDescMaker); \ + REGISTER_OPERATOR(reduce_##op_name##_grad, ops::ReduceGradOp) + +REGISTER_REDUCE_OP(sum); +REGISTER_REDUCE_OP(mean); +REGISTER_REDUCE_OP(max); +REGISTER_REDUCE_OP(min); +REGISTER_REDUCE_OP(prod); #define REGISTER_REDUCE_CPU_KERNEL(reduce_type, functor, grad_functor) \ REGISTER_OP_CPU_KERNEL(reduce_type, \ diff --git a/paddle/fluid/operators/reorder_lod_tensor_by_rank_op.cc b/paddle/fluid/operators/reorder_lod_tensor_by_rank_op.cc index 5c3e1f5678df0270c837ed407d1e6cc662276880..e4f4fe358e0e8cd2080525227f14a3d40f3c1411 100644 --- a/paddle/fluid/operators/reorder_lod_tensor_by_rank_op.cc +++ b/paddle/fluid/operators/reorder_lod_tensor_by_rank_op.cc @@ -23,9 +23,7 @@ namespace operators { class ReorderLoDTensorByRankTableOpProtoMaker : public framework::OpProtoAndCheckerMaker { public: - ReorderLoDTensorByRankTableOpProtoMaker(OpProto *proto, - OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "(LoDTensor), the input lod tensor to be reordered according to " "Input(RankTable)."); diff --git a/paddle/fluid/operators/reshape_op.cc b/paddle/fluid/operators/reshape_op.cc index 5e5ccc3ded95d57dfed37c1ac9c7eae61d36b8c0..7f743f577fbcdaf6f62e01031e25ef09a842c2e9 100644 --- a/paddle/fluid/operators/reshape_op.cc +++ b/paddle/fluid/operators/reshape_op.cc @@ -22,8 +22,7 @@ namespace operators { class ReshapeOpMaker : public framework::OpProtoAndCheckerMaker { public: - ReshapeOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "(Tensor). The input tensor of reshape operator."); AddInput("Shape", "(Tensor, optional). If provided, reshape according to " diff --git a/paddle/fluid/operators/rmsprop_op.cc b/paddle/fluid/operators/rmsprop_op.cc index a8855b3ccd1686c75953e762ce42cc27b26202e6..919ebe48ca38040274bd2052b95ef96eccff4db6 100644 --- a/paddle/fluid/operators/rmsprop_op.cc +++ b/paddle/fluid/operators/rmsprop_op.cc @@ -63,8 +63,7 @@ class RmspropOp : public framework::OperatorWithKernel { class RmspropOpMaker : public framework::OpProtoAndCheckerMaker { public: - RmspropOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("Param", "(Tensor, default Tensor) " "Input parameter value that has to be updated."); diff --git a/paddle/fluid/operators/rnn_memory_helper_op.cc b/paddle/fluid/operators/rnn_memory_helper_op.cc index 70f205d887ef710aeed02905713200ce32988987..23e5fc1112d0b1e634d0ab288721cbba57b3ffe5 100644 --- a/paddle/fluid/operators/rnn_memory_helper_op.cc +++ b/paddle/fluid/operators/rnn_memory_helper_op.cc @@ -59,8 +59,7 @@ class RNNMemoryHelperOpShapeInference : public framework::InferShapeBase { class RNNMemoryHelperOpInfoMaker : public framework::OpProtoAndCheckerMaker { public: - RNNMemoryHelperOpInfoMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", ""); AddOutput("Out", ""); AddAttr("dtype", @@ -117,8 +116,7 @@ class RNNMemoryHelperGradOp : public framework::OperatorBase { class RNNMemoryHelperGradOpInfoMaker : public framework::OpProtoAndCheckerMaker { public: - RNNMemoryHelperGradOpInfoMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput(framework::GradVarName("Out"), ""); AddInput("X", ""); AddInput("Out", ""); diff --git a/paddle/fluid/operators/roi_pool_op.cc b/paddle/fluid/operators/roi_pool_op.cc index 397e49ef20ac45515a852f466d693f358ef5461b..293abb0ea4f1ac03c3889ce2937ef8fa0845db73 100644 --- a/paddle/fluid/operators/roi_pool_op.cc +++ b/paddle/fluid/operators/roi_pool_op.cc @@ -98,8 +98,7 @@ class ROIPoolGradOp : public framework::OperatorWithKernel { class ROIPoolOpMaker : public framework::OpProtoAndCheckerMaker { public: - ROIPoolOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "(Tensor), " "the input of ROIPoolOp. " diff --git a/paddle/fluid/operators/row_conv_op.cc b/paddle/fluid/operators/row_conv_op.cc index 23f720da0b68cd2fd4c9b51182bf82f72078a906..20f140f962c3aac364a1239a663d5f340bbeb6b2 100644 --- a/paddle/fluid/operators/row_conv_op.cc +++ b/paddle/fluid/operators/row_conv_op.cc @@ -76,8 +76,7 @@ class RowConvGradOp : public framework::OperatorWithKernel { class RowConvOpMaker : public framework::OpProtoAndCheckerMaker { public: - RowConvOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : framework::OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "(LoDTensor), the input(X) is a LodTensor, which supports " "variable time-length input sequences. The underlying tensor " diff --git a/paddle/fluid/operators/save_combine_op.cc b/paddle/fluid/operators/save_combine_op.cc index 36e7522948eddd18e19707d8a96ec7d4e637c28f..cfee9207083b46f7c27354f22e82a7d3c38a027c 100644 --- a/paddle/fluid/operators/save_combine_op.cc +++ b/paddle/fluid/operators/save_combine_op.cc @@ -127,8 +127,7 @@ class SaveCombineOp : public framework::OperatorBase { class SaveCombineOpProtoMaker : public framework::OpProtoAndCheckerMaker { public: - SaveCombineOpProtoMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput( "X", "(vector) Input LoDTensors that need to be saved together in a file.") diff --git a/paddle/fluid/operators/save_op.cc b/paddle/fluid/operators/save_op.cc index dcc1b9ec204e9e273b8fd2b12f2423fc989ba502..e6d27e2dedd7668b93bd8ddc330a897d1c6fa732 100644 --- a/paddle/fluid/operators/save_op.cc +++ b/paddle/fluid/operators/save_op.cc @@ -117,8 +117,7 @@ class SaveOp : public framework::OperatorBase { class SaveOpProtoMaker : public framework::OpProtoAndCheckerMaker { public: - SaveOpProtoMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "(Tensor ) Input tensor to be saved"); AddComment(R"DOC( Save operator diff --git a/paddle/fluid/operators/scale_op.cc b/paddle/fluid/operators/scale_op.cc index 7dcf33c989c3bcd905da8017ee36ec8ce8032911..4687e21e7155fc7309fb28c881c0d47152df9ad5 100644 --- a/paddle/fluid/operators/scale_op.cc +++ b/paddle/fluid/operators/scale_op.cc @@ -37,8 +37,7 @@ class ScaleOp : public framework::OperatorWithKernel { class ScaleOpMaker : public framework::OpProtoAndCheckerMaker { public: - ScaleOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "(Tensor) Input tensor of scale operator."); AddOutput("Out", "(Tensor) Output tensor of scale operator."); AddComment(R"DOC( diff --git a/paddle/fluid/operators/scatter_op.cc b/paddle/fluid/operators/scatter_op.cc index 95b12455ea4996f00bab8a353ccd425b2c37aed1..bf5e0d864495ce3a651a31c9d5a7664fe9eb2396 100644 --- a/paddle/fluid/operators/scatter_op.cc +++ b/paddle/fluid/operators/scatter_op.cc @@ -78,8 +78,7 @@ class ScatterGradOp : public framework::OperatorWithKernel { class ScatterOpMaker : public framework::OpProtoAndCheckerMaker { public: - ScatterOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "The source input of scatter op"); AddInput("Ids", "The index input of scatter op where X will be updated"); AddInput("Updates", "The updated value of updates op"); diff --git a/paddle/fluid/operators/select_op.cc b/paddle/fluid/operators/select_op.cc index 876d8acf0d880a7ef806514014d297f98e04c53d..e71841d4d1815d50cd9800910c9db34e121beffc 100644 --- a/paddle/fluid/operators/select_op.cc +++ b/paddle/fluid/operators/select_op.cc @@ -380,8 +380,7 @@ class SelectOp : public framework::OperatorBase { class SelectOpMaker : public framework::OpProtoAndCheckerMaker { public: - SelectOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput(kX, "A set of variables, which are required by operators inside the " "cases of Select Op") diff --git a/paddle/fluid/operators/send_barrier_op.cc b/paddle/fluid/operators/send_barrier_op.cc index 12b844daaa33162b86b7daffa2e4c49785701662..1ce0907f3a9473e37f53bf7b2d42cddcb629dfa6 100644 --- a/paddle/fluid/operators/send_barrier_op.cc +++ b/paddle/fluid/operators/send_barrier_op.cc @@ -57,8 +57,7 @@ class SendBarrierOp : public framework::OperatorBase { class SendBarrierOpMaker : public framework::OpProtoAndCheckerMaker { public: - SendBarrierOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() { AddOutput("RPCClient", "(RPCClient) The RPC client object which is" "initialized at most once."); diff --git a/paddle/fluid/operators/send_op.cc b/paddle/fluid/operators/send_op.cc index e4386b640a298cd216bb60104653f20c4a96e7dc..95bb1f3c695297e6d8134a647925310207118a9b 100644 --- a/paddle/fluid/operators/send_op.cc +++ b/paddle/fluid/operators/send_op.cc @@ -92,8 +92,7 @@ class SendOp : public framework::OperatorBase { class SendOpMaker : public framework::OpProtoAndCheckerMaker { public: - SendOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() { AddInput("X", "(Tensor) Input tensor to be sent").AsDuplicable(); AddOutput("Out", "(Tensor) Output tensor to be received from server") .AsDuplicable(); diff --git a/paddle/fluid/operators/send_vars_op.cc b/paddle/fluid/operators/send_vars_op.cc index 56b3713d6af28d0787e114a672a503e86cbd85fd..f11e84c176ae97dff0fda560ce3ebe2ab72c7bcc 100644 --- a/paddle/fluid/operators/send_vars_op.cc +++ b/paddle/fluid/operators/send_vars_op.cc @@ -66,8 +66,7 @@ class SendVarsOp : public framework::OperatorBase { class SendVarsOpMaker : public framework::OpProtoAndCheckerMaker { public: - SendVarsOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() { AddInput("X", "(Tensor, SelectedRows) Input variables to be sent") .AsDuplicable(); AddOutput("RPCClient", diff --git a/paddle/fluid/operators/sequence_concat_op.cc b/paddle/fluid/operators/sequence_concat_op.cc index 3c21903e3a08dcfb55c6c07370a117d0ad633e69..077b9a5f7d935a39706ef3c2b710522bf1b713ed 100644 --- a/paddle/fluid/operators/sequence_concat_op.cc +++ b/paddle/fluid/operators/sequence_concat_op.cc @@ -43,8 +43,7 @@ class SequenceConcatOp : public framework::OperatorWithKernel { class SequenceConcatOpMaker : public framework::OpProtoAndCheckerMaker { public: - SequenceConcatOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "(LodTensorArray) Input is a vector of LoDTensor, " "each of which is a variable-length sequence or nested sequence.") diff --git a/paddle/fluid/operators/sequence_conv_op.cc b/paddle/fluid/operators/sequence_conv_op.cc index 94f4b49b0018fdbff6e67c3c081aa5706ccb2e66..ec6cb24350ae276724aae339590d40be1e9ea400 100644 --- a/paddle/fluid/operators/sequence_conv_op.cc +++ b/paddle/fluid/operators/sequence_conv_op.cc @@ -102,8 +102,7 @@ class SequenceConvGradOp : public framework::OperatorWithKernel { class SequenceConvOpMaker : public framework::OpProtoAndCheckerMaker { public: - SequenceConvOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput( "X", "(LoDTensor) the input(X) is a LodTensor, which supports " diff --git a/paddle/fluid/operators/sequence_erase_op.cc b/paddle/fluid/operators/sequence_erase_op.cc index 73c0e89512972cda002bd902ee0c78b4b77d8502..1c86486157a02c3b78ed61e840fd8e452b9cb452 100644 --- a/paddle/fluid/operators/sequence_erase_op.cc +++ b/paddle/fluid/operators/sequence_erase_op.cc @@ -37,8 +37,7 @@ class SequenceEraseOp : public framework::OperatorWithKernel { class SequenceEraseOpMaker : public framework::OpProtoAndCheckerMaker { public: - SequenceEraseOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "(2-D LoDTensor with the 2nd dim. equal to 1) " "Input LoDTensor of SequenceEraseOp."); diff --git a/paddle/fluid/operators/sequence_expand_op.cc b/paddle/fluid/operators/sequence_expand_op.cc index 84a35d7172a567a3f6505559fa45a32290288533..944c7f85e5f43679e1875fcce813382be2ba5526 100644 --- a/paddle/fluid/operators/sequence_expand_op.cc +++ b/paddle/fluid/operators/sequence_expand_op.cc @@ -94,8 +94,7 @@ class SequenceExpandOp : public framework::OperatorWithKernel { class SequenceExpandOpMaker : public framework::OpProtoAndCheckerMaker { public: - SequenceExpandOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "(LoDTensor, default LoDTensor) A 2-D LoDTensor whose lod " "level is at most 1."); diff --git a/paddle/fluid/operators/sequence_pool_op.cc b/paddle/fluid/operators/sequence_pool_op.cc index 933c8c26239d49221819a583f999389ed6fb6cb6..5c6fd13d42e43e3502a1cab85a56e019420c708d 100644 --- a/paddle/fluid/operators/sequence_pool_op.cc +++ b/paddle/fluid/operators/sequence_pool_op.cc @@ -38,8 +38,7 @@ class SequencePoolOp : public framework::OperatorWithKernel { class SequencePoolOpMaker : public framework::OpProtoAndCheckerMaker { public: - SequencePoolOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "(LoDTensor) The variable-length input of SequencePoolOp"); AddOutput("Out", "(Tensor) The output of SequencePoolOp does not contain LoD " diff --git a/paddle/fluid/operators/sequence_reshape_op.cc b/paddle/fluid/operators/sequence_reshape_op.cc index a2999650b8903f9d819a8e8011421349e098b219..ef5e6f3210234d59298fcf04c812390643c693d0 100644 --- a/paddle/fluid/operators/sequence_reshape_op.cc +++ b/paddle/fluid/operators/sequence_reshape_op.cc @@ -42,8 +42,7 @@ class SequenceReshapeOp : public framework::OperatorWithKernel { class SequenceReshapeOpMaker : public framework::OpProtoAndCheckerMaker { public: - SequenceReshapeOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "(LoDTensor, default LoDTensor) A 2-D LoDTensor with shape " "being [N, M]."); diff --git a/paddle/fluid/operators/sequence_slice_op.cc b/paddle/fluid/operators/sequence_slice_op.cc index 7cd620af07fa9b5f8fcee3c0f88207ef2800c4a1..df9243dc04c584d70dfa6ca78d5fac8423796466 100644 --- a/paddle/fluid/operators/sequence_slice_op.cc +++ b/paddle/fluid/operators/sequence_slice_op.cc @@ -79,8 +79,7 @@ class SequenceSliceGradOp : public framework::OperatorWithKernel { class SequenceSliceOpMaker : public framework::OpProtoAndCheckerMaker { public: - SequenceSliceOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "(LoDTensor), " "the input of SequenceSliceOp."); diff --git a/paddle/fluid/operators/sequence_softmax_op.cc b/paddle/fluid/operators/sequence_softmax_op.cc index a0d47c12ba606eb62bbbea4d5ea793ce915e8100..c44f8206eb5079fef969e3e527552512eebd0f1a 100644 --- a/paddle/fluid/operators/sequence_softmax_op.cc +++ b/paddle/fluid/operators/sequence_softmax_op.cc @@ -57,8 +57,7 @@ class SequenceSoftmaxOp : public framework::OperatorWithKernel { class SequenceSoftmaxOpMaker : public framework::OpProtoAndCheckerMaker { public: - SequenceSoftmaxOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "(LoDTensor) 1-D or 2-D input LoDTensor with the 2-nd dimension " "of length 1."); diff --git a/paddle/fluid/operators/sgd_op.cc b/paddle/fluid/operators/sgd_op.cc index bd04c60ffa5c1e5eb8d2051ce495ab6c685b14b5..7a2bdeac09d61603f437ff10d58d0542bb3c3689 100644 --- a/paddle/fluid/operators/sgd_op.cc +++ b/paddle/fluid/operators/sgd_op.cc @@ -68,8 +68,7 @@ class SGDOpInferVarType : public framework::VarTypeInference { class SGDOpMaker : public framework::OpProtoAndCheckerMaker { public: - SGDOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("Param", "(Tensor or SelectedRows) Input parameter"); AddInput("LearningRate", "(Tensor) Learning rate of SGD"); AddInput("Grad", "(Tensor or SelectedRows) Input gradient"); diff --git a/paddle/fluid/operators/shrink_rnn_memory_op.cc b/paddle/fluid/operators/shrink_rnn_memory_op.cc index a1871a8e7fb27d351f9d333966baa63c6f32ae01..8146c5f56104b7dec86b1c4491ed10fc2e94b58b 100644 --- a/paddle/fluid/operators/shrink_rnn_memory_op.cc +++ b/paddle/fluid/operators/shrink_rnn_memory_op.cc @@ -69,8 +69,7 @@ class ShrinkRNNMemoryOp : public ArrayOp { class ShrinkRNNMemoryOpProtoMaker : public framework::OpProtoAndCheckerMaker { public: - ShrinkRNNMemoryOpProtoMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "(LoDTensor) The RNN step memory to be shrinked."); AddInput("RankTable", "(LoDRankTable) The lod_rank_table of dynamic RNN."); AddInput("I", diff --git a/paddle/fluid/operators/sigmoid_cross_entropy_with_logits_op.cc b/paddle/fluid/operators/sigmoid_cross_entropy_with_logits_op.cc index 5db77d0493fc0abaa0a696cb559c3ca0534d4101..135e2a6f7f877c9ef159a4542b834d5627649e81 100644 --- a/paddle/fluid/operators/sigmoid_cross_entropy_with_logits_op.cc +++ b/paddle/fluid/operators/sigmoid_cross_entropy_with_logits_op.cc @@ -86,9 +86,7 @@ class SigmoidCrossEntropyWithLogitsGradOp class SigmoidCrossEntropyWithLogitsOpMaker : public framework::OpProtoAndCheckerMaker { public: - SigmoidCrossEntropyWithLogitsOpMaker(OpProto* proto, - OpAttrChecker* op_checker) - : framework::OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "(Tensor, default Tensor), a 2-D tensor with shape N x D, " "where N is the batch size and D is the number of classes. " diff --git a/paddle/fluid/operators/sign_op.cc b/paddle/fluid/operators/sign_op.cc index 8f8b7abd03212c12ca351e551621e63b4c7148c2..f3985dcc027f974e0213a73ea9a21e268d77615f 100644 --- a/paddle/fluid/operators/sign_op.cc +++ b/paddle/fluid/operators/sign_op.cc @@ -34,8 +34,7 @@ class SignOp : public framework::OperatorWithKernel { template class SignOpMaker : public framework::OpProtoAndCheckerMaker { public: - SignOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "(Tensor) Input tensor of sign operator."); AddOutput("Out", "(Tensor) Output tensor of sign operator."); AddComment(R"DOC( diff --git a/paddle/fluid/operators/smooth_l1_loss_op.cc b/paddle/fluid/operators/smooth_l1_loss_op.cc index 322581fdef27b12a06704abc9c3b8772adf002f2..c44c5f164b2d84616e9a85813e0ee5219b41df28 100644 --- a/paddle/fluid/operators/smooth_l1_loss_op.cc +++ b/paddle/fluid/operators/smooth_l1_loss_op.cc @@ -46,8 +46,7 @@ class SmoothL1LossOp : public framework::OperatorWithKernel { class SmoothL1LossOpMaker : public framework::OpProtoAndCheckerMaker { public: - SmoothL1LossOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "(Tensor, default Tensor) A tensor with rank at least 2. " "The input value of smooth l1 loss op with shape " diff --git a/paddle/fluid/operators/softmax_op.cc b/paddle/fluid/operators/softmax_op.cc index aa7b192e327704c02a26c86cc208ebe8a5cd7ba5..cc256aa627bdda0609f496cab93a2dec7d95f348 100644 --- a/paddle/fluid/operators/softmax_op.cc +++ b/paddle/fluid/operators/softmax_op.cc @@ -77,8 +77,7 @@ class SoftmaxOp : public framework::OperatorWithKernel { class SoftmaxOpMaker : public framework::OpProtoAndCheckerMaker { public: - SoftmaxOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "The input tensor of softmax. " "2-D with shape [batch_size, input_feature_dimensions]."); diff --git a/paddle/fluid/operators/softmax_with_cross_entropy_op.cc b/paddle/fluid/operators/softmax_with_cross_entropy_op.cc index 857e5733573497b56520daa7860f4feb4e01cda7..53cb716a979229c99fcbdc12f1aeab4e21b320f3 100644 --- a/paddle/fluid/operators/softmax_with_cross_entropy_op.cc +++ b/paddle/fluid/operators/softmax_with_cross_entropy_op.cc @@ -20,8 +20,7 @@ namespace operators { class SoftmaxWithCrossEntropyOpMaker : public framework::OpProtoAndCheckerMaker { public: - SoftmaxWithCrossEntropyOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("Logits", "(Tensor, default: Tensor), The unscaled log probabilities " "which is a 2-D tensor with shape [N x K]. N is the batch_size, " diff --git a/paddle/fluid/operators/split_byref_op.cc b/paddle/fluid/operators/split_byref_op.cc index 7413ce3e9ce60ed733bb4d27e9ec205e5f0a7e1b..bc998e1abbd7131a7497288cc9d66315a6fedc85 100644 --- a/paddle/fluid/operators/split_byref_op.cc +++ b/paddle/fluid/operators/split_byref_op.cc @@ -64,8 +64,7 @@ class SplitByrefOp : public framework::OperatorWithKernel { class SplitByrefOpMaker : public framework::OpProtoAndCheckerMaker { public: - SplitByrefOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "(Tensor) Input tensor of the split operator."); AddOutput("Out", "(Tensor) Output tensors of the split operator.") .AsDuplicable(); diff --git a/paddle/fluid/operators/split_ids_op.cc b/paddle/fluid/operators/split_ids_op.cc index a53cbc8ac5199061dafdc7f4cf560b9e4fc577ab..c867c46873ae7ddbdbda280351e4ab28235bcc08 100644 --- a/paddle/fluid/operators/split_ids_op.cc +++ b/paddle/fluid/operators/split_ids_op.cc @@ -19,8 +19,7 @@ namespace operators { class SplitIdsOpMaker : public framework::OpProtoAndCheckerMaker { public: - SplitIdsOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("Ids", "(LoDTensor) the input ids with shape{batch_num, 1}"); AddOutput("Out", "(LoDTensor) The outputs of the input Ids.") .AsDuplicable(); diff --git a/paddle/fluid/operators/split_lod_tensor_op.cc b/paddle/fluid/operators/split_lod_tensor_op.cc index 3222cce239988b170501f2b99e9f1253036b7fbc..767449cde981e5925b7144ff1038560c67651f3e 100644 --- a/paddle/fluid/operators/split_lod_tensor_op.cc +++ b/paddle/fluid/operators/split_lod_tensor_op.cc @@ -125,8 +125,7 @@ class SplitLoDTensorOp : public framework::OperatorBase { class SplitLoDTensorOpProtoMaker : public framework::OpProtoAndCheckerMaker { public: - SplitLoDTensorOpProtoMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "The input LoDTensor"); AddInput("Mask", "A bool column vector which mask the input"); AddOutput("OutTrue", "True branch of input LoDTensor"); diff --git a/paddle/fluid/operators/split_op.cc b/paddle/fluid/operators/split_op.cc index a4398df36bcc2d3b8bbe8949f27f5d6508861d95..5e2b2a994534c2fb1e053c067b36651d358b9da8 100644 --- a/paddle/fluid/operators/split_op.cc +++ b/paddle/fluid/operators/split_op.cc @@ -70,8 +70,7 @@ class SplitOp : public framework::OperatorWithKernel { class SplitOpMaker : public framework::OpProtoAndCheckerMaker { public: - SplitOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "(Tensor) Input tensor of the split operator."); AddOutput("Out", "(Tensor) Output tensors of the split operator.") .AsDuplicable(); diff --git a/paddle/fluid/operators/split_selected_rows_op.cc b/paddle/fluid/operators/split_selected_rows_op.cc index e1ce3d0c1bf11e9a623e4e9adc8f08f5069f4d94..76615a9405d7a8e3fa9dba8d01a956209e02ae8f 100644 --- a/paddle/fluid/operators/split_selected_rows_op.cc +++ b/paddle/fluid/operators/split_selected_rows_op.cc @@ -19,8 +19,7 @@ namespace operators { class SplitSelectedRowsOpMaker : public framework::OpProtoAndCheckerMaker { public: - SplitSelectedRowsOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "The input SelectedRows."); AddOutput("Out", "The outputs of the input SelectedRows.").AsDuplicable(); AddAttr>("height_sections", diff --git a/paddle/fluid/operators/spp_op.cc b/paddle/fluid/operators/spp_op.cc index 1cada95501a76da27081d533b451ce7f6a384a49..a2a96b72f09df86790ad1f90ead9189ff9bd581c 100644 --- a/paddle/fluid/operators/spp_op.cc +++ b/paddle/fluid/operators/spp_op.cc @@ -20,8 +20,7 @@ namespace operators { class SppOpMaker : public framework::OpProtoAndCheckerMaker { public: - SppOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput( "X", "(Tensor) The input tensor of spp operator. " diff --git a/paddle/fluid/operators/squared_l2_distance_op.cc b/paddle/fluid/operators/squared_l2_distance_op.cc index c32f575b541d6a6441cc1b6e999496eacef421a5..42532a294b2ef9ffdb240fac8596278047daf7fe 100644 --- a/paddle/fluid/operators/squared_l2_distance_op.cc +++ b/paddle/fluid/operators/squared_l2_distance_op.cc @@ -56,8 +56,7 @@ class SquaredL2DistanceOp : public framework::OperatorWithKernel { class SquaredL2DistanceOpMaker : public framework::OpProtoAndCheckerMaker { public: - SquaredL2DistanceOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "(Tensor) Input of SquaredL2DistanceOp."); AddInput("Y", "(Tensor) Target of SquaredL2DistanceOp."); AddOutput("sub_result", diff --git a/paddle/fluid/operators/squared_l2_norm_op.cc b/paddle/fluid/operators/squared_l2_norm_op.cc index 4ce51259da3530367d91b5da34f06fbe5d969fce..7bd82e0ce4add6d4434e1defaee43da178a6f309 100644 --- a/paddle/fluid/operators/squared_l2_norm_op.cc +++ b/paddle/fluid/operators/squared_l2_norm_op.cc @@ -48,8 +48,7 @@ class SquaredL2NormGradOp : public framework::OperatorWithKernel { class SquaredL2NormOpMaker : public framework::OpProtoAndCheckerMaker { public: - SquaredL2NormOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : framework::OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "(Tensor) The input of squared_l2_norm op."); AddOutput("Out", "(Scalar) The output of squared_l2_norm op."); AddComment(R"DOC( diff --git a/paddle/fluid/operators/sum_op.cc b/paddle/fluid/operators/sum_op.cc index 108f26fafe7af76eaa613d77ed77748ee43ea234..bcc5e22d4a77349e7cde9a43b83f23d4c867d994 100644 --- a/paddle/fluid/operators/sum_op.cc +++ b/paddle/fluid/operators/sum_op.cc @@ -112,8 +112,7 @@ class SumOp : public framework::OperatorWithKernel { class SumOpMaker : public framework::OpProtoAndCheckerMaker { public: - SumOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "(vector) The input tensors of sum operator.") .AsDuplicable(); AddOutput("Out", "(Tensor) The output tensor of sum operator."); diff --git a/paddle/fluid/operators/target_assign_op.cc b/paddle/fluid/operators/target_assign_op.cc index 33ff967e5e8f5afbaa62ba39ce596687ae0a71cd..9fce216e880f2af3b665202f4c4d2777995db003 100644 --- a/paddle/fluid/operators/target_assign_op.cc +++ b/paddle/fluid/operators/target_assign_op.cc @@ -65,8 +65,7 @@ class TargetAssignOp : public framework::OperatorWithKernel { class TargetAssignOpMaker : public framework::OpProtoAndCheckerMaker { public: - TargetAssignOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "(LoDTensor), This input is a 3D LoDTensor with shape [M, P, K]. " "Some elements in X will be assigned to Out based on the " diff --git a/paddle/fluid/operators/tensor_array_read_write_op.cc b/paddle/fluid/operators/tensor_array_read_write_op.cc index 2636812c42985536e7ca3475c03bbd8d1638ece6..c703d11eeccf8418250f00c801f47418ee9c85ae 100644 --- a/paddle/fluid/operators/tensor_array_read_write_op.cc +++ b/paddle/fluid/operators/tensor_array_read_write_op.cc @@ -57,8 +57,7 @@ class WriteToArrayOp : public ArrayOp { class WriteToArrayOpProtoMaker : public framework::OpProtoAndCheckerMaker { public: - WriteToArrayOpProtoMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "(LoDTensor) the tensor will be written to tensor array"); AddInput( "I", @@ -148,8 +147,7 @@ class ReadFromArrayOp : public ArrayOp { class ReadFromArrayProtoMaker : public framework::OpProtoAndCheckerMaker { public: - ReadFromArrayProtoMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "(TensorArray) the array will be read from."); AddInput("I", "(Tensor) the subscript index in tensor array. The number of " diff --git a/paddle/fluid/operators/top_k_op.cc b/paddle/fluid/operators/top_k_op.cc index 942a5de3f90f20eabe691924a570b61509eccf76..c17d1afc309c65035063348d4934ea1783b018ed 100644 --- a/paddle/fluid/operators/top_k_op.cc +++ b/paddle/fluid/operators/top_k_op.cc @@ -48,8 +48,7 @@ class TopkOp : public framework::OperatorWithKernel { class TopkOpMaker : public framework::OpProtoAndCheckerMaker { public: - TopkOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("X", "(Tensor) The input of Topk op"); AddOutput("Out", "(Tensor) The output tensor of Topk op"); AddOutput("Indices", "(Tensor) The indices of Topk elements of input"); diff --git a/paddle/fluid/operators/transpose_op.cc b/paddle/fluid/operators/transpose_op.cc index 3555cb68cab97c0cf983f1173c3b4ca9307e4f7d..60556a564c25c08612447ebd47a4b432b8a12d29 100644 --- a/paddle/fluid/operators/transpose_op.cc +++ b/paddle/fluid/operators/transpose_op.cc @@ -56,8 +56,7 @@ class TransposeOp : public framework::OperatorWithKernel { class TransposeOpMaker : public framework::OpProtoAndCheckerMaker { public: - TransposeOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput( "X", "(Tensor) The input tensor, tensors with rank up to 6 are supported."); diff --git a/paddle/fluid/operators/uniform_random_batch_size_like_op.cc b/paddle/fluid/operators/uniform_random_batch_size_like_op.cc index 00f00bb403db5e40939a1502b2219fb4d36d58e5..78fee77df8151221459b0afa0d6789bfe82cfda5 100644 --- a/paddle/fluid/operators/uniform_random_batch_size_like_op.cc +++ b/paddle/fluid/operators/uniform_random_batch_size_like_op.cc @@ -32,9 +32,8 @@ class UniformRandomBatchSizeLikeOp : public BatchSizeLikeOp { }; class UniformRandomBatchSizeLikeOpMaker : public BatchSizeLikeOpMaker { - public: - UniformRandomBatchSizeLikeOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : BatchSizeLikeOpMaker(proto, op_checker) { + protected: + void Apply() override { AddComment(R"DOC( Uniform random operator diff --git a/paddle/fluid/operators/uniform_random_op.cc b/paddle/fluid/operators/uniform_random_op.cc index 3b5cf68dd4f28d23e507058337fe55de9b88d3cd..137ea91caedabc3167146d91b063dbe9e2e2b931 100644 --- a/paddle/fluid/operators/uniform_random_op.cc +++ b/paddle/fluid/operators/uniform_random_op.cc @@ -85,8 +85,7 @@ class UniformRandomOp : public framework::OperatorWithKernel { class UniformRandomOpMaker : public framework::OpProtoAndCheckerMaker { public: - UniformRandomOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : framework::OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddOutput("Out", "(Tensor) The output tensor of uniform random op"); AddComment(R"DOC( Uniform random operator. diff --git a/paddle/fluid/operators/unpool_op.cc b/paddle/fluid/operators/unpool_op.cc index b3cd87efa21115565b32659cb35fee4b5bed2d4f..1d441b43b14ea194152095874645f8133c423efd 100644 --- a/paddle/fluid/operators/unpool_op.cc +++ b/paddle/fluid/operators/unpool_op.cc @@ -20,8 +20,7 @@ namespace operators { class Unpool2dOpMaker : public framework::OpProtoAndCheckerMaker { public: - Unpool2dOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput( "X", "(Tensor) The input tensor of unpool operator. " diff --git a/paddle/fluid/operators/warpctc_op.cc b/paddle/fluid/operators/warpctc_op.cc index 6835a5dd6286ece20c4ce6f3e951ed4b0057012c..e06c8c962f45a4e91b7efed7431571f0fc6870a3 100644 --- a/paddle/fluid/operators/warpctc_op.cc +++ b/paddle/fluid/operators/warpctc_op.cc @@ -53,8 +53,7 @@ class WarpCTCOp : public framework::OperatorWithKernel { class WarpCTCOpMaker : public framework::OpProtoAndCheckerMaker { public: - WarpCTCOpMaker(OpProto* proto, OpAttrChecker* op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput("Logits", "(LodTensor, default: LoDTensor), the unscaled " "probabilities of variable-length sequences, which is a 2-D " diff --git a/paddle/fluid/operators/while_op.cc b/paddle/fluid/operators/while_op.cc index 710cc9fc2e716da2e4fd067562a34d312e48b1a1..175c3ac5d79f24e47d21417df8e3eaeb4d5b2335 100644 --- a/paddle/fluid/operators/while_op.cc +++ b/paddle/fluid/operators/while_op.cc @@ -68,8 +68,7 @@ class WhileOp : public framework::OperatorBase { class WhileOpMaker : public framework::OpProtoAndCheckerMaker { public: - WhileOpMaker(OpProto *proto, OpAttrChecker *op_checker) - : OpProtoAndCheckerMaker(proto, op_checker) { + void Make() override { AddInput(kX, "A set of variables, which are required by operators inside the " "block of While Op.") diff --git a/python/paddle/fluid/data_feeder.py b/python/paddle/fluid/data_feeder.py index ac02401c79b787716b2e5f43e0d1c5686cf2bd13..0051b698471b40bffc12921f86dcde642714e07d 100644 --- a/python/paddle/fluid/data_feeder.py +++ b/python/paddle/fluid/data_feeder.py @@ -16,6 +16,7 @@ from __future__ import print_function import core import numpy import six.moves as six +import multiprocessing from framework import Variable, default_main_program @@ -116,3 +117,60 @@ class DataFeeder(object): for each_name, each_converter in six.zip(self.feed_names, converter): ret_dict[each_name] = each_converter.done() return ret_dict + + def feed_parallel(self, iterable, num_places=None): + if isinstance(self.place, core.CUDAPlace): + places = [ + core.CUDAPlace(i) + for i in six.xrange(self._get_number_of_places_(num_places)) + ] + else: + places = [ + core.CPUPlace() + for _ in six.xrange(self._get_number_of_places_(num_places)) + ] + + if len(iterable) != len(places): + raise ValueError("feed_parallel takes multiple mini-batches. Each " + "mini-batch will be feed on each device. The " + "number of devices and number of mini-batches " + "must be same.") + + place = self.place + for p, batch in six.zip(places, iterable): + self.place = p + yield self.feed(batch) + self.place = place + + def _get_number_of_places_(self, num_places): + if num_places is not None: + return int(num_places) + elif isinstance(self.place, core.CUDAPlace): + return core.get_cuda_device_count() + else: + return multiprocessing.cpu_count() + + def decorate_reader(self, + reader, + multi_devices, + num_places=None, + drop_last=True): + def __reader_creator__(): + if not multi_devices: + for item in reader(): + yield self.feed(item) + else: + num = self._get_number_of_places_(num_places) + item = [] + for batch in reader(): + item.append(batch) + if len(item) == num: + yield list(self.feed_parallel(item, num)) + item = [] + if not drop_last and len(item) != 0: + raise ValueError( + "The data batch which cannot fit for devices will be " + "dropped is not implementation. Other strategies are " + "not implemented") + + return __reader_creator__ diff --git a/python/paddle/fluid/inferencer.py b/python/paddle/fluid/inferencer.py index b38526bc574a103ece86aecdecf06b0bcfd6cad0..1b8b9c07622dce80245c69484bb6abf737ffca83 100644 --- a/python/paddle/fluid/inferencer.py +++ b/python/paddle/fluid/inferencer.py @@ -16,31 +16,42 @@ import core import framework import executor import io +from trainer import check_and_get_place + __all__ = ['Inferencer', ] class Inferencer(object): - def __init__(self, network_func, param_path=None, place=None): - # 1. we need to generate a framework.Program by calling - # network_func. Reference: fluid.program_guard in test_word2vec.py - - # 2. move the default_main_program to self.program. - - # 3. run the default_startup program. - - # 4. load params from param_path into scope + def __init__(self, param_path, place=None): + """ + :param param_path: the path where the inference model is saved by fluid.io.save_inference_model + :param place: place to do the inference + """ + self.param_path = param_path self.scope = core.Scope() - self.place = place - self.startup_program = framework.Program() - # TODO: generate the startup_program with network_func - - exe = executor.Executor(place) - exe.run(self.startup_program, scope=self.scope) - if param_path: + self.exe = executor.Executor(check_and_get_place(place)) + with executor.scope_guard(self.scope): # load params from param_path into scope - io.load_persistables(exe, dirname=param_path) - - def infer(self, inputs): - # run self.program - pass + [self.inference_program, _, + self.fetch_targets] = io.load_inference_model( + executor=self.exe, dirname=param_path) + + def infer(self, inputs, return_numpy=True): + """ + :param inputs: a map of {"input_name": input_var} that will be feed into the inference program + to get the predict value + :param return_numpy: if return numpy value for row tensor + :return: the predict value of the inference model + """ + if not isinstance(inputs, dict): + raise ValueError( + "inputs should be a map of {'input_name': input_var}") + + with executor.scope_guard(self.scope): + results = self.exe.run(self.inference_program, + feed=inputs, + fetch_list=self.fetch_targets, + return_numpy=return_numpy) + + return results diff --git a/python/paddle/fluid/io.py b/python/paddle/fluid/io.py index 08b8a878b6490bc989620085f3f9c06c7032d882..54506e97ed5c9a23f5a1e9624391f466c1c498d6 100644 --- a/python/paddle/fluid/io.py +++ b/python/paddle/fluid/io.py @@ -263,6 +263,9 @@ def get_inference_program(target_vars, main_program=None): def prepend_feed_ops(inference_program, feed_target_names, feed_holder_name='feed'): + if len(feed_target_names) == 0: + return + global_block = inference_program.global_block() feed_var = global_block.create_var( name=feed_holder_name, @@ -323,9 +326,10 @@ def save_inference_model(dirname, if isinstance(feeded_var_names, basestring): feeded_var_names = [feeded_var_names] else: - if not (bool(feeded_var_names) and all( - isinstance(name, basestring) for name in feeded_var_names)): - raise ValueError("'feed_var_names' should be a list of str.") + if len(feeded_var_names) > 0: + if not (bool(feeded_var_names) and all( + isinstance(name, basestring) for name in feeded_var_names)): + raise ValueError("'feed_var_names' should be a list of str.") if isinstance(target_vars, Variable): target_vars = [target_vars] diff --git a/python/paddle/fluid/layers/layer_function_generator.py b/python/paddle/fluid/layers/layer_function_generator.py index 35b01a79914b3427836d4abd51aa2e2eb471d517..295d1b7190ec39bcc6efdf72aebede14a99807aa 100644 --- a/python/paddle/fluid/layers/layer_function_generator.py +++ b/python/paddle/fluid/layers/layer_function_generator.py @@ -113,7 +113,7 @@ def generate_layer_fn(op_type): if len(not_intermediate_outputs) != 1: raise ValueError("Only one non intermediate output operator can be", - "automatically generated.") + "automatically generated. {0}".format(op_type)) if not_intermediate_outputs[0].duplicable: raise ValueError( diff --git a/python/paddle/fluid/tests/book/CMakeLists.txt b/python/paddle/fluid/tests/book/CMakeLists.txt index 673c965b662a022739f8d489c331f4de9455a926..ee734f3c782adb5196a03aca5718377009a5b4e7 100644 --- a/python/paddle/fluid/tests/book/CMakeLists.txt +++ b/python/paddle/fluid/tests/book/CMakeLists.txt @@ -5,3 +5,5 @@ string(REPLACE ".py" "" TEST_OPS "${TEST_OPS}") foreach(src ${TEST_OPS}) py_test(${src} SRCS ${src}.py) endforeach() + +add_subdirectory(high-level-api) diff --git a/python/paddle/fluid/tests/book/high-level-api/CMakeLists.txt b/python/paddle/fluid/tests/book/high-level-api/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..9ab00325a2eef3bbc79757ad1a3e6f8511c49552 --- /dev/null +++ b/python/paddle/fluid/tests/book/high-level-api/CMakeLists.txt @@ -0,0 +1,9 @@ +file(GLOB TEST_OPS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "test_*.py") +string(REPLACE ".py" "" TEST_OPS "${TEST_OPS}") + +# default test +foreach(src ${TEST_OPS}) + py_test(${src} SRCS ${src}.py) +endforeach() + +add_subdirectory(recognize_digits) diff --git a/python/paddle/fluid/tests/book/high-level-api/recognize_digits/CMakeLists.txt b/python/paddle/fluid/tests/book/high-level-api/recognize_digits/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..673c965b662a022739f8d489c331f4de9455a926 --- /dev/null +++ b/python/paddle/fluid/tests/book/high-level-api/recognize_digits/CMakeLists.txt @@ -0,0 +1,7 @@ +file(GLOB TEST_OPS RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "test_*.py") +string(REPLACE ".py" "" TEST_OPS "${TEST_OPS}") + +# default test +foreach(src ${TEST_OPS}) + py_test(${src} SRCS ${src}.py) +endforeach() diff --git a/python/paddle/fluid/tests/book/high-level-api/recognize_digits/notest_recognize_digits_conv.py b/python/paddle/fluid/tests/book/high-level-api/recognize_digits/test_recognize_digits_conv.py similarity index 57% rename from python/paddle/fluid/tests/book/high-level-api/recognize_digits/notest_recognize_digits_conv.py rename to python/paddle/fluid/tests/book/high-level-api/recognize_digits/test_recognize_digits_conv.py index a8282c71f895718930ea14a1e0bff777441c4c57..1f91f471f22f7c8fafc80672e660ddccf6f7cc4a 100644 --- a/python/paddle/fluid/tests/book/high-level-api/recognize_digits/notest_recognize_digits_conv.py +++ b/python/paddle/fluid/tests/book/high-level-api/recognize_digits/test_recognize_digits_conv.py @@ -21,7 +21,6 @@ import unittest import math import sys import os -import paddle.v2.dataset as dataset BATCH_SIZE = 64 @@ -54,47 +53,65 @@ def train_program(): predict = inference_program() cost = fluid.layers.cross_entropy(input=predict, label=label) avg_cost = fluid.layers.mean(cost) - acc = fluid.layers.accuracy(input=predict, label=label) - return avg_cost, acc + # acc = fluid.layers.accuracy(input=predict, label=label) + # return avg_cost, acc + return avg_cost def train(use_cuda, save_dirname): place = fluid.CUDAPlace(0) if use_cuda else fluid.CPUPlace() - optimizer = fluid.optimizer.Adam(learning_rate=0.001) - trainer = fluid.Trainer(train_program, place=place, optimizer=optimizer) + + trainer = fluid.Trainer( + train_func=train_program, + infer_func=inference_program, + place=place, + optimizer=optimizer) def event_handler(event): - if isinstance(event, fluid.EndIteration): - avg_cost, acc = event.values - print("avg_cost: %s" % avg_cost) - print("acc : %s" % acc) - - if (event.batch_id + 1) % 10 == 0: - test_metrics = trainer.test(reader=dataset.mnist.test()) - avg_cost_set = test_metrics[0] - acc_set = test_metrics[1] - - # get test acc and loss - acc = numpy.array(acc_set).mean() - avg_cost = numpy.array(avg_cost_set).mean() - if float(acc) > 0.2: # Smaller value to increase CI speed - trainer.save_params(save_dirname) - else: - print('BatchID {0}, Test Loss {1:0.2}, Acc {2:0.2}'.format( - event.batch_id + 1, float(avg_cost), float(acc))) - if math.isnan(float(avg_cost)): - sys.exit("got NaN loss, training failed.") + if isinstance(event, fluid.EndEpochEvent): + # if (event.epoch + 1) % 10 == 0: + # trainer.save_params(save_dirname) + trainer.save_inference_model(save_dirname) + + # TODO: Uncomment this part once we are sure that .train is working + # test_reader = paddle.batch( + # paddle.dataset.mnist.test(), batch_size=BATCH_SIZE) + # test_metrics = trainer.test(reader=test_reader) + # avg_cost_set = test_metrics[0] + # acc_set = test_metrics[1] + # + # # get test acc and loss + # acc = numpy.array(acc_set).mean() + # avg_cost = numpy.array(avg_cost_set).mean() + # + # print("avg_cost: %s" % avg_cost) + # print("acc : %s" % acc) + # + # if float(acc) > 0.2: # Smaller value to increase CI speed + # trainer.save_params(save_dirname) + # else: + # print('BatchID {0}, Test Loss {1:0.2}, Acc {2:0.2}'.format( + # event.epoch + 1, float(avg_cost), float(acc))) + # if math.isnan(float(avg_cost)): + # sys.exit("got NaN loss, training failed.") + + train_reader = paddle.batch( + paddle.reader.shuffle( + paddle.dataset.mnist.train(), buf_size=500), + batch_size=BATCH_SIZE) trainer.train( - reader=dataset.mnist.train(), num_pass=100, event_handler=event_handler) + num_epochs=1, + event_handler=event_handler, + reader=train_reader, + feed_order=['img', 'label']) def infer(use_cuda, save_dirname=None): place = fluid.CUDAPlace(0) if use_cuda else fluid.CPUPlace() - inferencer = fluid.Inferencer( - inference_program, param_path=save_dirname, place=place) + inferencer = fluid.Inferencer(param_path=save_dirname, place=place) batch_size = 1 tensor_img = numpy.random.uniform(-1.0, 1.0, @@ -114,5 +131,5 @@ def main(use_cuda): if __name__ == '__main__': - for use_cuda in (False, True): - main(use_cuda=use_cuda) + # for use_cuda in (False, True): + main(use_cuda=False) diff --git a/python/paddle/fluid/tests/book/high-level-api/recognize_digits/notest_recognize_digits_mlp.py b/python/paddle/fluid/tests/book/high-level-api/recognize_digits/test_recognize_digits_mlp.py similarity index 54% rename from python/paddle/fluid/tests/book/high-level-api/recognize_digits/notest_recognize_digits_mlp.py rename to python/paddle/fluid/tests/book/high-level-api/recognize_digits/test_recognize_digits_mlp.py index 3efa931d5886e565d2d876a31309883ee1660389..f072d70abdba5077bf0ac2ff6ff972e24c8226f5 100644 --- a/python/paddle/fluid/tests/book/high-level-api/recognize_digits/notest_recognize_digits_mlp.py +++ b/python/paddle/fluid/tests/book/high-level-api/recognize_digits/test_recognize_digits_mlp.py @@ -21,7 +21,6 @@ import unittest import math import sys import os -import paddle.v2.dataset as dataset BATCH_SIZE = 64 @@ -41,47 +40,64 @@ def train_program(): predict = inference_program() cost = fluid.layers.cross_entropy(input=predict, label=label) avg_cost = fluid.layers.mean(cost) - acc = fluid.layers.accuracy(input=predict, label=label) - return avg_cost, acc + # acc = fluid.layers.accuracy(input=predict, label=label) + # return avg_cost, acc + return avg_cost def train(use_cuda, save_dirname): place = fluid.CUDAPlace(0) if use_cuda else fluid.CPUPlace() - optimizer = fluid.optimizer.Adam(learning_rate=0.001) - trainer = fluid.Trainer(train_program, place=place, optimizer=optimizer) + + trainer = fluid.Trainer( + train_func=train_program, + infer_func=inference_program, + place=place, + optimizer=optimizer) def event_handler(event): - if isinstance(event, fluid.EndIteration): - avg_cost, acc = event.values - print("avg_cost: %s" % avg_cost) - print("acc : %s" % acc) - - if (event.batch_id + 1) % 10 == 0: - test_metrics = trainer.test(reader=dataset.mnist.test()) - avg_cost_set = test_metrics[0] - acc_set = test_metrics[1] - - # get test acc and loss - acc = numpy.array(acc_set).mean() - avg_cost = numpy.array(avg_cost_set).mean() - if float(acc) > 0.2: # Smaller value to increase CI speed - trainer.save_params(save_dirname) - else: - print('BatchID {0}, Test Loss {1:0.2}, Acc {2:0.2}'.format( - event.batch_id + 1, float(avg_cost), float(acc))) - if math.isnan(float(avg_cost)): - sys.exit("got NaN loss, training failed.") + if isinstance(event, fluid.EndEpochEvent): + # if (event.epoch + 1) % 10 == 0: + trainer.save_inference_model(save_dirname) + + # TODO: Uncomment this part once we are sure that .train is working + # test_reader = paddle.batch( + # paddle.dataset.mnist.test(), batch_size=BATCH_SIZE) + # test_metrics = trainer.test(reader=test_reader) + # avg_cost_set = test_metrics[0] + # acc_set = test_metrics[1] + # + # # get test acc and loss + # acc = numpy.array(acc_set).mean() + # avg_cost = numpy.array(avg_cost_set).mean() + # + # print("avg_cost: %s" % avg_cost) + # print("acc : %s" % acc) + # + # if float(acc) > 0.2: # Smaller value to increase CI speed + # trainer.save_params(save_dirname) + # else: + # print('BatchID {0}, Test Loss {1:0.2}, Acc {2:0.2}'.format( + # event.epoch + 1, float(avg_cost), float(acc))) + # if math.isnan(float(avg_cost)): + # sys.exit("got NaN loss, training failed.") + + train_reader = paddle.batch( + paddle.reader.shuffle( + paddle.dataset.mnist.train(), buf_size=500), + batch_size=BATCH_SIZE) trainer.train( - reader=dataset.mnist.train(), num_pass=100, event_handler=event_handler) + num_epochs=1, + event_handler=event_handler, + reader=train_reader, + feed_order=['img', 'label']) def infer(use_cuda, save_dirname=None): place = fluid.CUDAPlace(0) if use_cuda else fluid.CPUPlace() - inferencer = fluid.Inferencer( - inference_program, param_path=save_dirname, place=place) + inferencer = fluid.Inferencer(param_path=save_dirname, place=place) batch_size = 1 tensor_img = numpy.random.uniform(-1.0, 1.0, @@ -101,5 +117,5 @@ def main(use_cuda): if __name__ == '__main__': - for use_cuda in (False, True): - main(use_cuda=use_cuda) + # for use_cuda in (False, True): + main(use_cuda=False) diff --git a/python/paddle/fluid/tests/book/high-level-api/word2vec/no_test_word2vec_new_api.py b/python/paddle/fluid/tests/book/high-level-api/word2vec/no_test_word2vec_new_api.py index 93f7757a66ea9b217c7831c7263936ece0aa8f18..00ba4acf88b1b543c256a48709d7f514ebbe1e8c 100644 --- a/python/paddle/fluid/tests/book/high-level-api/word2vec/no_test_word2vec_new_api.py +++ b/python/paddle/fluid/tests/book/high-level-api/word2vec/no_test_word2vec_new_api.py @@ -99,45 +99,45 @@ def train(use_cuda, is_sparse, save_path): place = fluid.CUDAPlace(0) if use_cuda else fluid.CPUPlace() def event_handler(event): - # print type(event) if isinstance(event, fluid.EndEpochEvent): outs = trainer.test(reader=test_reader) avg_cost = outs[0] print("loss= ", avg_cost) if avg_cost < 5.0: - trainer.save_params(save_path) + trainer.save_inference_model(save_path) return if math.isnan(avg_cost): sys.exit("got NaN loss, training failed.") trainer = fluid.Trainer( partial(train_program, is_sparse), + partial(inference_program, is_sparse), fluid.optimizer.SGD(learning_rate=0.001), place=place) trainer.train( - reader=train_reader, num_epochs=100, event_handler=event_handler) + reader=train_reader, num_epochs=1, event_handler=event_handler) def infer(use_cuda, is_sparse, save_path): place = fluid.CUDAPlace(0) if use_cuda else fluid.CPUPlace() - inferencer = fluid.Inferencer( - partial(inference_program, is_sparse), - param_path=save_path, - place=place) + inferencer = fluid.Inferencer(param_path=save_path, place=place) lod = [0, 1] first_word = create_random_lodtensor(lod, place, low=0, high=dict_size - 1) second_word = create_random_lodtensor(lod, place, low=0, high=dict_size - 1) third_word = create_random_lodtensor(lod, place, low=0, high=dict_size - 1) fourth_word = create_random_lodtensor(lod, place, low=0, high=dict_size - 1) - result = inferencer.infer({ - 'firstw': first_word, - 'secondw': second_word, - 'thirdw': third_word, - 'forthw': fourth_word - }) - print(result) + + result = inferencer.infer( + { + 'firstw': first_word, + 'secondw': second_word, + 'thirdw': third_word, + 'forthw': fourth_word + }, + return_numpy=False) + print(np.array(result[0])) def main(use_cuda, is_sparse): diff --git a/python/paddle/fluid/tests/unittests/test_network_with_dtype.py b/python/paddle/fluid/tests/unittests/test_network_with_dtype.py index baafcdbb80238385752183ee0a8ff96a5da4659c..af487919a9986f0c45651e8825b8cc38231c1904 100644 --- a/python/paddle/fluid/tests/unittests/test_network_with_dtype.py +++ b/python/paddle/fluid/tests/unittests/test_network_with_dtype.py @@ -24,7 +24,7 @@ BATCH_SIZE = 20 class TestNetWithDtype(unittest.TestCase): - def setUp(self): + def set_network(self): self.dtype = "float64" self.init_dtype() self.x = fluid.layers.data(name='x', shape=[13], dtype=self.dtype) @@ -55,12 +55,14 @@ class TestNetWithDtype(unittest.TestCase): pass def test_cpu(self): + self.set_network() place = fluid.CPUPlace() self.run_net_on_place(place) def test_gpu(self): if not core.is_compiled_with_cuda(): return + self.set_network() place = fluid.CUDAPlace(0) self.run_net_on_place(place) diff --git a/python/paddle/fluid/tests/unittests/test_parallel_executor.py b/python/paddle/fluid/tests/unittests/test_parallel_executor.py index 4eb25a6e00b7564ac17db568ec78c1c84933af43..6db3a13718d0b258b297261f9df6457ad2035e3e 100644 --- a/python/paddle/fluid/tests/unittests/test_parallel_executor.py +++ b/python/paddle/fluid/tests/unittests/test_parallel_executor.py @@ -796,5 +796,42 @@ class TestFetchOp(unittest.TestCase): self.parallel_exe(train_inputs, seed=1) +class TestFeedParallel(unittest.TestCase): + def test_main(self): + main = fluid.Program() + startup = fluid.Program() + startup.random_seed = 1 + with fluid.scope_guard(fluid.core.Scope()): + with fluid.program_guard(main, startup): + data = fluid.layers.data( + name='image', shape=[3, 224, 224], dtype='float32') + label = fluid.layers.data( + name='label', shape=[1], dtype='int64') + out = Lenet(data, class_dim=102) + loss = fluid.layers.cross_entropy(input=out, label=label) + loss = fluid.layers.mean(loss) + opt = fluid.optimizer.Momentum( + learning_rate=0.1, + momentum=0.9, + regularization=fluid.regularizer.L2Decay(1e-4)) + + opt.minimize(loss) + place = fluid.CUDAPlace(0) + feeder = fluid.DataFeeder(place=place, feed_list=[data, label]) + reader = feeder.decorate_reader( + paddle.batch( + flowers.train(), batch_size=16), multi_devices=True) + exe = fluid.Executor(place) + exe.run(startup) + pe = fluid.ParallelExecutor( + use_cuda=True, loss_name=loss.name, main_program=main) + + for batch_id, data in enumerate(reader()): + loss_np = np.array(pe.run(feed=data, fetch_list=[loss.name])[0]) + print batch_id, loss_np + if batch_id == 2: + break + + if __name__ == '__main__': unittest.main() diff --git a/python/paddle/fluid/trainer.py b/python/paddle/fluid/trainer.py index 30b58b465ef2a7945ed87ce69397a050fc337623..67d8be82d5fa850a526f92753a086dac0cab5e2c 100644 --- a/python/paddle/fluid/trainer.py +++ b/python/paddle/fluid/trainer.py @@ -19,7 +19,7 @@ import executor import data_feeder import contextlib import io -import transpiler +import unique_name # optimizer is same as the parameter of Trainer.__init__. Rename it to opt_module import optimizer as opt_module @@ -56,26 +56,62 @@ class EndStepEvent(object): self.step = step_id +def check_and_get_place(place): + """ + Check the type of place or get the default place + Args: + place(None|core.CUDAPlace|core.CPUPlace): the place that trainer will be executed on. + + Raises: + TypeError if the type mismatched. + + Returns: + the original place if it is not None. + if fluid is compiled with CUDA, returns CUDAPlace(0) by default. + Otherwise returns CPUPlace by default. + """ + if place is None: + if core.is_compiled_with_cuda(): + return core.CUDAPlace(0) + else: + return core.CPUPlace() + else: + if not isinstance(place, core.CUDAPlace) and not isinstance( + place, core.CPUPlace): + raise TypeError("Place should be either CUDAPlace or CPUPlace") + return place + + class Trainer(object): """ Args: - program_func(callable): A function which will return loss. The loss must be a scaler. + train_func(callable): A function which will return loss. The loss must be a scalar. + infer_func(callable): A function which will return predict, used to save inference model optimizer(optimizer.Optimizer): The optimizer should be an instance of Optimizer place: The device place of this trainer. """ - def __init__(self, program_func, optimizer, param_path=None, place=None): + def __init__(self, + train_func, + infer_func, + optimizer, + param_path=None, + place=None): # 1. we need to generate a framework.Program by calling # program_func. Reference: fluid.program_guard in # test_word2vec.py + if not isinstance(optimizer, opt_module.Optimizer): + raise TypeError("The optimizer should be an instance of Optimizer") + + self.infer_func = infer_func self.scope = core.Scope() self.startup_program = framework.Program() self.train_program = framework.Program() with framework.program_guard(self.train_program, self.startup_program): - program_func_outs = program_func() + program_func_outs = train_func() self.test_outputs = program_func_outs if isinstance( program_func_outs, list) else [program_func_outs] self.test_program = self.train_program.clone() @@ -86,9 +122,9 @@ class Trainer(object): loss = self.test_outputs[0] optimize_ops, params_grads = optimizer.minimize(loss) - self.place = Trainer._check_and_get_place(place) + self.place = check_and_get_place(place) - self.dist_transpile_if_necessary(optimize_ops, params_grads) + self._dist_transpile_if_necessary(optimize_ops, params_grads) # 2. move the default_main_program to self.program and run the # default_startup program on an empty core.Scope() @@ -101,7 +137,7 @@ class Trainer(object): # load params from param_path into scope io.load_persistables(exe, dirname=param_path) - def dist_transpile_if_necessary(self, optimize_ops, params_grads): + def _dist_transpile_if_necessary(self, optimize_ops, params_grads): if "PADDLE_TRAINING_ROLE" not in os.environ: return @@ -190,31 +226,14 @@ class Trainer(object): exe = executor.Executor(self.place) io.save_persistables(exe, dirname=param_path) - @staticmethod - def _check_and_get_place(place): - """ - Check the type of place or get the default place - Args: - place(None|core.CUDAPlace|core.CPUPlace): the place that trainer will be executed on. - - Raises: - TypeError if the type mismatched. - - Returns: - the original place if it is not None. - if fluid is compiled with CUDA, returns CUDAPlace(0) by default. - Otherwise returns CPUPlace by default. - """ - if place is None: - if core.is_compiled_with_cuda(): - return core.CUDAPlace(0) - else: - return core.CPUPlace() - else: - if not isinstance(place, core.CUDAPlace) and not isinstance( - place, core.CPUPlace): - raise TypeError("Place should be either CUDAPlace or CPUPlace") - return place + def save_inference_model(self, model_path): + inference_program = framework.Program() + with framework.program_guard(inference_program): + with unique_name.guard(): + predict_var = self.infer_func() + predict_var = self.train_program.block(0).var(predict_var.name) + exe = executor.Executor(self.place) + io.save_inference_model(model_path, [], [predict_var], exe) @contextlib.contextmanager def _prog_and_scope_guard(self):