提交 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)
theano_logger.addHandler(logging_default_handler)
theano_logger.setLevel(logging.WARNING)
from theano.configdefaults import config
# Version information.
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
# might need manual changes if this number goes up. An undefined
# __api_version__ can be understood to mean api version 0.
......
......@@ -23,8 +23,7 @@ from six import string_types, iteritems, itervalues
from six.moves import StringIO, xrange
from theano.gof import (graph, utils, link, ops_with_inner_function)
from theano.gof.link import raise_with_op
from theano.configparser import (config, AddConfigVar, BoolParam, IntParam,
StrParam)
from theano.configparser import (config, AddConfigVar, IntParam, StrParam)
from theano.compile.function_module import (
FunctionMaker, Function, infer_reuse_pattern,
SymbolicInputKit, SymbolicOutput, Supervisor, std_fgraph)
......@@ -33,39 +32,6 @@ from theano.compile.ops import OutputGuard
__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):
if not isinstance(param, string_types):
......
......@@ -10,29 +10,13 @@ import numpy
import theano
from theano import gof
import theano.gof.vm
from theano.configparser import config, AddConfigVar, StrParam
from theano.configparser import config
from theano.compile.ops import _output_guard
from six import string_types
_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):
"""
......
......@@ -6,32 +6,11 @@ from six.moves import StringIO
import numpy as np
import theano
from theano.configparser import config, AddConfigVar, BoolParam, EnumStr
from theano.configparser import config
import theano.tensor as T
import theano.sandbox.cuda as cuda
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")
......
......@@ -11,7 +11,7 @@ from six import string_types, iteritems, itervalues
from theano.compile.mode import (Mode, register_mode,
predefined_modes, predefined_linkers,
predefined_optimizers)
from theano.configparser import config, AddConfigVar, IntParam, BoolParam
from theano.configparser import config
from theano.compile.function_module import FunctionMaker
from .profiling import ProfileStats
......@@ -20,28 +20,6 @@ run_cthunk = None # Will be imported only when needed.
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):
def create(self, input_storage=None, trustme=False, storage_map=None):
ret = super(Profile_Maker, self).create(input_storage, trustme,
......
......@@ -37,51 +37,6 @@ config = theano.config
_atexit_print_list = []
_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():
"""
......
......@@ -549,7 +549,7 @@ class Test_pfunc(unittest.TestCase):
def test_default_updates_input(self):
x = shared(0)
y = shared(1)
if theano.gof.python_int_bitwidth() == 32:
if theano.configdefaults.python_int_bitwidth() == 32:
a = iscalar('a')
else:
a = lscalar('a')
......
......@@ -18,7 +18,7 @@ class Test_SharedVariable(unittest.TestCase):
assert shared(7, dtype='float64').type == Scalar('float64')
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
else:
assert shared(7).type == theano.tensor.lscalar, shared(7).type
......
差异被折叠。
......@@ -124,7 +124,7 @@ def change_flags(**kwargs):
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.
A successful search returns a string value.
An unsuccessful search raises a KeyError
......@@ -137,6 +137,8 @@ def fetch_val_for_key(key):
# first try to find it in the FLAGS
try:
if delete_key:
return THEANO_FLAGS_DICT.pop(key)
return THEANO_FLAGS_DICT[key]
except KeyError:
pass
......@@ -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
# This allow to filter wrong value from the user.
if not callable(configparam.default):
configparam.__get__(root, type(root))
configparam.__get__(root, type(root), delete_key=True)
else:
# We do not want to evaluate now the default value
# when it is a callable.
try:
fetch_val_for_key(configparam.fullname)
# The user provided a value, filter it now.
configparam.__get__(root, type(root))
configparam.__get__(root, type(root), delete_key=True)
except KeyError:
pass
setattr(root.__class__, sections[0], configparam)
......@@ -305,12 +307,13 @@ class ConfigParam(object):
# Calling `filter` here may actually be harmful if the default value is
# 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:
return self
if not hasattr(self, 'val'):
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
except KeyError:
if callable(self.default):
......
......@@ -38,10 +38,6 @@ e-mail thread "What is gof?".
from theano.gof.cc import \
CLinker, OpWiseCLinker, DualLinker, HideC
# Also adds config vars
from theano.gof.compiledir import \
local_bitwidth, python_int_bitwidth
from theano.gof.fg import \
CachedConstantError, InconsistencyError, MissingInputError, FunctionGraph
......
......@@ -20,11 +20,6 @@ from theano.compat import izip
from six import string_types, reraise
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
from theano.gof import graph
from theano.gof import link
......@@ -33,10 +28,6 @@ from theano.gof import cmodule
from theano.gof.compilelock import get_lock, release_lock
from theano.gof.callcache import CallCache
AddConfigVar('gcc.cxxflags',
"Extra compiler flags for gcc",
StrParam(""))
_logger = logging.getLogger("theano.gof.cc")
......
......@@ -32,9 +32,7 @@ from theano.misc.windows import (subprocess_Popen,
# we will abuse the lockfile mechanism when reading and writing the registry
from theano.gof import compilelock
from theano.gof.compiledir import gcc_version_str, local_bitwidth
from theano.configparser import AddConfigVar, BoolParam
from theano.configdefaults import gcc_version_str, local_bitwidth
importlib = None
try:
......@@ -42,36 +40,6 @@ try:
except ImportError:
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")
METH_VARARGS = "METH_VARARGS"
......
差异被折叠。
......@@ -12,7 +12,6 @@ from contextlib import contextmanager
import numpy as np
from theano import config
from theano.configparser import AddConfigVar, IntParam
random = np.random.RandomState([2015, 8, 2])
......@@ -22,25 +21,6 @@ if _logger.level == logging.NOTSET:
# INFO will show the "Refreshing lock" messages
_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()
......
......@@ -1042,13 +1042,6 @@ class LocalOptimizer(object):
(' ' * 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):
"""
Base class for meta-optimizers that try a set of LocalOptimizers
......
......@@ -2,25 +2,12 @@ from __future__ import print_function
import copy
import sys
import numpy
from theano.compat import DefaultOrderedDict
from theano.misc.ordered_set import OrderedSet
from six import StringIO
from theano.gof import opt
from theano.configparser import AddConfigVar, FloatParam
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):
def __hash__(self):
......
from theano.gof.compiledir import short_platform
from theano.configdefaults import short_platform
def test_short_platform():
......
......@@ -13,8 +13,7 @@ import sys
import time
import warnings
from theano.configparser import (config, AddConfigVar,
BoolParam, ConfigParam, _config_var_list)
from theano.configparser import (config, _config_var_list)
import theano.gof.cmodule
......@@ -23,39 +22,6 @@ from six.moves import xrange
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,
dependencies):
......
......@@ -43,36 +43,6 @@ def register_opt(*tags, **kwargs):
_logger_name = 'theano.sandbox.cuda'
_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
# nvcc_compiler module
nvcc_compiler.is_nvcc_available()
......
......@@ -3008,7 +3008,7 @@ class GpuAdvancedIncSubtensor1_dev20(GpuAdvancedIncSubtensor1):
32: tensor.basic._convert_to_int32,
64: tensor.basic._convert_to_int64
}
intwidth = theano.gof.compiledir.python_int_bitwidth()
intwidth = theano.configdefaults.python_int_bitwidth()
ilist_ = convert_map[intwidth](ilist_)
assert x_.type.dtype == y_.type.dtype
......
......@@ -10,7 +10,7 @@ import numpy
from theano import config
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.cmodule import (std_libs, std_lib_dirs,
std_include_dirs, dlimport,
......
......@@ -89,15 +89,6 @@ _logger = logging.getLogger('theano.scan_module.scan_op')
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):
"""
......
......@@ -416,12 +416,12 @@ class BinCountOp(theano.Op):
# Some dtypes are not supported by numpy's implementation of bincount.
# Until another one is available, we should fail at graph construction
# time, not wait for execution.
int_bitwidth = theano.gof.python_int_bitwidth()
int_bitwidth = theano.configdefaults.python_int_bitwidth()
if int_bitwidth == 64:
numpy_unsupported_dtypes = ('uint64',)
if int_bitwidth == 32:
numpy_unsupported_dtypes = ('uint32', 'int64', 'uint64')
intp_bitwidth = theano.gof.local_bitwidth()
intp_bitwidth = theano.configdefaults.local_bitwidth()
if intp_bitwidth == 32:
out_type = basic.ivector()
elif intp_bitwidth == 64:
......@@ -598,7 +598,7 @@ class RepeatOp(theano.Op):
# Some dtypes are not supported by numpy's implementation of repeat.
# Until another one is available, we should fail at graph construction
# time, not wait for execution.
ptr_bitwidth = theano.gof.local_bitwidth()
ptr_bitwidth = theano.configdefaults.local_bitwidth()
if ptr_bitwidth == 64:
numpy_unsupported_dtypes = ('uint64',)
if ptr_bitwidth == 32:
......
......@@ -14,7 +14,6 @@ import numpy
import theano
from theano import config, gof, printing, scalar
from theano.compat import imap
from theano.configparser import AddConfigVar, BoolParam
from theano.printing import pprint
from theano.tensor import basic as tensor
from theano.tensor import elemwise, opt, NotScalarConstantError
......@@ -462,14 +461,6 @@ def is_1pexp(t):
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):
"""
Match a variable with either of the `exp(x)` or `-exp(x)` patterns.
......
......@@ -53,12 +53,6 @@ from six import StringIO
_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
......@@ -230,13 +224,6 @@ def broadcast_like(value, template, fgraph, dtype=None):
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):
"""
We parametrise it to make it work for Elemwise and GpuElemwise op.
......@@ -1609,26 +1596,6 @@ local_elemwise_alloc = register_specialize(
local_elemwise_alloc_op(T.Elemwise, T.Alloc, T.DimShuffle)),
'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])
def local_fill_sink(node):
......
......@@ -6672,7 +6672,7 @@ class test_arithmetic_cast(unittest.TestCase):
class T_long_tensor(unittest.TestCase):
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)
scalar_ct = constant(val)
......
......@@ -175,7 +175,7 @@ class TestBinCountOp(utt.InferShapeTester):
'uint8', 'uint16', 'uint32', 'uint64'):
# uint64 always fails
# 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:
numpy_unsupported_dtypes = ('uint64',)
if int_bitwidth == 32:
......@@ -208,7 +208,7 @@ class TestBinCountOp(utt.InferShapeTester):
for dtype in tensor.discrete_dtypes:
# uint64 always fails
# 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:
numpy_unsupported_dtypes = ('uint64',)
if int_bitwidth == 32:
......@@ -408,7 +408,7 @@ class TestRepeatOp(utt.InferShapeTester):
self.op = RepeatOp()
# uint64 always fails
# 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:
self.numpy_unsupported_dtypes = ('uint64',)
if ptr_bitwidth == 32:
......
......@@ -3,7 +3,6 @@ Test config options.
"""
import unittest
from theano import config
from theano.configparser import AddConfigVar, ConfigParam, THEANO_FLAGS_DICT
......@@ -31,7 +30,6 @@ class T_config(unittest.TestCase):
except ValueError:
pass
try:
THEANO_FLAGS_DICT['T_config.test_invalid_default_b'] = 'ok'
# This should succeed since we defined a proper value, even
# though the default was invalid.
......@@ -40,8 +38,8 @@ class T_config(unittest.TestCase):
doc='unittest',
configparam=ConfigParam('invalid', filter=filter),
in_c_key=False)
finally:
# Dicionary clean-up.
del THEANO_FLAGS_DICT['T_config.test_invalid_default_b']
# Check that the flag has been removed
assert 'T_config.test_invalid_default_b' not in THEANO_FLAGS_DICT
# TODO We should remove these dummy options on test exit.
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论