提交 2ef606f6 authored 作者: Pascal Lamblin's avatar Pascal Lamblin

Enable slow Python when no CPU BLAS in some tests

上级 cb1184d4
...@@ -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)
......
...@@ -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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论