Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
dda6b9d5
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,发现更多精彩内容 >>
未验证
提交
dda6b9d5
编写于
4月 25, 2023
作者:
C
ccrrong
提交者:
GitHub
4月 25, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update tile_grad composite rule (#53261)
上级
be1b3fc3
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
19 addition
and
23 deletion
+19
-23
paddle/fluid/operators/tile_op.cc
paddle/fluid/operators/tile_op.cc
+15
-4
paddle/fluid/prim/api/composite_backward/composite_backward_api.h
...luid/prim/api/composite_backward/composite_backward_api.h
+1
-16
paddle/phi/infermeta/unary.cc
paddle/phi/infermeta/unary.cc
+3
-3
未找到文件。
paddle/fluid/operators/tile_op.cc
浏览文件 @
dda6b9d5
...
...
@@ -171,14 +171,25 @@ class TileCompositeGradOpMaker : public prim::CompositeGradOpMakerBase {
paddle
::
Tensor
x
=
this
->
GetSingleForwardInput
(
"X"
);
paddle
::
Tensor
out_grad
=
this
->
GetSingleOutputGrad
(
"Out"
);
paddle
::
Tensor
x_grad
=
this
->
GetSingleInputGrad
(
"X"
);
paddle
::
optional
<
paddle
::
Tensor
>
tensor_repeat_times
=
this
->
GetOptionalSingleForwardInput
(
"RepeatTimes"
);
paddle
::
optional
<
paddle
::
Tensor
>
tensor_repeat_times_attr
=
this
->
GetOptionalSingleForwardInput
(
"repeat_times_tensor"
);
auto
dx_ptr
=
this
->
GetOutputPtr
(
&
x_grad
);
std
::
string
dx_name
=
this
->
GetOutputName
(
x_grad
);
auto
repeat_times
=
this
->
Attr
<
std
::
vector
<
int
>>
(
"repeat_times"
);
VLOG
(
6
)
<<
"Runing tile_grad composite func"
;
prim
::
tile_grad
<
prim
::
DescTensor
>
(
x
,
out_grad
,
paddle
::
experimental
::
IntArray
(
repeat_times
),
dx_ptr
);
this
->
RecoverOutputName
(
x_grad
,
dx_name
);
if
(
tensor_repeat_times
.
is_initialized
()
||
tensor_repeat_times_attr
.
is_initialized
())
{
PADDLE_THROW
(
platform
::
errors
::
Unimplemented
(
"We don't support RepeatTimes from tensor or repeat_times_tensor for "
"tile composite grad for now. "
));
}
else
{
VLOG
(
6
)
<<
"Runing tile_grad composite func"
;
prim
::
tile_grad
<
prim
::
DescTensor
>
(
x
,
out_grad
,
paddle
::
experimental
::
IntArray
(
repeat_times
),
dx_ptr
);
this
->
RecoverOutputName
(
x_grad
,
dx_name
);
}
}
};
...
...
paddle/fluid/prim/api/composite_backward/composite_backward_api.h
浏览文件 @
dda6b9d5
...
...
@@ -1774,22 +1774,7 @@ void tile_grad(const Tensor& x,
if
(
x_grad
)
{
auto
repeat_times_data
=
repeat_times
.
GetData
();
auto
out_grad_shape
=
phi
::
vectorize
<
int
>
(
out_grad
.
dims
());
auto
x_shape
=
phi
::
vectorize
<
int
>
(
x
.
dims
());
if
(
repeat_times_data
.
size
()
<
x_shape
.
size
())
{
int
diff
=
x_shape
.
size
()
-
repeat_times_data
.
size
();
repeat_times_data
.
insert
(
repeat_times_data
.
begin
(),
diff
,
1
);
}
else
{
int
diff
=
repeat_times_data
.
size
()
-
x_shape
.
size
();
x_shape
.
insert
(
x_shape
.
begin
(),
diff
,
1
);
}
for
(
int
i
=
0
;
i
<
static_cast
<
int
>
(
out_grad_shape
.
size
());
i
++
)
{
if
(
out_grad_shape
[
i
]
==
-
1
)
{
out_grad_shape
[
i
]
=
x_shape
[
i
]
*
repeat_times_data
[
i
];
}
}
auto
result
=
reshape
<
T
>
(
out_grad
,
out_grad_shape
);
auto
result
=
out_grad
;
for
(
int
i
=
0
;
i
<
static_cast
<
int
>
(
repeat_times_data
.
size
());
i
++
)
{
int
size
=
out_grad_shape
[
i
]
/
repeat_times_data
[
i
];
std
::
vector
<
int
>
sections
(
repeat_times_data
[
i
],
size
);
...
...
paddle/phi/infermeta/unary.cc
浏览文件 @
dda6b9d5
...
...
@@ -4220,7 +4220,7 @@ void TileInferMeta(const MetaTensor& x,
auto
repeat_times_data
=
repeat_times
.
GetData
();
auto
x_dims
=
x
.
dims
();
if
(
repeat_times_data
.
size
()
==
0
)
{
repeat_times_data
=
std
::
vector
<
int64_t
>
(
x_dims
.
size
(),
-
1
);
repeat_times_data
=
std
::
vector
<
int64_t
>
(
x_dims
.
size
(),
1
);
}
PADDLE_ENFORCE_LE
(
...
...
@@ -4253,10 +4253,10 @@ void TileInferMeta(const MetaTensor& x,
auto
x_dim_vec
=
phi
::
vectorize
<
int
>
(
x_dims
);
if
(
x_dim_vec
.
size
()
>
repeat_times_data
.
size
())
{
auto
diff
=
x_dim_vec
.
size
()
-
repeat_times_data
.
size
();
repeat_times_data
.
insert
(
repeat_times_data
.
begin
(),
diff
,
-
1
);
repeat_times_data
.
insert
(
repeat_times_data
.
begin
(),
diff
,
1
);
}
else
{
auto
diff
=
repeat_times_data
.
size
()
-
x_dim_vec
.
size
();
x_dim_vec
.
insert
(
x_dim_vec
.
begin
(),
diff
,
-
1
);
x_dim_vec
.
insert
(
x_dim_vec
.
begin
(),
diff
,
1
);
}
for
(
size_t
i
=
0
;
i
<
repeat_times_data
.
size
();
++
i
)
{
if
(
x_dim_vec
[
i
]
==
-
1
||
repeat_times_data
[
i
]
==
-
1
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录