Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
a3a49a80
提交
a3a49a80
authored
5月 07, 2015
作者:
--global
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add test cases for the memory reuse feature
上级
db6e7b56
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
82 行增加
和
0 行删除
+82
-0
test_scan.py
theano/scan_module/tests/test_scan.py
+82
-0
没有找到文件。
theano/scan_module/tests/test_scan.py
浏览文件 @
a3a49a80
...
@@ -3895,6 +3895,88 @@ class T_Scan(unittest.TestCase):
...
@@ -3895,6 +3895,88 @@ class T_Scan(unittest.TestCase):
f
=
theano
.
function
([
seq
],
results
[
1
],
updates
=
updates
)
f
=
theano
.
function
([
seq
],
results
[
1
],
updates
=
updates
)
assert
numpy
.
all
(
exp_out
==
f
(
inp
))
assert
numpy
.
all
(
exp_out
==
f
(
inp
))
def
test_memory_reuse_gpudimshuffle
(
self
):
# Test the memory pre-allocation feature in scan when one output is
# the result of a GpuDimshuffle (because an optimization in
# GpuDimshuffle can cause issues with the memory pre-allocation
# where it falsely thinks that a pre-allocated memory region has
# been used when it hasn't).
from
theano.sandbox
import
cuda
if
not
cuda
.
cuda_available
:
raise
SkipTest
(
'Optional package cuda disabled'
)
def
inner_fn
(
seq1
,
recurrent_out
):
temp
=
seq1
+
recurrent_out
.
sum
()
output1
=
temp
.
dimshuffle
(
1
,
0
)
output2
=
temp
.
sum
()
+
recurrent_out
return
output1
,
output2
input1
=
theano
.
tensor
.
tensor3
()
init
=
theano
.
tensor
.
tensor3
()
outputs_info
=
[
None
,
init
]
out
,
_
=
theano
.
scan
(
inner_fn
,
sequences
=
[
input1
],
outputs_info
=
outputs_info
,
mode
=
mode_with_gpu
)
out1
=
out
[
0
]
.
flatten
()
out2
=
out
[
1
]
.
flatten
()
fct
=
theano
.
function
([
input1
,
init
],
[
out1
,
out2
],
mode
=
mode_with_gpu
)
floatX
=
theano
.
config
.
floatX
output
=
fct
(
numpy
.
ones
((
2
,
1
,
1
),
dtype
=
floatX
),
numpy
.
ones
((
1
,
1
,
1
),
dtype
=
floatX
))
expected_output
=
(
numpy
.
array
([
2
,
4
],
dtype
=
floatX
),
numpy
.
array
([
3
,
7
],
dtype
=
floatX
))
utt
.
assert_allclose
(
output
,
expected_output
)
def
test_memory_reuse_with_outputs_as_inputs
(
self
):
# Test the memory pre-allocation feature in scan for the following
# cases :
# - An output of the inner graph is also an input of the inner graph
# - An output of the inner graph is not an input in the unoptimized
# graph but it could becomes the case in the optimized graph due to
# the optimizations.
# - An output of the inner graph is obtained through a view op on an
# input of the inner graph and the view op is removed by the
# optimization process
# - An output of the inner graph is obtained through a view op on an
# input of the inner graph and the view op is NOT removed by the
# optimization process
# - An output of the inner graph is not obtained through any of the
# previously mentionned cases (standard case)
def
inner_fn
(
tap_m3
,
tap_m2
,
tap_m1
):
return
(
tap_m2
,
(
tap_m1
*
1
),
theano
.
gradient
.
disconnected_grad
(
tap_m2
),
theano
.
tensor
.
opt
.
assert_
(
tap_m2
,
1
),
tap_m3
+
tap_m2
+
tap_m1
)
init
=
theano
.
tensor
.
matrix
()
outputs_info
=
[
None
,
None
,
None
,
None
,
dict
(
initial
=
init
,
taps
=
[
-
3
,
-
2
,
-
1
])]
out
,
_
=
theano
.
scan
(
inner_fn
,
outputs_info
=
outputs_info
,
n_steps
=
3
)
fct
=
theano
.
function
([
init
],
out
)
# Compare obtained outputs with expected outputs
floatX
=
theano
.
config
.
floatX
outputs
=
fct
(
numpy
.
arange
(
9
,
dtype
=
floatX
)
.
reshape
(
3
,
3
))
states
=
numpy
.
array
([[
0
,
1
,
2
],
[
3
,
4
,
5
],
[
6
,
7
,
8
],
[
9
,
12
,
15
],
[
18
,
23
,
28
],
[
33
,
42
,
51
]],
dtype
=
floatX
)
expected_outputs
=
[
states
[
1
:
4
],
states
[
2
:
5
],
states
[
1
:
4
],
states
[
1
:
4
],
states
[
3
:
6
]]
utt
.
assert_allclose
(
outputs
,
expected_outputs
)
def
test_grad_connectivity_matrix
(
self
):
def
test_grad_connectivity_matrix
(
self
):
def
inner_fn
(
x_tm1
,
y_tm1
,
z_tm1
):
def
inner_fn
(
x_tm1
,
y_tm1
,
z_tm1
):
x_tm1
.
name
=
'x'
x_tm1
.
name
=
'x'
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论