diff --git a/paddle/phi/api/yaml/legacy_api.yaml b/paddle/phi/api/yaml/legacy_api.yaml index d06d87ecf8f959499203e28ada3399bf85f3af02..b50b3096895aa23224c94bf38f11daaabf817531 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 6d5f30e567093cae6b094a73d6b419e897c3195b..937dda3b0517edc78fa971cacb73bfdcf298d6ea 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 f4cca91a562da09aef92e65c45b500db07ea7468..ce5cabea21c485ea096f6356103cb916798b69b6 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 dee6e9149ca2d4a894c448ff8fe76a38af648efe..e630cf5851695e1a477ea738db577a4b785d9333 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 3649185a0c7ee18dd302c0b6638dd3eb752fadd8..21223d55bfafea19e210cdd122920fa6fc1a119f 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 047b4ff69a784011f0cc7a87edd0a1bb2ea15d8f..4da7ef01cd390518c5d29e6486215cfccb15ef72 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 c05514236e091617c0a5f2d01c34be15621d6885..7b8bc6c95422da11a1fc2bd9e7b769d61b4d7149 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 61b022407306076c0852322b9a38ebdf7e14f75f..f40532afd8021b1f5c3d93e2dd798743f00ca49e 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 2e3f6a47cba9468ce25617793e10a8f63e0d9f70..f69a1b47f11300923c02b186b231c28dd4f519c7 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 f9b9c89c2b0b88b0483cff32030e128ccc4e0f78..fcbe3bff905f740757611fd68c9ca2464315dde7 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":