Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
13a22a37
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看板
未验证
提交
13a22a37
编写于
12月 02, 2020
作者:
L
Leo Chen
提交者:
GitHub
12月 02, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix shape of tile_grad op (#29289)
上级
be3777a5
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
11 addition
and
7 deletion
+11
-7
paddle/fluid/operators/tile_op.cc
paddle/fluid/operators/tile_op.cc
+1
-0
paddle/fluid/operators/tile_op.h
paddle/fluid/operators/tile_op.h
+10
-7
未找到文件。
paddle/fluid/operators/tile_op.cc
浏览文件 @
13a22a37
...
@@ -167,6 +167,7 @@ class TileGradOp : public framework::OperatorWithKernel {
...
@@ -167,6 +167,7 @@ class TileGradOp : public framework::OperatorWithKernel {
framework
::
GradVarName
(
"Out"
),
"TileGrad"
);
framework
::
GradVarName
(
"Out"
),
"TileGrad"
);
auto
x_dims
=
ctx
->
GetInputDim
(
"X"
);
auto
x_dims
=
ctx
->
GetInputDim
(
"X"
);
std
::
vector
<
int
>
repeat_times
=
std
::
vector
<
int
>
repeat_times
=
ctx
->
Attrs
().
Get
<
std
::
vector
<
int
>>
(
"repeat_times"
);
ctx
->
Attrs
().
Get
<
std
::
vector
<
int
>>
(
"repeat_times"
);
if
(
repeat_times
.
size
()
==
0
)
{
if
(
repeat_times
.
size
()
==
0
)
{
...
...
paddle/fluid/operators/tile_op.h
浏览文件 @
13a22a37
...
@@ -186,9 +186,9 @@ template <typename DeviceContext, typename T>
...
@@ -186,9 +186,9 @@ template <typename DeviceContext, typename T>
class
TileGradKernel
:
public
framework
::
OpKernel
<
T
>
{
class
TileGradKernel
:
public
framework
::
OpKernel
<
T
>
{
public:
public:
void
Compute
(
const
framework
::
ExecutionContext
&
context
)
const
override
{
void
Compute
(
const
framework
::
ExecutionContext
&
context
)
const
override
{
auto
*
in0
=
context
.
Input
<
Tensor
>
(
"X"
);
auto
*
x
=
context
.
Input
<
Tensor
>
(
"X"
);
auto
repeat_times
=
get_repeat_times
(
context
);
auto
repeat_times
=
get_repeat_times
(
context
);
auto
x_dims
=
in0
->
dims
();
auto
x_dims
=
x
->
dims
();
auto
vec_in_dims
=
framework
::
vectorize
<
int
>
(
x_dims
);
auto
vec_in_dims
=
framework
::
vectorize
<
int
>
(
x_dims
);
if
(
repeat_times
.
size
()
<
vec_in_dims
.
size
())
{
if
(
repeat_times
.
size
()
<
vec_in_dims
.
size
())
{
int
diff
=
vec_in_dims
.
size
()
-
repeat_times
.
size
();
int
diff
=
vec_in_dims
.
size
()
-
repeat_times
.
size
();
...
@@ -220,11 +220,13 @@ class TileGradKernel : public framework::OpKernel<T> {
...
@@ -220,11 +220,13 @@ class TileGradKernel : public framework::OpKernel<T> {
}
}
// no need reduce, just copy
// no need reduce, just copy
if
(
just_copy
)
{
if
(
just_copy
)
{
auto
*
in0
=
context
.
Input
<
Tensor
>
(
framework
::
GradVarName
(
"Out"
));
auto
*
dout
=
context
.
Input
<
Tensor
>
(
framework
::
GradVarName
(
"Out"
));
auto
*
out0
=
context
.
Output
<
Tensor
>
(
framework
::
GradVarName
(
"X"
));
auto
*
dx
=
context
.
Output
<
Tensor
>
(
framework
::
GradVarName
(
"X"
));
out0
->
mutable_data
<
T
>
(
context
.
GetPlace
());
dx
->
mutable_data
<
T
>
(
context
.
GetPlace
());
framework
::
TensorCopy
(
*
in0
,
context
.
GetPlace
(),
context
.
device_context
(),
framework
::
TensorCopy
(
*
dout
,
context
.
GetPlace
(),
context
.
device_context
(),
out0
);
dx
);
// TensorCopy may change the dims of dx
dx
->
Resize
(
x_dims
);
}
else
{
}
else
{
PADDLE_ENFORCE_GE
(
dims
,
1
,
PADDLE_ENFORCE_GE
(
dims
,
1
,
platform
::
errors
::
InvalidArgument
(
platform
::
errors
::
InvalidArgument
(
...
@@ -261,6 +263,7 @@ class TileGradKernel : public framework::OpKernel<T> {
...
@@ -261,6 +263,7 @@ class TileGradKernel : public framework::OpKernel<T> {
for
(
size_t
i
=
0
;
i
<
reduce_size
;
++
i
)
{
for
(
size_t
i
=
0
;
i
<
reduce_size
;
++
i
)
{
reduce_dims
[
i
]
=
reduce_dims_vec
[
i
];
reduce_dims
[
i
]
=
reduce_dims_vec
[
i
];
}
}
auto
out_grad
=
EigenVector
<
T
>::
Flatten
(
*
in0
);
auto
out_grad
=
EigenVector
<
T
>::
Flatten
(
*
in0
);
x_grad
.
device
(
x_grad
.
device
(
*
context
.
template
device_context
<
DeviceContext
>().
eigen_device
())
=
*
context
.
template
device_context
<
DeviceContext
>().
eigen_device
())
=
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录