提交 27a681ce authored 作者: Frédéric Bastien's avatar Frédéric Bastien 提交者: GitHub

Merge pull request #5652 from lamblin/fix_small_tests

A couple of test fixes
......@@ -75,6 +75,7 @@ THEANO_GPUARRAY_TESTS="theano/gpuarray/tests \
theano/sandbox/tests/test_rng_mrg.py:test_consistency_GPUA_serial \
theano/sandbox/tests/test_rng_mrg.py:test_consistency_GPUA_parallel \
theano/sandbox/tests/test_rng_mrg.py:test_GPUA_full_fill \
theano/scan_module/tests/test_scan.py:T_Scan_Gpuarray"
theano/scan_module/tests/test_scan.py:T_Scan_Gpuarray \
theano/scan_module/tests/test_scan_checkpoints.py:TestScanCheckpoint.test_memory"
FLAGS="init_gpu_device=$DEVICE,gpuarray.preallocate=1000,mode=FAST_RUN,on_opt_error=raise,on_shape_error=raise,cmodule.age_thresh_use=604800"
THEANO_FLAGS=${FLAGS} time nosetests --with-xunit --xunit-file=theanogpuarray_tests.xml ${THEANO_GPUARRAY_TESTS}
......@@ -251,8 +251,9 @@ class ProfileStats(object):
# param is called flag_time_thunks because most other attributes with time
# in the name are times *of* something, rather than configuration flags.
def __init__(self, atexit_print=True, flag_time_thunks=None, **kwargs):
if (config.profile and
def __init__(self, atexit_print=True, flag_time_thunks=None,
gpu_checks=True, **kwargs):
if (config.profile and gpu_checks and
((hasattr(theano, 'sandbox') and
hasattr(theano.sandbox, 'cuda') and
theano.sandbox.cuda.cuda_enabled) or (
......@@ -266,7 +267,7 @@ class ProfileStats(object):
" You must set the environment variable"
" CUDA_LAUNCH_BLOCKING to 1 to tell the CUDA driver to"
" synchronize the execution to get a meaningful profile.")
if (config.profile and
if (config.profile and gpu_checks and
hasattr(theano, 'gpuarray') and
theano.gpuarray.pygpu_activated and
not config.profiling.ignore_first_call):
......
......@@ -35,7 +35,7 @@ class Test_profiling(unittest.TestCase):
z += [T.outer(x[i], x[i + 1]).sum(axis=1) for i in range(len(x) - 1)]
z += [x[i] + x[i + 1] for i in range(len(x) - 1)]
p = theano.ProfileStats(False)
p = theano.ProfileStats(False, gpu_checks=False)
if theano.config.mode in ["DebugMode", "DEBUG_MODE", "FAST_COMPILE"]:
m = "FAST_RUN"
......@@ -87,7 +87,7 @@ class Test_profiling(unittest.TestCase):
z = ifelse(T.lt(a, b), x * 2, y * 2)
p = theano.ProfileStats(False)
p = theano.ProfileStats(False, gpu_checks=False)
if theano.config.mode in ["DebugMode", "DEBUG_MODE", "FAST_COMPILE"]:
m = "FAST_RUN"
......
......@@ -19,7 +19,7 @@ import theano
from theano import config
import theano.gof.cc
from six import itervalues
from six import itervalues, PY3
from theano.gof import graph
from theano.gof import utils
from theano.gof.cmodule import GCC_compiler
......@@ -35,6 +35,17 @@ __docformat__ = "restructuredtext en"
_logger = logging.getLogger('theano.gof.op.Op')
# Open file in "universal newline mode".
# In Python 2, this is done by calling open(..., 'U'), but this is
# deprected in Python 3 (where we would need to pass "newline=None",
# which is the default).
if PY3:
_open_u = open
else:
def _open_u(file):
return open(file, 'U')
class CLinkerObject(object):
"""
Standard elements of an Op or Type used with the CLinker.
......@@ -1297,7 +1308,7 @@ class COp(Op):
self.func_codes = []
for func_file in func_files:
# U (universal) will convert all new lines format to \n.
with open(func_file, 'U') as f:
with _open_u(func_file) as f:
self.func_codes.append(f.read())
# If both the old section markers and the new section markers are
......
......@@ -10,7 +10,6 @@ from __future__ import absolute_import, print_function, division
from . import link
from collections import defaultdict
import logging
import os
import sys
import time
import warnings
......@@ -757,21 +756,6 @@ class VM_Linker(link.LocalLinker):
associated to self, else, a new VM_Linker associated to fgraph.
"""
if ((config.profile or config.print_global_stats) and
((hasattr(theano, 'sandbox') and
hasattr(theano.sandbox, 'cuda') and
theano.sandbox.cuda.cuda_enabled) or
(hasattr(theano, 'gpuarray') and
theano.gpuarray.pygpu_activated))):
if os.environ.get('CUDA_LAUNCH_BLOCKING', '0') != '1':
raise Exception(
"You are running the Theano profiler with CUDA enabled."
" Theano GPU ops execution is asynchronous by default."
" So by default, the profile is useless."
" You must set the environment variable"
" CUDA_LAUNCH_BLOCKING to 1 to tell the CUDA driver to"
" synchronize the execution to get a meaningful profile.")
if no_recycling is None:
no_recycling = []
if self.fgraph is not None and self.fgraph is not fgraph:
......
......@@ -511,6 +511,8 @@ def test_pooling_opt_arbitrary_dimensions():
def test_pooling_empty_batch():
if not dnn.dnn_available(test_ctx_name):
raise SkipTest(dnn.dnn_available.msg)
img_shp = (0, 5, 6, 8)
img = T.ftensor4('img')
......
......@@ -863,7 +863,7 @@ def pydotprint(fct, outfile=None,
if profile:
time = profile.apply_time.get(node, 0)
# second, %fct time in profiler
if profile.fct_callcount == 0:
if profile.fct_callcount == 0 or profile.fct_call_time == 0:
pf = 0
else:
pf = time * 100 / profile.fct_call_time
......
......@@ -53,12 +53,13 @@ class TestScanCheckpoint(unittest.TestCase):
"""Test that scan_checkpoint reduces memory usage."""
if None not in theano.gpuarray.type.list_contexts():
return unittest.SkipTest('Requires gpuarray backend.')
from theano.gpuarray.tests.config import mode_with_gpu # noqa
f = theano.function(inputs=[self.A, self.k],
outputs=self.grad_A)
outputs=self.grad_A, mode=mode_with_gpu)
f_check = theano.function(inputs=[self.A, self.k],
outputs=self.grad_A_check)
outputs=self.grad_A_check, mode=mode_with_gpu)
free_gmem = theano.gpuarray.type._context_reg[None].free_gmem
data = numpy.ones(free_gmem / 3000, dtype=numpy.float32)
data = numpy.ones(free_gmem // 3000, dtype=numpy.float32)
# Check that it works with the checkpoints
f_check(data, 1000)
# Check that the basic scan fails in that case
......
......@@ -91,7 +91,7 @@ def test_pydotprint_profile():
raise SkipTest('pydot not available')
A = tensor.matrix()
prof = theano.compile.ProfileStats(atexit_print=False)
prof = theano.compile.ProfileStats(atexit_print=False, gpu_checks=False)
f = theano.function([A], A + 1, profile=prof)
theano.printing.pydotprint(f, print_output_file=False)
f([[1]])
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论