提交 3adaa82f authored 作者: abergeron's avatar abergeron

Merge pull request #4042 from adbrebs/warn_flags

[WIP] Move flags declarations and warn user if unknown flags
...@@ -36,11 +36,11 @@ logging_default_handler.setFormatter(logging_default_formatter) ...@@ -36,11 +36,11 @@ logging_default_handler.setFormatter(logging_default_formatter)
theano_logger.addHandler(logging_default_handler) theano_logger.addHandler(logging_default_handler)
theano_logger.setLevel(logging.WARNING) theano_logger.setLevel(logging.WARNING)
from theano.configdefaults import config
# Version information. # Version information.
from theano.version import version as __version__ from theano.version import version as __version__
from theano.configdefaults import config
# This is the api version for ops that generate C code. External ops # This is the api version for ops that generate C code. External ops
# might need manual changes if this number goes up. An undefined # might need manual changes if this number goes up. An undefined
# __api_version__ can be understood to mean api version 0. # __api_version__ can be understood to mean api version 0.
......
...@@ -23,8 +23,7 @@ from six import string_types, iteritems, itervalues ...@@ -23,8 +23,7 @@ from six import string_types, iteritems, itervalues
from six.moves import StringIO, xrange from six.moves import StringIO, xrange
from theano.gof import (graph, utils, link, ops_with_inner_function) from theano.gof import (graph, utils, link, ops_with_inner_function)
from theano.gof.link import raise_with_op from theano.gof.link import raise_with_op
from theano.configparser import (config, AddConfigVar, BoolParam, IntParam, from theano.configparser import (config, AddConfigVar, IntParam, StrParam)
StrParam)
from theano.compile.function_module import ( from theano.compile.function_module import (
FunctionMaker, Function, infer_reuse_pattern, FunctionMaker, Function, infer_reuse_pattern,
SymbolicInputKit, SymbolicOutput, Supervisor, std_fgraph) SymbolicInputKit, SymbolicOutput, Supervisor, std_fgraph)
...@@ -33,39 +32,6 @@ from theano.compile.ops import OutputGuard ...@@ -33,39 +32,6 @@ from theano.compile.ops import OutputGuard
__docformat__ = "restructuredtext en" __docformat__ = "restructuredtext en"
AddConfigVar('DebugMode.patience',
"Optimize graph this many times to detect inconsistency",
IntParam(10, lambda i: i > 0),
in_c_key=False)
AddConfigVar('DebugMode.check_c',
"Run C implementations where possible",
BoolParam(bool(theano.config.cxx)),
in_c_key=False)
AddConfigVar('DebugMode.check_py',
"Run Python implementations where possible",
BoolParam(True),
in_c_key=False)
AddConfigVar('DebugMode.check_finite',
"True -> complain about NaN/Inf results",
BoolParam(True),
in_c_key=False)
AddConfigVar('DebugMode.check_strides',
("Check that Python- and C-produced ndarrays have same strides. "
"On difference: (0) - ignore, (1) warn, or (2) raise error"),
IntParam(0, lambda i: i in (0, 1, 2)),
in_c_key=False)
AddConfigVar('DebugMode.warn_input_not_reused',
("Generate a warning when destroy_map or view_map says that an "
"op works inplace, but the op did not reuse the input for its "
"output."),
BoolParam(True),
in_c_key=False)
def is_valid_check_preallocated_output_param(param): def is_valid_check_preallocated_output_param(param):
if not isinstance(param, string_types): if not isinstance(param, string_types):
......
...@@ -10,29 +10,13 @@ import numpy ...@@ -10,29 +10,13 @@ import numpy
import theano import theano
from theano import gof from theano import gof
import theano.gof.vm import theano.gof.vm
from theano.configparser import config, AddConfigVar, StrParam from theano.configparser import config
from theano.compile.ops import _output_guard from theano.compile.ops import _output_guard
from six import string_types from six import string_types
_logger = logging.getLogger('theano.compile.mode') _logger = logging.getLogger('theano.compile.mode')
AddConfigVar('optimizer_excluding',
("When using the default mode, we will remove optimizer with "
"these tags. Separate tags with ':'."),
StrParam("", allow_override=False),
in_c_key=False)
AddConfigVar('optimizer_including',
("When using the default mode, we will add optimizer with "
"these tags. Separate tags with ':'."),
StrParam("", allow_override=False),
in_c_key=False)
AddConfigVar('optimizer_requiring',
("When using the default mode, we will require optimizer with "
"these tags. Separate tags with ':'."),
StrParam("", allow_override=False),
in_c_key=False)
def check_equal(x, y): def check_equal(x, y):
""" """
......
...@@ -6,32 +6,11 @@ from six.moves import StringIO ...@@ -6,32 +6,11 @@ from six.moves import StringIO
import numpy as np import numpy as np
import theano import theano
from theano.configparser import config, AddConfigVar, BoolParam, EnumStr from theano.configparser import config
import theano.tensor as T import theano.tensor as T
import theano.sandbox.cuda as cuda import theano.sandbox.cuda as cuda
from theano.compile import Mode from theano.compile import Mode
AddConfigVar('NanGuardMode.nan_is_error',
"Default value for nan_is_error",
BoolParam(True),
in_c_key=False)
AddConfigVar('NanGuardMode.inf_is_error',
"Default value for inf_is_error",
BoolParam(True),
in_c_key=False)
AddConfigVar('NanGuardMode.big_is_error',
"Default value for big_is_error",
BoolParam(True),
in_c_key=False)
AddConfigVar('NanGuardMode.action',
"What NanGuardMode does when it finds a problem",
EnumStr('raise', 'warn', 'pdb'),
in_c_key=False)
logger = logging.getLogger("theano.compile.nanguardmode") logger = logging.getLogger("theano.compile.nanguardmode")
......
...@@ -11,7 +11,7 @@ from six import string_types, iteritems, itervalues ...@@ -11,7 +11,7 @@ from six import string_types, iteritems, itervalues
from theano.compile.mode import (Mode, register_mode, from theano.compile.mode import (Mode, register_mode,
predefined_modes, predefined_linkers, predefined_modes, predefined_linkers,
predefined_optimizers) predefined_optimizers)
from theano.configparser import config, AddConfigVar, IntParam, BoolParam from theano.configparser import config
from theano.compile.function_module import FunctionMaker from theano.compile.function_module import FunctionMaker
from .profiling import ProfileStats from .profiling import ProfileStats
...@@ -20,28 +20,6 @@ run_cthunk = None # Will be imported only when needed. ...@@ -20,28 +20,6 @@ run_cthunk = None # Will be imported only when needed.
import_time = time.time() import_time = time.time()
AddConfigVar('ProfileMode.n_apply_to_print',
"Number of apply instances to print by default",
IntParam(15, lambda i: i > 0),
in_c_key=False)
AddConfigVar('ProfileMode.n_ops_to_print',
"Number of ops to print by default",
IntParam(20, lambda i: i > 0),
in_c_key=False)
AddConfigVar('ProfileMode.min_memory_size',
"For the memory profile, do not print apply nodes if the size "
"of their outputs (in bytes) is lower then this threshold",
IntParam(1024, lambda i: i >= 0),
in_c_key=False)
AddConfigVar('ProfileMode.profile_memory',
"""Enable profiling of memory used by Theano functions""",
BoolParam(False),
in_c_key=False)
class Profile_Maker(FunctionMaker): class Profile_Maker(FunctionMaker):
def create(self, input_storage=None, trustme=False, storage_map=None): def create(self, input_storage=None, trustme=False, storage_map=None):
ret = super(Profile_Maker, self).create(input_storage, trustme, ret = super(Profile_Maker, self).create(input_storage, trustme,
......
...@@ -37,51 +37,6 @@ config = theano.config ...@@ -37,51 +37,6 @@ config = theano.config
_atexit_print_list = [] _atexit_print_list = []
_atexit_registered = False _atexit_registered = False
AddConfigVar('profiling.time_thunks',
"""Time individual thunks when profiling""",
BoolParam(True),
in_c_key=False)
AddConfigVar('profiling.n_apply',
"Number of Apply instances to print by default",
IntParam(20, lambda i: i > 0),
in_c_key=False)
AddConfigVar('profiling.n_ops',
"Number of Ops to print by default",
IntParam(20, lambda i: i > 0),
in_c_key=False)
AddConfigVar('profiling.output_line_width',
"Max line width for the profiling output",
IntParam(512, lambda i: i > 0),
in_c_key=False)
AddConfigVar('profiling.min_memory_size',
"""For the memory profile, do not print Apply nodes if the size
of their outputs (in bytes) is lower than this threshold""",
IntParam(1024, lambda i: i >= 0),
in_c_key=False)
AddConfigVar('profiling.min_peak_memory',
"""The min peak memory usage of the order""",
BoolParam(False),
in_c_key=False)
AddConfigVar('profiling.destination',
"""
File destination of the profiling output
""",
StrParam('stderr'),
in_c_key=False)
AddConfigVar('profiling.debugprint',
"""
Do a debugprint of the profiled functions
""",
BoolParam(False),
in_c_key=False)
def _atexit_print_fn(): def _atexit_print_fn():
""" """
......
...@@ -549,7 +549,7 @@ class Test_pfunc(unittest.TestCase): ...@@ -549,7 +549,7 @@ class Test_pfunc(unittest.TestCase):
def test_default_updates_input(self): def test_default_updates_input(self):
x = shared(0) x = shared(0)
y = shared(1) y = shared(1)
if theano.gof.python_int_bitwidth() == 32: if theano.configdefaults.python_int_bitwidth() == 32:
a = iscalar('a') a = iscalar('a')
else: else:
a = lscalar('a') a = lscalar('a')
......
...@@ -18,7 +18,7 @@ class Test_SharedVariable(unittest.TestCase): ...@@ -18,7 +18,7 @@ class Test_SharedVariable(unittest.TestCase):
assert shared(7, dtype='float64').type == Scalar('float64') assert shared(7, dtype='float64').type == Scalar('float64')
else: else:
if theano.gof.python_int_bitwidth() == 32: if theano.configdefaults.python_int_bitwidth() == 32:
assert shared(7).type == theano.tensor.iscalar, shared(7).type assert shared(7).type == theano.tensor.iscalar, shared(7).type
else: else:
assert shared(7).type == theano.tensor.lscalar, shared(7).type assert shared(7).type == theano.tensor.lscalar, shared(7).type
......
import errno
import os import os
import sys import sys
import logging import logging
import numpy
import platform
import textwrap
import re
import socket
import struct
import warnings
import theano import theano
from theano.configparser import (AddConfigVar, BoolParam, ConfigParam, EnumStr, from theano.configparser import (AddConfigVar, BoolParam, ConfigParam, EnumStr,
FloatParam, IntParam, StrParam, FloatParam, IntParam, StrParam,
TheanoConfigParser) TheanoConfigParser, THEANO_FLAGS_DICT)
from theano.misc.cpucount import cpuCount from theano.misc.cpucount import cpuCount
from theano.misc.windows import call_subprocess_Popen from theano.misc.windows import call_subprocess_Popen, output_subprocess_Popen
_logger = logging.getLogger('theano.configdefaults') _logger = logging.getLogger('theano.configdefaults')
...@@ -316,9 +325,9 @@ AddConfigVar('dnn.conv.precision', ...@@ -316,9 +325,9 @@ AddConfigVar('dnn.conv.precision',
def default_dnn_path(suffix): def default_dnn_path(suffix):
def f(suffix=suffix): def f(suffix=suffix):
if config.cuda.root == '': if theano.config.cuda.root == '':
return '' return ''
return os.path.join(config.cuda.root, suffix) return os.path.join(theano.config.cuda.root, suffix)
return f return f
AddConfigVar('dnn.include_path', AddConfigVar('dnn.include_path',
...@@ -860,3 +869,571 @@ AddConfigVar('unittests.rseed', ...@@ -860,3 +869,571 @@ AddConfigVar('unittests.rseed',
"Special value 'random' means using a seed of None.", "Special value 'random' means using a seed of None.",
StrParam(666, is_valid=good_seed_param), StrParam(666, is_valid=good_seed_param),
in_c_key=False) in_c_key=False)
AddConfigVar('NanGuardMode.nan_is_error',
"Default value for nan_is_error",
BoolParam(True),
in_c_key=False)
AddConfigVar('NanGuardMode.inf_is_error',
"Default value for inf_is_error",
BoolParam(True),
in_c_key=False)
AddConfigVar('NanGuardMode.big_is_error',
"Default value for big_is_error",
BoolParam(True),
in_c_key=False)
AddConfigVar('NanGuardMode.action',
"What NanGuardMode does when it finds a problem",
EnumStr('raise', 'warn', 'pdb'),
in_c_key=False)
AddConfigVar('ProfileMode.n_apply_to_print',
"Number of apply instances to print by default",
IntParam(15, lambda i: i > 0),
in_c_key=False)
AddConfigVar('ProfileMode.n_ops_to_print',
"Number of ops to print by default",
IntParam(20, lambda i: i > 0),
in_c_key=False)
AddConfigVar('ProfileMode.min_memory_size',
"For the memory profile, do not print apply nodes if the size "
"of their outputs (in bytes) is lower then this threshold",
IntParam(1024, lambda i: i >= 0),
in_c_key=False)
AddConfigVar('ProfileMode.profile_memory',
"""Enable profiling of memory used by Theano functions""",
BoolParam(False),
in_c_key=False)
AddConfigVar('optimizer_excluding',
("When using the default mode, we will remove optimizer with "
"these tags. Separate tags with ':'."),
StrParam("", allow_override=False),
in_c_key=False)
AddConfigVar('optimizer_including',
("When using the default mode, we will add optimizer with "
"these tags. Separate tags with ':'."),
StrParam("", allow_override=False),
in_c_key=False)
AddConfigVar('optimizer_requiring',
("When using the default mode, we will require optimizer with "
"these tags. Separate tags with ':'."),
StrParam("", allow_override=False),
in_c_key=False)
AddConfigVar('DebugMode.patience',
"Optimize graph this many times to detect inconsistency",
IntParam(10, lambda i: i > 0),
in_c_key=False)
AddConfigVar('DebugMode.check_c',
"Run C implementations where possible",
BoolParam(
lambda: bool(theano.config.cxx)),
in_c_key=False)
AddConfigVar('DebugMode.check_py',
"Run Python implementations where possible",
BoolParam(True),
in_c_key=False)
AddConfigVar('DebugMode.check_finite',
"True -> complain about NaN/Inf results",
BoolParam(True),
in_c_key=False)
AddConfigVar('DebugMode.check_strides',
("Check that Python- and C-produced ndarrays have same strides. "
"On difference: (0) - ignore, (1) warn, or (2) raise error"),
IntParam(0, lambda i: i in (0, 1, 2)),
in_c_key=False)
AddConfigVar('DebugMode.warn_input_not_reused',
("Generate a warning when destroy_map or view_map says that an "
"op works inplace, but the op did not reuse the input for its "
"output."),
BoolParam(True),
in_c_key=False)
AddConfigVar('profiling.time_thunks',
"""Time individual thunks when profiling""",
BoolParam(True),
in_c_key=False)
AddConfigVar('profiling.n_apply',
"Number of Apply instances to print by default",
IntParam(20, lambda i: i > 0),
in_c_key=False)
AddConfigVar('profiling.n_ops',
"Number of Ops to print by default",
IntParam(20, lambda i: i > 0),
in_c_key=False)
AddConfigVar('profiling.output_line_width',
"Max line width for the profiling output",
IntParam(512, lambda i: i > 0),
in_c_key=False)
AddConfigVar('profiling.min_memory_size',
"""For the memory profile, do not print Apply nodes if the size
of their outputs (in bytes) is lower than this threshold""",
IntParam(1024, lambda i: i >= 0),
in_c_key=False)
AddConfigVar('profiling.min_peak_memory',
"""The min peak memory usage of the order""",
BoolParam(False),
in_c_key=False)
AddConfigVar('profiling.destination',
"""
File destination of the profiling output
""",
StrParam('stderr'),
in_c_key=False)
AddConfigVar('profiling.debugprint',
"""
Do a debugprint of the profiled functions
""",
BoolParam(False),
in_c_key=False)
AddConfigVar('optdb.position_cutoff',
'Where to stop eariler during optimization. It represent the'
' position of the optimizer where to stop.',
FloatParam(numpy.inf),
in_c_key=False)
AddConfigVar('optdb.max_use_ratio',
'A ratio that prevent infinite loop in EquilibriumOptimizer.',
FloatParam(5),
in_c_key=False)
AddConfigVar('gcc.cxxflags',
"Extra compiler flags for gcc",
StrParam(""))
AddConfigVar(
'cmodule.mac_framework_link',
"If set to True, breaks certain MacOS installations with the infamous "
"Bus Error",
BoolParam(False))
AddConfigVar('cmodule.warn_no_version',
"If True, will print a warning when compiling one or more Op "
"with C code that can't be cached because there is no "
"c_code_cache_version() function associated to at least one of "
"those Ops.",
BoolParam(False),
in_c_key=False)
AddConfigVar('cmodule.remove_gxx_opt',
"If True, will remove the -O* parameter passed to g++."
"This is useful to debug in gdb modules compiled by Theano."
"The parameter -g is passed by default to g++",
BoolParam(False))
AddConfigVar('cmodule.compilation_warning',
"If True, will print compilation warnings.",
BoolParam(False))
AddConfigVar('cmodule.preload_cache',
"If set to True, will preload the C module cache at import time",
BoolParam(False, allow_override=False),
in_c_key=False)
AddConfigVar(
'metaopt.verbose',
"Enable verbose output for meta optimizers",
theano.configparser.BoolParam(False),
in_c_key=False)
AddConfigVar('profile',
"If VM should collect profile information",
BoolParam(False),
in_c_key=False)
AddConfigVar('profile_optimizer',
"If VM should collect optimizer profile information",
BoolParam(False),
in_c_key=False)
AddConfigVar('profile_memory',
"If VM should collect memory profile information and print it",
BoolParam(False),
in_c_key=False)
def filter_vm_lazy(val):
if val == 'False' or val is False:
return False
elif val == 'True' or val is True:
return True
elif val == 'None' or val is None:
return None
else:
raise ValueError('Valid values for an vm.lazy parameter '
'should be None, False or True, not `%s`.' % val)
AddConfigVar('vm.lazy',
"Useful only for the vm linkers. When lazy is None,"
" auto detect if lazy evaluation is needed and use the apropriate"
" version. If lazy is True/False, force the version used between"
" Loop/LoopGC and Stack.",
ConfigParam('None', filter_vm_lazy),
in_c_key=False)
AddConfigVar(
'warn.identify_1pexp_bug',
'Warn if Theano versions prior to 7987b51 (2011-12-18) could have '
'yielded a wrong result due to a bug in the is_1pexp function',
BoolParam(warn_default('0.4.1')),
in_c_key=False)
AddConfigVar('on_shape_error',
"warn: print a warning and use the default"
" value. raise: raise an error",
theano.configparser.EnumStr("warn", "raise"),
in_c_key=False)
AddConfigVar(
'tensor.insert_inplace_optimizer_validate_nb',
"-1: auto, if graph have less then 500 nodes 1, else 10",
theano.configparser.IntParam(-1),
in_c_key=False)
AddConfigVar('experimental.local_alloc_elemwise',
"DEPRECATED: If True, enable the experimental"
" optimization local_alloc_elemwise."
" Generates error if not True. Use"
" optimizer_excluding=local_alloc_elemwise"
" to dsiable.",
theano.configparser.BoolParam(
True,
is_valid=lambda x: x
),
in_c_key=False)
# False could make the graph faster but not as safe.
AddConfigVar(
'experimental.local_alloc_elemwise_assert',
"When the local_alloc_elemwise is applied, add"
" an assert to highlight shape errors.",
theano.configparser.BoolParam(True),
in_c_key=False)
AddConfigVar('scan.allow_gc',
"Allow/disallow gc inside of Scan (default: False)",
BoolParam(False))
AddConfigVar('scan.allow_output_prealloc',
"Allow/disallow memory preallocation for outputs inside of scan "
"(default: True)",
BoolParam(True))
AddConfigVar('pycuda.init',
"""If True, always initialize PyCUDA when Theano want to
initilize the GPU. Currently, we must always initialize
PyCUDA before Theano do it. Setting this flag to True,
ensure that, but always import PyCUDA. It can be done
manually by importing theano.misc.pycuda_init before theano
initialize the GPU device.
""",
BoolParam(False),
in_c_key=False)
AddConfigVar('cublas.lib',
"""Name of the cuda blas library for the linker.""",
StrParam('cublas'))
AddConfigVar('lib.cnmem',
"""Do we enable CNMeM or not (a faster CUDA memory allocator).
The parameter represent the start size (in MB or % of
total GPU memory) of the memory pool.
0: not enabled.
0 < N <= 1: % of the total GPU memory (clipped to .985 for driver memory)
> 0: use that number of MB of memory.
""",
# We should not mix both allocator, so we can't override
FloatParam(0, lambda i: i >= 0, allow_override=False),
in_c_key=False)
AddConfigVar('compile.wait',
"""Time to wait before retrying to aquire the compile lock.""",
IntParam(5, lambda i: i > 0, allow_override=False),
in_c_key=False)
def _timeout_default():
return theano.config.compile.wait * 24
AddConfigVar('compile.timeout',
"""In seconds, time that a process will wait before deciding to
override an existing lock. An override only happens when the existing
lock is held by the same owner *and* has not been 'refreshed' by this
owner for more than this period. Refreshes are done every half timeout
period for running processes.""",
IntParam(_timeout_default, lambda i: i >= 0,
allow_override=False),
in_c_key=False)
try:
p_out = output_subprocess_Popen([config.cxx, '-dumpversion'])
gcc_version_str = p_out[0].strip().decode()
except OSError:
# Typically means gcc cannot be found.
gcc_version_str = 'GCC_NOT_FOUND'
def local_bitwidth():
"""
Return 32 for 32bit arch, 64 for 64bit arch.
By "architecture", we mean the size of memory pointers (size_t in C),
*not* the size of long int, as it can be different.
"""
# Note that according to Python documentation, `platform.architecture()` is
# not reliable on OS X with universal binaries.
# Also, sys.maxsize does not exist in Python < 2.6.
# 'P' denotes a void*, and the size is expressed in bytes.
return struct.calcsize('P') * 8
def python_int_bitwidth():
"""
Return the bit width of Python int (C long int).
Note that it can be different from the size of a memory pointer.
"""
# 'l' denotes a C long int, and the size is expressed in bytes.
return struct.calcsize('l') * 8
compiledir_format_dict = {
"platform": platform.platform(),
"processor": platform.processor(),
"python_version": platform.python_version(),
"python_bitwidth": local_bitwidth(),
"python_int_bitwidth": python_int_bitwidth(),
"theano_version": theano.__version__,
"numpy_version": numpy.__version__,
"gxx_version": gcc_version_str.replace(" ", "_"),
"hostname": socket.gethostname()}
def short_platform(r=None, p=None):
"""
Return a safe shorter version of platform.platform().
The old default Theano compiledir used platform.platform in
it. This use the platform.version() as a substring. This is too
specific as it contain the full kernel number and package
version. This cause the compiledir to change each time there is a
new linux kernel update. This function remove the part of platform
that are too precise.
If we have something else then expected, we do nothing. So this
should be safe on other OS.
Some example if we use platform.platform() direction. On the same
OS, with just some kernel updates.
compiledir_Linux-2.6.32-504.el6.x86_64-x86_64-with-redhat-6.6-Santiago-x86_64-2.6.6-64
compiledir_Linux-2.6.32-431.29.2.el6.x86_64-x86_64-with-redhat-6.5-Santiago-x86_64-2.6.6-64
compiledir_Linux-2.6.32-431.23.3.el6.x86_64-x86_64-with-redhat-6.5-Santiago-x86_64-2.6.6-64
compiledir_Linux-2.6.32-431.20.3.el6.x86_64-x86_64-with-redhat-6.5-Santiago-x86_64-2.6.6-64
compiledir_Linux-2.6.32-431.17.1.el6.x86_64-x86_64-with-redhat-6.5-Santiago-x86_64-2.6.6-64
compiledir_Linux-2.6.32-431.11.2.el6.x86_64-x86_64-with-redhat-6.5-Santiago-x86_64-2.6.6-64
compiledir_Linux-2.6.32-431.el6.x86_64-x86_64-with-redhat-6.5-Santiago-x86_64-2.6.6-64
compiledir_Linux-2.6.32-358.23.2.el6.x86_64-x86_64-with-redhat-6.4-Santiago-x86_64-2.6.6-64
compiledir_Linux-2.6.32-358.6.2.el6.x86_64-x86_64-with-redhat-6.4-Santiago-x86_64-2.6.6-64
compiledir_Linux-2.6.32-358.6.1.el6.x86_64-x86_64-with-redhat-6.4-Santiago-x86_64-2.6.6-64
compiledir_Linux-2.6.32-358.2.1.el6.x86_64-x86_64-with-redhat-6.4-Santiago-x86_64-2.6.6-64
compiledir_Linux-2.6.32-358.el6.x86_64-x86_64-with-redhat-6.4-Santiago-x86_64-2.6.6-64
compiledir_Linux-2.6.32-358.el6.x86_64-x86_64-with-redhat-6.4-Santiago-x86_64-2.6.6
compiledir_Linux-2.6.32-279.14.1.el6.x86_64-x86_64-with-redhat-6.4-Santiago-x86_64-2.6.6
compiledir_Linux-2.6.32-279.14.1.el6.x86_64-x86_64-with-redhat-6.3-Santiago-x86_64-2.6.6
compiledir_Linux-2.6.32-279.5.2.el6.x86_64-x86_64-with-redhat-6.3-Santiago-x86_64-2.6.6
compiledir_Linux-2.6.32-220.13.1.el6.x86_64-x86_64-with-redhat-6.3-Santiago-x86_64-2.6.6
compiledir_Linux-2.6.32-220.13.1.el6.x86_64-x86_64-with-redhat-6.2-Santiago-x86_64-2.6.6
compiledir_Linux-2.6.32-220.7.1.el6.x86_64-x86_64-with-redhat-6.2-Santiago-x86_64-2.6.6
compiledir_Linux-2.6.32-220.4.1.el6.x86_64-x86_64-with-redhat-6.2-Santiago-x86_64-2.6.6
We suppose the version are ``X.Y[.*]-(digit)*(anything)*``. We keep ``X.Y``
and don't keep less important digit in the part before ``-`` and we remove
the leading digit after the first ``-``.
If the information don't fit that pattern, we do not modify platform.
"""
if r is None:
r = platform.release()
if p is None:
p = platform.platform()
sp = r.split('-')
if len(sp) < 2:
return p
# For the split before the first -, we remove all learning digit:
kernel_version = sp[0].split('.')
if len(kernel_version) <= 2:
# kernel version should always have at least 3 number.
# If not, it use another semantic, so don't change it.
return p
sp[0] = '.'.join(kernel_version[:2])
# For the split after the first -, we remove leading non-digit value.
rest = sp[1].split('.')
while len(rest):
if rest[0].isdigit():
del rest[0]
else:
break
sp[1] = '.'.join(rest)
# For sp[2:], we don't change anything.
sr = '-'.join(sp)
p = p.replace(r, sr)
return p
compiledir_format_dict['short_platform'] = short_platform()
compiledir_format_keys = ", ".join(sorted(compiledir_format_dict.keys()))
default_compiledir_format = ("compiledir_%(short_platform)s-%(processor)s-"
"%(python_version)s-%(python_bitwidth)s")
AddConfigVar("compiledir_format",
textwrap.fill(textwrap.dedent("""\
Format string for platform-dependent compiled
module subdirectory (relative to base_compiledir).
Available keys: %s. Defaults to %r.
""" % (compiledir_format_keys, default_compiledir_format))),
StrParam(default_compiledir_format, allow_override=False),
in_c_key=False)
def default_compiledirname():
formatted = theano.config.compiledir_format % compiledir_format_dict
safe = re.sub("[\(\)\s,]+", "_", formatted)
return safe
def filter_base_compiledir(path):
# Expand '~' in path
return os.path.expanduser(str(path))
def filter_compiledir(path):
# Expand '~' in path
path = os.path.expanduser(path)
# Turn path into the 'real' path. This ensures that:
# 1. There is no relative path, which would fail e.g. when trying to
# import modules from the compile dir.
# 2. The path is stable w.r.t. e.g. symlinks (which makes it easier
# to re-use compiled modules).
path = os.path.realpath(path)
if os.access(path, os.F_OK): # Do it exist?
if not os.access(path, os.R_OK | os.W_OK | os.X_OK):
# If it exist we need read, write and listing access
raise ValueError(
"compiledir '%s' exists but you don't have read, write"
" or listing permissions." % path)
else:
try:
os.makedirs(path, 0o770) # read-write-execute for user and group
except OSError as e:
# Maybe another parallel execution of theano was trying to create
# the same directory at the same time.
if e.errno != errno.EEXIST:
raise ValueError(
"Unable to create the compiledir directory"
" '%s'. Check the permissions." % path)
# PROBLEM: sometimes the initial approach based on
# os.system('touch') returned -1 for an unknown reason; the
# alternate approach here worked in all cases... it was weird.
# No error should happen as we checked the permissions.
init_file = os.path.join(path, '__init__.py')
if not os.path.exists(init_file):
try:
open(init_file, 'w').close()
except IOError as e:
if os.path.exists(init_file):
pass # has already been created
else:
e.args += ('%s exist? %s' % (path, os.path.exists(path)),)
raise
return path
def get_home_dir():
"""
Return location of the user's home directory.
"""
home = os.getenv('HOME')
if home is None:
# This expanduser usually works on Windows (see discussion on
# theano-users, July 13 2010).
home = os.path.expanduser('~')
if home == '~':
# This might happen when expanduser fails. Although the cause of
# failure is a mystery, it has been seen on some Windows system.
home = os.getenv('USERPROFILE')
assert home is not None
return home
# On Windows we should avoid writing temporary files to a directory that is
# part of the roaming part of the user profile. Instead we use the local part
# of the user profile, when available.
if sys.platform == 'win32' and os.getenv('LOCALAPPDATA') is not None:
default_base_compiledir = os.path.join(os.getenv('LOCALAPPDATA'), 'Theano')
else:
default_base_compiledir = os.path.join(get_home_dir(), '.theano')
AddConfigVar(
'base_compiledir',
"platform-independent root directory for compiled modules",
ConfigParam(
default_base_compiledir,
filter=filter_base_compiledir,
allow_override=False),
in_c_key=False)
def default_compiledir():
return os.path.join(
theano.config.base_compiledir,
default_compiledirname())
AddConfigVar(
'compiledir',
"platform-dependent cache directory for compiled modules",
ConfigParam(
default_compiledir,
filter=filter_compiledir,
allow_override=False),
in_c_key=False)
# Check if there are remaining flags provided by the user through THEANO_FLAGS.
for key in THEANO_FLAGS_DICT.keys():
warnings.warn('Theano does not recognise this flag: {}'.format(key))
...@@ -124,7 +124,7 @@ def change_flags(**kwargs): ...@@ -124,7 +124,7 @@ def change_flags(**kwargs):
return change_flags_exec return change_flags_exec
def fetch_val_for_key(key): def fetch_val_for_key(key, delete_key=False):
"""Return the overriding config value for a key. """Return the overriding config value for a key.
A successful search returns a string value. A successful search returns a string value.
An unsuccessful search raises a KeyError An unsuccessful search raises a KeyError
...@@ -137,6 +137,8 @@ def fetch_val_for_key(key): ...@@ -137,6 +137,8 @@ def fetch_val_for_key(key):
# first try to find it in the FLAGS # first try to find it in the FLAGS
try: try:
if delete_key:
return THEANO_FLAGS_DICT.pop(key)
return THEANO_FLAGS_DICT[key] return THEANO_FLAGS_DICT[key]
except KeyError: except KeyError:
pass pass
...@@ -270,14 +272,14 @@ def AddConfigVar(name, doc, configparam, root=config, in_c_key=True): ...@@ -270,14 +272,14 @@ def AddConfigVar(name, doc, configparam, root=config, in_c_key=True):
# Trigger a read of the value from config files and env vars # Trigger a read of the value from config files and env vars
# This allow to filter wrong value from the user. # This allow to filter wrong value from the user.
if not callable(configparam.default): if not callable(configparam.default):
configparam.__get__(root, type(root)) configparam.__get__(root, type(root), delete_key=True)
else: else:
# We do not want to evaluate now the default value # We do not want to evaluate now the default value
# when it is a callable. # when it is a callable.
try: try:
fetch_val_for_key(configparam.fullname) fetch_val_for_key(configparam.fullname)
# The user provided a value, filter it now. # The user provided a value, filter it now.
configparam.__get__(root, type(root)) configparam.__get__(root, type(root), delete_key=True)
except KeyError: except KeyError:
pass pass
setattr(root.__class__, sections[0], configparam) setattr(root.__class__, sections[0], configparam)
...@@ -305,12 +307,13 @@ class ConfigParam(object): ...@@ -305,12 +307,13 @@ class ConfigParam(object):
# Calling `filter` here may actually be harmful if the default value is # Calling `filter` here may actually be harmful if the default value is
# invalid and causes a crash or has unwanted side effects. # invalid and causes a crash or has unwanted side effects.
def __get__(self, cls, type_): def __get__(self, cls, type_, delete_key=False):
if cls is None: if cls is None:
return self return self
if not hasattr(self, 'val'): if not hasattr(self, 'val'):
try: try:
val_str = fetch_val_for_key(self.fullname) val_str = fetch_val_for_key(self.fullname,
delete_key=delete_key)
self.is_default = False self.is_default = False
except KeyError: except KeyError:
if callable(self.default): if callable(self.default):
......
...@@ -38,10 +38,6 @@ e-mail thread "What is gof?". ...@@ -38,10 +38,6 @@ e-mail thread "What is gof?".
from theano.gof.cc import \ from theano.gof.cc import \
CLinker, OpWiseCLinker, DualLinker, HideC CLinker, OpWiseCLinker, DualLinker, HideC
# Also adds config vars
from theano.gof.compiledir import \
local_bitwidth, python_int_bitwidth
from theano.gof.fg import \ from theano.gof.fg import \
CachedConstantError, InconsistencyError, MissingInputError, FunctionGraph CachedConstantError, InconsistencyError, MissingInputError, FunctionGraph
......
...@@ -20,11 +20,6 @@ from theano.compat import izip ...@@ -20,11 +20,6 @@ from theano.compat import izip
from six import string_types, reraise from six import string_types, reraise
from six.moves import StringIO, xrange from six.moves import StringIO, xrange
# Note that we need to do this before importing cutils, since when there is
# no theano cache dir initialized yet, importing cutils may require compilation
# of cutils_ext.
from theano.configparser import AddConfigVar, StrParam
# gof imports # gof imports
from theano.gof import graph from theano.gof import graph
from theano.gof import link from theano.gof import link
...@@ -33,10 +28,6 @@ from theano.gof import cmodule ...@@ -33,10 +28,6 @@ from theano.gof import cmodule
from theano.gof.compilelock import get_lock, release_lock from theano.gof.compilelock import get_lock, release_lock
from theano.gof.callcache import CallCache from theano.gof.callcache import CallCache
AddConfigVar('gcc.cxxflags',
"Extra compiler flags for gcc",
StrParam(""))
_logger = logging.getLogger("theano.gof.cc") _logger = logging.getLogger("theano.gof.cc")
......
...@@ -32,9 +32,7 @@ from theano.misc.windows import (subprocess_Popen, ...@@ -32,9 +32,7 @@ from theano.misc.windows import (subprocess_Popen,
# we will abuse the lockfile mechanism when reading and writing the registry # we will abuse the lockfile mechanism when reading and writing the registry
from theano.gof import compilelock from theano.gof import compilelock
from theano.gof.compiledir import gcc_version_str, local_bitwidth from theano.configdefaults import gcc_version_str, local_bitwidth
from theano.configparser import AddConfigVar, BoolParam
importlib = None importlib = None
try: try:
...@@ -42,36 +40,6 @@ try: ...@@ -42,36 +40,6 @@ try:
except ImportError: except ImportError:
pass pass
AddConfigVar(
'cmodule.mac_framework_link',
"If set to True, breaks certain MacOS installations with the infamous "
"Bus Error",
BoolParam(False))
AddConfigVar('cmodule.warn_no_version',
"If True, will print a warning when compiling one or more Op "
"with C code that can't be cached because there is no "
"c_code_cache_version() function associated to at least one of "
"those Ops.",
BoolParam(False),
in_c_key=False)
AddConfigVar('cmodule.remove_gxx_opt',
"If True, will remove the -O* parameter passed to g++."
"This is useful to debug in gdb modules compiled by Theano."
"The parameter -g is passed by default to g++",
BoolParam(False))
AddConfigVar('cmodule.compilation_warning',
"If True, will print compilation warnings.",
BoolParam(False))
AddConfigVar('cmodule.preload_cache',
"If set to True, will preload the C module cache at import time",
BoolParam(False, allow_override=False),
in_c_key=False)
_logger = logging.getLogger("theano.gof.cmodule") _logger = logging.getLogger("theano.gof.cmodule")
METH_VARARGS = "METH_VARARGS" METH_VARARGS = "METH_VARARGS"
......
from __future__ import print_function from __future__ import print_function
import six.moves.cPickle as pickle import six.moves.cPickle as pickle
import errno
import logging import logging
import os import os
import platform
import re
import shutil import shutil
import struct
import socket
import sys
import textwrap
import numpy import numpy
import theano import theano
from six import string_types, iteritems from six import string_types, iteritems
from theano.configparser import config, AddConfigVar, ConfigParam, StrParam from theano.configparser import config
from theano.gof.utils import flatten from theano.gof.utils import flatten
from theano.misc.windows import output_subprocess_Popen
_logger = logging.getLogger("theano.gof.compiledir") _logger = logging.getLogger("theano.gof.compiledir")
try:
p_out = output_subprocess_Popen([theano.config.cxx, '-dumpversion'])
gcc_version_str = p_out[0].strip().decode()
except OSError:
# Typically means gcc cannot be found.
gcc_version_str = 'GCC_NOT_FOUND'
def local_bitwidth():
"""
Return 32 for 32bit arch, 64 for 64bit arch.
By "architecture", we mean the size of memory pointers (size_t in C),
*not* the size of long int, as it can be different.
"""
# Note that according to Python documentation, `platform.architecture()` is
# not reliable on OS X with universal binaries.
# Also, sys.maxsize does not exist in Python < 2.6.
# 'P' denotes a void*, and the size is expressed in bytes.
return struct.calcsize('P') * 8
def python_int_bitwidth():
"""
Return the bit width of Python int (C long int).
Note that it can be different from the size of a memory pointer.
"""
# 'l' denotes a C long int, and the size is expressed in bytes.
return struct.calcsize('l') * 8
compiledir_format_dict = {
"platform": platform.platform(),
"processor": platform.processor(),
"python_version": platform.python_version(),
"python_bitwidth": local_bitwidth(),
"python_int_bitwidth": python_int_bitwidth(),
"theano_version": theano.__version__,
"numpy_version": numpy.__version__,
"gxx_version": gcc_version_str.replace(" ", "_"),
"hostname": socket.gethostname()}
def short_platform(r=None, p=None):
"""
Return a safe shorter version of platform.platform().
The old default Theano compiledir used platform.platform in
it. This use the platform.version() as a substring. This is too
specific as it contain the full kernel number and package
version. This cause the compiledir to change each time there is a
new linux kernel update. This function remove the part of platform
that are too precise.
If we have something else then expected, we do nothing. So this
should be safe on other OS.
Some example if we use platform.platform() direction. On the same
OS, with just some kernel updates.
compiledir_Linux-2.6.32-504.el6.x86_64-x86_64-with-redhat-6.6-Santiago-x86_64-2.6.6-64
compiledir_Linux-2.6.32-431.29.2.el6.x86_64-x86_64-with-redhat-6.5-Santiago-x86_64-2.6.6-64
compiledir_Linux-2.6.32-431.23.3.el6.x86_64-x86_64-with-redhat-6.5-Santiago-x86_64-2.6.6-64
compiledir_Linux-2.6.32-431.20.3.el6.x86_64-x86_64-with-redhat-6.5-Santiago-x86_64-2.6.6-64
compiledir_Linux-2.6.32-431.17.1.el6.x86_64-x86_64-with-redhat-6.5-Santiago-x86_64-2.6.6-64
compiledir_Linux-2.6.32-431.11.2.el6.x86_64-x86_64-with-redhat-6.5-Santiago-x86_64-2.6.6-64
compiledir_Linux-2.6.32-431.el6.x86_64-x86_64-with-redhat-6.5-Santiago-x86_64-2.6.6-64
compiledir_Linux-2.6.32-358.23.2.el6.x86_64-x86_64-with-redhat-6.4-Santiago-x86_64-2.6.6-64
compiledir_Linux-2.6.32-358.6.2.el6.x86_64-x86_64-with-redhat-6.4-Santiago-x86_64-2.6.6-64
compiledir_Linux-2.6.32-358.6.1.el6.x86_64-x86_64-with-redhat-6.4-Santiago-x86_64-2.6.6-64
compiledir_Linux-2.6.32-358.2.1.el6.x86_64-x86_64-with-redhat-6.4-Santiago-x86_64-2.6.6-64
compiledir_Linux-2.6.32-358.el6.x86_64-x86_64-with-redhat-6.4-Santiago-x86_64-2.6.6-64
compiledir_Linux-2.6.32-358.el6.x86_64-x86_64-with-redhat-6.4-Santiago-x86_64-2.6.6
compiledir_Linux-2.6.32-279.14.1.el6.x86_64-x86_64-with-redhat-6.4-Santiago-x86_64-2.6.6
compiledir_Linux-2.6.32-279.14.1.el6.x86_64-x86_64-with-redhat-6.3-Santiago-x86_64-2.6.6
compiledir_Linux-2.6.32-279.5.2.el6.x86_64-x86_64-with-redhat-6.3-Santiago-x86_64-2.6.6
compiledir_Linux-2.6.32-220.13.1.el6.x86_64-x86_64-with-redhat-6.3-Santiago-x86_64-2.6.6
compiledir_Linux-2.6.32-220.13.1.el6.x86_64-x86_64-with-redhat-6.2-Santiago-x86_64-2.6.6
compiledir_Linux-2.6.32-220.7.1.el6.x86_64-x86_64-with-redhat-6.2-Santiago-x86_64-2.6.6
compiledir_Linux-2.6.32-220.4.1.el6.x86_64-x86_64-with-redhat-6.2-Santiago-x86_64-2.6.6
We suppose the version are ``X.Y[.*]-(digit)*(anything)*``. We keep ``X.Y``
and don't keep less important digit in the part before ``-`` and we remove
the leading digit after the first ``-``.
If the information don't fit that pattern, we do not modify platform.
"""
if r is None:
r = platform.release()
if p is None:
p = platform.platform()
sp = r.split('-')
if len(sp) < 2:
return p
# For the split before the first -, we remove all learning digit:
kernel_version = sp[0].split('.')
if len(kernel_version) <= 2:
# kernel version should always have at least 3 number.
# If not, it use another semantic, so don't change it.
return p
sp[0] = '.'.join(kernel_version[:2])
# For the split after the first -, we remove leading non-digit value.
rest = sp[1].split('.')
while len(rest):
if rest[0].isdigit():
del rest[0]
else:
break
sp[1] = '.'.join(rest)
# For sp[2:], we don't change anything.
sr = '-'.join(sp)
p = p.replace(r, sr)
p = p.replace(':', '-')
p = p.replace('?', '-')
p = p.replace('*', '-')
p = p.replace('/', '-')
return p
compiledir_format_dict['short_platform'] = short_platform()
compiledir_format_keys = ", ".join(sorted(compiledir_format_dict.keys()))
default_compiledir_format = ("compiledir_%(short_platform)s-%(processor)s-"
"%(python_version)s-%(python_bitwidth)s")
AddConfigVar("compiledir_format",
textwrap.fill(textwrap.dedent("""\
Format string for platform-dependent compiled
module subdirectory (relative to base_compiledir).
Available keys: %s. Defaults to %r.
""" % (compiledir_format_keys, default_compiledir_format))),
StrParam(default_compiledir_format, allow_override=False),
in_c_key=False)
def default_compiledirname():
formatted = config.compiledir_format % compiledir_format_dict
safe = re.sub("[\(\)\s,]+", "_", formatted)
return safe
def filter_base_compiledir(path):
# Expand '~' in path
return os.path.expanduser(str(path))
def filter_compiledir(path):
# Expand '~' in path
path = os.path.expanduser(path)
# Turn path into the 'real' path. This ensures that:
# 1. There is no relative path, which would fail e.g. when trying to
# import modules from the compile dir.
# 2. The path is stable w.r.t. e.g. symlinks (which makes it easier
# to re-use compiled modules).
path = os.path.realpath(path)
if os.access(path, os.F_OK): # Do it exist?
if not os.access(path, os.R_OK | os.W_OK | os.X_OK):
# If it exist we need read, write and listing access
raise ValueError(
"compiledir '%s' exists but you don't have read, write"
" or listing permissions." % path)
else:
try:
os.makedirs(path, 0o770) # read-write-execute for user and group
except OSError as e:
# Maybe another parallel execution of theano was trying to create
# the same directory at the same time.
if e.errno != errno.EEXIST:
raise ValueError(
"Unable to create the compiledir directory"
" '%s'. Check the permissions." % path)
# PROBLEM: sometimes the initial approach based on
# os.system('touch') returned -1 for an unknown reason; the
# alternate approach here worked in all cases... it was weird.
# No error should happen as we checked the permissions.
init_file = os.path.join(path, '__init__.py')
if not os.path.exists(init_file):
try:
open(init_file, 'w').close()
except IOError as e:
if os.path.exists(init_file):
pass # has already been created
else:
e.args += ('%s exist? %s' % (path, os.path.exists(path)),)
raise
return path
def get_home_dir():
"""
Return location of the user's home directory.
"""
home = os.getenv('HOME')
if home is None:
# This expanduser usually works on Windows (see discussion on
# theano-users, July 13 2010).
home = os.path.expanduser('~')
if home == '~':
# This might happen when expanduser fails. Although the cause of
# failure is a mystery, it has been seen on some Windows system.
home = os.getenv('USERPROFILE')
assert home is not None
return home
# On Windows we should avoid writing temporary files to a directory that is
# part of the roaming part of the user profile. Instead we use the local part
# of the user profile, when available.
if sys.platform == 'win32' and os.getenv('LOCALAPPDATA') is not None:
default_base_compiledir = os.path.join(os.getenv('LOCALAPPDATA'), 'Theano')
else:
home_dir = get_home_dir()
if not os.access(home_dir, os.W_OK):
home_dir = '/tmp'
user = os.getenv('USER')
if user is not None:
home_dir = os.path.join(home_dir, user)
default_base_compiledir = os.path.join(home_dir, '.theano')
AddConfigVar(
'base_compiledir',
"platform-independent root directory for compiled modules",
ConfigParam(
default_base_compiledir,
filter=filter_base_compiledir,
allow_override=False),
in_c_key=False)
AddConfigVar(
'compiledir',
"platform-dependent cache directory for compiled modules",
ConfigParam(
os.path.join(
config.base_compiledir,
default_compiledirname()),
filter=filter_compiledir,
allow_override=False),
in_c_key=False)
def cleanup(): def cleanup():
""" """
......
...@@ -12,7 +12,6 @@ from contextlib import contextmanager ...@@ -12,7 +12,6 @@ from contextlib import contextmanager
import numpy as np import numpy as np
from theano import config from theano import config
from theano.configparser import AddConfigVar, IntParam
random = np.random.RandomState([2015, 8, 2]) random = np.random.RandomState([2015, 8, 2])
...@@ -22,25 +21,6 @@ if _logger.level == logging.NOTSET: ...@@ -22,25 +21,6 @@ if _logger.level == logging.NOTSET:
# INFO will show the "Refreshing lock" messages # INFO will show the "Refreshing lock" messages
_logger.setLevel(logging.INFO) _logger.setLevel(logging.INFO)
AddConfigVar('compile.wait',
"""Time to wait before retrying to aquire the compile lock.""",
IntParam(5, lambda i: i > 0, allow_override=False),
in_c_key=False)
def _timeout_default():
return config.compile.wait * 24
AddConfigVar('compile.timeout',
"""In seconds, time that a process will wait before deciding to
override an existing lock. An override only happens when the existing
lock is held by the same owner *and* has not been 'refreshed' by this
owner for more than this period. Refreshes are done every half timeout
period for running processes.""",
IntParam(_timeout_default, lambda i: i >= 0,
allow_override=False),
in_c_key=False)
hostname = socket.gethostname() hostname = socket.gethostname()
......
...@@ -1042,13 +1042,6 @@ class LocalOptimizer(object): ...@@ -1042,13 +1042,6 @@ class LocalOptimizer(object):
(' ' * level), self.__class__.__name__, id(self)), file=stream) (' ' * level), self.__class__.__name__, id(self)), file=stream)
theano.configparser.AddConfigVar(
'metaopt.verbose',
"Enable verbose output for meta optimizers",
theano.configparser.BoolParam(False),
in_c_key=False)
class LocalMetaOptimizer(LocalOptimizer): class LocalMetaOptimizer(LocalOptimizer):
""" """
Base class for meta-optimizers that try a set of LocalOptimizers Base class for meta-optimizers that try a set of LocalOptimizers
......
...@@ -2,25 +2,12 @@ from __future__ import print_function ...@@ -2,25 +2,12 @@ from __future__ import print_function
import copy import copy
import sys import sys
import numpy
from theano.compat import DefaultOrderedDict from theano.compat import DefaultOrderedDict
from theano.misc.ordered_set import OrderedSet from theano.misc.ordered_set import OrderedSet
from six import StringIO from six import StringIO
from theano.gof import opt from theano.gof import opt
from theano.configparser import AddConfigVar, FloatParam
from theano import config from theano import config
AddConfigVar('optdb.position_cutoff',
'Where to stop eariler during optimization. It represent the'
' position of the optimizer where to stop.',
FloatParam(numpy.inf),
in_c_key=False)
AddConfigVar('optdb.max_use_ratio',
'A ratio that prevent infinite loop in EquilibriumOptimizer.',
FloatParam(5),
in_c_key=False)
class DB(object): class DB(object):
def __hash__(self): def __hash__(self):
......
from theano.gof.compiledir import short_platform from theano.configdefaults import short_platform
def test_short_platform(): def test_short_platform():
......
...@@ -13,8 +13,7 @@ import sys ...@@ -13,8 +13,7 @@ import sys
import time import time
import warnings import warnings
from theano.configparser import (config, AddConfigVar, from theano.configparser import (config, _config_var_list)
BoolParam, ConfigParam, _config_var_list)
import theano.gof.cmodule import theano.gof.cmodule
...@@ -23,39 +22,6 @@ from six.moves import xrange ...@@ -23,39 +22,6 @@ from six.moves import xrange
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
AddConfigVar('profile',
"If VM should collect profile information",
BoolParam(False),
in_c_key=False)
AddConfigVar('profile_optimizer',
"If VM should collect optimizer profile information",
BoolParam(False),
in_c_key=False)
AddConfigVar('profile_memory',
"If VM should collect memory profile information and print it",
BoolParam(False),
in_c_key=False)
def filter_vm_lazy(val):
if val == 'False' or val is False:
return False
elif val == 'True' or val is True:
return True
elif val == 'None' or val is None:
return None
else:
raise ValueError('Valid values for an vm.lazy parameter '
'should be None, False or True, not `%s`.' % val)
AddConfigVar('vm.lazy',
"Useful only for the vm linkers. When lazy is None,"
" auto detect if lazy evaluation is needed and use the apropriate"
" version. If lazy is True/False, force the version used between"
" Loop/LoopGC and Stack.",
ConfigParam('None', filter_vm_lazy),
in_c_key=False)
def calculate_reallocate_info(order, fgraph, storage_map, compute_map_re, def calculate_reallocate_info(order, fgraph, storage_map, compute_map_re,
dependencies): dependencies):
......
...@@ -43,36 +43,6 @@ def register_opt(*tags, **kwargs): ...@@ -43,36 +43,6 @@ def register_opt(*tags, **kwargs):
_logger_name = 'theano.sandbox.cuda' _logger_name = 'theano.sandbox.cuda'
_logger = logging.getLogger(_logger_name) _logger = logging.getLogger(_logger_name)
AddConfigVar('pycuda.init',
"""If True, always initialize PyCUDA when Theano want to
initilize the GPU. Currently, we must always initialize
PyCUDA before Theano do it. Setting this flag to True,
ensure that, but always import PyCUDA. It can be done
manually by importing theano.misc.pycuda_init before theano
initialize the GPU device.
""",
BoolParam(False),
in_c_key=False)
AddConfigVar('cublas.lib',
"""Name of the cuda blas library for the linker.""",
StrParam('cublas'))
AddConfigVar('lib.cnmem',
"""Do we enable CNMeM or not (a faster CUDA memory allocator).
The parameter represent the start size (in MB or % of
total GPU memory) of the memory pool.
0: not enabled.
0 < N <= 1: % of the total GPU memory (clipped to .985 for driver memory)
> 0: use that number of MB of memory.
""",
# We should not mix both allocator, so we can't override
FloatParam(0, lambda i: i >= 0, allow_override=False),
in_c_key=False)
# is_nvcc_available called here to initialize global vars in # is_nvcc_available called here to initialize global vars in
# nvcc_compiler module # nvcc_compiler module
nvcc_compiler.is_nvcc_available() nvcc_compiler.is_nvcc_available()
......
...@@ -3008,7 +3008,7 @@ class GpuAdvancedIncSubtensor1_dev20(GpuAdvancedIncSubtensor1): ...@@ -3008,7 +3008,7 @@ class GpuAdvancedIncSubtensor1_dev20(GpuAdvancedIncSubtensor1):
32: tensor.basic._convert_to_int32, 32: tensor.basic._convert_to_int32,
64: tensor.basic._convert_to_int64 64: tensor.basic._convert_to_int64
} }
intwidth = theano.gof.compiledir.python_int_bitwidth() intwidth = theano.configdefaults.python_int_bitwidth()
ilist_ = convert_map[intwidth](ilist_) ilist_ = convert_map[intwidth](ilist_)
assert x_.type.dtype == y_.type.dtype assert x_.type.dtype == y_.type.dtype
......
...@@ -10,7 +10,7 @@ import numpy ...@@ -10,7 +10,7 @@ import numpy
from theano import config from theano import config
from theano.compat import decode, decode_iter from theano.compat import decode, decode_iter
from theano.gof import local_bitwidth from theano.configdefaults import local_bitwidth
from theano.gof.utils import hash_from_file from theano.gof.utils import hash_from_file
from theano.gof.cmodule import (std_libs, std_lib_dirs, from theano.gof.cmodule import (std_libs, std_lib_dirs,
std_include_dirs, dlimport, std_include_dirs, dlimport,
......
...@@ -89,15 +89,6 @@ _logger = logging.getLogger('theano.scan_module.scan_op') ...@@ -89,15 +89,6 @@ _logger = logging.getLogger('theano.scan_module.scan_op')
from theano.configparser import AddConfigVar, BoolParam from theano.configparser import AddConfigVar, BoolParam
AddConfigVar('scan.allow_gc',
"Allow/disallow gc inside of Scan (default: False)",
BoolParam(False))
AddConfigVar('scan.allow_output_prealloc',
"Allow/disallow memory preallocation for outputs inside of scan "
"(default: True)",
BoolParam(True))
class Scan(PureOp): class Scan(PureOp):
""" """
......
...@@ -416,12 +416,12 @@ class BinCountOp(theano.Op): ...@@ -416,12 +416,12 @@ class BinCountOp(theano.Op):
# Some dtypes are not supported by numpy's implementation of bincount. # Some dtypes are not supported by numpy's implementation of bincount.
# Until another one is available, we should fail at graph construction # Until another one is available, we should fail at graph construction
# time, not wait for execution. # time, not wait for execution.
int_bitwidth = theano.gof.python_int_bitwidth() int_bitwidth = theano.configdefaults.python_int_bitwidth()
if int_bitwidth == 64: if int_bitwidth == 64:
numpy_unsupported_dtypes = ('uint64',) numpy_unsupported_dtypes = ('uint64',)
if int_bitwidth == 32: if int_bitwidth == 32:
numpy_unsupported_dtypes = ('uint32', 'int64', 'uint64') numpy_unsupported_dtypes = ('uint32', 'int64', 'uint64')
intp_bitwidth = theano.gof.local_bitwidth() intp_bitwidth = theano.configdefaults.local_bitwidth()
if intp_bitwidth == 32: if intp_bitwidth == 32:
out_type = basic.ivector() out_type = basic.ivector()
elif intp_bitwidth == 64: elif intp_bitwidth == 64:
...@@ -598,7 +598,7 @@ class RepeatOp(theano.Op): ...@@ -598,7 +598,7 @@ class RepeatOp(theano.Op):
# Some dtypes are not supported by numpy's implementation of repeat. # Some dtypes are not supported by numpy's implementation of repeat.
# Until another one is available, we should fail at graph construction # Until another one is available, we should fail at graph construction
# time, not wait for execution. # time, not wait for execution.
ptr_bitwidth = theano.gof.local_bitwidth() ptr_bitwidth = theano.configdefaults.local_bitwidth()
if ptr_bitwidth == 64: if ptr_bitwidth == 64:
numpy_unsupported_dtypes = ('uint64',) numpy_unsupported_dtypes = ('uint64',)
if ptr_bitwidth == 32: if ptr_bitwidth == 32:
......
...@@ -14,7 +14,6 @@ import numpy ...@@ -14,7 +14,6 @@ import numpy
import theano import theano
from theano import config, gof, printing, scalar from theano import config, gof, printing, scalar
from theano.compat import imap from theano.compat import imap
from theano.configparser import AddConfigVar, BoolParam
from theano.printing import pprint from theano.printing import pprint
from theano.tensor import basic as tensor from theano.tensor import basic as tensor
from theano.tensor import elemwise, opt, NotScalarConstantError from theano.tensor import elemwise, opt, NotScalarConstantError
...@@ -462,14 +461,6 @@ def is_1pexp(t): ...@@ -462,14 +461,6 @@ def is_1pexp(t):
return None return None
AddConfigVar(
'warn.identify_1pexp_bug',
'Warn if Theano versions prior to 7987b51 (2011-12-18) could have '
'yielded a wrong result due to a bug in the is_1pexp function',
BoolParam(theano.configdefaults.warn_default('0.4.1')),
in_c_key=False)
def is_exp(var): def is_exp(var):
""" """
Match a variable with either of the `exp(x)` or `-exp(x)` patterns. Match a variable with either of the `exp(x)` or `-exp(x)` patterns.
......
...@@ -53,12 +53,6 @@ from six import StringIO ...@@ -53,12 +53,6 @@ from six import StringIO
_logger = logging.getLogger('theano.tensor.opt') _logger = logging.getLogger('theano.tensor.opt')
theano.configparser.AddConfigVar('on_shape_error',
"warn: print a warning and use the default"
" value. raise: raise an error",
theano.configparser.EnumStr("warn", "raise"),
in_c_key=False)
# Utilities # Utilities
...@@ -230,13 +224,6 @@ def broadcast_like(value, template, fgraph, dtype=None): ...@@ -230,13 +224,6 @@ def broadcast_like(value, template, fgraph, dtype=None):
return rval return rval
theano.configparser.AddConfigVar(
'tensor.insert_inplace_optimizer_validate_nb',
"-1: auto, if graph have less then 500 nodes 1, else 10",
theano.configparser.IntParam(-1),
in_c_key=False)
def inplace_elemwise_optimizer_op(OP): def inplace_elemwise_optimizer_op(OP):
""" """
We parametrise it to make it work for Elemwise and GpuElemwise op. We parametrise it to make it work for Elemwise and GpuElemwise op.
...@@ -1609,26 +1596,6 @@ local_elemwise_alloc = register_specialize( ...@@ -1609,26 +1596,6 @@ local_elemwise_alloc = register_specialize(
local_elemwise_alloc_op(T.Elemwise, T.Alloc, T.DimShuffle)), local_elemwise_alloc_op(T.Elemwise, T.Alloc, T.DimShuffle)),
'local_alloc_elemwise') 'local_alloc_elemwise')
theano.configparser.AddConfigVar('experimental.local_alloc_elemwise',
"DEPRECATED: If True, enable the experimental"
" optimization local_alloc_elemwise."
" Generates error if not True. Use"
" optimizer_excluding=local_alloc_elemwise"
" to dsiable.",
theano.configparser.BoolParam(
True,
is_valid=lambda x: x
),
in_c_key=False)
# False could make the graph faster but not as safe.
theano.configparser.AddConfigVar(
'experimental.local_alloc_elemwise_assert',
"When the local_alloc_elemwise is applied, add"
" an assert to highlight shape errors.",
theano.configparser.BoolParam(True),
in_c_key=False)
@gof.local_optimizer([T.Elemwise]) @gof.local_optimizer([T.Elemwise])
def local_fill_sink(node): def local_fill_sink(node):
......
...@@ -6672,7 +6672,7 @@ class test_arithmetic_cast(unittest.TestCase): ...@@ -6672,7 +6672,7 @@ class test_arithmetic_cast(unittest.TestCase):
class T_long_tensor(unittest.TestCase): class T_long_tensor(unittest.TestCase):
def test_fit_int64(self): def test_fit_int64(self):
for exp in xrange(gof.python_int_bitwidth()): for exp in xrange(theano.configdefaults.python_int_bitwidth()):
val = L(2 ** exp - 1) val = L(2 ** exp - 1)
scalar_ct = constant(val) scalar_ct = constant(val)
......
...@@ -175,7 +175,7 @@ class TestBinCountOp(utt.InferShapeTester): ...@@ -175,7 +175,7 @@ class TestBinCountOp(utt.InferShapeTester):
'uint8', 'uint16', 'uint32', 'uint64'): 'uint8', 'uint16', 'uint32', 'uint64'):
# uint64 always fails # uint64 always fails
# int64 and uint32 also fail if python int are 32-bit # int64 and uint32 also fail if python int are 32-bit
int_bitwidth = theano.gof.python_int_bitwidth() int_bitwidth = theano.configdefaults.python_int_bitwidth()
if int_bitwidth == 64: if int_bitwidth == 64:
numpy_unsupported_dtypes = ('uint64',) numpy_unsupported_dtypes = ('uint64',)
if int_bitwidth == 32: if int_bitwidth == 32:
...@@ -208,7 +208,7 @@ class TestBinCountOp(utt.InferShapeTester): ...@@ -208,7 +208,7 @@ class TestBinCountOp(utt.InferShapeTester):
for dtype in tensor.discrete_dtypes: for dtype in tensor.discrete_dtypes:
# uint64 always fails # uint64 always fails
# int64 and uint32 also fail if python int are 32-bit # int64 and uint32 also fail if python int are 32-bit
int_bitwidth = theano.gof.python_int_bitwidth() int_bitwidth = theano.configdefaults.python_int_bitwidth()
if int_bitwidth == 64: if int_bitwidth == 64:
numpy_unsupported_dtypes = ('uint64',) numpy_unsupported_dtypes = ('uint64',)
if int_bitwidth == 32: if int_bitwidth == 32:
...@@ -408,7 +408,7 @@ class TestRepeatOp(utt.InferShapeTester): ...@@ -408,7 +408,7 @@ class TestRepeatOp(utt.InferShapeTester):
self.op = RepeatOp() self.op = RepeatOp()
# uint64 always fails # uint64 always fails
# int64 and uint32 also fail if python int are 32-bit # int64 and uint32 also fail if python int are 32-bit
ptr_bitwidth = theano.gof.local_bitwidth() ptr_bitwidth = theano.configdefaults.local_bitwidth()
if ptr_bitwidth == 64: if ptr_bitwidth == 64:
self.numpy_unsupported_dtypes = ('uint64',) self.numpy_unsupported_dtypes = ('uint64',)
if ptr_bitwidth == 32: if ptr_bitwidth == 32:
......
...@@ -3,7 +3,6 @@ Test config options. ...@@ -3,7 +3,6 @@ Test config options.
""" """
import unittest import unittest
from theano import config
from theano.configparser import AddConfigVar, ConfigParam, THEANO_FLAGS_DICT from theano.configparser import AddConfigVar, ConfigParam, THEANO_FLAGS_DICT
...@@ -31,7 +30,6 @@ class T_config(unittest.TestCase): ...@@ -31,7 +30,6 @@ class T_config(unittest.TestCase):
except ValueError: except ValueError:
pass pass
try:
THEANO_FLAGS_DICT['T_config.test_invalid_default_b'] = 'ok' THEANO_FLAGS_DICT['T_config.test_invalid_default_b'] = 'ok'
# This should succeed since we defined a proper value, even # This should succeed since we defined a proper value, even
# though the default was invalid. # though the default was invalid.
...@@ -40,8 +38,8 @@ class T_config(unittest.TestCase): ...@@ -40,8 +38,8 @@ class T_config(unittest.TestCase):
doc='unittest', doc='unittest',
configparam=ConfigParam('invalid', filter=filter), configparam=ConfigParam('invalid', filter=filter),
in_c_key=False) in_c_key=False)
finally:
# Dicionary clean-up. # Check that the flag has been removed
del THEANO_FLAGS_DICT['T_config.test_invalid_default_b'] assert 'T_config.test_invalid_default_b' not in THEANO_FLAGS_DICT
# TODO We should remove these dummy options on test exit. # TODO We should remove these dummy options on test exit.
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论