From 384062fab81caaf6416445ca9b360cf8f29877c9 Mon Sep 17 00:00:00 2001 From: zyfncg Date: Wed, 18 May 2022 10:45:08 +0800 Subject: [PATCH] Add intermediate config for some api in yaml (#42824) * add intermediate for some api * fix bug * fix fluid.layer --- paddle/phi/infermeta/unary.cc | 6 +++--- paddle/phi/infermeta/unary.h | 6 +++--- paddle/phi/kernels/impl/squeeze_kernel_impl.h | 4 ++-- paddle/phi/kernels/impl/unsqueeze_kernel_impl.h | 4 ++-- paddle/phi/kernels/squeeze_kernel.h | 4 ++-- paddle/phi/kernels/unsqueeze_kernel.h | 4 ++-- paddle/phi/ops/compat/squeeze_sig.cc | 2 +- paddle/phi/ops/compat/unsqueeze_sig.cc | 6 +++--- python/paddle/fluid/layers/nn.py | 4 ++-- python/paddle/tensor/manipulation.py | 7 +++---- python/paddle/utils/code_gen/api.yaml | 8 +++++--- python/paddle/utils/code_gen/backward.yaml | 4 ++-- 12 files changed, 30 insertions(+), 29 deletions(-) diff --git a/paddle/phi/infermeta/unary.cc b/paddle/phi/infermeta/unary.cc index 6c2956417a3..c88c2d6f60f 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 559857bd6ce..58b256dc66e 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 d2b40824a91..bb1627d4092 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 58efff16a5a..02110d631fb 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 22254eacfce..bd8f508cbb1 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 d18bde1c2ef..4622a9b0a85 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 c65d77df980..cd6d5fc7253 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 c802c2684b2..aee83933e5b 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 8be719758ef..799d93918f2 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 22e3b7cd29e..9a4025a768e 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 5f533d241f1..b34acb96052 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 1d27473d5c2..3a5552dd89d 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 : -- GitLab