提交 ae9139ac authored 作者: Arnaud Bergeron's avatar Arnaud Bergeron

Remove code that is never executed.

上级 48b65cb5
...@@ -353,21 +353,6 @@ PyArray_SetBaseObject(%(res)s, (PyObject*)%(basename)s); ...@@ -353,21 +353,6 @@ PyArray_SetBaseObject(%(res)s, (PyObject*)%(basename)s);
strides_statements + strides_statements +
close_bracket) close_bracket)
if 0:
print('C_CODE')
print('')
print(self)
print("IN BROAD", self.input_broadcastable)
print("NEW ORDER", self.new_order)
print("SHUFFLE", self.shuffle)
print("AUGMENT", self.augment)
print('------------')
print('')
print(full_code)
if 0:
sys.exit()
return full_code % dict(locals(), **sub) return full_code % dict(locals(), **sub)
def c_code_cache_version(self): def c_code_cache_version(self):
......
...@@ -927,46 +927,14 @@ class ConvOp(OpenMPOp): ...@@ -927,46 +927,14 @@ class ConvOp(OpenMPOp):
filters = filters[:, :, ::-1, ::-1] # flip them filters = filters[:, :, ::-1, ::-1] # flip them
if 0: # find good value for the unroll dw = ConvOp(imshp, kshp, nkern, bsize, 1, 1, output_mode='valid',
unroll_batch=None, unroll_kern=None, unroll_patch=None,
if all_shape and un_b != 0 and bsize % un_b != 0: imshp_logical=imshp_logical,
if bsize < un_b: kshp_logical=kshp_logical,
un_b = bsize kshp_logical_top_aligned=kshp_logical_top_aligned,
else: version=self.version,
un_b = 1 direction_hint='bprop weights',
_logger.warn( verbose=self.verbose)
"Optimization Warning: in ConvOp.grad() we can't "
" determine a good unroll value for the batch."
" Maybe you can optimize this!")
if all_shape and un_k != 0 and nkern % un_k != 0:
if nkern < un_k:
un_k = nkern
else:
un_k = 1
_logger.warn(
"Optimization Warning: in ConvOp.grad() we can't"
" determine a good unroll value for the kernel. Maybe"
" you can optimize this!")
dw = ConvOp(imshp, kshp, nkern, bsize, 1, 1, output_mode='valid',
unroll_batch=un_b, unroll_kern=un_k, unroll_patch=un_p,
imshp_logical=imshp_logical,
kshp_logical=kshp_logical,
kshp_logical_top_aligned=kshp_logical_top_aligned,
version=self.version,
direction_hint='bprop weights',
verbose=self.verbose)
else: # let __init__ choose c params be chosen automatically from shapes
dw = ConvOp(imshp, kshp, nkern, bsize, 1, 1, output_mode='valid',
unroll_batch=None, unroll_kern=None, unroll_patch=None,
imshp_logical=imshp_logical,
kshp_logical=kshp_logical,
kshp_logical_top_aligned=kshp_logical_top_aligned,
version=self.version,
direction_hint='bprop weights',
verbose=self.verbose)
dw = dw(img, filters) dw = dw(img, filters)
...@@ -990,26 +958,15 @@ class ConvOp(OpenMPOp): ...@@ -990,26 +958,15 @@ class ConvOp(OpenMPOp):
imshp_logical = (self.nkern, self.fulloutshp[0], imshp_logical = (self.nkern, self.fulloutshp[0],
self.fulloutshp[1]) self.fulloutshp[1])
if 0: # hard-code c generation parameters din = ConvOp(imshp, self.kshp, nkern, self.bsize,
din = ConvOp(imshp, self.kshp, nkern, self.bsize, 1, 1, output_mode=mode,
1, 1, output_mode=mode, unroll_batch=None, unroll_kern=None,
unroll_batch=un_b, unroll_kern=un_k, unroll_patch=None,
unroll_patch=un_p, imshp_logical=imshp_logical,
imshp_logical=imshp_logical, kshp_logical=None,
kshp_logical=None, version=-1, # we we change the mode, we don't forward the version.
version=-1, # we we change the mode, we don't forward the version. direction_hint='bprop inputs',
direction_hint='bprop inputs', verbose=self.verbose)
verbose=self.verbose)
else: # let __init__ figure out the unrolling / patch sizes
din = ConvOp(imshp, self.kshp, nkern, self.bsize,
1, 1, output_mode=mode,
unroll_batch=None, unroll_kern=None,
unroll_patch=None,
imshp_logical=imshp_logical,
kshp_logical=None,
version=-1, # we we change the mode, we don't forward the version.
direction_hint='bprop inputs',
verbose=self.verbose)
din = din(gz, filters) din = din(gz, filters)
......
...@@ -1014,47 +1014,3 @@ register_local_1msigmoid = False ...@@ -1014,47 +1014,3 @@ register_local_1msigmoid = False
if register_local_1msigmoid: if register_local_1msigmoid:
opt.register_canonicalize(local_1msigmoid) opt.register_canonicalize(local_1msigmoid)
if 0:
# This code is if'd out because it is not complete,
# and it isn't obviously a good idea anyway.
# The motivation here was to identify the last exp() node
# in the SciPy2010 article, which was not optimized away at the time of publication,
# so the example is actually not numerically stable, even though it should be.
@opt.register_stabilize
@gof.local_optimizer([tensor.mul])
def local_sigm_gest(node):
print("CANONICALIZE")
print(sigm_canonicalize(node))
def sigm_canonicalize(node):
mul = tensor.mul
div = tensor.true_div
if node.op == tensor.add:
rval = []
for i in node.inputs:
rval += sigm_canonicalize(i)
return rval
if node.op == tensor.mul:
rval = sigm_canonicalize(node.inputs[0])
for i in node.inputs[1:]:
old_rval = rval
rval = []
for t1 in sigm_canonicalize(i):
for t0 in old_rval:
assert t1.owner.op == div
assert t0.owner.op == div
t0top, t0bot = t0.owner.inputs
t1top, t1bot = t1.owner.inputs
rval.append(div(mul(*(
t0top + t1top)), mul(*(t0bot + t1bot))))
if len(rval) > 100:
# This loop can be exponentially long.
# aborting
return []
elif len(node.outputs) > 1:
return []
else:
return [node.outputs[0]]
...@@ -1441,9 +1441,6 @@ def test_asymptotic_32(): ...@@ -1441,9 +1441,6 @@ def test_asymptotic_32():
c = categorical_crossentropy(softmax(x + x2), y) c = categorical_crossentropy(softmax(x + x2), y)
f = theano.function([x, y, x2], [c.sum(), f = theano.function([x, y, x2], [c.sum(),
tensor.grad(c.sum(), x)], mode='FAST_RUN') tensor.grad(c.sum(), x)], mode='FAST_RUN')
if 0:
for i, n in enumerate(f.maker.fgraph.toposort()):
print(i, n)
xval = numpy.zeros((5, 5), dtype=dtype).astype(dtype) xval = numpy.zeros((5, 5), dtype=dtype).astype(dtype)
x2val = numpy.zeros(5, dtype=xval.dtype).astype(dtype) x2val = numpy.zeros(5, dtype=xval.dtype).astype(dtype)
......
...@@ -4510,45 +4510,6 @@ def local_reshape_lift(node): ...@@ -4510,45 +4510,6 @@ def local_reshape_lift(node):
return [re] return [re]
if 0:
# TODO: Test that this optimziation works.
# TODO: Once it works, copy over stacktrace appropriately.
@register_canonicalize
@gof.local_optimizer([T.Reshape])
def local_scalar_reshape(node):
"""Eliminate reshape Ops whose inputs and outputs are scalars """
if isinstance(node.op, T.Reshape):
x, shp = node.inputs
if x.ndim == 0 and T.get_vector_length(shp) == 0:
return [x]
if 0:
# TODO: Finish writing and testing this optimization. The idea is
# that if we can prove the output to this sum has a
# zero-size dimension, then it can be replaced by an
# appropriately typed and broadcasted zero.
# TODO: Remember to take into account the new sum dtype argument if this
# optimization is enabled.
# TODO: Once it works, copy over stacktrace appropriately.
@register_canonicalize
@gof.local_optimizer([T.Sum])
def local_sum_over_empty(node):
if isinstance(node.op, T.Sum):
# This optimization needs ShapeOpt and fgraph.shape_feature
if not hasattr(node.fgraph, 'shape_feature'):
return
y, = node.outputs
y_shape = node.fgraph.shape_feature.shape_of[y]
def tmp(thing):
try:
return T.get_scalar_constant_value(thing,
only_process_constants=True)
except (TypeError, ValueError) as e:
print(e, thing.owner.inputs[0])
return None
print('LOCAL SUM EMPTY', [tmp(s) for s in y_shape])
################## ##################
# Middleman cuts # # Middleman cuts #
################## ##################
...@@ -4657,23 +4618,6 @@ class Canonizer(gof.LocalOptimizer): ...@@ -4657,23 +4618,6 @@ class Canonizer(gof.LocalOptimizer):
# argument. The leaf-Variables of the graph covered by the # argument. The leaf-Variables of the graph covered by the
# recursion may be of any Variable type. # recursion may be of any Variable type.
if 0:
# UPDATE: This logic makes it impossible to recognize some
# important patterns (e.g. variants on the x/x) and it is
# screwing up the RBM free energy gradient.
# TODO: review this
if len(input.clients) > 1:
# this logic is too conservative, but doing it is
# better than not doing it.
#
# we don't want to canonize a subgraph that we will
# need to compute anyway for the other clients.
# This check is too conservative because if the other
# clients are also in the subgraph we are canonizing,
# then we should [probably?] recurse anyway.
return [input], []
if input.owner is None or input.owner.op not in [ if input.owner is None or input.owner.op not in [
self.main, self.inverse, self.reciprocal]: self.main, self.inverse, self.reciprocal]:
if input.owner and isinstance(input.owner.op, T.DimShuffle): if input.owner and isinstance(input.owner.op, T.DimShuffle):
......
...@@ -203,8 +203,6 @@ class RandomFunction(gof.Op): ...@@ -203,8 +203,6 @@ class RandomFunction(gof.Op):
assert (shape.type.dtype == 'int64') or (shape.type.dtype == 'int32') assert (shape.type.dtype == 'int64') or (shape.type.dtype == 'int32')
if not isinstance(r.type, RandomStateType): if not isinstance(r.type, RandomStateType):
print('WARNING: RandomState instances should be in RandomStateType', file=sys.stderr) print('WARNING: RandomState instances should be in RandomStateType', file=sys.stderr)
if 0:
raise TypeError('r must be RandomStateType instance', r)
# the following doesn't work because we want to ignore the # the following doesn't work because we want to ignore the
# broadcastable flags in shape.type # broadcastable flags in shape.type
# assert shape.type == tensor.lvector # assert shape.type == tensor.lvector
......
...@@ -1285,108 +1285,6 @@ class test_fusion(unittest.TestCase): ...@@ -1285,108 +1285,6 @@ class test_fusion(unittest.TestCase):
print("time", self.do(self.mode, self._shared, shp=(1000, 1000), print("time", self.do(self.mode, self._shared, shp=(1000, 1000),
assert_len_topo=False, slice=s, nb_repeat=100)) assert_len_topo=False, slice=s, nb_repeat=100))
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?
fx = fmatrices('x')
fy = fmatrices('y')
fxv = np.zeros(shp, dtype='float32') + 2
cases = [
(fx, (fx), (fxv), 'float32'), # 1
]
import gc
import pdb
import objgraph
import weakref
d = {}
dl = []
v1 = None
mode = compile.mode.Mode('c', 'merge')
# TODO: if mode is Mode('py','merge') then their is no memory leak!
from theano.compile.function_module import orig_function
for id, [g, sym_inputs, val_inputs, out_dtype] in enumerate(cases):
for zzzz in xrange(nb_repeat):
v = np.zeros(shp, dtype=out_dtype)
gc.collect()
gc.collect()
gc.collect()
v1 = weakref.ref(v) # noqa
pdb.set_trace()
# no memory leak
# f = orig_function([compile.In(fx),compile.In(variable=fy, value=None)],
# [fy+fx],mode=mode)
# memory leak
f = orig_function( # noqa
[compile.In(fx), compile.In(variable=fy, value=v)],
[fy + fx], mode=mode)
del v
gc.collect()
gc.collect()
gc.collect()
pdb.set_trace()
if False:
gc.collect()
gc.collect()
gc.collect()
nd = objgraph.typestats()
print('key, old val, new val, diff')
for key in set(d.keys() + nd.keys()):
if key in d and key in nd and nd[key] != d[key]:
print(key, d.get(key), nd.get(key), end=' ')
if key in d and key in nd:
print(nd[key] - d[key])
else:
print(None)
gc.collect()
gc.collect()
gc.collect()
d = nd
# pdb.set_trace()
if False:
gc.collect()
gc.collect()
gc.collect()
ndl = objgraph.by_type('list')
ll = []
if len(dl) > 0:
nb = 0
for x in ndl:
cmp = not isinstance(x, list)
if not cmp and x:
cmp = (x[0].__class__.__name__ != 'array_converter')
if cmp:
cmp = x[0] != 'Option'
if cmp:
cmp = x[0] != 270
cmp = False
if cmp and x in dl:
nb += 1
ll.append(x)
# pdb.set_trace()
pass
pdb.set_trace()
dl = ndl
gc.collect()
gc.collect()
gc.collect()
# objgraph.show_most_common_types(limit=40)
# f(*val_inputs)
gc.collect()
gc.collect()
gc.collect()
# cases[id]=None #to remove g, that link to out that link to the ndarray!
# g.owner.inputs[0] is out... make owner a weakref?
class TimesN(theano.scalar.basic.UnaryScalarOp): class TimesN(theano.scalar.basic.UnaryScalarOp):
"""Used in test TestCompositeCodegen """Used in test TestCompositeCodegen
...@@ -1506,19 +1404,10 @@ def test_log1p(): ...@@ -1506,19 +1404,10 @@ def test_log1p():
f([1e-7, 10], [[0, 0], [0, 0]]) # debugmode will verify values f([1e-7, 10], [[0, 0], [0, 0]]) # debugmode will verify values
if 0: # should work for int
# at one point this worked, but it has been broken since z = tensor.imatrix()
# the constant up-casting made 1 -> 1.0+0.0j f = function([z], T.log(1 + (z)), mode=m)
# I was never sure if this optimization should work on complex numbers or not. assert [node.op for node in f.maker.fgraph.toposort()] == [T.log1p]
z = tensor.zmatrix()
f = function([z], T.log(1 + (z)), mode=m)
assert [node.op for node in f.maker.fgraph.toposort()] == [T.log1p]
if 1:
# should work for int
z = tensor.imatrix()
f = function([z], T.log(1 + (z)), mode=m)
assert [node.op for node in f.maker.fgraph.toposort()] == [T.log1p]
def test_log_add(): def test_log_add():
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论