Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
5e722245
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2299
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看板
未验证
提交
5e722245
编写于
1月 13, 2023
作者:
L
Leo Guo
提交者:
GitHub
1月 13, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add unitest for set_value, set_value_grad. test=kunlun (#49773)
上级
5fd115f3
变更
3
展开全部
隐藏空白更改
内联
并排
Showing
3 changed file
with
876 addition
and
16 deletion
+876
-16
paddle/phi/kernels/xpu/set_value_grad_kernel.cc
paddle/phi/kernels/xpu/set_value_grad_kernel.cc
+7
-1
paddle/phi/kernels/xpu/set_value_kernel.cc
paddle/phi/kernels/xpu/set_value_kernel.cc
+8
-4
python/paddle/fluid/tests/unittests/xpu/test_set_value_op_xpu.py
...paddle/fluid/tests/unittests/xpu/test_set_value_op_xpu.py
+861
-11
未找到文件。
paddle/phi/kernels/xpu/set_value_grad_kernel.cc
浏览文件 @
5e722245
...
@@ -143,7 +143,13 @@ void SetValueGradImpl(const Context& dev_ctx,
...
@@ -143,7 +143,13 @@ void SetValueGradImpl(const Context& dev_ctx,
if
(
x_grad
)
{
if
(
x_grad
)
{
// Set gradient of `Input`
// Set gradient of `Input`
Copy
(
dev_ctx
,
out_grad
,
dev_ctx
.
GetPlace
(),
false
,
x_grad
);
x_grad
->
Resize
(
out_grad
.
dims
());
dev_ctx
.
template
Alloc
<
T
>(
x_grad
);
r
=
xpu
::
copy
(
dev_ctx
.
x_context
(),
reinterpret_cast
<
const
XPUType
*>
(
out_grad
.
data
<
T
>
()),
reinterpret_cast
<
XPUType
*>
(
x_grad
->
data
<
T
>
()),
out_grad
.
numel
());
PADDLE_ENFORCE_XDNN_SUCCESS
(
r
,
"copy"
);
DenseTensor
tmp
=
Full
<
T
>
(
dev_ctx
,
out_dims_vector
,
static_cast
<
T
>
(
0
));
DenseTensor
tmp
=
Full
<
T
>
(
dev_ctx
,
out_dims_vector
,
static_cast
<
T
>
(
0
));
...
...
paddle/phi/kernels/xpu/set_value_kernel.cc
浏览文件 @
5e722245
...
@@ -119,8 +119,6 @@ void SetValueImpl(const Context& dev_ctx,
...
@@ -119,8 +119,6 @@ void SetValueImpl(const Context& dev_ctx,
slice_dims_for_assign
=
phi
::
make_ddim
(
slice_dims_with_none
);
slice_dims_for_assign
=
phi
::
make_ddim
(
slice_dims_with_none
);
}
}
auto
place
=
dev_ctx
.
GetPlace
();
// Here copy data from input to avoid data loss at PE and Graph level.
// Here copy data from input to avoid data loss at PE and Graph level.
// TODO(liym27): Speed up in the future version.
// TODO(liym27): Speed up in the future version.
// - Q: Why don't call ShareDataWith to speed up?
// - Q: Why don't call ShareDataWith to speed up?
...
@@ -132,7 +130,14 @@ void SetValueImpl(const Context& dev_ctx,
...
@@ -132,7 +130,14 @@ void SetValueImpl(const Context& dev_ctx,
// be two ops points to the output in graph: op1 -> output <- set_value.
// be two ops points to the output in graph: op1 -> output <- set_value.
// In this case, we have to find a way to handle the running order of
// In this case, we have to find a way to handle the running order of
// set_value is what we want.
// set_value is what we want.
Copy
(
dev_ctx
,
in
,
place
,
false
,
out
);
int
r
=
XPU_SUCCESS
;
out
->
Resize
(
in
.
dims
());
dev_ctx
.
template
Alloc
<
T
>(
out
);
r
=
xpu
::
copy
(
dev_ctx
.
x_context
(),
reinterpret_cast
<
const
XPUType
*>
(
in
.
data
<
T
>
()),
reinterpret_cast
<
XPUType
*>
(
out
->
data
<
T
>
()),
in
.
numel
());
PADDLE_ENFORCE_XDNN_SUCCESS
(
r
,
"copy"
);
DenseTensor
slice_tensor
=
DenseTensor
slice_tensor
=
Empty
<
T
>
(
dev_ctx
,
IntArray
{
slice_dims
.
Get
(),
slice_dims
.
size
()});
Empty
<
T
>
(
dev_ctx
,
IntArray
{
slice_dims
.
Get
(),
slice_dims
.
size
()});
...
@@ -179,7 +184,6 @@ void SetValueImpl(const Context& dev_ctx,
...
@@ -179,7 +184,6 @@ void SetValueImpl(const Context& dev_ctx,
auto
out_shape
=
phi
::
vectorize
<
int
>
(
out
->
dims
());
auto
out_shape
=
phi
::
vectorize
<
int
>
(
out
->
dims
());
auto
slice_shape
=
phi
::
vectorize
<
int
>
(
slice_dims
);
auto
slice_shape
=
phi
::
vectorize
<
int
>
(
slice_dims
);
int
r
=
XPU_SUCCESS
;
r
=
xpu
::
strided_slice
(
dev_ctx
.
x_context
(),
r
=
xpu
::
strided_slice
(
dev_ctx
.
x_context
(),
reinterpret_cast
<
const
XPUType
*>
(
out
->
data
<
T
>
()),
reinterpret_cast
<
const
XPUType
*>
(
out
->
data
<
T
>
()),
reinterpret_cast
<
XPUType
*>
(
slice_tensor
.
data
<
T
>
()),
reinterpret_cast
<
XPUType
*>
(
slice_tensor
.
data
<
T
>
()),
...
...
python/paddle/fluid/tests/unittests/xpu/test_set_value_op_xpu.py
浏览文件 @
5e722245
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录