提交 4c012319 authored 作者: Roy Xue's avatar Roy Xue 提交者: Lijun Xue

Update previous test_profiling

上级 bed110ff
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
Test of memory profiling Test of memory profiling
""" """
import unittest
import StringIO import StringIO
import numpy import numpy
...@@ -11,94 +13,96 @@ import theano.tensor as T ...@@ -11,94 +13,96 @@ import theano.tensor as T
from theano.ifelse import ifelse from theano.ifelse import ifelse
def test_profiling(): class Test_profiling(unittest.TestCase):
def test_profiling(self):
config1 = theano.config.profile config1 = theano.config.profile
config2 = theano.config.profile_memory config2 = theano.config.profile_memory
config3 = theano.config.profiling.min_peak_memory config3 = theano.config.profiling.min_peak_memory
try: try:
theano.config.profile = True theano.config.profile = True
theano.config.profile_memory = True theano.config.profile_memory = True
theano.config.profiling.min_peak_memory = True theano.config.profiling.min_peak_memory = True
x = [T.fvector("val%i" % i) for i in range(3)] x = [T.fvector("val%i" % i) for i in range(3)]
z = [] z = []
z += [T.outer(x[i], x[i + 1]).sum(axis=1) for i in range(len(x) - 1)] z += [T.outer(x[i], x[i + 1]).sum(axis=1) for i in range(len(x) - 1)]
z += [x[i] + x[i + 1] for i in range(len(x) - 1)] z += [x[i] + x[i + 1] for i in range(len(x) - 1)]
p = theano.ProfileStats(False) p = theano.ProfileStats(False)
if theano.config.mode in ["DebugMode", "DEBUG_MODE", "FAST_COMPILE"]: if theano.config.mode in ["DebugMode", "DEBUG_MODE", "FAST_COMPILE"]:
m = "FAST_RUN" m = "FAST_RUN"
else: else:
m = None m = None
f = theano.function(x, z, profile=p, name="test_profiling", f = theano.function(x, z, profile=p, name="test_profiling",
mode=m) mode=m)
inp = [numpy.arange(1024, dtype='float32') + 1 for i in range(len(x))] inp = [numpy.arange(1024, dtype='float32') + 1 for i in range(len(x))]
output = f(*inp) output = f(*inp)
buf = StringIO.StringIO() buf = StringIO.StringIO()
f.profile.summary(buf) f.profile.summary(buf)
# regression testing for future algo speed up # regression testing for future algo speed up
the_string = buf.getvalue() the_string = buf.getvalue()
lines1 = [l for l in the_string.split("\n") if "Max if linker" in l] lines1 = [l for l in the_string.split("\n") if "Max if linker" in l]
lines2 = [l for l in the_string.split("\n") if "Minimum peak" in l] lines2 = [l for l in the_string.split("\n") if "Minimum peak" in l]
if theano.config.device == 'cpu': if theano.config.device == 'cpu':
assert "Max if linker=cvm(default): 4112KB (8204KB)" in the_string, ( assert "Max if linker=cvm(default): 4112KB (8204KB)" in the_string, (
lines1, lines2) lines1, lines2)
assert "Minimum peak from all valid apply node order is 4104KB" in the_string, ( assert "Minimum peak from all valid apply node order is 4104KB" in the_string, (
lines1, lines2) lines1, lines2)
else: else:
assert "Max if linker=cvm(default): 8220KB (8220KB)" in the_string, ( assert "Max if linker=cvm(default): 8220KB (8220KB)" in the_string, (
lines1, lines2) lines1, lines2)
assert "Minimum peak from all valid apply node order is 4116KB" in the_string, ( assert "Minimum peak from all valid apply node order is 4116KB" in the_string, (
lines1, lines2) lines1, lines2)
finally: finally:
theano.config.profile = config1 theano.config.profile = config1
theano.config.profile_memory = config2 theano.config.profile_memory = config2
theano.config.profiling.min_peak_memory = config3 theano.config.profiling.min_peak_memory = config3
def test_ifelse(): def test_ifelse(self):
config1 = theano.config.profile config1 = theano.config.profile
config2 = theano.config.profile_memory config2 = theano.config.profile_memory
try: try:
theano.config.profile = True theano.config.profile = True
theano.config.profile_memory = True theano.config.profile_memory = True
a, b = T.scalars('a', 'b') a, b = T.scalars('a', 'b')
x, y = T.scalars('x', 'y') x, y = T.scalars('x', 'y')
z = ifelse(T.lt(a, b), x * 2, y * 2) z = ifelse(T.lt(a, b), x * 2, y * 2)
p = theano.ProfileStats(False) p = theano.ProfileStats(False)
if theano.config.mode in ["DebugMode", "DEBUG_MODE", "FAST_COMPILE"]: if theano.config.mode in ["DebugMode", "DEBUG_MODE", "FAST_COMPILE"]:
m = "FAST_RUN" m = "FAST_RUN"
else: else:
m = None m = None
f_ifelse = theano.function([a, b, x, y], z, profile=p, name="test_ifelse", f_ifelse = theano.function([a, b, x, y], z, profile=p, name="test_ifelse",
mode=m) mode=m)
val1 = 0. val1 = 0.
val2 = 1. val2 = 1.
big_mat1 = 10 big_mat1 = 10
big_mat2 = 11 big_mat2 = 11
out = f_ifelse(val1, val2, big_mat1, big_mat2) out = f_ifelse(val1, val2, big_mat1, big_mat2)
finally: finally:
theano.config.profile = config1 theano.config.profile = config1
theano.config.profile_memory = config2 theano.config.profile_memory = config2
if __name__ == '__main__': if __name__ == '__main__':
test_profiling() Test_profiling.test_profiling()
test_ifelse() Test_profiling.test_ifelse()
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论