提交 4be478ff authored 作者: James Bergstra's avatar James Bergstra

fixed test of canonize that was modifying global mode variables

上级 88b0c613
...@@ -246,6 +246,8 @@ class test_canonize(unittest.TestCase): ...@@ -246,6 +246,8 @@ class test_canonize(unittest.TestCase):
#We must be sure that the Canonizer is working, but that we don't have other #We must be sure that the Canonizer is working, but that we don't have other
# optimisation that could hide bug in the Canonizer as local_elemwise_fusion # optimisation that could hide bug in the Canonizer as local_elemwise_fusion
mode=compile.mode.predefined_modes[compile.mode.default_mode] mode=compile.mode.predefined_modes[compile.mode.default_mode]
old_optimizer = mode._optimizer
try:
mode._optimizer=gof.Query(["canonicalize"]) mode._optimizer=gof.Query(["canonicalize"])
mode._optimizer=mode._optimizer.excluding('local_elemwise_fusion') mode._optimizer=mode._optimizer.excluding('local_elemwise_fusion')
for id, [g, sym_inputs, val_inputs, nb_elemwise, out_dtype] in enumerate(cases): for id, [g, sym_inputs, val_inputs, nb_elemwise, out_dtype] in enumerate(cases):
...@@ -256,6 +258,8 @@ class test_canonize(unittest.TestCase): ...@@ -256,6 +258,8 @@ class test_canonize(unittest.TestCase):
out = f(*val_inputs) out = f(*val_inputs)
assert(len(f.maker.env.toposort())==nb_elemwise) assert(len(f.maker.env.toposort())==nb_elemwise)
assert(out_dtype==out.dtype) assert(out_dtype==out.dtype)
finally:
mode._optimizer = old_optimizer
def test_elemwise_multiple_inputs_optimisation2(self): def test_elemwise_multiple_inputs_optimisation2(self):
""" """
...@@ -367,6 +371,8 @@ class test_canonize(unittest.TestCase): ...@@ -367,6 +371,8 @@ class test_canonize(unittest.TestCase):
#We must be sure that the Canonizer is working, but that we don't have other #We must be sure that the Canonizer is working, but that we don't have other
# optimisation that could hide bug in the Canonizer as local_elemwise_fusion # optimisation that could hide bug in the Canonizer as local_elemwise_fusion
mode=compile.mode.predefined_modes[compile.mode.default_mode] mode=compile.mode.predefined_modes[compile.mode.default_mode]
old_optimizer = mode._optimizer
try:
mode._optimizer=gof.Query(["canonicalize"]) mode._optimizer=gof.Query(["canonicalize"])
mode._optimizer=mode._optimizer.excluding('local_elemwise_fusion') mode._optimizer=mode._optimizer.excluding('local_elemwise_fusion')
...@@ -416,7 +422,7 @@ class test_canonize(unittest.TestCase): ...@@ -416,7 +422,7 @@ class test_canonize(unittest.TestCase):
#must broadcast as their is a dimshuffle in the computation #must broadcast as their is a dimshuffle in the computation
((dx/dv)/dx,[dx,dv],[dxv,dvv],2,'float64'), ((dx/dv)/dx,[dx,dv],[dxv,dvv],2,'float64'),
#topo: [Elemwise{inv,no_inplace}(<TensorType(float64, row)>), Elemwise{second,no_inplace}(x, Elemwise{inv,no_inplace}.0)] #topo: [Elemwise{inv,no_inplace}(<TensorType(float64, row)>), Elemwise{second,no_inplace}(x, Elemwise{inv,no_inplace}.0)]
((fx/fv)/fx,[fx,fv],[fxv,fvv],2,'float32'), ((fx/fv)/fx,[fx,fv],[fxv,fvv],2,'float32'),
#topo:[Elemwise{inv,no_inplace}(<TensorType(float32, row)>), Elemwise{second,no_inplace}(x, Elemwise{inv,no_inplace}.0)] #topo:[Elemwise{inv,no_inplace}(<TensorType(float32, row)>), Elemwise{second,no_inplace}(x, Elemwise{inv,no_inplace}.0)]
]): ]):
...@@ -491,6 +497,8 @@ class test_canonize(unittest.TestCase): ...@@ -491,6 +497,8 @@ class test_canonize(unittest.TestCase):
topo=f.maker.env.toposort() topo=f.maker.env.toposort()
assert len(topo)==0 assert len(topo)==0
assert(out_dtype==out.dtype) assert(out_dtype==out.dtype)
finally:
mode._optimizer = old_optimizer
def test_multiple_case_that_fail(self): def test_multiple_case_that_fail(self):
...@@ -510,10 +518,12 @@ class test_canonize(unittest.TestCase): ...@@ -510,10 +518,12 @@ class test_canonize(unittest.TestCase):
#We must be sure that the Canonizer is working, but that we don't have other #We must be sure that the Canonizer is working, but that we don't have other
# optimisation that could hide bug in the Canonizer as local_elemwise_fusion # optimisation that could hide bug in the Canonizer as local_elemwise_fusion
mode=compile.mode.predefined_modes[compile.mode.default_mode] mode=compile.mode.predefined_modes[compile.mode.default_mode]
old_optimizer = mode._optimizer
try:
mode._optimizer=gof.Query(["canonicalize"]) mode._optimizer=gof.Query(["canonicalize"])
mode._optimizer=mode._optimizer.excluding('local_elemwise_fusion') mode._optimizer=mode._optimizer.excluding('local_elemwise_fusion')
#test fail! #test fail!
#test x / y / z -> x / (y * z) #test x / y / z -> x / (y * z)
for (g, sym_inputs, val_inputs, out_dtype) in [ for (g, sym_inputs, val_inputs, out_dtype) in [
((dx/dy)/dz,[dx,dy,dz],[dxv,dyv,dzv],'float64'), ((dx/dy)/dz,[dx,dy,dz],[dxv,dyv,dzv],'float64'),
...@@ -548,6 +558,9 @@ class test_canonize(unittest.TestCase): ...@@ -548,6 +558,9 @@ class test_canonize(unittest.TestCase):
assert len(topo[0].inputs)==1 assert len(topo[0].inputs)==1
assert(out_dtype==out.dtype) assert(out_dtype==out.dtype)
finally:
mode._optimizer = old_optimizer
def test_dont_merge_if_multiple_client(self): def test_dont_merge_if_multiple_client(self):
""" test those case take from the comment in Canonizer """ test those case take from the comment in Canonizer
""" """
...@@ -571,9 +584,15 @@ def test_local_shape_lift_dot(): ...@@ -571,9 +584,15 @@ def test_local_shape_lift_dot():
for y in [fvector, fmatrix]: for y in [fvector, fmatrix]:
i = x() i = x()
j = y() j = y()
print 'I SHAPE', i.type.shape
print 'J SHAPE', j.type.shape
d = shape(dot(i,j)) d = shape(dot(i,j))
if x is fvector and y is fvector:
assert d == ()
else:
g = Env([i,j], [d]) g = Env([i,j], [d])
gof.TopoOptimizer(gof.LocalOptGroup(local_shape_lift_dot), order='out_to_in').optimize(g) gof.TopoOptimizer(gof.LocalOptGroup(local_shape_lift_dot), order='out_to_in').optimize(g)
print pprint(g.outputs[0]), args_to_result[(x,y)]
assert pprint(g.outputs[0]) == args_to_result[(x,y)] assert pprint(g.outputs[0]) == args_to_result[(x,y)]
# def test_plusmin(self): # def test_plusmin(self):
...@@ -982,8 +1001,10 @@ class test_fusion(unittest.TestCase): ...@@ -982,8 +1001,10 @@ class test_fusion(unittest.TestCase):
#Follow up. Clinker do the same... second cause? #Follow up. Clinker do the same... second cause?
mode2=compile.Mode(linker(), copy.copy(compile.mode.OPT_FAST_RUN)) mode2=compile.Mode(linker(), copy.copy(compile.mode.OPT_FAST_RUN))
# mode2=copy.copy(compile.mode.predefined_modes['FAST_RUN']) # mode2=copy.copy(compile.mode.predefined_modes['FAST_RUN'])
old_optimizer = mode2._optimizer
try:
mode2._optimizer=mode2._optimizer.excluding('local_elemwise_fusion') mode2._optimizer=mode2._optimizer.excluding('local_elemwise_fusion')
# mode2=compile.Mode(gof.OpWiseCLinker(allow_gc=True), compile.mode.OPT_FAST_COMPILE) # mode2=compile.Mode(gof.OpWiseCLinker(allow_gc=True), compile.mode.OPT_FAST_COMPILE)
if s is None: if s is None:
s=slice(0,49) s=slice(0,49)
...@@ -997,8 +1018,10 @@ class test_fusion(unittest.TestCase): ...@@ -997,8 +1018,10 @@ class test_fusion(unittest.TestCase):
print "times2 FAST_RUN optimisation without local_elemwise_fusion" print "times2 FAST_RUN optimisation without local_elemwise_fusion"
print times2, times2.min(), times2.max(), times2.sum() print times2, times2.min(), times2.max(), times2.sum()
d=times2/times1 d=times2/times1
# d.sort() # d.sort()
print "times2/times1",d,d.min(), d.max(), d.mean(), d.std() print "times2/times1",d,d.min(), d.max(), d.mean(), d.std()
finally:
mode2._optimizer = old_optimizer
def speed_fusion_gpu(self): def speed_fusion_gpu(self):
import theano_cuda_ndarray as tcn import theano_cuda_ndarray as tcn
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论