提交 f970c385 authored 作者: ricardoV94's avatar ricardoV94 提交者: Ricardo Vieira

Specify mode for tests that are C-specific

上级 23d6b3cd
...@@ -624,7 +624,7 @@ class TestFunction: ...@@ -624,7 +624,7 @@ class TestFunction:
def test_constant_output(self): def test_constant_output(self):
# Test that if the output is a constant, we respect the pytensor memory interface # Test that if the output is a constant, we respect the pytensor memory interface
f = function([], pt.constant([4])) f = function([], pt.constant([4]), mode="CVM")
# print f.maker.fgraph.toposort() # print f.maker.fgraph.toposort()
out = f() out = f()
assert (out == 4).all() assert (out == 4).all()
...@@ -635,7 +635,7 @@ class TestFunction: ...@@ -635,7 +635,7 @@ class TestFunction:
assert (out2 == 4).all() assert (out2 == 4).all()
# Test that if the output is a constant and borrow, we respect the pytensor memory interface # Test that if the output is a constant and borrow, we respect the pytensor memory interface
f = function([], Out(pt.constant([4]), borrow=True)) f = function([], Out(pt.constant([4]), borrow=True), mode="CVM")
# print f.maker.fgraph.toposort() # print f.maker.fgraph.toposort()
out = f() out = f()
assert (out == 4).all() assert (out == 4).all()
......
...@@ -33,12 +33,7 @@ class TestProfiling: ...@@ -33,12 +33,7 @@ class TestProfiling:
p = ProfileStats(False, gpu_checks=False) p = ProfileStats(False, gpu_checks=False)
if config.mode in ("DebugMode", "DEBUG_MODE", "FAST_COMPILE"): f = function(x, z, profile=p, name="test_profiling", mode="CVM")
m = "FAST_RUN"
else:
m = None
f = function(x, z, profile=p, name="test_profiling", mode=m)
inp = [np.arange(1024, dtype="float32") + 1 for i in range(len(x))] inp = [np.arange(1024, dtype="float32") + 1 for i in range(len(x))]
f(*inp) f(*inp)
......
...@@ -92,21 +92,15 @@ def test_inter_process_cache(): ...@@ -92,21 +92,15 @@ def test_inter_process_cache():
""" """
x, y = dvectors("xy") x, y = dvectors("xy")
f = function([x, y], [MyOp()(x), MyOp()(y)]) f = function([x, y], [MyOp()(x), MyOp()(y)], mode="CVM")
f(np.arange(60), np.arange(60)) f(np.arange(60), np.arange(60))
if config.mode == "FAST_COMPILE" or config.cxx == "": assert MyOp.nb_called == 1
assert MyOp.nb_called == 0
else:
assert MyOp.nb_called == 1
# What if we compile a new function with new variables? # What if we compile a new function with new variables?
x, y = dvectors("xy") x, y = dvectors("xy")
f = function([x, y], [MyOp()(x), MyOp()(y)]) f = function([x, y], [MyOp()(x), MyOp()(y)], mode="CVM")
f(np.arange(60), np.arange(60)) f(np.arange(60), np.arange(60))
if config.mode == "FAST_COMPILE" or config.cxx == "": assert MyOp.nb_called == 1
assert MyOp.nb_called == 0
else:
assert MyOp.nb_called == 1
@pytest.mark.filterwarnings("error") @pytest.mark.filterwarnings("error")
...@@ -401,7 +395,7 @@ def _f_build_cache_race_condition(factor): ...@@ -401,7 +395,7 @@ def _f_build_cache_race_condition(factor):
# optimization passes, so we need these config changes to prevent the # optimization passes, so we need these config changes to prevent the
# exceptions from being caught # exceptions from being caught
a = pt.vector() a = pt.vector()
f = pytensor.function([a], factor * a) f = pytensor.function([a], factor * a, mode="CVM")
return f(np.array([1], dtype=config.floatX)) return f(np.array([1], dtype=config.floatX))
......
...@@ -98,9 +98,7 @@ class TestCOp: ...@@ -98,9 +98,7 @@ class TestCOp:
def test_op_struct(self): def test_op_struct(self):
sop = StructOp() sop = StructOp()
c = sop(pytensor.tensor.constant(0)) c = sop(pytensor.tensor.constant(0))
mode = None mode = "CVM"
if config.mode == "FAST_COMPILE":
mode = "FAST_RUN"
f = pytensor.function([], c, mode=mode) f = pytensor.function([], c, mode=mode)
rval = f() rval = f()
assert rval == 0 assert rval == 0
......
...@@ -339,8 +339,8 @@ class TestParamsType: ...@@ -339,8 +339,8 @@ class TestParamsType:
x = matrix(dtype="float64") x = matrix(dtype="float64")
y1 = QuadraticOpFunc(a, b, c)(x) y1 = QuadraticOpFunc(a, b, c)(x)
y2 = QuadraticCOpFunc(a, b, c)(x) y2 = QuadraticCOpFunc(a, b, c)(x)
f1 = pytensor.function([x], y1) f1 = pytensor.function([x], y1, mode="CVM")
f2 = pytensor.function([x], y2) f2 = pytensor.function([x], y2, mode="CVM")
shape = (100, 100) shape = (100, 100)
vx = ( vx = (
np.random.normal(size=shape[0] * shape[1]).astype("float64").reshape(*shape) np.random.normal(size=shape[0] * shape[1]).astype("float64").reshape(*shape)
......
...@@ -73,9 +73,7 @@ def test_cdata(): ...@@ -73,9 +73,7 @@ def test_cdata():
i = TensorType("float32", shape=(None,))() i = TensorType("float32", shape=(None,))()
c = ProdOp()(i) c = ProdOp()(i)
i2 = GetOp()(c) i2 = GetOp()(c)
mode = None mode = "CVM"
if pytensor.config.mode == "FAST_COMPILE":
mode = "FAST_RUN"
# This should be a passthrough function for vectors # This should be a passthrough function for vectors
f = pytensor.function([i], i2, mode=mode) f = pytensor.function([i], i2, mode=mode)
...@@ -266,7 +264,7 @@ class TestEnumTypes: ...@@ -266,7 +264,7 @@ class TestEnumTypes:
c_sub = MyOpEnumList("-")(a, b) c_sub = MyOpEnumList("-")(a, b)
c_multiply = MyOpEnumList("*")(a, b) c_multiply = MyOpEnumList("*")(a, b)
c_divide = MyOpEnumList("/")(a, b) c_divide = MyOpEnumList("/")(a, b)
f = pytensor.function([a, b], [c_add, c_sub, c_multiply, c_divide]) f = pytensor.function([a, b], [c_add, c_sub, c_multiply, c_divide], mode="CVM")
va = 12 va = 12
vb = 15 vb = 15
ref = [va + vb, va - vb, va * vb, va // vb] ref = [va + vb, va - vb, va * vb, va // vb]
...@@ -281,7 +279,7 @@ class TestEnumTypes: ...@@ -281,7 +279,7 @@ class TestEnumTypes:
million = MyOpCEnumType("million")() million = MyOpCEnumType("million")()
billion = MyOpCEnumType("billion")() billion = MyOpCEnumType("billion")()
two_billions = MyOpCEnumType("two_billions")() two_billions = MyOpCEnumType("two_billions")()
f = pytensor.function([], [million, billion, two_billions]) f = pytensor.function([], [million, billion, two_billions], mode="CVM")
val_million, val_billion, val_two_billions = f() val_million, val_billion, val_two_billions = f()
assert val_million == 1000000 assert val_million == 1000000
assert val_billion == val_million * 1000 assert val_billion == val_million * 1000
......
...@@ -13,7 +13,6 @@ from pytensor.graph.fg import FunctionGraph ...@@ -13,7 +13,6 @@ from pytensor.graph.fg import FunctionGraph
from pytensor.graph.op import Op from pytensor.graph.op import Op
from pytensor.ifelse import ifelse from pytensor.ifelse import ifelse
from pytensor.link.c.basic import OpWiseCLinker from pytensor.link.c.basic import OpWiseCLinker
from pytensor.link.c.exceptions import MissingGXX
from pytensor.link.utils import map_storage from pytensor.link.utils import map_storage
from pytensor.link.vm import VM, Loop, Stack, VMLinker from pytensor.link.vm import VM, Loop, Stack, VMLinker
from pytensor.tensor.math import cosh, tanh from pytensor.tensor.math import cosh, tanh
...@@ -388,10 +387,10 @@ def test_VMLinker_make_vm_no_cvm(): ...@@ -388,10 +387,10 @@ def test_VMLinker_make_vm_no_cvm():
with config.change_flags(cxx=""): with config.change_flags(cxx=""):
# Make sure that GXX isn't present # Make sure that GXX isn't present
with pytest.raises(MissingGXX): # with pytest.raises(MissingGXX):
import pytensor.link.c.cvm import pytensor.link.c.cvm
reload(pytensor.link.c.cvm) reload(pytensor.link.c.cvm)
# Make sure that `cvm` module is missing # Make sure that `cvm` module is missing
with patch.dict("sys.modules", {"pytensor.link.c.cvm": None}): with patch.dict("sys.modules", {"pytensor.link.c.cvm": None}):
......
...@@ -1112,7 +1112,7 @@ class TestScan: ...@@ -1112,7 +1112,7 @@ class TestScan:
final_result = result[-1] final_result = result[-1]
f = function(inputs=[A, k], outputs=final_result) f = function(inputs=[A, k], outputs=final_result, mode="CVM")
f(np.asarray([2, 3, 0.1, 0, 1], dtype=config.floatX), 4) f(np.asarray([2, 3, 0.1, 0, 1], dtype=config.floatX), 4)
# There should be 3 outputs greater than 10: prior_result[0] at step 3, # There should be 3 outputs greater than 10: prior_result[0] at step 3,
......
...@@ -6,7 +6,7 @@ import pytensor.tensor as pt ...@@ -6,7 +6,7 @@ import pytensor.tensor as pt
from pytensor import function, scan, shared from pytensor import function, scan, shared
from pytensor.compile.builders import OpFromGraph from pytensor.compile.builders import OpFromGraph
from pytensor.compile.io import In from pytensor.compile.io import In
from pytensor.compile.mode import get_default_mode from pytensor.compile.mode import get_default_mode, get_mode
from pytensor.configdefaults import config from pytensor.configdefaults import config
from pytensor.gradient import grad, jacobian from pytensor.gradient import grad, jacobian
from pytensor.graph.basic import Constant, equal_computations from pytensor.graph.basic import Constant, equal_computations
...@@ -1796,7 +1796,7 @@ def test_inner_replace_dot(): ...@@ -1796,7 +1796,7 @@ def test_inner_replace_dot():
W = matrix("W") W = matrix("W")
h = matrix("h") h = matrix("h")
mode = get_default_mode().including("scan") # .excluding("BlasOpt") mode = get_mode("CVM").including("scan") # .excluding("BlasOpt")
o = scan( o = scan(
lambda hi, him1, W: (hi, dot(hi + him1, W)), lambda hi, him1, W: (hi, dot(hi + him1, W)),
...@@ -1922,7 +1922,7 @@ def test_opt_order(): ...@@ -1922,7 +1922,7 @@ def test_opt_order():
A = matrix("A") A = matrix("A")
z = scan(dot, sequences=[], non_sequences=[x, A], n_steps=2, return_updates=False) z = scan(dot, sequences=[], non_sequences=[x, A], n_steps=2, return_updates=False)
f = function([x, A], z, mode="FAST_RUN") f = function([x, A], z, mode="CVM")
topo = f.maker.fgraph.toposort() topo = f.maker.fgraph.toposort()
assert any(isinstance(node.op, Dot22) for node in topo) assert any(isinstance(node.op, Dot22) for node in topo)
......
...@@ -11,7 +11,7 @@ import pytensor.scalar as ps ...@@ -11,7 +11,7 @@ import pytensor.scalar as ps
import pytensor.tensor as pt import pytensor.tensor as pt
from pytensor.compile.function import function from pytensor.compile.function import function
from pytensor.compile.io import In from pytensor.compile.io import In
from pytensor.compile.mode import Mode from pytensor.compile.mode import Mode, get_mode
from pytensor.compile.sharedvalue import shared from pytensor.compile.sharedvalue import shared
from pytensor.configdefaults import config from pytensor.configdefaults import config
from pytensor.gradient import grad from pytensor.gradient import grad
...@@ -71,15 +71,7 @@ from tests import unittest_tools as utt ...@@ -71,15 +71,7 @@ from tests import unittest_tools as utt
from tests.tensor.utils import inplace_func, makeTester, random from tests.tensor.utils import inplace_func, makeTester, random
if config.mode == "FAST_COMPILE": mode_blas_opt = get_mode("CVM").excluding("c_blas")
mode_not_fast_compile = "FAST_RUN"
else:
mode_not_fast_compile = config.mode
mode_blas_opt = pytensor.compile.get_default_mode().including(
"BlasOpt", "specialize", "InplaceBlasOpt"
)
mode_blas_opt = mode_blas_opt.excluding("c_blas")
def test_dot_eq(): def test_dot_eq():
...@@ -214,7 +206,7 @@ class TestGemm: ...@@ -214,7 +206,7 @@ class TestGemm:
f = function( f = function(
[a, b], [a, b],
updates=[(s, lr1 * dot(a, b) + l2_reg * lr2 * s)], updates=[(s, lr1 * dot(a, b) + l2_reg * lr2 * s)],
mode=mode_not_fast_compile, mode="CVM",
).maker.fgraph.toposort() ).maker.fgraph.toposort()
# [Gemm{inplace}(<TensorType(float64, matrix)>, 0.01, # [Gemm{inplace}(<TensorType(float64, matrix)>, 0.01,
# <TensorType(float64, matrix)>, <TensorType(float64, matrix)>, # <TensorType(float64, matrix)>, <TensorType(float64, matrix)>,
...@@ -226,7 +218,7 @@ class TestGemm: ...@@ -226,7 +218,7 @@ class TestGemm:
f = function( f = function(
[a, b], [a, b],
updates=[(s, lr1 * (dot(a, b) - l2_reg * s))], updates=[(s, lr1 * (dot(a, b) - l2_reg * s))],
mode=mode_not_fast_compile, mode="CVM",
).maker.fgraph.toposort() ).maker.fgraph.toposort()
# [Gemm{inplace}(<TensorType(float64, matrix)>, 0.01, # [Gemm{inplace}(<TensorType(float64, matrix)>, 0.01,
# <TensorType(float64, matrix)>, <TensorType(float64, matrix)>, # <TensorType(float64, matrix)>, <TensorType(float64, matrix)>,
...@@ -238,7 +230,7 @@ class TestGemm: ...@@ -238,7 +230,7 @@ class TestGemm:
f = function( f = function(
[a, b], [a, b],
updates=[(s, s - lr1 * (s * 0.0002 + dot(a, b)))], updates=[(s, s - lr1 * (s * 0.0002 + dot(a, b)))],
mode=mode_not_fast_compile, mode="CVM",
).maker.fgraph.toposort() ).maker.fgraph.toposort()
# [Gemm{inplace}(<TensorType(float64, matrix)>, -0.01, # [Gemm{inplace}(<TensorType(float64, matrix)>, -0.01,
# <TensorType(float64, matrix)>, <TensorType(float64, matrix)>, # <TensorType(float64, matrix)>, <TensorType(float64, matrix)>,
...@@ -448,7 +440,11 @@ class TestGemmNoFlags: ...@@ -448,7 +440,11 @@ class TestGemmNoFlags:
B1 = self.get_variable(B, transpose_B, slice_B) B1 = self.get_variable(B, transpose_B, slice_B)
C1 = self.get_variable(C, transpose_C, slice_C) C1 = self.get_variable(C, transpose_C, slice_C)
return function([alpha, A, B, beta, C], self.gemm(C1, alpha, A1, B1, beta)) return function(
[alpha, A, B, beta, C],
self.gemm(C1, alpha, A1, B1, beta),
mode=mode_blas_opt,
)
def generate_value(self, dtype, width, height, to_transpose, to_slice, rng): def generate_value(self, dtype, width, height, to_transpose, to_slice, rng):
if to_slice: if to_slice:
...@@ -583,7 +579,7 @@ def just_gemm(i, o, ishapes=None, max_graphlen=0, expected_nb_gemm=1): ...@@ -583,7 +579,7 @@ def just_gemm(i, o, ishapes=None, max_graphlen=0, expected_nb_gemm=1):
f = inplace_func( f = inplace_func(
[In(ii, mutable=True, allow_downcast=True) for ii in i], [In(ii, mutable=True, allow_downcast=True) for ii in i],
o, o,
mode="FAST_RUN", mode=mode_blas_opt,
on_unused_input="ignore", on_unused_input="ignore",
) )
nb_gemm = 0 nb_gemm = 0
...@@ -680,7 +676,7 @@ def test_gemm_opt_double_gemm(): ...@@ -680,7 +676,7 @@ def test_gemm_opt_double_gemm():
f = inplace_func( f = inplace_func(
[In(ii, mutable=True) for ii in i], [In(ii, mutable=True) for ii in i],
o, o,
mode="FAST_RUN", mode=mode_blas_opt,
on_unused_input="ignore", on_unused_input="ignore",
) )
for node in f.maker.fgraph.apply_nodes: for node in f.maker.fgraph.apply_nodes:
...@@ -818,10 +814,10 @@ def test_gemm_opt_vector_stuff(): ...@@ -818,10 +814,10 @@ def test_gemm_opt_vector_stuff():
X, Y, a = matrix(), matrix(), scalar() X, Y, a = matrix(), matrix(), scalar()
u, v = vector(), vector() u, v = vector(), vector()
f = inplace_func([a, u, v], a + dot(u, v), mode="FAST_RUN") f = inplace_func([a, u, v], a + dot(u, v), mode=mode_blas_opt)
assert gemm_inplace not in [n.op for n in f.maker.fgraph.apply_nodes] assert gemm_inplace not in [n.op for n in f.maker.fgraph.apply_nodes]
f = inplace_func([a, u, X, Y], a * u + dot(X, Y), mode="FAST_RUN") f = inplace_func([a, u, X, Y], a * u + dot(X, Y), mode=mode_blas_opt)
assert gemm_inplace not in [n.op for n in f.maker.fgraph.apply_nodes] assert gemm_inplace not in [n.op for n in f.maker.fgraph.apply_nodes]
...@@ -886,7 +882,7 @@ def test_inplace0(): ...@@ -886,7 +882,7 @@ def test_inplace0():
) )
R, S, c = matrix("R"), matrix("S"), scalar("c") R, S, c = matrix("R"), matrix("S"), scalar("c")
f = inplace_func([Z, b, R, S], [Z * (Z + b * dot(R, S).T)], mode="FAST_RUN") f = inplace_func([Z, b, R, S], [Z * (Z + b * dot(R, S).T)], mode=mode_blas_opt)
assert gemm_inplace not in [n.op for n in f.maker.fgraph.apply_nodes] assert gemm_inplace not in [n.op for n in f.maker.fgraph.apply_nodes]
assert gemm_no_inplace in [n.op for n in f.maker.fgraph.apply_nodes] assert gemm_no_inplace in [n.op for n in f.maker.fgraph.apply_nodes]
...@@ -894,7 +890,7 @@ def test_inplace0(): ...@@ -894,7 +890,7 @@ def test_inplace0():
f = inplace_func( f = inplace_func(
[X, Y, Z, a, b, R, S, c], [X, Y, Z, a, b, R, S, c],
[Z * (c * Z + a * dot(X, Y) + b * dot(R, S).T)], [Z * (c * Z + a * dot(X, Y) + b * dot(R, S).T)],
mode="FAST_RUN", mode=mode_blas_opt,
) )
assert gemm_inplace in [n.op for n in f.maker.fgraph.apply_nodes] assert gemm_inplace in [n.op for n in f.maker.fgraph.apply_nodes]
...@@ -902,7 +898,7 @@ def test_inplace0(): ...@@ -902,7 +898,7 @@ def test_inplace0():
def test_inplace1(): def test_inplace1():
X, Y, Z, _a, _b = XYZab() X, Y, Z, _a, _b = XYZab()
# with > 2 terms in the overall addition # with > 2 terms in the overall addition
f = inplace_func([X, Y, Z], [Z + Z + dot(X, Y)], mode="FAST_RUN") f = inplace_func([X, Y, Z], [Z + Z + dot(X, Y)], mode=mode_blas_opt)
# pytensor.printing.debugprint(f) # pytensor.printing.debugprint(f)
# it doesn't work inplace because we didn't mark Z as mutable input # it doesn't work inplace because we didn't mark Z as mutable input
assert [n.op for n in f.maker.fgraph.apply_nodes] == [gemm_no_inplace] assert [n.op for n in f.maker.fgraph.apply_nodes] == [gemm_no_inplace]
...@@ -1119,7 +1115,7 @@ def test_dot22scalar_cast(): ...@@ -1119,7 +1115,7 @@ def test_dot22scalar_cast():
def test_local_dot22_to_dot22scalar(): def test_local_dot22_to_dot22scalar():
# This test that the bug in gh-1507 is really fixed # This test that the bug in gh-1507 is really fixed
A = dmatrix() A = dmatrix()
mode = pytensor.compile.mode.get_default_mode() mode = get_mode("CVM")
opt = in2out(local_dot22_to_dot22scalar) opt = in2out(local_dot22_to_dot22scalar)
mode = mode.__class__(optimizer=opt) mode = mode.__class__(optimizer=opt)
...@@ -1359,7 +1355,7 @@ class TestGemv(unittest_tools.OptimizationTestMixin): ...@@ -1359,7 +1355,7 @@ class TestGemv(unittest_tools.OptimizationTestMixin):
beta = shared(np.asarray(1.0, dtype=config.floatX), name="beta") beta = shared(np.asarray(1.0, dtype=config.floatX), name="beta")
z = beta * y + alpha * dot(A, x) z = beta * y + alpha * dot(A, x)
f = function([A, x, y], z) f = function([A, x, y], z, mode=mode_blas_opt)
# Matrix value # Matrix value
A_val = np.ones((5, 3), dtype=config.floatX) A_val = np.ones((5, 3), dtype=config.floatX)
...@@ -1726,8 +1722,7 @@ class TestGer(unittest_tools.OptimizationTestMixin): ...@@ -1726,8 +1722,7 @@ class TestGer(unittest_tools.OptimizationTestMixin):
shared = staticmethod(shared) shared = staticmethod(shared)
def setup_method(self): def setup_method(self):
self.mode = pytensor.compile.get_default_mode().including("fast_run") self.mode = get_mode("cvm").excluding("c_blas", "scipy_blas")
self.mode = self.mode.excluding("c_blas", "scipy_blas")
dtype = self.dtype = "float64" # optimization isn't dtype-dependent dtype = self.dtype = "float64" # optimization isn't dtype-dependent
self.A = tensor(dtype=dtype, shape=(None, None)) self.A = tensor(dtype=dtype, shape=(None, None))
self.a = tensor(dtype=dtype, shape=()) self.a = tensor(dtype=dtype, shape=())
...@@ -1940,8 +1935,7 @@ class TestGer(unittest_tools.OptimizationTestMixin): ...@@ -1940,8 +1935,7 @@ class TestGer(unittest_tools.OptimizationTestMixin):
class TestBlasStrides: class TestBlasStrides:
dtype = "float64" dtype = "float64"
mode = pytensor.compile.get_default_mode() mode = get_mode("cvm").excluding("c_blas", "scipy_blas")
mode = mode.including("fast_run").excluding("gpu", "c_blas", "scipy_blas")
def random(self, *shape, rng=None): def random(self, *shape, rng=None):
return np.asarray(rng.random(shape), dtype=self.dtype) return np.asarray(rng.random(shape), dtype=self.dtype)
...@@ -2326,6 +2320,8 @@ class TestBlasStrides: ...@@ -2326,6 +2320,8 @@ class TestBlasStrides:
class TestInferShape(unittest_tools.InferShapeTester): class TestInferShape(unittest_tools.InferShapeTester):
mode = mode_blas_opt
def test_dot22(self): def test_dot22(self):
rng = np.random.default_rng(unittest_tools.fetch_seed()) rng = np.random.default_rng(unittest_tools.fetch_seed())
x, y = matrices("xy") x, y = matrices("xy")
...@@ -2475,6 +2471,7 @@ TestBatchedDot = makeTester( ...@@ -2475,6 +2471,7 @@ TestBatchedDot = makeTester(
bad_dim1=(random(3, 5, 7, rng=rng), random(3, 5, 7, rng=rng)), bad_dim1=(random(3, 5, 7, rng=rng), random(3, 5, 7, rng=rng)),
bad_dim2=(random(3, 5, 7, rng=rng), random(3, 8, 3, rng=rng)), bad_dim2=(random(3, 5, 7, rng=rng), random(3, 8, 3, rng=rng)),
), ),
mode=mode_blas_opt,
) )
...@@ -2536,7 +2533,7 @@ def test_batched_dot_not_contiguous(): ...@@ -2536,7 +2533,7 @@ def test_batched_dot_not_contiguous():
def test_batched_dot_blas_flags(): def test_batched_dot_blas_flags():
"""Test that BatchedDot works regardless of presence of BLAS flags""" """Test that BatchedDot works regardless of presence of BLAS flags"""
mode = "FAST_RUN" mode = mode_blas_opt
rng = np.random.default_rng(2708) rng = np.random.default_rng(2708)
x = tensor("x", shape=(2, 5, 3)) x = tensor("x", shape=(2, 5, 3))
......
...@@ -5,6 +5,7 @@ import pytest ...@@ -5,6 +5,7 @@ import pytest
import pytensor import pytensor
import pytensor.tensor as pt import pytensor.tensor as pt
from pytensor.compile import get_mode
from pytensor.tensor.basic import AllocEmpty from pytensor.tensor.basic import AllocEmpty
from pytensor.tensor.blas import Ger from pytensor.tensor.blas import Ger
from pytensor.tensor.blas_c import CGemv, CGer, must_initialize_y_gemv from pytensor.tensor.blas_c import CGemv, CGer, must_initialize_y_gemv
...@@ -22,9 +23,7 @@ from tests.tensor.test_blas import BaseGemv, TestBlasStrides ...@@ -22,9 +23,7 @@ from tests.tensor.test_blas import BaseGemv, TestBlasStrides
from tests.unittest_tools import OptimizationTestMixin from tests.unittest_tools import OptimizationTestMixin
mode_blas_opt = pytensor.compile.get_default_mode().including( mode_blas_opt = get_mode("CVM")
"BlasOpt", "specialize", "InplaceBlasOpt", "c_blas"
)
def skip_if_blas_ldflags_empty(*functions_detected): def skip_if_blas_ldflags_empty(*functions_detected):
...@@ -46,7 +45,7 @@ class TestCGer(OptimizationTestMixin): ...@@ -46,7 +45,7 @@ class TestCGer(OptimizationTestMixin):
def manual_setup_method(self, dtype="float64"): def manual_setup_method(self, dtype="float64"):
# This tests can run even when pytensor.config.blas__ldflags is empty. # This tests can run even when pytensor.config.blas__ldflags is empty.
self.dtype = dtype self.dtype = dtype
self.mode = pytensor.compile.get_default_mode().including("fast_run") self.mode = mode_blas_opt
self.A = tensor(dtype=dtype, shape=(None, None)) self.A = tensor(dtype=dtype, shape=(None, None))
self.a = tensor(dtype=dtype, shape=()) self.a = tensor(dtype=dtype, shape=())
self.x = tensor(dtype=dtype, shape=(None,)) self.x = tensor(dtype=dtype, shape=(None,))
...@@ -130,10 +129,9 @@ class TestCGemv(OptimizationTestMixin): ...@@ -130,10 +129,9 @@ class TestCGemv(OptimizationTestMixin):
""" """
def setup_method(self): def setup_method(self):
# This tests can run even when pytensor.config.blas__ldflags is empty.
dtype = "float64" dtype = "float64"
self.dtype = dtype self.dtype = dtype
self.mode = pytensor.compile.get_default_mode().including("fast_run") self.mode = mode_blas_opt
# matrix # matrix
self.A = tensor("A", dtype=dtype, shape=(None, None)) self.A = tensor("A", dtype=dtype, shape=(None, None))
self.Aval = np.ones((2, 3), dtype=dtype) self.Aval = np.ones((2, 3), dtype=dtype)
......
...@@ -3752,7 +3752,7 @@ class TestMatMul: ...@@ -3752,7 +3752,7 @@ class TestMatMul:
def test_dot22_opt(self): def test_dot22_opt(self):
x, y = matrices("xy") x, y = matrices("xy")
fn = function([x, y], x @ y, mode="FAST_RUN") fn = function([x, y], x @ y, mode="CVM")
[node] = fn.maker.fgraph.apply_nodes [node] = fn.maker.fgraph.apply_nodes
assert isinstance(node.op, Dot22) assert isinstance(node.op, Dot22)
......
...@@ -513,6 +513,7 @@ def makeSharedTester( ...@@ -513,6 +513,7 @@ def makeSharedTester(
updates=[ updates=[
(s_shared, pytensor.tensor.dot(a_shared, b_shared) + s_shared) (s_shared, pytensor.tensor.dot(a_shared, b_shared) + s_shared)
], ],
mode="CVM",
) )
topo = f.maker.fgraph.toposort() topo = f.maker.fgraph.toposort()
f() f()
...@@ -546,6 +547,7 @@ def makeSharedTester( ...@@ -546,6 +547,7 @@ def makeSharedTester(
pytensor.tensor.dot(a_shared, b_shared) + s_shared_specify, pytensor.tensor.dot(a_shared, b_shared) + s_shared_specify,
) )
], ],
mode="CVM",
) )
topo = f.maker.fgraph.toposort() topo = f.maker.fgraph.toposort()
shp = f() shp = f()
...@@ -577,6 +579,7 @@ def makeSharedTester( ...@@ -577,6 +579,7 @@ def makeSharedTester(
pytensor.tensor.dot(a_shared, b_shared) + s_shared_specify, pytensor.tensor.dot(a_shared, b_shared) + s_shared_specify,
) )
], ],
mode="CVM",
) )
topo = f.maker.fgraph.toposort() topo = f.maker.fgraph.toposort()
shp = f() shp = f()
......
...@@ -158,8 +158,7 @@ def test_debugprint(): ...@@ -158,8 +158,7 @@ def test_debugprint():
F = D + E F = D + E
G = C + F G = C + F
mode = pytensor.compile.get_default_mode().including("fusion") g = pytensor.function([A, B, D, E], G)
g = pytensor.function([A, B, D, E], G, mode=mode)
# just test that it work # just test that it work
s = StringIO() s = StringIO()
...@@ -250,7 +249,7 @@ def test_debugprint(): ...@@ -250,7 +249,7 @@ def test_debugprint():
assert s == reference assert s == reference
# Test the `profile` handling when profile data is missing # Test the `profile` handling when profile data is missing
g = pytensor.function([A, B, D, E], G, mode=mode, profile=True) g = pytensor.function([A, B, D, E], G, profile=True)
s = StringIO() s = StringIO()
debugprint(g, file=s, id_type="", print_storage=True) debugprint(g, file=s, id_type="", print_storage=True)
...@@ -291,7 +290,7 @@ def test_debugprint(): ...@@ -291,7 +290,7 @@ def test_debugprint():
J = dvector() J = dvector()
s = StringIO() s = StringIO()
debugprint( debugprint(
pytensor.function([A, B, D, J], A + (B.dot(J) - D), mode="FAST_RUN"), pytensor.function([A, B, D, J], A + (B.dot(J) - D), mode="CVM"),
file=s, file=s,
id_type="", id_type="",
print_destroy_map=True, print_destroy_map=True,
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论