Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
b1658232
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2298
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
b1658232
编写于
9月 20, 2022
作者:
Y
YuanRisheng
提交者:
GitHub
9月 20, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[PHI]Move merge_selected_rows kernel to PHI (#46004)
* move_merge_selected_rows * update code
上级
b408e71f
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
102 addition
and
85 deletion
+102
-85
paddle/fluid/operators/merge_selected_rows_op.cc
paddle/fluid/operators/merge_selected_rows_op.cc
+12
-24
paddle/fluid/operators/merge_selected_rows_op.cu.cc
paddle/fluid/operators/merge_selected_rows_op.cu.cc
+0
-22
paddle/fluid/operators/merge_selected_rows_op.h
paddle/fluid/operators/merge_selected_rows_op.h
+0
-37
paddle/fluid/operators/unity_build_rule.cmake
paddle/fluid/operators/unity_build_rule.cmake
+0
-2
paddle/phi/api/yaml/legacy_ops.yaml
paddle/phi/api/yaml/legacy_ops.yaml
+8
-0
paddle/phi/kernels/selected_rows/merge_selected_rows_kernel.cc
...e/phi/kernels/selected_rows/merge_selected_rows_kernel.cc
+51
-0
paddle/phi/kernels/selected_rows/merge_selected_rows_kernel.h
...le/phi/kernels/selected_rows/merge_selected_rows_kernel.h
+28
-0
python/paddle/fluid/layers/nn.py
python/paddle/fluid/layers/nn.py
+3
-0
未找到文件。
paddle/fluid/operators/merge_selected_rows_op.cc
浏览文件 @
b1658232
...
...
@@ -12,33 +12,19 @@ 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/merge_selected_rows_op.h"
#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
;
void
InferShape
(
framework
::
InferShapeContext
*
ctx
)
const
override
{
OP_INOUT_CHECK
(
ctx
->
HasInput
(
"X"
),
"Input"
,
"X"
,
"MergeSelectedRows"
);
OP_INOUT_CHECK
(
ctx
->
HasOutput
(
"Out"
),
"Output"
,
"Out"
,
"MergeSelectedRows"
);
PADDLE_ENFORCE_EQ
(
ctx
->
GetInputsVarType
(
"X"
).
front
(),
framework
::
proto
::
VarType
::
SELECTED_ROWS
,
platform
::
errors
::
InvalidArgument
(
"Input(X) of MergeSelectedRowsOp "
"should be of type SelectedRows."
));
PADDLE_ENFORCE_EQ
(
ctx
->
GetOutputsVarType
(
"Out"
).
front
(),
framework
::
proto
::
VarType
::
SELECTED_ROWS
,
platform
::
errors
::
InvalidArgument
(
"Output(Out) of MergeSelectedRowsOp "
"should be of type SelectedRows."
));
ctx
->
ShareDim
(
"X"
,
/*->*/
"Out"
);
}
};
class
MergeSelectedRowsOpMaker
:
public
framework
::
OpProtoAndCheckerMaker
{
...
...
@@ -95,11 +81,13 @@ class MergeSelectedRowsOpInferVarType
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
);
REGISTER_OP_CPU_KERNEL
(
merge_selected_rows
,
ops
::
MergeSelectedRowsKernel
<
phi
::
CPUContext
,
float
>
,
ops
::
MergeSelectedRowsKernel
<
phi
::
CPUContext
,
double
>
);
ops
::
MergeSelectedRowsOpInferVarType
,
MergeSelectedRowsInferMetaFunctor
);
paddle/fluid/operators/merge_selected_rows_op.cu.cc
已删除
100644 → 0
浏览文件 @
b408e71f
/* 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/operators/merge_selected_rows_op.h"
namespace
ops
=
paddle
::
operators
;
namespace
plat
=
paddle
::
platform
;
REGISTER_OP_CUDA_KERNEL
(
merge_selected_rows
,
ops
::
MergeSelectedRowsKernel
<
phi
::
GPUContext
,
float
>
,
ops
::
MergeSelectedRowsKernel
<
phi
::
GPUContext
,
double
>
);
paddle/fluid/operators/merge_selected_rows_op.h
已删除
100644 → 0
浏览文件 @
b408e71f
/* 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 <string>
#include "paddle/fluid/framework/op_registry.h"
#include "paddle/fluid/operators/math/selected_rows_functor.h"
namespace
paddle
{
namespace
operators
{
template
<
typename
DeviceContext
,
typename
T
>
class
MergeSelectedRowsKernel
:
public
framework
::
OpKernel
<
T
>
{
public:
void
Compute
(
const
framework
::
ExecutionContext
&
context
)
const
override
{
auto
*
x
=
context
.
Input
<
phi
::
SelectedRows
>
(
"X"
);
auto
*
out
=
context
.
Output
<
phi
::
SelectedRows
>
(
"Out"
);
math
::
scatter
::
MergeAdd
<
DeviceContext
,
T
>
merge_func
;
merge_func
(
context
.
template
device_context
<
DeviceContext
>(),
*
x
,
out
);
}
};
}
// namespace operators
}
// namespace paddle
paddle/fluid/operators/unity_build_rule.cmake
浏览文件 @
b1658232
...
...
@@ -365,7 +365,6 @@ register_unity_group(
split_op.cu.cc
activation_cudnn_op.cu.cc
assign_value_op.cu.cc
merge_selected_rows_op.cu.cc
run_program_op.cu.cc
warpctc_op.cu.cc
)
register_unity_group
(
...
...
@@ -469,7 +468,6 @@ register_unity_group(
lookup_table_v2_op.cu
margin_rank_loss_op.cu
masked_select_op.cu
merge_selected_rows_op.cu
lstmp_op.cu
shuffle_channel_op.cu
softmax_cudnn_op.cu
...
...
paddle/phi/api/yaml/legacy_ops.yaml
浏览文件 @
b1658232
...
...
@@ -1762,6 +1762,14 @@
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()}
...
...
paddle/phi/kernels/selected_rows/merge_selected_rows_kernel.cc
0 → 100644
浏览文件 @
b1658232
// 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/kernels/selected_rows/merge_selected_rows_kernel.h"
#include "paddle/phi/backends/cpu/cpu_context.h"
#include "paddle/phi/backends/gpu/gpu_context.h"
#include "paddle/phi/core/kernel_registry.h"
#include "paddle/fluid/operators/math/selected_rows_functor.h"
namespace
phi
{
namespace
sr
{
template
<
typename
T
,
typename
Context
>
void
MergeSelectedRowsKernel
(
const
Context
&
dev_ctx
,
const
SelectedRows
&
x
,
SelectedRows
*
out
)
{
paddle
::
operators
::
math
::
scatter
::
MergeAdd
<
Context
,
T
>
merge_func
;
merge_func
(
dev_ctx
,
x
,
out
);
}
}
// namespace sr
}
// namespace phi
PD_REGISTER_KERNEL
(
merge_selected_rows
,
CPU
,
ALL_LAYOUT
,
phi
::
sr
::
MergeSelectedRowsKernel
,
float
,
double
)
{}
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
PD_REGISTER_KERNEL
(
merge_selected_rows
,
GPU
,
ALL_LAYOUT
,
phi
::
sr
::
MergeSelectedRowsKernel
,
float
,
double
)
{}
#endif
paddle/phi/kernels/selected_rows/merge_selected_rows_kernel.h
0 → 100644
浏览文件 @
b1658232
// 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.
#pragma once
#include "paddle/phi/core/selected_rows.h"
namespace
phi
{
namespace
sr
{
template
<
typename
T
,
typename
Context
>
void
MergeSelectedRowsKernel
(
const
Context
&
dev_ctx
,
const
SelectedRows
&
x
,
SelectedRows
*
out
);
}
// namespace sr
}
// namespace phi
python/paddle/fluid/layers/nn.py
浏览文件 @
b1658232
...
...
@@ -13216,6 +13216,9 @@ def merge_selected_rows(x, name=None):
type=fluid.core.VarDesc.VarType.SELECTED_ROWS)
y = fluid.layers.merge_selected_rows(var)
"""
if in_dygraph_mode():
return _C_ops.merge_selected_rows(x)
if _non_static_mode():
return _legacy_C_ops.merge_selected_rows(x)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录