Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
4267a81a
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看板
未验证
提交
4267a81a
编写于
4月 13, 2019
作者:
Y
Yibing Liu
提交者:
GitHub
4月 13, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Correct the lod level of compiled time in lod_reset (#16790)
test=develop
上级
1b750494
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
39 addition
and
7 deletion
+39
-7
paddle/fluid/framework/var_type_inference.h
paddle/fluid/framework/var_type_inference.h
+6
-2
paddle/fluid/operators/lod_reset_op.cc
paddle/fluid/operators/lod_reset_op.cc
+21
-3
paddle/fluid/operators/lod_reset_op.h
paddle/fluid/operators/lod_reset_op.h
+1
-1
python/paddle/fluid/tests/unittests/test_layers.py
python/paddle/fluid/tests/unittests/test_layers.py
+11
-1
未找到文件。
paddle/fluid/framework/var_type_inference.h
浏览文件 @
4267a81a
...
@@ -45,12 +45,16 @@ class InferVarTypeContext {
...
@@ -45,12 +45,16 @@ class InferVarTypeContext {
virtual
bool
HasInput
(
const
std
::
string
&
name
)
const
{
virtual
bool
HasInput
(
const
std
::
string
&
name
)
const
{
PADDLE_ENFORCE_NOT_NULL
(
op_
);
PADDLE_ENFORCE_NOT_NULL
(
op_
);
return
op_
->
Inputs
().
count
(
name
)
>
0
;
auto
&
inputs
=
op_
->
Inputs
();
auto
input
=
inputs
.
find
(
name
);
return
input
!=
inputs
.
end
()
&&
!
input
->
second
.
empty
();
}
}
virtual
bool
HasOutput
(
const
std
::
string
&
name
)
const
{
virtual
bool
HasOutput
(
const
std
::
string
&
name
)
const
{
PADDLE_ENFORCE_NOT_NULL
(
op_
);
PADDLE_ENFORCE_NOT_NULL
(
op_
);
return
op_
->
Outputs
().
count
(
name
)
>
0
;
auto
&
outputs
=
op_
->
Outputs
();
auto
output
=
outputs
.
find
(
name
);
return
output
!=
outputs
.
end
()
&&
!
output
->
second
.
empty
();
}
}
virtual
const
std
::
vector
<
std
::
string
>&
Input
(
const
std
::
string
&
name
)
const
{
virtual
const
std
::
vector
<
std
::
string
>&
Input
(
const
std
::
string
&
name
)
const
{
...
...
paddle/fluid/operators/lod_reset_op.cc
浏览文件 @
4267a81a
...
@@ -30,10 +30,10 @@ class LoDResetOp : public framework::OperatorWithKernel {
...
@@ -30,10 +30,10 @@ class LoDResetOp : public framework::OperatorWithKernel {
if
(
!
ctx
->
HasInput
(
"Y"
))
{
if
(
!
ctx
->
HasInput
(
"Y"
))
{
auto
level0
=
ctx
->
Attrs
().
Get
<
std
::
vector
<
int
>>
(
"target_lod"
);
auto
level0
=
ctx
->
Attrs
().
Get
<
std
::
vector
<
int
>>
(
"target_lod"
);
PADDLE_ENFORCE_GT
(
level0
.
size
(),
1
,
PADDLE_ENFORCE_GT
(
level0
.
size
(),
0
,
"If Input(Y) not provided, the target lod should be "
"If Input(Y) not provided, the target lod should be "
"specified by attribute `target_lod`."
);
"specified by attribute `target_lod`."
);
}
else
{
}
else
if
(
ctx
->
IsRuntime
())
{
ctx
->
ShareLoD
(
"Y"
,
"Out"
);
ctx
->
ShareLoD
(
"Y"
,
"Out"
);
}
}
...
@@ -48,6 +48,23 @@ class LoDResetOp : public framework::OperatorWithKernel {
...
@@ -48,6 +48,23 @@ class LoDResetOp : public framework::OperatorWithKernel {
}
}
};
};
class
LoDResetOpVarTypeInference
:
public
framework
::
VarTypeInference
{
public:
void
operator
()(
framework
::
InferVarTypeContext
*
ctx
)
const
override
{
auto
x_var_name
=
ctx
->
Input
(
"X"
).
front
();
auto
out_var_name
=
ctx
->
Output
(
"Out"
).
front
();
if
(
ctx
->
HasInput
(
"Y"
))
{
auto
y_var_name
=
ctx
->
Input
(
"Y"
).
front
();
auto
y_lod_level
=
std
::
max
(
ctx
->
GetLoDLevel
(
y_var_name
),
1
);
ctx
->
SetLoDLevel
(
out_var_name
,
y_lod_level
);
}
else
{
ctx
->
SetLoDLevel
(
out_var_name
,
1
);
}
ctx
->
SetDataType
(
out_var_name
,
ctx
->
GetDataType
(
x_var_name
));
ctx
->
SetType
(
out_var_name
,
paddle
::
framework
::
proto
::
VarType
::
LOD_TENSOR
);
}
};
class
LoDResetOpMaker
:
public
framework
::
OpProtoAndCheckerMaker
{
class
LoDResetOpMaker
:
public
framework
::
OpProtoAndCheckerMaker
{
public:
public:
void
Make
()
override
{
void
Make
()
override
{
...
@@ -177,9 +194,10 @@ DECLARE_NO_NEED_BUFFER_VARS_INFERENCE(LoDResetGradNoNeedBufferVarInference,
...
@@ -177,9 +194,10 @@ DECLARE_NO_NEED_BUFFER_VARS_INFERENCE(LoDResetGradNoNeedBufferVarInference,
namespace
ops
=
paddle
::
operators
;
namespace
ops
=
paddle
::
operators
;
REGISTER_OPERATOR
(
lod_reset
,
ops
::
LoDResetOp
,
ops
::
LoDResetOpMaker
,
REGISTER_OPERATOR
(
lod_reset
,
ops
::
LoDResetOp
,
ops
::
LoDResetOpMaker
,
ops
::
LoDResetGradDescMaker
);
ops
::
LoDResetGradDescMaker
,
ops
::
LoDResetOpVarTypeInference
);
REGISTER_OPERATOR
(
lod_reset_grad
,
ops
::
LoDResetGradOp
,
REGISTER_OPERATOR
(
lod_reset_grad
,
ops
::
LoDResetGradOp
,
ops
::
LoDResetGradNoNeedBufferVarInference
);
ops
::
LoDResetGradNoNeedBufferVarInference
);
REGISTER_OP_CPU_KERNEL
(
REGISTER_OP_CPU_KERNEL
(
lod_reset
,
ops
::
LoDResetKernel
<
paddle
::
platform
::
CPUPlace
,
float
>
,
lod_reset
,
ops
::
LoDResetKernel
<
paddle
::
platform
::
CPUPlace
,
float
>
,
ops
::
LoDResetKernel
<
paddle
::
platform
::
CPUPlace
,
double
>
,
ops
::
LoDResetKernel
<
paddle
::
platform
::
CPUPlace
,
double
>
,
...
...
paddle/fluid/operators/lod_reset_op.h
浏览文件 @
4267a81a
...
@@ -63,7 +63,7 @@ class LoDResetKernel : public framework::OpKernel<T> {
...
@@ -63,7 +63,7 @@ class LoDResetKernel : public framework::OpKernel<T> {
"Target LoD should be a vector end with the "
"Target LoD should be a vector end with the "
"first dimension of Input(X)."
);
"first dimension of Input(X)."
);
for
(
size_t
i
=
0
;
i
<
level0
.
size
()
-
1
;
++
i
)
{
for
(
size_t
i
=
0
;
i
<
level0
.
size
()
-
1
;
++
i
)
{
PADDLE_ENFORCE
(
level0
[
i
+
1
]
>
level0
[
i
],
PADDLE_ENFORCE
(
level0
[
i
+
1
]
>
=
level0
[
i
],
"Target LoD should be an ascending vector."
);
"Target LoD should be an ascending vector."
);
}
}
...
...
python/paddle/fluid/tests/unittests/test_layers.py
浏览文件 @
4267a81a
...
@@ -1759,10 +1759,20 @@ class TestBook(LayerTest):
...
@@ -1759,10 +1759,20 @@ class TestBook(LayerTest):
def
test_lod_reset
(
self
):
def
test_lod_reset
(
self
):
# TODO(minqiyang): dygraph do not support lod now
# TODO(minqiyang): dygraph do not support lod now
with
self
.
static_graph
():
with
self
.
static_graph
():
# case 1
x
=
layers
.
data
(
name
=
'x'
,
shape
=
[
10
],
dtype
=
'float32'
)
x
=
layers
.
data
(
name
=
'x'
,
shape
=
[
10
],
dtype
=
'float32'
)
y
=
layers
.
data
(
y
=
layers
.
data
(
name
=
'y'
,
shape
=
[
10
,
20
],
dtype
=
'float32'
,
lod_level
=
2
)
name
=
'y'
,
shape
=
[
10
,
20
],
dtype
=
'float32'
,
lod_level
=
2
)
return
(
layers
.
lod_reset
(
x
=
x
,
y
=
y
))
z
=
layers
.
lod_reset
(
x
=
x
,
y
=
y
)
self
.
assertTrue
(
z
.
lod_level
==
2
)
# case 2
lod_tensor_in
=
layers
.
data
(
name
=
'lod_in'
,
shape
=
[
1
],
dtype
=
'int64'
)
z
=
layers
.
lod_reset
(
x
=
x
,
y
=
lod_tensor_in
)
self
.
assertTrue
(
z
.
lod_level
==
1
)
# case 3
z
=
layers
.
lod_reset
(
x
=
x
,
target_lod
=
[
1
,
2
,
3
])
self
.
assertTrue
(
z
.
lod_level
==
1
)
return
z
def
test_affine_grid
(
self
):
def
test_affine_grid
(
self
):
with
self
.
static_graph
():
with
self
.
static_graph
():
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录