From 6de3bdb35347762bd44ac3ca21de915e65a3fec2 Mon Sep 17 00:00:00 2001 From: HongyuJia Date: Mon, 15 Aug 2022 19:01:16 +0800 Subject: [PATCH] [phi] change op name linear_interp_v2 to linear_interp (#45128) * change name linear_interp_v2 to linear_interp * fix deprecated_op_names * deprecated_op_names add linear_interp_grad --- paddle/phi/api/yaml/legacy_api.yaml | 6 +- paddle/phi/api/yaml/legacy_backward.yaml | 6 +- paddle/phi/core/compat/op_utils.h | 65 ++++++++++--------- .../kernels/cpu/interpolate_grad_kernel.cc | 2 +- paddle/phi/kernels/cpu/interpolate_kernel.cc | 2 +- .../kernels/gpu/interpolate_grad_kernel.cu | 2 +- paddle/phi/kernels/gpu/interpolate_kernel.cu | 2 +- paddle/phi/ops/compat/interpolate_sig.cc | 7 +- .../unittests/test_linear_interp_v2_op.py | 45 ++++++------- python/paddle/nn/functional/common.py | 22 +++---- 10 files changed, 80 insertions(+), 79 deletions(-) diff --git a/paddle/phi/api/yaml/legacy_api.yaml b/paddle/phi/api/yaml/legacy_api.yaml index d06d87ecf8..b50b309689 100755 --- a/paddle/phi/api/yaml/legacy_api.yaml +++ b/paddle/phi/api/yaml/legacy_api.yaml @@ -1428,16 +1428,16 @@ kernel : func : less_than -- api : linear_interp_v2 +- api : linear_interp args : (Tensor x, Tensor out_size, Tensor[] size_tensor, Tensor scale_tensor, str data_layout, int out_d, int out_h, int out_w, float[] scale, str interp_method, bool align_corners, int align_mode) output : Tensor(output) infer_meta : func : InterpolateInferMeta optional: out_size, size_tensor, scale_tensor kernel : - func : linear_interp_v2 + func : linear_interp data_type : x - backward : linear_interp_v2_grad + backward : linear_interp_grad - api : linspace args : (Tensor start, Tensor stop, Tensor number, DataType dtype) diff --git a/paddle/phi/api/yaml/legacy_backward.yaml b/paddle/phi/api/yaml/legacy_backward.yaml index 6d5f30e567..937dda3b05 100755 --- a/paddle/phi/api/yaml/legacy_backward.yaml +++ b/paddle/phi/api/yaml/legacy_backward.yaml @@ -1213,8 +1213,8 @@ kernel : func : lerp_grad -- backward_api : linear_interp_v2_grad - forward : linear_interp_v2 (Tensor x, Tensor out_size, Tensor[] size_tensor, Tensor scale_tensor, str data_layout, int out_d, int out_h, int out_w, float[] scale, str interp_method, bool align_corners, int align_mode) -> Tensor(output) +- backward_api : linear_interp_grad + forward : linear_interp (Tensor x, Tensor out_size, Tensor[] size_tensor, Tensor scale_tensor, str data_layout, int out_d, int out_h, int out_w, float[] scale, str interp_method, bool align_corners, int align_mode) -> Tensor(output) args : (Tensor x, Tensor out_size, Tensor[] size_tensor, Tensor scale_tensor, Tensor output_grad, str data_layout, int out_d, int out_h, int out_w, float[] scale, str interp_method, bool align_corners, int align_mode) output : Tensor(x_grad) infer_meta : @@ -1222,7 +1222,7 @@ param: [x] optional: out_size, size_tensor, scale_tensor kernel : - func : linear_interp_v2_grad + func : linear_interp_grad data_type : output_grad - backward_api : log10_grad diff --git a/paddle/phi/core/compat/op_utils.h b/paddle/phi/core/compat/op_utils.h index f4cca91a56..ce5cabea21 100644 --- a/paddle/phi/core/compat/op_utils.h +++ b/paddle/phi/core/compat/op_utils.h @@ -40,37 +40,40 @@ const std::unordered_set standard_kernel_suffixs({ * after 2.0, and can no longer be occupied by the previously abandoned ops. * They are marked here uniformly. */ -const std::unordered_set deprecated_op_names({"diag", - "flatten", - "flatten_grad", - "isinf", - "isnan", - "unsqueeze", - "unsqueeze_grad", - "squeeze", - "squeeze_grad", - "isfinite", - "matmul", - "fill", - "matmul_grad", - "matmul_grad_grad", - "max", - "max_grad", - "min", - "min_grad", - "prod", - "prod_grad", - "any", - "all", - "reshape", - "reshape_grad", - "expand", - "expand_as", - "expand_grad", - "expand_as_grad", - "one_hot", - "top_k", - "top_k_grad"}); +const std::unordered_set deprecated_op_names( + {"diag", + "flatten", + "flatten_grad", + "isinf", + "isnan", + "unsqueeze", + "unsqueeze_grad", + "squeeze", + "squeeze_grad", + "isfinite", + "matmul", + "fill", + "matmul_grad", + "matmul_grad_grad", + "max", + "max_grad", + "min", + "min_grad", + "prod", + "prod_grad", + "any", + "all", + "reshape", + "reshape_grad", + "expand", + "expand_as", + "expand_grad", + "expand_as_grad", + "one_hot", + "top_k", + "top_k_grad", + "linear_interp", + "linear_interp_grad"}); class DefaultKernelSignatureMap { public: diff --git a/paddle/phi/kernels/cpu/interpolate_grad_kernel.cc b/paddle/phi/kernels/cpu/interpolate_grad_kernel.cc index dee6e9149c..e630cf5851 100644 --- a/paddle/phi/kernels/cpu/interpolate_grad_kernel.cc +++ b/paddle/phi/kernels/cpu/interpolate_grad_kernel.cc @@ -1063,7 +1063,7 @@ PD_REGISTER_KERNEL(trilinear_interp_v2_grad, kernel->InputAt(2).SetBackend(phi::Backend::ALL_BACKEND); kernel->InputAt(3).SetBackend(phi::Backend::ALL_BACKEND); } -PD_REGISTER_KERNEL(linear_interp_v2_grad, +PD_REGISTER_KERNEL(linear_interp_grad, CPU, ALL_LAYOUT, phi::LinearInterpGradKernel, diff --git a/paddle/phi/kernels/cpu/interpolate_kernel.cc b/paddle/phi/kernels/cpu/interpolate_kernel.cc index 3649185a0c..21223d55bf 100644 --- a/paddle/phi/kernels/cpu/interpolate_kernel.cc +++ b/paddle/phi/kernels/cpu/interpolate_kernel.cc @@ -1219,7 +1219,7 @@ PD_REGISTER_KERNEL(trilinear_interp_v2, kernel->InputAt(2).SetBackend(phi::Backend::ALL_BACKEND); kernel->InputAt(3).SetBackend(phi::Backend::ALL_BACKEND); } -PD_REGISTER_KERNEL(linear_interp_v2, +PD_REGISTER_KERNEL(linear_interp, CPU, ALL_LAYOUT, phi::LinearInterpKernel, diff --git a/paddle/phi/kernels/gpu/interpolate_grad_kernel.cu b/paddle/phi/kernels/gpu/interpolate_grad_kernel.cu index 047b4ff69a..4da7ef01cd 100644 --- a/paddle/phi/kernels/gpu/interpolate_grad_kernel.cu +++ b/paddle/phi/kernels/gpu/interpolate_grad_kernel.cu @@ -1596,7 +1596,7 @@ PD_REGISTER_KERNEL(trilinear_interp_v2_grad, kernel->InputAt(2).SetBackend(phi::Backend::ALL_BACKEND); kernel->InputAt(3).SetBackend(phi::Backend::ALL_BACKEND); } -PD_REGISTER_KERNEL(linear_interp_v2_grad, +PD_REGISTER_KERNEL(linear_interp_grad, GPU, ALL_LAYOUT, phi::LinearInterpGradKernel, diff --git a/paddle/phi/kernels/gpu/interpolate_kernel.cu b/paddle/phi/kernels/gpu/interpolate_kernel.cu index c05514236e..7b8bc6c954 100644 --- a/paddle/phi/kernels/gpu/interpolate_kernel.cu +++ b/paddle/phi/kernels/gpu/interpolate_kernel.cu @@ -1471,7 +1471,7 @@ PD_REGISTER_KERNEL(trilinear_interp_v2, kernel->InputAt(2).SetBackend(phi::Backend::ALL_BACKEND); kernel->InputAt(3).SetBackend(phi::Backend::ALL_BACKEND); } -PD_REGISTER_KERNEL(linear_interp_v2, +PD_REGISTER_KERNEL(linear_interp, GPU, ALL_LAYOUT, phi::LinearInterpKernel, diff --git a/paddle/phi/ops/compat/interpolate_sig.cc b/paddle/phi/ops/compat/interpolate_sig.cc index 61b0224073..f40532afd8 100644 --- a/paddle/phi/ops/compat/interpolate_sig.cc +++ b/paddle/phi/ops/compat/interpolate_sig.cc @@ -62,7 +62,7 @@ KernelSignature TrilinearInterpOpArgumentMapping( KernelSignature LinearInterpOpArgumentMapping( const ArgumentMappingContext& ctx) { - return KernelSignature("linear_interp_v2", + return KernelSignature("linear_interp", {"X", "OutSize", "SizeTensor", "Scale"}, {"data_layout", "out_d", @@ -136,7 +136,7 @@ KernelSignature TrilinearInterpGradOpArgumentMapping( KernelSignature LinearInterpGradOpArgumentMapping( const ArgumentMappingContext& ctx) { - return KernelSignature("linear_interp_v2_grad", + return KernelSignature("linear_interp_grad", {"X", "OutSize", "SizeTensor", "Scale", "Out@GRAD"}, {"data_layout", "out_d", @@ -166,6 +166,9 @@ KernelSignature BicubicInterpGradOpArgumentMapping( } // namespace phi +PD_REGISTER_BASE_KERNEL_NAME(linear_interp_v2, linear_interp); +PD_REGISTER_BASE_KERNEL_NAME(linear_interp_v2_grad, linear_interp_grad); + PD_REGISTER_ARG_MAPPING_FN(bilinear_interp_v2, phi::BilinearInterpOpArgumentMapping); PD_REGISTER_ARG_MAPPING_FN(nearest_interp_v2, diff --git a/python/paddle/fluid/tests/unittests/test_linear_interp_v2_op.py b/python/paddle/fluid/tests/unittests/test_linear_interp_v2_op.py index 2e3f6a47cb..f69a1b47f1 100755 --- a/python/paddle/fluid/tests/unittests/test_linear_interp_v2_op.py +++ b/python/paddle/fluid/tests/unittests/test_linear_interp_v2_op.py @@ -22,21 +22,21 @@ import paddle.fluid.core as core import paddle.fluid as fluid from paddle.fluid import Program, program_guard from paddle.nn.functional import interpolate -from paddle._C_ops import final_state_linear_interp_v2 - - -def linear_interp_v2_test(x, - OutSize=None, - SizeTensor=None, - Scale=None, - data_layout='NCHW', - out_d=-1, - out_h=-1, - out_w=-1, - scale=0.0, - interp_method='linear', - align_corners=False, - align_mode=1): +from paddle._C_ops import final_state_linear_interp + + +def linear_interp_test(x, + OutSize=None, + SizeTensor=None, + Scale=None, + data_layout='NCHW', + out_d=-1, + out_h=-1, + out_w=-1, + scale=[], + interp_method='linear', + align_corners=False, + align_mode=1): if isinstance(scale, float) or isinstance(scale, int): scale_list = [] for _ in range(len(x.shape) - 2): @@ -45,11 +45,12 @@ def linear_interp_v2_test(x, elif isinstance(scale, list) or isinstance(scale, tuple): scale = list(map(float, scale)) if SizeTensor is not None: - SizeTensor = [SizeTensor] - return final_state_linear_interp_v2(x, OutSize, SizeTensor, Scale, - data_layout, out_d, out_h, out_w, scale, - interp_method, align_corners, - align_mode) + if not isinstance(SizeTensor, list) and not isinstance( + SizeTensor, tuple): + SizeTensor = [SizeTensor] + return final_state_linear_interp(x, OutSize, SizeTensor, Scale, data_layout, + out_d, out_h, out_w, scale, interp_method, + align_corners, align_mode) def linear_interp_np(input, @@ -107,7 +108,7 @@ def linear_interp_np(input, class TestLinearInterpOp(OpTest): def setUp(self): - self.python_api = linear_interp_v2_test + self.python_api = linear_interp_test self.out_size = None self.actual_shape = None self.data_layout = 'NCHW' @@ -219,7 +220,7 @@ class TestLinearInterpOpScale(TestLinearInterpOp): class TestLinearInterpOpSizeTensor(TestLinearInterpOp): def setUp(self): - self.python_api = linear_interp_v2_test + self.python_api = linear_interp_test self.out_size = None self.actual_shape = None self.data_layout = 'NCHW' diff --git a/python/paddle/nn/functional/common.py b/python/paddle/nn/functional/common.py index f9b9c89c2b..fcbe3bff90 100644 --- a/python/paddle/nn/functional/common.py +++ b/python/paddle/nn/functional/common.py @@ -590,22 +590,16 @@ def interpolate(x, attr_list.append(v) dy_attr = tuple(attr_list) - eager_args = [x] - eager_args.append(inputs['OutSize'] if 'OutSize' in inputs else None) - eager_args.append(inputs['SizeTensor'] if 'SizeTensor' in - inputs else None) - eager_args.append(inputs['Scale'] if 'Scale' in inputs else None) - eager_args.extend([ - attrs['data_layout'], attrs['out_d'], attrs['out_h'], attrs['out_w'] - ]) - eager_args.append(attrs['scale'] if 'scale' in attrs else []) - eager_args.extend([ - attrs['interp_method'], attrs['align_corners'], attrs['align_mode'] - ]) - if resample_type == "linear": if in_dygraph_mode(): - out = _C_ops.final_state_linear_interp_v2(*eager_args) + out = _C_ops.final_state_linear_interp( + x, inputs['OutSize'] if 'OutSize' in inputs else None, + inputs['SizeTensor'] if 'SizeTensor' in inputs else None, + inputs['Scale'] if 'Scale' in inputs else None, + attrs['data_layout'], attrs['out_d'], attrs['out_h'], + attrs['out_w'], attrs['scale'] if 'scale' in attrs else [], + attrs['interp_method'], attrs['align_corners'], + attrs['align_mode']) else: out = _C_ops.linear_interp_v2(x, *dy_attr) elif resample_type == "bilinear": -- GitLab