Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
0759e99d
P
Paddle
项目概览
机器未来
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
0759e99d
编写于
4月 18, 2022
作者:
z8hanghuan
提交者:
GitHub
4月 18, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
support tril_triu_grad for KL2, *test=kunlun (#41877)
上级
ceef73c9
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
49 addition
and
4 deletion
+49
-4
paddle/fluid/operators/tril_triu_op_xpu.cc
paddle/fluid/operators/tril_triu_op_xpu.cc
+32
-0
paddle/fluid/platform/device/xpu/xpu2_op_list.h
paddle/fluid/platform/device/xpu/xpu2_op_list.h
+3
-0
python/paddle/fluid/tests/unittests/xpu/test_tril_triu_op_xpu.py
...paddle/fluid/tests/unittests/xpu/test_tril_triu_op_xpu.py
+14
-4
未找到文件。
paddle/fluid/operators/tril_triu_op_xpu.cc
浏览文件 @
0759e99d
...
...
@@ -43,6 +43,34 @@ class TrilTriuXPUKernel : public framework::OpKernel<T> {
}
};
template
<
typename
DeviceContext
,
typename
T
>
class
TrilTriuGradXPUKernel
:
public
framework
::
OpKernel
<
T
>
{
public:
void
Compute
(
const
framework
::
ExecutionContext
&
context
)
const
override
{
const
auto
*
d_out
=
context
.
Input
<
framework
::
Tensor
>
(
framework
::
GradVarName
(
"Out"
));
const
auto
*
dout_data
=
d_out
->
data
<
T
>
();
auto
*
d_x
=
context
.
Output
<
framework
::
Tensor
>
(
framework
::
GradVarName
(
"X"
));
auto
*
dx_data
=
d_x
->
mutable_data
<
T
>
(
context
.
GetPlace
());
const
int
diagonal
=
context
.
Attr
<
int
>
(
"diagonal"
);
const
bool
lower
=
context
.
Attr
<
bool
>
(
"lower"
);
auto
dy_shape
=
phi
::
vectorize
<
int
>
(
d_out
->
dims
());
auto
&
dev_ctx
=
context
.
template
device_context
<
DeviceContext
>();
int
r
=
0
;
if
(
lower
)
{
r
=
xpu
::
tril
(
dev_ctx
.
x_context
(),
dout_data
,
dx_data
,
dy_shape
,
diagonal
);
PADDLE_ENFORCE_XDNN_SUCCESS
(
r
,
"tril_op"
);
}
else
{
r
=
xpu
::
triu
(
dev_ctx
.
x_context
(),
dout_data
,
dx_data
,
dy_shape
,
diagonal
);
PADDLE_ENFORCE_XDNN_SUCCESS
(
r
,
"triu_op"
);
}
}
};
}
// namespace operators
}
// namespace paddle
...
...
@@ -50,4 +78,8 @@ namespace ops = paddle::operators;
REGISTER_OP_XPU_KERNEL
(
tril_triu
,
ops
::
TrilTriuXPUKernel
<
paddle
::
platform
::
XPUDeviceContext
,
int
>
,
ops
::
TrilTriuXPUKernel
<
paddle
::
platform
::
XPUDeviceContext
,
float
>
);
REGISTER_OP_XPU_KERNEL
(
tril_triu_grad
,
ops
::
TrilTriuGradXPUKernel
<
paddle
::
platform
::
XPUDeviceContext
,
int
>
,
ops
::
TrilTriuGradXPUKernel
<
paddle
::
platform
::
XPUDeviceContext
,
float
>
);
#endif
paddle/fluid/platform/device/xpu/xpu2_op_list.h
浏览文件 @
0759e99d
...
...
@@ -380,6 +380,9 @@ XPUOpMap& get_kl2_ops() {
pOpKernelType
(
vartype
::
FP16
,
XPUPlace
())})},
{
"tril_triu"
,
XPUKernelSet
({
pOpKernelType
(
vartype
::
FP32
,
XPUPlace
()),
pOpKernelType
(
vartype
::
INT32
,
XPUPlace
())})},
{
"tril_triu_grad"
,
XPUKernelSet
({
pOpKernelType
(
vartype
::
FP32
,
XPUPlace
()),
pOpKernelType
(
vartype
::
INT32
,
XPUPlace
())})},
{
"tile"
,
XPUKernelSet
({
pOpKernelType
(
vartype
::
INT32
,
XPUPlace
()),
pOpKernelType
(
vartype
::
INT64
,
XPUPlace
()),
pOpKernelType
(
vartype
::
BOOL
,
XPUPlace
()),
...
...
python/paddle/fluid/tests/unittests/xpu/test_tril_triu_op_xpu.py
浏览文件 @
0759e99d
...
...
@@ -42,6 +42,7 @@ class XPUTestTrilTriuOp(XPUOpTestWrapper):
self
.
real_np_op
=
getattr
(
np
,
self
.
real_op_type
)
self
.
set_xpu
()
self
.
op_type
=
"tril_triu"
self
.
place
=
paddle
.
XPUPlace
(
0
)
if
self
.
dtype
==
np
.
int32
:
self
.
X
=
np
.
arange
(
1
,
self
.
get_Xshape_prod
()
+
1
,
...
...
@@ -69,13 +70,22 @@ class XPUTestTrilTriuOp(XPUOpTestWrapper):
def
set_xpu
(
self
):
self
.
__class__
.
use_xpu
=
True
self
.
__class__
.
no_need_check_grad
=
Tru
e
self
.
__class__
.
no_need_check_grad
=
Fals
e
self
.
__class__
.
op_type
=
self
.
real_op_type
def
test_check_output
(
self
):
if
paddle
.
is_compiled_with_xpu
():
place
=
paddle
.
XPUPlace
(
0
)
self
.
check_output_with_place
(
place
)
self
.
check_output_with_place
(
self
.
place
)
def
test_check_grad_normal
(
self
):
if
self
.
dtype
==
np
.
int32
:
user_defined_grad_outputs
=
np
.
random
.
random
(
self
.
Xshape
).
astype
(
'float32'
)
self
.
check_grad_with_place
(
self
.
place
,
[
'X'
],
'Out'
,
user_defined_grad_outputs
=
user_defined_grad_outputs
)
else
:
self
.
check_grad_with_place
(
self
.
place
,
[
'X'
],
'Out'
)
def
initTestCase
(
self
):
self
.
diagonal
=
None
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录