提交 a361fc81 authored 作者: Cesar Laurent's avatar Cesar Laurent

Added some doc for scan_with_checkpoints

上级 033adc6a
...@@ -602,6 +602,38 @@ a single larger one and thus improves performance at the cost of a potentially ...@@ -602,6 +602,38 @@ a single larger one and thus improves performance at the cost of a potentially
higher memory usage. higher memory usage.
Reduce memory usage using checkpoints
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
This section presents the ``scan_with_checkpoints`` function. In short, this
function reduces the memory usage of scan (at the cost of more computation
time) by not keeping in memory all the intermediate time steps of the loop,
and recomputing them when computing the gradients. This function is therefore
only useful if you need to compute the gradient of the ouptut of scan with
respect to its inputs, and shouldn't be used otherwise.
Before going more into the details, here are a few current limitations:
* It only works in the case where only the output of the last time step is
needed, like when computing ``A**k`` or in an `encoder-decoder` setup.
* It only accepts sequences of the same length.
* If ``n_steps`` is specified, it has the same value as the length of any
sequences.
* Only singly-recurrent and non-recurrent outputs are used. TODO WHAT DOES IT MEANS?
Often, in order to be able to compute the gradients through scan operations,
Theano needs to keep in memory some intermediate computations of scan. This
can sometimes use a prohibitively large amount of memory.
``scan_with_checkpoints`` allows to discard some of those intermediate steps and
recompute them again when computing the gradients. Its ``save_every_N`` argument
specifies the number time steps to do without storing the intermediate results.
For example, ``save_every_N = 4`` will reduce the memory usage by 4, while having
to recompute 3/4 time steps of the forward loop. Since the grad of scan is
about 6x slower than the forward, a ~20% slowdown is expected. Apart from the
``save_every_N`` argument and the current limitations, the usage of this function
is similar to the classic ``scan`` function.
reference reference
========= =========
...@@ -612,4 +644,4 @@ reference ...@@ -612,4 +644,4 @@ reference
.. autofunction:: theano.foldl .. autofunction:: theano.foldl
.. autofunction:: theano.foldr .. autofunction:: theano.foldr
.. autofunction:: theano.scan .. autofunction:: theano.scan
.. autofunction:: theano.scan_with_checkpoints
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论