Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
wmsofts
Paddle
提交
cb7fd370
P
Paddle
项目概览
wmsofts
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
cb7fd370
编写于
3月 10, 2023
作者:
Q
QingshuChen
提交者:
GitHub
3月 10, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
support c_embedding_grad for kunlun (#51399)
上级
e3826e0a
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
68 addition
and
0 deletion
+68
-0
paddle/fluid/operators/collective/c_embedding_op_xpu.cc
paddle/fluid/operators/collective/c_embedding_op_xpu.cc
+67
-0
paddle/phi/backends/xpu/xpu2_op_list.cc
paddle/phi/backends/xpu/xpu2_op_list.cc
+1
-0
未找到文件。
paddle/fluid/operators/collective/c_embedding_op_xpu.cc
浏览文件 @
cb7fd370
...
...
@@ -71,6 +71,70 @@ class CEmbeddingOpXPUKernel : public framework::OpKernel<T> {
}
};
template
<
typename
DeviceContext
,
typename
T
>
class
CEmbeddingGradOpXPUKernel
:
public
framework
::
OpKernel
<
T
>
{
public:
void
Compute
(
const
framework
::
ExecutionContext
&
context
)
const
override
{
const
int64_t
start_idx
=
context
.
Attr
<
int64_t
>
(
"start_index"
);
auto
ids_t
=
context
.
Input
<
phi
::
DenseTensor
>
(
"Ids"
);
auto
d_output_t
=
context
.
Input
<
phi
::
DenseTensor
>
(
framework
::
GradVarName
(
"Out"
));
auto
table_t
=
context
.
Input
<
phi
::
DenseTensor
>
(
"W"
);
auto
table_grad_t
=
context
.
Output
<
phi
::
DenseTensor
>
(
framework
::
GradVarName
(
"W"
));
T
*
table_grad_data
=
table_grad_t
->
mutable_data
<
T
>
(
table_t
->
dims
(),
context
.
GetPlace
());
size_t
table_t_mem_size
=
table_t
->
numel
()
*
phi
::
SizeOf
(
table_grad_t
->
dtype
());
size_t
table_grad_t_mem_size
=
table_grad_t
->
numel
()
*
framework
::
SizeOfType
(
framework
::
TransToProtoVarType
(
table_grad_t
->
dtype
()));
VLOG
(
10
)
<<
"table_dims:"
<<
table_t
->
dims
()
<<
", table_t memory_size:"
<<
table_t_mem_size
<<
", table_grad_t memory_size:"
<<
table_grad_t_mem_size
<<
", start_index:"
<<
start_idx
;
auto
&
dev_ctx
=
context
.
template
device_context
<
DeviceContext
>();
int
r
=
xpu
::
constant
(
dev_ctx
.
x_context
(),
table_grad_data
,
table_grad_t_mem_size
,
(
T
)
0
);
PADDLE_ENFORCE_XDNN_SUCCESS
(
r
,
"constant"
);
const
T
*
d_output_data
=
d_output_t
->
data
<
T
>
();
const
int64_t
height
=
table_t
->
dims
()[
0
];
const
int64_t
width
=
table_t
->
dims
()[
1
];
const
auto
&
index_type
=
framework
::
TransToProtoVarType
(
ids_t
->
dtype
());
if
(
index_type
==
framework
::
proto
::
VarType
::
INT32
)
{
r
=
xpu
::
embedding_grad
(
dev_ctx
.
x_context
(),
d_output_data
,
ids_t
->
data
<
int32_t
>
(),
table_grad_data
,
height
,
width
,
ids_t
->
numel
(),
-
1
,
static_cast
<
int32_t
>
(
start_idx
));
}
else
if
(
index_type
==
framework
::
proto
::
VarType
::
INT64
)
{
r
=
xpu
::
embedding_grad
(
dev_ctx
.
x_context
(),
d_output_data
,
ids_t
->
data
<
int64_t
>
(),
table_grad_data
,
height
,
width
,
ids_t
->
numel
(),
-
1
,
static_cast
<
int64_t
>
(
start_idx
));
}
else
{
PADDLE_THROW
(
platform
::
errors
::
Unavailable
(
"XPU c_embedding ids only support int32 or int64."
));
}
}
};
}
// namespace operators
}
// namespace paddle
...
...
@@ -80,3 +144,6 @@ namespace plat = paddle::platform;
REGISTER_OP_XPU_KERNEL
(
c_embedding
,
ops
::
CEmbeddingOpXPUKernel
<
paddle
::
platform
::
XPUDeviceContext
,
float
>
);
REGISTER_OP_XPU_KERNEL
(
c_embedding_grad
,
ops
::
CEmbeddingGradOpXPUKernel
<
paddle
::
platform
::
XPUDeviceContext
,
float
>
);
paddle/phi/backends/xpu/xpu2_op_list.cc
浏览文件 @
cb7fd370
...
...
@@ -97,6 +97,7 @@ XPUOpMap& get_kl2_ops() {
{
"c_concat"
,
XPUKernelSet
({
phi
::
DataType
::
FLOAT16
,
phi
::
DataType
::
FLOAT32
})},
{
"c_embedding"
,
XPUKernelSet
({
phi
::
DataType
::
FLOAT32
})},
{
"c_embedding_grad"
,
XPUKernelSet
({
phi
::
DataType
::
FLOAT32
})},
{
"c_identity"
,
XPUKernelSet
({
phi
::
DataType
::
FLOAT16
,
phi
::
DataType
::
FLOAT32
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录