Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
f58e14cc
提交
f58e14cc
authored
6月 08, 2012
作者:
Frederic
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add a test that show when the gemm optimizer add a gemm, but didn't remove a dot22.
上级
d604b4be
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
45 行增加
和
3 行删除
+45
-3
test_blas.py
theano/tensor/tests/test_blas.py
+45
-3
没有找到文件。
theano/tensor/tests/test_blas.py
浏览文件 @
f58e14cc
...
...
@@ -45,6 +45,10 @@ def test_dot_eq():
assert
T
.
Dot
()
==
T
.
Dot
()
def
sharedX
(
x
,
name
):
return
theano
.
shared
(
numpy
.
asarray
(
x
,
config
.
floatX
),
name
=
name
)
class
t_gemm
(
TestCase
):
"""This test suite is supposed to establish that gemm works as it
is supposed to.
...
...
@@ -480,7 +484,7 @@ def just_gemm(i, o, ishapes=[(4, 3), (3, 5), (4, 5), (), ()],
raise
Failure
(
'_dot22 not changed to gemm_inplace in graph'
)
if
node
.
op
==
gemm_inplace
:
nb_gemm
+=
1
assert
nb_gemm
==
expected_nb_gemm
assert
nb_gemm
==
expected_nb_gemm
,
(
nb_gemm
,
expected_nb_gemm
)
g
=
inplace_func
(
i
,
o
,
mode
=
compile
.
Mode
(
linker
=
'py'
,
optimizer
=
None
),
allow_input_downcast
=
True
,
on_unused_input
=
'ignore'
)
for
node
in
g
.
maker
.
env
.
nodes
:
...
...
@@ -712,8 +716,8 @@ def test_gemm_opt_wishlist():
X
,
Y
,
Z
,
a
,
b
=
T
.
matrix
(),
T
.
matrix
(),
T
.
matrix
(),
T
.
scalar
(),
T
.
scalar
()
#with >2 additions of the same T.dot(X,Y term
just_gemm
([
X
,
Y
,
Z
,
a
,
b
],
[(
b
*
b
)
*
Z
*
a
+
(
a
*
a
)
*
T
.
dot
(
X
,
Y
)
+
b
*
T
.
dot
(
X
,
Y
)])
just_gemm
([
X
,
Y
,
Z
,
a
,
b
],
[(
b
*
b
)
*
Z
*
a
+
(
a
*
a
)
*
T
.
dot
(
X
,
Y
)
+
b
*
T
.
dot
(
X
,
Y
)])
just_gemm
([
X
,
Y
,
Z
,
a
,
b
],
[
Z
+
T
.
dot
(
X
,
Y
)
+
T
.
dot
(
X
,
Y
)])
...
...
@@ -763,6 +767,44 @@ def test_gemm_opt_vector_stuff():
raise
Failure
(
'gemm_inplace in graph'
)
def
test_gemm_unrolled
():
batch_size
=
100
rep_size
=
40
rng
=
numpy
.
random
.
RandomState
([
1
,
2
,
3
])
for
num_rounds
in
range
(
1
,
10
):
W
=
sharedX
(
rng
.
randn
(
rep_size
,
rep_size
),
name
=
'W'
)
V
=
sharedX
(
numpy
.
zeros
((
batch_size
,
rep_size
)),
name
=
'V'
)
H
=
sharedX
(
numpy
.
zeros
((
batch_size
,
rep_size
)),
name
=
'H'
)
G
=
sharedX
(
numpy
.
zeros
((
batch_size
,
rep_size
)),
name
=
'G'
)
init_V
=
sharedX
(
rng
.
uniform
(
0
,
1
,
(
batch_size
,
rep_size
)),
name
=
'init_V'
)
init_H
=
sharedX
(
rng
.
uniform
(
0
,
1
,
(
batch_size
,
rep_size
)),
name
=
'init_H'
)
cur_V
=
V
cur_H
=
H
def
update_V
(
cur_H
):
return
T
.
nnet
.
sigmoid
(
T
.
dot
(
cur_H
,
W
.
T
))
def
update_H
(
cur_V
):
return
T
.
nnet
.
sigmoid
(
T
.
dot
(
cur_V
,
W
)
+
T
.
dot
(
G
,
W
.
T
))
for
i
in
xrange
(
num_rounds
):
cur_V
=
update_V
(
cur_H
)
cur_H
=
update_H
(
cur_V
)
unrolled_theano
=
theano
.
function
([],
updates
=
{
V
:
cur_V
,
H
:
cur_H
},
name
=
'unrolled_theano'
)
nb_dot
=
sum
([
1
for
node
in
unrolled_theano
.
maker
.
env
.
toposort
()
if
isinstance
(
node
.
op
,
(
theano
.
tensor
.
Dot
,
theano
.
tensor
.
blas
.
Dot22
,
theano
.
tensor
.
blas
.
Gemm
))])
assert
nb_dot
==
num_rounds
*
2
+
1
,
nb_dot
unrolled_theano
()
def
test_inplace0
():
#should fail to insert gemm_inplace because gemm_inplace would
#create cycles
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论