Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
787133a7
提交
787133a7
authored
3月 03, 2015
作者:
Pascal Lamblin
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2364 from lamblin/scan_nonseq_grad
[WIP] Detect Null gradient wrt non-sequences in scan
上级
e9fee711
cc264051
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
53 行增加
和
6 行删除
+53
-6
scan_op.py
theano/scan_module/scan_op.py
+20
-6
test_scan.py
theano/scan_module/tests/test_scan.py
+33
-0
没有找到文件。
theano/scan_module/scan_op.py
浏览文件 @
787133a7
...
...
@@ -1883,13 +1883,27 @@ class Scan(PureOp):
type_outs
.
append
(
'disconnected'
)
else
:
type_outs
.
append
(
'connected'
)
inner_inp_sitsot
=
dC_dXtm1s
[
ins_pos
-
self
.
n_seqs
:]
outer_inp_sitsot
=
[
tensor
.
zeros
([
grad_steps
+
1
]
+
[
x
.
shape
[
i
]
for
i
in
xrange
(
x
.
ndim
)],
dtype
=
y
.
dtype
)
for
y
,
x
in
zip
(
inner_inp_sitsot
,
self
.
outer_non_seqs
(
inputs
))]
outer_inp_sitsot
=
[]
for
_idx
,
y
in
enumerate
(
inner_inp_sitsot
):
x
=
self
.
outer_non_seqs
(
inputs
)[
_idx
]
if
isinstance
(
y
.
type
,
NullType
):
# Cannot use dC_dXtm1s.dtype, so we use floatX instead.
outer_inp_sitsot
.
append
(
tensor
.
zeros
([
grad_steps
+
1
]
+
[
x
.
shape
[
i
]
for
i
in
xrange
(
x
.
ndim
)],
dtype
=
theano
.
config
.
floatX
))
# replace y by a zero tensor of the right shape
inner_inp_sitsot
[
_idx
]
=
tensor
.
zeros
(
diff_inputs
[
ins_pos
+
_idx
]
.
shape
,
dtype
=
theano
.
config
.
floatX
)
else
:
outer_inp_sitsot
.
append
(
tensor
.
zeros
([
grad_steps
+
1
]
+
[
x
.
shape
[
i
]
for
i
in
xrange
(
x
.
ndim
)],
dtype
=
y
.
dtype
))
n_sitsot_outs
=
len
(
outer_inp_sitsot
)
new_tap_array
=
mitmot_inp_taps
+
[[
-
1
]
for
k
in
...
...
theano/scan_module/tests/test_scan.py
浏览文件 @
787133a7
...
...
@@ -10,6 +10,7 @@ import cPickle
import
numpy
from
nose.plugins.skip
import
SkipTest
from
nose.plugins.attrib
import
attr
from
nose.tools
import
assert_raises
from
numpy.testing
import
dec
import
theano
...
...
@@ -3122,6 +3123,38 @@ class T_Scan(unittest.TestCase):
assert
out
[
4
]
==
19
# 19.0
def
test_crash_nonseq_grad
(
self
):
# Test case was originally reported by Bitton Tenessi. It crashed
# during the grad operation and this tests validates that it now
# raises a NullTypeGradError instead because the gradient relies on
# the intermediary states of the random number generators used in the
# test. The test case was modified from the original for simplicity
rand_stream
=
tensor
.
shared_randomstreams
.
RandomStreams
()
inp
=
tensor
.
matrix
()
norm_inp
=
inp
/
tensor
.
sum
(
inp
,
axis
=
0
)
def
unit_dropout
(
out_idx
):
def
stochastic_pooling
(
in_idx
):
# sample the input matrix for each column according to the
# column values
pvals
=
norm_inp
.
T
sample
=
rand_stream
.
multinomial
(
n
=
1
,
pvals
=
pvals
)
return
inp
+
sample
pooled
,
updates_inner
=
theano
.
scan
(
fn
=
stochastic_pooling
,
sequences
=
tensor
.
arange
(
inp
.
shape
[
0
]))
# randomly add stuff to units
rand_nums
=
rand_stream
.
binomial
(
size
=
pooled
.
shape
)
return
pooled
+
rand_nums
,
updates_inner
out
,
updates_outer
=
theano
.
scan
(
unit_dropout
,
sequences
=
[
tensor
.
arange
(
inp
.
shape
[
0
])])
assert_raises
(
theano
.
gradient
.
NullTypeGradError
,
tensor
.
grad
,
out
.
sum
(),
inp
)
def
test_bugFunctioProvidesIntermediateNodesAsInputs
(
self
):
# This is a bug recently reported by Ilya
# made it CPU friendly
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论