Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
6c3d8e26
提交
6c3d8e26
authored
6月 15, 2015
作者:
abergeron
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #3002 from carriepl/scan_index_error
[CRASH] Scan index error
上级
32bc96d7
7b984d13
全部展开
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
105 行增加
和
19 行删除
+105
-19
scan_op.py
theano/scan_module/scan_op.py
+0
-0
test_scan.py
theano/scan_module/tests/test_scan.py
+105
-19
没有找到文件。
theano/scan_module/scan_op.py
浏览文件 @
6c3d8e26
差异被折叠。
点击展开。
theano/scan_module/tests/test_scan.py
浏览文件 @
6c3d8e26
...
...
@@ -657,19 +657,18 @@ class T_Scan(unittest.TestCase):
tensor
.
grad
(
a
[
-
1
],
a0
)
# Also validate that the m
ethods get_outer_iidx_from_outer_oidx_seq
#
and get_outer_iidx_from_inner_iidx_seq
produce the correct results
# Also validate that the m
appings outer_inp_from_outer_out and
#
outer_inp_from_inner_inp
produce the correct results
scan_node
=
a
.
owner
.
inputs
[
0
]
.
owner
result
=
scan_node
.
op
.
get_outer_iidx_from_outer_oidx_seq
()
expected_result
=
[
1
,
2
]
result
=
scan_node
.
op
.
var_mappings
[
'outer_inp_from_outer_out'
]
expected_result
=
{
0
:
1
,
1
:
2
}
assert
(
result
==
expected_result
)
result
=
scan_node
.
op
.
get_outer_iidx_from_inner_iidx_seq
()
expected_result
=
[
1
,
1
,
2
,
2
]
result
=
scan_node
.
op
.
var_mappings
[
'outer_inp_from_inner_inp'
]
expected_result
=
{
0
:
1
,
1
:
1
,
2
:
2
,
3
:
2
}
assert
(
result
==
expected_result
)
def
test_connection_pattern2
(
self
):
# This tests for a crash in connection_pattern() when a scan node
# has more than one mitmot (multiple input taps as well as
...
...
@@ -690,18 +689,42 @@ class T_Scan(unittest.TestCase):
scan_node
=
g_out
[
0
]
.
owner
.
inputs
[
1
]
.
owner
.
inputs
[
1
]
.
owner
.
inputs
[
0
]
.
owner
connection_pattern
=
scan_node
.
op
.
connection_pattern
(
scan_node
)
# Also validate that the m
ethods get_outer_iidx_from_outer_oidx_seq
#
and get_outer_iidx_from_inner_iidx_seq
produce the correct results
# Also validate that the m
appings outer_inp_from_outer_out and
#
outer_inp_from_inner_inp
produce the correct results
scan_node
=
out
.
owner
.
inputs
[
0
]
.
owner
result
=
scan_node
.
op
.
get_outer_iidx_from_outer_oidx_seq
()
expected_result
=
[
2
]
result
=
scan_node
.
op
.
var_mappings
[
'outer_inp_from_outer_out'
]
expected_result
=
{
0
:
2
}
assert
(
result
==
expected_result
)
result
=
scan_node
.
op
.
get_outer_iidx_from_inner_iidx_seq
()
expected_result
=
[
1
,
2
,
2
]
result
=
scan_node
.
op
.
var_mappings
[
'outer_inp_from_inner_inp'
]
expected_result
=
{
0
:
1
,
1
:
2
,
2
:
2
}
assert
(
result
==
expected_result
)
def
test_grad_grad_mitsot_sitsot
(
self
):
# Test for an index error when taking the second derivative
# through a Scan node with one sitsot and one mitsot.
def
inner_fct
(
mitsot_m2
,
mitsot_m1
,
sitsot
):
total
=
mitsot_m2
+
mitsot_m1
+
sitsot
output
=
total
**
2
return
output
,
output
inputs
=
[
tensor
.
matrix
(),
tensor
.
vector
()]
outputs_info
=
[
dict
(
initial
=
inputs
[
0
],
taps
=
[
-
2
,
-
1
]),
inputs
[
1
]]
scan_outputs
,
updates
=
theano
.
scan
(
fn
=
inner_fct
,
outputs_info
=
outputs_info
,
n_steps
=
5
)
# Take the gradient of each output wrt its corresponding initial state
gradients
=
[
theano
.
grad
(
scan_outputs
[
0
]
.
sum
(),
inputs
[
0
]),
theano
.
grad
(
scan_outputs
[
1
]
.
sum
(),
inputs
[
1
])]
# Take the gradient of the sum of gradients wrt the inputs
sum_of_grads
=
sum
([
g
.
sum
()
for
g
in
gradients
])
second_gradients
=
theano
.
grad
(
sum_of_grads
,
inputs
[
0
])
def
test_grad_two_scans
(
self
):
# data input & output
...
...
@@ -1680,16 +1703,16 @@ class T_Scan(unittest.TestCase):
analytic_grad
[
max_err_pos
],
num_grad
.
gx
[
max_err_pos
]))
# Also validate that the m
ethods get_outer_iidx_from_outer_oidx_seq
#
and get_outer_iidx_from_inner_iidx_seq
produce the correct results
# Also validate that the m
appings outer_inp_from_outer_out and
#
outer_inp_from_inner_inp
produce the correct results
scan_node
=
updates
.
values
()[
0
]
.
owner
result
=
scan_node
.
op
.
get_outer_iidx_from_outer_oidx_seq
()
expected_result
=
[
3
,
-
1
,
4
]
result
=
scan_node
.
op
.
var_mappings
[
'outer_inp_from_outer_out'
]
expected_result
=
{
0
:
3
,
1
:
5
,
2
:
4
}
assert
(
result
==
expected_result
)
result
=
scan_node
.
op
.
get_outer_iidx_from_inner_iidx_seq
()
expected_result
=
[
1
,
2
,
3
,
4
,
6
]
result
=
scan_node
.
op
.
var_mappings
[
'outer_inp_from_inner_inp'
]
expected_result
=
{
0
:
1
,
1
:
2
,
2
:
3
,
3
:
4
,
4
:
6
}
assert
(
result
==
expected_result
)
def
test_grad_multiple_outs_some_truncate
(
self
):
...
...
@@ -3299,6 +3322,69 @@ class T_Scan(unittest.TestCase):
if
isinstance
(
x
.
op
,
theano
.
scan_module
.
scan_op
.
Scan
)]
assert
len
(
lssc
)
==
0
def
test_oinp_iinp_iout_oout_mappings
(
self
):
# Test the mapping produces by
# ScanOp.get_oinp_iinp_iout_oout_mappings()
rng
=
theano
.
tensor
.
shared_randomstreams
.
RandomStreams
(
123
)
def
inner_fct
(
seq
,
mitsot
,
sitsot
,
nitsot
,
nseq
):
random_scalar
=
rng
.
uniform
((
1
,))[
0
]
total
=
seq
+
mitsot
+
sitsot
+
nitsot
+
nseq
+
random_scalar
return
total
,
total
,
total
# Assemble a scan with one sequence, one mitsot, one sitsot, one nitsot
# a non-sequence and a random state to test the mappings.
seq
=
[
tensor
.
vector
()]
non_seq
=
[
tensor
.
scalar
()]
outputs_info
=
[
dict
(
initial
=
tensor
.
vector
(),
taps
=
[
-
3
,
-
1
]),
tensor
.
scalar
(),
None
]
scan_outputs
,
_
=
theano
.
scan
(
fn
=
inner_fct
,
sequences
=
seq
,
outputs_info
=
outputs_info
,
non_sequences
=
non_seq
)
# Compare the mappings with the expected values
scan_node
=
scan_outputs
[
0
]
.
owner
.
inputs
[
0
]
.
owner
mappings
=
scan_node
.
op
.
var_mappings
assert
mappings
[
'inner_inp_from_outer_inp'
]
==
{
0
:
[],
1
:
[
0
],
2
:
[
1
,
2
],
3
:
[
3
],
4
:
[
4
],
5
:
[],
6
:
[
5
]}
assert
mappings
[
'inner_out_from_outer_inp'
]
==
{
0
:
[],
1
:
[],
2
:
[
0
],
3
:
[
1
],
4
:
[
3
],
5
:
[
2
],
6
:
[]}
assert
mappings
[
'outer_out_from_outer_inp'
]
==
{
0
:
-
1
,
1
:
-
1
,
2
:
0
,
3
:
1
,
4
:
3
,
5
:
2
,
6
:
-
1
}
assert
mappings
[
'outer_inp_from_inner_inp'
]
==
{
0
:
1
,
1
:
2
,
2
:
2
,
3
:
3
,
4
:
4
,
5
:
6
}
assert
mappings
[
'inner_out_from_inner_inp'
]
==
{
0
:
[],
1
:
[
0
],
2
:
[
0
],
3
:
[
1
],
4
:
[
3
],
5
:
[]}
assert
mappings
[
'outer_out_from_inner_inp'
]
==
{
0
:
-
1
,
1
:
0
,
2
:
0
,
3
:
1
,
4
:
3
,
5
:
-
1
}
assert
mappings
[
'outer_inp_from_inner_out'
]
==
{
0
:
2
,
1
:
3
,
2
:
5
,
3
:
4
}
assert
mappings
[
'inner_inp_from_inner_out'
]
==
{
0
:
[
1
,
2
],
1
:
[
3
],
2
:
[],
3
:
[
4
]}
assert
mappings
[
'outer_out_from_inner_out'
]
==
{
0
:
0
,
1
:
1
,
2
:
2
,
3
:
3
}
assert
mappings
[
'outer_inp_from_outer_out'
]
==
{
0
:
2
,
1
:
3
,
2
:
5
,
3
:
4
}
assert
mappings
[
'inner_inp_from_outer_out'
]
==
{
0
:
[
1
,
2
],
1
:
[
3
],
2
:
[],
3
:
[
4
]}
assert
mappings
[
'inner_out_from_outer_out'
]
==
{
0
:
[
0
],
1
:
[
1
],
2
:
[
2
],
3
:
[
3
]}
def
test_grad_duplicate_outputs
(
self
):
# This test validates that taking the gradient of a scan, in which
# multiple outputs are the same theano variable, works.
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论