提交 cfc2f4e0 authored 作者: Frederic's avatar Frederic

Add the Theano flag optimizer_verbose

上级 a4580829
...@@ -482,6 +482,14 @@ import theano and print the config variable, as in: ...@@ -482,6 +482,14 @@ import theano and print the config variable, as in:
This flag's value cannot be modified during the program execution. This flag's value cannot be modified during the program execution.
.. attribute:: optimizer_verbose
Bool value: either True or False
Default: False
When True, we print on the stdout the optimization applied.
.. attribute:: nocleanup .. attribute:: nocleanup
Bool value: either True or False Bool value: either True or False
......
...@@ -157,6 +157,11 @@ AddConfigVar('optimizer', ...@@ -157,6 +157,11 @@ AddConfigVar('optimizer',
EnumStr('fast_run', 'merge', 'fast_compile', 'None'), EnumStr('fast_run', 'merge', 'fast_compile', 'None'),
in_c_key=False) in_c_key=False)
AddConfigVar('optimizer_verbose',
"If True, we print all optimization being applied",
BoolParam(False),
in_c_key=False)
AddConfigVar('on_opt_error', AddConfigVar('on_opt_error',
("What to do when an optimization crashes: warn and skip it, raise " ("What to do when an optimization crashes: warn and skip it, raise "
"the exception, or fall into the pdb debugger."), "the exception, or fall into the pdb debugger."),
......
...@@ -413,12 +413,15 @@ class FunctionGraph(utils.object2): ...@@ -413,12 +413,15 @@ class FunctionGraph(utils.object2):
self.__prune_r__([r], reason=reason) self.__prune_r__([r], reason=reason)
### replace ### ### replace ###
def replace(self, r, new_r, reason=None, verbose=None):
def replace(self, r, new_r, reason=None):
""" WRITEME """ WRITEME
This is the main interface to manipulate the subgraph in FunctionGraph. This is the main interface to manipulate the subgraph in FunctionGraph.
For every node that uses r as input, makes it use new_r instead. For every node that uses r as input, makes it use new_r instead.
""" """
if verbose is None:
verbose = config.optimizer_verbose
if verbose:
print reason, r, new_r
if r.fgraph is not self: if r.fgraph is not self:
raise Exception("Cannot replace %s because it does not belong to this FunctionGraph" % r, str(reason)) raise Exception("Cannot replace %s because it does not belong to this FunctionGraph" % r, str(reason))
if not r.type == new_r.type: if not r.type == new_r.type:
......
import sys import sys
import time import time
from theano import config
from theano.gof.python25 import partial from theano.gof.python25 import partial
from theano.gof.python25 import OrderedDict from theano.gof.python25 import OrderedDict
from theano.gof import graph from theano.gof import graph
...@@ -197,11 +198,14 @@ class ReplaceValidate(History, Validator): ...@@ -197,11 +198,14 @@ class ReplaceValidate(History, Validator):
def replace_validate(self, fgraph, r, new_r, reason=None): def replace_validate(self, fgraph, r, new_r, reason=None):
self.replace_all_validate(fgraph, [(r, new_r)], reason=reason) self.replace_all_validate(fgraph, [(r, new_r)], reason=reason)
def replace_all_validate(self, fgraph, replacements, reason=None): def replace_all_validate(self, fgraph, replacements,
reason=None, verbose=None):
chk = fgraph.checkpoint() chk = fgraph.checkpoint()
if verbose is None:
verbose = config.optimizer_verbose
for r, new_r in replacements: for r, new_r in replacements:
try: try:
fgraph.replace(r, new_r, reason=reason) fgraph.replace(r, new_r, reason=reason, verbose=False)
except Exception, e: except Exception, e:
if ('The type of the replacement must be the same' not in if ('The type of the replacement must be the same' not in
str(e) and 'does not belong to this FunctionGraph' not in str(e)): str(e) and 'does not belong to this FunctionGraph' not in str(e)):
...@@ -217,6 +221,8 @@ class ReplaceValidate(History, Validator): ...@@ -217,6 +221,8 @@ class ReplaceValidate(History, Validator):
except Exception, e: except Exception, e:
fgraph.revert(chk) fgraph.revert(chk)
raise raise
if verbose:
print reason, r, new_r
return chk return chk
def replace_all_validate_remove(self, fgraph, replacements, def replace_all_validate_remove(self, fgraph, replacements,
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论