diff --git a/paddle/fluid/operators/generator/filters.py b/paddle/fluid/operators/generator/filters.py index 56f87f3c1de7560cc0b7b28155fc4667f4020f58..0ef3adc3306ec937b61126255121607268bc5dd7 100644 --- a/paddle/fluid/operators/generator/filters.py +++ b/paddle/fluid/operators/generator/filters.py @@ -40,6 +40,18 @@ def get_infer_var_type_func(op_name): }} }}; """ + elif op_name == "merge_selected_rows": + return f""" + class {to_pascal_case(op_name)}InferVarType + : public framework::PassInDtypeAndVarTypeToOutput {{ + protected: + std::unordered_map& GetInputOutputWithSameType() + const override {{ + static std::unordered_map m{{{{"X", /*->*/ "Out"}}}}; + return m; + }} + }}; + """ else: return None diff --git a/paddle/fluid/operators/merge_selected_rows_op.cc b/paddle/fluid/operators/merge_selected_rows_op.cc deleted file mode 100644 index b408e42488b89d64c33b7c4e4eb565792c773918..0000000000000000000000000000000000000000 --- a/paddle/fluid/operators/merge_selected_rows_op.cc +++ /dev/null @@ -1,93 +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 - -#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 MergeSelectedRowsOp : public framework::OperatorWithKernel { - public: - using framework::OperatorWithKernel::OperatorWithKernel; -}; - -class MergeSelectedRowsOpMaker : public framework::OpProtoAndCheckerMaker { - public: - void Make() override { - AddInput("X", - "The input type is SelectedRows, and the selected rows may be " - "duplicated."); - AddOutput("Out", - "The output type is SelectedRows, and the selected rows are not " - "duplicated."); - AddComment( - R"DOC( -MergeSelectedRows Operator. - -MergeSelectedRows is used to merge the duplicated rows of the input. The -output's row has no duplicated, and it's order is incremental. - -Example: - Input: - X.rows is [0, 5, 5, 4, 19] - X.height is 20 - X.value is: - [[1, 1] - [2, 2] - [3, 3] - [4, 4] - [6, 6]] - - Output: - Out.row is [0, 4, 5, 19] - Out.height is 20 - Out.value is: - [[1, 1] - [4, 4] - [5, 5] - [6, 6]] -)DOC"); - } -}; - -class MergeSelectedRowsOpInferVarType - : public framework::PassInDtypeAndVarTypeToOutput { - protected: - std::unordered_map& GetInputOutputWithSameType() - const override { - static std::unordered_map m{{"X", /*->*/ "Out"}}; - return m; - } -}; - -} // namespace operators -} // namespace paddle - -namespace ops = paddle::operators; -namespace plat = paddle::platform; - -DECLARE_INFER_SHAPE_FUNCTOR(merge_selected_rows, - MergeSelectedRowsInferMetaFunctor, - PD_INFER_META(phi::UnchangedInferMeta)); - -REGISTER_OPERATOR(merge_selected_rows, - ops::MergeSelectedRowsOp, - ops::MergeSelectedRowsOpMaker, - ops::MergeSelectedRowsOpInferVarType, - MergeSelectedRowsInferMetaFunctor); diff --git a/paddle/phi/api/yaml/legacy_ops.yaml b/paddle/phi/api/yaml/legacy_ops.yaml index abc364f9cc5d53471a1fdae5ea7ac7294d09fb8e..183da66a5aad9fecd898a5a636eb54130b5fade5 100755 --- a/paddle/phi/api/yaml/legacy_ops.yaml +++ b/paddle/phi/api/yaml/legacy_ops.yaml @@ -1032,14 +1032,6 @@ func : mean_all backward : mean_all_grad -- op : merge_selected_rows - args : (Tensor x) - output : Tensor - infer_meta : - func : UnchangedInferMeta - kernel : - func : merge_selected_rows {selected_rows -> selected_rows} - - op : merged_adam_ args : (Tensor[] param, Tensor[] grad, Tensor[] learning_rate, Tensor[] moment1, Tensor[] moment2, Tensor[] beta1_pow, Tensor[] beta2_pow, Tensor[] master_param, Scalar beta1, Scalar beta2, Scalar epsilon, bool multi_precision, bool use_global_beta_pow) output : Tensor[](param_out){param.size()}, Tensor[](moment1_out){param.size()}, Tensor[](moment2_out){param.size()}, Tensor[](beta1_pow_out){param.size()}, Tensor[](beta2_pow_out){param.size()}, Tensor[](master_param_out){param.size()} diff --git a/paddle/phi/api/yaml/op_compat.yaml b/paddle/phi/api/yaml/op_compat.yaml index dc48ead7f5795a9c0c3281ffc30764a152299173..118c315ba4325e7a1cdc29deb21c63ef00530102 100644 --- a/paddle/phi/api/yaml/op_compat.yaml +++ b/paddle/phi/api/yaml/op_compat.yaml @@ -1253,6 +1253,12 @@ extra : attrs : [bool use_mkldnn = false] +- op : merge_selected_rows + inputs : + x : X + outputs : + out : Out + - op : meshgrid backward : meshgrid_grad inputs : diff --git a/paddle/phi/api/yaml/ops.yaml b/paddle/phi/api/yaml/ops.yaml index 37dce69cb5896997157571ac5e4faac3f457ff85..82bae11179fd10a987da6a20c551970665647407 100644 --- a/paddle/phi/api/yaml/ops.yaml +++ b/paddle/phi/api/yaml/ops.yaml @@ -1011,6 +1011,14 @@ optional : bias, cu_seqlens_q, cu_seqlens_k, causal_diagonal, seqlen_k backward : memory_efficient_attention_grad +- op : merge_selected_rows + args : (Tensor x) + output : Tensor(out) + infer_meta : + func : UnchangedInferMeta + kernel : + func : merge_selected_rows {selected_rows -> selected_rows} + - op : meshgrid args : (Tensor[] inputs) output : Tensor[]{inputs.size()}