chainer.functions.forget¶

chainer.functions.
forget
(func, *xs)[source]¶ Call a function without storing internal results.
On a forward propagation Chainer stores all internal results of
Function
on a computational graph as they are required on backwardpropagation. These results consume too much memory when the internal results are too large. This method forgets such internal results on forward propagation, and still supports backpropagation with recalculation.In a forward propagation, this method calls a given function with given variables without creating a computational graph. That means, no internal results are stored. In a backward propagation this method calls the given function again to create a computational graph to execute backpropagation.
This method reduces internal memory usage. Instead it requires more calculation time as it calls the function twice.
Example
Let
f
be a function defined as:>>> def f(a, b): ... return a + b + a
and,
x
andy
beVariable
:>>> x = chainer.Variable(np.random.uniform(1, 1, 5).astype('f')) >>> y = chainer.Variable(np.random.uniform(1, 1, 5).astype('f'))
When
z
is calculated asz = f(x, y)
, its internal resultx + y
is stored in memory. Instead if you callf
withforget()
:>>> z = F.forget(f, x, y)
internal
x + y
is forgotten.Note
The method does not support functions behaving randomly, such as
dropout()
andnegative_sampling()
. It is because first results of these function differ from the second one.Parameters: Returns: A variable
func
returns. If it returns a tuple, the method returns a tuple too.Return type: