提交 51f375bf authored 作者: carriepl's avatar carriepl

Merge pull request #2292 from ballasn/memoutput

Output StorageMap content in raise_with_op
......@@ -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.vm.raise_with_op(
self.fn.nodes[self.fn.position_of_error])
gof.link.raise_with_op(
self.fn.nodes[self.fn.position_of_error],
storage_map=self.fn.storage_map)
else:
# old-style linkers raise their own exceptions
raise
......
"""WRITEME"""
from copy import copy, deepcopy
from sys import getsizeof
import StringIO
import sys
import traceback
import numpy
import theano
from theano.gof import utils
......@@ -58,7 +60,7 @@ sys.excepthook = thunk_hook
# TODO: Make this work with linker defined schedule
def raise_with_op(node, thunk=None, exc_info=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.
......@@ -71,6 +73,9 @@ def raise_with_op(node, thunk=None, exc_info=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
-----
......@@ -162,16 +167,44 @@ def raise_with_op(node, thunk=None, exc_info=None):
" Theano optimizations can be disabled with 'optimizer=None'.")
if theano.config.exception_verbosity == 'high':
f = StringIO.StringIO()
theano.printing.debugprint(node, file=f, stop_on_name=True,
print_type=True)
detailed_err_msg += "\nDebugprint of the apply node: \n"
detailed_err_msg += f.getvalue()
# Prints output_map
if storage_map is not None:
detailed_err_msg += "\nStorage map footprint:\n"
for k in storage_map.keys():
if storage_map[k][0] is not None:
detailed_err_msg += " - " + str(k) + ", "
shapeinfo = None
if hasattr(storage_map[k][0], 'shape'):
shapeinfo = storage_map[k][0].shape
if len(shapeinfo) != 0:
detailed_err_msg += "Shape: %s, " % str(shapeinfo)
else:
detailed_err_msg += "Shape: (1,), "
if hasattr(storage_map[k][0], 'dtype'):
dtype = storage_map[k][0].dtype
detailed_err_msg += "ElemSize: %s Byte(s)" % numpy.dtype(dtype).itemsize
if shapeinfo is None:
detailed_err_msg += "\n"
else:
detailed_err_msg += ", TotalSize: %s Byte(s)\n" % (numpy.dtype(dtype).itemsize * numpy.prod(shapeinfo))
else:
bytes = getsizeof(storage_map[k][0])
detailed_err_msg += "ElemSize: %s Byte(s)\n" % str(bytes)
else:
hints.append(
"HINT: Use the Theano flag 'exception_verbosity=high'"
" for a debugprint of this apply node.")
" for a debugprint and storage map footprint of this apply node.")
exc_value = exc_type(str(exc_value) + detailed_err_msg +
'\n' + '\n'.join(hints))
......
......@@ -52,9 +52,6 @@ AddConfigVar('vm.lazy',
ConfigParam('None', filter_vm_lazy),
in_c_key=False)
raise_with_op = link.raise_with_op
class VM(object):
"""
......@@ -180,7 +177,7 @@ class Loop(VM):
self.call_counts[i] += 1
self.call_times[i] += t1 - t0
except:
raise_with_op(node, thunk)
link.raise_with_op(node, thunk)
else:
for cont in self.pre_call_clear:
cont[0] = None
......@@ -188,7 +185,7 @@ class Loop(VM):
for thunk, node in zip(self.thunks, self.nodes):
thunk()
except:
raise_with_op(node, thunk)
link.raise_with_op(node, thunk)
class LoopGC(VM):
......@@ -222,7 +219,7 @@ class LoopGC(VM):
old_s[0] = None
i += 1
except:
raise_with_op(node, thunk)
link.raise_with_op(node, thunk)
else:
for cont in self.pre_call_clear:
cont[0] = None
......@@ -233,7 +230,7 @@ class LoopGC(VM):
for old_s in old_storage:
old_s[0] = None
except:
raise_with_op(node, thunk)
link.raise_with_op(node, thunk)
class Stack(VM):
......@@ -425,8 +422,9 @@ class Stack(VM):
st = "c"
self.variable_strides[var] = st
except Exception:
raise_with_op(current_apply,
self.thunks[self.node_idx[current_apply]])
link.raise_with_op(current_apply,
self.thunks[self.node_idx[current_apply]],
storage_map=storage_map)
for o in current_apply.outputs:
compute_map[o][0] = 1
......@@ -494,8 +492,9 @@ class Stack(VM):
self.call_times[current_idx] += dt
except Exception:
raise_with_op(current_apply,
self.thunks[self.node_idx[current_apply]])
link.raise_with_op(current_apply,
self.thunks[self.node_idx[current_apply]],
storage_map)
if requires:
for r in requires:
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论