diff --git a/paddle/fluid/operators/arg_max_op.cc b/paddle/fluid/operators/arg_max_op.cc deleted file mode 100644 index c61ae6744b664911eaa838f004ff32527efc8222..0000000000000000000000000000000000000000 --- a/paddle/fluid/operators/arg_max_op.cc +++ /dev/null @@ -1,47 +0,0 @@ -/* Copyright (c) 2018 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_version_registry.h" -#include "paddle/fluid/operators/arg_min_max_op_base.h" -#include "paddle/phi/core/infermeta_utils.h" -#include "paddle/phi/infermeta/unary.h" - -DECLARE_INFER_SHAPE_FUNCTOR(arg_max, - ArgMaxInferShapeFunctor, - PD_INFER_META(phi::ArgMinMaxInferMeta)); - -REGISTER_OPERATOR( - arg_max, - paddle::operators::ArgMinMaxOp, - paddle::operators::ArgMaxOpMaker, - paddle::framework::EmptyGradOpMaker, - paddle::framework::EmptyGradOpMaker, - ArgMaxInferShapeFunctor); - -REGISTER_OP_VERSION(arg_max).AddCheckpoint( - R"ROC( - Upgrade argmax add a new attribute [flatten] and modify the attribute of dtype)ROC", - paddle::framework::compatible::OpVersionDesc() - .NewAttr("flatten", - "In order to compute the argmax over the flattened array " - "when the " - "argument `axis` in python API is None.", - false) - .ModifyAttr("dtype", - "Change the default value of dtype from -1 to 3" - ", means return the int64 indices directly. The rearse why " - "changing the default value is that the int64 value in " - "VarType is 3 in the frameworke.proto.", - 3)); diff --git a/paddle/fluid/operators/arg_max_op_npu.cc b/paddle/fluid/operators/arg_max_op_npu.cc deleted file mode 100644 index 014fb09474936404017376dddff82d01988a21ce..0000000000000000000000000000000000000000 --- a/paddle/fluid/operators/arg_max_op_npu.cc +++ /dev/null @@ -1,77 +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 Licnse. */ - -#include "paddle/fluid/operators/arg_min_max_op_base.h" - -namespace paddle { -namespace operators { - -using NPUDeviceContext = platform::NPUDeviceContext; - -template -struct VisitDataArgNPUMaxFunctor { - const framework::ExecutionContext& ctx; - - explicit VisitDataArgNPUMaxFunctor(const framework::ExecutionContext& ctx) - : ctx(ctx) {} - template - void apply() const { - auto& x = *(ctx.Input("X")); - auto& out = *(ctx.Output("Out")); - out.template mutable_data(ctx.GetPlace()); - auto axis = ctx.Attr("axis"); - auto dtype = ctx.Attr("dtype"); - const bool& flatten = ctx.Attr("flatten"); - - phi::DenseTensor transformed_x(x.type()); - transformed_x.ShareDataWith(x); - if (flatten) { - transformed_x.Resize(phi::make_ddim({x.numel()})); - } - - auto stream = ctx.template device_context().stream(); - NpuOpRunner runner; - runner.SetType("ArgMaxV2") - .AddInput(transformed_x) - .AddInput(std::vector{axis}) - .AddOutput(out) - .AddAttrDataType("dtype", dtype) - .Run(stream); - } -}; - -template -class ArgMaxNPUKernel : public framework::OpKernel { - public: - void Compute(const framework::ExecutionContext& ctx) const override { - auto& dtype = ctx.Attr("dtype"); - if (dtype < 0) { - framework::VisitDataTypeTiny(static_cast( - framework::proto::VarType::INT64), - VisitDataArgNPUMaxFunctor(ctx)); - return; - } - framework::VisitDataTypeTiny( - static_cast(dtype), - VisitDataArgNPUMaxFunctor(ctx)); - } -}; - -} // namespace operators -} // namespace paddle - -namespace ops = paddle::operators; -REGISTER_OP_NPU_KERNEL(arg_max, - ops::ArgMaxNPUKernel, - ops::ArgMaxNPUKernel); diff --git a/paddle/fluid/operators/arg_min_max_op_base.h b/paddle/fluid/operators/arg_min_max_op_base.h deleted file mode 100644 index 090fdff31c1dacdbc780295f9cf328ffaa83f1c8..0000000000000000000000000000000000000000 --- a/paddle/fluid/operators/arg_min_max_op_base.h +++ /dev/null @@ -1,86 +0,0 @@ -/* Copyright (c) 2018 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. */ - -#pragma once -#include -#include -#include - -#include "paddle/fluid/framework/eigen.h" -#include "paddle/fluid/framework/lod_tensor.h" -#include "paddle/fluid/framework/op_registry.h" -#include "paddle/fluid/framework/operator.h" -#include "paddle/fluid/platform/enforce.h" -#include "paddle/fluid/string/printf.h" -#include "paddle/phi/core/ddim.h" - -namespace paddle { -namespace operators { - -class ArgMinMaxOp : public framework::OperatorWithKernel { - public: - using framework::OperatorWithKernel::OperatorWithKernel; - - phi::KernelKey GetExpectedKernelType( - const framework::ExecutionContext& ctx) const override { - auto input_data_type = - framework::OperatorWithKernel::IndicateVarDataType(ctx, "X"); - return phi::KernelKey(input_data_type, ctx.GetPlace()); - } -}; - -class BaseArgMinMaxOpMaker : public framework::OpProtoAndCheckerMaker { - protected: - virtual const char* OpName() const = 0; - virtual const char* Name() const = 0; - - public: - void Make() override { - AddInput("X", "Input tensor."); - AddOutput("Out", "Output tensor."); - AddAttr("axis", "The axis in which to compute the arg indics.") - .SupportTensor(); - AddAttr("keepdims", "Keep the dim that to reduce.").SetDefault(false); - AddAttr("flatten", - "Flatten the input value, and search the min or max indices") - .SetDefault(false); - AddAttr("dtype", - "(int, 3), the dtype of indices, the indices dtype must be " - "int32, int64." - "default dtype is int64, and proto value is 3.") - .SetDefault(3); - AddComment(string::Sprintf(R"DOC( - %s Operator. - - Computes the indices of the %s elements of the input tensor's element - along the provided axis. -)DOC", - OpName(), - Name())); - } -}; - -class ArgMinOpMaker : public BaseArgMinMaxOpMaker { - protected: - const char* OpName() const override { return "ArgMin"; } - const char* Name() const override { return "min"; } -}; - -class ArgMaxOpMaker : public BaseArgMinMaxOpMaker { - protected: - const char* OpName() const override { return "ArgMax"; } - const char* Name() const override { return "max"; } -}; -} // namespace operators -} // namespace paddle diff --git a/paddle/fluid/operators/arg_min_op.cc b/paddle/fluid/operators/arg_min_op.cc deleted file mode 100644 index 0cbe2cf81d33c98891c358c4051e4de78a2d8dd4..0000000000000000000000000000000000000000 --- a/paddle/fluid/operators/arg_min_op.cc +++ /dev/null @@ -1,47 +0,0 @@ -/* Copyright (c) 2018 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_version_registry.h" -#include "paddle/fluid/operators/arg_min_max_op_base.h" -#include "paddle/phi/core/infermeta_utils.h" -#include "paddle/phi/infermeta/unary.h" - -DECLARE_INFER_SHAPE_FUNCTOR(arg_min, - ArgMinInferShapeFunctor, - PD_INFER_META(phi::ArgMinMaxInferMeta)); - -REGISTER_OPERATOR( - arg_min, - paddle::operators::ArgMinMaxOp, - paddle::operators::ArgMinOpMaker, - paddle::framework::EmptyGradOpMaker, - paddle::framework::EmptyGradOpMaker, - ArgMinInferShapeFunctor); - -REGISTER_OP_VERSION(arg_min).AddCheckpoint( - R"ROC( - Upgrade argmin add a new attribute [flatten] and modify the attribute of dtype)ROC", - paddle::framework::compatible::OpVersionDesc() - .NewAttr("flatten", - "In order to compute the argmin over the flattened array " - "when the " - "argument `axis` in python API is None.", - false) - .ModifyAttr("dtype", - "Change the default value of dtype from -1 to 3" - ", means return the int64 indices directly. The rearse why " - "changing the default value is that the int64 value in " - "VarType is 3 in the frameworke.proto.", - 3)); diff --git a/paddle/fluid/operators/arg_min_op_npu.cc b/paddle/fluid/operators/arg_min_op_npu.cc deleted file mode 100644 index e601efd2d37e1d6434a41fdf7e2c97cc5be15b34..0000000000000000000000000000000000000000 --- a/paddle/fluid/operators/arg_min_op_npu.cc +++ /dev/null @@ -1,53 +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/operators/arg_min_max_op_base.h" - -namespace paddle { -namespace operators { - -template -class ArgMinNPUKernel : public framework::OpKernel { - public: - void Compute(const framework::ExecutionContext& ctx) const override { - auto* x = ctx.Input("X"); - int64_t axis = ctx.Attr("axis"); - auto dtype = ctx.Attr("dtype"); - - auto* out = ctx.Output("Out"); - out->mutable_data(ctx.GetPlace()); - - NpuOpRunner runner; - runner.SetType("ArgMin") - .AddInput(*x) - .AddInput(std::vector{axis}) - .AddOutput(*out) - .AddAttr("dtype", dtype); - - auto stream = - ctx.template device_context() - .stream(); - runner.Run(stream); - } -}; - -} // namespace operators -} // namespace paddle - -namespace ops = paddle::operators; -REGISTER_OP_NPU_KERNEL( - arg_min, - ops::ArgMinNPUKernel, - ops::ArgMinNPUKernel); diff --git a/paddle/phi/api/yaml/legacy_ops.yaml b/paddle/phi/api/yaml/legacy_ops.yaml index cd6ef6fbdf71f4ed2c49ceeb5fca3c11a21695ca..8e97c11ae7bf373c0263894796ce9deb5c8f11d3 100755 --- a/paddle/phi/api/yaml/legacy_ops.yaml +++ b/paddle/phi/api/yaml/legacy_ops.yaml @@ -143,22 +143,6 @@ data_transform : support_trans_dtype : start, end, step -- op : argmax - args : (Tensor x, Scalar axis, bool keepdims, bool flatten, int dtype) - output : Tensor(out) - infer_meta : - func : ArgMinMaxInferMeta - kernel : - func : argmax - -- op : argmin - args : (Tensor x, Scalar axis, bool keepdims, bool flatten, int dtype) - output : Tensor(out) - infer_meta : - func : ArgMinMaxInferMeta - kernel : - func : argmin - - op : assign args : (Tensor x) output : Tensor diff --git a/paddle/phi/api/yaml/op_compat.yaml b/paddle/phi/api/yaml/op_compat.yaml index 0c064bdd6fe949bfcd17cdffcd54dd022e13f194..549029bcd2299684a1e1fc99076a5e221fdebfe5 100644 --- a/paddle/phi/api/yaml/op_compat.yaml +++ b/paddle/phi/api/yaml/op_compat.yaml @@ -109,6 +109,26 @@ outputs : out : Out +- op : argmax(arg_max) + inputs : + x : X + outputs : + out : Out + scalar: + axis: + data_type : int64_t + support_tensor : true + +- op : argmin(arg_min) + inputs : + x : X + outputs : + out : Out + scalar: + axis: + data_type : int64_t + support_tensor : true + - op : argsort inputs : x : X diff --git a/paddle/phi/api/yaml/ops.yaml b/paddle/phi/api/yaml/ops.yaml index 573b64940676f7c2f7f5bf0e1263a5d4500e0c8b..cb55a85b45c600ef683573fde1b96c07d83aecef 100644 --- a/paddle/phi/api/yaml/ops.yaml +++ b/paddle/phi/api/yaml/ops.yaml @@ -61,6 +61,24 @@ func : angle backward : angle_grad +- op : argmax + args : (Tensor x, Scalar(int64_t) axis, bool keepdims = false, bool flatten = false, int dtype = 3) + output : Tensor(out) + infer_meta : + func : ArgMinMaxInferMeta + kernel : + func : argmax + data_type : x + +- op : argmin + args : (Tensor x, Scalar(int64_t) axis, bool keepdims = false, bool flatten = false, int dtype = 3) + output : Tensor(out) + infer_meta : + func : ArgMinMaxInferMeta + kernel : + func : argmin + data_type : x + - op : argsort args : (Tensor x, int axis=-1, bool descending=false) output : Tensor(out), Tensor(indices) diff --git a/paddle/phi/ops/compat/arg_min_max_sig.cc b/paddle/phi/ops/compat/arg_min_max_sig.cc deleted file mode 100644 index 4739165c8299cb7a97038e6078e8f5d267d3689d..0000000000000000000000000000000000000000 --- a/paddle/phi/ops/compat/arg_min_max_sig.cc +++ /dev/null @@ -1,18 +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" - -PD_REGISTER_BASE_KERNEL_NAME(arg_max, argmax); -PD_REGISTER_BASE_KERNEL_NAME(arg_min, argmin);