Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
s920243400
PaddleDetection
提交
6776e928
P
PaddleDetection
项目概览
s920243400
/
PaddleDetection
与 Fork 源项目一致
Fork自
PaddlePaddle / PaddleDetection
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
6776e928
编写于
11月 28, 2018
作者:
C
chengduo
提交者:
GitHub
11月 28, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refine tensor_array_write_read (#14643)
test=develop
上级
dfd4a111
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
57 addition
and
2 deletion
+57
-2
paddle/fluid/framework/op_desc.cc
paddle/fluid/framework/op_desc.cc
+24
-2
paddle/fluid/framework/operator.cc
paddle/fluid/framework/operator.cc
+5
-0
paddle/fluid/framework/shape_inference.h
paddle/fluid/framework/shape_inference.h
+3
-0
paddle/fluid/operators/controlflow/tensor_array_read_write_op.cc
...fluid/operators/controlflow/tensor_array_read_write_op.cc
+13
-0
paddle/fluid/operators/lod_tensor_to_array_op.cc
paddle/fluid/operators/lod_tensor_to_array_op.cc
+4
-0
paddle/fluid/operators/reorder_lod_tensor_by_rank_op.cc
paddle/fluid/operators/reorder_lod_tensor_by_rank_op.cc
+3
-0
paddle/fluid/operators/shrink_rnn_memory_op.cc
paddle/fluid/operators/shrink_rnn_memory_op.cc
+3
-0
python/paddle/fluid/tests/unittests/test_dyn_rnn.py
python/paddle/fluid/tests/unittests/test_dyn_rnn.py
+2
-0
未找到文件。
paddle/fluid/framework/op_desc.cc
浏览文件 @
6776e928
...
...
@@ -81,13 +81,35 @@ class CompileTimeInferShapeContext : public InferShapeContext {
"The %s[%d] is @EMPTY@"
,
out
,
j
);
auto
*
in_var
=
block_
.
FindVarRecursive
(
Inputs
(
in
)[
i
]);
auto
*
out_var
=
block_
.
FindVarRecursive
(
Outputs
(
out
)[
j
]);
if
(
in_var
->
GetType
()
!=
proto
::
VarType
::
LOD_TENSOR
)
{
VLOG
(
3
)
<<
"input "
<<
in
<<
" is not LodTensor"
;
if
(
in_var
->
GetType
()
!=
proto
::
VarType
::
LOD_TENSOR
&&
in_var
->
GetType
()
!=
proto
::
VarType
::
LOD_TENSOR_ARRAY
)
{
VLOG
(
3
)
<<
"input "
<<
in
<<
" is not LodTensor or LodTensorArray."
;
return
;
}
out_var
->
SetLoDLevel
(
in_var
->
GetLoDLevel
());
}
void
DecreaseLoDLevel
(
const
std
::
string
&
in
,
const
std
::
string
&
out
,
size_t
i
=
0
,
size_t
j
=
0
)
const
override
{
PADDLE_ENFORCE_LT
(
i
,
Inputs
(
in
).
size
());
PADDLE_ENFORCE_LT
(
j
,
Outputs
(
out
).
size
());
PADDLE_ENFORCE
(
Inputs
(
in
)[
i
]
!=
framework
::
kEmptyVarName
,
"The %s[%d] is @EMPTY@"
,
in
,
i
);
PADDLE_ENFORCE
(
Outputs
(
out
)[
j
]
!=
framework
::
kEmptyVarName
,
"The %s[%d] is @EMPTY@"
,
out
,
j
);
auto
*
in_var
=
block_
.
FindVarRecursive
(
Inputs
(
in
)[
i
]);
auto
*
out_var
=
block_
.
FindVarRecursive
(
Outputs
(
out
)[
j
]);
PADDLE_ENFORCE
(
out_var
->
GetType
()
==
proto
::
VarType
::
LOD_TENSOR_ARRAY
||
out_var
->
GetType
()
==
proto
::
VarType
::
LOD_TENSOR
,
"The input %s should be LodTensorArray or LodTensor."
,
out_var
->
Name
());
PADDLE_ENFORCE
(
in_var
->
GetType
()
==
proto
::
VarType
::
LOD_TENSOR
,
"The input %s should be LodTensor."
,
in_var
->
Name
());
if
(
in_var
->
GetLoDLevel
()
>
0
)
{
out_var
->
SetLoDLevel
(
in_var
->
GetLoDLevel
()
-
1
);
}
}
bool
IsRuntime
()
const
override
;
protected:
...
...
paddle/fluid/framework/operator.cc
浏览文件 @
6776e928
...
...
@@ -623,6 +623,11 @@ class RuntimeInferShapeContext : public InferShapeContext {
out_tensor
->
set_layout
(
in_tensor
.
layout
());
}
void
DecreaseLoDLevel
(
const
std
::
string
&
in
,
const
std
::
string
&
out
,
size_t
i
=
0
,
size_t
j
=
0
)
const
override
{
PADDLE_THROW
(
"DecreaseLoDLevel is only used in compile time."
);
}
bool
IsRuntime
()
const
override
{
return
true
;
}
protected:
...
...
paddle/fluid/framework/shape_inference.h
浏览文件 @
6776e928
...
...
@@ -62,6 +62,9 @@ class InferShapeContext {
virtual
void
ShareLoD
(
const
std
::
string
&
in
,
const
std
::
string
&
out
,
size_t
i
=
0
,
size_t
j
=
0
)
const
=
0
;
virtual
void
DecreaseLoDLevel
(
const
std
::
string
&
in
,
const
std
::
string
&
out
,
size_t
i
=
0
,
size_t
j
=
0
)
const
=
0
;
virtual
bool
IsRuntime
()
const
=
0
;
std
::
vector
<
InferShapeVarPtr
>
GetInputVarPtrs
(
const
std
::
string
&
name
);
...
...
paddle/fluid/operators/controlflow/tensor_array_read_write_op.cc
浏览文件 @
6776e928
...
...
@@ -167,6 +167,19 @@ $$T = A[i]$$
};
class
ReadFromArrayInferShape
:
public
WriteToArrayInferShape
{
public:
void
operator
()(
framework
::
InferShapeContext
*
context
)
const
override
{
WriteToArrayInferShape
::
operator
()(
context
);
if
(
!
context
->
HasInput
(
"X"
))
{
return
;
}
// FIXME: just for compile time.
if
(
!
context
->
IsRuntime
())
{
context
->
ShareLoD
(
"X"
,
/*->*/
"Out"
);
}
}
protected:
const
char
*
NotHasXError
()
const
override
{
return
"The input array X must be set"
;
...
...
paddle/fluid/operators/lod_tensor_to_array_op.cc
浏览文件 @
6776e928
...
...
@@ -192,6 +192,10 @@ class LoDTensorToArrayInferShape : public framework::InferShapeBase {
// The first dim of each LoDTensor in Output can only be set at run-time.;
// We still have to Resize each LoDTensor in Output.
context
->
SetOutputDim
(
"Out"
,
x_dim
);
// The lod level should be passed to out in compile time.
if
(
!
context
->
IsRuntime
())
{
context
->
DecreaseLoDLevel
(
"X"
,
/*->*/
"Out"
);
}
}
};
...
...
paddle/fluid/operators/reorder_lod_tensor_by_rank_op.cc
浏览文件 @
6776e928
...
...
@@ -201,6 +201,9 @@ class IdentityInferShape : public framework::InferShapeBase {
public:
void
operator
()(
framework
::
InferShapeContext
*
context
)
const
override
{
context
->
SetOutputDim
(
"Out"
,
context
->
GetInputDim
(
"X"
));
if
(
!
context
->
IsRuntime
())
{
context
->
ShareLoD
(
"X"
,
/*->*/
"Out"
);
}
}
};
...
...
paddle/fluid/operators/shrink_rnn_memory_op.cc
浏览文件 @
6776e928
...
...
@@ -100,6 +100,9 @@ class ShrinkRNNMemoryInferShape : public framework::InferShapeBase {
PADDLE_ENFORCE
(
context
->
HasInput
(
"I"
));
PADDLE_ENFORCE
(
context
->
HasInput
(
"RankTable"
));
context
->
SetOutputDim
(
"Out"
,
context
->
GetInputDim
(
"X"
));
if
(
!
context
->
IsRuntime
())
{
context
->
DecreaseLoDLevel
(
"X"
,
/*->*/
"Out"
);
}
}
};
...
...
python/paddle/fluid/tests/unittests/test_dyn_rnn.py
浏览文件 @
6776e928
...
...
@@ -172,6 +172,7 @@ class TestDynRNN(unittest.TestCase):
rnn
=
fluid
.
layers
.
DynamicRNN
()
with
rnn
.
block
():
in_
=
rnn
.
step_input
(
sentence
)
assert
in_
.
lod_level
==
1
,
"the lod level of in_ should be 1"
sent_emb
=
fluid
.
layers
.
embedding
(
input
=
in_
,
size
=
[
len
(
word_dict
),
32
],
dtype
=
'float32'
)
out_
=
fluid
.
layers
.
fc
(
input
=
sent_emb
,
size
=
100
,
act
=
'tanh'
)
...
...
@@ -179,6 +180,7 @@ class TestDynRNN(unittest.TestCase):
rnn1
=
fluid
.
layers
.
DynamicRNN
()
with
rnn1
.
block
():
in_1
=
rnn1
.
step_input
(
out_
)
assert
in_1
.
lod_level
==
0
,
"the lod level of in_1 should be 0"
out_1
=
fluid
.
layers
.
fc
(
input
=
[
in_1
],
size
=
100
,
act
=
'tanh'
)
rnn1
.
output
(
out_1
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录