From c540aa040fe536999b8d4e018e619a09d21150e3 Mon Sep 17 00:00:00 2001 From: dangqingqing Date: Fri, 4 Aug 2017 14:56:17 +0800 Subject: [PATCH 1/8] Refine unit test in op_test_util --- .../paddle/v2/framework/tests/op_test_util.py | 21 ++++++++++++------- .../v2/framework/tests/test_add_two_op.py | 8 ++++--- .../framework/tests/test_cross_entropy_op.py | 10 +++++---- .../paddle/v2/framework/tests/test_mean_op.py | 4 ++-- .../paddle/v2/framework/tests/test_mul_op.py | 8 ++++--- .../v2/framework/tests/test_rowwise_add_op.py | 8 ++++--- .../paddle/v2/framework/tests/test_sgd_op.py | 11 ++++++---- .../v2/framework/tests/test_sigmoid_op.py | 4 ++-- .../v2/framework/tests/test_softmax_op.py | 6 ++++-- 9 files changed, 49 insertions(+), 31 deletions(-) diff --git a/python/paddle/v2/framework/tests/op_test_util.py b/python/paddle/v2/framework/tests/op_test_util.py index 98fae1b975ad6..cad7b0fed08fa 100644 --- a/python/paddle/v2/framework/tests/op_test_util.py +++ b/python/paddle/v2/framework/tests/op_test_util.py @@ -33,23 +33,28 @@ def test_all(self): for place in places: for in_name in func.all_input_args: - if hasattr(self, in_name): + if hasattr(self, "inputs") and in_name in self.inputs: kwargs[in_name] = in_name var = scope.new_var(in_name).get_tensor() - arr = getattr(self, in_name) + arr = self.inputs[in_name] var.set_dims(arr.shape) var.set(arr, place) else: kwargs[in_name] = "@EMPTY@" for out_name in func.all_output_args: - if hasattr(self, out_name): - kwargs[out_name] = out_name - scope.new_var(out_name).get_tensor() + if not hasattr(self, "outputs"): + raise ValueError( + "The test op must set self.outputs dict.") + if out_name not in self.outputs: + raise ValueError("The %s is not self.outputs dict." % + (out_name)) + kwargs[out_name] = out_name + scope.new_var(out_name).get_tensor() for attr_name in func.all_attr_args: - if hasattr(self, attr_name): - kwargs[attr_name] = getattr(self, attr_name) + if hasattr(self, "attrs") and attr_name in self.attrs: + kwargs[attr_name] = self.attrs[attr_name] op = func(**kwargs) @@ -60,7 +65,7 @@ def test_all(self): for out_name in func.all_output_args: actual = numpy.array(scope.find_var(out_name).get_tensor()) - expect = getattr(self, out_name) + expect = self.outputs[out_name] # TODO(qijun) The default decimal is 7, but numpy.dot and eigen.mul # has some diff, and could not pass unittest. So I set decimal 3 here. # And I will check this in future. diff --git a/python/paddle/v2/framework/tests/test_add_two_op.py b/python/paddle/v2/framework/tests/test_add_two_op.py index 6e6643201bf36..8ef48f4727b0a 100644 --- a/python/paddle/v2/framework/tests/test_add_two_op.py +++ b/python/paddle/v2/framework/tests/test_add_two_op.py @@ -12,9 +12,11 @@ class TestAddOp(unittest.TestCase): def setUp(self): self.type = "add_two" - self.X = numpy.random.random((102, 105)).astype("float32") - self.Y = numpy.random.random((102, 105)).astype("float32") - self.Out = self.X + self.Y + self.inputs = { + 'X': numpy.random.random((102, 105)).astype("float32"), + 'Y': numpy.random.random((102, 105)).astype("float32") + } + self.outputs = {'Out': self.inputs['X'] + self.inputs['Y']} class TestAddGradOp(unittest.TestCase): diff --git a/python/paddle/v2/framework/tests/test_cross_entropy_op.py b/python/paddle/v2/framework/tests/test_cross_entropy_op.py index 609c56535ef03..424207378790b 100644 --- a/python/paddle/v2/framework/tests/test_cross_entropy_op.py +++ b/python/paddle/v2/framework/tests/test_cross_entropy_op.py @@ -7,15 +7,17 @@ class TestSGD(unittest.TestCase): __metaclass__ = OpTestMeta def setUp(self): + # TODO this unit test is not passed self.type = "onehot_cross_entropy" batch_size = 100 class_num = 10 - self.X = numpy.random.random((batch_size, class_num)).astype("float32") - self.label = 5 * numpy.ones(batch_size).astype("int32") + X = numpy.random.random((batch_size, class_num)).astype("float32") + label = 5 * numpy.ones(batch_size).astype("int32") + self.inputs = {'X': X, 'label': label} Y = [] for i in range(0, batch_size): - Y.append(-numpy.log(self.X[i][self.label[i]])) - self.Y = numpy.array(Y).astype("float32") + Y.append(-numpy.log(X[i][label[i]])) + self.outputs = {'Y': numpy.array(Y).astype("float32")} if __name__ == "__main__": diff --git a/python/paddle/v2/framework/tests/test_mean_op.py b/python/paddle/v2/framework/tests/test_mean_op.py index 78fff1eeff998..b5d52b90567bc 100644 --- a/python/paddle/v2/framework/tests/test_mean_op.py +++ b/python/paddle/v2/framework/tests/test_mean_op.py @@ -8,8 +8,8 @@ class TestMeanOp(unittest.TestCase): def setUp(self): self.type = "mean" - self.X = np.random.random((32, 784)).astype("float32") - self.Out = np.mean(self.X) + self.inputs = {'X': np.random.random((32, 784)).astype("float32")} + self.outputs = {'Out': np.mean(self.inputs['X'])} if __name__ == '__main__': diff --git a/python/paddle/v2/framework/tests/test_mul_op.py b/python/paddle/v2/framework/tests/test_mul_op.py index e1ac66d3a4d23..ec0ac99156a54 100644 --- a/python/paddle/v2/framework/tests/test_mul_op.py +++ b/python/paddle/v2/framework/tests/test_mul_op.py @@ -8,9 +8,11 @@ class TestMulOp(unittest.TestCase): def setUp(self): self.type = "mul" - self.X = np.random.random((32, 84)).astype("float32") - self.Y = np.random.random((84, 100)).astype("float32") - self.Out = np.dot(self.X, self.Y) + self.inputs = { + 'X': np.random.random((32, 84)).astype("float32"), + 'Y': np.random.random((84, 100)).astype("float32") + } + self.outputs = {'Out': np.dot(self.inputs['X'], self.inputs['Y'])} if __name__ == '__main__': diff --git a/python/paddle/v2/framework/tests/test_rowwise_add_op.py b/python/paddle/v2/framework/tests/test_rowwise_add_op.py index 04abc14ee198f..f8521eb517057 100644 --- a/python/paddle/v2/framework/tests/test_rowwise_add_op.py +++ b/python/paddle/v2/framework/tests/test_rowwise_add_op.py @@ -8,9 +8,11 @@ class TestRowwiseAddOp(unittest.TestCase): def setUp(self): self.type = "rowwise_add" - self.X = np.random.random((32, 84)).astype("float32") - self.b = np.random.random(84).astype("float32") - self.Out = np.add(self.X, self.b) + self.inputs = { + 'X': np.random.random((32, 84)).astype("float32"), + 'b': np.random.random(84).astype("float32") + } + self.outputs = {'Out': np.add(self.inputs['X'], self.inputs['b'])} if __name__ == '__main__': diff --git a/python/paddle/v2/framework/tests/test_sgd_op.py b/python/paddle/v2/framework/tests/test_sgd_op.py index ca03cc11abe2c..e5f9ef865e84f 100644 --- a/python/paddle/v2/framework/tests/test_sgd_op.py +++ b/python/paddle/v2/framework/tests/test_sgd_op.py @@ -8,10 +8,13 @@ class TestSGD(unittest.TestCase): def setUp(self): self.type = "sgd" - self.param = numpy.random.random((102, 105)).astype("float32") - self.grad = numpy.random.random((102, 105)).astype("float32") - self.learning_rate = 0.1 - self.param_out = self.param - self.learning_rate * self.grad + w = numpy.random.random((102, 105)).astype("float32") + g = numpy.random.random((102, 105)).astype("float32") + lr = 0.1 + + self.inputs = {'param': w, 'grad': g} + self.attrs = {'learning_rate': lr} + self.outputs = {'param_out': w - lr * g} if __name__ == "__main__": diff --git a/python/paddle/v2/framework/tests/test_sigmoid_op.py b/python/paddle/v2/framework/tests/test_sigmoid_op.py index 50044a122f1d6..2610bcf16303d 100644 --- a/python/paddle/v2/framework/tests/test_sigmoid_op.py +++ b/python/paddle/v2/framework/tests/test_sigmoid_op.py @@ -8,8 +8,8 @@ class TestSigmoidOp(unittest.TestCase): def setUp(self): self.type = "sigmoid" - self.X = np.random.random((32, 100)).astype("float32") - self.Y = 1 / (1 + np.exp(-self.X)) + self.inputs = {'X': np.random.random((32, 100)).astype("float32")} + self.outputs = {'Y': 1 / (1 + np.exp(-self.inputs['X']))} if __name__ == '__main__': diff --git a/python/paddle/v2/framework/tests/test_softmax_op.py b/python/paddle/v2/framework/tests/test_softmax_op.py index c80888128781d..98ca8ddc860c3 100644 --- a/python/paddle/v2/framework/tests/test_softmax_op.py +++ b/python/paddle/v2/framework/tests/test_softmax_op.py @@ -19,8 +19,10 @@ class TestSoftmaxOp(unittest.TestCase): def setUp(self): self.type = "softmax" - self.X = np.random.random((32, 100)).astype("float32") - self.Y = np.apply_along_axis(stable_softmax, 1, self.X) + self.inputs = {'X': np.random.random((32, 100)).astype("float32")} + self.outputs = { + 'Y': np.apply_along_axis(stable_softmax, 1, self.inputs['X']) + } class TestSoftmaxGradOp(unittest.TestCase): From 0c2f472ca4e4e3c4444b9112c3746a5015eb69a7 Mon Sep 17 00:00:00 2001 From: Yi Wang Date: Sun, 6 Aug 2017 06:39:41 -0700 Subject: [PATCH 2/8] Use PaddlePaddle fork of any --- cmake/external/any.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/external/any.cmake b/cmake/external/any.cmake index 45e3764e8482a..5d2f7219b2007 100644 --- a/cmake/external/any.cmake +++ b/cmake/external/any.cmake @@ -7,7 +7,7 @@ INCLUDE_DIRECTORIES(${ANY_SOURCE_DIR}/src/extern_lib_any) ExternalProject_Add( extern_lib_any ${EXTERNAL_PROJECT_LOG_ARGS} - GIT_REPOSITORY "https://github.com/thelink2012/any.git" + GIT_REPOSITORY "https://github.com/PaddlePaddle/any.git" GIT_TAG "8fef1e93710a0edf8d7658999e284a1142c4c020" PREFIX ${ANY_SOURCE_DIR} UPDATE_COMMAND "" From b18e6141639807406e5569a0e447cd0d1198bcf6 Mon Sep 17 00:00:00 2001 From: dongzhihong Date: Mon, 7 Aug 2017 09:43:57 +0800 Subject: [PATCH 3/8] "change device context to pointer" --- paddle/framework/operator.cc | 4 ++-- paddle/framework/operator.h | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/paddle/framework/operator.cc b/paddle/framework/operator.cc index cb86e6be2be36..beb6793289812 100644 --- a/paddle/framework/operator.cc +++ b/paddle/framework/operator.cc @@ -22,14 +22,14 @@ namespace framework { template <> Eigen::DefaultDevice& ExecutionContext::GetEigenDevice< platform::CPUPlace, Eigen::DefaultDevice>() const { - return *device_context_.get_eigen_device(); + return *device_context_->get_eigen_device(); } #ifndef PADDLE_ONLY_CPU template <> Eigen::GpuDevice& ExecutionContext::GetEigenDevice() const { - return *device_context_.get_eigen_device(); + return *device_context_->get_eigen_device(); } #endif diff --git a/paddle/framework/operator.h b/paddle/framework/operator.h index d42e21c0a2357..b25362fef336f 100644 --- a/paddle/framework/operator.h +++ b/paddle/framework/operator.h @@ -252,7 +252,7 @@ struct EigenDeviceConverter { class ExecutionContext : public OperatorContext { public: ExecutionContext(const OperatorBase* op, const Scope& scope, - const platform::DeviceContext& device_context) + const platform::DeviceContext* device_context) : OperatorContext(op, scope), device_context_(device_context) {} template ::EigenDeviceType> DeviceType& GetEigenDevice() const; - platform::Place GetPlace() const { return device_context_.GetPlace(); } + platform::Place GetPlace() const { return device_context_->GetPlace(); } - const platform::DeviceContext& device_context_; + const platform::DeviceContext* device_context_; }; class OpKernel { @@ -311,7 +311,7 @@ class OperatorWithKernel : public OperatorBase { void Run(const Scope& scope, const platform::DeviceContext& dev_ctx) const final { auto& opKernel = AllOpKernels().at(type_).at(OpKernelKey(dev_ctx)); - opKernel->Compute(ExecutionContext(this, scope, dev_ctx)); + opKernel->Compute(ExecutionContext(this, scope, &dev_ctx)); } static std::unordered_map& From 47c011665311d444b8443275c5df9fe9dd792451 Mon Sep 17 00:00:00 2001 From: liaogang Date: Mon, 7 Aug 2017 10:14:21 +0800 Subject: [PATCH 4/8] Import HPC linear algebra libs as cblas target --- cmake/external/openblas.cmake | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cmake/external/openblas.cmake b/cmake/external/openblas.cmake index 60a1041936437..4b13bf0f2037d 100644 --- a/cmake/external/openblas.cmake +++ b/cmake/external/openblas.cmake @@ -69,8 +69,13 @@ ENDIF(NOT ${CBLAS_FOUND}) MESSAGE(STATUS "BLAS library: ${CBLAS_LIBRARIES}") INCLUDE_DIRECTORIES(${CBLAS_INC_DIR}) -ADD_LIBRARY(cblas STATIC IMPORTED) -SET_PROPERTY(TARGET cblas PROPERTY IMPORTED_LOCATION ${CBLAS_LIBRARIES}) +# FIXME(gangliao): generate cblas target to track all high performance +# linear algebra libraries for cc_library(xxx SRCS xxx.c DEPS cblas) +SET(dummyfile ${CMAKE_CURRENT_BINARY_DIR}/lib_any_dummy.c) +FILE(WRITE ${dummyfile} "const char * dummy_any = \"${dummyfile}\";") +ADD_LIBRARY(cblas STATIC ${dummyfile}) +TARGET_LINK_LIBRARIES(cblas ${CBLAS_LIBRARIES}) + IF(NOT ${CBLAS_FOUND}) ADD_DEPENDENCIES(cblas extern_openblas) LIST(APPEND external_project_dependencies cblas) From 2f9c443be3943f2698ce9f57d303aded7fba5649 Mon Sep 17 00:00:00 2001 From: liaogang Date: Mon, 7 Aug 2017 10:16:25 +0800 Subject: [PATCH 5/8] fix name typo --- cmake/external/openblas.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/external/openblas.cmake b/cmake/external/openblas.cmake index 4b13bf0f2037d..db09232c0e690 100644 --- a/cmake/external/openblas.cmake +++ b/cmake/external/openblas.cmake @@ -71,8 +71,8 @@ INCLUDE_DIRECTORIES(${CBLAS_INC_DIR}) # FIXME(gangliao): generate cblas target to track all high performance # linear algebra libraries for cc_library(xxx SRCS xxx.c DEPS cblas) -SET(dummyfile ${CMAKE_CURRENT_BINARY_DIR}/lib_any_dummy.c) -FILE(WRITE ${dummyfile} "const char * dummy_any = \"${dummyfile}\";") +SET(dummyfile ${CMAKE_CURRENT_BINARY_DIR}/cblas_dummy.c) +FILE(WRITE ${dummyfile} "const char * dummy = \"${dummyfile}\";") ADD_LIBRARY(cblas STATIC ${dummyfile}) TARGET_LINK_LIBRARIES(cblas ${CBLAS_LIBRARIES}) From 7ecdf6ad9321a00ca469f827839e03eb44df8367 Mon Sep 17 00:00:00 2001 From: liaogang Date: Mon, 7 Aug 2017 11:26:28 +0800 Subject: [PATCH 6/8] Add py_test --- cmake/generic.cmake | 13 ++++++ paddle/api/test/CMakeLists.txt | 8 +++- .../paddle/v2/framework/tests/CMakeLists.txt | 40 +++++++++++-------- python/paddle/v2/plot/tests/CMakeLists.txt | 2 +- python/paddle/v2/reader/tests/CMakeLists.txt | 3 +- python/paddle/v2/tests/CMakeLists.txt | 9 ++++- 6 files changed, 52 insertions(+), 23 deletions(-) diff --git a/cmake/generic.cmake b/cmake/generic.cmake index 41b9b5928958a..957c20bcf603f 100644 --- a/cmake/generic.cmake +++ b/cmake/generic.cmake @@ -403,3 +403,16 @@ function(py_proto_compile TARGET_NAME) protobuf_generate_python(py_srcs ${py_proto_compile_SRCS}) add_custom_target(${TARGET_NAME} ALL DEPENDS ${py_srcs}) endfunction() + +function(py_test TARGET_NAME) + if(WITH_TESTING) + set(options STATIC static SHARED shared) + set(oneValueArgs "") + set(multiValueArgs SRCS DEPS) + cmake_parse_arguments(py_test "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + add_test(NAME ${TARGET_NAME} + COMMAND env PYTHONPATH=${PADDLE_PYTHON_PACKAGE_DIR} + python2 ${py_test_SRCS} + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}) + endif() +endfunction() diff --git a/paddle/api/test/CMakeLists.txt b/paddle/api/test/CMakeLists.txt index f3b1c2c4d438b..761aeb5b17410 100644 --- a/paddle/api/test/CMakeLists.txt +++ b/paddle/api/test/CMakeLists.txt @@ -1,2 +1,6 @@ -add_python_test(test_swig_api - testArguments.py testGradientMachine.py testMatrix.py testVector.py testTrain.py testTrainer.py) +py_test(testTrain SRCS testTrain.py) +py_test(testMatrix SRCS testMatrix.py) +py_test(testVector SRCS testVector.py) +py_test(testTrainer SRCS testTrainer.py) +py_test(testArguments SRCS testArguments.py) +py_test(testGradientMachine SRCS testGradientMachine.py) diff --git a/python/paddle/v2/framework/tests/CMakeLists.txt b/python/paddle/v2/framework/tests/CMakeLists.txt index e66197030e2dd..7eec376788155 100644 --- a/python/paddle/v2/framework/tests/CMakeLists.txt +++ b/python/paddle/v2/framework/tests/CMakeLists.txt @@ -1,17 +1,23 @@ -add_python_test(test_framework - test_protobuf.py - test_scope.py - test_default_scope_funcs.py - test_op_creation_methods.py - test_net.py - test_tensor.py - test_fc_op.py - test_add_two_op.py - test_sgd_op.py - test_mul_op.py - test_mean_op.py - test_sigmoid_op.py - test_softmax_op.py - test_rowwise_add_op.py - test_network.py - gradient_checker.py) +py_test(test_net SRCS test_net.py) + +py_test(test_fc_op SRCS test_fc_op.py) +py_test(test_scope SRCS test_scope.py) + +py_test(test_tensor SRCS test_tensor.py) +py_test(test_mul_op SRCS test_mul_op.py) + +py_test(test_network SRCS test_network.py) +py_test(test_mean_op SRCS test_mean_op.py) + +py_test(test_protobuf SRCS test_protobuf.py) + +py_test(test_add_two_op SRCS test_add_two_op.py) +py_test(test_sigmoid_op SRCS test_sigmoid_op.py) +py_test(test_softmax_op SRCS test_softmax_op.py) + +py_test(gradient_checker SRCS gradient_checker.py) + +py_test(test_rowwise_add_op SRCS test_rowwise_add_op.py) + +py_test(test_default_scope_funcs SRCS test_default_scope_funcs.py) +py_test(test_op_creation_methods SRCS test_op_creation_methods.py) diff --git a/python/paddle/v2/plot/tests/CMakeLists.txt b/python/paddle/v2/plot/tests/CMakeLists.txt index da5cd764889b4..4b6c1c8096918 100644 --- a/python/paddle/v2/plot/tests/CMakeLists.txt +++ b/python/paddle/v2/plot/tests/CMakeLists.txt @@ -1,5 +1,5 @@ if (NOT APPLE) # The Mac OS X backend will not be able to function correctly if Python is # not installed as a framework. - add_python_test(test_ploter test_ploter.py) + py_test(test_ploter SRCS test_ploter.py) endif() diff --git a/python/paddle/v2/reader/tests/CMakeLists.txt b/python/paddle/v2/reader/tests/CMakeLists.txt index 6a1d337b232c7..107d5912e1567 100644 --- a/python/paddle/v2/reader/tests/CMakeLists.txt +++ b/python/paddle/v2/reader/tests/CMakeLists.txt @@ -1 +1,2 @@ -add_python_test(reader_tests creator_test.py decorator_test.py) +py_test(creator_test SRCS creator_test.py) +py_test(decorator_test SRCS decorator_test.py) diff --git a/python/paddle/v2/tests/CMakeLists.txt b/python/paddle/v2/tests/CMakeLists.txt index 058f22befd065..b779155959432 100644 --- a/python/paddle/v2/tests/CMakeLists.txt +++ b/python/paddle/v2/tests/CMakeLists.txt @@ -1,2 +1,7 @@ -add_python_test(test_v2_api test_data_feeder.py test_op.py test_parameters.py -test_layer.py test_rnn_layer.py test_topology.py test_image.py) +py_test(test_op SRCS test_op.py) +py_test(test_image SRCS test_image.py) +py_test(test_layer SRCS test_layer.py) +py_test(test_topology SRCS test_topology.py) +py_test(test_rnn_layer SRCS test_rnn_layer.py) +py_test(test_parameters SRCS test_parameters.py) +py_test(test_data_feeder SRCS test_data_feeder.py) From 9f816352e56f9f350a49cb5822c1f2bf0327300a Mon Sep 17 00:00:00 2001 From: Yu Yang Date: Mon, 7 Aug 2017 14:40:07 +0800 Subject: [PATCH 7/8] Follow comments --- python/paddle/v2/framework/op.py | 40 ++++++++++++------- .../paddle/v2/framework/tests/CMakeLists.txt | 2 +- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/python/paddle/v2/framework/op.py b/python/paddle/v2/framework/op.py index a3dbd0cc89394..81c8c3fed8446 100644 --- a/python/paddle/v2/framework/op.py +++ b/python/paddle/v2/framework/op.py @@ -145,6 +145,16 @@ def any_is_true(generator): return False +class OpInfo(object): + def __init__(self, name, method, inputs, outputs, attrs, no_temp_outputs): + self.name = name + self.method = method + self.inputs = inputs + self.outputs = outputs + self.attrs = attrs + self.no_temp_outputs = no_temp_outputs + + def create_op_creation_method(op_proto): """ Generate op creation method for an OpProto @@ -155,15 +165,15 @@ def __impl__(*args, **kwargs): opdesc = method(*args, **kwargs) return core.Operator.create(opdesc.SerializeToString()) - return { - 'method': __impl__, - 'name': op_proto.type, - 'all_inputs': [var.name for var in op_proto.inputs], - 'all_outputs': [var.name for var in op_proto.outputs], - 'all_attrs': [attr.name for attr in op_proto.attrs], - 'all_no_temp_outputs': - [var.name for var in op_proto.outputs if not var.temporary] - } + return OpInfo( + method=__impl__, + name=op_proto.type, + inputs=[var.name for var in op_proto.inputs], + outputs=[var.name for var in op_proto.outputs], + attrs=[attr.name for attr in op_proto.attrs], + no_temp_outputs=[ + var.name for var in op_proto.outputs if not var.temporary + ]) class OperatorFactory(object): @@ -185,27 +195,27 @@ def __call__(self, *args, **kwargs): "argument except type") t = args[0] - return self.get_op_creation_info(t)['method'](**kwargs) + return self.get_op_info(t).method(**kwargs) def types(self): return self.op_methods.keys() - def get_op_creation_info(self, t): + def get_op_info(self, t): if t not in self.op_methods: raise ValueError("operator %s is not registered", t) return self.op_methods.get(t) def get_op_input_names(self, type): - return self.get_op_creation_info(type)['all_inputs'] + return self.get_op_info(type).inputs def get_op_output_names(self, type): - return self.get_op_creation_info(type)['all_outputs'] + return self.get_op_info(type).outputs def get_op_attr_names(self, type): - return self.get_op_creation_info(type)['all_attrs'] + return self.get_op_info(type).attrs def get_op_no_temp_output_names(self, type): - return self.get_op_creation_info(type)['all_no_temp_outputs'] + return self.get_op_info(type).no_temp_outputs Operator = OperatorFactory() # Default global factory diff --git a/python/paddle/v2/framework/tests/CMakeLists.txt b/python/paddle/v2/framework/tests/CMakeLists.txt index 2c648d22f35a1..d01e005aca6d4 100644 --- a/python/paddle/v2/framework/tests/CMakeLists.txt +++ b/python/paddle/v2/framework/tests/CMakeLists.txt @@ -20,4 +20,4 @@ py_test(gradient_checker SRCS gradient_checker.py) py_test(test_rowwise_add_op SRCS test_rowwise_add_op.py) py_test(test_default_scope_funcs SRCS test_default_scope_funcs.py) -py_test(test_operator SRCS test_operator.py +py_test(test_operator SRCS test_operator.py) From 460326f4b2233037aac7629d089f70d8ee389eb2 Mon Sep 17 00:00:00 2001 From: Yu Yang Date: Mon, 7 Aug 2017 16:45:56 +0800 Subject: [PATCH 8/8] Fix CI Test --- python/paddle/v2/framework/op.py | 2 +- python/paddle/v2/framework/tests/CMakeLists.txt | 1 - python/paddle/v2/framework/tests/op_test_util.py | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/python/paddle/v2/framework/op.py b/python/paddle/v2/framework/op.py index 81c8c3fed8446..7fd8b55a5d167 100644 --- a/python/paddle/v2/framework/op.py +++ b/python/paddle/v2/framework/op.py @@ -181,7 +181,7 @@ def __init__(self): self.op_methods = dict() for op_proto in get_all_op_protos(): method = create_op_creation_method(op_proto) - self.op_methods[method['name']] = method + self.op_methods[method.name] = method def __call__(self, *args, **kwargs): if 'type' in kwargs: diff --git a/python/paddle/v2/framework/tests/CMakeLists.txt b/python/paddle/v2/framework/tests/CMakeLists.txt index d01e005aca6d4..4322781b342fa 100644 --- a/python/paddle/v2/framework/tests/CMakeLists.txt +++ b/python/paddle/v2/framework/tests/CMakeLists.txt @@ -6,7 +6,6 @@ py_test(test_scope SRCS test_scope.py) py_test(test_tensor SRCS test_tensor.py) py_test(test_mul_op SRCS test_mul_op.py) -py_test(test_network SRCS test_network.py) py_test(test_mean_op SRCS test_mean_op.py) py_test(test_protobuf SRCS test_protobuf.py) diff --git a/python/paddle/v2/framework/tests/op_test_util.py b/python/paddle/v2/framework/tests/op_test_util.py index d1f6de22e7c70..034df88ed841c 100644 --- a/python/paddle/v2/framework/tests/op_test_util.py +++ b/python/paddle/v2/framework/tests/op_test_util.py @@ -29,7 +29,7 @@ def test_all(self): for place in places: for in_name in Operator.get_op_input_names(self.type): - if hasattr(self, "inputs") and in_name in self.inputs + if hasattr(self, "inputs") and in_name in self.inputs: kwargs[in_name] = in_name var = scope.new_var(in_name).get_tensor() arr = self.inputs[in_name]