提交 62508f2d authored 作者: Pascal Lamblin's avatar Pascal Lamblin

Add config.time_eq_optimizer

Like config.time_seq_optimizer, prints timing information on EquilibriumOptimizer. Also change a little bit how config.time_seq_optimizer prints some informations.
上级 c1366d70
...@@ -29,6 +29,11 @@ AddConfigVar('time_seq_optimizer', ...@@ -29,6 +29,11 @@ AddConfigVar('time_seq_optimizer',
BoolParam(False), BoolParam(False),
in_c_key=False) in_c_key=False)
AddConfigVar('time_eq_optimizer',
"Should EquilibriumOptimizer print the time taken by each optimizer",
BoolParam(False),
in_c_key=False)
import destroyhandler as dh import destroyhandler as dh
import traceback import traceback
...@@ -174,7 +179,10 @@ class SeqOptimizer(Optimizer, list): ...@@ -174,7 +179,10 @@ class SeqOptimizer(Optimizer, list):
if a[0]<b[0]: return -1 if a[0]<b[0]: return -1
return 1 return 1
lll.sort(cmp) lll.sort(cmp)
print lll
for (t, opt) in lll[::-1]:
print ' %.6fs - %s' % (t, opt)
print
def __eq__(self, other): def __eq__(self, other):
#added to override the list's __eq__ implementation #added to override the list's __eq__ implementation
...@@ -1115,7 +1123,12 @@ class EquilibriumOptimizer(NavigatorOptimizer): ...@@ -1115,7 +1123,12 @@ class EquilibriumOptimizer(NavigatorOptimizer):
process_count = {} process_count = {}
max_nb_nodes = 0 max_nb_nodes = 0
loop_timing = []
global_opt_timing = []
nb_nodes = []
while changed and not max_use_abort: while changed and not max_use_abort:
t0 = time.time()
changed = False changed = False
#apply global optimizer #apply global optimizer
...@@ -1125,12 +1138,15 @@ class EquilibriumOptimizer(NavigatorOptimizer): ...@@ -1125,12 +1138,15 @@ class EquilibriumOptimizer(NavigatorOptimizer):
if env.change_tracker.changed: if env.change_tracker.changed:
changed = True changed = True
global_opt_timing.append(float(time.time() - t0))
#apply local optimizer #apply local optimizer
for node in start_from: for node in start_from:
assert node in env.outputs assert node in env.outputs
q = deque(graph.io_toposort(env.inputs, start_from)) q = deque(graph.io_toposort(env.inputs, start_from))
nb_nodes.append(len(q))
max_nb_nodes = max(max_nb_nodes, len(q)) max_nb_nodes = max(max_nb_nodes, len(q))
max_use = max_nb_nodes * self.max_use_ratio max_use = max_nb_nodes * self.max_use_ratio
def importer(node): def importer(node):
...@@ -1163,12 +1179,37 @@ class EquilibriumOptimizer(NavigatorOptimizer): ...@@ -1163,12 +1179,37 @@ class EquilibriumOptimizer(NavigatorOptimizer):
finally: finally:
self.detach_updater(env, u) self.detach_updater(env, u)
self.detach_updater(env, u) #TODO: erase this line, it's redundant at best self.detach_updater(env, u) #TODO: erase this line, it's redundant at best
loop_timing.append(float(time.time() - t0))
if max_use_abort: if max_use_abort:
_logger.error("EquilibriumOptimizer max'ed out by '%s'" % opt_name _logger.error("EquilibriumOptimizer max'ed out by '%s'" % opt_name
+ ". You can safely raise the current threshold of " + ". You can safely raise the current threshold of "
+ "%f with the theano flag 'optdb.max_use_ratio'." % + "%f with the theano flag 'optdb.max_use_ratio'." %
config.optdb.max_use_ratio) config.optdb.max_use_ratio)
if config.time_eq_optimizer:
print "EquilibriumOptimizer",
print getattr(self, "name", getattr(self, "__name__", ""))
print " time %.3fs for %d passes, %d nodes max" % (
sum(loop_timing), len(loop_timing), max_nb_nodes)
for i in range(len(loop_timing)):
print '%d - %.3fs (%.3fs in global opts) - %d nodes' % (
i, loop_timing[i], global_opt_timing[i], nb_nodes[i])
print
count_opt = []
for opt, count in process_count.iteritems():
if count > 0:
count_opt.append((count, opt))
if count_opt:
print 'times applied - optimizer:'
count_opt.sort()
for (count, opt) in count_opt[::-1]:
print ' %d - %s' % (count, opt)
print
def print_summary(self, stream=sys.stdout, level=0, depth=-1): def print_summary(self, stream=sys.stdout, level=0, depth=-1):
name = getattr(self, 'name', None) name = getattr(self, 'name', None)
print >> stream, "%s%s %s id=%i" %(' '*level, self.__class__.__name__, name, id(self)) print >> stream, "%s%s %s id=%i" %(' '*level, self.__class__.__name__, name, id(self))
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论