提交 d7e78733 authored 作者: Frederic's avatar Frederic

Make scan opt before blas opt.

上级 382b607c
...@@ -129,7 +129,9 @@ def remove_constants_and_unused_inputs_scan(node): ...@@ -129,7 +129,9 @@ def remove_constants_and_unused_inputs_scan(node):
return False return False
scan_seqopt = theano.gof.SequenceDB() scan_seqopt = theano.gof.SequenceDB()
optdb.register('scan_seqopt', scan_seqopt, 1.9, 'fast_run', 'scan') # We run before blas opt at 1.7 and specialize 2.0
# but after stabilize at 1.5. Should we put it before stabilize?
optdb.register('scan_seqopt', scan_seqopt, 1.6, 'fast_run', 'scan')
scan_seqopt.register('scanOp_remove_constants_and_unused_inputs', scan_seqopt.register('scanOp_remove_constants_and_unused_inputs',
opt.in2out(remove_constants_and_unused_inputs_scan, opt.in2out(remove_constants_and_unused_inputs_scan,
ignore_newtrees=True), ignore_newtrees=True),
......
...@@ -2599,6 +2599,31 @@ class T_Scan(unittest.TestCase): ...@@ -2599,6 +2599,31 @@ class T_Scan(unittest.TestCase):
assert numpy.allclose(theano_x , v_x[-2:]) assert numpy.allclose(theano_x , v_x[-2:])
assert numpy.allclose(theano_y , v_y[-4:]) assert numpy.allclose(theano_y , v_y[-4:])
def test_opt_order(self):
""" Verify that scan optimizations are applied before blas
optimizations.
This is needed as otherwise, the dot won't become a dot22
so it will be slower and won't get transferred to the gpu.
"""
x = theano.tensor.matrix('x')
A = theano.tensor.matrix('A')
z, updates = theano.scan(
theano.dot,
sequences=[],
non_sequences=[x, A],
n_steps=2)
f = theano.function([x, A], z)
topo = f.maker.env.toposort()
if theano.config.mode != "FAST_COMPILE":
assert any([isinstance(node.op, tensor.blas.Dot22)
for node in topo])
vx = numpy.array([[1., 1.], [2., 2.]], dtype=theano.config.floatX)
vA = numpy.array([[1., 1.], [1., 0.]], dtype=theano.config.floatX)
vR = numpy.array([[[2, 1], [4, 2]], [[2, 1], [4, 2]]],
dtype=theano.config.floatX)
assert numpy.allclose(f(vx, vA), vR)
def test_speed(): def test_speed():
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论