未验证 提交 76e0926c 编写于 作者: C Charles-hit 提交者: GitHub

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
上级 a46d7fe6
// 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 <typename T>
class ErfinvGradMaker : public framework::SingleGradOpMaker<T> {
public:
using framework::SingleGradOpMaker<T>::SingleGradOpMaker;
void Apply(GradOpPtr<T> 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::framework::OpDesc>,
paddle::operators::ErfinvGradMaker<paddle::imperative::OpBase>,
paddle::operators::ErfinvInplaceInferer,
ErfinvInferShapeFunctor);
REGISTER_OPERATOR(erfinv_grad, paddle::operators::ErfinvGradOp);
......@@ -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
......
......@@ -86,6 +86,12 @@
outputs :
out : Out
- api : erfinv
inputs :
x : X
outputs :
out : Out
- api : lgamma
inputs :
x : X
......
......@@ -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)
......
......@@ -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
......
......@@ -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):
......
......@@ -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)
......
......@@ -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)
......
// 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);
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册