Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
8049c3ed
提交
8049c3ed
authored
12月 21, 2020
作者:
Brandon T. Willard
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Rename VM_Linker to VMLinker
上级
233feaf5
隐藏空白字符变更
内嵌
并排
正在显示
8 个修改的文件
包含
44 行增加
和
44 行删除
+44
-44
test_modes.py
tests/compile/test_modes.py
+1
-1
test_lazy.py
tests/link/test_lazy.py
+3
-3
test_vm.py
tests/link/test_vm.py
+25
-25
record.py
tests/record.py
+2
-2
test_conv.py
tests/tensor/nnet/test_conv.py
+1
-1
mode.py
theano/compile/mode.py
+6
-6
nanguardmode.py
theano/compile/nanguardmode.py
+1
-1
vm.py
theano/link/c/vm.py
+5
-5
没有找到文件。
tests/compile/test_modes.py
浏览文件 @
8049c3ed
...
...
@@ -35,7 +35,7 @@ class TestBunchOfModes:
# regression check:
# there should be
# -
VM_Linker
# -
`VMLinker`
# - OpWiseCLinker (FAST_RUN)
# - PerformLinker (FAST_COMPILE)
# - DebugMode's Linker (DEBUG_MODE)
...
...
tests/link/test_lazy.py
浏览文件 @
8049c3ed
...
...
@@ -124,7 +124,7 @@ def test_ifelse():
for
cloop
in
cloops
:
for
lazy
in
lazys
:
linker
=
theano
.
link
.
c
.
vm
.
VM
_
Linker
(
use_cloop
=
cloop
,
lazy
=
lazy
)
linker
=
theano
.
link
.
c
.
vm
.
VMLinker
(
use_cloop
=
cloop
,
lazy
=
lazy
)
f
=
function
(
[
a
,
b
,
c
],
ifelse
(
a
,
notimpl
(
b
),
c
),
...
...
@@ -154,11 +154,11 @@ def test_nested():
t4
=
ifelseifelseif
(
tt
.
eq
(
x1
,
x2
),
x1
,
tt
.
eq
(
x1
,
5
),
x2
,
c2
,
t3
,
t3
+
0.5
)
t4
.
name
=
"t4"
linker
=
theano
.
link
.
c
.
vm
.
VM
_
Linker
(
lazy
=
False
)
linker
=
theano
.
link
.
c
.
vm
.
VMLinker
(
lazy
=
False
)
f
=
function
([
c1
,
c2
,
x1
,
x2
],
t4
,
mode
=
Mode
(
linker
=
linker
,
optimizer
=
"fast_run"
))
with
pytest
.
raises
(
NotImplementedOpException
):
f
(
1
,
0
,
np
.
array
(
10
,
dtype
=
x1
.
dtype
),
0
)
linker
=
theano
.
link
.
c
.
vm
.
VM
_
Linker
(
lazy
=
True
)
linker
=
theano
.
link
.
c
.
vm
.
VMLinker
(
lazy
=
True
)
f
=
function
([
c1
,
c2
,
x1
,
x2
],
t4
,
mode
=
Mode
(
linker
=
linker
,
optimizer
=
"fast_run"
))
assert
f
(
1
,
0
,
np
.
array
(
10
,
dtype
=
x1
.
dtype
),
0
)
==
20.5
tests/link/test_vm.py
浏览文件 @
8049c3ed
...
...
@@ -10,11 +10,11 @@ from theano import function, tensor
from
theano.compile
import
Mode
from
theano.ifelse
import
ifelse
from
theano.link.c.cc
import
OpWiseCLinker
from
theano.link.c.vm
import
VM
_
Linker
from
theano.link.c.vm
import
VMLinker
class
TestCallbacks
:
# Test the
VM_Linker
's callback argument, which can be useful for debugging.
# Test the
`VMLinker`
's callback argument, which can be useful for debugging.
def
setup_method
(
self
):
self
.
n_callbacks
=
{}
...
...
@@ -29,7 +29,7 @@ class TestCallbacks:
f
=
function
(
[
a
,
b
,
c
],
(
a
+
b
)
+
c
,
mode
=
Mode
(
optimizer
=
None
,
linker
=
VM
_
Linker
(
callback
=
self
.
callback
)),
mode
=
Mode
(
optimizer
=
None
,
linker
=
VMLinker
(
callback
=
self
.
callback
)),
)
f
(
1
,
2
,
3
)
...
...
@@ -42,7 +42,7 @@ class TestCallbacks:
f
=
function
(
[
a
,
b
,
c
],
ifelse
(
a
,
2
*
b
,
2
*
c
),
mode
=
Mode
(
optimizer
=
None
,
linker
=
VM
_
Linker
(
callback
=
self
.
callback
)),
mode
=
Mode
(
optimizer
=
None
,
linker
=
VMLinker
(
callback
=
self
.
callback
)),
)
f
(
1
,
2
,
3
)
...
...
@@ -60,7 +60,7 @@ def test_c_thunks():
[
a
,
b
,
c
],
ifelse
(
a
,
a
*
b
,
b
*
c
),
mode
=
Mode
(
optimizer
=
None
,
linker
=
VM
_
Linker
(
c_thunks
=
c_thunks
,
use_cloop
=
False
)
optimizer
=
None
,
linker
=
VMLinker
(
c_thunks
=
c_thunks
,
use_cloop
=
False
)
),
)
f
(
1
,
[
2
],
[
3
,
2
])
...
...
@@ -129,10 +129,10 @@ def test_speed():
print
(
f
"{name} takes {1000 * (t_b - t_a) / (steps_b - steps_a):f} s/Kop"
)
time_linker
(
"c|py"
,
OpWiseCLinker
)
time_linker
(
"vmLinker"
,
VM
_
Linker
)
time_linker
(
"vmLinker_nogc"
,
lambda
:
VM
_
Linker
(
allow_gc
=
False
))
time_linker
(
"vmLinker"
,
VMLinker
)
time_linker
(
"vmLinker_nogc"
,
lambda
:
VMLinker
(
allow_gc
=
False
))
if
theano
.
config
.
cxx
:
time_linker
(
"vmLinker_CLOOP"
,
lambda
:
VM
_
Linker
(
allow_gc
=
False
,
use_cloop
=
True
))
time_linker
(
"vmLinker_CLOOP"
,
lambda
:
VMLinker
(
allow_gc
=
False
,
use_cloop
=
True
))
time_numpy
()
...
...
@@ -169,10 +169,10 @@ def test_speed_lazy():
print
(
f
"{name} takes {1000 * (t_b - t_a) / (steps_b - steps_a):f} s/Kop"
)
time_linker
(
"vmLinker"
,
VM
_
Linker
)
time_linker
(
"vmLinker_nogc"
,
lambda
:
VM
_
Linker
(
allow_gc
=
False
))
time_linker
(
"vmLinker"
,
VMLinker
)
time_linker
(
"vmLinker_nogc"
,
lambda
:
VMLinker
(
allow_gc
=
False
))
if
theano
.
config
.
cxx
:
time_linker
(
"vmLinker_C"
,
lambda
:
VM
_
Linker
(
allow_gc
=
False
,
use_cloop
=
True
))
time_linker
(
"vmLinker_C"
,
lambda
:
VMLinker
(
allow_gc
=
False
,
use_cloop
=
True
))
def
test_partial_function
():
...
...
@@ -189,7 +189,7 @@ def test_partial_function():
assert
f
(
4
,
output_subset
=
[
0
,
2
])
==
[
f
(
4
)[
0
],
f
(
4
)[
2
]]
utt
.
assert_allclose
(
f
(
5
),
np
.
array
([
32.0
,
16.0
,
1.7857142857142858
]))
check_partial_function
(
VM
_
Linker
(
allow_partial_eval
=
True
,
use_cloop
=
False
))
check_partial_function
(
VMLinker
(
allow_partial_eval
=
True
,
use_cloop
=
False
))
if
not
theano
.
config
.
cxx
:
pytest
.
skip
(
"Need cxx for this test"
)
check_partial_function
(
"cvm"
)
...
...
@@ -209,7 +209,7 @@ def test_partial_function_with_output_keys():
assert
f
(
5
,
output_subset
=
[
"a"
])[
"a"
]
==
f
(
5
)[
"a"
]
check_partial_function_output_keys
(
VM
_
Linker
(
allow_partial_eval
=
True
,
use_cloop
=
False
)
VMLinker
(
allow_partial_eval
=
True
,
use_cloop
=
False
)
)
check_partial_function_output_keys
(
"cvm"
)
...
...
@@ -240,7 +240,7 @@ def test_partial_function_with_updates():
assert
g
(
40
,
output_subset
=
[])
==
[]
assert
y
.
get_value
()
==
10
check_updates
(
VM
_
Linker
(
allow_partial_eval
=
True
,
use_cloop
=
False
))
check_updates
(
VMLinker
(
allow_partial_eval
=
True
,
use_cloop
=
False
))
check_updates
(
"cvm"
)
...
...
@@ -326,9 +326,9 @@ if run_memory_usage_tests:
# print(pre.ru_maxrss, post.ru_maxrss)
print
(
1
)
time_linker
(
"vmLinker_C"
,
lambda
:
VM
_
Linker
(
allow_gc
=
False
,
use_cloop
=
True
))
time_linker
(
"vmLinker_C"
,
lambda
:
VMLinker
(
allow_gc
=
False
,
use_cloop
=
True
))
print
(
2
)
time_linker
(
"vmLinker"
,
lambda
:
VM
_
Linker
(
allow_gc
=
False
,
use_cloop
=
False
))
time_linker
(
"vmLinker"
,
lambda
:
VMLinker
(
allow_gc
=
False
,
use_cloop
=
False
))
def
test_no_leak_many_call_nonlazy
():
# Verify no memory leaks when calling a function a lot of times
...
...
@@ -353,9 +353,9 @@ if run_memory_usage_tests:
f_a
(
inp
)
print
(
1
)
time_linker
(
"vmLinker_C"
,
lambda
:
VM
_
Linker
(
allow_gc
=
False
,
use_cloop
=
True
))
time_linker
(
"vmLinker_C"
,
lambda
:
VMLinker
(
allow_gc
=
False
,
use_cloop
=
True
))
print
(
2
)
time_linker
(
"vmLinker"
,
lambda
:
VM
_
Linker
(
allow_gc
=
False
,
use_cloop
=
False
))
time_linker
(
"vmLinker"
,
lambda
:
VMLinker
(
allow_gc
=
False
,
use_cloop
=
False
))
class
RunOnce
(
theano
.
Op
):
...
...
@@ -382,7 +382,7 @@ def test_vm_gc():
x
=
theano
.
tensor
.
vector
()
p
=
RunOnce
()(
x
)
mode
=
theano
.
Mode
(
linker
=
VM
_
Linker
(
lazy
=
True
))
mode
=
theano
.
Mode
(
linker
=
VMLinker
(
lazy
=
True
))
f
=
theano
.
function
([
theano
.
In
(
x
,
mutable
=
True
)],
[
p
+
1
,
p
+
2
],
mode
=
mode
)
f
([
1
,
2
,
3
])
...
...
@@ -398,8 +398,8 @@ def test_reallocation():
z
=
tensor
.
tanh
(
3
*
x
+
y
)
+
tensor
.
cosh
(
x
+
5
*
y
)
# The functinality is currently implement for non lazy and non c VM only.
for
linker
in
[
VM
_
Linker
(
allow_gc
=
False
,
lazy
=
False
,
use_cloop
=
False
),
VM
_
Linker
(
allow_gc
=
True
,
lazy
=
False
,
use_cloop
=
False
),
VMLinker
(
allow_gc
=
False
,
lazy
=
False
,
use_cloop
=
False
),
VMLinker
(
allow_gc
=
True
,
lazy
=
False
,
use_cloop
=
False
),
]:
m
=
theano
.
compile
.
get_mode
(
theano
.
Mode
(
linker
=
linker
))
m
=
m
.
excluding
(
"fusion"
,
"inplace"
)
...
...
@@ -431,10 +431,10 @@ def test_reallocation():
def
test_no_recycling
():
x
=
theano
.
tensor
.
vector
()
for
lnk
in
[
VM
_
Linker
(
use_cloop
=
True
),
VM
_
Linker
(
use_cloop
=
False
,
lazy
=
True
),
VM
_
Linker
(
use_cloop
=
False
,
lazy
=
False
,
allow_gc
=
True
),
VM
_
Linker
(
use_cloop
=
False
,
lazy
=
False
,
allow_gc
=
False
),
VMLinker
(
use_cloop
=
True
),
VMLinker
(
use_cloop
=
False
,
lazy
=
True
),
VMLinker
(
use_cloop
=
False
,
lazy
=
False
,
allow_gc
=
True
),
VMLinker
(
use_cloop
=
False
,
lazy
=
False
,
allow_gc
=
False
),
]:
mode
=
theano
.
Mode
(
optimizer
=
"fast_compile"
,
linker
=
lnk
)
...
...
tests/record.py
浏览文件 @
8049c3ed
from
theano.compile
import
Mode
from
theano.configdefaults
import
config
from
theano.link.basic
import
WrapLinkerMany
from
theano.link.c.vm
import
VM
_
Linker
from
theano.link.c.vm
import
VMLinker
from
theano.printing
import
hex_digest
,
min_informative_str
...
...
@@ -250,7 +250,7 @@ class RecordMode(Mode):
handle_line
(
fgraph
,
line
,
i
,
node
,
fn
)
# linker = theano.link.c.cc.OpWiseCLinker()
linker
=
VM
_
Linker
(
use_cloop
=
bool
(
config
.
cxx
))
linker
=
VMLinker
(
use_cloop
=
bool
(
config
.
cxx
))
wrap_linker
=
WrapLinkerMany
([
linker
],
[
callback
])
super
()
.
__init__
(
wrap_linker
,
optimizer
=
"fast_run"
)
tests/tensor/nnet/test_conv.py
浏览文件 @
8049c3ed
...
...
@@ -607,7 +607,7 @@ class TestConv2D(utt.InferShapeTester):
openmp
=
openmp
,
)
mode
=
theano
.
Mode
(
linker
=
theano
.
link
.
c
.
vm
.
VM
_
Linker
(
linker
=
theano
.
link
.
c
.
vm
.
VMLinker
(
allow_gc
=
False
,
use_cloop
=
True
)
)
...
...
theano/compile/mode.py
浏览文件 @
8049c3ed
...
...
@@ -11,7 +11,7 @@ from theano import config, gof
from
theano.compile.function.types
import
Supervisor
from
theano.link.basic
import
PerformLinker
from
theano.link.c.cc
import
CLinker
,
OpWiseCLinker
from
theano.link.c.vm
import
VM
_
Linker
from
theano.link.c.vm
import
VMLinker
from
theano.link.jax
import
JAXLinker
...
...
@@ -26,10 +26,10 @@ predefined_linkers = {
"c"
:
CLinker
(),
# Don't support gc. so don't check allow_gc
"c|py"
:
OpWiseCLinker
(),
# Use allow_gc Theano flag
"c|py_nogc"
:
OpWiseCLinker
(
allow_gc
=
False
),
"vm"
:
VM
_
Linker
(
use_cloop
=
False
),
# Use allow_gc Theano flag
"cvm"
:
VM
_
Linker
(
use_cloop
=
True
),
# Use allow_gc Theano flag
"vm_nogc"
:
VM
_
Linker
(
allow_gc
=
False
,
use_cloop
=
False
),
"cvm_nogc"
:
VM
_
Linker
(
allow_gc
=
False
,
use_cloop
=
True
),
"vm"
:
VMLinker
(
use_cloop
=
False
),
# Use allow_gc Theano flag
"cvm"
:
VMLinker
(
use_cloop
=
True
),
# Use allow_gc Theano flag
"vm_nogc"
:
VMLinker
(
allow_gc
=
False
,
use_cloop
=
False
),
"cvm_nogc"
:
VMLinker
(
allow_gc
=
False
,
use_cloop
=
True
),
"jax"
:
JAXLinker
(),
}
...
...
@@ -409,7 +409,7 @@ class Mode:
# string as the key
# Use VM_linker to allow lazy evaluation by default.
FAST_COMPILE
=
Mode
(
theano
.
link
.
c
.
vm
.
VM
_
Linker
(
use_cloop
=
False
,
c_thunks
=
False
),
"fast_compile"
theano
.
link
.
c
.
vm
.
VMLinker
(
use_cloop
=
False
,
c_thunks
=
False
),
"fast_compile"
)
if
theano
.
config
.
cxx
:
FAST_RUN
=
Mode
(
"cvm"
,
"fast_run"
)
...
...
theano/compile/nanguardmode.py
浏览文件 @
8049c3ed
...
...
@@ -292,7 +292,7 @@ class NanGuardMode(Mode):
if
getattr
(
var
.
tag
,
"nan_guard_mode_check"
,
True
):
do_check_on
(
value
,
None
,
var
=
var
)
wrap_linker
=
theano
.
link
.
c
.
vm
.
VM
_
Linker
(
wrap_linker
=
theano
.
link
.
c
.
vm
.
VMLinker
(
callback
=
nan_check
,
callback_input
=
nan_check_input
)
super
()
.
__init__
(
wrap_linker
,
optimizer
=
self
.
provided_optimizer
)
theano/link/c/vm.py
浏览文件 @
8049c3ed
...
...
@@ -719,7 +719,7 @@ except (OSError, MissingGXX) as e:
assert
not
config
.
_config_var_dict
[
"linker"
]
.
default
.
startswith
(
"cvm"
),
e
class
VM
_
Linker
(
LocalLinker
):
class
VMLinker
(
LocalLinker
):
"""
Class that satisfies the Linker interface by acting as a VM factory.
...
...
@@ -785,7 +785,7 @@ class VM_Linker(LocalLinker):
def
accept
(
self
,
fgraph
,
no_recycling
=
None
,
profile
=
None
):
"""Check if fgraph is the first FunctionGraph that has ever been
associated to self, else, create a new
VM_Linker
associated to self, else, create a new
`VMLinker`
associated to fgraph
Parameters
...
...
@@ -805,7 +805,7 @@ class VM_Linker(LocalLinker):
give to the user. We don't want to reuse those object in
case the user have kept it.
VM_Linker
make sure this happen by setting the list
`VMLinker`
make sure this happen by setting the list
element to None at the start of each call.
Older Linker use not exactly the same mechanism. They will
...
...
@@ -824,13 +824,13 @@ class VM_Linker(LocalLinker):
Returns
-------
Self if fgraph is the first FunctionGraph that has ever been
associated to self, else, a new
VM_Linker
associated to fgraph.
associated to self, else, a new
`VMLinker`
associated to fgraph.
"""
if
no_recycling
is
None
:
no_recycling
=
[]
if
self
.
fgraph
is
not
None
and
self
.
fgraph
is
not
fgraph
:
# Build a new
VM_Linker
, and call accept on that one.
# Build a new
`VMLinker`
, and call accept on that one.
# Warning: make sure to forward the correct values of
# all parameters to __init__ here.
return
type
(
self
)(
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论