提交 9ccbda50 authored 作者: Frédéric Bastien's avatar Frédéric Bastien

Merge pull request #3066 from t13m/debug_flag_print_rejected_optimizations

Debug flag print rejected optimizations when validate fails
...@@ -538,7 +538,6 @@ AddConfigVar( ...@@ -538,7 +538,6 @@ AddConfigVar(
BoolParam(True, allow_override=True), BoolParam(True, allow_override=True),
in_c_key=False) in_c_key=False)
"""Note to developers: """Note to developers:
Generally your exceptions should use an apply node's __str__ Generally your exceptions should use an apply node's __str__
method when exception_verbosity == 'low'. When exception_verbosity method when exception_verbosity == 'low'. When exception_verbosity
......
...@@ -2,6 +2,7 @@ from __future__ import print_function ...@@ -2,6 +2,7 @@ from __future__ import print_function
from functools import partial from functools import partial
import sys import sys
import time import time
import inspect
import theano import theano
from theano import config from theano import config
...@@ -200,7 +201,27 @@ class Validator(Feature): ...@@ -200,7 +201,27 @@ class Validator(Feature):
def validate_(self, fgraph): def validate_(self, fgraph):
t0 = time.time() t0 = time.time()
ret = fgraph.execute_callbacks('validate') try:
ret = fgraph.execute_callbacks('validate')
except Exception as e:
cf = inspect.currentframe()
uf = cf.f_back
uf_info = inspect.getframeinfo(uf)
# If the caller is replace_all_validate, just raise the
# exception. replace_all_validate will print out the
# verbose output.
# Or it has to be done here before raise.
if uf_info.function == 'replace_all_validate':
raise
else:
verbose = uf.f_locals.get('verbose', False)
if verbose:
r = uf.f_locals.get('r', "")
reason = uf_info.function
print("validate failed on node %s.\n Reason: %s, %s" %
(r, reason, e))
raise
t1 = time.time() t1 = time.time()
if fgraph.profile: if fgraph.profile:
fgraph.profile.validate_time += t1 - t0 fgraph.profile.validate_time += t1 - t0
...@@ -272,6 +293,8 @@ class ReplaceValidate(History, Validator): ...@@ -272,6 +293,8 @@ class ReplaceValidate(History, Validator):
fgraph.validate() fgraph.validate()
except Exception as e: except Exception as e:
fgraph.revert(chk) fgraph.revert(chk)
if verbose:
print("validate failed on node %s.\n Reason: %s, %s" % (r, reason, e))
raise raise
if verbose: if verbose:
print(reason, r, new_r) print(reason, r, new_r)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论