diff --git a/paddle/phi/infermeta/unary.cc b/paddle/phi/infermeta/unary.cc index 6c2956417a3a363b508b66356f5ab90a956c9c0d..c88c2d6f60f100069ea2f7143b81253b401c7b58 100644 --- a/paddle/phi/infermeta/unary.cc +++ b/paddle/phi/infermeta/unary.cc @@ -2163,8 +2163,8 @@ void SplitInferMeta(const MetaTensor& x, void SqueezeInferMeta(const MetaTensor& x, const std::vector& axes, - MetaTensor* xshape, - MetaTensor* out) { + MetaTensor* out, + MetaTensor* xshape) { const auto& x_dims = x.dims(); // Check input tensor dims (<6) Eigen limit. PADDLE_ENFORCE_LE(x_dims.size(), @@ -2964,8 +2964,8 @@ void UniqueRawInferMeta(const MetaTensor& x, void UnsqueezeInferMeta(const MetaTensor& x, const IntArray& axes, - MetaTensor* xshape, MetaTensor* out, + MetaTensor* xshape, MetaConfig config) { const auto& x_dims = x.dims(); // Validity Check: input tensor dims (<6). diff --git a/paddle/phi/infermeta/unary.h b/paddle/phi/infermeta/unary.h index 559857bd6ce9bd94c6d94e0631f2cd326edd710e..58b256dc66ee2aa764d17c3e23d9babfd54b5a30 100644 --- a/paddle/phi/infermeta/unary.h +++ b/paddle/phi/infermeta/unary.h @@ -306,8 +306,8 @@ void SplitInferMeta(const MetaTensor& x_meta, void SqueezeInferMeta(const MetaTensor& x, const std::vector& axes, - MetaTensor* xshape, - MetaTensor* out); + MetaTensor* out, + MetaTensor* xshape); void StridedSliceRawInferMeta(const MetaTensor& x, const std::vector& axes, @@ -425,8 +425,8 @@ void UniqueRawInferMeta(const MetaTensor& x, void UnsqueezeInferMeta(const MetaTensor& x, const IntArray& axes, - MetaTensor* xshape, MetaTensor* out, + MetaTensor* xshape, MetaConfig config = MetaConfig()); void UnStackInferMeta(const MetaTensor& x, diff --git a/paddle/phi/kernels/impl/squeeze_kernel_impl.h b/paddle/phi/kernels/impl/squeeze_kernel_impl.h index d2b40824a91c99ac4f69b689b2219822e21c6aea..bb1627d40925fcb229d3cb0ba1f54eb1b7d10010 100644 --- a/paddle/phi/kernels/impl/squeeze_kernel_impl.h +++ b/paddle/phi/kernels/impl/squeeze_kernel_impl.h @@ -22,8 +22,8 @@ template void SqueezeKernel(const Context& dev_ctx, const DenseTensor& x, const std::vector& axes, - DenseTensor* xshape, - DenseTensor* out) { + DenseTensor* out, + DenseTensor* xshape) { auto x_dims = x.dims(); auto out_dims = funcs::GetOutputSqueezeShape(axes, x_dims, true); diff --git a/paddle/phi/kernels/impl/unsqueeze_kernel_impl.h b/paddle/phi/kernels/impl/unsqueeze_kernel_impl.h index 58efff16a5a5ac44e5ab6b91909d385b03795c8e..02110d631fb4def572d8c49c662d4df77d9c233f 100644 --- a/paddle/phi/kernels/impl/unsqueeze_kernel_impl.h +++ b/paddle/phi/kernels/impl/unsqueeze_kernel_impl.h @@ -22,8 +22,8 @@ template void UnsqueezeKernel(const Context& dev_ctx, const DenseTensor& x, const IntArray& axes, - DenseTensor* xshape, - DenseTensor* out) { + DenseTensor* out, + DenseTensor* xshape) { auto x_dims = x.dims(); auto out_dims = out->dims(); if (axes.FromTensor()) { diff --git a/paddle/phi/kernels/squeeze_kernel.h b/paddle/phi/kernels/squeeze_kernel.h index 22254eacfcefcd3a3dd33870c4d068c1114335b7..bd8f508cbb1db8ffdc138187270065895fc8834d 100644 --- a/paddle/phi/kernels/squeeze_kernel.h +++ b/paddle/phi/kernels/squeeze_kernel.h @@ -23,6 +23,6 @@ template void SqueezeKernel(const Context& dev_ctx, const DenseTensor& x, const std::vector& axes, - DenseTensor* xshape, - DenseTensor* out); + DenseTensor* out, + DenseTensor* xshape); } // namespace phi diff --git a/paddle/phi/kernels/unsqueeze_kernel.h b/paddle/phi/kernels/unsqueeze_kernel.h index d18bde1c2efab996ae40df0282bf9866281ab98b..4622a9b0a859c913ee8c8899d1d12a0a7f988f73 100644 --- a/paddle/phi/kernels/unsqueeze_kernel.h +++ b/paddle/phi/kernels/unsqueeze_kernel.h @@ -24,6 +24,6 @@ template void UnsqueezeKernel(const Context& dev_ctx, const DenseTensor& x, const IntArray& axes, - DenseTensor* xshape, - DenseTensor* out); + DenseTensor* out, + DenseTensor* xshape); } // namespace phi diff --git a/paddle/phi/ops/compat/squeeze_sig.cc b/paddle/phi/ops/compat/squeeze_sig.cc index c65d77df9808e1b85ef15d890c75757a2177c2f4..cd6d5fc7253dfa855b4abea094e992e19ec7d9bf 100644 --- a/paddle/phi/ops/compat/squeeze_sig.cc +++ b/paddle/phi/ops/compat/squeeze_sig.cc @@ -18,7 +18,7 @@ namespace phi { KernelSignature SqueezeOpArgumentMapping(const ArgumentMappingContext& ctx) { - return KernelSignature("squeeze", {"X"}, {"axes"}, {"XShape", "Out"}); + return KernelSignature("squeeze", {"X"}, {"axes"}, {"Out", "XShape"}); } KernelSignature SqueezeGradOpArgumentMapping( diff --git a/paddle/phi/ops/compat/unsqueeze_sig.cc b/paddle/phi/ops/compat/unsqueeze_sig.cc index c802c2684b282f972cb27aaa577b7b9e0b79ddaf..aee83933e5b970c07e09aff6b8816d0b9fe86a31 100644 --- a/paddle/phi/ops/compat/unsqueeze_sig.cc +++ b/paddle/phi/ops/compat/unsqueeze_sig.cc @@ -21,14 +21,14 @@ KernelSignature UnsqueezeOpArgumentMapping(const ArgumentMappingContext& ctx) { if (ctx.InputSize("AxesTensorList") > 0) { VLOG(2) << "unsqueeze2 in AxesTensorList"; return KernelSignature( - "unsqueeze", {"X"}, {"AxesTensorList"}, {"XShape", "Out"}); + "unsqueeze", {"X"}, {"AxesTensorList"}, {"Out", "XShape"}); } else if (ctx.InputSize("AxesTensor") > 0) { VLOG(2) << "unsqueeze2 in AxesTensor"; return KernelSignature( - "unsqueeze", {"X"}, {"AxesTensor"}, {"XShape", "Out"}); + "unsqueeze", {"X"}, {"AxesTensor"}, {"Out", "XShape"}); } else { VLOG(2) << "unsqueeze2 in axes"; - return KernelSignature("unsqueeze", {"X"}, {"axes"}, {"XShape", "Out"}); + return KernelSignature("unsqueeze", {"X"}, {"axes"}, {"Out", "XShape"}); } } diff --git a/python/paddle/fluid/layers/nn.py b/python/paddle/fluid/layers/nn.py index 8be719758ef981c946f7251b89705aa3aa12422a..799d93918f2efd6b67da1d34c8a94bb39697dcf5 100755 --- a/python/paddle/fluid/layers/nn.py +++ b/python/paddle/fluid/layers/nn.py @@ -6533,7 +6533,7 @@ def squeeze(input, axes, name=None): """ if in_dygraph_mode(): - return _C_ops.final_state_squeeze(input, axes)[1] + return _C_ops.final_state_squeeze(input, axes) if _in_legacy_dygraph(): out, _ = _C_ops.squeeze2(input, 'axes', axes) return out @@ -6598,7 +6598,7 @@ def unsqueeze(input, axes, name=None): if _in_legacy_dygraph(): out, _ = _C_ops.unsqueeze2(input, 'axes', axes) return out - return _C_ops.final_state_unsqueeze(input, axes)[1] + return _C_ops.final_state_unsqueeze(input, axes) check_type(axes, 'axis/axes', (int, list, tuple, Variable), 'unsqueeze') check_variable_and_dtype(input, 'input', [ diff --git a/python/paddle/tensor/manipulation.py b/python/paddle/tensor/manipulation.py index 22e3b7cd29e0ec7c505806f5a41db8788fd9e569..9a4025a768e9e204ee4f642870031388622eb096 100755 --- a/python/paddle/tensor/manipulation.py +++ b/python/paddle/tensor/manipulation.py @@ -1427,8 +1427,7 @@ def flatten(x, start_axis=0, stop_axis=-1, name=None): raise ValueError("The stop_axis should be larger than stat_axis") if in_dygraph_mode(): - dy_out, _ = _C_ops.final_state_flatten(x, start_axis, stop_axis) - return dy_out + return _C_ops.final_state_flatten(x, start_axis, stop_axis) if _in_legacy_dygraph(): dy_out, _ = _C_ops.flatten_contiguous_range(x, 'start_axis', start_axis, @@ -1936,7 +1935,7 @@ def squeeze(x, axis=None, name=None): input = x axes = axis if in_dygraph_mode(): - return _C_ops.final_state_squeeze(input, axes)[1] + return _C_ops.final_state_squeeze(input, axes) if _in_legacy_dygraph(): out, _ = _C_ops.squeeze2(input, 'axes', axes) return out @@ -2271,7 +2270,7 @@ def unsqueeze(x, axis, name=None): if _in_legacy_dygraph(): out, _ = _C_ops.unsqueeze2(input, 'axes', axes) return out - return _C_ops.final_state_unsqueeze(input, axes)[1] + return _C_ops.final_state_unsqueeze(input, axes) check_type(axes, 'axis/axes', (int, list, tuple, Variable), 'unsqueeze') check_variable_and_dtype(input, 'input', [ diff --git a/python/paddle/utils/code_gen/api.yaml b/python/paddle/utils/code_gen/api.yaml index 5f533d241f1f328ab4992b82f7c6a47367f88986..b34acb9605272363a62ce91700027a6164d623fc 100644 --- a/python/paddle/utils/code_gen/api.yaml +++ b/python/paddle/utils/code_gen/api.yaml @@ -714,7 +714,7 @@ backend : x inplace : (x -> out) view : (x -> out) - # intermediate : xshape + intermediate : xshape backward : flatten_grad # flip @@ -1984,12 +1984,13 @@ - api : squeeze args : (Tensor x, int[] axes) - output : Tensor(xshape), Tensor(out) + output : Tensor(out), Tensor(xshape) infer_meta : func : SqueezeInferMeta kernel : func : squeeze view: (x -> out) + intermediate : xshape backward : squeeze_grad - api : stack @@ -2213,12 +2214,13 @@ - api : unsqueeze args : (Tensor x, IntArray axis) - output : Tensor(xshape), Tensor(out) + output : Tensor(out), Tensor(xshape) infer_meta : func : UnsqueezeInferMeta kernel : func : unsqueeze view: (x -> out) + intermediate : xshape backward : unsqueeze_grad # viterbi_decode diff --git a/python/paddle/utils/code_gen/backward.yaml b/python/paddle/utils/code_gen/backward.yaml index 1d27473d5c25c40aa87a211b593f45cb6ca839a3..3a5552dd89d77f25471b84f16b7d0bc15e75bba2 100644 --- a/python/paddle/utils/code_gen/backward.yaml +++ b/python/paddle/utils/code_gen/backward.yaml @@ -1750,7 +1750,7 @@ func : square_grad - backward_api : squeeze_grad - forward : squeeze(Tensor x, int[] axes) -> Tensor(xshape), Tensor(out) + forward : squeeze(Tensor x, int[] axes) -> Tensor(out), Tensor(xshape) args : (Tensor xshape, Tensor out_grad, int[] axes) output : Tensor(x_grad) infer_meta : @@ -2021,7 +2021,7 @@ no_need_buffer : x - backward_api : unsqueeze_grad - forward : unsqueeze(Tensor x, IntArray axes) -> Tensor(xshape), Tensor(out) + forward : unsqueeze(Tensor x, IntArray axes) -> Tensor(out), Tensor(xshape) args : (Tensor xshape, Tensor out_grad) output : Tensor(x_grad) infer_meta :