提交 4f375851 authored 作者: Frederic Bastien's avatar Frederic Bastien

added 3 theano flags optimizer_including, optimizer_excluding,…

added 3 theano flags optimizer_including, optimizer_excluding, optimizer_requiring. If using the default mode, this allow to select via the corresponding fct the optimizer to use.
上级 7ac2df31
...@@ -2,12 +2,22 @@ ...@@ -2,12 +2,22 @@
""" """
import os, logging import os, logging
import numpy import numpy, theano
from theano import gof from theano import gof
from theano.configparser import config from theano.configparser import config, AddConfigVar, StrParam
_logger = logging.getLogger('theano.compile.mode') _logger = logging.getLogger('theano.compile.mode')
AddConfigVar('optimizer_excluding',
"When using the default mode, we will remove optimizer with that tag",
StrParam(""))
AddConfigVar('optimizer_including',
"When using the default mode, we will add optimizer with that tag",
StrParam(""))
AddConfigVar('optimizer_requiring',
"When using the default mode, we will require optimizer with that tag",
StrParam(""))
def check_equal(x, y): def check_equal(x, y):
""" """
Returns True iff x[0] and y[0] are equal (checks the dtype and Returns True iff x[0] and y[0] are equal (checks the dtype and
...@@ -254,10 +264,10 @@ predefined_modes = {'FAST_COMPILE': FAST_COMPILE, ...@@ -254,10 +264,10 @@ predefined_modes = {'FAST_COMPILE': FAST_COMPILE,
'SANITY_CHECK': SANITY_CHECK} 'SANITY_CHECK': SANITY_CHECK}
instanciated_default_mode=None instanciated_default_mode=None
def get_mode(string): def get_mode(orig_string):
if string is None: if orig_string is None:
string = config.mode string = config.mode
else: string = orig_string
if not isinstance(string, str): return string #it is hopefully already a mode... if not isinstance(string, str): return string #it is hopefully already a mode...
global instanciated_default_mode global instanciated_default_mode
...@@ -272,11 +282,21 @@ def get_mode(string): ...@@ -272,11 +282,21 @@ def get_mode(string):
#must tell python to print the summary at the end. #must tell python to print the summary at the end.
if string == 'ProfileMode': if string == 'ProfileMode':
prof_mode_instance_to_print.append(instanciated_default_mode) prof_mode_instance_to_print.append(instanciated_default_mode)
return instanciated_default_mode ret = instanciated_default_mode
if not predefined_modes.has_key(string): elif not predefined_modes.has_key(string):
raise Exception("No predefined mode exist for string: %s"%string) raise Exception("No predefined mode exist for string: %s"%string)
return predefined_modes[string] else: ret = predefined_modes[string]
if orig_string is None:
if theano.config.optimizer_excluding:
ret = ret.excluding(theano.config.optimizer_excluding)
if theano.config.optimizer_including:
ret = ret.including(theano.config.optimizer_including)
if theano.config.optimizer_requiring:
ret = ret.requiring(theano.config.optimizer_requiring)
instanciated_default_mode = ret
return ret
def get_default_mode(): def get_default_mode():
return get_mode(None) return get_mode(None)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论