chainer.functions.forget¶
-
chainer.functions.forget(func, *xs)[source]¶ Calls a function without storing intermediate results.
On a forward propagation, Chainer normally stores all intermediate results of
VariableNodes on a computational graph as they are required on backward propagation. Sometimes these results consume too much memory.F.forgetforgets such intermediate results on forward propagation, and still supports backpropagation with recalculation.On a forward propagation,
F.forgetcalls a given function with given variables without creating a computational graph. That means, no intermediate results are stored. On a backward propagation,F.forgetcalls the given function again to create a computational graph for backpropagation.F.forgetreduces internal memory usage, whereas it requires more calculation time as it calls the function twice.Example
Let
fbe a function defined as:>>> def f(a, b): ... return a + b + a
and,
xandybeVariables:>>> x = chainer.Variable(np.random.uniform(-1, 1, 5).astype('f')) >>> y = chainer.Variable(np.random.uniform(-1, 1, 5).astype('f'))
When
zis calculated asz = f(x, y), its intermediate resultx + yis stored in memory. Instead, if you callfwithF.forget:>>> z = F.forget(f, x, y)
intermediate
x + yis forgotten.Note
F.forgetdoes not support functions which behave differently in multiple calls with the same inputs, such asF.dropout()andF.negative_sampling().Parameters: Returns: A variable
funcreturns. If it returns a tuple, the method returns a tuple too.Return type: