Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
b8165faa
提交
b8165faa
authored
6月 14, 2012
作者:
nouiz
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #621 from pascanur/fix_scan_savemem_matthias
fix for the bug involving multiple subtensor on a scan. The consequence was warning printed to the user and scan use more memory.
上级
4999500e
e9f7fab3
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
36 行增加
和
4 行删除
+36
-4
scan.py
theano/sandbox/scan.py
+1
-1
scan_opt.py
theano/scan_module/scan_opt.py
+2
-3
test_scan.py
theano/scan_module/tests/test_scan.py
+33
-0
没有找到文件。
theano/sandbox/scan.py
浏览文件 @
b8165faa
...
@@ -609,7 +609,7 @@ def scan(fn,
...
@@ -609,7 +609,7 @@ def scan(fn,
info
[
'gpu'
]
=
False
info
[
'gpu'
]
=
False
info
[
'as_while'
]
=
as_while
info
[
'as_while'
]
=
as_while
info
[
'profile'
]
=
profile
info
[
'profile'
]
=
profile
info
[
'_scan_
merge
_visited'
]
=
True
info
[
'_scan_
savemem
_visited'
]
=
True
local_op
=
scan_op
.
Scan
(
inner_inputs
,
new_outs
,
info
)
local_op
=
scan_op
.
Scan
(
inner_inputs
,
new_outs
,
info
)
...
...
theano/scan_module/scan_opt.py
浏览文件 @
b8165faa
...
@@ -526,7 +526,6 @@ class ScanSaveMem(gof.Optimizer):
...
@@ -526,7 +526,6 @@ class ScanSaveMem(gof.Optimizer):
if
(
isinstance
(
this_slice
[
0
],
slice
)
and
if
(
isinstance
(
this_slice
[
0
],
slice
)
and
this_slice
[
0
]
.
stop
is
None
):
this_slice
[
0
]
.
stop
is
None
):
global_nsteps
=
None
global_nsteps
=
None
break
if
isinstance
(
cf_slice
[
0
],
slice
):
if
isinstance
(
cf_slice
[
0
],
slice
):
stop
=
tensor
.
basic
.
extract_constant
(
cf_slice
[
0
]
.
stop
)
stop
=
tensor
.
basic
.
extract_constant
(
cf_slice
[
0
]
.
stop
)
else
:
else
:
...
@@ -741,7 +740,7 @@ class ScanSaveMem(gof.Optimizer):
...
@@ -741,7 +740,7 @@ class ScanSaveMem(gof.Optimizer):
# 3.6 Compose the new scan
# 3.6 Compose the new scan
# I need to make sure I'm not reapplying the same optimization
# I need to make sure I'm not reapplying the same optimization
# twice since bad things usually happen if I do that
# twice since bad things usually happen if I do that
info
[
'_scan_
merge
_visited'
]
=
True
info
[
'_scan_
savemem
_visited'
]
=
True
new_outs
=
scan_op
.
Scan
(
inps
,
new_outs
=
scan_op
.
Scan
(
inps
,
outs
,
outs
,
info
)
.
make_node
(
*
node_ins
)
.
outputs
info
)
.
make_node
(
*
node_ins
)
.
outputs
...
@@ -834,7 +833,7 @@ class ScanSaveMem(gof.Optimizer):
...
@@ -834,7 +833,7 @@ class ScanSaveMem(gof.Optimizer):
nodelist
=
[
x
for
x
in
env
.
toposort
()
if
isinstance
(
x
.
op
,
nodelist
=
[
x
for
x
in
env
.
toposort
()
if
isinstance
(
x
.
op
,
scan_op
.
Scan
)]
scan_op
.
Scan
)]
for
node
in
nodelist
:
for
node
in
nodelist
:
if
not
hasattr
(
node
.
op
,
'_scan_
merge
_visited'
):
if
not
hasattr
(
node
.
op
,
'_scan_
savemem
_visited'
):
self
.
process_node
(
env
,
node
)
self
.
process_node
(
env
,
node
)
# Just before specialize to have the other optimization
# Just before specialize to have the other optimization
...
...
theano/scan_module/tests/test_scan.py
浏览文件 @
b8165faa
...
@@ -285,6 +285,39 @@ class T_Scan(unittest.TestCase):
...
@@ -285,6 +285,39 @@ class T_Scan(unittest.TestCase):
theano_values
=
my_f
(
state
,
steps
)
theano_values
=
my_f
(
state
,
steps
)
assert
numpy
.
allclose
(
numpy_values
,
theano_values
)
assert
numpy
.
allclose
(
numpy_values
,
theano_values
)
def
test_subtensor_multiple_slices
(
self
):
# This addresses a bug reported by Matthias Zoehrer
# the bug happens when you have multiple subtensors on the output of
# scan (the bug requires the reshape to be produced, and it has
# which has something to do with how the subtensors overlap
def
f_pow2
(
x_tm1
):
return
2
*
x_tm1
state
=
theano
.
tensor
.
vector
(
'state'
)
n_steps
=
theano
.
tensor
.
iscalar
(
'nsteps'
)
output
,
updates
=
theano
.
scan
(
f_pow2
,
[],
state
,
[],
n_steps
=
n_steps
,
truncate_gradient
=-
1
,
go_backwards
=
False
)
nw_shape
=
tensor
.
ivector
(
'nw_shape'
)
# Note that the output is reshaped to 3 dimensional tensor, and
my_f
=
theano
.
function
([
state
,
n_steps
,
nw_shape
],
[
tensor
.
reshape
(
output
,
nw_shape
,
ndim
=
3
)[:
-
2
],
output
[:
-
4
]],
updates
=
updates
,
allow_input_downcast
=
True
)
nodes
=
[
x
for
x
in
my_f
.
maker
.
env
.
toposort
()
if
isinstance
(
x
.
op
,
theano
.
scan_module
.
scan_op
.
Scan
)]
# This assertation fails if savemem optimization failed on scan
assert
nodes
[
0
]
.
op
.
_scan_savemem_visited
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
my_f
(
rng
.
uniform
(
size
=
(
3
,)),
4
,
numpy
.
int64
([
2
,
2
,
3
]))
# simple rnn, one input, one state, weights for each; input/state
# simple rnn, one input, one state, weights for each; input/state
# are vectors, weights are scalars
# are vectors, weights are scalars
def
test_one_sequence_one_output_weights
(
self
):
def
test_one_sequence_one_output_weights
(
self
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论