提交 80db2da2 authored 作者: Hengjean's avatar Hengjean 提交者: Frederic

Updated current progress on same fgraph debug.

上级 a5ee246d
...@@ -1091,24 +1091,26 @@ class FunctionMaker(object): ...@@ -1091,24 +1091,26 @@ class FunctionMaker(object):
''' '''
graph_db and need_optimize graph_db and need_optimize
''' '''
try: if os.path.isfile(graph_db_file):
f = open(graph_db_file, 'r+b')
print 'graph_db exists' print 'graph_db exists'
except IOError: else:
# create graph_db # create graph_db
f = open(graph_db_file, 'w+b') f = open(graph_db_file, 'w+b')
print 'created new graph_db %s'%graph_db_file print 'created new graph_db %s' % graph_db_file
f.close
# load the graph_db dictionary # load the graph_db dictionary
try: try:
f = open(graph_db_file, 'r+b')
graph_db = pickle.load(f) graph_db = pickle.load(f)
f.close()
print 'graph_db is not empty' print 'graph_db is not empty'
except EOFError, e: except EOFError, e:
# the file has nothing in it # the file has nothing in it
print e print e
print 'graph_db is empty' print 'graph_db is empty'
graph_db = {} graph_db = {}
print 'loaded graph_db from %s, size=%d'%(graph_db_file,len(graph_db)) print 'loaded graph_db from %s, size=%d'%(graph_db_file,len(graph_db))
need_optimize = True need_optimize = True
# the sole purpose of this loop is to set 'need_optimize' # the sole purpose of this loop is to set 'need_optimize'
...@@ -1146,18 +1148,31 @@ class FunctionMaker(object): ...@@ -1146,18 +1148,31 @@ class FunctionMaker(object):
flags = [] flags = []
for output_new, output_old in zip(outputs_new, outputs_old): for output_new, output_old in zip(outputs_new, outputs_old):
print 'loop through outputs node for both graphs' print 'loop through outputs node for both graphs'
t1 = copy.deepcopy(output_new) t1 = copy.deepcopy(output_new)
t2 = copy.deepcopy(output_old) t2 = copy.deepcopy(output_old)
# is_same_graph complains if fgraph is not None # is_same_graph complains if fgraph is not None
del t1.owner.fgraph
del t2.owner.fgraph def removeAllFgraph(remove):
del t1.fgraph if hasattr(remove, 'fgraph'):
del t2.fgraph remove.fgraph = None
if hasattr(remove, 'owner'):
flag = is_same_graph(t1, t2 ,givens=givens) if remove.owner == None:
remove.fgraph = None
else:
if hasattr(remove.owner, 'fgraph'):
remove.owner.fgraph = None
if hasattr(remove.owner, 'inputs'):
remove.owner.inputs = [removeAllFgraph(
i) for i in remove.owner.inputs]
return remove
t1 = removeAllFgraph(t1)
t2 = removeAllFgraph(t2)
flag = is_same_graph(t1, t2, givens=givens)
flags.append(flag) flags.append(flag)
is_same = all(flags) is_same = all(flags)
if is_same: if is_same:
# found the match # found the match
...@@ -1183,16 +1198,16 @@ class FunctionMaker(object): ...@@ -1183,16 +1198,16 @@ class FunctionMaker(object):
cPickle.load(test_file) cPickle.load(test_file)
''' '''
graph_db.update({before_opt:fgraph}) graph_db.update({before_opt:fgraph})
f = open(graph_db_file, 'w+b')
pickle.dump(graph_db, f, -1) pickle.dump(graph_db, f, -1)
f.close()
print 'saved into graph_db' print 'saved into graph_db'
else: else:
print 'no opt, get graph from graph_db' print 'no opt, get graph from graph_db'
# just read the optmized graph from graph_db # just read the optmized graph from graph_db
opt_time = 0 opt_time = 0
fgraph = graph_db[fgraph] fgraph = graph_db[fgraph]
# release stuff # release stuff
f.close()
release_lock() release_lock()
return opt_time return opt_time
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论