提交 db9dc771 authored 作者: James Bergstra's avatar James Bergstra

merge; no conflict

...@@ -2228,23 +2228,23 @@ def test_speed_rnn(): ...@@ -2228,23 +2228,23 @@ def test_speed_rnn():
t0 = time.time() t0 = time.time()
for i in xrange(1,L): for i in xrange(1,L):
r[i] += numpy.tanh(numpy.dot(r[i-1], w)) r[i] = numpy.tanh(numpy.dot(r[i-1], w))
t1 = time.time() t1 = time.time()
print 'python', t1 - t0 print 'python', t1 - t0
if 1: if 1:
r = numpy.arange(L*N).astype(theano.config.floatX).reshape(L,N) r = numpy.arange(L*N).astype(theano.config.floatX).reshape(L,N)
s_r = tensor.matrix() s_r = tensor.matrix()
s_y, updates = theano.scan(fn=lambda ri, rii:ri+tensor.tanh(tensor.dot(rii, w)), s_y, updates = theano.scan(fn=lambda ri, rii:tensor.tanh(tensor.dot(rii, w)),
sequences=[s_r[1:]], sequences=[s_r[1:]],
outputs_info=tensor.constant(r[0])) outputs_info=tensor.constant(r[0]))
assert not updates assert not updates
f = theano.function([s_r], s_y) f = theano.function([s_r], s_y, mode='FAST_RUN_NOGC')
t2 = time.time() t2 = time.time()
f(r) f(r)
t3 = time.time() t3 = time.time()
print 'theano1', t3 - t2 print 'theano (scan)', t3 - t2
if 1: if 1:
r = numpy.arange(L*N).astype(theano.config.floatX).reshape(L,N) r = numpy.arange(L*N).astype(theano.config.floatX).reshape(L,N)
...@@ -2262,19 +2262,15 @@ def test_speed_rnn(): ...@@ -2262,19 +2262,15 @@ def test_speed_rnn():
updates={ updates={
s_i: s_i+1, s_i: s_i+1,
shared_r: s_rinc, shared_r: s_rinc,
}) },
mode='CVM')
theano.printing.debugprint(f ) theano.printing.debugprint(f )
f_fn = f.fn f_fn = f.fn
t2 = time.time() t2 = time.time()
if 0:
f_fn(n_calls=L-2) f_fn(n_calls=L-2)
elif 0:
for i in xrange(L-2): f_fn()
else:
for i in xrange(L-2): f()
f() #999 to update the profiling timers f() #999 to update the profiling timers
t3 = time.time() t3 = time.time()
print 'theano2', t3 - t2 print 'theano (updates)', t3 - t2
print shared_r.get_value() print shared_r.get_value()
if __name__ == '__main__': if __name__ == '__main__':
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论