Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
36c85ef4
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,发现更多精彩内容 >>
未验证
提交
36c85ef4
编写于
10月 13, 2019
作者:
C
chengduo
提交者:
GitHub
10月 13, 2019
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add sub-scope check in RecurrentOp (#20468)
* fix recurrent bug test=develop
上级
12e4be03
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
51 addition
and
23 deletion
+51
-23
paddle/fluid/operators/controlflow/while_op.cc
paddle/fluid/operators/controlflow/while_op.cc
+11
-0
paddle/fluid/operators/recurrent_op.cc
paddle/fluid/operators/recurrent_op.cc
+3
-1
python/paddle/fluid/tests/unittests/test_while_op.py
python/paddle/fluid/tests/unittests/test_while_op.py
+37
-22
未找到文件。
paddle/fluid/operators/controlflow/while_op.cc
浏览文件 @
36c85ef4
...
...
@@ -62,6 +62,17 @@ class WhileOp : public framework::OperatorBase {
auto
step_scopes
=
scope
.
FindVar
(
Output
(
kStepScopes
))
->
GetMutable
<
StepScopeVar
>
();
if
(
step_scopes
->
size
()
>
0
)
{
platform
::
DeviceContextPool
::
Instance
().
Get
(
dev_place
)
->
Wait
();
for
(
auto
&
s
:
*
step_scopes
)
{
if
(
scope
.
HasKid
(
s
))
{
scope
.
DeleteScope
(
s
);
}
}
step_scopes
->
clear
();
}
PADDLE_ENFORCE_EQ
(
step_scopes
->
size
(),
0
,
"The StepScope should be empty."
);
PADDLE_ENFORCE
(
platform
::
is_cpu_place
(
cond
.
place
()),
"Condition of while op must in CPU memory."
);
...
...
paddle/fluid/operators/recurrent_op.cc
浏览文件 @
36c85ef4
...
...
@@ -48,7 +48,9 @@ static void ClearStepScopes(const platform::DeviceContext &dev_ctx,
dev_ctx
.
Wait
();
for
(
auto
*
sub_scope
:
*
step_scopes
)
{
parent_scope
->
DeleteScope
(
sub_scope
);
if
(
parent_scope
->
HasKid
(
sub_scope
))
{
parent_scope
->
DeleteScope
(
sub_scope
);
}
}
step_scopes
->
clear
();
...
...
python/paddle/fluid/tests/unittests/test_while_op.py
浏览文件 @
36c85ef4
...
...
@@ -18,46 +18,38 @@ import unittest
import
paddle.fluid.layers
as
layers
from
paddle.fluid.executor
import
Executor
import
paddle.fluid.core
as
core
import
paddle.fluid
as
fluid
from
paddle.fluid.backward
import
append_backward
import
numpy
class
TestWhileOp
(
unittest
.
TestCase
):
def
test_simple_forward
(
self
):
def
simple_net
(
self
):
d0
=
layers
.
data
(
"d0"
,
shape
=
[
10
],
append_batch_size
=
False
,
dtype
=
'float32'
)
d1
=
layers
.
data
(
"d1"
,
shape
=
[
10
],
append_batch_size
=
False
,
dtype
=
'float32'
)
d2
=
layers
.
data
(
"d2"
,
shape
=
[
10
],
append_batch_size
=
False
,
dtype
=
'float32'
)
i
=
layers
.
zeros
(
shape
=
[
1
],
dtype
=
'int64'
)
i
.
stop_gradient
=
True
init
=
layers
.
zeros
(
shape
=
[
10
],
dtype
=
'float32'
)
mem_array
=
layers
.
array_write
(
x
=
init
,
i
=
i
)
data_array
=
layers
.
array_write
(
x
=
d0
,
i
=
i
)
i
=
layers
.
increment
(
i
)
layers
.
array_write
(
d1
,
i
,
array
=
data_array
)
i
=
layers
.
increment
(
i
)
layers
.
array_write
(
d2
,
i
,
array
=
data_array
)
i
=
layers
.
zeros
(
shape
=
[
1
],
dtype
=
'int64'
)
i
.
stop_gradient
=
True
array_len
=
layers
.
fill_constant
(
shape
=
[
1
],
dtype
=
'int64'
,
value
=
1
)
array_len
.
stop_gradient
=
True
cond
=
layers
.
less_than
(
x
=
i
,
y
=
array_len
)
j
=
layers
.
fill_constant
(
shape
=
[
1
],
dtype
=
'int64'
,
value
=
1
)
j
.
stop_gradient
=
True
array_len2
=
layers
.
fill_constant
(
shape
=
[
1
],
dtype
=
'int64'
,
value
=
3
)
array_len2
.
stop_gradient
=
True
cond2
=
layers
.
less_than
(
x
=
j
,
y
=
array_len2
)
while_op
=
layers
.
While
(
cond
=
cond
)
while_op2
=
layers
.
While
(
cond
=
cond2
)
with
while_op
.
block
():
...
...
@@ -77,24 +69,47 @@ class TestWhileOp(unittest.TestCase):
j
=
layers
.
increment
(
x
=
j
,
in_place
=
True
)
layers
.
array_write
(
result2
,
i
=
j
,
array
=
mem_array
)
layers
.
less_than
(
x
=
j
,
y
=
array_len2
,
cond
=
cond2
)
sum_result
=
layers
.
array_read
(
array
=
mem_array
,
i
=
j
)
loss
=
layers
.
mean
(
sum_result
)
return
loss
,
sum_result
def
test_simple_net
(
self
):
main_program
=
fluid
.
Program
()
startup_program
=
fluid
.
Program
()
with
fluid
.
program_guard
(
main_program
,
startup_program
):
loss
,
sum_result
=
self
.
simple_net
()
append_backward
(
loss
)
cpu
=
core
.
CPUPlace
()
exe
=
Executor
(
cpu
)
d
=
[]
for
i
in
range
(
3
):
d
.
append
(
numpy
.
random
.
random
(
size
=
[
10
]).
astype
(
'float32'
))
outs
=
exe
.
run
(
feed
=
{
'd0'
:
d
[
0
],
'd1'
:
d
[
1
],
'd2'
:
d
[
2
]},
fetch_list
=
[
sum_result
])
self
.
assertAlmostEqual
(
numpy
.
sum
(
d
),
numpy
.
sum
(
outs
[
0
]),
delta
=
0.01
)
append_backward
(
loss
)
def
test_simple_net_forward
(
self
):
main_program
=
fluid
.
Program
()
startup_program
=
fluid
.
Program
()
with
fluid
.
program_guard
(
main_program
,
startup_program
):
self
.
simple_net
()
binary
=
fluid
.
compiler
.
CompiledProgram
(
main_program
)
cpu
=
core
.
CPUPlace
()
exe
=
Executor
(
cpu
)
d
=
[]
cpu
=
core
.
CPUPlace
()
exe
=
Executor
(
cpu
)
d
=
[]
for
i
in
range
(
3
):
d
.
append
(
numpy
.
random
.
random
(
size
=
[
10
]).
astype
(
'float32'
))
for
i
in
range
(
3
):
d
.
append
(
numpy
.
random
.
random
(
size
=
[
10
]).
astype
(
'float32'
))
outs
=
exe
.
run
(
feed
=
{
'd0'
:
d
[
0
],
'd1'
:
d
[
1
],
'd2'
:
d
[
2
]},
fetch_list
=
[
sum_result
])
self
.
assertAlmostEqual
(
numpy
.
sum
(
d
),
numpy
.
sum
(
outs
[
0
]),
delta
=
0.01
)
for
_
in
range
(
2
):
exe
.
run
(
binary
,
feed
=
{
'd0'
:
d
[
0
],
'd1'
:
d
[
1
],
'd2'
:
d
[
2
]})
def
test_exceptions
(
self
):
i
=
layers
.
zeros
(
shape
=
[
2
],
dtype
=
'int64'
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录