rem
stringlengths
0
322k
add
stringlengths
0
2.05M
context
stringlengths
8
228k
f(numpy.random.rand(4), numpy.random.rand(3))
f(theano._asarray(numpy.random.rand(4), dtype='float32'), theano._asarray(numpy.random.rand(3), dtype='float32'))
def test_elemwise4(): """ Test that two vectors can be broadcast to form an outer product (by performing rank-1 matrix update""" shape = (3,4) a = tcn.shared_constructor(numpy.random.rand(*shape), 'a') b = tensor.fvector() c = tensor.fvector() f = pfunc([b,c], [], updates=[(a, (a+b.dimshuffle('x', 0)*c.dimshuffle(0, '...
if hasattr(something[j],'dtype') and y[j].dtype != something[j].dtpye:
if hasattr(something[j],'dtype') and y[j].dtype != something[j].dtype:
def scan(self, fn, args, n_seqs, n_outs, seqs_taps, outs_taps, n_steps, go_backwards, inplace_map): ''' Actual loop of the scap op perform function ''' # Note that we removed the n_steps from the args for this function, so the # order of arguments is slightly different compared to perform y = [] # When you have taps, ...
n = n.item()
n = int(n.item())
def permutation_helper(random_state, n, shape): """Helper function to generate permutations from integers. permutation_helper(random_state, n, (1,)) will generate a permutation of integers 0..n-1. In general, it will generate as many such permutation as required by shape. For instance, if shape=(p,q), p*q permutations...
if dtype != None or dtype != 'float32':
if dtype != None and dtype != 'float32':
def __init__(self, broadcastable, name=None, dtype=None): if dtype != None or dtype != 'float32': raise TypeError(self.__class__.__name__+' only support dtype float32 for now.') self.broadcastable = tuple(broadcastable) self.name = name self.dtype_specs() # error checking is done there
key_pkl = os.path.join(root, 'key.pkl')
def refresh(self): """Update self.entry_from_key by walking the cache directory structure.
if kshp_logical_top_aligned:
if self.kshp_logical_top_aligned:
def perform(self,node, (img2d, filtersflipped), (z,)): """ By default if len(img2d.shape)==3, we """ # TODO: move these back out to global scope when they no longer cause an atexit error from scipy.signal.signaltools import _valfrommode, _bvalfromboundary from scipy.signal.sigtools import _convolve2d imshp = self.imsh...
if a.dtype == numpy.float32:
if getattr(a, 'dtype',None) == numpy.float32:
def round_half_away_from_zero_vec(a): if a.dtype == numpy.float32: return round_half_away_from_zero_vec32(a) return round_half_away_from_zero_vec64(a)
hg_subprocess = Popen(hg_command.split(), stdout=PIPE, stderr=PIPE)
hg_subprocess = Popen(hg_command_tuple, stdout=PIPE, stderr=PIPE)
def run_mercurial_command(hg_command): try: hg_subprocess = Popen(hg_command.split(), stdout=PIPE, stderr=PIPE) except OSError: print >> sys.stderr, "Can't find the hg executable!" sys.exit(1) hg_out, hg_err = hg_subprocess.communicate() if len(hg_err) > 0: raise MercurialRuntimeError(hg_err) return hg_out
hg_out = run_mercurial_command("hg tip --template '{file_mods}'")
hg_out = run_mercurial_command("tip --template '{file_mods}'")
def changed_files(): hg_out = run_mercurial_command("hg tip --template '{file_mods}'") return parse_stdout_filelist(hg_out)
hg_out = run_mercurial_command("hg tip --template '{file_adds}'")
hg_out = run_mercurial_command("tip --template '{file_adds}'")
def added_files(): hg_out = run_mercurial_command("hg tip --template '{file_adds}'") return parse_stdout_filelist(hg_out)
hg_out = run_mercurial_command("hg cat -r %s %s" % (revision, filename))
hg_out = run_mercurial_command("cat -r %s %s" % (revision, filename))
def get_file_contents(filename, revision="tip"): hg_out = run_mercurial_command("hg cat -r %s %s" % (revision, filename)) return hg_out
commit_message = run_mercurial_command("hg tip --template '{desc}'")
commit_message = run_mercurial_command("tip --template '{desc}'")
def save_commit_message(filename): commit_message = run_mercurial_command("hg tip --template '{desc}'") save_file = open(filename, "w") save_file.write(commit_message) save_file.close()
a = tcn.shared_constructor(numpy.random.rand(4,4), 'a')
a = tcn.shared_constructor(my_rand(4,4), 'a')
def test_dot(): a = tcn.shared_constructor(numpy.random.rand(4,4), 'a') b = tensor.fmatrix() f = pfunc([b], [], updates=[(a, tensor.dot(a,b))], mode=mode_with_gpu) a0 = a.value * 1.0 print a0 for i, node in enumerate(f.maker.env.toposort()): print i, node bval = numpy.random.rand(4,4) f(bval) print a.value assert ...
bval = numpy.random.rand(4,4)
bval = my_rand(4,4)
def test_dot(): a = tcn.shared_constructor(numpy.random.rand(4,4), 'a') b = tensor.fmatrix() f = pfunc([b], [], updates=[(a, tensor.dot(a,b))], mode=mode_with_gpu) a0 = a.value * 1.0 print a0 for i, node in enumerate(f.maker.env.toposort()): print i, node bval = numpy.random.rand(4,4) f(bval) print a.value assert ...
a = tcn.shared_constructor(numpy.random.rand(4,4), 'a')
a = tcn.shared_constructor(my_rand(4,4), 'a')
def test_gemm(): a = tcn.shared_constructor(numpy.random.rand(4,4), 'a') b = tensor.fmatrix('b') c = tensor.fmatrix('c') f = pfunc([b,c], [], updates=[(a, tensor.dot(a,b) + tensor.exp(c))], mode=mode_with_gpu) a0 = a.value * 1.0 print a0 for i, node in enumerate(f.maker.env.toposort()): print i, node bval = numpy.r...
bval = numpy.random.rand(4,4) cval = numpy.random.rand(4,4)
bval = my_rand(4,4) cval = my_rand(4,4)
def test_gemm(): a = tcn.shared_constructor(numpy.random.rand(4,4), 'a') b = tensor.fmatrix('b') c = tensor.fmatrix('c') f = pfunc([b,c], [], updates=[(a, tensor.dot(a,b) + tensor.exp(c))], mode=mode_with_gpu) a0 = a.value * 1.0 print a0 for i, node in enumerate(f.maker.env.toposort()): print i, node bval = numpy.r...
for r in storage_map:
for r in r_transfered_from_storage_map:
def f(): debug("starting a DebugMode call") for x in no_recycling: x[0] = None
for r in node.inputs: storage_map[r][0] = _lessbroken_deepcopy(r_vals[r])
clobber = True if thunk_py: for r in node.inputs: storage_map[r][0] = _lessbroken_deepcopy(r_vals[r]) clobber = False
def f(): debug("starting a DebugMode call") for x in no_recycling: x[0] = None
clobber_dr_vals=False, perform='c')
clobber_dr_vals=clobber, perform='c')
def f(): debug("starting a DebugMode call") for x in no_recycling: x[0] = None
print >> ssio, " PyValue shape, dtype, strides, min, max:",
print >> ssio, " PyValue shape, dtype, strides, min, max, n_inf, n_nan:",
def str_diagnostic(self): """Return a pretty multiline string representating the cause of the exception""" sio = StringIO() print >> sio, "BadCLinkerOutput" print >> sio, " variable:", self.r print >> sio, " val_py :", self.val_py print >> sio, " val_c :", self.val_c print >> sio, " op :", self.offending_op...
print >> ssio, self.val_py.strides
print >> ssio, self.val_py.strides,
def str_diagnostic(self): """Return a pretty multiline string representating the cause of the exception""" sio = StringIO() print >> sio, "BadCLinkerOutput" print >> sio, " variable:", self.r print >> sio, " val_py :", self.val_py print >> sio, " val_c :", self.val_c print >> sio, " op :", self.offending_op...
print >> ssio, " CValue shape, dtype, strides, min, max:",
print >> ssio, " CValue shape, dtype, strides, min, max, n_inf, n_nan:",
def str_diagnostic(self): """Return a pretty multiline string representating the cause of the exception""" sio = StringIO() print >> sio, "BadCLinkerOutput" print >> sio, " variable:", self.r print >> sio, " val_py :", self.val_py print >> sio, " val_c :", self.val_c print >> sio, " op :", self.offending_op...
print >> ssio, " Max Abs Diff: ", numpy.max(numpy.absolute(nv-ov)) print >> ssio, " Mean Abs Diff: ", numpy.mean(numpy.absolute(nv-ov)) print >> ssio, " Median Abs Diff: ", numpy.median(numpy.absolute(nv-ov)) print >> ssio, " Std Abs Diff: ", numpy.std(numpy.absolute(nv-ov))
absdiff = numpy.absolute(nv-ov) print >> ssio, " Max Abs Diff: ", numpy.max(absdiff) print >> ssio, " Mean Abs Diff: ", numpy.mean(absdiff) print >> ssio, " Median Abs Diff: ", numpy.median(absdiff) print >> ssio, " Std Abs Diff: ", numpy.std(absdiff)
def str_diagnostic(self): """Return a pretty multiline string representating the cause of the exception""" sio = StringIO() print >> sio, "BadCLinkerOutput" print >> sio, " variable:", self.r print >> sio, " val_py :", self.val_py print >> sio, " val_c :", self.val_c print >> sio, " op :", self.offending_op...
floor = Floor(same_out_nocomplex, name = 'ceil')
floor = Floor(same_out_nocomplex, name = 'floor')
def c_code(self, node, name, (x,), (z,), sub): return "%(z)s = floor(%(x)s);" % locals()
def run_conv_nnet1(shared_fn):
def run_conv_nnet1(use_gpu): if use_gpu: shared_fn = tcn.shared_constructor else: shared_fn = shared
def run_conv_nnet1(shared_fn): n_batch = 16 n_kern = 20 shape_img = (n_batch, 1, 32, 32) shape_kern = (n_kern, 1, 5, 5) logical_hid_shape = tcn.blas.GpuConv.logical_output_shape_2d(shape_img[2:],shape_kern[2:], 'valid') n_hid = n_kern * logical_hid_shape[0] * logical_hid_shape[1] n_out = 10 w = shared_fn(numpy.asarra...
mode = get_mode()
mode = get_mode(use_gpu)
def run_conv_nnet1(shared_fn): n_batch = 16 n_kern = 20 shape_img = (n_batch, 1, 32, 32) shape_kern = (n_kern, 1, 5, 5) logical_hid_shape = tcn.blas.GpuConv.logical_output_shape_2d(shape_img[2:],shape_kern[2:], 'valid') n_hid = n_kern * logical_hid_shape[0] * logical_hid_shape[1] n_out = 10 w = shared_fn(numpy.asarra...
rval_cpu = run_conv_nnet1(shared)
rval_cpu = run_conv_nnet1(False)
def test_conv_nnet1(): numpy.random.seed(23456) rval_cpu = run_conv_nnet1(shared) numpy.random.seed(23456) rval_gpu = run_conv_nnet1(tcn.shared_constructor) assert numpy.allclose(rval_cpu, rval_gpu,rtol=1e-4,atol=1e-6)
rval_gpu = run_conv_nnet1(tcn.shared_constructor)
rval_gpu = run_conv_nnet1(True)
def test_conv_nnet1(): numpy.random.seed(23456) rval_cpu = run_conv_nnet1(shared) numpy.random.seed(23456) rval_gpu = run_conv_nnet1(tcn.shared_constructor) assert numpy.allclose(rval_cpu, rval_gpu,rtol=1e-4,atol=1e-6)
def run_conv_nnet2(shared_fn):
def run_conv_nnet2(use_gpu): if use_gpu: shared_fn = tcn.shared_constructor else: shared_fn = shared
def run_conv_nnet2(shared_fn): # pretend we are training LeNet for MNIST #cumulativ rounding error affect this comparaison of result. So we lower the tolerance. #TODO: why the last two example see the error lower? We are converging? #n_train=10, n_batch=3, n_kern=1, n_kern1=1, error see of 1e-9 #n_train=10, n_batch=3,...
mode = get_mode()
mode = get_mode(use_gpu)
def run_conv_nnet2(shared_fn): # pretend we are training LeNet for MNIST #cumulativ rounding error affect this comparaison of result. So we lower the tolerance. #TODO: why the last two example see the error lower? We are converging? #n_train=10, n_batch=3, n_kern=1, n_kern1=1, error see of 1e-9 #n_train=10, n_batch=3,...
rval_gpu = run_conv_nnet2(tcn.shared_constructor)
rval_gpu = run_conv_nnet2(True)
def test_conv_nnet2(): numpy.random.seed(23456) rval_gpu = run_conv_nnet2(tcn.shared_constructor) if True: numpy.random.seed(23456) rval_cpu = run_conv_nnet2(shared) print rval_cpu[0], rval_gpu[0],rval_cpu[0]-rval_gpu[0] assert numpy.allclose(rval_cpu, rval_gpu,rtol=1e-4,atol=1e-4)
rval_cpu = run_conv_nnet2(shared)
rval_cpu = run_conv_nnet2(False)
def test_conv_nnet2(): numpy.random.seed(23456) rval_gpu = run_conv_nnet2(tcn.shared_constructor) if True: numpy.random.seed(23456) rval_cpu = run_conv_nnet2(shared) print rval_cpu[0], rval_gpu[0],rval_cpu[0]-rval_gpu[0] assert numpy.allclose(rval_cpu, rval_gpu,rtol=1e-4,atol=1e-4)
if other_host == os.uname()[1]:
if other_host == socket.gethostname():
def lock(tmp_dir, timeout=120, min_wait=5, max_wait=10, verbosity=1): """ Obtain lock access by creating a given temporary directory (whose base will be created if needed, but will not be deleted after the lock is removed). If access is refused by the same lock owner during more than 'timeout' seconds, then the current...
os.uname()[1])
socket.gethostname())
def refresh_lock(lock_file): """ 'Refresh' an existing lock by re-writing the file containing the owner's unique id, using a new (randomly generated) id, which is also returned. """ unique_id = '%s_%s_%s' % (os.getpid(), ''.join([str(random.randint(0,9)) for i in range(10)]), os.uname()[1]) lock_write = open(lock_file,...
== [T.log1p, alloc]
== [inplace.log1p_inplace, alloc]
def test_log1p(): m = theano.config.mode if m == 'FAST_COMPILE': m = 'FAST_RUN' m = compile.mode.get_mode(m) m = m.excluding('fusion') # check some basic cases x = dvector() f = function([x], T.log(1+(x)), mode=m) assert [node.op for node in f.maker.env.toposort()] == [T.log1p] f = function([x], T.log(1+(-x)), mode=m) ...
"kernel_reduce_sum_010_%(name)s",
"kernel_reduce_sum_0101_%(name)s",
def c_code_reduce_0101(self, sio, node, name, x, z, fail): print >> sio, """ { int verbose = 0; dim3 n_threads( std::min(CudaNdarray_HOST_DIMS(%(x)s)[3], NUM_VECTOR_OP_THREADS_PER_BLOCK)); while (n_threads.x * n_threads.y <= NUM_VECTOR_OP_THREADS_PER_BLOCK) { if (n_threads.y > CudaNdarray_HOST_DIMS(%(x)s)[1]) break; n_...
self.pycuda_fct(*i, grid=sp[0], block=sp[1])
self.pycuda_fct(*i)
def perform(self, node, inputs, (z,)): #TODO assert all input have the same shape if z[0] is None or z[0].shape!=inputs[0].shape: z[0] = theano.sandbox.cuda.CudaNdarray.zeros(inputs[0].shape) i = inputs + z sp = splay(i[0].mem_size) self.pycuda_fct(*i, grid=sp[0], block=sp[1])
for x in self.input_storage:
for c in self.input_storage:
def __call__(self, *args, **kwargs): t0 = time.time()
if isinstance(o_output,list) > 1:
if isinstance(o_output,list):
def function(inputs, output): if mode is None: f = compile.function(inputs, output, accept_inplace=True) else: f = compile.function(inputs, output, accept_inplace=True, mode=mode) return f
out=shared_fn(v,'out')
v1=weakref.ref(v)
def tes_memory_leak(self, mode=compile.mode.Mode('c', 'merge'), shared_fn=shared, shp=(3000,3000), gpu=False, nb_repeat=30, assert_len_topo=True, slice=None): """ param shared_fn: if None, will use compile.function verify that the elemwise fusion work Test with and without DimShuffle """ #TODO: disable the canonizer? f...
f = compile.function([fx,compile.In(variable=out, value=out.container, mutable=None)], [out+fx],mode=mode)
f = orig_function([compile.In(fx),compile.In(variable=fy, value=v)], [fy+fx],mode=mode)
def tes_memory_leak(self, mode=compile.mode.Mode('c', 'merge'), shared_fn=shared, shp=(3000,3000), gpu=False, nb_repeat=30, assert_len_topo=True, slice=None): """ param shared_fn: if None, will use compile.function verify that the elemwise fusion work Test with and without DimShuffle """ #TODO: disable the canonizer? f...
while (n_blocks.x * n_blocks.y <= NUM_VECTOR_OP_BLOCKS) { if (n_blocks.y > CudaNdarray_HOST_DIMS(%(x)s)[2]) break;
while (n_blocks.x * (n_blocks.y+1) <= NUM_VECTOR_OP_BLOCKS && n_blocks.y <= CudaNdarray_HOST_DIMS(%(x)s)[2]) {
def c_code_reduce_100(self, sio, node, name, x, z, fail): makecall = self._makecall(node, name, x, z, fail) # use threadIdx.x for i0 # use blockIdx.x for i1 # use blockIdx.y for i2 print >> sio, """ { int verbose = 0; dim3 n_threads( std::min(CudaNdarray_HOST_DIMS(%(x)s)[0], NUM_VECTOR_OP_THREADS_PER_BLOCK)); dim3 n_bl...
n_blocks.y -= 1;
def c_code_reduce_100(self, sio, node, name, x, z, fail): makecall = self._makecall(node, name, x, z, fail) # use threadIdx.x for i0 # use blockIdx.x for i1 # use blockIdx.y for i2 print >> sio, """ { int verbose = 0; dim3 n_threads( std::min(CudaNdarray_HOST_DIMS(%(x)s)[0], NUM_VECTOR_OP_THREADS_PER_BLOCK)); dim3 n_bl...
return (13,)
return (14,)
def c_code_cache_version(self): return (13,)
class T_local_sum_canonicalize(unittest.TestCase):
class T_local_sum(unittest.TestCase):
def test_constant_get_stabilized(): """ Currently Theano enable the constant_folding optimization before stabilization optimization. This cause some stabilization optimization not being implemented and thus cause inf value to appear when it should not. .. note: we can't simply move the constant_folding optimization to...
f = theano.function([a],a.sum())
f = theano.function([a],a.sum()),mode=self.mode)
def test_local_sum_all_to_none(self): a = T.tensor3() input=numpy.arange(3*3*3).reshape(3,3,3) f = theano.function([a],a.sum()) assert len(f.maker.env.nodes)==1 assert numpy.allclose(f(input),input.sum())
f = theano.function([a],a.sum([0,1,2]))
f = theano.function([a],a.sum([0,1,2]),mode=self.mode)
def test_local_sum_all_to_none(self): a = T.tensor3() input=numpy.arange(3*3*3).reshape(3,3,3) f = theano.function([a],a.sum()) assert len(f.maker.env.nodes)==1 assert numpy.allclose(f(input),input.sum())
f = theano.function([a],a.sum(0).sum(0).sum(0))
f = theano.function([a],a.sum(0).sum(0).sum(0),mode=self.mode)
def test_local_sum_all_to_none(self): a = T.tensor3() input=numpy.arange(3*3*3).reshape(3,3,3) f = theano.function([a],a.sum()) assert len(f.maker.env.nodes)==1 assert numpy.allclose(f(input),input.sum())
f = theano.function([a],a.sum(d).sum(dd))
f = theano.function([a],a.sum(d).sum(dd),mode=self.mode)
def test_local_sum_sum(self): a=T.tensor3() input=numpy.arange(3*3*3).reshape(3,3,3) dims=[(0,0),(1,0),(2,0),(0,1),(1,1),(2,1)]
f = theano.function([a],a.sum(d).sum(dd).sum(0))
f = theano.function([a],a.sum(d).sum(dd).sum(0),mode=self.mode)
def test_local_sum_sum(self): a=T.tensor3() input=numpy.arange(3*3*3).reshape(3,3,3) dims=[(0,0),(1,0),(2,0),(0,1),(1,1),(2,1)]
f = theano.function([a],a.sum(d).sum(None))
f = theano.function([a],a.sum(d).sum(None),mode=self.mode)
def test_local_sum_sum(self): a=T.tensor3() input=numpy.arange(3*3*3).reshape(3,3,3) dims=[(0,0),(1,0),(2,0),(0,1),(1,1),(2,1)]
f = theano.function([a],a.sum(None).sum())
f = theano.function([a],a.sum(None).sum(),mode=self.mode)
def test_local_sum_sum(self): a=T.tensor3() input=numpy.arange(3*3*3).reshape(3,3,3) dims=[(0,0),(1,0),(2,0),(0,1),(1,1),(2,1)]
post_r, out = rf(rng_R, (4,))
post_r, out = rf(rng_R, (4,), 0., 1.)
def test_basic_usage(self): rf = RandomFunction(numpy.random.RandomState.uniform, tensor.dvector) assert not rf.inplace assert getattr(rf, 'destroy_map', {}) == {}
post_r2, out2 = rf2(rng_R, (4,))
post_r2, out2 = rf2(rng_R, (4,), 0., 1.)
def test_inplace_optimization(self): """Test that FAST_RUN includes the random_make_inplace optimization""" #inplace = False rf2 = RandomFunction(numpy.random.RandomState.uniform, tensor.dvector) rng_R = random_state_type()
:type file: None or file-like object :param file: print to this file (None means sys.stdout) :rtype: None or file-like object :returns: `file` argument
:type file: None, 'str', or file-like object :param file: print to this file ('str' means to return a string) :returns: str if `file`=='str', else file arg
def debugprint(obj, depth=-1, file=None): """Print a computation graph to file :type obj: Variable, Apply, or Function instance :param obj: symbolic thing to print :type depth: integer :param depth: print graph to this depth (-1 for unlimited) :type file: None or file-like object :param file: print to this file (None ...
if file is None:
if file == 'str': _file = StringIO.StringIO() elif file is None:
def debugprint(obj, depth=-1, file=None): """Print a computation graph to file :type obj: Variable, Apply, or Function instance :param obj: symbolic thing to print :type depth: integer :param depth: print graph to this depth (-1 for unlimited) :type file: None or file-like object :param file: print to this file (None ...
if file is None:
if file is _file: return file elif file=='str': return _file.getvalue() else:
def debugprint(obj, depth=-1, file=None): """Print a computation graph to file :type obj: Variable, Apply, or Function instance :param obj: symbolic thing to print :type depth: integer :param depth: print graph to this depth (-1 for unlimited) :type file: None or file-like object :param file: print to this file (None ...
return file
def debugprint(obj, depth=-1, file=None): """Print a computation graph to file :type obj: Variable, Apply, or Function instance :param obj: symbolic thing to print :type depth: integer :param depth: print graph to this depth (-1 for unlimited) :type file: None or file-like object :param file: print to this file (None ...
assert numpy.allclose(theano_result, scipy_result)
assert _allclose(theano_result, scipy_result)
def test_upcast(self):
print r
def _skip_mul_1(r): print r if r.owner and r.owner.op == tensor.mul: not_is_1 = [i for i in r.owner.inputs if not _is_1(i) ] print 'ni1', not_is_1 if len(not_is_1)==1: return not_is_1[0]
print 'ni1', not_is_1
def _skip_mul_1(r): print r if r.owner and r.owner.op == tensor.mul: not_is_1 = [i for i in r.owner.inputs if not _is_1(i) ] print 'ni1', not_is_1 if len(not_is_1)==1: return not_is_1[0]
if node is None: return None if any([o.dtype!=dtype for o in node.outputs]):
if node is None: return None if any([getattr(o.type, 'dtype', 'nodtype') != dtype for o in node.outputs]):
def get_first_node(node, dtype): if node is None: return None if any([o.dtype!=dtype for o in node.outputs]): for i in node.inputs: n = get_first_node(i.owner, dtype) if n is not None: return n return node#no parent generated a different type else: return None
'Here is the first node we found that generated a type that is not the same as the output wanted.',
'Hint: FWIW, this is the closest node that generated an incompatible dtype:',
def get_first_node(node, dtype): if node is None: return None if any([o.dtype!=dtype for o in node.outputs]): for i in node.inputs: n = get_first_node(i.owner, dtype) if n is not None: return n return node#no parent generated a different type else: return None
if not type(g_scan_outs) in (list, tuple): g_scan_outs = [ g_scan_outs ]
def zero(p): try: use_dtype = p.type.dtype except: use_dtype = theano.config.floatX return tensor.TensorConstant(tensor.TensorType(\ dtype=use_dtype, broadcastable=[]), safe_asarray._asarray(0,dtype = use_dtype))
def _find_bad_optimizations0(order, reasons, r_vals, allow_remove_inf=False):
def _find_bad_optimizations0(order, reasons, r_vals):
def _find_bad_optimizations0(order, reasons, r_vals, allow_remove_inf=False): """Use a simple algorithm to find broken optimizations. This algorithm is simple to understand, but sometimes when there's a problem it identifies the wrong optimization as the culprit. The problem stems from the fact that results are not e...
if not r.type.values_eq_approx(r_val, new_r_val, allow_remove_inf=allow_remove_inf):
if not r.type.values_eq_approx(r_val, new_r_val):
def _find_bad_optimizations0(order, reasons, r_vals, allow_remove_inf=False): """Use a simple algorithm to find broken optimizations. This algorithm is simple to understand, but sometimes when there's a problem it identifies the wrong optimization as the culprit. The problem stems from the fact that results are not e...
allow_remove_inf = self.maker.mode.allow_remove_inf
def f(): debug("starting a DebugMode call") for x in no_recycling: x[0] = None
if not r.type.values_eq_approx(r_vals[r], storage_map[r][0], allow_remove_inf=allow_remove_inf):
if not r.type.values_eq_approx(r_vals[r], storage_map[r][0]):
def f(): debug("starting a DebugMode call") for x in no_recycling: x[0] = None
_find_bad_optimizations(order, env.equivalence_tracker.reasons, r_vals, allow_remove_inf=allow_remove_inf)
_find_bad_optimizations(order, env.equivalence_tracker.reasons, r_vals)
def f(): debug("starting a DebugMode call") for x in no_recycling: x[0] = None
allow_remove_inf = config.DebugMode.allow_remove_inf """ Default False. Do we allow that an optimization remove inf value. This is usefull to test stabilization optimization. """
def _pickle_DebugMode_Maker(maker): raise NotImplementedError('DebugMode is not picklable (yet)')
n_update_rules = 0 for v in dummy_f.maker.expanded_inputs : if isinstance(v.variable, theano.compile.SharedVariable) and v.update: n_update_rules += 1
def scan(fn, sequences=[], outputs_info=[], non_sequences=[], n_steps = 0, truncate_gradient = -1, go_backwards = False, mode = None): '''Function that constructs and applies a Scan op :param fn: Function that describes the operations involved in one step of scan Given variables representing all the slices of input an...
print len(inner_fn_out_states), n_outs, n_update_rules print inner_fn_out_states
def scan(fn, sequences=[], outputs_info=[], non_sequences=[], n_steps = 0, truncate_gradient = -1, go_backwards = False, mode = None): '''Function that constructs and applies a Scan op :param fn: Function that describes the operations involved in one step of scan Given variables representing all the slices of input an...
print outs_info print inner_fn_out_states print n_outs
def scan(fn, sequences=[], outputs_info=[], non_sequences=[], n_steps = 0, truncate_gradient = -1, go_backwards = False, mode = None): '''Function that constructs and applies a Scan op :param fn: Function that describes the operations involved in one step of scan Given variables representing all the slices of input an...
return Apply(self, [ten4, neib_shape], [T.matrix()])
return Apply(self, [ten4, neib_shape], [ten4.type()])
def make_node(self, ten4, neib_shape): ten4 = T.as_tensor_variable(ten4) neib_shape = T.as_tensor_variable(neib_shape) return Apply(self, [ten4, neib_shape], [T.matrix()])
m = theano.compile.mode.get_mode('FAST_RUN')
m = theano.compile.mode.get_mode('FAST_RUN').excluding('local_elemwise_fusion')
def setUp(self): if theano.config.mode == 'FAST_COMPILE': m = theano.compile.mode.get_mode('FAST_RUN') else: m = theano.compile.mode.get_default_mode().excluding('local_elemwise_fusion') self.m = m utt.seed_rng()
def run_nnet(use_gpu, n_batch=60, n_in=1024, n_hid=2048, n_out=10, n_iter=100):
def run_nnet(use_gpu, n_batch=60, n_in=1024, n_hid=2048, n_out=10, n_train=100): if config.mode=='DEBUG_MODE': n_train=1
def run_nnet(use_gpu, n_batch=60, n_in=1024, n_hid=2048, n_out=10, n_iter=100): if use_gpu: w = tcn.shared_constructor(0.01*(my_rand(n_in,n_hid)-0.5), 'w') b = tcn.shared_constructor(my_zeros(n_hid), 'b') v = tcn.shared_constructor(my_zeros((n_hid, n_out)), 'c') c = tcn.shared_constructor(my_zeros(n_out), 'c') else: w...
for i in xrange(n_iter):
for i in xrange(n_train):
def run_nnet(use_gpu, n_batch=60, n_in=1024, n_hid=2048, n_out=10, n_iter=100): if use_gpu: w = tcn.shared_constructor(0.01*(my_rand(n_in,n_hid)-0.5), 'w') b = tcn.shared_constructor(my_zeros(n_hid), 'b') v = tcn.shared_constructor(my_zeros((n_hid, n_out)), 'c') c = tcn.shared_constructor(my_zeros(n_out), 'c') else: w...
rval_cpu = run_nnet(False, 10, 128, 50, 4, n_iter=10000)
rval_cpu = run_nnet(False, 10, 128, 50, 4, n_train=10000)
def test_run_nnet_med(): numpy.random.seed(23456) rval_cpu = run_nnet(False, 10, 128, 50, 4, n_iter=10000)
rval_cpu = run_nnet(False, 10, 10, 4, 4, n_iter=100000)
rval_cpu = run_nnet(False, 10, 10, 4, 4, n_train=100000)
def test_run_nnet_small(): numpy.random.seed(23456) rval_cpu = run_nnet(False, 10, 10, 4, 4, n_iter=100000)
for i in xrange(10):
for i in xrange(n_train):
def run_conv_nnet1(use_gpu): if use_gpu: shared_fn = tcn.shared_constructor else: shared_fn = shared n_batch = 16 n_kern = 20 shape_img = (n_batch, 1, 32, 32) shape_kern = (n_kern, 1, 5, 5) logical_hid_shape = tcn.blas.GpuConv.logical_output_shape_2d(shape_img[2:],shape_kern[2:], 'valid') n_hid = n_kern * logical_hid_...
def run_conv_nnet2_classif(use_gpu, isize, ksize, n_batch, n_iter,
def run_conv_nnet2_classif(use_gpu, isize, ksize, n_batch, n_train,
def run_conv_nnet2_classif(use_gpu, isize, ksize, n_batch, n_iter, downsample_ops=True, verbose=0, version=-1): if use_gpu: shared_fn = tcn.shared_constructor else: shared_fn = shared isize1=isize isize2=isize if isinstance(isize,(tuple,)): isize1=isize[0] isize2=isize[1] shape_img = (n_batch, 1, isize1, isize2) n_k...
rvals=my_zeros(n_iter)
rvals=my_zeros(n_train)
def run_conv_nnet2_classif(use_gpu, isize, ksize, n_batch, n_iter, downsample_ops=True, verbose=0, version=-1): if use_gpu: shared_fn = tcn.shared_constructor else: shared_fn = shared isize1=isize isize2=isize if isinstance(isize,(tuple,)): isize1=isize[0] isize2=isize[1] shape_img = (n_batch, 1, isize1, isize2) n_k...
for i in xrange(n_iter):
for i in xrange(n_train):
def run_conv_nnet2_classif(use_gpu, isize, ksize, n_batch, n_iter, downsample_ops=True, verbose=0, version=-1): if use_gpu: shared_fn = tcn.shared_constructor else: shared_fn = shared isize1=isize isize2=isize if isinstance(isize,(tuple,)): isize1=isize[0] isize2=isize[1] shape_img = (n_batch, 1, isize1, isize2) n_k...
n_iter=10,
n_train=10,
def cmp_run_conv_nnet2_classif(seed, isize, ksize, bsize, ignore_error=False, n_iter=10, gpu_only=False, cpu_only=False, float_atol=1e-06, check_isfinite=True, pickle=False, verbose=0, version=-1): """ float_atol: None mean use the default value. check_isfinite: the debug mode option. We forward this value to debug mod...
isize, ksize, bsize, n_iter, verbose=verbose, version=version)
isize, ksize, bsize, n_train, verbose=verbose, version=version)
def cmp_run_conv_nnet2_classif(seed, isize, ksize, bsize, ignore_error=False, n_iter=10, gpu_only=False, cpu_only=False, float_atol=1e-06, check_isfinite=True, pickle=False, verbose=0, version=-1): """ float_atol: None mean use the default value. check_isfinite: the debug mode option. We forward this value to debug mod...
rval_cpu, tc, cpu_mode = run_conv_nnet2_classif(False, isize, ksize, bsize, n_iter,
rval_cpu, tc, cpu_mode = run_conv_nnet2_classif(False, isize, ksize, bsize, n_train,
def cmp_run_conv_nnet2_classif(seed, isize, ksize, bsize, ignore_error=False, n_iter=10, gpu_only=False, cpu_only=False, float_atol=1e-06, check_isfinite=True, pickle=False, verbose=0, version=-1): """ float_atol: None mean use the default value. check_isfinite: the debug mode option. We forward this value to debug mod...
print "estimated time for one pass through MNIST with cpu: %f" % (tc * (60000.0 / (n_iter*bsize))) print "estimated time for one pass through MNIST with gpu: %f" % (tg * (60000.0 / (n_iter*bsize)))
print "estimated time for one pass through MNIST with cpu: %f" % (tc * (60000.0 / (n_train*bsize))) print "estimated time for one pass through MNIST with gpu: %f" % (tg * (60000.0 / (n_train*bsize)))
def cmp_run_conv_nnet2_classif(seed, isize, ksize, bsize, ignore_error=False, n_iter=10, gpu_only=False, cpu_only=False, float_atol=1e-06, check_isfinite=True, pickle=False, verbose=0, version=-1): """ float_atol: None mean use the default value. check_isfinite: the debug mode option. We forward this value to debug mod...
print "estimated time for one pass through MNIST with cpu: %f" % (tc * (60000.0 / (n_iter*bsize)))
print "estimated time for one pass through MNIST with cpu: %f" % (tc * (60000.0 / (n_train*bsize)))
def cmp_run_conv_nnet2_classif(seed, isize, ksize, bsize, ignore_error=False, n_iter=10, gpu_only=False, cpu_only=False, float_atol=1e-06, check_isfinite=True, pickle=False, verbose=0, version=-1): """ float_atol: None mean use the default value. check_isfinite: the debug mode option. We forward this value to debug mod...
cmp_run_conv_nnet2_classif(23485, 28, 5, 60, n_iter=10,
cmp_run_conv_nnet2_classif(23485, 28, 5, 60, n_train=10,
def test_lenet_28(): #MNIST cmp_run_conv_nnet2_classif(23485, 28, 5, 60, n_iter=10, ignore_error=ignore_error, gpu_only=gpu_only, cpu_only=cpu_only, verbose=verbose, version=version)
cmp_run_conv_nnet2_classif(23485, 32, 5, 60, n_iter=10,
cmp_run_conv_nnet2_classif(23485, 32, 5, 60, n_train=10,
def test_lenet_32(): #CIFAR10 / Shapeset cmp_run_conv_nnet2_classif(23485, 32, 5, 60, n_iter=10, ignore_error=ignore_error, gpu_only=gpu_only, verbose=verbose, version=version)
cmp_run_conv_nnet2_classif(23485, 32, 5, 30, n_iter=50,
cmp_run_conv_nnet2_classif(23485, 32, 5, 30, n_train=50,
def test_lenet_32_long(): #CIFAR10 / Shapeset # this tests the gradient of downsample on the GPU, # which does not recieve specific testing cmp_run_conv_nnet2_classif(23485, 32, 5, 30, n_iter=50, ignore_error=ignore_error, gpu_only=gpu_only, cpu_only=cpu_only, verbose=verbose, version=version)
cmp_run_conv_nnet2_classif(23485, 64, 7, 10, n_iter=10,
cmp_run_conv_nnet2_classif(23485, 64, 7, 10, n_train=10,
def test_lenet_64(): # ??? #float_atol need to pass in debug mode #needed as cpu use extended precision and gpu don't cmp_run_conv_nnet2_classif(23485, 64, 7, 10, n_iter=10, ignore_error=ignore_error, gpu_only=gpu_only, cpu_only=cpu_only, verbose=verbose, float_atol=5e-4, check_isfinite=True, version=version)
cmp_run_conv_nnet2_classif(23485, 108, 7, 5, n_iter=4,
cmp_run_conv_nnet2_classif(23485, 108, 7, 5, n_train=4,
def test_lenet_108(): # NORB cmp_run_conv_nnet2_classif(23485, 108, 7, 5, n_iter=4, ignore_error=ignore_error, gpu_only=gpu_only, cpu_only=cpu_only, verbose=verbose, check_isfinite=True, version=version, float_atol=7e-2)
cmp_run_conv_nnet2_classif(23485, 256, 9, 2, n_iter=5,
cmp_run_conv_nnet2_classif(23485, 256, 9, 2, n_train=5,
def test_lenet_256(): # ImageNet cmp_run_conv_nnet2_classif(23485, 256, 9, 2, n_iter=5, ignore_error=ignore_error, gpu_only=gpu_only, cpu_only=cpu_only, verbose=verbose, check_isfinite=True, version=version)
cmp_run_conv_nnet2_classif(23485, (720,1280), 9, 2, n_iter=3,
cmp_run_conv_nnet2_classif(23485, (720,1280), 9, 2, n_train=3,
def tes_lenet_hd(): #HD 720p: 1280(wid)x720(len) cmp_run_conv_nnet2_classif(23485, (720,1280), 9, 2, n_iter=3, ignore_error=ignore_error, gpu_only=gpu_only, cpu_only=cpu_only, verbose=verbose, check_isfinite=True, version=version)
return vec(x)
return round_half_away_from_zero_vec(x)
def impl(self, x): return vec(x)
cmp_run_conv_nnet2_classif(23485, 108, 7, 10, n_iter=5,
cmp_run_conv_nnet2_classif(23485, 108, 7, 5, n_iter=4,
def test_lenet_108(): # NORB cmp_run_conv_nnet2_classif(23485, 108, 7, 10, n_iter=5, ignore_error=ignore_error, gpu_only=gpu_only, cpu_only=cpu_only, verbose=verbose, check_isfinite=True, version=version)
check_isfinite=True, version=version)
check_isfinite=True, version=version, float_atol=7e-2)
def test_lenet_108(): # NORB cmp_run_conv_nnet2_classif(23485, 108, 7, 10, n_iter=5, ignore_error=ignore_error, gpu_only=gpu_only, cpu_only=cpu_only, verbose=verbose, check_isfinite=True, version=version)
cmp_run_conv_nnet2_classif(23485, 256, 9, 2, n_iter=3,
cmp_run_conv_nnet2_classif(23485, 256, 9, 2, n_iter=5,
def test_lenet_256(): # ImageNet cmp_run_conv_nnet2_classif(23485, 256, 9, 2, n_iter=3, ignore_error=ignore_error, gpu_only=gpu_only, cpu_only=cpu_only, verbose=verbose, check_isfinite=True, version=version)
if not (type(sequences) in (list, tuple)):
if not (type(sequences) in (list, tuple)) and sequences != None:
def scan( fn , sequences = None , outputs_info = None , non_sequences = None , n_steps = None , truncate_gradient = -1 , go_backwards = False , mode = None , name = None ): """ This function constructs and applies a Scan op to the provided arguments. :param fn:...