提交 8049c3ed authored 作者: Brandon T. Willard's avatar Brandon T. Willard

Rename VM_Linker to VMLinker

上级 233feaf5
...@@ -35,7 +35,7 @@ class TestBunchOfModes: ...@@ -35,7 +35,7 @@ class TestBunchOfModes:
# regression check: # regression check:
# there should be # there should be
# - VM_Linker # - `VMLinker`
# - OpWiseCLinker (FAST_RUN) # - OpWiseCLinker (FAST_RUN)
# - PerformLinker (FAST_COMPILE) # - PerformLinker (FAST_COMPILE)
# - DebugMode's Linker (DEBUG_MODE) # - DebugMode's Linker (DEBUG_MODE)
......
...@@ -124,7 +124,7 @@ def test_ifelse(): ...@@ -124,7 +124,7 @@ def test_ifelse():
for cloop in cloops: for cloop in cloops:
for lazy in lazys: 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( f = function(
[a, b, c], [a, b, c],
ifelse(a, notimpl(b), c), ifelse(a, notimpl(b), c),
...@@ -154,11 +154,11 @@ def test_nested(): ...@@ -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 = ifelseifelseif(tt.eq(x1, x2), x1, tt.eq(x1, 5), x2, c2, t3, t3 + 0.5)
t4.name = "t4" 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")) f = function([c1, c2, x1, x2], t4, mode=Mode(linker=linker, optimizer="fast_run"))
with pytest.raises(NotImplementedOpException): with pytest.raises(NotImplementedOpException):
f(1, 0, np.array(10, dtype=x1.dtype), 0) 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")) 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 assert f(1, 0, np.array(10, dtype=x1.dtype), 0) == 20.5
...@@ -10,11 +10,11 @@ from theano import function, tensor ...@@ -10,11 +10,11 @@ from theano import function, tensor
from theano.compile import Mode from theano.compile import Mode
from theano.ifelse import ifelse from theano.ifelse import ifelse
from theano.link.c.cc import OpWiseCLinker from theano.link.c.cc import OpWiseCLinker
from theano.link.c.vm import VM_Linker from theano.link.c.vm import VMLinker
class TestCallbacks: 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): def setup_method(self):
self.n_callbacks = {} self.n_callbacks = {}
...@@ -29,7 +29,7 @@ class TestCallbacks: ...@@ -29,7 +29,7 @@ class TestCallbacks:
f = function( f = function(
[a, b, c], [a, b, c],
(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) f(1, 2, 3)
...@@ -42,7 +42,7 @@ class TestCallbacks: ...@@ -42,7 +42,7 @@ class TestCallbacks:
f = function( f = function(
[a, b, c], [a, b, c],
ifelse(a, 2 * b, 2 * 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) f(1, 2, 3)
...@@ -60,7 +60,7 @@ def test_c_thunks(): ...@@ -60,7 +60,7 @@ def test_c_thunks():
[a, b, c], [a, b, c],
ifelse(a, a * b, b * c), ifelse(a, a * b, b * c),
mode=Mode( 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]) f(1, [2], [3, 2])
...@@ -129,10 +129,10 @@ def test_speed(): ...@@ -129,10 +129,10 @@ def test_speed():
print(f"{name} takes {1000 * (t_b - t_a) / (steps_b - steps_a):f} s/Kop") print(f"{name} takes {1000 * (t_b - t_a) / (steps_b - steps_a):f} s/Kop")
time_linker("c|py", OpWiseCLinker) time_linker("c|py", OpWiseCLinker)
time_linker("vmLinker", VM_Linker) time_linker("vmLinker", VMLinker)
time_linker("vmLinker_nogc", lambda: VM_Linker(allow_gc=False)) time_linker("vmLinker_nogc", lambda: VMLinker(allow_gc=False))
if theano.config.cxx: 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() time_numpy()
...@@ -169,10 +169,10 @@ def test_speed_lazy(): ...@@ -169,10 +169,10 @@ def test_speed_lazy():
print(f"{name} takes {1000 * (t_b - t_a) / (steps_b - steps_a):f} s/Kop") print(f"{name} takes {1000 * (t_b - t_a) / (steps_b - steps_a):f} s/Kop")
time_linker("vmLinker", VM_Linker) time_linker("vmLinker", VMLinker)
time_linker("vmLinker_nogc", lambda: VM_Linker(allow_gc=False)) time_linker("vmLinker_nogc", lambda: VMLinker(allow_gc=False))
if theano.config.cxx: 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(): def test_partial_function():
...@@ -189,7 +189,7 @@ 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]] 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])) 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: if not theano.config.cxx:
pytest.skip("Need cxx for this test") pytest.skip("Need cxx for this test")
check_partial_function("cvm") check_partial_function("cvm")
...@@ -209,7 +209,7 @@ def test_partial_function_with_output_keys(): ...@@ -209,7 +209,7 @@ def test_partial_function_with_output_keys():
assert f(5, output_subset=["a"])["a"] == f(5)["a"] assert f(5, output_subset=["a"])["a"] == f(5)["a"]
check_partial_function_output_keys( 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") check_partial_function_output_keys("cvm")
...@@ -240,7 +240,7 @@ def test_partial_function_with_updates(): ...@@ -240,7 +240,7 @@ def test_partial_function_with_updates():
assert g(40, output_subset=[]) == [] assert g(40, output_subset=[]) == []
assert y.get_value() == 10 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") check_updates("cvm")
...@@ -326,9 +326,9 @@ if run_memory_usage_tests: ...@@ -326,9 +326,9 @@ if run_memory_usage_tests:
# print(pre.ru_maxrss, post.ru_maxrss) # print(pre.ru_maxrss, post.ru_maxrss)
print(1) 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) 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(): def test_no_leak_many_call_nonlazy():
# Verify no memory leaks when calling a function a lot of times # Verify no memory leaks when calling a function a lot of times
...@@ -353,9 +353,9 @@ if run_memory_usage_tests: ...@@ -353,9 +353,9 @@ if run_memory_usage_tests:
f_a(inp) f_a(inp)
print(1) 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) 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): class RunOnce(theano.Op):
...@@ -382,7 +382,7 @@ def test_vm_gc(): ...@@ -382,7 +382,7 @@ def test_vm_gc():
x = theano.tensor.vector() x = theano.tensor.vector()
p = RunOnce()(x) 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 = theano.function([theano.In(x, mutable=True)], [p + 1, p + 2], mode=mode)
f([1, 2, 3]) f([1, 2, 3])
...@@ -398,8 +398,8 @@ def test_reallocation(): ...@@ -398,8 +398,8 @@ def test_reallocation():
z = tensor.tanh(3 * x + y) + tensor.cosh(x + 5 * y) z = tensor.tanh(3 * x + y) + tensor.cosh(x + 5 * y)
# The functinality is currently implement for non lazy and non c VM only. # The functinality is currently implement for non lazy and non c VM only.
for linker in [ for linker in [
VM_Linker(allow_gc=False, lazy=False, use_cloop=False), VMLinker(allow_gc=False, lazy=False, use_cloop=False),
VM_Linker(allow_gc=True, lazy=False, use_cloop=False), VMLinker(allow_gc=True, lazy=False, use_cloop=False),
]: ]:
m = theano.compile.get_mode(theano.Mode(linker=linker)) m = theano.compile.get_mode(theano.Mode(linker=linker))
m = m.excluding("fusion", "inplace") m = m.excluding("fusion", "inplace")
...@@ -431,10 +431,10 @@ def test_reallocation(): ...@@ -431,10 +431,10 @@ def test_reallocation():
def test_no_recycling(): def test_no_recycling():
x = theano.tensor.vector() x = theano.tensor.vector()
for lnk in [ for lnk in [
VM_Linker(use_cloop=True), VMLinker(use_cloop=True),
VM_Linker(use_cloop=False, lazy=True), VMLinker(use_cloop=False, lazy=True),
VM_Linker(use_cloop=False, lazy=False, allow_gc=True), VMLinker(use_cloop=False, lazy=False, allow_gc=True),
VM_Linker(use_cloop=False, lazy=False, allow_gc=False), VMLinker(use_cloop=False, lazy=False, allow_gc=False),
]: ]:
mode = theano.Mode(optimizer="fast_compile", linker=lnk) mode = theano.Mode(optimizer="fast_compile", linker=lnk)
......
from theano.compile import Mode from theano.compile import Mode
from theano.configdefaults import config from theano.configdefaults import config
from theano.link.basic import WrapLinkerMany 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 from theano.printing import hex_digest, min_informative_str
...@@ -250,7 +250,7 @@ class RecordMode(Mode): ...@@ -250,7 +250,7 @@ class RecordMode(Mode):
handle_line(fgraph, line, i, node, fn) handle_line(fgraph, line, i, node, fn)
# linker = theano.link.c.cc.OpWiseCLinker() # 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]) wrap_linker = WrapLinkerMany([linker], [callback])
super().__init__(wrap_linker, optimizer="fast_run") super().__init__(wrap_linker, optimizer="fast_run")
...@@ -607,7 +607,7 @@ class TestConv2D(utt.InferShapeTester): ...@@ -607,7 +607,7 @@ class TestConv2D(utt.InferShapeTester):
openmp=openmp, openmp=openmp,
) )
mode = theano.Mode( mode = theano.Mode(
linker=theano.link.c.vm.VM_Linker( linker=theano.link.c.vm.VMLinker(
allow_gc=False, use_cloop=True allow_gc=False, use_cloop=True
) )
) )
......
...@@ -11,7 +11,7 @@ from theano import config, gof ...@@ -11,7 +11,7 @@ from theano import config, gof
from theano.compile.function.types import Supervisor from theano.compile.function.types import Supervisor
from theano.link.basic import PerformLinker from theano.link.basic import PerformLinker
from theano.link.c.cc import CLinker, OpWiseCLinker 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 from theano.link.jax import JAXLinker
...@@ -26,10 +26,10 @@ predefined_linkers = { ...@@ -26,10 +26,10 @@ predefined_linkers = {
"c": CLinker(), # Don't support gc. so don't check allow_gc "c": CLinker(), # Don't support gc. so don't check allow_gc
"c|py": OpWiseCLinker(), # Use allow_gc Theano flag "c|py": OpWiseCLinker(), # Use allow_gc Theano flag
"c|py_nogc": OpWiseCLinker(allow_gc=False), "c|py_nogc": OpWiseCLinker(allow_gc=False),
"vm": VM_Linker(use_cloop=False), # Use allow_gc Theano flag "vm": VMLinker(use_cloop=False), # Use allow_gc Theano flag
"cvm": VM_Linker(use_cloop=True), # Use allow_gc Theano flag "cvm": VMLinker(use_cloop=True), # Use allow_gc Theano flag
"vm_nogc": VM_Linker(allow_gc=False, use_cloop=False), "vm_nogc": VMLinker(allow_gc=False, use_cloop=False),
"cvm_nogc": VM_Linker(allow_gc=False, use_cloop=True), "cvm_nogc": VMLinker(allow_gc=False, use_cloop=True),
"jax": JAXLinker(), "jax": JAXLinker(),
} }
...@@ -409,7 +409,7 @@ class Mode: ...@@ -409,7 +409,7 @@ class Mode:
# string as the key # string as the key
# Use VM_linker to allow lazy evaluation by default. # Use VM_linker to allow lazy evaluation by default.
FAST_COMPILE = Mode( 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: if theano.config.cxx:
FAST_RUN = Mode("cvm", "fast_run") FAST_RUN = Mode("cvm", "fast_run")
......
...@@ -292,7 +292,7 @@ class NanGuardMode(Mode): ...@@ -292,7 +292,7 @@ class NanGuardMode(Mode):
if getattr(var.tag, "nan_guard_mode_check", True): if getattr(var.tag, "nan_guard_mode_check", True):
do_check_on(value, None, var=var) 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 callback=nan_check, callback_input=nan_check_input
) )
super().__init__(wrap_linker, optimizer=self.provided_optimizer) super().__init__(wrap_linker, optimizer=self.provided_optimizer)
...@@ -719,7 +719,7 @@ except (OSError, MissingGXX) as e: ...@@ -719,7 +719,7 @@ except (OSError, MissingGXX) as e:
assert not config._config_var_dict["linker"].default.startswith("cvm"), 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. Class that satisfies the Linker interface by acting as a VM factory.
...@@ -785,7 +785,7 @@ class VM_Linker(LocalLinker): ...@@ -785,7 +785,7 @@ class VM_Linker(LocalLinker):
def accept(self, fgraph, no_recycling=None, profile=None): def accept(self, fgraph, no_recycling=None, profile=None):
"""Check if fgraph is the first FunctionGraph that has ever been """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 associated to fgraph
Parameters Parameters
...@@ -805,7 +805,7 @@ class VM_Linker(LocalLinker): ...@@ -805,7 +805,7 @@ class VM_Linker(LocalLinker):
give to the user. We don't want to reuse those object in give to the user. We don't want to reuse those object in
case the user have kept it. 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. element to None at the start of each call.
Older Linker use not exactly the same mechanism. They will Older Linker use not exactly the same mechanism. They will
...@@ -824,13 +824,13 @@ class VM_Linker(LocalLinker): ...@@ -824,13 +824,13 @@ class VM_Linker(LocalLinker):
Returns Returns
------- -------
Self if fgraph is the first FunctionGraph that has ever been 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: if no_recycling is None:
no_recycling = [] no_recycling = []
if self.fgraph is not None and self.fgraph is not fgraph: 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 # Warning: make sure to forward the correct values of
# all parameters to __init__ here. # all parameters to __init__ here.
return type(self)( return type(self)(
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论