diff --git a/paddle/fluid/operators/eigvalsh_op.cc b/paddle/fluid/operators/eigvalsh_op.cc deleted file mode 100644 index 27c70f1e9b9a9ac737922b96858435ed18ab5b6c..0000000000000000000000000000000000000000 --- a/paddle/fluid/operators/eigvalsh_op.cc +++ /dev/null @@ -1,113 +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/backward.h" -#include "paddle/phi/infermeta/unary.h" - -namespace paddle { -namespace operators { - -class EigvalshOp : public framework::OperatorWithKernel { - public: - using framework::OperatorWithKernel::OperatorWithKernel; -}; - -class EigvalshOpMaker : public framework::OpProtoAndCheckerMaker { - public: - void Make() override { - AddInput("X", - "(Tensor), Hermitian or real symmetric matrices." - "Its shape should be [*, N, N] where * is zero or" - "more batch dimensions. The data type is float32 ," - "float64, complex64, complex128."); - AddOutput("Eigenvalues", - "(Tensor), The eigenvalues in ascending order." - "The data type is float32 or float64."); - AddOutput( - "Eigenvectors", - "(Tensor), The column is the normalized eigenvector " - "corresponding to the eigenvalue. The data type is the same as ``X``." - "Eigenvectors are required to calculate gradient when backward."); - AddAttr( - "UPLO", - "(string, default 'L'), 'L' represents the lower triangular matrix," - "'U' represents the upper triangular matrix.") - .SetDefault("L"); - AddAttr("is_test", - "(bool, default false) Set to true for inference only, false " - "for training.") - .SetDefault(false); - AddComment(R"DOC( -Eigvalsh Operator. - -Computes the eigenvalues of a complex Hermitian - (conjugate symmetric) or a real symmetric matrix. - -)DOC"); - } -}; - -class EigvalshGradOp : public framework::OperatorWithKernel { - public: - using framework::OperatorWithKernel::OperatorWithKernel; - - protected: - phi::KernelKey GetExpectedKernelType( - const framework::ExecutionContext& ctx) const override { - return phi::KernelKey( - OperatorWithKernel::IndicateVarDataType(ctx, "Eigenvectors"), - ctx.device_context().GetPlace()); - } -}; - -template -class EigvalshGradOpMaker : public framework::SingleGradOpMaker { - public: - using framework::SingleGradOpMaker::SingleGradOpMaker; - - protected: - void Apply(GradOpPtr op) const override { - op->SetType(this->ForwardOpType() + "_grad"); - op->SetInput("Eigenvectors", this->Output("Eigenvectors")); - op->SetInput(framework::GradVarName("Eigenvalues"), - this->OutputGrad("Eigenvalues")); - op->SetAttrMap(this->Attrs()); - op->SetOutput(framework::GradVarName("X"), this->InputGrad("X")); - } -}; - -} // namespace operators -} // namespace paddle - -namespace ops = paddle::operators; - -DECLARE_INFER_SHAPE_FUNCTOR(eigvalsh, - EigvalshInferShapeFunctor, - PD_INFER_META(phi::EigvalshInferMeta)); -DECLARE_INFER_SHAPE_FUNCTOR(eigvalsh_grad, - EigvalshGradInferShapeFunctor, - PD_INFER_META(phi::EigvalshGradInferMeta)); - -REGISTER_OPERATOR(eigvalsh, - ops::EigvalshOp, - ops::EigvalshOpMaker, - ops::EigvalshGradOpMaker, - ops::EigvalshGradOpMaker, - EigvalshInferShapeFunctor); -REGISTER_OPERATOR(eigvalsh_grad, - ops::EigvalshGradOp, - EigvalshGradInferShapeFunctor); diff --git a/paddle/phi/api/yaml/backward.yaml b/paddle/phi/api/yaml/backward.yaml index b046f5830ad4c851a2dc2a9e971f8a0e73a58614..e0a12e13fb4e94de5240adf62f120e5309da21fc 100644 --- a/paddle/phi/api/yaml/backward.yaml +++ b/paddle/phi/api/yaml/backward.yaml @@ -456,6 +456,16 @@ func : eigh_grad data_type : out_v +- backward_op : eigvalsh_grad + forward : eigvalsh (Tensor x, str uplo = "L", bool is_test = false) -> Tensor(eigenvalues), Tensor(eigenvectors) + args : (Tensor eigenvectors, Tensor eigenvalues_grad, str uplo, bool is_test) + output : Tensor(x_grad) + infer_meta : + func : EigvalshGradInferMeta + kernel : + func : eigvalsh_grad + data_type : eigenvectors + - backward_op : elu_double_grad forward : elu_grad (Tensor x, Tensor out, Tensor grad_out, float alpha)-> Tensor(grad_x) args : (Tensor x, Tensor grad_out, Tensor grad_x_grad, float alpha) diff --git a/paddle/phi/api/yaml/legacy_backward.yaml b/paddle/phi/api/yaml/legacy_backward.yaml index 037a2f94862bcefdd97236d6e9f185304346f025..1e11bc54b3f51c102201520d9c8ed3fbaf2e72f7 100755 --- a/paddle/phi/api/yaml/legacy_backward.yaml +++ b/paddle/phi/api/yaml/legacy_backward.yaml @@ -340,18 +340,6 @@ kernel : func : dropout_grad -- backward_op : eigvalsh_grad - forward : eigvalsh (Tensor x, str uplo, bool is_test) -> Tensor(eigenvalues), Tensor(eigenvectors) - args : (Tensor eigenvectors, Tensor eigenvalues_grad, str uplo, bool is_test) - output : Tensor(x_grad) - infer_meta : - func : EigvalshGradInferMeta - kernel : - func : eigvalsh_grad - data_type : eigenvectors - data_transform : - skip_transform : eigenvalues_grad - - backward_op : einsum_grad forward : einsum (Tensor[] x, str equation) -> Tensor(out), Tensor[](inner_cache), Tensor[](x_shape) args : (Tensor[] x_shape, Tensor[] inner_cache, Tensor out_grad, str equation) diff --git a/paddle/phi/api/yaml/legacy_ops.yaml b/paddle/phi/api/yaml/legacy_ops.yaml index aa942970c8b17ef2b696e718f38b3fd88ffd7004..a689fbc17dfaf4c1c17d77d29b5597ebdaa0f48c 100755 --- a/paddle/phi/api/yaml/legacy_ops.yaml +++ b/paddle/phi/api/yaml/legacy_ops.yaml @@ -424,15 +424,6 @@ data_type: DataType::FLOAT32 optional : hypslength, refslength -- op : eigvalsh - args : (Tensor x, str uplo, bool is_test) - output : Tensor(eigenvalues), Tensor(eigenvectors) - infer_meta : - func : EigvalshInferMeta - kernel : - func : eigvalsh - backward : eigvalsh_grad - - op : einsum args : (Tensor[] x, str equation) output : Tensor, Tensor[]{x.size()}, Tensor[]{x.size()} diff --git a/paddle/phi/api/yaml/op_compat.yaml b/paddle/phi/api/yaml/op_compat.yaml index 63cca1670fe9bcb8726d52879db87073ff9f9992..8a2ce29511f06cb9495087444577c03fbf0bd88b 100644 --- a/paddle/phi/api/yaml/op_compat.yaml +++ b/paddle/phi/api/yaml/op_compat.yaml @@ -614,6 +614,15 @@ outputs : out : Out +- op : eigvalsh + backward : eigvalsh_grad + inputs : + {x : X} + outputs : + {eigenvalues : Eigenvalues, eigenvectors : Eigenvectors} + attrs : + uplo : UPLO + - op : elementwise_pow backward : elementwise_pow_grad extra : diff --git a/paddle/phi/api/yaml/ops.yaml b/paddle/phi/api/yaml/ops.yaml index 1870de32b49efdff8b9644876c4b89b2959e3177..110fc1838aba102564c6d864f742bb33c121afac 100644 --- a/paddle/phi/api/yaml/ops.yaml +++ b/paddle/phi/api/yaml/ops.yaml @@ -486,6 +486,16 @@ kernel : func : eigvals +- op : eigvalsh + args : (Tensor x, str uplo = "L", bool is_test = false) + output : Tensor(eigenvalues), Tensor(eigenvectors) + infer_meta : + func : EigvalshInferMeta + kernel : + func : eigvalsh + data_type : x + backward : eigvalsh_grad + - op : elu args : (Tensor x, float alpha = 1.0f) output : Tensor(out) diff --git a/paddle/phi/kernels/cpu/eigvalsh_grad_kernel.cc b/paddle/phi/kernels/cpu/eigvalsh_grad_kernel.cc index b7b5927740e0939e61204bf0b83bd5af38e15ef9..2489cbc825b22f98862899a3799b0bef6d052f0a 100644 --- a/paddle/phi/kernels/cpu/eigvalsh_grad_kernel.cc +++ b/paddle/phi/kernels/cpu/eigvalsh_grad_kernel.cc @@ -26,4 +26,6 @@ PD_REGISTER_KERNEL(eigvalsh_grad, float, double, phi::dtype::complex, - phi::dtype::complex) {} + phi::dtype::complex) { + kernel->InputAt(1).SetDataType(phi::dtype::ToReal(kernel_key.dtype())); +} diff --git a/paddle/phi/kernels/gpu/eigvalsh_grad_kernel.cu b/paddle/phi/kernels/gpu/eigvalsh_grad_kernel.cu index de26617d80f1b81af007a0327ae0d3ed18cff52c..bf62c2736e87c1fc94d488f5c52260c05f3e0c3e 100644 --- a/paddle/phi/kernels/gpu/eigvalsh_grad_kernel.cu +++ b/paddle/phi/kernels/gpu/eigvalsh_grad_kernel.cu @@ -26,4 +26,6 @@ PD_REGISTER_KERNEL(eigvalsh_grad, float, double, phi::dtype::complex, - phi::dtype::complex) {} + phi::dtype::complex) { + kernel->InputAt(1).SetDataType(phi::dtype::ToReal(kernel_key.dtype())); +} diff --git a/paddle/phi/kernels/gpu/eigvalsh_kernel.cu b/paddle/phi/kernels/gpu/eigvalsh_kernel.cu index 383f036c98cf9dfb65a419e46533dc974ccf8264..a075dad6cddb3029dbfbc6ad5bb3ce20a44ceb71 100644 --- a/paddle/phi/kernels/gpu/eigvalsh_kernel.cu +++ b/paddle/phi/kernels/gpu/eigvalsh_kernel.cu @@ -26,4 +26,6 @@ PD_REGISTER_KERNEL(eigvalsh, // cuda_only float, double, phi::dtype::complex, - phi::dtype::complex) {} + phi::dtype::complex) { + kernel->InputAt(1).SetDataType(phi::dtype::ToReal(kernel_key.dtype())); +} diff --git a/paddle/phi/ops/compat/eigvalsh_sig.cc b/paddle/phi/ops/compat/eigvalsh_sig.cc deleted file mode 100644 index b0635403355f7b4ba8044a744ec27718dd5b03ec..0000000000000000000000000000000000000000 --- a/paddle/phi/ops/compat/eigvalsh_sig.cc +++ /dev/null @@ -1,34 +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 EigvalshOpArgumentMapping(const ArgumentMappingContext& ctx) { - return KernelSignature( - "eigvalsh", {"X"}, {"UPLO", "is_test"}, {"Eigenvalues", "Eigenvectors"}); -} - -KernelSignature EigvalshGradOpArgumentMapping( - const ArgumentMappingContext& ctx) { - return KernelSignature("eigvalsh_grad", - {"Eigenvectors", "Eigenvalues@GRAD"}, - {"UPLO", "is_test"}, - {"X@GRAD"}); -} -} // namespace phi - -PD_REGISTER_ARG_MAPPING_FN(eigvalsh, phi::EigvalshOpArgumentMapping); -PD_REGISTER_ARG_MAPPING_FN(eigvalsh_grad, phi::EigvalshGradOpArgumentMapping);