Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
34154000
提交
34154000
authored
10月 03, 2016
作者:
Cesar Laurent
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Added docstring of scan_checkpoint.
上级
9b02fa85
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
55 行增加
和
7 行删除
+55
-7
scan_checkpoint.py
theano/scan_module/scan_checkpoint.py
+55
-7
没有找到文件。
theano/scan_module/scan_checkpoint.py
浏览文件 @
34154000
...
@@ -4,16 +4,67 @@ import theano
...
@@ -4,16 +4,67 @@ import theano
def
scan_with_checkpoints
(
fn
,
sequences
=
[],
outputs_info
=
None
,
def
scan_with_checkpoints
(
fn
,
sequences
=
[],
outputs_info
=
None
,
non_sequences
=
[],
name
=
"checkpointscan_fn"
,
non_sequences
=
[],
name
=
"checkpointscan_fn"
,
n_steps
=
None
,
save_every_N
=
10
):
n_steps
=
None
,
save_every_N
=
10
):
"""
"""Scan function that uses less memory, but is more restrictive.
In ``scan``, if you compute the gradient of the output with respect
to the input, you will have to store the intermediate results at
each time step, which can be prohibitively huge. This function allows
to do several steps of forward computations without storing the
intermediate results, and to recompute them during the gradient
computation.
Current assumptions :
Current assumptions :
- Every sequence has the same length
- Every sequence has the same length.
- If n_steps is specified, it has the same value as the length of any sequence
- If n_steps is specified, it has the same value as the length of any
sequence.
- The value of "save_every_N" divides the number of steps the Scan will
- The value of "save_every_N" divides the number of steps the Scan will
run without remainder
run without remainder
.
- Only singly-recurrent and non-recurrent outputs are used.
- Only singly-recurrent and non-recurrent outputs are used.
No multiple recurrences.
No multiple recurrences.
- Only the last timestep of any output will ever be used.
- Only the last timestep of any output will ever be used.
Parameters
----------
fn
``fn`` is a function that describes the operations involved in one
step of ``scan``. See the documentation of ``scan`` for more
information.
sequences
``sequences`` is the list of Theano variables or dictionaries
describing the sequences ``scan`` has to iterate over. All
sequences must be the same length in this version of ``scan``.
outputs_info
``outputs_info`` is the list of Theano variables or dictionaries
describing the initial state of the outputs computed
recurrently.
non_sequences
``non_sequences`` is the list of arguments that are passed to
``fn`` at each steps. One can opt to exclude variable
used in ``fn`` from this list as long as they are part of the
computational graph, though for clarity we encourage not to do so.
n_steps
``n_steps`` is the number of steps to iterate given as an int
or Theano scalar. If any of the input sequences do not have
enough elements, scan will raise an error. If the *value is 0* the
outputs will have *0 rows*. If the value is negative, ``scan``
will run backwards in time. If the ``go_backwards`` flag is already
set and also ``n_steps`` is negative, ``scan`` will run forward
in time. If n_steps is not provided, ``scan`` will figure
out the amount of steps it should run given its input sequences.
save_every_N
``save_every_N`` is the number of steps to go without storing
the computations of scan (ie they will have to be recomputed
during the gradient computation).
See Also
--------
scan : Looping in Theano.
"""
"""
# Standardize the format of input arguments
# Standardize the format of input arguments
if
not
isinstance
(
sequences
,
list
):
if
not
isinstance
(
sequences
,
list
):
...
@@ -26,8 +77,6 @@ def scan_with_checkpoints(fn, sequences=[], outputs_info=None,
...
@@ -26,8 +77,6 @@ def scan_with_checkpoints(fn, sequences=[], outputs_info=None,
# Determine how many steps the original scan would run
# Determine how many steps the original scan would run
if
n_steps
is
None
:
if
n_steps
is
None
:
n_steps
=
sequences
[
0
]
.
shape
[
0
]
n_steps
=
sequences
[
0
]
.
shape
[
0
]
else
:
n_steps
=
n_steps
# Compute the number of steps of the inner and of the outer scan
# Compute the number of steps of the inner and of the outer scan
o_n_steps
=
theano
.
tensor
.
cast
(
n_steps
/
save_every_N
,
'int64'
)
o_n_steps
=
theano
.
tensor
.
cast
(
n_steps
/
save_every_N
,
'int64'
)
...
@@ -71,5 +120,4 @@ def scan_with_checkpoints(fn, sequences=[], outputs_info=None,
...
@@ -71,5 +120,4 @@ def scan_with_checkpoints(fn, sequences=[], outputs_info=None,
name
=
name
+
"_outer"
,
name
=
name
+
"_outer"
,
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
return
results
,
updates
return
results
,
updates
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论