From d9b5f1261cb470f07cfa726f9e2edc0e63b7e493 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9F=B3=E6=99=93=E4=BC=9F?= <39303645+Shixiaowei02@users.noreply.github.com> Date: Fri, 30 Oct 2020 19:55:43 +0800 Subject: [PATCH] update the version of pybind, test=develop (#28284) * update version pybind to v2.4.3, test=develop * update unittests, test=develop --- cmake/external/pybind11.cmake | 3 +-- paddle/fluid/pybind/tensor_py.h | 4 +-- python/paddle/fluid/executor.py | 7 ++++- .../test_feed_data_check_shape_type.py | 10 ++----- .../fluid/tests/unittests/test_var_base.py | 27 +++---------------- 5 files changed, 14 insertions(+), 37 deletions(-) diff --git a/cmake/external/pybind11.cmake b/cmake/external/pybind11.cmake index 3a0b3676db3..8722b9003b7 100644 --- a/cmake/external/pybind11.cmake +++ b/cmake/external/pybind11.cmake @@ -17,7 +17,7 @@ include(ExternalProject) set(PYBIND_PREFIX_DIR ${THIRD_PARTY_PATH}/pybind) set(PYBIND_SOURCE_DIR ${THIRD_PARTY_PATH}/pybind/src/extern_pybind) SET(PYBIND_REPOSITORY ${GIT_URL}/pybind/pybind11.git) -SET(PYBIND_TAG v2.2.4) +SET(PYBIND_TAG v2.4.3) cache_third_party(extern_pybind REPOSITORY ${PYBIND_REPOSITORY} @@ -34,7 +34,6 @@ ExternalProject_Add( "${PYBIND_DOWNLOAD_CMD}" PREFIX ${PYBIND_PREFIX_DIR} SOURCE_DIR ${PYBIND_SOURCE_DIR} - UPDATE_COMMAND "" CONFIGURE_COMMAND "" BUILD_COMMAND "" INSTALL_COMMAND "" diff --git a/paddle/fluid/pybind/tensor_py.h b/paddle/fluid/pybind/tensor_py.h index 142ab2bb9d7..012f624f67b 100644 --- a/paddle/fluid/pybind/tensor_py.h +++ b/paddle/fluid/pybind/tensor_py.h @@ -58,7 +58,7 @@ struct npy_format_descriptor { // https://docs.python.org/3/library/struct.html#format-characters. return "e"; } - static PYBIND11_DESCR name() { return _("float16"); } + static constexpr auto name = _("float16"); }; // Note: Since bfloat16 is not a builtin type in C++ and in numpy, @@ -75,7 +75,7 @@ struct npy_format_descriptor { // https://docs.python.org/3/library/struct.html#format-characters. return "H"; } - static PYBIND11_DESCR name() { return _("bfloat16"); } + static constexpr auto name = _("bfloat16"); }; } // namespace detail diff --git a/python/paddle/fluid/executor.py b/python/paddle/fluid/executor.py index be72b4158c3..90851e6d864 100644 --- a/python/paddle/fluid/executor.py +++ b/python/paddle/fluid/executor.py @@ -1261,6 +1261,11 @@ class Executor(object): "Executor requires Program as its Parameter. But you passed in %s" % (type(program))) + if not isinstance(fetch_var_name, str): + raise TypeError( + "The name of fetch variable requires string as its Parameter. But you passed in %s" + % (type(fetch_var_name))) + if use_program_cache: cache_key = _get_strong_program_cache_key(program, feed, fetch_list) cached_program = self._get_program_cache(cache_key) @@ -1311,7 +1316,7 @@ class Executor(object): if not use_program_cache: self._default_executor.run(program.desc, scope, 0, True, True, - fetch_var_name) + [fetch_var_name]) else: self._default_executor.run_prepared_ctx(ctx, scope, False, False, False) diff --git a/python/paddle/fluid/tests/unittests/test_feed_data_check_shape_type.py b/python/paddle/fluid/tests/unittests/test_feed_data_check_shape_type.py index 4d7fc69058d..3bbc4cc2904 100644 --- a/python/paddle/fluid/tests/unittests/test_feed_data_check_shape_type.py +++ b/python/paddle/fluid/tests/unittests/test_feed_data_check_shape_type.py @@ -86,14 +86,8 @@ class TestFeedData(unittest.TestCase): self._test_feed_lod_tensor(use_cuda, use_parallel_executor) # Test exception message when feeding with error - if six.PY2: - in_shape_tuple = (long(-1), long(3), long(4), long(8)) - error_shape_list = [ - long(self.data_batch_size), long(3), long(4), long(5) - ] - else: - in_shape_tuple = (-1, 3, 4, 8) - error_shape_list = [self.data_batch_size, 3, 4, 5] + in_shape_tuple = (-1, 3, 4, 8) + error_shape_list = [self.data_batch_size, 3, 4, 5] with self.assertRaises(ValueError) as shape_mismatch_err: self._test_feed_data_shape_mismatch(use_cuda, diff --git a/python/paddle/fluid/tests/unittests/test_var_base.py b/python/paddle/fluid/tests/unittests/test_var_base.py index 42fd2de864d..41aef68db62 100644 --- a/python/paddle/fluid/tests/unittests/test_var_base.py +++ b/python/paddle/fluid/tests/unittests/test_var_base.py @@ -430,18 +430,7 @@ class TestVarBase(unittest.TestCase): paddle.set_printoptions(4, 100, 3) a_str = str(a) - if six.PY2: - expected = '''Tensor(shape=[10L, 20L], dtype=float32, place=CPUPlace, stop_gradient=True, - [[0.2727, 0.5489, 0.8655, ..., 0.2916, 0.8525, 0.9000], - [0.3806, 0.8996, 0.0928, ..., 0.9535, 0.8378, 0.6409], - [0.1484, 0.4038, 0.8294, ..., 0.0148, 0.6520, 0.4250], - ..., - [0.3426, 0.1909, 0.7240, ..., 0.4218, 0.2676, 0.5679], - [0.5561, 0.2081, 0.0676, ..., 0.9778, 0.3302, 0.9559], - [0.2665, 0.8483, 0.5389, ..., 0.4956, 0.6862, 0.9178]])''' - - else: - expected = '''Tensor(shape=[10, 20], dtype=float32, place=CPUPlace, stop_gradient=True, + expected = '''Tensor(shape=[10, 20], dtype=float32, place=CPUPlace, stop_gradient=True, [[0.2727, 0.5489, 0.8655, ..., 0.2916, 0.8525, 0.9000], [0.3806, 0.8996, 0.0928, ..., 0.9535, 0.8378, 0.6409], [0.1484, 0.4038, 0.8294, ..., 0.0148, 0.6520, 0.4250], @@ -458,12 +447,7 @@ class TestVarBase(unittest.TestCase): a = paddle.to_tensor([[1.5111111, 1.0], [0, 0]]) a_str = str(a) - if six.PY2: - expected = '''Tensor(shape=[2L, 2L], dtype=float32, place=CPUPlace, stop_gradient=True, - [[1.5111, 1. ], - [0. , 0. ]])''' - else: - expected = '''Tensor(shape=[2, 2], dtype=float32, place=CPUPlace, stop_gradient=True, + expected = '''Tensor(shape=[2, 2], dtype=float32, place=CPUPlace, stop_gradient=True, [[1.5111, 1. ], [0. , 0. ]])''' @@ -475,12 +459,7 @@ class TestVarBase(unittest.TestCase): a = paddle.to_tensor([[-1.5111111, 1.0], [0, -0.5]]) a_str = str(a) - if six.PY2: - expected = '''Tensor(shape=[2L, 2L], dtype=float32, place=CPUPlace, stop_gradient=True, - [[-1.5111, 1. ], - [ 0. , -0.5000]])''' - else: - expected = '''Tensor(shape=[2, 2], dtype=float32, place=CPUPlace, stop_gradient=True, + expected = '''Tensor(shape=[2, 2], dtype=float32, place=CPUPlace, stop_gradient=True, [[-1.5111, 1. ], [ 0. , -0.5000]])''' -- GitLab