Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
7ed6a03b
提交
7ed6a03b
authored
7月 08, 2021
作者:
Brandon T. Willard
提交者:
Brandon T. Willard
7月 11, 2021
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use timeit in test_speed_batchrnn
上级
9e83b193
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
13 行增加
和
21 行删除
+13
-21
test_basic.py
tests/scan/test_basic.py
+13
-21
没有找到文件。
tests/scan/test_basic.py
浏览文件 @
7ed6a03b
...
@@ -13,7 +13,7 @@ import os
...
@@ -13,7 +13,7 @@ import os
import
pickle
import
pickle
import
shutil
import
shutil
import
sys
import
sys
import
time
import
time
it
from
collections
import
OrderedDict
from
collections
import
OrderedDict
from
tempfile
import
mkdtemp
from
tempfile
import
mkdtemp
...
@@ -4568,8 +4568,6 @@ def test_cvm_exception_handling():
...
@@ -4568,8 +4568,6 @@ def test_cvm_exception_handling():
not
config
.
cxx
,
reason
=
"G++ not available, so we need to skip this test."
not
config
.
cxx
,
reason
=
"G++ not available, so we need to skip this test."
)
)
def
test_speed
():
def
test_speed
():
from
timeit
import
timeit
n_timeit
=
50
n_timeit
=
50
# We need the CVM for this speed test
# We need the CVM for this speed test
...
@@ -4579,7 +4577,7 @@ def test_speed():
...
@@ -4579,7 +4577,7 @@ def test_speed():
for
i
in
range
(
1
,
1000
):
for
i
in
range
(
1
,
1000
):
r
[
i
]
+=
r
[
i
-
1
]
r
[
i
]
+=
r
[
i
-
1
]
python_duration
=
timeit
(
lambda
:
f_py
(),
number
=
n_timeit
)
python_duration
=
timeit
.
timeit
(
lambda
:
f_py
(),
number
=
n_timeit
)
r
=
np
.
arange
(
10000
)
.
astype
(
config
.
floatX
)
.
reshape
(
1000
,
10
)
r
=
np
.
arange
(
10000
)
.
astype
(
config
.
floatX
)
.
reshape
(
1000
,
10
)
...
@@ -4593,7 +4591,7 @@ def test_speed():
...
@@ -4593,7 +4591,7 @@ def test_speed():
except
StopIteration
:
except
StopIteration
:
break
break
python_iter_duration
=
timeit
(
lambda
:
f_py_iter
(),
number
=
n_timeit
)
python_iter_duration
=
timeit
.
timeit
(
lambda
:
f_py_iter
(),
number
=
n_timeit
)
# r = np.arange(10000).astype(config.floatX).reshape(1000, 10)
# r = np.arange(10000).astype(config.floatX).reshape(1000, 10)
# s_r = matrix()
# s_r = matrix()
...
@@ -4607,7 +4605,7 @@ def test_speed():
...
@@ -4607,7 +4605,7 @@ def test_speed():
#
#
# f_cvm = function([s_r], s_y)
# f_cvm = function([s_r], s_y)
#
#
# cvm_duration = timeit(lambda: f_cvm(r), number=n_timeit)
# cvm_duration = timeit
.timeit
(lambda: f_cvm(r), number=n_timeit)
# XXX: Why does this take so much longer than Python?!
# XXX: Why does this take so much longer than Python?!
# assert cvm_duration - python_duration < python_duration * 0.15
# assert cvm_duration - python_duration < python_duration * 0.15
...
@@ -4627,7 +4625,7 @@ def test_speed():
...
@@ -4627,7 +4625,7 @@ def test_speed():
)
)
f_cvm_shared
.
_check_for_aliased_inputs
=
False
f_cvm_shared
.
_check_for_aliased_inputs
=
False
cvm_shared_duration
=
timeit
(
lambda
:
f_cvm_shared
(),
number
=
n_timeit
)
cvm_shared_duration
=
timeit
.
timeit
(
lambda
:
f_cvm_shared
(),
number
=
n_timeit
)
assert
cvm_shared_duration
<
python_duration
assert
cvm_shared_duration
<
python_duration
assert
cvm_shared_duration
<
python_iter_duration
assert
cvm_shared_duration
<
python_iter_duration
...
@@ -4637,8 +4635,6 @@ def test_speed():
...
@@ -4637,8 +4635,6 @@ def test_speed():
not
config
.
cxx
,
reason
=
"G++ not available, so we need to skip this test."
not
config
.
cxx
,
reason
=
"G++ not available, so we need to skip this test."
)
)
def
test_speed_rnn
():
def
test_speed_rnn
():
from
timeit
import
timeit
n_timeit
=
50
n_timeit
=
50
L
=
10000
L
=
10000
N
=
50
N
=
50
...
@@ -4651,7 +4647,7 @@ def test_speed_rnn():
...
@@ -4651,7 +4647,7 @@ def test_speed_rnn():
for
i
in
range
(
1
,
L
):
for
i
in
range
(
1
,
L
):
r
[
i
]
=
np
.
tanh
(
np
.
dot
(
r
[
i
-
1
],
w
))
r
[
i
]
=
np
.
tanh
(
np
.
dot
(
r
[
i
-
1
],
w
))
python_duration
=
timeit
(
lambda
:
f_py
(),
number
=
n_timeit
)
python_duration
=
timeit
.
timeit
(
lambda
:
f_py
(),
number
=
n_timeit
)
# r = np.arange(L * N).astype(config.floatX).reshape(L, N)
# r = np.arange(L * N).astype(config.floatX).reshape(L, N)
# s_r = matrix()
# s_r = matrix()
...
@@ -4665,7 +4661,7 @@ def test_speed_rnn():
...
@@ -4665,7 +4661,7 @@ def test_speed_rnn():
#
#
# f_cvm = function([s_r], s_y, mode=Mode(linker="cvm"))
# f_cvm = function([s_r], s_y, mode=Mode(linker="cvm"))
#
#
# cvm_duration = timeit(lambda: f_cvm(r), number=n_timeit)
# cvm_duration = timeit
.timeit
(lambda: f_cvm(r), number=n_timeit)
# XXX: Why does this take so much longer than Python?!
# XXX: Why does this take so much longer than Python?!
# assert cvm_duration - python_duration < python_duration * 0.15
# assert cvm_duration - python_duration < python_duration * 0.15
...
@@ -4685,7 +4681,7 @@ def test_speed_rnn():
...
@@ -4685,7 +4681,7 @@ def test_speed_rnn():
mode
=
Mode
(
linker
=
"cvm"
),
mode
=
Mode
(
linker
=
"cvm"
),
)
)
cvm_shared_duration
=
timeit
(
lambda
:
f_cvm_shared
(),
number
=
n_timeit
)
cvm_shared_duration
=
timeit
.
timeit
(
lambda
:
f_cvm_shared
(),
number
=
n_timeit
)
assert
cvm_shared_duration
<
python_duration
assert
cvm_shared_duration
<
python_duration
...
@@ -4714,11 +4710,11 @@ def test_speed_batchrnn():
...
@@ -4714,11 +4710,11 @@ def test_speed_batchrnn():
r
=
np
.
arange
(
B
*
L
*
N
)
.
astype
(
config
.
floatX
)
.
reshape
(
L
,
B
,
N
)
r
=
np
.
arange
(
B
*
L
*
N
)
.
astype
(
config
.
floatX
)
.
reshape
(
L
,
B
,
N
)
w
=
np
.
random
.
default_rng
(
utt
.
fetch_seed
())
.
random
((
N
,
N
))
.
astype
(
config
.
floatX
)
w
=
np
.
random
.
default_rng
(
utt
.
fetch_seed
())
.
random
((
N
,
N
))
.
astype
(
config
.
floatX
)
t0
=
time
.
time
()
def
ref_fn
():
for
i
in
range
(
1
,
L
):
for
i
in
range
(
1
,
L
):
r
[
i
]
=
np
.
tanh
(
np
.
dot
(
r
[
i
-
1
],
w
))
r
[
i
]
=
np
.
tanh
(
np
.
dot
(
r
[
i
-
1
],
w
))
t1
=
time
.
time
()
python_duration
=
t
1
-
t0
python_duration
=
t
imeit
.
timeit
(
ref_fn
,
number
=
20
)
r
=
np
.
arange
(
B
*
L
*
N
)
.
astype
(
config
.
floatX
)
.
reshape
(
L
,
B
,
N
)
r
=
np
.
arange
(
B
*
L
*
N
)
.
astype
(
config
.
floatX
)
.
reshape
(
L
,
B
,
N
)
shared_r
=
shared
(
r
)
shared_r
=
shared
(
r
)
...
@@ -4734,12 +4730,8 @@ def test_speed_batchrnn():
...
@@ -4734,12 +4730,8 @@ def test_speed_batchrnn():
updates
=
[(
s_i
,
s_i
+
1
),
(
shared_r
,
s_rinc
)],
updates
=
[(
s_i
,
s_i
+
1
),
(
shared_r
,
s_rinc
)],
mode
=
Mode
(
linker
=
"cvm"
),
mode
=
Mode
(
linker
=
"cvm"
),
)
)
f_fn
=
f
.
fn
t2
=
time
.
time
()
cvm_duration
=
timeit
.
timeit
(
f
,
number
=
20
)
f_fn
(
n_calls
=
L
-
2
)
f
()
# 999 to update the profiling timers
t3
=
time
.
time
()
cvm_duration
=
t3
-
t2
assert
cvm_duration
<
python_duration
assert
cvm_duration
<
python_duration
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论