From 7078c1e16222798e4dd741c72921290f42f6ed0f Mon Sep 17 00:00:00 2001 From: Vvsmile <450864116@qq.com> Date: Tue, 29 Nov 2022 14:47:49 +0800 Subject: [PATCH] [Clean Fluid API]Remove API: lod_append (remove directly) (#47941) * Remove API: lod_append remove lod_append which is not used in Paddle 2.0 * remove lod_append test file --- python/paddle/fluid/layers/nn.py | 66 ------------------ .../tests/unittests/test_lod_append_op.py | 69 ------------------- tools/parallel_UT_rule.py | 2 - tools/static_mode_white_list.py | 1 - 4 files changed, 138 deletions(-) delete mode 100644 python/paddle/fluid/tests/unittests/test_lod_append_op.py diff --git a/python/paddle/fluid/layers/nn.py b/python/paddle/fluid/layers/nn.py index 00da0deea20..60371974007 100644 --- a/python/paddle/fluid/layers/nn.py +++ b/python/paddle/fluid/layers/nn.py @@ -92,7 +92,6 @@ __all__ = [ 'autoincreased_step_counter', 'unsqueeze', 'lod_reset', - 'lod_append', 'pad', 'image_resize', 'resize_bilinear', @@ -4360,71 +4359,6 @@ def lod_reset(x, y=None, target_lod=None): return out -def lod_append(x, level): - """ - Append level to LoD of :attr:`x`. - - .. code-block:: text - - * Example 1: - - given a 1-level LoDTensor x: - x.lod = [[ 2, 3, 1 ]] - x.data = [[1.0], [2.0], [3.0], [4.0], [5.0], [6.0]] - x.dims = [6, 1] - - level: [1, 1, 1, 1, 1, 1, 1] - - then we get a 2-level LoDTensor: - x.lod = [[ 2, 3, 1 ], [1, 1, 1, 1, 1, 1]] - x.data = [[1.0], [2.0], [3.0], [4.0], [5.0], [6.0]] - x.dims = [6, 1] - - Args: - x (Variable): Input variable which could be a tensor or LoDTensor. - The data type should be int32, int64, float32 or float64. - level (list|tuple|Variable, optional): The LoD level to be appended into LoD of x. - If level is variable and its lod level>0, the data type can be any type. - If level is variable and its lod level=0, the data type should be int32. - Returns: - Variable: Output variable with new LoD level. - - Raises: - ValueError: If :attr:`y` is None or and :attr:`level` is not Iterator. - - Examples: - .. code-block:: python - - import paddle.fluid as fluid - x = fluid.layers.data(name='x', shape=[6, 10], lod_level=1) - out = fluid.layers.lod_append(x, [1,1,1,1,1,1]) - """ - if x is None: - raise ValueError("Input(x) can't be None.") - if (not isinstance(level, Iterable)) and (not isinstance(level, Variable)): - raise ValueError("Input(level) must be list, tuple or Variable.") - - check_variable_and_dtype( - x, 'x', ['float32', 'float64', 'int32', 'int64'], 'lod_append' - ) - - helper = LayerHelper("lod_append", **locals()) - out = helper.create_variable_for_type_inference(dtype=x.dtype) - - inputs = {'X': x} - attrs = {'append': True} - - if isinstance(level, Variable): - inputs['Y'] = level - # TODO: check y.lod_level = 0 dtype - else: - attrs['target_lod'] = level - helper.append_op( - type="lod_reset", inputs=inputs, attrs=attrs, outputs={'Out': out} - ) - return out - - def pad(x, paddings, pad_value=0.0, name=None): r""" :alias_main: paddle.nn.functional.pad diff --git a/python/paddle/fluid/tests/unittests/test_lod_append_op.py b/python/paddle/fluid/tests/unittests/test_lod_append_op.py deleted file mode 100644 index 721a247d5d6..00000000000 --- a/python/paddle/fluid/tests/unittests/test_lod_append_op.py +++ /dev/null @@ -1,69 +0,0 @@ -# Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import unittest -import numpy as np -import paddle.fluid as fluid -from paddle.fluid import Program - - -class TestLoDAppendAPI(unittest.TestCase): - def test_api(self, use_cuda=False): - main_program = Program() - with fluid.program_guard(main_program): - x = fluid.layers.data(name='x', shape=[6], dtype='float32') - level = fluid.layers.data( - name='level', shape=[3], dtype='int32', lod_level=0 - ) - result = fluid.layers.lod_append(x, level) - - x_i = np.array([1.0, 1.0, 1.0, 1.0, 1.0, 1.0]).astype("float32") - level_i = np.array([0, 2, 6]).astype("int32") - - for use_cuda in [False, True]: - if use_cuda and not fluid.core.is_compiled_with_cuda(): - return - place = fluid.CUDAPlace(0) if use_cuda else fluid.CPUPlace() - exe = fluid.Executor(place) - [out] = exe.run( - fluid.default_main_program(), - feed={'x': x_i, 'level': level_i}, - fetch_list=[result], - return_numpy=False, - ) - self.assertEqual(out.recursive_sequence_lengths(), [[2, 4]]) - - -class TestLodAppendOpError(unittest.TestCase): - def test_error(self): - # The input(x) must be Variable. - x1 = np.array([0.9383, 0.1983, 3.2, 1.2]).astype("float64") - level1 = [0, 2, 4] - self.assertRaises(TypeError, fluid.layers.lod_append, x1, level1) - - # The input(level) must be Variable or list. - x2 = fluid.layers.data(name='x2', shape=[4], dtype='float32') - self.assertRaises(ValueError, fluid.layers.lod_append, x2, 2) - - # Input(x) dtype must be float32 or float64 or int32 or int64 - for dtype in ["bool", "float16"]: - x3 = fluid.layers.data(name='x3_' + dtype, shape=[4], dtype=dtype) - level3 = fluid.layers.data( - name='level3' + dtype, shape=[4], dtype='int32', lod_level=2 - ) - self.assertRaises(TypeError, fluid.layers.lod_append, x3, level3) - - -if __name__ == "__main__": - unittest.main() diff --git a/tools/parallel_UT_rule.py b/tools/parallel_UT_rule.py index 30d91d9685d..b2cda25fc93 100755 --- a/tools/parallel_UT_rule.py +++ b/tools/parallel_UT_rule.py @@ -1124,7 +1124,6 @@ FOURTH_HIGH_PARALLEL_JOB_NEW = [ 'test_tree_conv_op', 'test_share_data_op', 'test_ir_memory_optimize_transformer', - 'test_lod_append_op', 'test_math_op_patch', 'test_base_layer', 'test_dequantize_log_op', @@ -2467,7 +2466,6 @@ TETRAD_PARALLEL_JOB = [ 'test_merged_momentum_op', 'test_median', 'test_math_op_patch_var_base', - 'test_lod_append_op', 'test_layer_norm_op_v2', 'test_label_smooth_functional', 'test_instance_norm_op', diff --git a/tools/static_mode_white_list.py b/tools/static_mode_white_list.py index aec18068c9a..ed5fb31009a 100755 --- a/tools/static_mode_white_list.py +++ b/tools/static_mode_white_list.py @@ -314,7 +314,6 @@ STATIC_MODE_TESTING_LIST = [ 'test_load_op', 'test_load_vars_shape_check', 'test_locality_aware_nms_op', - 'test_lod_append_op', 'test_lod_array_length_op', 'test_lod_rank_table', 'test_lod_tensor_array_ops', -- GitLab