提交 a4643310 authored 作者: abergeron's avatar abergeron

Merge pull request #1926 from nouiz/err

Better error when missing inputs.
...@@ -584,13 +584,15 @@ class Function(object): ...@@ -584,13 +584,15 @@ class Function(object):
# done by raise_with_op is not implemented in C. # done by raise_with_op is not implemented in C.
if hasattr(self.fn, 'thunks'): if hasattr(self.fn, 'thunks'):
# For the CVM # For the CVM
gof.vm.raise_with_op(self.fn.nodes[self.fn.position_of_error], gof.vm.raise_with_op(
self.fn.thunks[self.fn.position_of_error]) self.fn.nodes[self.fn.position_of_error],
self.fn.thunks[self.fn.position_of_error])
else: else:
# For the c linker # For the c linker We don't have access from
# We don't have access from python to all the temps values # python to all the temps values So for now, we
# So for now, we just don't print the extra shapes/strides info # just don't print the extra shapes/strides info
gof.vm.raise_with_op(self.fn.nodes[self.fn.position_of_error]) gof.vm.raise_with_op(
self.fn.nodes[self.fn.position_of_error])
else: else:
# old-style linkers raise their own exceptions # old-style linkers raise their own exceptions
raise raise
......
...@@ -4,8 +4,10 @@ fg.py: fg stands for FunctionGraph ...@@ -4,8 +4,10 @@ fg.py: fg stands for FunctionGraph
Contains the FunctionGraph class and exception Contains the FunctionGraph class and exception
types that it can raise types that it can raise
""" """
import StringIO
import sys import sys
import time import time
import traceback
import theano import theano
from theano.gof import graph from theano.gof import graph
...@@ -328,18 +330,29 @@ class FunctionGraph(utils.object2): ...@@ -328,18 +330,29 @@ class FunctionGraph(utils.object2):
#if there is no path then r isn't really a graph input so we shouldn't be running error #if there is no path then r isn't really a graph input so we shouldn't be running error
#handler code in the first place #handler code in the first place
assert path is not None assert path is not None
tr = getattr(r.tag, 'trace', None)
raise MissingInputError(( detailed_err_msg = ""
if tr:
sio = StringIO.StringIO()
traceback.print_list(tr, sio)
tr = sio.getvalue()
detailed_err_msg += "\nBacktrace when the variable is created:\n"
detailed_err_msg += str(tr)
raise MissingInputError(
'A variable that is an input to the graph was ' 'A variable that is an input to the graph was '
'neither provided as an input to the function ' 'neither provided as an input to the function '
'nor given a value. A chain of variables ' 'nor given a value. A chain of variables '
'leading from this input to an output is %s. ' 'leading from this input to an output is %s. '
'This chain may not be unique' % str(path))) 'This chain may not be unique' % str(path) +
detailed_err_msg)
#Standard error message #Standard error message
raise MissingInputError(( raise MissingInputError((
"An input of the graph, used to compute %s, " "An input of the graph, used to compute %s, "
"was not provided and not given a value" "was not provided and not given a value."
"Use the Theano flag exception_verbosity='high',"
"for more information on this error."
% str(node)), % str(node)),
r) r)
......
...@@ -13,7 +13,7 @@ __excepthook = sys.excepthook ...@@ -13,7 +13,7 @@ __excepthook = sys.excepthook
def log_thunk_trace(value, f=sys.stderr): def log_thunk_trace(value, f=sys.stderr):
"""Log theano's diagnostic stack trace for an exception """Log Theano's diagnostic stack trace for an exception
raised by raise_with_op. raised by raise_with_op.
""" """
# in future, consider accepting `write` as arg rather than file # in future, consider accepting `write` as arg rather than file
...@@ -149,7 +149,7 @@ def raise_with_op(node, thunk=None, exc_info=None): ...@@ -149,7 +149,7 @@ def raise_with_op(node, thunk=None, exc_info=None):
sio = StringIO.StringIO() sio = StringIO.StringIO()
traceback.print_list(tr, sio) traceback.print_list(tr, sio)
tr = sio.getvalue() tr = sio.getvalue()
detailed_err_msg += "\nBacktrace when the node is created:" detailed_err_msg += "\nBacktrace when the node is created:\n"
detailed_err_msg += str(tr) detailed_err_msg += str(tr)
else: else:
hints.append( hints.append(
......
...@@ -19,17 +19,18 @@ import theano.gof.cmodule ...@@ -19,17 +19,18 @@ import theano.gof.cmodule
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
AddConfigVar('profile', AddConfigVar('profile',
"If VM should collect profile information", "If VM should collect profile information",
BoolParam(False), BoolParam(False),
in_c_key=False) in_c_key=False)
AddConfigVar('profile_optimizer', AddConfigVar('profile_optimizer',
"If VM should collect optimizer profile information", "If VM should collect optimizer profile information",
BoolParam(False), BoolParam(False),
in_c_key=False) in_c_key=False)
AddConfigVar('profile_memory', AddConfigVar('profile_memory',
"If VM should collect memory profile information and print it", "If VM should collect memory profile information and print it",
BoolParam(False), BoolParam(False),
in_c_key=False) in_c_key=False)
def filter_vm_lazy(val): def filter_vm_lazy(val):
if val == 'False' or val is False: if val == 'False' or val is False:
...@@ -40,7 +41,7 @@ def filter_vm_lazy(val): ...@@ -40,7 +41,7 @@ def filter_vm_lazy(val):
return None return None
else: else:
raise ValueError('Valid values for an vm.lazy parameter ' raise ValueError('Valid values for an vm.lazy parameter '
'should be None, False or True, not `%s`.' % val) 'should be None, False or True, not `%s`.' % val)
AddConfigVar('vm.lazy', AddConfigVar('vm.lazy',
"Useful only for the vm linkers. When lazy is None," "Useful only for the vm linkers. When lazy is None,"
......
...@@ -11,7 +11,6 @@ from theano.tensor.utils import hash_from_ndarray ...@@ -11,7 +11,6 @@ from theano.tensor.utils import hash_from_ndarray
from theano.tensor.type import TensorType from theano.tensor.type import TensorType
class AsTensorError(TypeError): class AsTensorError(TypeError):
"""Raised when as_tensor_variable isn't able to create a """Raised when as_tensor_variable isn't able to create a
TensorVariable. TensorVariable.
...@@ -560,13 +559,16 @@ class _tensor_py_operators: ...@@ -560,13 +559,16 @@ class _tensor_py_operators:
def swapaxes(self, axis1, axis2): def swapaxes(self, axis1, axis2):
"""Return 'tensor.swapaxes(self, axis1, axis2) """Return 'tensor.swapaxes(self, axis1, axis2)
If a matrix is provided with the right axes, its transpose will be returned. If a matrix is provided with the right axes, its transpose
will be returned.
""" """
return theano.tensor.basic.swapaxes(self, axis1, axis2) return theano.tensor.basic.swapaxes(self, axis1, axis2)
def fill(self, value): def fill(self, value):
"""Fill inputted tensor with the assigned value""" """Fill inputted tensor with the assigned value"""
return theano.tensor.basic.fill(self, value) return theano.tensor.basic.fill(self, value)
class TensorVariable(_tensor_py_operators, Variable): class TensorVariable(_tensor_py_operators, Variable):
"""Subclass to add the tensor operators to the basic `Variable` class.""" """Subclass to add the tensor operators to the basic `Variable` class."""
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论