Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
8d1910e3
提交
8d1910e3
authored
4月 24, 2015
作者:
abergeron
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2717 from carriepl/scan_crash_infer_shape
[CRASH] Fix crash in save_mem when directly using outputs of the scan node
上级
0cc16359
ed009e03
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
73 行增加
和
5 行删除
+73
-5
scan_opt.py
theano/scan_module/scan_opt.py
+26
-5
test_scan.py
theano/scan_module/tests/test_scan.py
+47
-0
没有找到文件。
theano/scan_module/scan_opt.py
浏览文件 @
8d1910e3
...
@@ -1336,12 +1336,33 @@ class ScanSaveMem(gof.Optimizer):
...
@@ -1336,12 +1336,33 @@ class ScanSaveMem(gof.Optimizer):
if
global_nsteps
is
not
None
:
if
global_nsteps
is
not
None
:
for
idx
,
val
in
enumerate
(
store_steps
[
op
.
n_mit_mot
:]):
for
idx
,
val
in
enumerate
(
store_steps
[
op
.
n_mit_mot
:]):
if
val
==
0
:
if
val
==
0
:
# val == 0 means that we want to keep all intermediate
# results for that state, including the initial values.
if
idx
<
op
.
n_mit_sot
+
op
.
n_sit_sot
:
if
idx
<
op
.
n_mit_sot
+
op
.
n_sit_sot
:
_nw_input
=
nw_inputs
[
offset
+
idx
]
.
owner
.
inputs
[
1
]
in_idx
=
offset
+
idx
nw_input
=
scan_utils
.
expand
(
_nw_input
,
nw_steps
)
# Number of steps in the initial state
nw_inputs
[
offset
+
idx
]
=
nw_input
initl
=
init_l
[
op
.
n_mit_mot
+
idx
]
elif
idx
<
(
op
.
n_mit_sot
+
op
.
n_sit_sot
+
op
.
n_nit_sot
):
# If the initial buffer has the form
# inc_subtensor(zeros(...)[...], _nw_input)
# we want to make the zeros tensor as small as
# possible (nw_steps + initl), and call
# inc_subtensor on that instead.
# Otherwise, simply take 0:(nw_steps+initl).
if
((
nw_inputs
[
in_idx
]
.
owner
and
isinstance
(
nw_inputs
[
in_idx
]
.
owner
.
op
,
tensor
.
IncSubtensor
)
and
isinstance
(
nw_inputs
[
in_idx
]
.
owner
.
op
.
idx_list
[
0
],
slice
))):
_nw_input
=
nw_inputs
[
in_idx
]
.
owner
.
inputs
[
1
]
nw_input
=
scan_utils
.
expand
(
_nw_input
,
nw_steps
)
nw_inputs
[
in_idx
]
=
nw_input
else
:
nw_input
=
nw_inputs
[
in_idx
][:(
initl
+
nw_steps
)]
elif
idx
<
op
.
n_mit_sot
+
op
.
n_sit_sot
+
op
.
n_nit_sot
:
in_idx
=
offset
+
idx
+
op
.
n_shared_outs
in_idx
=
offset
+
idx
+
op
.
n_shared_outs
if
nw_inputs
[
in_idx
]
==
node
.
inputs
[
0
]:
if
nw_inputs
[
in_idx
]
==
node
.
inputs
[
0
]:
nw_inputs
[
in_idx
]
=
nw_steps
nw_inputs
[
in_idx
]
=
nw_steps
...
...
theano/scan_module/tests/test_scan.py
浏览文件 @
8d1910e3
...
@@ -2581,6 +2581,53 @@ class T_Scan(unittest.TestCase):
...
@@ -2581,6 +2581,53 @@ class T_Scan(unittest.TestCase):
utt
.
assert_allclose
(
tx4
,
v_u
[
-
1
]
+
4.
)
utt
.
assert_allclose
(
tx4
,
v_u
[
-
1
]
+
4.
)
utt
.
assert_allclose
(
tx5
,
v_u
[
-
1
]
+
5.
)
utt
.
assert_allclose
(
tx5
,
v_u
[
-
1
]
+
5.
)
def
test_use_scan_direct_output
(
self
):
# This test looks for a crash that happened when directly using the
# recurrent output of a scan node instead of taking the result
# returned by the scan() function
# Obtain a compilation mode that will cause the test to fail if an
# exception occurs in the optimization process
on_opt_error
=
theano
.
config
.
on_opt_error
theano
.
config
.
on_opt_error
=
"raise"
mode
=
theano
.
compile
.
get_default_mode
()
theano
.
config
.
on_opt_error
=
on_opt_error
x
=
tensor
.
scalar
()
seq
=
tensor
.
vector
()
outputs_info
=
[
x
,
tensor
.
zeros_like
(
x
)]
(
out1
,
out2
),
updates
=
theano
.
scan
(
lambda
a
,
b
,
c
:
(
a
+
b
,
b
+
c
),
sequences
=
seq
,
outputs_info
=
outputs_info
,
mode
=
mode
)
# Obtain a reference to the scan outputs before the subtensor and
# compile a function with them as outputs
assert
isinstance
(
out1
.
owner
.
op
,
tensor
.
subtensor
.
Subtensor
)
assert
isinstance
(
out2
.
owner
.
op
,
tensor
.
subtensor
.
Subtensor
)
out1_direct
=
out1
.
owner
.
inputs
[
0
]
out2_direct
=
out2
.
owner
.
inputs
[
0
]
fct
=
theano
.
function
([
x
,
seq
],
[
out1_direct
[:
-
1
],
out2_direct
[:
-
1
]],
mode
=
mode
)
# Test the function to ensure valid outputs
floatX
=
theano
.
config
.
floatX
init_value
=
5.0
seq_value
=
numpy
.
arange
(
4
,
dtype
=
floatX
)
output1
,
output2
=
fct
(
init_value
,
seq_value
)
expected_output1
=
[
init_value
]
expected_output2
=
[
0
]
for
i
in
seq_value
[:
-
1
]:
expected_output2
.
append
(
expected_output1
[
-
1
]
+
expected_output2
[
-
1
])
expected_output1
.
append
(
expected_output1
[
-
1
]
+
i
)
utt
.
assert_allclose
(
output1
,
expected_output1
)
utt
.
assert_allclose
(
output2
,
expected_output2
)
def
test_infer_shape
(
self
):
def
test_infer_shape
(
self
):
# Test for a crash in scan.infer_shape when using both
# Test for a crash in scan.infer_shape when using both
# an until condition and random sampling in the inner function.
# an until condition and random sampling in the inner function.
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论