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

merge

...@@ -43,8 +43,10 @@ Environment Variables ...@@ -43,8 +43,10 @@ Environment Variables
.. envvar:: THEANO_FLAGS .. envvar:: THEANO_FLAGS
This is a list of comma-delimited key[=value] pairs that control Theano's behavior. A key that appears without an '=value' must be for a boolean value, and it acts as setting it to True. This is a list of comma-delimited key[=value] pairs that control
Theano's behavior. A key that appears without an '=value' must be
for a boolean value, and it acts as setting it to True.
For example, in bash, you can override your :envvar:`THEANORC` defaults For example, in bash, you can override your :envvar:`THEANORC` defaults
for <myscript>.py by typing this: for <myscript>.py by typing this:
...@@ -52,11 +54,15 @@ Environment Variables ...@@ -52,11 +54,15 @@ Environment Variables
THEANO_FLAGS='floatX=float32,device=gpu0,nvcc.fastmath' python <myscript>.py THEANO_FLAGS='floatX=float32,device=gpu0,nvcc.fastmath' python <myscript>.py
If a value is defined several times in ``THEANO_FLAGS``,
the right-most definition is used. So, for instance, if
``THEANO_FLAGS='device=cpu,device=gpu0'``, then gpu0 will be used.
.. envvar:: THEANORC .. envvar:: THEANORC
The location[s] of the .theanorc file[s] in ConfigParser format. The location[s] of the .theanorc file[s] in ConfigParser format.
It defaults to ``$HOME/.theanorc``. It defaults to ``$HOME/.theanorc``.
Here is the .theanorc equivalent to the THEANO_FLAGS in the example above: Here is the .theanorc equivalent to the THEANO_FLAGS in the example above:
.. code-block:: text .. code-block:: text
...@@ -70,10 +76,10 @@ Environment Variables ...@@ -70,10 +76,10 @@ Environment Variables
Multiple configuration files can be specified by separating them with ':' Multiple configuration files can be specified by separating them with ':'
characters (as in $PATH). Multiple configuration files will be merged, characters (as in $PATH). Multiple configuration files will be merged,
with earlier (left-most) files taking priority over later files in the with later (right-most) files taking priority over earlier files in the
case that multiple files specify values for a common configuration option. case that multiple files specify values for a common configuration option.
For example, to override system-wide settings with personal ones, For example, to override system-wide settings with personal ones,
set ``THEANORC=~/.theanorc:/etc/theanorc`` set ``THEANORC=/etc/theanorc:~/.theanorc``.
The rest of this page describes some of the more common and important flags The rest of this page describes some of the more common and important flags
that you might want to use. For the complete list (including documentation), that you might want to use. For the complete list (including documentation),
......
import time, atexit, copy import time, atexit, copy
from theano.gof.link import WrapLinkerMany from theano.gof.link import WrapLinker
from theano.gof.cutils import run_cthunk from theano.gof.cutils import run_cthunk
from theano.compile.mode import Mode, register_mode, predefined_modes, predefined_linkers, predefined_optimizers, default_linker, default_optimizer from theano.compile.mode import Mode, register_mode, predefined_modes, predefined_linkers, predefined_optimizers, default_linker, default_optimizer
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
from theano.configparser import config, AddConfigVar, IntParam from theano.configparser import config, AddConfigVar, IntParam
from theano.compile.function_module import FunctionMaker
import_time = time.time() import_time = time.time()
...@@ -18,6 +19,17 @@ AddConfigVar('ProfileMode.n_ops_to_print', ...@@ -18,6 +19,17 @@ AddConfigVar('ProfileMode.n_ops_to_print',
"Number of ops to print by default", "Number of ops to print by default",
IntParam(20, lambda i: i > 0)) IntParam(20, lambda i: i > 0))
class Profile_Maker(FunctionMaker):
def create(self, input_storage=None, trustme=False):
ret = super(Profile_Maker,self).create(input_storage, trustme)
for i, node in enumerate(ret.maker.env.toposort()):
self.mode.apply_time[(i,node.op)]=0.0
self.mode.apply_call[(i,node.op)]=0
self.mode.op_time[node.op]=0.
# self.mode.op_cimpl[node.op] =
self.mode.op_call[node.op] = 0
return ret
class ProfileMode(Mode): class ProfileMode(Mode):
def __init__(self, linker=default_linker, optimizer=default_optimizer): def __init__(self, linker=default_linker, optimizer=default_optimizer):
...@@ -36,6 +48,12 @@ class ProfileMode(Mode): ...@@ -36,6 +48,12 @@ class ProfileMode(Mode):
op_time, op_cimpl, op_call, op_time, op_cimpl, op_call,
compile_time, fct_call_time, fct_call)) compile_time, fct_call_time, fct_call))
def function_maker(self, i,o,m, *args, **kwargs):
"""Return an instance of `Profiler_Maker` which init the count"""
assert m is self
return Profile_Maker(i, o, self, *args, **kwargs)
def __getstate__(self): def __getstate__(self):
#print "__getstate__",self.provided_linker,self.provided_optimizer #print "__getstate__",self.provided_linker,self.provided_optimizer
return (self.provided_linker, self.provided_optimizer, self.local_time, return (self.provided_linker, self.provided_optimizer, self.local_time,
...@@ -63,7 +81,7 @@ class ProfileMode(Mode): ...@@ -63,7 +81,7 @@ class ProfileMode(Mode):
failure = run_cthunk(th.cthunk) failure = run_cthunk(th.cthunk)
dt = time.time() - t0 dt = time.time() - t0
if failure: if failure:
raise RuntimeError(('A C Op raised an exception. PerformLinker cannot' raise RuntimeError(('A C Op raised an exception. PROFILE_MODE cannot'
' tell you what it was though. Use a standard mode such as' ' tell you what it was though. Use a standard mode such as'
' FAST_RUN_NOGC to correct the problem.')) ' FAST_RUN_NOGC to correct the problem.'))
else: else:
...@@ -72,11 +90,11 @@ class ProfileMode(Mode): ...@@ -72,11 +90,11 @@ class ProfileMode(Mode):
dt = time.time() - t0 dt = time.time() - t0
local_time[0] += dt local_time[0] += dt
apply_time[(i,node.op)] = apply_time.get((i,node.op), 0.0) + dt apply_time[(i,node.op)] += dt
apply_call[(i,node.op)] = apply_call.get((i,node.op), 0) + 1 apply_call[(i,node.op)] += 1
op_time[node.op] = op_time.get(node.op, 0.0) + dt op_time[node.op] += dt
op_cimpl[node.op] = hasattr(th, 'cthunk') op_cimpl[node.op] = hasattr(th, 'cthunk')
op_call[node.op] = op_call.get(node.op,0) + 1 op_call[node.op] += 1
self.provided_linker = linker self.provided_linker = linker
...@@ -84,7 +102,7 @@ class ProfileMode(Mode): ...@@ -84,7 +102,7 @@ class ProfileMode(Mode):
if isinstance(linker, str) or linker is None: if isinstance(linker, str) or linker is None:
linker = predefined_linkers[linker] linker = predefined_linkers[linker]
linker = WrapLinkerMany([linker], [blah]) linker = WrapLinker([linker], blah)
self.linker = linker self.linker = linker
if isinstance(optimizer, str) or optimizer is None: if isinstance(optimizer, str) or optimizer is None:
......
...@@ -14,11 +14,12 @@ THEANO_FLAGS=os.getenv("THEANO_FLAGS","") ...@@ -14,11 +14,12 @@ THEANO_FLAGS=os.getenv("THEANO_FLAGS","")
# [section.]option[=value] entries. If the section part is omited, their should be only one # [section.]option[=value] entries. If the section part is omited, their should be only one
# section with that contain the gived option. # section with that contain the gived option.
# THEANORC=~/.theanorc:~lisa/.theanorc # THEANORC can contain a colon-delimited list of config files, like
# THEANORC=~lisa/.theanorc:~/.theanorc
# In that case, definitions in files on the right (here, ~/.theanorc) have
# precedence over those in files on the left.
def config_files_from_theanorc(): def config_files_from_theanorc():
rval = [os.path.expanduser(s) for s in os.getenv('THEANORC', '~/.theanorc').split(':')] rval = [os.path.expanduser(s) for s in os.getenv('THEANORC', '~/.theanorc').split(':')]
rval.reverse()
print "THEANORC", rval
return rval return rval
theano_cfg = ConfigParser.SafeConfigParser() theano_cfg = ConfigParser.SafeConfigParser()
theano_cfg.read(config_files_from_theanorc()) theano_cfg.read(config_files_from_theanorc())
...@@ -42,14 +43,15 @@ def fetch_val_for_key(key): ...@@ -42,14 +43,15 @@ def fetch_val_for_key(key):
"""Return the overriding config value for a key. """Return the overriding config value for a key.
A successful search returs a string value. A successful search returs a string value.
An unsuccessful search raises a KeyError An unsuccessful search raises a KeyError
The priority order is: The (decreasing) priority order is:
- THEANO_FLAGS - THEANO_FLAGS
- ~./theanorc - ~./theanorc
""" """
# first try to find it in the FLAGS # first try to find it in the FLAGS
rval = None
for name_val in THEANO_FLAGS.split(','): for name_val in THEANO_FLAGS.split(','):
if not name_val: if not name_val:
continue continue
...@@ -60,7 +62,12 @@ def fetch_val_for_key(key): ...@@ -60,7 +62,12 @@ def fetch_val_for_key(key):
name, val = name_val_tuple name, val = name_val_tuple
if name == key: if name == key:
return val # rval might be overriden by a later definition in THEANO_FLAGS
rval = val
# If an rval is found, it should be a string
if rval is not None:
return rval
# next try to find it in the config file # next try to find it in the config file
...@@ -77,7 +84,7 @@ def fetch_val_for_key(key): ...@@ -77,7 +84,7 @@ def fetch_val_for_key(key):
return theano_cfg.get(section, option) return theano_cfg.get(section, option)
except (ConfigParser.NoOptionError, ConfigParser.NoSectionError): except (ConfigParser.NoOptionError, ConfigParser.NoSectionError):
raise KeyError(key) raise KeyError(key)
class TheanoConfigParser(object): class TheanoConfigParser(object):
#properties are installed by AddConfigVar #properties are installed by AddConfigVar
...@@ -143,7 +150,7 @@ class ConfigParam(object): ...@@ -143,7 +150,7 @@ class ConfigParam(object):
self.val = val self.val = val
deleter=None deleter=None
class EnumStr(ConfigParam): class EnumStr(ConfigParam):
def __init__(self, default, *options): def __init__(self, default, *options):
self.default = default self.default = default
......
...@@ -18,18 +18,22 @@ def _asarray(a, dtype=None, order=None): ...@@ -18,18 +18,22 @@ def _asarray(a, dtype=None, order=None):
Currently, this issue has only been causing trouble when the target Currently, this issue has only been causing trouble when the target
data type is 'int32', on some computers. As a result, this is the only data type is 'int32', on some computers. As a result, this is the only
situation where we do more than a simple call to ``numpy.asarray``. If it situation where we may do more than a simple call to ``numpy.asarray``. If
turns out that a similar problem can occur for more data type, this it turns out that a similar problem can occur for more data type, this
function should be updated accordingly. function should be updated accordingly.
This function's name starts with a '_' to indicate that it is meant to be This function's name starts with a '_' to indicate that it is meant to be
used internally. It is imported so as to be available directly through used internally. It is imported so as to be available directly through
theano._asarray theano._asarray
""" """
dtype = numpy.dtype(dtype) # Convert into dtype object.
rval = numpy.asarray(a, dtype=dtype, order=order) rval = numpy.asarray(a, dtype=dtype, order=order)
if dtype is numpy.int32 or dtype == 'int32': numpy_int32 = numpy.dtype(numpy.int32)
# Make sure the type is properly set to the correct type. if (dtype is numpy_int32 and rval.dtype is not numpy_int32):
return rval.view(dtype=numpy.int32) # Enfore the numpy.int32 dtype.
return rval.view(dtype=numpy_int32)
else: else:
# Using ``numpy.asarray`` should work just fine. # Using ``numpy.asarray`` should work just fine.
# Debug assert if we want to detect other failure cases (untested):
# assert rval.dtype is dtype
return rval return rval
...@@ -5,7 +5,19 @@ from theano import gof, Op, tensor, config ...@@ -5,7 +5,19 @@ from theano import gof, Op, tensor, config
from theano.printing import Print from theano.printing import Print
def getFilterOutShp(inshp, kshp, (dx,dy)=(1,1), mode='valid'): def getFilterOutShp(inshp, kshp, (dx,dy)=(1,1), mode='valid'):
"""Returns numpy ndarray of len 2 """Computes the shape (nb_rows, nb_col) of each output image.
:type inshp: tuple, list or 1D ndarray of length 2
:param inshp: shape of each (2D) input image
:type kshp: tuple, list or 1D ndarray of length 2
:param kshp: shape of each (2D) kernel filter
:type mode: string
:param mode: 'valid' or 'full' (see 'border_mode' in conv2d's doc)
:rtype: numpy 1D ndarray of len 2
:return: shape of each output "image" (or feature map)
""" """
if mode=='valid': s = -1 if mode=='valid': s = -1
else: s = 1 else: s = 1
...@@ -60,11 +72,11 @@ def conv2d(input, filters, border_mode='valid', subsample=(1,1), ...@@ -60,11 +72,11 @@ def conv2d(input, filters, border_mode='valid', subsample=(1,1),
class ConvOp(Op): class ConvOp(Op):
""" """
A convolution op that should extend scipy.signal.convolve2d, but much faster! A convolution op that should behave like scipy.signal.convolve2d,
but much faster!
""" """
__attrnames = ['imshp', 'kshp', 'nkern', 'bsize', 'dx', 'dy', 'out_mode', __attrnames = ['imshp', 'kshp', 'nkern', 'bsize', 'dx', 'dy', 'out_mode',
'unroll_batch', 'unroll_kern', 'unroll_patch', 'unroll_batch', 'unroll_kern', 'unroll_patch',
'imshp_logical', 'kshp_logical', 'kshp_logical_top_aligned'] 'imshp_logical', 'kshp_logical', 'kshp_logical_top_aligned']
...@@ -587,7 +599,7 @@ using namespace std; ...@@ -587,7 +599,7 @@ using namespace std;
if self.unroll_patch: if self.unroll_patch:
if self.verbose: if self.verbose:
print "return unroll patch version",self.dx,self.dy print "return unroll patch version. all_shape=", all_shape
return _conv_op_code_unroll_patch%d return _conv_op_code_unroll_patch%d
if self.unroll_batch>0 or self.unroll_kern>0: if self.unroll_batch>0 or self.unroll_kern>0:
if self.unroll_batch<=0: self.unroll_batch=1 if self.unroll_batch<=0: self.unroll_batch=1
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论