Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
e995d1fd
提交
e995d1fd
authored
3月 18, 2015
作者:
Pierre Luc Carrier
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix crash in scan.grad and add test
上级
54dc5a79
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
64 行增加
和
1 行删除
+64
-1
scan_op.py
theano/scan_module/scan_op.py
+10
-1
test_scan.py
theano/scan_module/tests/test_scan.py
+54
-0
没有找到文件。
theano/scan_module/scan_op.py
浏览文件 @
e995d1fd
...
@@ -1597,7 +1597,16 @@ class Scan(PureOp):
...
@@ -1597,7 +1597,16 @@ class Scan(PureOp):
if
idx
>=
self
.
n_mit_mot_outs
:
if
idx
>=
self
.
n_mit_mot_outs
:
Xt_placeholder
=
safe_new
(
Xt
)
Xt_placeholder
=
safe_new
(
Xt
)
Xts
.
append
(
Xt_placeholder
)
Xts
.
append
(
Xt_placeholder
)
if
Xt
not
in
self
.
inner_nitsot_outs
(
self_outputs
):
# Different processing based on whether Xt is a nitsot output
# or not. NOTE : This cannot be done by using
# "if Xt not in self.inner_nitsot_outs(self_outputs)" because
# the exact same variable can be used as multiple outputs.
idx_nitsot_start
=
(
self
.
info
[
'n_mit_mot'
]
+
self
.
info
[
'n_mit_sot'
]
+
self
.
info
[
'n_sit_sot'
])
idx_nitsot_end
=
idx_nitsot_start
+
self
.
info
[
'n_nit_sot'
]
if
idx
<
idx_nitsot_start
or
idx
>=
idx_nitsot_end
:
# What we do here is loop through dC_douts and collect all
# What we do here is loop through dC_douts and collect all
# those that are connected to the specific one and do an
# those that are connected to the specific one and do an
# upcast on all of their dtypes to get the dtype for this
# upcast on all of their dtypes to get the dtype for this
...
...
theano/scan_module/tests/test_scan.py
浏览文件 @
e995d1fd
...
@@ -3279,6 +3279,60 @@ class T_Scan(unittest.TestCase):
...
@@ -3279,6 +3279,60 @@ class T_Scan(unittest.TestCase):
if
isinstance
(
x
.
op
,
theano
.
scan_module
.
scan_op
.
Scan
)]
if
isinstance
(
x
.
op
,
theano
.
scan_module
.
scan_op
.
Scan
)]
assert
len
(
lssc
)
==
0
assert
len
(
lssc
)
==
0
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.
def
inner_fct
(
inp1
,
inp2
,
inp3
):
total
=
inp1
+
inp2
+
inp3
return
total
,
total
# Assemble the scan
seq
=
tensor
.
matrix
()
out_init
=
tensor
.
matrix
()
non_seq
=
tensor
.
vector
()
outputs_info
=
([
None
,
dict
(
initial
=
out_init
,
taps
=
[
-
3
])])
scan_outputs
,
_
=
theano
.
scan
(
fn
=
inner_fct
,
sequences
=
seq
,
outputs_info
=
outputs_info
,
non_sequences
=
non_seq
)
# Attempt to take various gradients
g_output0
=
theano
.
grad
(
scan_outputs
[
0
]
.
sum
(),
[
seq
,
out_init
,
non_seq
])
g_output1
=
theano
.
grad
(
scan_outputs
[
1
]
.
sum
(),
[
seq
,
out_init
,
non_seq
])
# Compile the function
fct
=
theano
.
function
([
seq
,
out_init
,
non_seq
],
g_output0
+
g_output1
)
# Run the function and validate the outputs
seq_value
=
numpy
.
random
.
random
((
10
,
3
))
out_init_value
=
numpy
.
random
.
random
((
3
,
3
))
non_seq_value
=
numpy
.
random
.
random
((
3
))
outputs
=
fct
(
seq_value
,
out_init_value
,
non_seq_value
)
expected_g_seq
=
numpy
.
array
([[
4
,
4
,
4
],
[
3
,
3
,
3
],
[
3
,
3
,
3
],
[
3
,
3
,
3
],
[
2
,
2
,
2
],
[
2
,
2
,
2
],
[
2
,
2
,
2
],
[
1
,
1
,
1
],
[
1
,
1
,
1
],
[
1
,
1
,
1
]])
expected_g_out_init
=
expected_g_seq
[:
3
]
expected_g_non_seq
=
numpy
.
array
([
22
,
22
,
22
])
utt
.
assert_allclose
(
outputs
[
0
],
expected_g_seq
)
utt
.
assert_allclose
(
outputs
[
1
],
expected_g_out_init
)
utt
.
assert_allclose
(
outputs
[
2
],
expected_g_non_seq
)
utt
.
assert_allclose
(
outputs
[
3
],
expected_g_seq
)
utt
.
assert_allclose
(
outputs
[
4
],
expected_g_out_init
)
utt
.
assert_allclose
(
outputs
[
5
],
expected_g_non_seq
)
def
test_grad_multiple_seqs_different_nsteps
(
self
):
def
test_grad_multiple_seqs_different_nsteps
(
self
):
# Example provided Michael Forbes
# Example provided Michael Forbes
# This test assures that we clip the sequences to n_steps before
# This test assures that we clip the sequences to n_steps before
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论