提交 799e97dd authored 作者: abergeron's avatar abergeron

Merge pull request #1920 from nouiz/fix_tests

Fix tests in buildbot and memory leak with allow_gc=False
...@@ -6,23 +6,30 @@ import theano ...@@ -6,23 +6,30 @@ import theano
import theano.tensor as T import theano.tensor as T
import StringIO import StringIO
def test_profiling(): def test_profiling():
old1 = theano.config.profile old1 = theano.config.profile
old2 = theano.config.profile_memory old2 = theano.config.profile_memory
try:
theano.config.profile = True theano.config.profile = True
theano.config.profile_memory = True theano.config.profile_memory = True
x = T.dvector("x") x = T.dvector("x")
y = T.dvector("y") y = T.dvector("y")
z = x + y z = x + y
f = theano.function([x, y], z, profile=True, name="test_profiling") p = theano.ProfileStats(False)
output = f([1, 2, 3, 4],[1, 1, 1, 1]) if theano.config.mode in ["DebugMode", "DEBUG_MODE"]:
m = "FAST_RUN"
else:
m = None
f = theano.function([x, y], z, profile=p, name="test_profiling",
mode=m)
output = f([1, 2, 3, 4], [1, 1, 1, 1])
buf = StringIO.StringIO() buf = StringIO.StringIO()
f.profile.summary(buf) f.profile.summary(buf)
finally:
theano.config.profile = old1 theano.config.profile = old1
theano.config.profile_memory = old2 theano.config.profile_memory = old2
......
...@@ -3289,7 +3289,7 @@ class GpuContiguous(GpuOp): ...@@ -3289,7 +3289,7 @@ class GpuContiguous(GpuOp):
Py_INCREF(%(z)s); Py_INCREF(%(z)s);
} else if ((NULL == %(z)s)""" % locals() } else if ((NULL == %(z)s)""" % locals()
for i in xrange(len(node.inputs[0].type.broadcastable)): for i in xrange(node.inputs[0].type.ndim):
str += "\n|| (CudaNdarray_HOST_DIMS(%(input)s)[%(i)s] != CudaNdarray_HOST_DIMS(%(z)s)[%(i)s])" % locals() str += "\n|| (CudaNdarray_HOST_DIMS(%(input)s)[%(i)s] != CudaNdarray_HOST_DIMS(%(z)s)[%(i)s])" % locals()
str += """ str += """
|| !CudaNdarray_is_c_contiguous(%(z)s)) || !CudaNdarray_is_c_contiguous(%(z)s))
......
...@@ -1409,12 +1409,13 @@ class Assert(T.Op): ...@@ -1409,12 +1409,13 @@ class Assert(T.Op):
check = "\n".join(check) check = "\n".join(check)
return """ return """
%(check)s %(check)s
Py_XDECREF(%(out)s);
%(out)s = %(value)s; %(out)s = %(value)s;
Py_INCREF(%(value)s); Py_INCREF(%(value)s);
""" % locals() """ % locals()
def c_code_cache_version(self): def c_code_cache_version(self):
return (1, 0) return (1, 1)
def infer_shape(self, node, input_shapes): def infer_shape(self, node, input_shapes):
return [input_shapes[0]] return [input_shapes[0]]
......
...@@ -20,30 +20,35 @@ def test_no_reuse(): ...@@ -20,30 +20,35 @@ def test_no_reuse():
return return
assert not 'should not get here' assert not 'should not get here'
def test_gc_never_pickles_temporaries(): def test_gc_never_pickles_temporaries():
x = T.dvector() x = T.dvector()
#print >> sys.stderr, 'BUILDING GRAPH' #print >> sys.stderr, 'BUILDING GRAPH'
for i in xrange(2): #TODO: 30 causes like LONG compilation due to MERGE for i in xrange(2): # TODO: 30 causes like LONG compilation due to MERGE
if i : if i:
r = r + r/10 r = r + r/10
else: else:
r = x r = x
optimizer=None optimizer = None
optimizer='fast_run' optimizer = 'fast_run'
for f_linker, g_linker in [ for f_linker, g_linker in [
(theano.PerformLinker(allow_gc = True), theano.PerformLinker(allow_gc=False)), (theano.PerformLinker(allow_gc=True),
(theano.OpWiseCLinker(allow_gc = True), theano.OpWiseCLinker(allow_gc=False))]: theano.PerformLinker(allow_gc=False)),
(theano.OpWiseCLinker(allow_gc=True),
theano.OpWiseCLinker(allow_gc=False))]:
#f_linker has garbage collection #f_linker has garbage collection
#g_linker has no garbage collection #g_linker has no garbage collection
#print >> sys.stderr, 'COMPILING' #print >> sys.stderr, 'COMPILING'
f = theano.function([x], r,mode=theano.Mode(optimizer=optimizer, linker=f_linker)) f = theano.function([x], r, mode=theano.Mode(optimizer=optimizer,
g = theano.function([x], r,mode=theano.Mode(optimizer=optimizer, linker=g_linker)) linker=f_linker))
g = theano.function([x], r, mode=theano.Mode(optimizer=optimizer,
linker=g_linker))
len_pre_f = len(cPickle.dumps(f)) len_pre_f = len(cPickle.dumps(f))
len_pre_g = len(cPickle.dumps(g)) len_pre_g = len(cPickle.dumps(g))
...@@ -70,7 +75,6 @@ def test_gc_never_pickles_temporaries(): ...@@ -70,7 +75,6 @@ def test_gc_never_pickles_temporaries():
assert c(f) == c(f) # some sanity checks on the pickling mechanism assert c(f) == c(f) # some sanity checks on the pickling mechanism
assert c(g) == c(g) # some sanity checks on the pickling mechanism assert c(g) == c(g) # some sanity checks on the pickling mechanism
# now run the function once to create temporaries within the no-gc # now run the function once to create temporaries within the no-gc
# linker # linker
f(numpy.ones(100, dtype='float64')) f(numpy.ones(100, dtype='float64'))
...@@ -86,28 +90,32 @@ def test_gc_never_pickles_temporaries(): ...@@ -86,28 +90,32 @@ def test_gc_never_pickles_temporaries():
# allow_gc should leave the function un-changed by calling # allow_gc should leave the function un-changed by calling
assert len_pre_f == len_post_f assert len_pre_f == len_post_f
#assert that g() didn't cause g to grow #assert that g() didn't cause g to grow because temporaries
# because temporaries that weren't collected shouldn't be pickled anyway # that weren't collected shouldn't be pickled anyway
assert len_post_f == len_post_g, (f_linker, len_post_f, len_post_g) assert len_post_f == len_post_g, (f_linker, len_post_f, len_post_g)
def test_merge_opt_runtime(): def test_merge_opt_runtime():
"""In the original merge optimization, the following graph took like caused the MERGE """In the original merge optimization, the following graph took
optimizer to exhibit really bad performance (quadratic? exponential?) like caused the MERGE optimizer to exhibit really bad performance
(quadratic? exponential?)
Ironically, there is actually no merging to do in this graph. Ironically, there is actually no merging to do in this graph.
""" """
x = T.dvector() x = T.dvector()
for i in xrange(50): for i in xrange(50):
if i : if i:
r = r + r/10 r = r + r/10
else: else:
r = x r = x
t = time.time() t = time.time()
f = theano.function([x], r, mode='FAST_COMPILE') f = theano.function([x], r, mode='FAST_COMPILE')
# FAST_RUN does in-place optimizer which requires a lot of toposorting, which is actually # FAST_RUN does in-place optimizer which requires a lot of
# pretty slow at the moment. This test was designed to test MergeOptimizer... so I'm # toposorting, which is actually pretty slow at the moment. This
# leaving toposort optimizations for a later date. # test was designed to test MergeOptimizer... so I'm leaving
# toposort optimizations for a later date.
dt = time.time() - t dt = time.time() - t
assert dt < 5.0 #it should never take longer than 5 seconds to compile this graph # it should never take longer than 5 seconds to compile this graph
assert dt < 5.0
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论