diff --git a/paddle/fluid/operators/cumprod_op.cc b/paddle/fluid/operators/cumprod_op.cc deleted file mode 100644 index 52e112d39ed245b7e904ccc419c9275ccd076fdb..0000000000000000000000000000000000000000 --- a/paddle/fluid/operators/cumprod_op.cc +++ /dev/null @@ -1,94 +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/fluid/framework/operator.h" -#include "paddle/phi/infermeta/unary.h" - -namespace paddle { -namespace operators { - -class CumprodOp : public framework::OperatorWithKernel { - public: - using framework::OperatorWithKernel::OperatorWithKernel; -}; - -class CumprodOpMaker : public framework::OpProtoAndCheckerMaker { - public: - void Make() override { - AddInput("X", "(Tensor), The input tensor of cumprod op."); - AddOutput("Out", "(Tensor), The output tensor of cumprod op."); - AddAttr( - "dim", - "(int), The dim along which the input tensors will be cumproded"); - AddComment( - R"DOC(Cumprod operator. Return the cumprod results of the input elements along the dim. - For example, if input X is a tensor with rank 1 and N elements, the output will also be a tensor - with rank 1 and N elements, and elements y[i] = x[0] * x[1] * x[2] *...* x[i] (0<=i -class CumprodGradOpMaker : public framework::SingleGradOpMaker { - public: - using framework::SingleGradOpMaker::SingleGradOpMaker; - - protected: - void Apply(GradOpPtr grad_op) const override { - grad_op->SetType("cumprod_grad"); - grad_op->SetInput("X", this->Input("X")); - grad_op->SetInput("Out", this->Output("Out")); - grad_op->SetInput(framework::GradVarName("Out"), this->OutputGrad("Out")); - grad_op->SetOutput(framework::GradVarName("X"), this->InputGrad("X")); - grad_op->SetAttrMap(this->Attrs()); - } -}; - -class CumprodGradOp : public framework::OperatorWithKernel { - public: - using framework::OperatorWithKernel::OperatorWithKernel; - - void InferShape(framework::InferShapeContext *ctx) const override { - OP_INOUT_CHECK(ctx->HasInput("X"), "Input", "X", "CumprodGrad"); - OP_INOUT_CHECK(ctx->HasInput("Out"), "Input", "Out", "CumprodGrad"); - OP_INOUT_CHECK(ctx->HasInput(framework::GradVarName("Out")), - "Input", - "framework::GradVarName(\"Out\")", - "CumprodGrad"); - OP_INOUT_CHECK(ctx->HasOutput(framework::GradVarName("X")), - "Output", - "framework::GradVarName(\"X\")", - "CumprodGrad"); - ctx->ShareDim(framework::GradVarName("Out"), framework::GradVarName("X")); - ctx->ShareLoD(framework::GradVarName("Out"), framework::GradVarName("X")); - } -}; - -} // namespace operators -} // namespace paddle - -namespace ops = paddle::operators; -DECLARE_INFER_SHAPE_FUNCTOR(cumprod, - CumprodInferShapeFunctor, - PD_INFER_META(phi::UnchangedInferMetaCheckAxis)); - -REGISTER_OPERATOR(cumprod, - ops::CumprodOp, - ops::CumprodOpMaker, - ops::CumprodGradOpMaker, - ops::CumprodGradOpMaker, - CumprodInferShapeFunctor); - -REGISTER_OPERATOR(cumprod_grad, ops::CumprodGradOp); diff --git a/paddle/phi/api/yaml/backward.yaml b/paddle/phi/api/yaml/backward.yaml index 89cd2e1b0a0c8a956b207a7f67c3044616891255..e20143d96287ac3607259593cb5947d3b8488737 100644 --- a/paddle/phi/api/yaml/backward.yaml +++ b/paddle/phi/api/yaml/backward.yaml @@ -337,6 +337,16 @@ func : cross_grad data_type : out_grad +- backward_op : cumprod_grad + forward : cumprod (Tensor x, int dim) -> Tensor(out) + args : (Tensor x, Tensor out, Tensor out_grad, int dim) + output : Tensor(x_grad) + infer_meta : + func : UnchangedInferMeta + param: [x] + kernel : + func : cumprod_grad + - backward_op : det_grad forward : det (Tensor x) -> Tensor(out) args : (Tensor x, Tensor out, Tensor out_grad) diff --git a/paddle/phi/api/yaml/legacy_backward.yaml b/paddle/phi/api/yaml/legacy_backward.yaml index 503ae20c3e22231ecf72ea8637986d35c9f0c762..146d8d6fa37775926acfd408ee9f15b858240563 100755 --- a/paddle/phi/api/yaml/legacy_backward.yaml +++ b/paddle/phi/api/yaml/legacy_backward.yaml @@ -273,16 +273,6 @@ data_type : softmax inplace : (softmax -> input_grad) -- backward_op : cumprod_grad - forward : cumprod (Tensor x, int dim) -> Tensor(out) - args : (Tensor x, Tensor out, Tensor out_grad, int dim) - output : Tensor(x_grad) - infer_meta : - func : UnchangedInferMeta - param: [x] - kernel : - func : cumprod_grad - - backward_op : cumsum_grad forward : cumsum(Tensor x, Scalar axis, bool flatten, bool exclusive, bool reverse) -> Tensor(out) args : (Tensor x, Tensor out_grad, Scalar axis, bool flatten, bool exclusive, bool reverse) diff --git a/paddle/phi/api/yaml/legacy_ops.yaml b/paddle/phi/api/yaml/legacy_ops.yaml index 4bbf11c4e294b15dba808955bc115469665296f7..4721dff883a94c9abff9e8d3a4d7fe64a2d46c48 100755 --- a/paddle/phi/api/yaml/legacy_ops.yaml +++ b/paddle/phi/api/yaml/legacy_ops.yaml @@ -388,15 +388,6 @@ data_type : input backward : cross_entropy_with_softmax_grad -- op : cumprod - args : (Tensor x, int dim) - output : Tensor(out) - infer_meta : - func : UnchangedInferMetaCheckAxis - kernel : - func : cumprod - backward : cumprod_grad - - op : cumsum args : (Tensor x, Scalar axis, bool flatten, bool exclusive, bool reverse) output : Tensor(out) diff --git a/paddle/phi/api/yaml/op_compat.yaml b/paddle/phi/api/yaml/op_compat.yaml index 2652221f5727f0c0357fab8f701111c63f8a04bf..d7dee1d99446e505495e866ac1f3bc9e97040976 100644 --- a/paddle/phi/api/yaml/op_compat.yaml +++ b/paddle/phi/api/yaml/op_compat.yaml @@ -398,6 +398,15 @@ outputs : out : Out +- op : cumprod + backward : cumprod_grad + inputs : + x : X + attrs : + dim : dim + outputs : + out : Out + - op : cumsum backward: cumsum_grad inputs : diff --git a/paddle/phi/api/yaml/ops.yaml b/paddle/phi/api/yaml/ops.yaml index 673b42cd57ac8e778568f8cbb6a36ca81d98f978..f1bab0fd3a5644212891394a0458ed413646b002 100644 --- a/paddle/phi/api/yaml/ops.yaml +++ b/paddle/phi/api/yaml/ops.yaml @@ -320,6 +320,15 @@ data_type : x backward : cross_grad +- op : cumprod + args : (Tensor x, int dim) + output : Tensor(out) + infer_meta : + func : UnchangedInferMetaCheckAxis + kernel : + func : cumprod + backward : cumprod_grad + - op : det args : (Tensor x) output : Tensor diff --git a/paddle/phi/ops/compat/cumprod_sig.cc b/paddle/phi/ops/compat/cumprod_sig.cc deleted file mode 100644 index ffe0ba75bb9df2472746874b8e2c5829cae15311..0000000000000000000000000000000000000000 --- a/paddle/phi/ops/compat/cumprod_sig.cc +++ /dev/null @@ -1,26 +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 CumprodGradGradOpArgumentMapping( - const ArgumentMappingContext& ctx) { - return KernelSignature( - "cumprod_grad", {"X", "Out", "Out@GRAD"}, {"dim"}, {"X@GRAD"}); -} - -} // namespace phi -PD_REGISTER_ARG_MAPPING_FN(cumprod_grad, phi::CumprodGradGradOpArgumentMapping);