提交 1dab0010 authored 作者: Nicolas Ballas's avatar Nicolas Ballas

add storage_map dbg infos in raise_with_op

上级 56aa741b
......@@ -602,13 +602,15 @@ class Function(object):
# For the CVM
gof.link.raise_with_op(
self.fn.nodes[self.fn.position_of_error],
self.fn.thunks[self.fn.position_of_error])
self.fn.thunks[self.fn.position_of_error],
storage_map=self.fn.storage_map)
else:
# For the c linker We don't have access from
# python to all the temps values So for now, we
# just don't print the extra shapes/strides info
gof.link.raise_with_op(
self.fn.nodes[self.fn.position_of_error])
self.fn.nodes[self.fn.position_of_error],
storage_map=self.fn.storage_map)
else:
# old-style linkers raise their own exceptions
raise
......
......@@ -56,7 +56,7 @@ sys.excepthook = thunk_hook
# TODO: Make this work with linker defined schedule
def raise_with_op(node, thunk=None, exc_info=None, func=None):
def raise_with_op(node, thunk=None, exc_info=None, storage_map=None):
"""
Re-raise an exception while annotating the exception object with
debug info.
......@@ -69,6 +69,9 @@ def raise_with_op(node, thunk=None, exc_info=None, func=None):
A tuple containing the exception type, exception object and
associated traceback, as would be returned by a call to
`sys.exc_info()` (which is done if `None` is passed).
storage_map: dict, optional
storage map of the theano function that resulted in the
raised exception.
Notes
-----
......@@ -89,6 +92,7 @@ def raise_with_op(node, thunk=None, exc_info=None, func=None):
"""
if exc_info is None:
exc_info = sys.exc_info()
print exc_info
exc_type, exc_value, exc_trace = exc_info
if exc_type == KeyboardInterrupt:
# print a simple traceback from KeyboardInterrupt
......@@ -171,6 +175,16 @@ def raise_with_op(node, thunk=None, exc_info=None, func=None):
"HINT: Use the Theano flag 'exception_verbosity=high'"
" for a debugprint of this apply node.")
# Prints output_map
if storage_map is not None:
from sys import getsizeof
detailed_err_msg += "\nStorage Map memory print:\n"
for k in storage_map.keys():
if storage_map[k][0] is not None:
bytes = getsizeof(storage_map[k][0])
detailed_err_msg += str(k) + ": " + str(bytes) + " bytes\n"
exc_value = exc_type(str(exc_value) + detailed_err_msg +
'\n' + '\n'.join(hints))
raise exc_type, exc_value, exc_trace
......
......@@ -416,7 +416,8 @@ class Stack(VM):
self.variable_strides[var] = st
except Exception:
link.raise_with_op(current_apply,
self.thunks[self.node_idx[current_apply]])
self.thunks[self.node_idx[current_apply]],
storage_map)
for o in current_apply.outputs:
compute_map[o][0] = 1
......@@ -484,7 +485,8 @@ class Stack(VM):
except Exception:
link.raise_with_op(current_apply,
self.thunks[self.node_idx[current_apply]])
self.thunks[self.node_idx[current_apply]],
storage_map)
if requires:
for r in requires:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论