Theano's function() reports that my `givens` value is not needed for the graph
<p>Sorry for not posting entire snippets -- the code is very big and spread out, so hopefully this can illustrate my issue. I have these:</p>

<pre><code>train = theano.function([X], output, updates=update_G,
                        givens={train_mode=:np.cast['int32'](1)})
</code></pre>

<p>and </p>

<pre><code>test = theano.function([X], output, updates=update_G,
                       givens={train_mode=:np.cast['int32'](0)})
</code></pre>

<p>to my understanding, <code>givens</code> would input the value of <code>train_mode</code> (i.e. <code>1</code>/<code>0</code>) wherever it's needed to compute the output.</p>

<p>The <code>output</code> is computed in the lines of this:</p>

<pre><code>     ...
     network2 = Net2()
     # This is sort of a dummy variable so I don't get a NameError when this
     # is called before `theano.function()` is called. Not sure if this is the
     # right way to do this.
     train_mode = T.iscalar('train_mode')
     output = loss(network1.get_outputs(network2.get_outputs(X, train_mode=train_mode)),something).mean()

 ....
 class Net2(): 
      def get_outputs(self, x, train_mode):
           from theano.ifelse import ifelse
           import theano.tensor as T
           my_flag = ifelse(T.eq(train_mode, 1), 1, 0)
           return something if my_flag else something_else
</code></pre>

<p>So <code>train_mode</code> is used as an argument in one of the nested functions, and I use it to tell between <code>train</code> and <code>test</code> as I'd like to handle them slightly differently.</p>

<p>However, when I try to run this, I get this error:</p>

<pre><code>theano.compile.function_module.UnusedInputError: theano.function was
asked to create a function computing outputs given certain inputs, but
the provided input variable at index 1 is not part of the computational
graph needed to compute the outputs: &lt;TensorType(int32, scalar)&gt;.To make 
this error into a warning, you can pass the parameter 
on_unused_input='warn' to theano.function. To disable it completely, use 
on_unused_input='ignore'.    
</code></pre>

<p>If I delete the <code>givens</code> parameter, the error disappears, so to my understanding Theano believes that my <code>train_mode</code> is not necessary for compute the <code>function()</code>. I can use <code>on_unusued_input='ignore'</code> as per their suggestion, but that would just ignore my <code>train_mode</code> if they think it's unused. Am I going around this the wrong way? I basically just want to train a neural network with dropout, but not use dropout when evaluating.</p>

<p>why you use "=" sign? I think, it made train_mode not readable, my code works well by writing:
<code>givens = {train_mode:1}</code></p>

python neural-network deep-learning theano conv-neural-network