未验证 提交 6cd3575c 编写于 作者: W Wang Xin 提交者: GitHub

add autogen code support for merge_selected_rows (#52274)

* add autogen code support for merge_selected_rows

* bug fixed
上级 336160cf
...@@ -40,6 +40,18 @@ def get_infer_var_type_func(op_name): ...@@ -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<std::string, std::string>& GetInputOutputWithSameType()
const override {{
static std::unordered_map<std::string, std::string> m{{{{"X", /*->*/ "Out"}}}};
return m;
}}
}};
"""
else: else:
return None return None
......
/* 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 <unordered_map>
#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<std::string, std::string>& GetInputOutputWithSameType()
const override {
static std::unordered_map<std::string, std::string> 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);
...@@ -1032,14 +1032,6 @@ ...@@ -1032,14 +1032,6 @@
func : mean_all func : mean_all
backward : mean_all_grad 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_ - 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) 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()} 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()}
......
...@@ -1253,6 +1253,12 @@ ...@@ -1253,6 +1253,12 @@
extra : extra :
attrs : [bool use_mkldnn = false] attrs : [bool use_mkldnn = false]
- op : merge_selected_rows
inputs :
x : X
outputs :
out : Out
- op : meshgrid - op : meshgrid
backward : meshgrid_grad backward : meshgrid_grad
inputs : inputs :
......
...@@ -1011,6 +1011,14 @@ ...@@ -1011,6 +1011,14 @@
optional : bias, cu_seqlens_q, cu_seqlens_k, causal_diagonal, seqlen_k optional : bias, cu_seqlens_q, cu_seqlens_k, causal_diagonal, seqlen_k
backward : memory_efficient_attention_grad 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 - op : meshgrid
args : (Tensor[] inputs) args : (Tensor[] inputs)
output : Tensor[]{inputs.size()} output : Tensor[]{inputs.size()}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册