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

New Theano flag on_unused_input that default the default value.

上级 195e8380
...@@ -42,6 +42,8 @@ Interface changes ...@@ -42,6 +42,8 @@ Interface changes
instance, function([x, y], [y]). You can use the kwarg instance, function([x, y], [y]). You can use the kwarg
``on_unused_input={'raise', 'warn', 'ignore'}`` to control this. ``on_unused_input={'raise', 'warn', 'ignore'}`` to control this.
(Pascal L.) (Pascal L.)
* New Theano flag "on_unused_input" that define the default value of the
previous point. (Frederic B.)
* tensor.alloc() now raises an error during graph build time * tensor.alloc() now raises an error during graph build time
when we try to create less dimensions than the number of dimensions when we try to create less dimensions than the number of dimensions
the provided value have. In the past, the error was at run time. the provided value have. In the past, the error was at run time.
......
...@@ -2065,7 +2065,7 @@ class _Maker(FunctionMaker): # inheritance buys a few helper functions ...@@ -2065,7 +2065,7 @@ class _Maker(FunctionMaker): # inheritance buys a few helper functions
accept_inplace = False, accept_inplace = False,
function_builder = Function, function_builder = Function,
profile=None, profile=None,
on_unused_input='raise'): on_unused_input=None):
""" """
:type inputs: a list of SymbolicInput instances :type inputs: a list of SymbolicInput instances
......
...@@ -14,7 +14,7 @@ from numpy import any #for to work in python 2.4 ...@@ -14,7 +14,7 @@ from numpy import any #for to work in python 2.4
def function(inputs, outputs=None, mode=None, updates=None, givens=None, def function(inputs, outputs=None, mode=None, updates=None, givens=None,
no_default_updates=False, accept_inplace=False, name=None, no_default_updates=False, accept_inplace=False, name=None,
rebuild_strict=True, allow_input_downcast=None, profile=None, rebuild_strict=True, allow_input_downcast=None, profile=None,
on_unused_input='raise'): on_unused_input=None):
""" """
Return a callable object that will calculate `outputs` from `inputs`. Return a callable object that will calculate `outputs` from `inputs`.
...@@ -70,7 +70,7 @@ def function(inputs, outputs=None, mode=None, updates=None, givens=None, ...@@ -70,7 +70,7 @@ def function(inputs, outputs=None, mode=None, updates=None, givens=None,
used. This profiling object will be available via self.profile. used. This profiling object will be available via self.profile.
:param on_unused_input: What to do if a variable in the 'inputs' list is :param on_unused_input: What to do if a variable in the 'inputs' list is
not used in the graph. Possible values are 'raise', 'warn', and 'ignore'. not used in the graph. Possible values are 'raise', 'warn', 'ignore' and None.
:note: Regarding givens: Be careful to make sure that these substitutions are :note: Regarding givens: Be careful to make sure that these substitutions are
independent--behaviour when Var1 of one pair appears in the graph leading to Var2 in independent--behaviour when Var1 of one pair appears in the graph leading to Var2 in
......
...@@ -965,7 +965,7 @@ class FunctionMaker(object): ...@@ -965,7 +965,7 @@ class FunctionMaker(object):
def __init__(self, inputs, outputs, def __init__(self, inputs, outputs,
mode = None, accept_inplace = False, function_builder = Function, mode = None, accept_inplace = False, function_builder = Function,
profile=None, on_unused_input='raise'): profile=None, on_unused_input=None):
""" """
:type inputs: a list of SymbolicInput instances :type inputs: a list of SymbolicInput instances
...@@ -982,9 +982,10 @@ class FunctionMaker(object): ...@@ -982,9 +982,10 @@ class FunctionMaker(object):
:param on_unused_input: What to do if a variable in the 'inputs' list :param on_unused_input: What to do if a variable in the 'inputs' list
is not used in the graph. Possible values are: is not used in the graph. Possible values are:
- 'raise' (default): raise an error - 'raise': raise an error
- 'warn': log a warning - 'warn': log a warning
- 'ignore': do not do anything - 'ignore': do not do anything
- None: Use the value in the Theano flags on_unused_input
""" """
mode = mode_module.get_mode(mode) mode = mode_module.get_mode(mode)
...@@ -1090,6 +1091,9 @@ class FunctionMaker(object): ...@@ -1090,6 +1091,9 @@ class FunctionMaker(object):
for i in self.inputs] for i in self.inputs]
def _check_unused_inputs(self, inputs, outputs, on_unused_input): def _check_unused_inputs(self, inputs, outputs, on_unused_input):
if on_unused_input is None:
on_unused_input = theano.config.on_unused_input
if on_unused_input == 'ignore': if on_unused_input == 'ignore':
return return
...@@ -1256,7 +1260,7 @@ def register_checker(checker): ...@@ -1256,7 +1260,7 @@ def register_checker(checker):
def orig_function(inputs, outputs, mode=None, accept_inplace=False, def orig_function(inputs, outputs, mode=None, accept_inplace=False,
name=None, profile=None, on_unused_input='raise'): name=None, profile=None, on_unused_input=None):
""" """
Return a Function that will calculate the outputs from the inputs. Return a Function that will calculate the outputs from the inputs.
...@@ -1290,7 +1294,8 @@ def orig_function(inputs, outputs, mode=None, accept_inplace=False, ...@@ -1290,7 +1294,8 @@ def orig_function(inputs, outputs, mode=None, accept_inplace=False,
:param profile: None or ProfileStats instance :param profile: None or ProfileStats instance
:param on_unused_input: What to do if a variable in the 'inputs' list is :param on_unused_input: What to do if a variable in the 'inputs' list is
not used in the graph. Possible values are 'raise', 'warn', and 'ignore'. not used in the graph. Possible values are 'raise', 'warn', 'ignore'
and None
""" """
# Every element of the input list will be upgraded to an `In` instance if # Every element of the input list will be upgraded to an `In` instance if
......
...@@ -325,7 +325,7 @@ class Param(object): ...@@ -325,7 +325,7 @@ class Param(object):
def pfunc(params, outputs=None, mode=None, updates=None, givens=None, def pfunc(params, outputs=None, mode=None, updates=None, givens=None,
no_default_updates=False, accept_inplace=False, name=None, no_default_updates=False, accept_inplace=False, name=None,
rebuild_strict=True, allow_input_downcast=None, rebuild_strict=True, allow_input_downcast=None,
profile=None, on_unused_input='raise'): profile=None, on_unused_input=None):
"""Function-constructor for graphs with shared variables. """Function-constructor for graphs with shared variables.
:type params: list of either Variable or Param instances. :type params: list of either Variable or Param instances.
...@@ -375,8 +375,8 @@ def pfunc(params, outputs=None, mode=None, updates=None, givens=None, ...@@ -375,8 +375,8 @@ def pfunc(params, outputs=None, mode=None, updates=None, givens=None,
:type on_unused_input: str :type on_unused_input: str
:param on_unused_input: What to do if a variable in the 'inputs' list :param on_unused_input: What to do if a variable in the 'inputs' list
is not used in the graph. Possible values are 'raise', 'warn', and is not used in the graph. Possible values are 'raise', 'warn',
'ignore. 'ignore' and None.
:rtype: theano.compile.Function :rtype: theano.compile.Function
......
...@@ -159,6 +159,11 @@ AddConfigVar('nocleanup', ...@@ -159,6 +159,11 @@ AddConfigVar('nocleanup',
BoolParam(False), BoolParam(False),
in_c_key=False) in_c_key=False)
AddConfigVar('on_unused_input',
"What to do if a variable in the 'inputs' list of "
" theano.function() is not used in the graph.",
EnumStr('raise' 'warn', 'ignore'),
in_c_key=False)
# This flag is used when we import Theano to initialize global variables. # This flag is used when we import Theano to initialize global variables.
# So changing it after import will not modify these global variables. # So changing it after import will not modify these global variables.
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论