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

merge

......@@ -43,8 +43,10 @@ Environment Variables
.. 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 <myscript>.py by typing this:
......@@ -52,11 +54,15 @@ Environment Variables
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
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:
.. code-block:: text
......@@ -70,10 +76,10 @@ Environment Variables
Multiple configuration files can be specified by separating them with ':'
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.
For example, to override system-wide settings with personal ones,
set ``THEANORC=~/.theanorc:/etc/theanorc``
For example, to override system-wide settings with personal ones,
set ``THEANORC=/etc/theanorc:~/.theanorc``.
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),
......
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.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.python25 import any
from theano import gof
from theano.configparser import config, AddConfigVar, IntParam
from theano.compile.function_module import FunctionMaker
import_time = time.time()
......@@ -18,6 +19,17 @@ AddConfigVar('ProfileMode.n_ops_to_print',
"Number of ops to print by default",
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):
def __init__(self, linker=default_linker, optimizer=default_optimizer):
......@@ -36,6 +48,12 @@ class ProfileMode(Mode):
op_time, op_cimpl, op_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):
#print "__getstate__",self.provided_linker,self.provided_optimizer
return (self.provided_linker, self.provided_optimizer, self.local_time,
......@@ -63,7 +81,7 @@ class ProfileMode(Mode):
failure = run_cthunk(th.cthunk)
dt = time.time() - t0
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'
' FAST_RUN_NOGC to correct the problem.'))
else:
......@@ -72,11 +90,11 @@ class ProfileMode(Mode):
dt = time.time() - t0
local_time[0] += dt
apply_time[(i,node.op)] = apply_time.get((i,node.op), 0.0) + dt
apply_call[(i,node.op)] = apply_call.get((i,node.op), 0) + 1
op_time[node.op] = op_time.get(node.op, 0.0) + dt
apply_time[(i,node.op)] += dt
apply_call[(i,node.op)] += 1
op_time[node.op] += dt
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
......@@ -84,7 +102,7 @@ class ProfileMode(Mode):
if isinstance(linker, str) or linker is None:
linker = predefined_linkers[linker]
linker = WrapLinkerMany([linker], [blah])
linker = WrapLinker([linker], blah)
self.linker = linker
if isinstance(optimizer, str) or optimizer is None:
......
......@@ -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 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():
rval = [os.path.expanduser(s) for s in os.getenv('THEANORC', '~/.theanorc').split(':')]
rval.reverse()
print "THEANORC", rval
return rval
theano_cfg = ConfigParser.SafeConfigParser()
theano_cfg.read(config_files_from_theanorc())
......@@ -42,14 +43,15 @@ def fetch_val_for_key(key):
"""Return the overriding config value for a key.
A successful search returs a string value.
An unsuccessful search raises a KeyError
The priority order is:
The (decreasing) priority order is:
- THEANO_FLAGS
- ~./theanorc
"""
# first try to find it in the FLAGS
rval = None
for name_val in THEANO_FLAGS.split(','):
if not name_val:
continue
......@@ -60,7 +62,12 @@ def fetch_val_for_key(key):
name, val = name_val_tuple
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
......@@ -77,7 +84,7 @@ def fetch_val_for_key(key):
return theano_cfg.get(section, option)
except (ConfigParser.NoOptionError, ConfigParser.NoSectionError):
raise KeyError(key)
class TheanoConfigParser(object):
#properties are installed by AddConfigVar
......@@ -143,7 +150,7 @@ class ConfigParam(object):
self.val = val
deleter=None
class EnumStr(ConfigParam):
def __init__(self, default, *options):
self.default = default
......
......@@ -18,18 +18,22 @@ def _asarray(a, dtype=None, order=None):
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
situation where we do more than a simple call to ``numpy.asarray``. If it
turns out that a similar problem can occur for more data type, this
situation where we may do more than a simple call to ``numpy.asarray``. If
it turns out that a similar problem can occur for more data type, this
function should be updated accordingly.
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
theano._asarray
"""
dtype = numpy.dtype(dtype) # Convert into dtype object.
rval = numpy.asarray(a, dtype=dtype, order=order)
if dtype is numpy.int32 or dtype == 'int32':
# Make sure the type is properly set to the correct type.
return rval.view(dtype=numpy.int32)
numpy_int32 = numpy.dtype(numpy.int32)
if (dtype is numpy_int32 and rval.dtype is not numpy_int32):
# Enfore the numpy.int32 dtype.
return rval.view(dtype=numpy_int32)
else:
# 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
......@@ -5,7 +5,19 @@ from theano import gof, Op, tensor, config
from theano.printing import Print
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
else: s = 1
......@@ -60,11 +72,11 @@ def conv2d(input, filters, border_mode='valid', subsample=(1,1),
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',
'unroll_batch', 'unroll_kern', 'unroll_patch',
'imshp_logical', 'kshp_logical', 'kshp_logical_top_aligned']
......@@ -587,7 +599,7 @@ using namespace std;
if self.unroll_patch:
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
if self.unroll_batch>0 or self.unroll_kern>0:
if self.unroll_batch<=0: self.unroll_batch=1
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论