提交 9880362c authored 作者: lamblin's avatar lamblin

Merge pull request #1178 from pascanur/nicolasDLT_scan_bug

Fix bugs reported by the DL tutorial wrote by Nicolas
......@@ -1344,8 +1344,8 @@ class Scan(PureOp):
j_inp_idx = self.get_input_pos(jidx) + 1
if connection_pattern[j_inp_idx][iidx] == True:
for k in xrange(len(connection_pattern)):
if connection_pattern[k][iidx]:
connection_pattern[k][jidx] = True
if connection_pattern[k][jidx]:
connection_pattern[k][iidx] = True
return connection_pattern
### GRAD FUNCTION
......
......@@ -1463,10 +1463,10 @@ class PushOutDot1(gof.Optimizer):
inp2 = x.owner.inputs[1]
if inp1 in seqs or inp2 in seqs:
new_scan_out = inp2
if inp2 in seqs:
new_scan_out = inp1
if inp1 in seqs:
new_scan_out = inp2
idx = sitsot_outs.index(out)
# We've found our pattern and need to construct a new
# scan node to replace this one. For this we need to
......@@ -1535,6 +1535,8 @@ class PushOutDot1(gof.Optimizer):
outer_non_seqs)
new_outs = new_op(*_scan_inputs)
if type(new_outs) not in (list, tuple):
new_outs = [new_outs]
# We need now to pair correctly the new outputs with the
# old ones
......
......@@ -3310,6 +3310,32 @@ class T_Scan(unittest.TestCase):
# disconnected gradient a non disconnected type was returned
tensor.grad((m * m2).sum(), v)
def test_disconnected_gradient2(self):
v = tensor.vector('v')
m = tensor.matrix('m')
u0 = tensor.zeros((7,))
[u, m2], _ = theano.scan(lambda x, u: [x+u, u+v],
sequences=m,
outputs_info=[u0, None])
# This used to raise an exception with older versions becasue
# scan could not detect the connection between `m2` and `x`
tensor.grad(m2.sum(), m)
def test_dot_optimization(self):
A = tensor.matrix('A')
B = tensor.matrix('B')
S, _ = theano.scan(lambda x1,x2, u: u + tensor.dot(x1,x2),
sequences = [A.dimshuffle(0, 1, 'x'),
B.dimshuffle(0,'x', 1)],
outputs_info=[tensor.zeros_like(A)])
f = theano.function([A,B], S.owner.inputs[0][-1])
rng = numpy.random.RandomState(utt.fetch_seed())
vA = rng.uniform(size=(5,5))
vB = rng.uniform(size=(5,5))
assert numpy.allclose(f(vA, vB), numpy.dot(vA.T, vB))
def test_pregreedy_optimizer(self):
W = tensor.zeros((5, 4))
bv = tensor.zeros((5,))
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论