Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
1dc1f927
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
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看板
未验证
提交
1dc1f927
编写于
3月 17, 2020
作者:
G
GaoWei8
提交者:
GitHub
3月 17, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix lod error of concat op for axis = 0 (#22538)
上级
660ff184
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
65 addition
and
2 deletion
+65
-2
paddle/fluid/operators/concat_op.h
paddle/fluid/operators/concat_op.h
+28
-2
python/paddle/fluid/tests/unittests/test_concat_op.py
python/paddle/fluid/tests/unittests/test_concat_op.py
+37
-0
未找到文件。
paddle/fluid/operators/concat_op.h
浏览文件 @
1dc1f927
...
...
@@ -76,8 +76,8 @@ template <typename DeviceContext, typename T>
class
ConcatKernel
:
public
framework
::
OpKernel
<
T
>
{
public:
void
Compute
(
const
framework
::
ExecutionContext
&
ctx
)
const
override
{
auto
ins
=
ctx
.
MultiInput
<
framework
::
Tensor
>
(
"X"
);
framework
::
Tensor
*
out
=
ctx
.
Output
<
framework
::
Tensor
>
(
"Out"
);
auto
ins
=
ctx
.
MultiInput
<
framework
::
LoD
Tensor
>
(
"X"
);
framework
::
LoDTensor
*
out
=
ctx
.
Output
<
framework
::
LoD
Tensor
>
(
"Out"
);
PADDLE_ENFORCE_EQ
(
ins
[
0
]
!=
nullptr
,
true
,
"The input should not be null."
);
auto
axis
=
ctx
.
Attr
<
int
>
(
"axis"
);
bool
need_resize_out_dims
=
false
;
...
...
@@ -102,6 +102,32 @@ class ConcatKernel : public framework::OpKernel<T> {
auto
place
=
ctx
.
GetPlace
();
out
->
mutable_data
<
T
>
(
place
);
// If axis is 0, the lod of the output is not the same as inputs.
if
(
axis
==
0
&&
ins
[
0
]
->
lod
().
size
()
>
0
)
{
size_t
lod_size_0
=
ins
[
0
]
->
lod
().
size
();
size_t
lod_size
=
lod_size_0
;
for
(
size_t
i
=
1
;
i
<
ins
.
size
();
++
i
)
{
if
(
ins
[
i
]
->
lod
().
size
()
>
0
)
{
PADDLE_ENFORCE_EQ
(
ins
[
i
]
->
lod
().
size
(),
lod_size_0
,
platform
::
errors
::
Unimplemented
(
"The lod level of all input LoDTensors should be same. "
"Maybe different lod level of input LoDTensors can concat,"
" it is not supported currently."
));
}
else
{
lod_size
=
0
;
break
;
}
}
if
(
lod_size
)
{
auto
*
out_lod
=
out
->
mutable_lod
();
for
(
size_t
i
=
1
;
i
<
ins
.
size
();
++
i
)
{
auto
in_lod
=
ConvertToLengthBasedLoD
(
ins
[
i
]
->
lod
());
AppendLoD
(
out_lod
,
in_lod
);
}
}
}
// Sometimes direct copies will be faster, this maybe need deeply analysis.
if
(
axis
==
0
&&
ins
.
size
()
<
10
)
{
size_t
output_offset
=
0
;
...
...
python/paddle/fluid/tests/unittests/test_concat_op.py
浏览文件 @
1dc1f927
...
...
@@ -100,6 +100,41 @@ class TestConcatOp5(TestConcatOp):
self
.
axis
=
-
3
class
TestConcatOp6
(
TestConcatOp
):
def
setUp
(
self
):
self
.
op_type
=
"concat"
self
.
dtype
=
self
.
get_dtype
()
self
.
init_test_data
()
self
.
lod
=
[[
20
,
80
]]
self
.
out_lod
=
[[
20
,
80
,
20
,
80
,
20
,
80
]]
self
.
inputs
=
{
'X'
:
[(
'x0'
,
(
self
.
x0
,
self
.
lod
)),
(
'x1'
,
(
self
.
x1
,
self
.
lod
)),
(
'x2'
,
(
self
.
x2
,
self
.
lod
))]
}
self
.
attrs
=
{
'axis'
:
self
.
axis
}
if
self
.
axis
<
0
:
self
.
actual_axis
=
self
.
axis
+
len
(
self
.
x0
.
shape
)
self
.
actual_axis
=
self
.
actual_axis
if
self
.
actual_axis
>
0
else
0
else
:
self
.
actual_axis
=
self
.
axis
out
=
np
.
concatenate
((
self
.
x0
,
self
.
x1
,
self
.
x2
),
axis
=
self
.
actual_axis
)
self
.
outputs
=
{
'Out'
:
(
out
,
self
.
out_lod
)}
def
test_check_output
(
self
):
self
.
check_output
(
check_dygraph
=
False
)
def
test_check_grad
(
self
):
self
.
check_grad
([
'x0'
],
'Out'
,
check_dygraph
=
False
)
self
.
check_grad
([
'x1'
],
'Out'
,
check_dygraph
=
False
)
self
.
check_grad
([
'x2'
],
'Out'
,
check_dygraph
=
False
)
def
init_test_data
(
self
):
self
.
x0
=
np
.
random
.
random
([
100
]).
astype
(
self
.
dtype
)
self
.
x1
=
np
.
random
.
random
([
100
]).
astype
(
self
.
dtype
)
self
.
x2
=
np
.
random
.
random
([
100
]).
astype
(
self
.
dtype
)
self
.
axis
=
0
def
create_test_AxisTensor
(
parent
):
class
TestConcatAxisTensor
(
parent
):
def
setUp
(
self
):
...
...
@@ -134,6 +169,7 @@ create_test_AxisTensor(TestConcatOp2)
create_test_AxisTensor
(
TestConcatOp3
)
create_test_AxisTensor
(
TestConcatOp4
)
create_test_AxisTensor
(
TestConcatOp5
)
create_test_AxisTensor
(
TestConcatOp6
)
#----------------Concat Fp16----------------
...
...
@@ -155,6 +191,7 @@ create_test_fp16(TestConcatOp2)
create_test_fp16
(
TestConcatOp3
)
create_test_fp16
(
TestConcatOp4
)
create_test_fp16
(
TestConcatOp5
)
create_test_fp16
(
TestConcatOp6
)
class
TestConcatOpError
(
unittest
.
TestCase
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录