提交 22b943c3 authored 作者: Frédéric Bastien's avatar Frédéric Bastien

Merge pull request #4249 from lamblin/fix_windows

Fix windows test failures
...@@ -1944,7 +1944,7 @@ def local_gpu_downsample_factor_max_grad_grad(node): ...@@ -1944,7 +1944,7 @@ def local_gpu_downsample_factor_max_grad_grad(node):
'padding', 'mode') 'padding', 'mode')
if (node.op.padding != (0, 0) or if (node.op.padding != (0, 0) or
node.op.mode != 'max' or node.op.mode != 'max' or
node.op.st != (1, 1)): node.op.st != node.op.ds):
return return
x, z, gx = node.inputs x, z, gx = node.inputs
if (x.owner and isinstance(x.owner.op, HostFromGpu)): if (x.owner and isinstance(x.owner.op, HostFromGpu)):
......
...@@ -845,10 +845,15 @@ def conv_grad(mode, bs, ch, nf, rImg1, rImg2, rFlt1, rFlt2, subsample, op): ...@@ -845,10 +845,15 @@ def conv_grad(mode, bs, ch, nf, rImg1, rImg2, rFlt1, rFlt2, subsample, op):
outputs.extend([corr_op_dik, conv_op_dik, outputs.extend([corr_op_dik, conv_op_dik,
corr_op_dki, conv_op_dki]) corr_op_dki, conv_op_dki])
# TODO: fix when the abstractconv tests can pass debug mode. if not theano.config.blas.ldflags:
mode = theano_mode # Some of the operations are not transferred to the GPU,
if theano.config.mode == 'DEBUG_MODE': # and withoug BLAS, the abstract Op will not be optimized
mode = theano.compile.mode.get_mode('FAST_RUN').including('gpu') # to CorrMM either, so we have to accept the use of the
# slow Python convolution in that case.
mode = theano_mode.excluding('AbstractConvCheck')
else:
mode = theano_mode
f = theano.function([i, k], outputs, mode=mode) f = theano.function([i, k], outputs, mode=mode)
allvals = f(npy_img, npy_kern) allvals = f(npy_img, npy_kern)
......
import logging import logging
import os
import sys
from nose.plugins.skip import SkipTest from nose.plugins.skip import SkipTest
import numpy
from itertools import chain, product from itertools import chain, product
import six.moves.cPickle as pickle import six.moves.cPickle as pickle
import os from six import StringIO
from six import reraise
import numpy
import theano import theano
from six import StringIO
import theano.tensor as T import theano.tensor as T
import theano.tests.unittest_tools as utt import theano.tests.unittest_tools as utt
from theano.sandbox.neighbours import images2neibs from theano.sandbox.neighbours import images2neibs
...@@ -390,7 +393,17 @@ def test_old_pool_interface(): ...@@ -390,7 +393,17 @@ def test_old_pool_interface():
testfile_dir = os.path.dirname(os.path.realpath(__file__)) testfile_dir = os.path.dirname(os.path.realpath(__file__))
fname = 'old_pool_interface.pkl' fname = 'old_pool_interface.pkl'
with open(os.path.join(testfile_dir, fname), 'rb') as fp: with open(os.path.join(testfile_dir, fname), 'rb') as fp:
pickle.load(fp) try:
pickle.load(fp)
except ImportError:
# Windows sometimes fail with nonsensical errors like:
# ImportError: No module named type
# ImportError: No module named copy_reg
# when "type" and "copy_reg" are builtin modules.
if sys.platform == 'win32':
exc_type, exc_value, exc_trace = sys.exc_info()
reraise(SkipTest, exc_value, exc_trace)
raise
def test_pooling3d(): def test_pooling3d():
......
import os.path import os.path
import sys
from six import reraise
from nose.plugins.skip import SkipTest from nose.plugins.skip import SkipTest
from nose.tools import assert_raises from nose.tools import assert_raises
...@@ -40,7 +42,18 @@ def test_unpickle_cudandarray_as_numpy_ndarray_flag0(): ...@@ -40,7 +42,18 @@ def test_unpickle_cudandarray_as_numpy_ndarray_flag0():
else: else:
u = CompatUnpickler(fp) u = CompatUnpickler(fp)
if cuda_available: if cuda_available:
mat = u.load() try:
mat = u.load()
except ImportError:
# Windows sometimes fail with nonsensical errors like:
# ImportError: No module named type
# ImportError: No module named copy_reg
# when "type" and "copy_reg" are builtin modules.
if sys.platform == 'win32':
exc_type, exc_value, exc_trace = sys.exc_info()
reraise(SkipTest, exc_value, exc_trace)
raise
assert isinstance(mat, CudaNdarray) assert isinstance(mat, CudaNdarray)
assert numpy.asarray(mat)[0] == -42.0 assert numpy.asarray(mat)[0] == -42.0
else: else:
...@@ -62,7 +75,17 @@ def test_unpickle_cudandarray_as_numpy_ndarray_flag1(): ...@@ -62,7 +75,17 @@ def test_unpickle_cudandarray_as_numpy_ndarray_flag1():
u = CompatUnpickler(fp, encoding="latin1") u = CompatUnpickler(fp, encoding="latin1")
else: else:
u = CompatUnpickler(fp) u = CompatUnpickler(fp)
mat = u.load() try:
mat = u.load()
except ImportError:
# Windows sometimes fail with nonsensical errors like:
# ImportError: No module named type
# ImportError: No module named copy_reg
# when "type" and "copy_reg" are builtin modules.
if sys.platform == 'win32':
exc_type, exc_value, exc_trace = sys.exc_info()
reraise(SkipTest, exc_value, exc_trace)
raise
assert isinstance(mat, numpy.ndarray) assert isinstance(mat, numpy.ndarray)
assert mat[0] == -42.0 assert mat[0] == -42.0
......
...@@ -6,6 +6,8 @@ regular test file. ...@@ -6,6 +6,8 @@ regular test file.
""" """
import os import os
import sys
from six import reraise
from nose.plugins.skip import SkipTest from nose.plugins.skip import SkipTest
from nose.tools import assert_raises from nose.tools import assert_raises
...@@ -69,7 +71,17 @@ def test_unpickle_gpuarray_as_numpy_ndarray_flag2(): ...@@ -69,7 +71,17 @@ def test_unpickle_gpuarray_as_numpy_ndarray_flag2():
u = CompatUnpickler(fp, encoding="latin1") u = CompatUnpickler(fp, encoding="latin1")
else: else:
u = CompatUnpickler(fp) u = CompatUnpickler(fp)
mat = u.load() try:
mat = u.load()
except ImportError:
# Windows sometimes fail with nonsensical errors like:
# ImportError: No module named type
# ImportError: No module named copy_reg
# when "type" and "copy_reg" are builtin modules.
if sys.platform == 'win32':
exc_type, exc_value, exc_trace = sys.exc_info()
reraise(SkipTest, exc_value, exc_trace)
raise
assert isinstance(mat, numpy.ndarray) assert isinstance(mat, numpy.ndarray)
assert mat[0] == -42.0 assert mat[0] == -42.0
......
import copy import copy
import os
import sys
from six import reraise
from nose.plugins.skip import SkipTest
import numpy import numpy
import theano import theano
...@@ -8,7 +12,6 @@ from theano.sandbox import multinomial ...@@ -8,7 +12,6 @@ from theano.sandbox import multinomial
from theano.compile.mode import get_default_mode, predefined_linkers from theano.compile.mode import get_default_mode, predefined_linkers
import theano.sandbox.cuda as cuda import theano.sandbox.cuda as cuda
import theano.tests.unittest_tools as utt import theano.tests.unittest_tools as utt
import os
from theano.compat import PY3 from theano.compat import PY3
from theano.misc.pkl_utils import CompatUnpickler from theano.misc.pkl_utils import CompatUnpickler
...@@ -91,7 +94,18 @@ def test_n_samples_compatibility(): ...@@ -91,7 +94,18 @@ def test_n_samples_compatibility():
u = CompatUnpickler(pkl_file, encoding="latin1") u = CompatUnpickler(pkl_file, encoding="latin1")
else: else:
u = CompatUnpickler(pkl_file) u = CompatUnpickler(pkl_file)
X, samples = u.load() try:
X, samples = u.load()
except ImportError:
# Windows sometimes fail with nonsensical errors like:
# ImportError: No module named type
# ImportError: No module named copy_reg
# when "type" and "copy_reg" are builtin modules.
if sys.platform == 'win32':
exc_type, exc_value, exc_trace = sys.exc_info()
reraise(SkipTest, exc_value, exc_trace)
raise
f = theano.function([X], samples) f = theano.function([X], samples)
res = f(numpy.random.randn(20, 10)) res = f(numpy.random.randn(20, 10))
assert numpy.all(res.sum(axis=1) == 1) assert numpy.all(res.sum(axis=1) == 1)
......
...@@ -1151,7 +1151,13 @@ class IsNan(FixedLogicalComparison): ...@@ -1151,7 +1151,13 @@ class IsNan(FixedLogicalComparison):
(z,) = outputs (z,) = outputs
if node.inputs[0].type in complex_types: if node.inputs[0].type in complex_types:
raise NotImplementedError() raise NotImplementedError()
return "%(z)s = isnan(%(x)s);" % locals() # Windows tries to be different and sometimes return -1, but we want
# to be consistent with numpy (which returns True), hence the "abs".
return "%(z)s = abs(isnan(%(x)s));" % locals()
def c_code_cache_version(self):
scalarop_version = super(IsNan, self).c_code_cache_version()
return tuple(scalarop_version) + (2,)
isnan = IsNan() isnan = IsNan()
......
...@@ -522,6 +522,7 @@ def bilinear_upsampling(input, ...@@ -522,6 +522,7 @@ def bilinear_upsampling(input,
# first and last col # first and last col
concat_mat = T.concatenate((concat_mat[:, :, :, :1], concat_mat, concat_mat = T.concatenate((concat_mat[:, :, :, :1], concat_mat,
concat_mat[:, :, :, -1:]), axis=3) concat_mat[:, :, :, -1:]), axis=3)
concat_col = col + 2
pad = 2 * ratio - (ratio - 1) // 2 - 1 pad = 2 * ratio - (ratio - 1) // 2 - 1
...@@ -533,7 +534,8 @@ def bilinear_upsampling(input, ...@@ -533,7 +534,8 @@ def bilinear_upsampling(input,
np.newaxis, :, np.newaxis, :,
np.newaxis], np.newaxis],
input_shape=(up_bs, 1, input_shape=(up_bs, 1,
row * ratio, col), row * ratio,
concat_col),
filter_shape=(1, 1, None, 1), filter_shape=(1, 1, None, 1),
border_mode=(pad, 0), border_mode=(pad, 0),
subsample=(ratio, 1), subsample=(ratio, 1),
......
...@@ -401,7 +401,7 @@ def local_abstractconv_check(node): ...@@ -401,7 +401,7 @@ def local_abstractconv_check(node):
'do you have a BLAS library installed Theano can link against?' % 'do you have a BLAS library installed Theano can link against?' %
node.op.__class__.__name__) node.op.__class__.__name__)
optdb.register('AbstracConvCheck', optdb.register('AbstractConvCheck',
opt.in2out(local_abstractconv_check, opt.in2out(local_abstractconv_check,
name="AbstractConvCheck"), name="AbstractConvCheck"),
48.7, 'fast_compile', 'fast_run') 48.7, 'fast_compile', 'fast_run')
...@@ -538,6 +538,11 @@ class TestConvTypes(unittest.TestCase): ...@@ -538,6 +538,11 @@ class TestConvTypes(unittest.TestCase):
class TestBilinearUpsampling(unittest.TestCase): class TestBilinearUpsampling(unittest.TestCase):
# If BLAS is not available on CPU, then we accept the fallback to the
# slow Python implementation for that test.
compile_mode = theano.compile.mode.get_default_mode()
if not theano.config.blas.ldflags:
compile_mode = compile_mode.excluding('AbstractConvCheck')
def numerical_kernel_1D(self, ratio): def numerical_kernel_1D(self, ratio):
"""Gets numerical 1D kernel for bilinear upsampling""" """Gets numerical 1D kernel for bilinear upsampling"""
...@@ -678,7 +683,7 @@ class TestBilinearUpsampling(unittest.TestCase): ...@@ -678,7 +683,7 @@ class TestBilinearUpsampling(unittest.TestCase):
bilin_mat = bilinear_upsampling(input=input_x, ratio=ratio, bilin_mat = bilinear_upsampling(input=input_x, ratio=ratio,
batch_size=1, num_input_channels=1, batch_size=1, num_input_channels=1,
use_1D_kernel=True) use_1D_kernel=True)
f = theano.function([], bilin_mat) f = theano.function([], bilin_mat, mode=self.compile_mode)
up_mat_2d = self.get_upsampled_twobytwo_mat(input_x, ratio) up_mat_2d = self.get_upsampled_twobytwo_mat(input_x, ratio)
utt.assert_allclose(f(), up_mat_2d, rtol=1e-06) utt.assert_allclose(f(), up_mat_2d, rtol=1e-06)
...@@ -697,8 +702,8 @@ class TestBilinearUpsampling(unittest.TestCase): ...@@ -697,8 +702,8 @@ class TestBilinearUpsampling(unittest.TestCase):
mat_2D = bilinear_upsampling(input=input_x, ratio=5, mat_2D = bilinear_upsampling(input=input_x, ratio=5,
batch_size=5, num_input_channels=4, batch_size=5, num_input_channels=4,
use_1D_kernel=False) use_1D_kernel=False)
f_1D = theano.function([], mat_1D) f_1D = theano.function([], mat_1D, mode=self.compile_mode)
f_2D = theano.function([], mat_2D) f_2D = theano.function([], mat_2D, mode=self.compile_mode)
utt.assert_allclose(f_1D(), f_2D(), rtol=1e-06) utt.assert_allclose(f_1D(), f_2D(), rtol=1e-06)
# checking upsampling with ratio 8 # checking upsampling with ratio 8
...@@ -709,6 +714,6 @@ class TestBilinearUpsampling(unittest.TestCase): ...@@ -709,6 +714,6 @@ class TestBilinearUpsampling(unittest.TestCase):
mat_2D = bilinear_upsampling(input=input_x, ratio=8, mat_2D = bilinear_upsampling(input=input_x, ratio=8,
batch_size=12, num_input_channels=11, batch_size=12, num_input_channels=11,
use_1D_kernel=False) use_1D_kernel=False)
f_1D = theano.function([], mat_1D) f_1D = theano.function([], mat_1D, mode=self.compile_mode)
f_2D = theano.function([], mat_2D) f_2D = theano.function([], mat_2D, mode=self.compile_mode)
utt.assert_allclose(f_1D(), f_2D(), rtol=1e-06) utt.assert_allclose(f_1D(), f_2D(), rtol=1e-06)
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论