提交 6f4c3dc5 authored 作者: Li's avatar Li 提交者: Frederic

opt caching pkl optmized graph problem

上级 2dc51295
...@@ -1108,7 +1108,7 @@ class FunctionMaker(object): ...@@ -1108,7 +1108,7 @@ class FunctionMaker(object):
print 'loaded %s, size=%d'%(graph_db_file,len(graph_db)) print 'loaded %s, size=%d'%(graph_db_file,len(graph_db))
need_optimize = True need_optimize = True
# the sole purpose of this loop is to fill 'same_graph_found' # the sole purpose of this loop is to set 'need_optimize'
for graph_old in graph_db.keys(): for graph_old in graph_db.keys():
inputs_old = graph_old.inputs inputs_old = graph_old.inputs
outputs_old = graph_old.outputs outputs_old = graph_old.outputs
...@@ -1121,24 +1121,40 @@ class FunctionMaker(object): ...@@ -1121,24 +1121,40 @@ class FunctionMaker(object):
# two graphs are for sure different # two graphs are for sure different
continue continue
else: else:
# if the both inputs are of the same size # when the both inputs are of the same size
givens = dict(zip(inputs_new, inputs_old)) givens = dict(zip(inputs_new, inputs_old))
is_same = is_same_graph(outputs_new, outputs_old, is_same = is_same_graph(outputs_new, outputs_old,
givens=givens) givens=givens)
if is_same: if is_same:
# found the match
print 'found the match'
need_optimize = False need_optimize = False
break break
# now optimize or not # now optimize or not
if need_optimize: if need_optimize:
# this is a brand new graph, optimize it, save it to graph_db # this is a brand new graph, optimize it, save it to graph_db
import ipdb; ipdb.set_trace()
test_file = open(theano.config.compiledir + '/test.pkl', 'w+')
cPickle.dump(fgraph, test_file)
test_file.close()
test_file = open(theano.config.compiledir + '/test.pkl', 'r')
cPickle.load(test_file)
print 'Need to optimize the graph' print 'Need to optimize the graph'
before_opt = copy.deepcopy(fgraph) before_opt = copy.deepcopy(fgraph)
start_optimizer = time.time() start_optimizer = time.time()
optimizer_profile = optimizer(fgraph) optimizer_profile = optimizer(fgraph)
end_optimizer = time.time() end_optimizer = time.time()
opt_time = end_optimizer - start_optimizer opt_time = end_optimizer - start_optimizer
import ipdb; ipdb.set_trace() import ipdb; ipdb.set_trace()
test_file = open(theano.config.compiledir + '/test.pkl', 'w+')
cPickle.dump(fgraph, test_file)
test_file.close()
test_file = open(theano.config.compiledir + '/test.pkl', 'r')
cPickle.load(test_file)
graph_db.update({before_opt:fgraph}) graph_db.update({before_opt:fgraph})
cPickle.dump(graph_db, f) cPickle.dump(graph_db, f)
else: else:
...@@ -1150,7 +1166,7 @@ class FunctionMaker(object): ...@@ -1150,7 +1166,7 @@ class FunctionMaker(object):
# release stuff # release stuff
f.close() f.close()
release_lock() release_lock()
opt_time return opt_time
opt_time = optimize_graph(fgraph) opt_time = optimize_graph(fgraph)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论