提交 0684faa3 authored 作者: Frederic's avatar Frederic

Lower indentation level

上级 b823ef7f
...@@ -175,106 +175,106 @@ def raise_with_op(node, thunk=None, exc_info=None, storage_map=None): ...@@ -175,106 +175,106 @@ def raise_with_op(node, thunk=None, exc_info=None, storage_map=None):
detailed_err_msg += "\nDebugprint of the apply node: \n" detailed_err_msg += "\nDebugprint of the apply node: \n"
detailed_err_msg += f.getvalue() detailed_err_msg += f.getvalue()
# Prints output_map # Prints output_map
if storage_map is not None: if theano.config.exception_verbosity == 'high' and storage_map is not None:
detailed_err_msg += "\nStorage map footprint:\n" detailed_err_msg += "\nStorage map footprint:\n"
shared_input_list = [ shared_input_list = [
item for item in node.fgraph.inputs item for item in node.fgraph.inputs
if isinstance(item, theano.compile.SharedVariable)] if isinstance(item, theano.compile.SharedVariable)]
nonshared_input_list = [ nonshared_input_list = [
item for item in node.fgraph.inputs item for item in node.fgraph.inputs
if not isinstance(item, theano.compile.SharedVariable)] if not isinstance(item, theano.compile.SharedVariable)]
storage_map_list = [] storage_map_list = []
total_size = 0 total_size = 0
total_size_inputs = 0 total_size_inputs = 0
for k in storage_map.keys(): for k in storage_map.keys():
storage_map_item = [] storage_map_item = []
# storage_map_item[0]: the variable # storage_map_item[0]: the variable
storage_map_item.append(str(k)) storage_map_item.append(str(k))
# storage_map_item[1]: the shape # storage_map_item[1]: the shape
shapeinfo = None shapeinfo = None
if hasattr(storage_map[k][0], 'shape'): if hasattr(storage_map[k][0], 'shape'):
shapeinfo = storage_map[k][0].shape shapeinfo = storage_map[k][0].shape
if len(shapeinfo) != 0: if len(shapeinfo) != 0:
storage_map_item.append(shapeinfo) storage_map_item.append(shapeinfo)
else:
storage_map_item.append(tuple())
else:
storage_map_item.append(None)
# storage_map_item[2]: itemsize
# storage_map_item[3]: bytes
if hasattr(storage_map[k][0], 'dtype'):
dtype = storage_map[k][0].dtype
storage_map_item.append(numpy.dtype(dtype).itemsize)
if shapeinfo is None:
storage_map_item.append(None)
else:
sz = numpy.dtype(dtype).itemsize * numpy.prod(shapeinfo)
storage_map_item.append(sz)
total_size += sz
if not k.owner:
total_size_inputs += sz
else:
# If it is a view, don't count it twice.
if getattr(k.owner.op, 'view_map', None):
vmap = k.owner.op.view_map
out_idx = k.owner.outputs.index(k)
data = storage_map[k][0]
if out_idx in vmap:
assert len(vmap[out_idx]) == 1
input_data = storage_map[k.owner.inputs[vmap[out_idx][0]]][0]
if k.type.may_share_memory(data, input_data):
total_size -= sz
# If it is a destroyed input, the input shouldn't be in the storage_map anymore
# except if there is a special flag used. So we still must check it.
if getattr(k.owner.op, 'destroy_map', None):
vmap = k.owner.op.destroy_map
out_idx = k.owner.outputs.index(k)
data = storage_map[k][0]
if out_idx in vmap:
assert len(vmap[out_idx]) == 1
input_data = storage_map[k.owner.inputs[vmap[out_idx][0]]][0]
if k.type.may_share_memory(data, input_data):
total_size -= sz
else:
bytes = getsizeof(storage_map[k][0])
storage_map_item.append(bytes)
storage_map_item.append(None)
# Flag of shared val
# storage_map_item[4]
if k in shared_input_list:
storage_map_item.append(True)
elif k in nonshared_input_list:
storage_map_item.append(False)
else: else:
storage_map_item.append(tuple())
else:
storage_map_item.append(None)
# storage_map_item[2]: itemsize
# storage_map_item[3]: bytes
if hasattr(storage_map[k][0], 'dtype'):
dtype = storage_map[k][0].dtype
storage_map_item.append(numpy.dtype(dtype).itemsize)
if shapeinfo is None:
storage_map_item.append(None) storage_map_item.append(None)
storage_map_list.append(storage_map_item)
from operator import itemgetter
storage_map_list.sort(key=itemgetter(3), reverse=True)
for storage_map_item in storage_map_list:
if storage_map_item[3] is None:
continue
detailed_err_msg += " - " + storage_map_item[0] + ", "
if storage_map_item[4] is True:
detailed_err_msg += "Shared Input, "
elif storage_map_item[4] is False:
detailed_err_msg += "Input, "
if storage_map_item[1] is not None:
detailed_err_msg += "Shape: %s, " % str(storage_map_item[1])
detailed_err_msg += "ElemSize: %s Byte(s)" % storage_map_item[2]
if storage_map_item[3] is not None:
detailed_err_msg += ", TotalSize: %s Byte(s)\n" % storage_map_item[3]
else: else:
detailed_err_msg += "\n" sz = numpy.dtype(dtype).itemsize * numpy.prod(shapeinfo)
detailed_err_msg += " TotalSize: %s Byte(s) %.3f GB\n" % ( storage_map_item.append(sz)
total_size, total_size/1024./1024/1024) total_size += sz
detailed_err_msg += " TotalSize inputs: %s Byte(s) %.3f BG\n" % ( if not k.owner:
total_size_inputs, total_size_inputs/1024./1024/1024) total_size_inputs += sz
else:
# If it is a view, don't count it twice.
if getattr(k.owner.op, 'view_map', None):
vmap = k.owner.op.view_map
out_idx = k.owner.outputs.index(k)
data = storage_map[k][0]
if out_idx in vmap:
assert len(vmap[out_idx]) == 1
input_data = storage_map[k.owner.inputs[vmap[out_idx][0]]][0]
if k.type.may_share_memory(data, input_data):
total_size -= sz
# If it is a destroyed input, the input shouldn't be in the storage_map anymore
# except if there is a special flag used. So we still must check it.
if getattr(k.owner.op, 'destroy_map', None):
vmap = k.owner.op.destroy_map
out_idx = k.owner.outputs.index(k)
data = storage_map[k][0]
if out_idx in vmap:
assert len(vmap[out_idx]) == 1
input_data = storage_map[k.owner.inputs[vmap[out_idx][0]]][0]
if k.type.may_share_memory(data, input_data):
total_size -= sz
else:
bytes = getsizeof(storage_map[k][0])
storage_map_item.append(bytes)
storage_map_item.append(None)
# Flag of shared val
# storage_map_item[4]
if k in shared_input_list:
storage_map_item.append(True)
elif k in nonshared_input_list:
storage_map_item.append(False)
else:
storage_map_item.append(None)
storage_map_list.append(storage_map_item)
from operator import itemgetter
storage_map_list.sort(key=itemgetter(3), reverse=True)
for storage_map_item in storage_map_list:
if storage_map_item[3] is None:
continue
detailed_err_msg += " - " + storage_map_item[0] + ", "
if storage_map_item[4] is True:
detailed_err_msg += "Shared Input, "
elif storage_map_item[4] is False:
detailed_err_msg += "Input, "
if storage_map_item[1] is not None:
detailed_err_msg += "Shape: %s, " % str(storage_map_item[1])
detailed_err_msg += "ElemSize: %s Byte(s)" % storage_map_item[2]
if storage_map_item[3] is not None:
detailed_err_msg += ", TotalSize: %s Byte(s)\n" % storage_map_item[3]
else:
detailed_err_msg += "\n"
detailed_err_msg += " TotalSize: %s Byte(s) %.3f GB\n" % (
total_size, total_size/1024./1024/1024)
detailed_err_msg += " TotalSize inputs: %s Byte(s) %.3f BG\n" % (
total_size_inputs, total_size_inputs/1024./1024/1024)
else: else:
hints.append( hints.append(
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论