From 76e0926ca601317d468b7519e443b84cdd87a4a2 Mon Sep 17 00:00:00 2001 From: Charles-hit <56987902+Charles-hit@users.noreply.github.com> Date: Tue, 9 Aug 2022 15:03:43 +0800 Subject: [PATCH] move api(erfinv) from legacy_api.yaml to api.yaml (#44987) * move api(erfinv) from legacy_api.yaml to api.yaml * change inplace_map key --- paddle/fluid/operators/erfinv_op.cc | 89 -------------------- paddle/phi/api/yaml/api.yaml | 10 +++ paddle/phi/api/yaml/api_compat.yaml | 6 ++ paddle/phi/api/yaml/backward.yaml | 10 +++ paddle/phi/api/yaml/generator/generate_op.py | 1 + paddle/phi/api/yaml/generator/tests.py | 2 +- paddle/phi/api/yaml/legacy_api.yaml | 10 --- paddle/phi/api/yaml/legacy_backward.yaml | 10 --- paddle/phi/ops/compat/erfinv_sig.cc | 25 ------ 9 files changed, 28 insertions(+), 135 deletions(-) delete mode 100644 paddle/fluid/operators/erfinv_op.cc delete mode 100644 paddle/phi/ops/compat/erfinv_sig.cc diff --git a/paddle/fluid/operators/erfinv_op.cc b/paddle/fluid/operators/erfinv_op.cc deleted file mode 100644 index 1e615aa7be7..00000000000 --- a/paddle/fluid/operators/erfinv_op.cc +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright (c) 2021 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. - -#include "paddle/fluid/framework/infershape_utils.h" -#include "paddle/fluid/framework/op_registry.h" -#include "paddle/phi/core/infermeta_utils.h" -#include "paddle/phi/infermeta/unary.h" - -namespace paddle { -namespace operators { - -class ErfinvOp : public framework::OperatorWithKernel { - public: - using framework::OperatorWithKernel::OperatorWithKernel; -}; - -class ErfinvOpMaker : public framework::OpProtoAndCheckerMaker { - public: - void Make() override { - AddInput("X", "(Tensor), The input tensor of erfinv op."); - AddOutput("Out", "(Tensor), The output tensor of erfinv op."); - AddComment(R"DOC( -Erfinv Operator. - -This operator is used to compute inverse error function of input $X$. - -The equation is: - -$$erfinv(x) = {ndtri({x \over 2} + 0.5)} \over {\sqrt{2}}$$ - -The input `X` can carry the LoD (Level of Details) information, -or not. And the output shares the LoD information with input `X`. -)DOC"); - } -}; - -class ErfinvGradOp : public framework::OperatorWithKernel { - public: - using framework::OperatorWithKernel::OperatorWithKernel; - - void InferShape(framework::InferShapeContext* ctx) const override { - ctx->SetOutputDim(framework::GradVarName("X"), ctx->GetInputDim("Out")); - } -}; - -template -class ErfinvGradMaker : public framework::SingleGradOpMaker { - public: - using framework::SingleGradOpMaker::SingleGradOpMaker; - - void Apply(GradOpPtr op) const override { - op->SetType("erfinv_grad"); - op->SetInput("Out", this->Output("Out")); - op->SetInput(framework::GradVarName("Out"), this->OutputGrad("Out")); - op->SetOutput(framework::GradVarName("X"), this->InputGrad("X")); - op->SetAttrMap(this->Attrs()); - } -}; - -DECLARE_INPLACE_OP_INFERER(ErfinvInplaceInferer, {"X", "Out"}); - -} // namespace operators -} // namespace paddle - -DECLARE_INFER_SHAPE_FUNCTOR(erfinv, - ErfinvInferShapeFunctor, - PD_INFER_META(phi::UnchangedInferMeta)); - -REGISTER_OPERATOR( - erfinv, - paddle::operators::ErfinvOp, - paddle::operators::ErfinvOpMaker, - paddle::operators::ErfinvGradMaker, - paddle::operators::ErfinvGradMaker, - paddle::operators::ErfinvInplaceInferer, - ErfinvInferShapeFunctor); - -REGISTER_OPERATOR(erfinv_grad, paddle::operators::ErfinvGradOp); diff --git a/paddle/phi/api/yaml/api.yaml b/paddle/phi/api/yaml/api.yaml index 1674ecd2c6d..12ea231a939 100644 --- a/paddle/phi/api/yaml/api.yaml +++ b/paddle/phi/api/yaml/api.yaml @@ -98,6 +98,16 @@ func : erf backward : erf_grad +- api : erfinv + args : (Tensor x) + output : Tensor(out) + infer_meta : + func : UnchangedInferMeta + kernel : + func : erfinv + inplace : (x -> out) + backward : erfinv_grad + - api : fft_c2c args : (Tensor x, int64_t[] axes, str normalization, bool forward) output : Tensor diff --git a/paddle/phi/api/yaml/api_compat.yaml b/paddle/phi/api/yaml/api_compat.yaml index afa55479b35..9ac1e8bd719 100644 --- a/paddle/phi/api/yaml/api_compat.yaml +++ b/paddle/phi/api/yaml/api_compat.yaml @@ -86,6 +86,12 @@ outputs : out : Out +- api : erfinv + inputs : + x : X + outputs : + out : Out + - api : lgamma inputs : x : X diff --git a/paddle/phi/api/yaml/backward.yaml b/paddle/phi/api/yaml/backward.yaml index 30c2c9f9e12..1b1c0be7aa9 100644 --- a/paddle/phi/api/yaml/backward.yaml +++ b/paddle/phi/api/yaml/backward.yaml @@ -105,6 +105,16 @@ func : erf_grad data_type : out_grad +- backward_api : erfinv_grad + forward : erfinv (Tensor x) -> Tensor(out) + args : (Tensor out, Tensor out_grad) + output : Tensor(x_grad) + infer_meta : + func : UnchangedInferMeta + param : [out] + kernel : + func : erfinv_grad + - backward_api : fft_c2c_grad forward: fft_c2c(Tensor x, int64_t[] axes, str normalization, bool forward) -> Tensor(out) args : (Tensor out_grad, int64_t[] axes, str normalization, bool forward) diff --git a/paddle/phi/api/yaml/generator/generate_op.py b/paddle/phi/api/yaml/generator/generate_op.py index bc8b80efb51..ac43db18e57 100644 --- a/paddle/phi/api/yaml/generator/generate_op.py +++ b/paddle/phi/api/yaml/generator/generate_op.py @@ -111,6 +111,7 @@ def replace_compat_name(api_op_map, forward_api_dict, backward_api_dict): key = args_map[key] if val in args_map: val = args_map[val] + key, val = val, key inplace_map[key] = val forward_api_item['inplace'] = inplace_map diff --git a/paddle/phi/api/yaml/generator/tests.py b/paddle/phi/api/yaml/generator/tests.py index d322fe1885b..c96e6ba6ef4 100644 --- a/paddle/phi/api/yaml/generator/tests.py +++ b/paddle/phi/api/yaml/generator/tests.py @@ -50,7 +50,7 @@ def supports_selected_rows_kernel(api): def supports_inplace(api): - return "inplace_map" in api + return api['inplace'] is not None def supports_no_need_buffer(api): diff --git a/paddle/phi/api/yaml/legacy_api.yaml b/paddle/phi/api/yaml/legacy_api.yaml index 5fd0e570c22..6fefa0affdf 100755 --- a/paddle/phi/api/yaml/legacy_api.yaml +++ b/paddle/phi/api/yaml/legacy_api.yaml @@ -790,16 +790,6 @@ kernel : func : equal_all -- api : erfinv - args : (Tensor x) - output : Tensor(out) - infer_meta : - func : UnchangedInferMeta - kernel : - func : erfinv - inplace : (x -> out) - backward : erfinv_grad - # exp - api : exp args : (Tensor x) diff --git a/paddle/phi/api/yaml/legacy_backward.yaml b/paddle/phi/api/yaml/legacy_backward.yaml index ea067ef389a..20b05d4cfc6 100755 --- a/paddle/phi/api/yaml/legacy_backward.yaml +++ b/paddle/phi/api/yaml/legacy_backward.yaml @@ -740,16 +740,6 @@ output : Tensor(weight_grad) invoke : embedding_grad_impl(x, weight, out_grad, padding_idx, sparse, weight_grad) -- backward_api : erfinv_grad - forward : erfinv (Tensor x) -> Tensor(out) - args : (Tensor out, Tensor out_grad) - output : Tensor(x_grad) - infer_meta : - func : UnchangedInferMeta - param : [out] - kernel : - func : erfinv_grad - - backward_api : exp_grad forward : exp (Tensor x) -> Tensor(out) args : (Tensor out, Tensor out_grad) diff --git a/paddle/phi/ops/compat/erfinv_sig.cc b/paddle/phi/ops/compat/erfinv_sig.cc deleted file mode 100644 index 37d30aaaeb6..00000000000 --- a/paddle/phi/ops/compat/erfinv_sig.cc +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) 2022 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. - -#include "paddle/phi/core/compat/op_utils.h" - -namespace phi { - -KernelSignature ErfinvGradOpArgumentMapping(const ArgumentMappingContext& ctx) { - return KernelSignature("erfinv_grad", {"Out", "Out@GRAD"}, {}, {"X@GRAD"}); -} - -} // namespace phi - -PD_REGISTER_ARG_MAPPING_FN(erfinv_grad, phi::ErfinvGradOpArgumentMapping); -- GitLab