Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
5f84d0b3
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看板
未验证
提交
5f84d0b3
编写于
12月 04, 2020
作者:
L
liym27
提交者:
GitHub
12月 04, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix bug: delete wrong check_type of paddle.concat and support LoDTensorArray (#29306)
上级
f7cdcefa
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
41 addition
and
13 deletion
+41
-13
python/paddle/fluid/layers/tensor.py
python/paddle/fluid/layers/tensor.py
+4
-0
python/paddle/fluid/tests/unittests/test_concat_op.py
python/paddle/fluid/tests/unittests/test_concat_op.py
+36
-11
python/paddle/tensor/manipulation.py
python/paddle/tensor/manipulation.py
+1
-2
未找到文件。
python/paddle/fluid/layers/tensor.py
浏览文件 @
5f84d0b3
...
@@ -327,6 +327,10 @@ def concat(input, axis=0, name=None):
...
@@ -327,6 +327,10 @@ def concat(input, axis=0, name=None):
out
=
helper
.
create_variable_for_type_inference
(
dtype
=
helper
.
input_dtype
())
out
=
helper
.
create_variable_for_type_inference
(
dtype
=
helper
.
input_dtype
())
if
input
[
0
].
desc
.
type
()
==
core
.
VarDesc
.
VarType
.
LOD_TENSOR_ARRAY
:
if
input
[
0
].
desc
.
type
()
==
core
.
VarDesc
.
VarType
.
LOD_TENSOR_ARRAY
:
# NOTE(liym27): Don't remove this if branch!
# This feature is supported for Dynamic-to-Static, because after transformed, the type of inputs[0]
# is LOD_TENSOR_ARRAY in some scenarios. And this feature can be used in static mode.
assert
len
(
input
)
==
1
,
"If the elements of 'input' in concat are Variable(LoDTensorArray), "
\
assert
len
(
input
)
==
1
,
"If the elements of 'input' in concat are Variable(LoDTensorArray), "
\
"number of the elements must be 1, but received %s."
%
len
(
input
)
"number of the elements must be 1, but received %s."
%
len
(
input
)
out_index
=
helper
.
create_variable_for_type_inference
(
dtype
=
"int32"
)
out_index
=
helper
.
create_variable_for_type_inference
(
dtype
=
"int32"
)
...
...
python/paddle/fluid/tests/unittests/test_concat_op.py
浏览文件 @
5f84d0b3
...
@@ -228,6 +228,7 @@ class TestConcatOpError(unittest.TestCase):
...
@@ -228,6 +228,7 @@ class TestConcatOpError(unittest.TestCase):
class
TestConcatAPI
(
unittest
.
TestCase
):
class
TestConcatAPI
(
unittest
.
TestCase
):
def
test_fluid_api
(
self
):
def
test_fluid_api
(
self
):
paddle
.
enable_static
()
x_1
=
fluid
.
data
(
shape
=
[
None
,
1
,
4
,
5
],
dtype
=
'int32'
,
name
=
'x_1'
)
x_1
=
fluid
.
data
(
shape
=
[
None
,
1
,
4
,
5
],
dtype
=
'int32'
,
name
=
'x_1'
)
fluid
.
layers
.
concat
([
x_1
,
x_1
],
0
)
fluid
.
layers
.
concat
([
x_1
,
x_1
],
0
)
...
@@ -253,6 +254,7 @@ class TestConcatAPI(unittest.TestCase):
...
@@ -253,6 +254,7 @@ class TestConcatAPI(unittest.TestCase):
assert
np
.
array_equal
(
res_3
,
np
.
concatenate
((
input_2
,
input_3
),
axis
=
1
))
assert
np
.
array_equal
(
res_3
,
np
.
concatenate
((
input_2
,
input_3
),
axis
=
1
))
def
test_api
(
self
):
def
test_api
(
self
):
paddle
.
enable_static
()
x_1
=
paddle
.
fluid
.
data
(
x_1
=
paddle
.
fluid
.
data
(
shape
=
[
None
,
1
,
4
,
5
],
dtype
=
'int32'
,
name
=
'x_1'
)
shape
=
[
None
,
1
,
4
,
5
],
dtype
=
'int32'
,
name
=
'x_1'
)
paddle
.
concat
([
x_1
,
x_1
],
0
)
paddle
.
concat
([
x_1
,
x_1
],
0
)
...
@@ -338,21 +340,44 @@ class TestConcatAPIWithLoDTensorArray(unittest.TestCase):
...
@@ -338,21 +340,44 @@ class TestConcatAPIWithLoDTensorArray(unittest.TestCase):
self
.
x
=
np
.
random
.
random
(
self
.
input_shape
).
astype
(
"float32"
)
self
.
x
=
np
.
random
.
random
(
self
.
input_shape
).
astype
(
"float32"
)
self
.
place
=
fluid
.
CUDAPlace
(
0
)
\
self
.
place
=
fluid
.
CUDAPlace
(
0
)
\
if
fluid
.
is_compiled_with_cuda
()
else
fluid
.
CPUPlace
()
if
fluid
.
is_compiled_with_cuda
()
else
fluid
.
CPUPlace
()
self
.
set_program
()
def
set_program
(
self
):
def
set_program
(
self
,
use_fluid_api
):
paddle
.
enable_static
()
if
use_fluid_api
:
self
.
program
=
fluid
.
Program
()
self
.
program
=
fluid
.
Program
()
with
fluid
.
program_guard
(
self
.
program
):
with
fluid
.
program_guard
(
self
.
program
):
input
=
fluid
.
layers
.
assign
(
self
.
x
)
input
=
fluid
.
layers
.
assign
(
self
.
x
)
tensor_array
=
fluid
.
layers
.
create_array
(
dtype
=
'float32'
)
tensor_array
=
fluid
.
layers
.
create_array
(
dtype
=
'float32'
)
zero
=
fluid
.
layers
.
fill_constant
(
shape
=
[
1
],
value
=
0
,
dtype
=
"int64"
)
zero
=
fluid
.
layers
.
fill_constant
(
shape
=
[
1
],
value
=
0
,
dtype
=
"int64"
)
for
i
in
range
(
self
.
iter_num
):
for
i
in
range
(
self
.
iter_num
):
fluid
.
layers
.
array_write
(
input
,
zero
+
i
,
tensor_array
)
fluid
.
layers
.
array_write
(
input
,
zero
+
i
,
tensor_array
)
self
.
out_var
=
fluid
.
layers
.
concat
(
tensor_array
,
axis
=
self
.
axis
)
self
.
out_var
=
fluid
.
layers
.
concat
(
tensor_array
,
axis
=
self
.
axis
)
else
:
self
.
program
=
paddle
.
static
.
Program
()
with
paddle
.
static
.
program_guard
(
self
.
program
):
input
=
paddle
.
assign
(
self
.
x
)
tensor_array
=
fluid
.
layers
.
create_array
(
dtype
=
'float32'
)
# Api create_array is not supported in paddle 2.0 yet.
zero
=
paddle
.
zeros
(
shape
=
[
1
],
dtype
=
"int64"
)
for
i
in
range
(
self
.
iter_num
):
# Api array_write is not supported in paddle 2.0 yet.
fluid
.
layers
.
array_write
(
input
,
zero
+
i
,
tensor_array
)
self
.
out_var
=
paddle
.
concat
(
tensor_array
,
axis
=
self
.
axis
)
def
test_fluid_api
(
self
):
self
.
_run_static_mode
(
use_fluid_api
=
True
)
def
test_paddle_api
(
self
):
self
.
_run_static_mode
(
use_fluid_api
=
False
)
def
test_case
(
self
):
def
_run_static_mode
(
self
,
use_fluid_api
):
self
.
set_program
(
use_fluid_api
)
self
.
assertTrue
(
self
.
out_var
.
shape
[
self
.
axis
]
==
-
1
)
self
.
assertTrue
(
self
.
out_var
.
shape
[
self
.
axis
]
==
-
1
)
exe
=
fluid
.
Executor
(
self
.
place
)
exe
=
fluid
.
Executor
(
self
.
place
)
res
=
exe
.
run
(
self
.
program
,
fetch_list
=
self
.
out_var
)
res
=
exe
.
run
(
self
.
program
,
fetch_list
=
self
.
out_var
)
...
...
python/paddle/tensor/manipulation.py
浏览文件 @
5f84d0b3
...
@@ -110,7 +110,6 @@ def concat(x, axis=0, name=None):
...
@@ -110,7 +110,6 @@ def concat(x, axis=0, name=None):
# [11 12 13]
# [11 12 13]
# [14 15 16]]
# [14 15 16]]
"""
"""
check_type
(
x
,
'x'
,
(
list
,
tuple
),
'concat'
)
return
paddle
.
fluid
.
layers
.
concat
(
input
=
x
,
axis
=
axis
,
name
=
name
)
return
paddle
.
fluid
.
layers
.
concat
(
input
=
x
,
axis
=
axis
,
name
=
name
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录