Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
4fe2f548
提交
4fe2f548
authored
9月 19, 2016
作者:
Cesar Laurent
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Small doc fix.
上级
a361fc81
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
33 行增加
和
33 行删除
+33
-33
scan.txt
doc/library/scan.txt
+32
-32
scan_checkpoint.py
theano/scan_module/scan_checkpoint.py
+1
-1
没有找到文件。
doc/library/scan.txt
浏览文件 @
4fe2f548
...
@@ -529,6 +529,38 @@ As a rule, scan always expects the condition to be the last thing returned
...
@@ -529,6 +529,38 @@ As a rule, scan always expects the condition to be the last thing returned
by the inner function, otherwise an error will be raised.
by the inner function, otherwise an error will be raised.
Reduce Scan's memory usage
--------------------------
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.
Optimizing Scan's performance
Optimizing Scan's performance
-----------------------------
-----------------------------
...
@@ -602,38 +634,6 @@ a single larger one and thus improves performance at the cost of a potentially
...
@@ -602,38 +634,6 @@ 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
=========
=========
...
...
theano/scan_module/scan_checkpoint.py
浏览文件 @
4fe2f548
...
@@ -75,7 +75,7 @@ def scan_with_checkpoints(fn, sequences=[], outputs_info=None,
...
@@ -75,7 +75,7 @@ def scan_with_checkpoints(fn, sequences=[], outputs_info=None,
n_steps
=
o_n_steps
,
allow_gc
=
True
)
n_steps
=
o_n_steps
,
allow_gc
=
True
)
# Keep only the last timestep of every output but keep all the updates
# Keep only the last timestep of every output but keep all the updates
return
results
,
updates
return
results
,
updates
# TODO is it a bug?
if
not
isinstance
(
results
,
list
):
if
not
isinstance
(
results
,
list
):
return
results
[
-
1
:],
updates
return
results
[
-
1
:],
updates
else
:
else
:
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论