Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
f953c0f0
提交
f953c0f0
authored
5月 08, 2015
作者:
--global
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Document memory pre-allocation feature
上级
86082148
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
42 行增加
和
0 行删除
+42
-0
scan_op.py
theano/scan_module/scan_op.py
+42
-0
没有找到文件。
theano/scan_module/scan_op.py
浏览文件 @
f953c0f0
...
...
@@ -2,6 +2,48 @@
This module provides the Scan Op
See scan.py for details on scan
Memory reuse in scan
--------------------
To reduce the number of memory allocations and copies associated with calling
the inner function and recovering the outputs at every iteration, Scan uses a
memory pre-allocation mechanism for some of its outputs. Instead of repeatedly
calling the inner function and copying the outputs to designated locations,
it tries to make the inner function write the outputs directly to the
designated locations.
This is achieved by initializing, at every iteration, the output storage
of the inner function with references to previously allocated memory. Other
than the code in the Python and Cython backends to do this and to ensure that
the pre-allocated memory has been used, the memory pre-allocation mechanism
relies on the following elements to work properly :
- In make_thunk(), when compiling the inner function, the borrow flag must
be set to False for the inputs. This will prevent aliasing between the
inputs and the outputs of the inner function which could lead to invalid
results.
- In make_thunk(), again, the borrow flag must be set to True for the outputs.
This will make Theano consider the output storages as persistent and make
Theano provide them as pre-allocated storage to the ops that compute the
outputs of the inner function instead of letting these ops allocate their
own output storage.
- The ops that produce the outputs of the inner function must be prevented
from working inplace because if they do, they're not using the pre-allocated
storage. This is achieved by including the optimization
'add_no_output_from_inplace' to the compilation mode used by scan. It
prevents other optimizations from altering the graph such that outputs are
produced by inplace operations.
- The ScanSaveMem optimization, whose goal is to limit the amount of memory
used by scan, needs to allocate buffers large enough to be able, at every
iteration, to simultaneously read the needed previous states and storing
the new states. Before the memory reuse feature, the buffers could be
smaller because, often, Scan only needed buffers large enough to read the
needed previous states. This is because all the outputs of the inner
function were computed before any of them was stored in the buffers. Now,
the outputs are stored as they are computed which means that, if the buffer
is too small, computing an output can overwrite an input that is still
needed to compute another output.
"""
__docformat__
=
'restructedtext en'
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论