diff --git a/paddle/fluid/operators/index_add_op.cc b/paddle/fluid/operators/index_add_op.cc deleted file mode 100644 index da3b720ae3ebeca858718ae367c1059107a71965..0000000000000000000000000000000000000000 --- a/paddle/fluid/operators/index_add_op.cc +++ /dev/null @@ -1,118 +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 - -#include "paddle/fluid/framework/infershape_utils.h" -#include "paddle/fluid/framework/op_registry.h" -#include "paddle/phi/infermeta/backward.h" -#include "paddle/phi/infermeta/binary.h" - -namespace paddle { -namespace operators { - -class IndexAddOp : public framework::OperatorWithKernel { - public: - using framework::OperatorWithKernel::OperatorWithKernel; - - phi::KernelKey GetExpectedKernelType( - const framework::ExecutionContext& ctx) const override { - return phi::KernelKey(OperatorWithKernel::IndicateVarDataType(ctx, "X"), - ctx.GetPlace()); - } -}; - -class IndexAddOpMaker : public framework::OpProtoAndCheckerMaker { - public: - void Make() override { - AddInput("X", - "(Tensor), " - "the input feature data of IndexAddOp, dtype should be" - "bool, int32, int64, float16, float32, float64."); - AddInput("Index", - "(Tensor), the 1-D tensor containing the indices to index."); - AddInput("AddValue", "(Tensor), the tensor containing values to add."); - AddOutput( - "Out", - "(Tensor)," - " the output of IndexAddOp, whose dtype and shape are the same as X."); - AddAttr("axis", "the dimension in which we index.").SetDefault(0); - AddComment(R"DOC( - IndexAdd operator - Add the elements of the input tensor with value - by selecting the indices in the order given in index. - This operator also supports inplace modification. - )DOC"); - } -}; - -template -class IndexAddGradMaker : public framework::SingleGradOpMaker { - public: - using framework::SingleGradOpMaker::SingleGradOpMaker; - - void Apply(GradOpPtr op) const override { - op->SetType("index_add_grad"); - op->SetInput("Index", this->Input("Index")); - op->SetInput("AddValue", this->Input("AddValue")); - op->SetInput(framework::GradVarName("Out"), this->OutputGrad("Out")); - op->SetAttrMap(this->Attrs()); - op->SetOutput(framework::GradVarName("X"), this->InputGrad("X")); - op->SetOutput(framework::GradVarName("AddValue"), - this->InputGrad("AddValue")); - } -}; - -class IndexAddGradOp : public framework::OperatorWithKernel { - public: - using framework::OperatorWithKernel::OperatorWithKernel; - - protected: - phi::KernelKey GetExpectedKernelType( - const framework::ExecutionContext& ctx) const override { - return phi::KernelKey(OperatorWithKernel::IndicateVarDataType( - ctx, framework::GradVarName("Out")), - ctx.GetPlace()); - } -}; - -DECLARE_INPLACE_OP_INFERER(IndexAddInplaceInferer, {"X", "Out"}); -DECLARE_INPLACE_OP_INFERER(IndexAddGradInplaceInferer, - {framework::GradVarName("Out"), - framework::GradVarName("X")}); - -} // namespace operators -} // namespace paddle - -namespace ops = paddle::operators; -DECLARE_INFER_SHAPE_FUNCTOR(index_add, - IndexAddInferShapeFunctor, - PD_INFER_META(phi::IndexAddInferMeta)); - -REGISTER_OPERATOR(index_add, - ops::IndexAddOp, - ops::IndexAddOpMaker, - ops::IndexAddGradMaker, - ops::IndexAddGradMaker, - ops::IndexAddInplaceInferer, - IndexAddInferShapeFunctor); - -DECLARE_INFER_SHAPE_FUNCTOR(index_add_grad, - IndexAddGradInferShapeFunctor, - PD_INFER_META(phi::IndexAddGradInferMeta)); - -REGISTER_OPERATOR(index_add_grad, - ops::IndexAddGradOp, - ops::IndexAddGradInplaceInferer, - IndexAddGradInferShapeFunctor); diff --git a/paddle/phi/api/yaml/backward.yaml b/paddle/phi/api/yaml/backward.yaml index d164484d0026e4cf52700d6a766c8a63da3b03c4..6891cef3ffe707c687c8e9dd206094db30f18d95 100644 --- a/paddle/phi/api/yaml/backward.yaml +++ b/paddle/phi/api/yaml/backward.yaml @@ -689,6 +689,17 @@ func : imag_grad data_type : complex(out_grad) +- backward_op : index_add_grad + forward : index_add(Tensor x, Tensor index, Tensor add_value, int axis=0) -> Tensor(out) + args : (Tensor index, Tensor add_value, Tensor out_grad, int axis) + output : Tensor(x_grad), Tensor(add_value_grad) + infer_meta : + func : IndexAddGradInferMeta + kernel : + func : index_add_grad + data_type : out_grad + inplace : (out_grad -> x_grad) + - backward_op : index_sample_grad forward : index_sample (Tensor x, Tensor index) -> Tensor(out) args : (Tensor x, Tensor index, Tensor out_grad) diff --git a/paddle/phi/api/yaml/legacy_backward.yaml b/paddle/phi/api/yaml/legacy_backward.yaml index 8e467746c8214698c380c8b4b2504d99b1c0c47d..607ee5da9ae7e2e714666e20cd613df8c3e1c886 100755 --- a/paddle/phi/api/yaml/legacy_backward.yaml +++ b/paddle/phi/api/yaml/legacy_backward.yaml @@ -574,17 +574,6 @@ kernel : func : huber_loss_grad -- backward_op : index_add_grad - forward : index_add(Tensor x, Tensor index, Tensor add_value, int axis) -> Tensor(out) - args : (Tensor index, Tensor add_value, Tensor out_grad, int axis) - output : Tensor(x_grad), Tensor(add_value_grad) - infer_meta : - func : IndexAddGradInferMeta - kernel : - func : index_add_grad - data_type : out_grad - inplace : (out_grad -> x_grad) - - backward_op : instance_norm_double_grad forward : instance_norm_grad(Tensor x, Tensor fwd_scale, Tensor saved_mean, Tensor saved_variance, Tensor grad_y, float epsilon) -> Tensor(grad_x), Tensor(grad_scale), Tensor(grad_bias) args : (Tensor x, Tensor fwd_scale, Tensor saved_mean, Tensor saved_variance, Tensor grad_y, Tensor grad_x_grad, Tensor grad_scale_grad, Tensor grad_bias_grad, float epsilon) diff --git a/paddle/phi/api/yaml/legacy_ops.yaml b/paddle/phi/api/yaml/legacy_ops.yaml index 5c99d79961f64bc67c62232981daf064e88b7c8b..9f30d076a5eb6d972c336e6c2aa42d11184ae203 100755 --- a/paddle/phi/api/yaml/legacy_ops.yaml +++ b/paddle/phi/api/yaml/legacy_ops.yaml @@ -831,17 +831,6 @@ func : increment inplace : (x -> out) -- op : index_add - args : (Tensor x, Tensor index, Tensor add_value, int axis) - output : Tensor(out) - infer_meta : - func : IndexAddInferMeta - kernel : - func : index_add - data_type : x - inplace : (x -> out) - backward : index_add_grad - - op : instance_norm args : (Tensor x, Tensor scale, Tensor bias, float epsilon) output : Tensor(y), Tensor(saved_mean), Tensor(saved_variance) diff --git a/paddle/phi/api/yaml/op_compat.yaml b/paddle/phi/api/yaml/op_compat.yaml index 5f3d4ba7bf837260f3a7004e5409135118189a7f..f6656f39e862b96d18ae47e200d25b9c495c1cda 100644 --- a/paddle/phi/api/yaml/op_compat.yaml +++ b/paddle/phi/api/yaml/op_compat.yaml @@ -882,6 +882,12 @@ outputs : out : Out +- op : index_add + inputs : + {x : X, index : Index, add_value : AddValue} + outputs : + out : Out + - op : index_sample inputs : {x : X, index : Index} diff --git a/paddle/phi/api/yaml/ops.yaml b/paddle/phi/api/yaml/ops.yaml index 24887ee6512ca0482c077b2979cbe22c8b7d02ea..b20c9e6769d4dcf891567fd571120adf4123de30 100644 --- a/paddle/phi/api/yaml/ops.yaml +++ b/paddle/phi/api/yaml/ops.yaml @@ -710,6 +710,17 @@ func : imag backward : imag_grad +- op : index_add + args : (Tensor x, Tensor index, Tensor add_value, int axis = 0) + output : Tensor(out) + infer_meta : + func : IndexAddInferMeta + kernel : + func : index_add + data_type : x + inplace : (x -> out) + backward : index_add_grad + - op : index_sample args : (Tensor x, Tensor index) output : Tensor diff --git a/paddle/phi/ops/compat/index_add_sig.cc b/paddle/phi/ops/compat/index_add_sig.cc deleted file mode 100644 index 39b231406fa66793289bbe291d019fdd21184bc3..0000000000000000000000000000000000000000 --- a/paddle/phi/ops/compat/index_add_sig.cc +++ /dev/null @@ -1,35 +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 IndexAddOpArgumentMapping(const ArgumentMappingContext& ctx) { - return KernelSignature( - "index_add", {"X", "Index", "AddValue"}, {"axis"}, {"Out"}); -} - -KernelSignature IndexAddGradOpArgumentMapping( - const ArgumentMappingContext& ctx) { - return KernelSignature("index_add_grad", - {"Index", "AddValue", "Out@GRAD"}, - {"axis"}, - {"X@GRAD", "AddValue@GRAD"}); -} - -} // namespace phi - -PD_REGISTER_ARG_MAPPING_FN(index_add, phi::IndexAddOpArgumentMapping); -PD_REGISTER_ARG_MAPPING_FN(index_add_grad, phi::IndexAddGradOpArgumentMapping);