From a52ab1351fd80ba7d14f2ce7668726c4d74ab583 Mon Sep 17 00:00:00 2001 From: Tony Cao <57024921+caolonghao@users.noreply.github.com> Date: Tue, 11 Oct 2022 12:06:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E9=80=80=E5=9C=BA=EF=BC=8C?= =?UTF-8?q?=E6=B8=85=E9=99=A4=E4=BA=86=E4=B8=8Epython2=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E7=9A=84=E4=B8=80=E4=BA=9B=E6=9D=A1=E4=BB=B6=E5=88=86=E6=94=AF?= =?UTF-8?q?=20(#46696)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- python/paddle/fluid/layers/rnn.py | 26 +++----------- python/paddle/fluid/param_attr.py | 5 +-- .../tests/unittests/test_fs_interface.py | 5 +-- .../test_imperative_data_loader_exit_func.py | 5 +-- .../test_imperative_data_loader_process.py | 5 +-- python/paddle/nn/layer/rnn.py | 11 ++---- python/paddle/tests/test_callback_visualdl.py | 4 --- python/setup.py.in | 8 ++--- tools/prune_for_jetson.py | 35 ++++++------------- tools/remove_grad_op_and_kernel.py | 18 ++++------ 10 files changed, 30 insertions(+), 92 deletions(-) diff --git a/python/paddle/fluid/layers/rnn.py b/python/paddle/fluid/layers/rnn.py index 3c1bda1baa..1c375e37a4 100644 --- a/python/paddle/fluid/layers/rnn.py +++ b/python/paddle/fluid/layers/rnn.py @@ -126,43 +126,27 @@ class RNNCell(object): Variable: tensor variable[s] packed in the same structure provided \ by shape, representing the initialized states. """ - if sys.version_info < (3, ): - integer_types = ( - int, - long, - ) - else: - integer_types = (int, ) check_variable_and_dtype(batch_ref, 'batch_ref', ['float32', 'float64', 'int32', 'int64'], 'RNNCell') - check_type(shape, 'shape', (list, tuple, type(None), integer_types), - 'RNNCell') + check_type(shape, 'shape', (list, tuple, type(None), int), 'RNNCell') if isinstance(shape, (list, tuple)): shapes = map_structure(lambda x: x, shape) if isinstance(shape, list): for i, _shape in enumerate(shapes): - check_type(_shape, 'shapes[' + str(i) + ']', integer_types, - 'RNNCell') + check_type(_shape, 'shapes[' + str(i) + ']', int, 'RNNCell') else: - check_type(shapes, 'shapes', integer_types, 'RNNCell') + check_type(shapes, 'shapes', int, 'RNNCell') check_dtype(dtype, 'dtype', ['float32', 'float64'], 'RNNCell') # TODO: use inputs and batch_size batch_ref = flatten(batch_ref)[0] def _is_shape_sequence(seq): - if sys.version_info < (3, ): - integer_types = ( - int, - long, - ) - else: - integer_types = (int, ) """For shape, list/tuple of integer is the finest-grained objection""" if (isinstance(seq, list) or isinstance(seq, tuple)): - if reduce(lambda flag, x: isinstance(x, integer_types) and flag, - seq, True): + if reduce(lambda flag, x: isinstance(x, int) and flag, seq, + True): return False # TODO: Add check for the illegal if isinstance(seq, dict): diff --git a/python/paddle/fluid/param_attr.py b/python/paddle/fluid/param_attr.py index 9d2c9e911b..fcc546bf39 100644 --- a/python/paddle/fluid/param_attr.py +++ b/python/paddle/fluid/param_attr.py @@ -84,10 +84,7 @@ class ParamAttr(object): do_model_average=True, need_clip=True): - if sys.version_info.major == 2: - check_type(name, "name", (str, type(None), unicode), "ParamAttr") - else: - check_type(name, "name", (str, type(None)), "ParamAttr") + check_type(name, "name", (str, type(None)), "ParamAttr") check_type(learning_rate, "learning_rate", (float, int), "ParamAttr") check_type(trainable, "trainable", (bool), "ParamAttr") check_type(do_model_average, "do_model_average", (bool), "ParamAttr") diff --git a/python/paddle/fluid/tests/unittests/test_fs_interface.py b/python/paddle/fluid/tests/unittests/test_fs_interface.py index 56341fa489..e97093c8cd 100644 --- a/python/paddle/fluid/tests/unittests/test_fs_interface.py +++ b/python/paddle/fluid/tests/unittests/test_fs_interface.py @@ -26,10 +26,7 @@ from paddle.distributed.fleet.utils.fs import LocalFS, FS, HDFSClient, FSTimeOut class FSTest(unittest.TestCase): def _test_method(self, func): - if sys.version_info[0] <= 2: - args = inspect.getargspec(func).args - else: - args = inspect.getfullargspec(func).args + args = inspect.getfullargspec(func).args a = None try: diff --git a/python/paddle/fluid/tests/unittests/test_imperative_data_loader_exit_func.py b/python/paddle/fluid/tests/unittests/test_imperative_data_loader_exit_func.py index 021637ec3a..f50c1e912f 100644 --- a/python/paddle/fluid/tests/unittests/test_imperative_data_loader_exit_func.py +++ b/python/paddle/fluid/tests/unittests/test_imperative_data_loader_exit_func.py @@ -21,10 +21,7 @@ import time import paddle.compat as cpt from paddle.fluid.framework import _test_eager_guard -if sys.version_info[0] == 2: - import Queue as queue -else: - import queue +import queue from paddle.fluid.reader import multiprocess_queue_set, _cleanup, CleanupFuncRegistrar diff --git a/python/paddle/fluid/tests/unittests/test_imperative_data_loader_process.py b/python/paddle/fluid/tests/unittests/test_imperative_data_loader_process.py index c860e5ed09..0f1be02f37 100644 --- a/python/paddle/fluid/tests/unittests/test_imperative_data_loader_process.py +++ b/python/paddle/fluid/tests/unittests/test_imperative_data_loader_process.py @@ -21,10 +21,7 @@ from paddle.fluid import core from paddle.fluid.reader import _reader_process_loop from paddle.fluid.framework import _test_eager_guard -if sys.version_info[0] == 2: - import Queue as queue -else: - import queue +import queue def get_random_images_and_labels(image_shape, label_shape): diff --git a/python/paddle/nn/layer/rnn.py b/python/paddle/nn/layer/rnn.py index a927258bf7..f1b728d7bb 100644 --- a/python/paddle/nn/layer/rnn.py +++ b/python/paddle/nn/layer/rnn.py @@ -188,17 +188,10 @@ class RNNCellBase(Layer): batch_ref = flatten(batch_ref)[0] def _is_shape_sequence(seq): - if sys.version_info < (3, ): - integer_types = ( - int, - long, - ) - else: - integer_types = (int, ) """For shape, list/tuple of integer is the finest-grained objection""" if (isinstance(seq, list) or isinstance(seq, tuple)): - if reduce(lambda flag, x: isinstance(x, integer_types) and flag, - seq, True): + if reduce(lambda flag, x: isinstance(x, int) and flag, seq, + True): return False # TODO: Add check for the illegal if isinstance(seq, dict): diff --git a/python/paddle/tests/test_callback_visualdl.py b/python/paddle/tests/test_callback_visualdl.py index e62c045d60..6ea6e61f4e 100644 --- a/python/paddle/tests/test_callback_visualdl.py +++ b/python/paddle/tests/test_callback_visualdl.py @@ -47,10 +47,6 @@ class TestCallbacks(unittest.TestCase): shutil.rmtree(self.save_dir) def func_visualdl_callback(self): - # visualdl not support python2 - if sys.version_info < (3, ): - return - inputs = [InputSpec([-1, 1, 28, 28], 'float32', 'image')] labels = [InputSpec([None, 1], 'int64', 'label')] diff --git a/python/setup.py.in b/python/setup.py.in index 35da6880b2..555bf40de9 100755 --- a/python/setup.py.in +++ b/python/setup.py.in @@ -735,12 +735,8 @@ else: yield # Log for PYPI -if sys.version_info > (3,0): - with open("@PADDLE_BINARY_DIR@/python/paddle/README.rst", "r", encoding='UTF-8') as f: - long_description = f.read() -else: - with open("@PADDLE_BINARY_DIR@/python/paddle/README.rst", "r")as f: - long_description = unicode(f.read(), 'UTF-8') +with open("@PADDLE_BINARY_DIR@/python/paddle/README.rst", "r", encoding='UTF-8') as f: + long_description = f.read() # strip *.so to reduce package size if '${WITH_STRIP}' == 'ON': diff --git a/tools/prune_for_jetson.py b/tools/prune_for_jetson.py index 4be99a85c4..dfefb936bd 100644 --- a/tools/prune_for_jetson.py +++ b/tools/prune_for_jetson.py @@ -54,18 +54,11 @@ def find_kernel(content, pattern): def prune_phi_kernels(): tool_dir = os.path.dirname(os.path.abspath(__file__)) - if sys.version_info[0] == 3: - all_op = glob.glob(os.path.join(tool_dir, - '../paddle/phi/kernels/**/*.cc'), - recursive=True) - all_op += glob.glob(os.path.join(tool_dir, - '../paddle/phi/kernels/**/*.cu'), - recursive=True) - elif sys.version_info[0] == 2: - all_op = find_type_files( - os.path.join(tool_dir, '../paddle/phi/kernels/'), '.cc') - all_op = find_type_files( - os.path.join(tool_dir, '../paddle/phi/kernels/'), '.cu', all_op) + + all_op = glob.glob(os.path.join(tool_dir, '../paddle/phi/kernels/**/*.cc'), + recursive=True) + all_op += glob.glob(os.path.join(tool_dir, '../paddle/phi/kernels/**/*.cu'), + recursive=True) register_op_count = 0 for op_file in all_op: @@ -139,18 +132,12 @@ def append_fluid_kernels(): #2. add op and kernel register op_white_list.append("tensorrt_engine") tool_dir = os.path.dirname(os.path.abspath(__file__)) - if sys.version_info[0] == 3: - all_op = glob.glob(os.path.join(tool_dir, - '../paddle/fluid/operators/**/*.cc'), - recursive=True) - all_op += glob.glob(os.path.join(tool_dir, - '../paddle/fluid/operators/**/*.cu'), - recursive=True) - elif sys.version_info[0] == 2: - all_op = find_type_files( - os.path.join(tool_dir, '../paddle/fluid/operators/'), '.cc') - all_op = find_type_files( - os.path.join(tool_dir, '../paddle/fluid/operators/'), '.cu', all_op) + all_op = glob.glob(os.path.join(tool_dir, + '../paddle/fluid/operators/**/*.cc'), + recursive=True) + all_op += glob.glob(os.path.join(tool_dir, + '../paddle/fluid/operators/**/*.cu'), + recursive=True) for op_file in all_op: with io.open(op_file, 'r', encoding='utf-8') as f: diff --git a/tools/remove_grad_op_and_kernel.py b/tools/remove_grad_op_and_kernel.py index 8f01895d01..6c1cd5b02a 100644 --- a/tools/remove_grad_op_and_kernel.py +++ b/tools/remove_grad_op_and_kernel.py @@ -67,18 +67,12 @@ if __name__ == '__main__': tool_dir = os.path.dirname(os.path.abspath(__file__)) - if sys.version_info[0] == 3: - all_op = glob.glob(os.path.join(tool_dir, - '../paddle/fluid/operators/**/*.cc'), - recursive=True) - all_op += glob.glob(os.path.join(tool_dir, - '../paddle/fluid/operators/**/*.cu'), - recursive=True) - elif sys.version_info[0] == 2: - all_op = find_type_files( - os.path.join(tool_dir, '../paddle/fluid/operators/'), '.cc') - all_op = find_type_files( - os.path.join(tool_dir, '../paddle/fluid/operators/'), '.cu', all_op) + all_op = glob.glob(os.path.join(tool_dir, + '../paddle/fluid/operators/**/*.cc'), + recursive=True) + all_op += glob.glob(os.path.join(tool_dir, + '../paddle/fluid/operators/**/*.cu'), + recursive=True) spec_ops = ['activation_op.cc'] -- GitLab