提交 ab1d2d48 authored 作者: abergeron's avatar abergeron

Merge pull request #2524 from nouiz/tests

Faster tests in DebugMode and more resistent to rounding difference.
......@@ -5,14 +5,14 @@ Easy Installation of an Optimized Theano on Current Ubuntu
For Ubuntu 11.10 through 14.04:
.. code-block: bash
.. code-block:: bash
sudo apt-get install python-numpy python-scipy python-dev python-pip python-nose g++ libopenblas-dev git
sudo pip install Theano
For Ubuntu 11.04:
.. code-block: bash
.. code-block:: bash
sudo apt-get install python-numpy python-scipy python-dev python-pip python-nose g++ git libatlas3gf-base libatlas-dev
sudo pip install Theano
......@@ -71,7 +71,7 @@ If you would like, instead, to install the bleeding edge Theano (from github)
such that you can edit and contribute to Theano, replace the `pip install Theano`
command with:
.. code-block: bash
.. code-block:: bash
git clone git://github.com/Theano/Theano.git
cd Theano
......@@ -85,7 +85,7 @@ If you would like to install Theano in a VirtualEnv, you will want to pass the
`--system-site-packages` flag when creating the VirtualEnv so that it will pick up
the system-provided `Numpy` and `SciPy`.
.. code-block: bash
.. code-block:: bash
virtualenv --system-site-packages -p python2.7 theano-env
source theano-env/bin/activate
......@@ -166,7 +166,7 @@ Updating Bleeding Edge Installs
Change to the Theano directory and run:
.. code-block: bash
.. code-block:: bash
git pull
......
......@@ -3065,7 +3065,8 @@ CudaNdarray_ptr_int_size(PyObject* _unused, PyObject* args)
PyErr_SetString(PyExc_RuntimeError, "error copying data to from memory");
return NULL;
}
return Py_BuildValue("iiii", gpu_sizes[0], sizeof(float*), sizeof(int), gpu_sizes[1]);
return Py_BuildValue("iiii", (int) gpu_sizes[0], (int)sizeof(float*),
(int)sizeof(int), (int) gpu_sizes[1]);
}
static int cublas_init();
......
......@@ -313,8 +313,8 @@ def local_gpu_split(node):
if host_input.owner and isinstance(host_input.owner.op, tensor.Split):
split_node = host_input.owner
new_op = GpuSplit(split_node.op.len_splits)
return [new_op(gpu_from_host(split_node.inputs[0]),
*split_node.inputs[1:])]
return new_op(gpu_from_host(split_node.inputs[0]),
*split_node.inputs[1:])
return False
......@@ -1742,7 +1742,7 @@ def get_device_type_sizes():
cuda_ndarray = theano.sandbox.cuda.cuda_ndarray.cuda_ndarray
t = cuda_ndarray.ptr_int_size()
gpu_ptr_size, cpu_ptr_size, int_size, gpu_int_size = t
assert int_size == gpu_int_size
assert int_size == gpu_int_size, (int_size, gpu_int_size)
del gpu_int_size
del t
except Exception, e:
......@@ -1751,7 +1751,9 @@ def get_device_type_sizes():
"This could cause less GpuElemwise fused together.\n"
"%s") % e)
rval = get_device_type_sizes.rval = locals()
rval = get_device_type_sizes.rval = dict(gpu_ptr_size=gpu_ptr_size,
cpu_ptr_size=cpu_ptr_size,
int_size=int_size)
return rval
......
import unittest
import numpy
import copy
import theano
from theano.tests import unittest_tools as utt
......@@ -86,7 +85,6 @@ class TestConv2dFFT(unittest.TestCase):
assert sum(isinstance(n.op, theano.sandbox.cuda.fftconv.CuFFTOp)
for n in topo) == 2, topo
res_ref = f_ref()
res_fft = f_fft()
......@@ -130,11 +128,11 @@ class TestConv2dFFT(unittest.TestCase):
inputs = shared(inputs_val)
filters = shared(filters_val)
conv = theano.tensor.nnet.conv.conv2d(inputs, filters, version='no_fft')
conv = theano.tensor.nnet.conv.conv2d(inputs, filters,
version='no_fft')
mode = mode_with_gpu.including('conv_fft_valid')
f_ref = theano.function([], conv)
f_fft = theano.function([], conv, mode=mode)
# make sure we that no CuFFTOp has been inserted
......@@ -158,7 +156,6 @@ class TestConv2dFFT(unittest.TestCase):
mode = mode_with_gpu.including('conv_fft_full')
f_ref = theano.function([], conv)
f_fft = theano.function([], conv, mode=mode)
# make sure we that no CuFFTOp has been inserted
......@@ -178,15 +175,16 @@ class TestConv3dFFT(unittest.TestCase):
bias = shared(numpy.zeros(filters_shape[0]).astype('float32'))
# Flip filter as conv3D compute correlation
filters_flip = filters[:,::-1,::-1,::-1,:]
#filters_flip = filters
filters_flip = filters[:, ::-1, ::-1, ::-1, :]
# filters_flip = filters
conv_ref = theano.tensor.nnet.conv3D(V=inputs, W=filters_flip,
b=bias, d=(1,1,1))
b=bias, d=(1, 1, 1))
conv_fft = theano.sandbox.cuda.fftconv.conv3d_fft(inputs.dimshuffle(0, 4, 1, 2, 3),
filters.dimshuffle(0, 4, 1, 2, 3),
border_mode = "valid",
pad_last_dim = pad)
conv_fft = theano.sandbox.cuda.fftconv.conv3d_fft(
inputs.dimshuffle(0, 4, 1, 2, 3),
filters.dimshuffle(0, 4, 1, 2, 3),
border_mode="valid",
pad_last_dim=pad)
conv_fft = conv_fft.dimshuffle(0, 2, 3, 4, 1)
f_ref = theano.function([], conv_ref, mode="FAST_RUN")
......@@ -198,8 +196,6 @@ class TestConv3dFFT(unittest.TestCase):
res_fft = f_fft()
utt.assert_allclose(res_ref, res_fft, rtol=1e-05, atol=1e-05)
def run_conv_full(self, inputs_shape, filters_shape, pad=False):
inputs_val = numpy.random.random(inputs_shape).astype('float32')
filters_val = numpy.random.random(filters_shape).astype('float32')
......@@ -208,14 +204,15 @@ class TestConv3dFFT(unittest.TestCase):
filters = shared(filters_val)
bias = shared(numpy.zeros(filters_shape[4]).astype('float32'))
conv_ref = theano.tensor.nnet.convTransp3D(W=filters, b=bias, d=(1,1,1),
H=inputs)
conv_ref = theano.tensor.nnet.convTransp3D(
W=filters, b=bias, d=(1, 1, 1),
H=inputs)
filters = filters.dimshuffle(4, 0, 1, 2, 3)
inputs = inputs.dimshuffle(0, 4, 1, 2, 3)
conv_fft = theano.sandbox.cuda.fftconv.conv3d_fft(inputs, filters,
border_mode = "full",
pad_last_dim = pad)
border_mode="full",
pad_last_dim=pad)
conv_fft = conv_fft.dimshuffle(0, 2, 3, 4, 1)
f_ref = theano.function([], conv_ref)
......@@ -233,6 +230,7 @@ class TestConv3dFFT(unittest.TestCase):
self.run_conv_valid(inputs_shape=(16, 20, 32, 15, 1),
filters_shape=(10, 6, 12, 4, 1),
pad=True)
def test_full(self):
self.run_conv_full(inputs_shape=(16, 15, 21, 16, 10),
filters_shape=(10, 6, 12, 4, 1),
......@@ -253,7 +251,7 @@ class TestConv3dFFT(unittest.TestCase):
bias = shared(numpy.zeros(filters_shape[0]).astype('float32'))
conv = theano.tensor.nnet.conv3D(V=inputs, W=filters,
b=bias, d=(1,1,1))
b=bias, d=(1, 1, 1))
mode = mode_with_gpu.including('conv3d_fft')
mode.check_py_code = False
......@@ -265,16 +263,19 @@ class TestConv3dFFT(unittest.TestCase):
assert sum(isinstance(n.op, theano.sandbox.cuda.fftconv.CuFFTOp)
for n in topo) == 2
res_ref = f_ref()
res_fft = f_fft()
utt.assert_allclose(res_ref, res_fft)
def test_opt_convgrad3d_fft(self):
inputs_shape = (16, 20, 32, 16, 1)
filters_shape = (10, 6, 12, 4, 1)
dCdH_shape = (16, 15, 21, 13, 10)
inputs_shape = (2, 17, 15, 16, 1)
filters_shape = (10, 6, 7, 4, 1)
dCdH_shape = (inputs_shape[0],
inputs_shape[1] - filters_shape[1] + 1,
inputs_shape[2] - filters_shape[2] + 1,
inputs_shape[3] - filters_shape[3] + 1,
filters_shape[0])
inputs_val = numpy.random.random(inputs_shape).astype('float32')
dCdH_val = numpy.random.random(dCdH_shape).astype('float32')
......@@ -284,7 +285,7 @@ class TestConv3dFFT(unittest.TestCase):
conv = theano.tensor.nnet.convGrad3D(V=inputs, dCdH=dCdH,
WShape=filters_shape,
d=(1,1,1))
d=(1, 1, 1))
mode = mode_with_gpu.including('convgrad3d_fft')
mode.check_py_code = False
......@@ -296,16 +297,14 @@ class TestConv3dFFT(unittest.TestCase):
assert sum(isinstance(n.op, theano.sandbox.cuda.fftconv.CuFFTOp)
for n in topo) == 2
res_ref = f_ref()
res_fft = f_fft()
utt.assert_allclose(res_ref, res_fft, rtol=1e-04, atol=1e-04)
def test_opt_convtransp3d_fft(self):
inputs_shape = (16, 15, 21, 12, 10)
filters_shape = (10, 6, 12, 4, 1)
inputs_shape = (2, 9, 16, 12, 10)
filters_shape = (10, 3, 8, 4, 1)
inputs_val = numpy.random.random(inputs_shape).astype('float32')
filters_val = numpy.random.random(filters_shape).astype('float32')
......@@ -314,7 +313,7 @@ class TestConv3dFFT(unittest.TestCase):
inputs = shared(inputs_val)
filters = shared(filters_val)
conv = theano.tensor.nnet.convTransp3D(W=filters, b=bias, d=(1,1,1),
conv = theano.tensor.nnet.convTransp3D(W=filters, b=bias, d=(1, 1, 1),
H=inputs)
mode = mode_with_gpu.including('convtransp3d_fft')
......@@ -326,9 +325,7 @@ class TestConv3dFFT(unittest.TestCase):
assert sum(isinstance(n.op, theano.sandbox.cuda.fftconv.CuFFTOp)
for n in topo) == 2
res_ref = f_ref()
res_fft = f_fft()
utt.assert_allclose(res_ref, res_fft, rtol=1e-04, atol=1e-04)
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论