提交 ac95733a authored 作者: James Bergstra's avatar James Bergstra

merge

...@@ -24,6 +24,11 @@ To learn more, check out: ...@@ -24,6 +24,11 @@ To learn more, check out:
""" """
__docformat__ = "restructuredtext en" __docformat__ = "restructuredtext en"
import configparser, configdefaults
config = configparser.TheanoConfigParser()
import gof import gof
from gof import \ from gof import \
...@@ -63,14 +68,7 @@ import gof ...@@ -63,14 +68,7 @@ import gof
import floatX import floatX
floatX.set_floatX() floatX.set_floatX()
import config if config.device.startswith('gpu'):
#if THEANO_GPU not defined: don't automaticcaly importe cuda
#if THEANO_GPU defined to something else then "": automatically import cuda
# he will init cuda automatically if THEANO_GPU is not -1 or GPU
#if cuda.use() and THEANO_GPU not defined or defined to "": init to device 0.
#if THEANO_GPU defined to "-1" or "CPU", automatically import cuda, but don't init it.
if config.THEANO_GPU not in [None,""]:
import theano.sandbox.cuda import theano.sandbox.cuda
## import scalar_opt ## import scalar_opt
......
...@@ -11,7 +11,7 @@ from theano.gof import Env, graph, utils, link ...@@ -11,7 +11,7 @@ from theano.gof import Env, graph, utils, link
from theano.gof.link import WrapLinkerMany, raise_with_op from theano.gof.link import WrapLinkerMany, raise_with_op
#from theano.gof.cutils import run_cthunk #from theano.gof.cutils import run_cthunk
from theano.gof.cc import OpWiseCLinker, CLinker from theano.gof.cc import OpWiseCLinker, CLinker
import theano.config as config from ..configparser import config
from theano.compile.function_module import (FunctionMaker, from theano.compile.function_module import (FunctionMaker,
Function, Function,
infer_reuse_pattern, infer_reuse_pattern,
...@@ -1375,27 +1375,27 @@ class DebugMode(Mode): ...@@ -1375,27 +1375,27 @@ class DebugMode(Mode):
""" """
stability_patience = config.THEANO_DEBUGMODE_PATIENCE stability_patience = config.DebugMode.patience
""" """
When checking for the stability of optimization, recompile the graph this many times. When checking for the stability of optimization, recompile the graph this many times.
""" """
check_c_code = config.THEANO_DEBUGMODE_CHECK_C check_c_code = config.DebugMode.check_c
""" """
Should we evaluate (and check) the `c_code` implementations? Should we evaluate (and check) the `c_code` implementations?
""" """
check_py_code = config.THEANO_DEBUGMODE_CHECK_PY check_py_code = config.DebugMode.check_py
""" """
Should we evaluate (and check) the `perform` implementations? Should we evaluate (and check) the `perform` implementations?
""" """
check_isfinite = config.THEANO_DEBUGMODE_CHECK_FINITE check_isfinite = config.DebugMode.check_finite
""" """
Should we check for (and complain about) NaN/Inf ndarray elements? Should we check for (and complain about) NaN/Inf ndarray elements?
""" """
require_matching_strides = config.THEANO_DEBUGMODE_CHECK_STRIDES require_matching_strides = config.DebugMode.check_strides
""" """
Should we check for (and complain about) Ops whose python and C outputs are ndarrays with Should we check for (and complain about) Ops whose python and C outputs are ndarrays with
different strides? (This can catch bugs, but is generally overly strict.) 0 no check, 1 warn, 2 err. different strides? (This can catch bugs, but is generally overly strict.) 0 no check, 1 warn, 2 err.
......
...@@ -4,7 +4,7 @@ import os, logging ...@@ -4,7 +4,7 @@ import os, logging
import numpy import numpy
from theano import gof from theano import gof
import theano.config as config from ..configparser import config
_logger = logging.getLogger('theano.compile.mode') _logger = logging.getLogger('theano.compile.mode')
...@@ -225,7 +225,7 @@ predefined_modes = {'FAST_COMPILE': FAST_COMPILE, ...@@ -225,7 +225,7 @@ predefined_modes = {'FAST_COMPILE': FAST_COMPILE,
# is not set, it will default to 'FAST_RUN' # is not set, it will default to 'FAST_RUN'
# keep default_mode.optimizer==default_optimizer and default_mode.linker==default_linker! # keep default_mode.optimizer==default_optimizer and default_mode.linker==default_linker!
## ##
default_mode = config.THEANO_DEFAULT_MODE default_mode = config.mode
def get_mode(string): def get_mode(string):
if string is None: string = default_mode if string is None: string = default_mode
......
...@@ -6,7 +6,7 @@ from theano.compile.mode import Mode, register_mode, predefined_modes, predefine ...@@ -6,7 +6,7 @@ from theano.compile.mode import Mode, register_mode, predefined_modes, predefine
from theano.gof.cc import OpWiseCLinker from theano.gof.cc import OpWiseCLinker
from theano.gof.python25 import any from theano.gof.python25 import any
from theano import gof from theano import gof
import theano.config as config from ..configparser import config
import_time = time.time() import_time = time.time()
...@@ -83,8 +83,8 @@ class ProfileMode(Mode): ...@@ -83,8 +83,8 @@ class ProfileMode(Mode):
self._optimizer = optimizer self._optimizer = optimizer
def print_summary(self, def print_summary(self,
n_apply_to_print=config.config.getint("ProfileMode.n_apply_to_print", None), n_apply_to_print=config.ProfileMode.n_apply_to_print,
n_ops_to_print=config.config.getint("ProfileMode.n_ops_to_print", None)): n_ops_to_print=config.ProfileMode.n_ops_to_print):
""" Print 3 summary that show where the time is spend. The first show an Apply-wise summary, the second show an Op-wise summary, the third show an type-Op-wise summary. """ Print 3 summary that show where the time is spend. The first show an Apply-wise summary, the second show an Op-wise summary, the third show an type-Op-wise summary.
The Apply-wise summary print the timing information for the worst offending Apply nodes. This corresponds to individual Op applications within your graph which take the longest to execute (so if you use dot twice, you will see two entries there). The Apply-wise summary print the timing information for the worst offending Apply nodes. This corresponds to individual Op applications within your graph which take the longest to execute (so if you use dot twice, you will see two entries there).
......
import os
import ConfigParser
userconf_filename=""
default_={
'ProfileMode.n_apply_to_print':15,
'ProfileMode.n_ops_to_print':20,
'tensor_opt.local_elemwise_fusion':False,
'lib.amdlibm':False,
'op.set_flops':False,#currently used only in ConvOp. The profile mode will print the flops/s for the op.
'nvcc.fastmath':False,
'gpuelemwise.sync':True, #when true, wait that the gpu fct finished and check it error code.
}
#default value taked from env variable
THEANO_UNITTEST_SEED = os.getenv('THEANO_UNITTEST_SEED', 666)
THEANO_NOCLEANUP = os.getenv('THEANO_NOCLEANUP', 0)
THEANO_COMPILEDIR = os.getenv('THEANO_COMPILEDIR', None)
THEANO_BASE_COMPILEDIR = os.getenv('THEANO_BASE_COMPILEDIR', None)
HOME = os.getenv('HOME')
#0 compare with default precission, 1 less precission, 2 event less.
THEANO_CMP_SLOPPY = int(os.getenv('THEANO_CMP_SLOPPY', 0))
#flag for compiling with an optimized blas library. Used for gemm operation
#if THEANO_BLAS_LDFLAGS exist but empty, we will use numpy.dot()
THEANO_BLAS_LDFLAGS = os.getenv('THEANO_BLAS_LDFLAGS','-lblas')
#for gpu
CUDA_ROOT = os.getenv('CUDA_ROOT')
THEANO_GPU = os.getenv("THEANO_GPU")
THEANO_DEFAULT_MODE = os.getenv('THEANO_DEFAULT_MODE','FAST_RUN')
#debug mode
THEANO_DEBUGMODE_PATIENCE = int(os.getenv('THEANO_DEBUGMODE_PATIENCE', 10))
THEANO_DEBUGMODE_CHECK_C = bool(int(os.getenv('THEANO_DEBUGMODE_CHECK_C', 1)))
THEANO_DEBUGMODE_CHECK_PY = bool(int(os.getenv('THEANO_DEBUGMODE_CHECK_PY', 1)))
THEANO_DEBUGMODE_CHECK_FINITE = bool(int(os.getenv('THEANO_DEBUGMODE_CHECK_FINITE', 1)))
THEANO_DEBUGMODE_CHECK_STRIDES = bool(int(os.getenv('THEANO_DEBUGMODE_CHECK_STRIDES', 1)))
THEANO_FLAGS=os.getenv("THEANO_FLAGS","")
def parse_env_flags(flags, name , default_value=None):
#The value in the env variable THEANO_FLAGS override the previous value
val = default_value
for flag in flags.split(','):
if not flag:
continue
sp=flag.split('=',1)
if sp[0]==name:
if len(sp)==1:
val=True
else:
val=sp[1]
val=str(val)
return val
floatX=parse_env_flags(THEANO_FLAGS,'floatX','float64')
class TheanoConfig(object):
"""Return the value for a key after parsing ~/.theano.cfg and
the THEANO_FLAGS environment variable.
We parse in that order the value to have:
1)the pair 'section.option':value in default_
2)The ~/.theano.cfg file
3)The value value provided in the get*() fct.
The last value found is the value returned.
The THEANO_FLAGS environement variable should be a list of comma-separated [section.]option[=value] entries. If the section part is omited, their should be only one section with that contain the gived option.
"""
def __init__(self):
d={} # no section
for k,v in default_.items():
if len(k.split('.'))==1:
d[k]=v
#set default value common for all section
self.config = ConfigParser.SafeConfigParser(d)
#set default value specific for each section
for k, v in default_.items():
sp = k.split('.',1)
if len(sp)==2:
if not self.config.has_section(sp[0]):
self.config.add_section(sp[0])
self.config.set(sp[0], sp[1], str(v))
#user config file override the default value
self.config.read(['theano.cfg', os.path.expanduser('~/.theano.cfg')])
self.env_flags=THEANO_FLAGS
#The value in the env variable THEANO_FLAGS override the previous value
for flag in self.env_flags.split(','):
if not flag:
continue
sp=flag.split('=',1)
if len(sp)==1:
val=True
else:
val=sp[1]
val=str(val)
sp=sp[0].split('.',1)#option or section.option
if len(sp)==2:
self.config.set(sp[0],sp[1],val)
else:
found=0
sp=sp[0].lower()#the ConfigParser seam to use only lower letter.
for sec in self.config.sections():
for opt in self.config.options(sec):
if opt == sp:
found+=1
section=sec
option=opt
if found==1:
self.config.set(section,option,val)
elif found>1:
raise Exception("Ambiguous option (%s) in THEANO_FLAGS"%(sp))
def __getitem__(self, key):
""":returns: a str with the value associated to the key"""
return self.get(key)
def get(self, key, val=None):
"""
:param key: the key that we want the value
:type key: str
:returns: a str with the value associated to the key
"""
#self.config.get(section, option, raw, vars)
if val is not None:
return val
sp = key.split('.',1)
if len(sp)!=2:
raise Exception("When we get a key, their must be a section and an option")
return self.config.get(sp[0],sp[1], False)
def getfloat(self, key, val=None):
""" :return: cast the output of self.get to a float"""
if val is not None:
return float(val)
return float(self.get(key))
def getboolean(self, key, val=None):
""" :return: cast the output of self.get to a boolean"""
if val is None:
val=self.get(key)
if val == "False" or val == "0" or not val:
val = False
else:
val = True
return val
def getint(self, key, val=None):
""" :return: cast the output of self.get to an int"""
if val is not None:
return int(val)
return int(self.get(key))
config = TheanoConfig()
if floatX not in ['float32', 'float64']:
raise Exception("the configuration scalar.floatX must have value float32 or float64 not", floatX)
"""Provide xscalar, xvector, xmatrix, etc. pseudo-types """Provide xscalar, xvector, xmatrix, etc. pseudo-types
""" """
import theano.config as config from .configparser import config
from theano.scalar import float64, float32 from theano.scalar import float64, float32
from theano.tensor import (fscalar, fvector, fmatrix, frow, fcol, ftensor3, ftensor4, dscalar, from theano.tensor import (fscalar, fvector, fmatrix, frow, fcol, ftensor3, ftensor4, dscalar,
dvector, dmatrix, drow, dcol, dtensor3, dtensor4) dvector, dmatrix, drow, dcol, dtensor3, dtensor4)
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
""" """
import os, tempfile, StringIO, sys, logging, subprocess, cPickle, atexit, time, shutil, stat import os, tempfile, StringIO, sys, logging, subprocess, cPickle, atexit, time, shutil, stat
import distutils.sysconfig import distutils.sysconfig
import theano.config as config from theano.configparser import config
import numpy.distutils #TODO: TensorType should handle this import numpy.distutils #TODO: TensorType should handle this
import compilelock # we will abuse the lockfile mechanism when reading and writing the registry import compilelock # we will abuse the lockfile mechanism when reading and writing the registry
...@@ -515,7 +515,7 @@ class ModuleCache(object): ...@@ -515,7 +515,7 @@ class ModuleCache(object):
def _rmtree(parent): def _rmtree(parent):
try: try:
if not config.THEANO_NOCLEANUP: if not config.nocleanup:
shutil.rmtree(parent) shutil.rmtree(parent)
except Exception, e: except Exception, e:
try: try:
......
...@@ -4,7 +4,7 @@ import os ...@@ -4,7 +4,7 @@ import os
import platform import platform
import re import re
import theano.config as config from ..configparser import config
def set_compiledir(path=None): def set_compiledir(path=None):
"""Set the directory into which theano will compile code objects """Set the directory into which theano will compile code objects
...@@ -27,15 +27,15 @@ def set_compiledir(path=None): ...@@ -27,15 +27,15 @@ def set_compiledir(path=None):
if path is None: if path is None:
# we need to set the default, which can come from one of two places # we need to set the default, which can come from one of two places
if config.THEANO_COMPILEDIR: if config.compiledir:
path = config.THEANO_COMPILEDIR path = config.compiledir
else: else:
platform_id = platform.platform() + '-' + platform.processor() platform_id = platform.platform() + '-' + platform.processor()
platform_id = re.sub("[\(\)\s]+", "_", platform_id) platform_id = re.sub("[\(\)\s]+", "_", platform_id)
if config.THEANO_BASE_COMPILEDIR: if config.base_compiledir:
base = config.THEANO_BASE_COMPILEDIR base = config.base_compiledir
else: else:
base = os.path.join(config.HOME,'.theano') base = os.path.join(config.home,'.theano')
path = os.path.join(base, 'compiledir_'+platform_id) path = os.path.join(base, 'compiledir_'+platform_id)
if not os.access(path, os.R_OK | os.W_OK): if not os.access(path, os.R_OK | os.W_OK):
......
...@@ -7,7 +7,7 @@ import numpy ...@@ -7,7 +7,7 @@ import numpy
from theano import gof from theano import gof
from theano.gof import Op, utils, Variable, Constant, Type, Apply, Env from theano.gof import Op, utils, Variable, Constant, Type, Apply, Env
from theano.gof.python25 import partial, all, any from theano.gof.python25 import partial, all, any
import theano.config as config from ..configparser import config
def upcast(dtype, *dtypes): def upcast(dtype, *dtypes):
z = numpy.zeros((), dtype = dtype) z = numpy.zeros((), dtype = dtype)
...@@ -77,18 +77,18 @@ class Scalar(Type): ...@@ -77,18 +77,18 @@ class Scalar(Type):
def c_headers(self): def c_headers(self):
l=['<math.h>'] l=['<math.h>']
if config.config.getboolean('lib.amdlibm'): if config.lib.amdlibm:
l+=['<amdlibm.h>'] l+=['<amdlibm.h>']
return l return l
def c_libraries(self): def c_libraries(self):
l=[] l=[]
if config.config.getboolean('lib.amdlibm'): if config.lib.amdlibm:
l+=['amdlibm'] l+=['amdlibm']
return l return l
def c_compile_args(self): def c_compile_args(self):
if config.config.getboolean('lib.amdlibm'): if config.lib.amdlibm:
return ['-DREPLACE_WITH_AMDLIBM'] return ['-DREPLACE_WITH_AMDLIBM']
else: return [] else: return []
......
...@@ -4,7 +4,7 @@ __docformat__ = "restructuredtext en" ...@@ -4,7 +4,7 @@ __docformat__ = "restructuredtext en"
import __builtin__ import __builtin__
import sys # for sys.maxint import sys # for sys.maxint
import theano.config as config # for THEANO_CMP_SLOPPY from ..configparser import config
import traceback #for overriding Op.__call__ import traceback #for overriding Op.__call__
if sys.version_info >= (2,5): if sys.version_info >= (2,5):
import functools import functools
...@@ -260,7 +260,7 @@ def _wrap_tensor_into_member(x): ...@@ -260,7 +260,7 @@ def _wrap_tensor_into_member(x):
return compile.module.Member(constant(x)) return compile.module.Member(constant(x))
compile.module.register_wrapper(_obj_is_wrappable_as_tensor, _wrap_tensor_into_member) compile.module.register_wrapper(_obj_is_wrappable_as_tensor, _wrap_tensor_into_member)
if int(config.THEANO_CMP_SLOPPY)>1: if int(config.tensor.cmp_sloppy)>1:
# This environment variable is a quick-and-dirty way to get low-precision comparisons. # This environment variable is a quick-and-dirty way to get low-precision comparisons.
# For a more precise setting of these tolerances set them explicitly in your user code by # For a more precise setting of these tolerances set them explicitly in your user code by
# assigning, for example, "theano.tensor.basic.float32_atol = ..." # assigning, for example, "theano.tensor.basic.float32_atol = ..."
...@@ -270,7 +270,7 @@ if int(config.THEANO_CMP_SLOPPY)>1: ...@@ -270,7 +270,7 @@ if int(config.THEANO_CMP_SLOPPY)>1:
float32_rtol = 1e-3 float32_rtol = 1e-3
float64_rtol = 1e-4 float64_rtol = 1e-4
float64_atol = 1e-3 float64_atol = 1e-3
elif int(config.THEANO_CMP_SLOPPY): elif int(config.tensor.cmp_sloppy):
float32_atol = 1e-4 float32_atol = 1e-4
float32_rtol = 1e-3 float32_rtol = 1e-3
float64_rtol = 1e-4 float64_rtol = 1e-4
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
import sys, traceback, logging import sys, traceback, logging
import numpy import numpy
import theano.config as config from ..configparser import config
from theano.gof import (utils, Op, Apply, view_roots, PatternSub, DestroyHandler, from theano.gof import (utils, Op, Apply, view_roots, PatternSub, DestroyHandler,
SeqOptimizer, local_optimizer, Optimizer, LocalOptimizer, OpKeyOptimizer, SeqOptimizer, local_optimizer, Optimizer, LocalOptimizer, OpKeyOptimizer,
InconsistencyError, toolbox) InconsistencyError, toolbox)
...@@ -33,7 +33,7 @@ def ldflags(libs=True, flags=False): ...@@ -33,7 +33,7 @@ def ldflags(libs=True, flags=False):
Default: ['blas'], but environment variable THEANO_BLAS_LDFLAGS overrides this. Default: ['blas'], but environment variable THEANO_BLAS_LDFLAGS overrides this.
""" """
rval = [] rval = []
for t in config.THEANO_BLAS_LDFLAGS.split(): for t in config.blas.ldflags.split():
try: try:
t0, t1, t2 = t[0:3] t0, t1, t2 = t[0:3]
assert t0 == '-' assert t0 == '-'
......
...@@ -9,7 +9,7 @@ _logger = logging.getLogger('theano.tensor.opt') ...@@ -9,7 +9,7 @@ _logger = logging.getLogger('theano.tensor.opt')
from theano import gof from theano import gof
from theano.gof import opt, InconsistencyError, TopoOptimizer, graph from theano.gof import opt, InconsistencyError, TopoOptimizer, graph
from theano.gof.utils import MethodNotDefined from theano.gof.utils import MethodNotDefined
import theano.config as config from ..configparser import config
from elemwise import Elemwise, DimShuffle from elemwise import Elemwise, DimShuffle
from theano import scalar from theano import scalar
import basic as T import basic as T
...@@ -1467,7 +1467,7 @@ class FusionOptimizer(Optimizer): ...@@ -1467,7 +1467,7 @@ class FusionOptimizer(Optimizer):
pass pass
if config.config.getboolean('tensor_opt.local_elemwise_fusion'): if config.tensor.local_elemwise_fusion:
_logger.debug("enabling optimization fusion elemwise in fast_run") _logger.debug("enabling optimization fusion elemwise in fast_run")
compile.optdb.register('elemwise_fusion', FusionOptimizer(), 71.00, 'fast_run', 'fusion', 'local_elemwise_fusion') compile.optdb.register('elemwise_fusion', FusionOptimizer(), 71.00, 'fast_run', 'fusion', 'local_elemwise_fusion')
else: else:
......
import unittest import unittest
import numpy import numpy
import theano.tensor as T import theano.tensor as T
import theano.config as config from ..configparser import config, AddConfigVar, IntParam
import os, sys import os, sys
AddConfigVar('unittests.rseed',
"Seed to use for randomized unit tests",
IntParam(666))
def fetch_seed(pseed=None): def fetch_seed(pseed=None):
""" """
Returns the seed to use for running the unit tests. Returns the seed to use for running the unit tests.
...@@ -17,7 +21,7 @@ def fetch_seed(pseed=None): ...@@ -17,7 +21,7 @@ def fetch_seed(pseed=None):
>>> rng = numpy.random.RandomState(unittest_tools.fetch_seed()) >>> rng = numpy.random.RandomState(unittest_tools.fetch_seed())
""" """
seed = pseed or config.THEANO_UNITTEST_SEED seed = pseed or config.unittests.rseed
if seed=='random': if seed=='random':
seed = None seed = None
#backport #backport
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论