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