提交 aa37b4bb authored 作者: Pascal Lamblin's avatar Pascal Lamblin

Merge pull request #2208 from nouiz/tests

Crash fix and Tests fix
......@@ -1024,7 +1024,7 @@ static PyTypeObject lazylinker_ext_CLazyLinkerType = {
static PyObject * get_version(PyObject *dummy, PyObject *args)
{
PyObject *result = PyFloat_FromDouble(0.20);
PyObject *result = PyFloat_FromDouble(0.21);
return result;
}
......
......@@ -14,7 +14,8 @@ from theano.gof import cmodule
_logger = logging.getLogger('theano.gof.lazylinker_c')
force_compile = False
version = 0.20 # must match constant returned in function get_version()
version = 0.21 # must match constant returned in function get_version()
def try_import():
global lazylinker_ext
......@@ -22,6 +23,7 @@ def try_import():
import lazylinker_ext
del sys.path[0]
def try_reload():
sys.path[0:0] = [config.compiledir]
reload(lazylinker_ext)
......
......@@ -20,6 +20,7 @@ from theano import tensor
from theano.ifelse import ifelse
import theano
class TestCallbacks(unittest.TestCase):
"""
Test the VM_Linker's callback argument, which can be useful for debugging.
......@@ -34,7 +35,7 @@ class TestCallbacks(unittest.TestCase):
def test_callback(self):
a, b, c = tensor.scalars('abc')
f = function([a,b,c], (a + b) + c,
f = function([a, b, c], (a + b) + c,
mode=Mode(
optimizer=None,
linker=vm.VM_Linker(callback=self.callback)))
......@@ -44,13 +45,12 @@ class TestCallbacks(unittest.TestCase):
f(1, 2, 3)
assert sum(self.n_callbacks.values()) == len(f.maker.fgraph.toposort()) * 2
def test_callback_with_ifelse(self):
a, b, c = tensor.scalars('abc')
f = function([a,b,c], ifelse(a, 2*b, 2*c),
mode=Mode(
optimizer=None,
linker=vm.VM_Linker(callback=self.callback)))
f = function([a, b, c], ifelse(a, 2*b, 2*c),
mode=Mode(
optimizer=None,
linker=vm.VM_Linker(callback=self.callback)))
f(1, 2, 3)
assert self.n_callbacks['IfElse'] == 2
......@@ -71,6 +71,7 @@ def test_speed():
for d in xrange(depth):
z = (z+z)
return z
def time_numpy():
steps_a = 5
steps_b = 100
......@@ -78,10 +79,10 @@ def test_speed():
numpy_version(x, steps_a)
t0 = time.time()
#print numpy_version(x, steps_a)
# print numpy_version(x, steps_a)
t1 = time.time()
t2 = time.time()
#print numpy_version(x, steps_b)
# print numpy_version(x, steps_b)
t3 = time.time()
t_a = t1 - t0
t_b = t3 - t2
......@@ -94,18 +95,17 @@ def test_speed():
steps_a = 5
steps_b = 100
x = tensor.vector()
a = build_graph(x,steps_a)
b = build_graph(x,steps_b)
a = build_graph(x, steps_a)
b = build_graph(x, steps_b)
f_a = function([x], a,
mode=Mode(optimizer=None, linker=linker()),
#profile='f_a speed test %s'%name,
)
mode=Mode(optimizer=None, linker=linker()),
#profile='f_a speed test %s'%name,
)
f_b = function([x], b,
mode=Mode(optimizer=None, linker=linker()),
#profile='f_b speed test %s'%name,
)
mode=Mode(optimizer=None, linker=linker()),
#profile='f_b speed test %s'%name,
)
f_a([2.0, 3.0])
t0 = time.time()
......@@ -122,17 +122,18 @@ def test_speed():
t_b = t3 - t2
print "%s takes %f s/Kop" % (
name,
(1000*(t_b-t_a) / (steps_b - steps_a)))
name,
(1000*(t_b-t_a) / (steps_b - steps_a)))
time_linker('c|py', OpWiseCLinker)
time_linker('vmLinker', vm.VM_Linker)
time_linker('vmLinker_nogc', lambda : vm.VM_Linker(allow_gc=False))
time_linker('vmLinker_nogc', lambda: vm.VM_Linker(allow_gc=False))
if theano.config.cxx:
time_linker('vmLinker_CLOOP', lambda : vm.VM_Linker(allow_gc=False,
use_cloop=True))
time_linker('vmLinker_CLOOP', lambda: vm.VM_Linker(allow_gc=False,
use_cloop=True))
time_numpy()
def test_speed_lazy():
def build_graph(x, depth=5):
......@@ -148,17 +149,16 @@ def test_speed_lazy():
a = build_graph(x, steps_a)
b = build_graph(x, steps_b)
f_a = function([x], a,
mode=Mode(optimizer=None,
linker=linker()),
#profile='f_a lazy ifelse %s'%name,
)
mode=Mode(optimizer=None,
linker=linker()),
#profile='f_a lazy ifelse %s'%name,
)
f_b = function([x], b,
mode=Mode(optimizer=None,
linker=linker()),
#profile='f_b lazy ifelse %s'%name,
)
mode=Mode(optimizer=None,
linker=linker()),
#profile='f_b lazy ifelse %s'%name,
)
f_a([2.0])
t0 = time.time()
......@@ -179,15 +179,20 @@ def test_speed_lazy():
(1000*(t_b-t_a) / (steps_b - steps_a)))
time_linker('vmLinker', vm.VM_Linker)
time_linker('vmLinker_nogc', lambda : vm.VM_Linker(allow_gc=False))
time_linker('vmLinker_nogc', lambda: vm.VM_Linker(allow_gc=False))
if theano.config.cxx:
time_linker('vmLinker_C', lambda : vm.VM_Linker(allow_gc=False,
use_cloop=True))
time_linker('vmLinker_C', lambda: vm.VM_Linker(allow_gc=False,
use_cloop=True))
def test_allow_gc_cvm():
mode = theano.config.mode
if mode in ['DEBUG_MODE', 'DebugMode']:
mode = "FAST_RUN"
v = theano.tensor.vector()
f = theano.function([v], v + 1)
f = theano.function([v], v + 1, mode=mode)
f([1])
n = list(f.maker.fgraph.apply_nodes)[0].outputs[0]
assert f.fn.storage_map[n][0] is None
......@@ -262,8 +267,8 @@ if run_memory_usage_tests:
a = build_graph(x, steps_a)
f_a = function([x], a,
mode=Mode(optimizer=None,
linker=linker()))
mode=Mode(optimizer=None,
linker=linker()))
for i in xrange(100000):
f_a([2.0])
......@@ -296,8 +301,8 @@ if run_memory_usage_tests:
a = build_graph(x, steps_a)
f_a = function([x], a,
mode=Mode(optimizer=None,
linker=linker()))
mode=Mode(optimizer=None,
linker=linker()))
for i in xrange(500000):
f_a([2.0])
......
......@@ -1123,11 +1123,17 @@ def local_gpu_conv(node):
if theano.sandbox.cuda.dnn.dnn_available():
repl = local_gpu_conv_legacy.transform(node)
if repl:
n = repl[0].owner.inputs[0].owner
assert isinstance(n.op, GpuConv)
ret = theano.sandbox.cuda.dnn.local_conv_dnn.transform(n)
if isinstance(node.op, GpuFromHost):
gpu_conv = repl[0].owner
else:
gpu_conv = repl[0].owner.inputs[0].owner
assert isinstance(gpu_conv.op, GpuConv)
ret = theano.sandbox.cuda.dnn.local_conv_dnn.transform(gpu_conv)
if ret:
return [host_from_gpu(ret[0])]
if isinstance(node.op, GpuFromHost):
return ret
else:
return [host_from_gpu(ret[0])]
# If dnn isn't avail, the local_gpu_conv_legacy wil introduce the
# legacy opt. Then the local_conv_gemm will convert it to gemm
# opt.
......
......@@ -747,6 +747,10 @@ def test_dnn_subsample():
class TestConv2DGPU(unittest.TestCase):
conv_ops = (cuda.blas.GpuConv,
cuda.dnn.GpuDnnConvBase,
cuda.blas.BaseGpuCorrMM)
def test_logical_shapes(self):
seed_rng()
for stride in range(1, 4):
......@@ -773,7 +777,7 @@ class TestConv2DGPU(unittest.TestCase):
func = theano.function([a, A], image_estimate, mode=theano_mode)
#theano.printing.debugprint(func,)
assert any([isinstance(node.op, theano.sandbox.cuda.blas.GpuConv)
assert any([isinstance(node.op, self.conv_ops)
for node in func.maker.fgraph.toposort()])
a_in = numpy.random.randn(*featshp).astype("float32")
......
......@@ -396,7 +396,11 @@ def build_conv_nnet2_classif(use_gpu, isize, ksize, n_batch,
if use_gpu:
# Check that GpuConv is used
topo = train.maker.fgraph.toposort()
assert len([n for n in topo if isinstance(n.op, tcn.blas.GpuConv)]) > 0
conv_ops = (tcn.blas.GpuConv,
tcn.dnn.GpuDnnConvBase,
tcn.blas.BaseGpuCorrMM)
assert len([n for n in topo if isinstance(n.op, conv_ops)]) > 0
shape_target = (n_batch, n_out)
return train, params, shape_img, shape_target, mode
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论