[Bug] This test is intentionally non-deterministic, if it fails please report it in github issue together with this seed 2466330562623059511
Expected behavior
The tests/python/unittest/test_arith_solve_linear_equations.py::test_solution_consistency ut can pass
Actual behavior
This test is intentionally non-deterministic, if it fails please report it in github issue together with this seed 2466330562623059511
def test_solution_consistency(): seed = random.randrange(sys.maxsize) seed = 2466330562623059511 print( "\nThis test is intentionally non-deterministic, " "if it fails please report it in github issue together with this seed {}\n".format(seed) ) random.seed(seed)
def _check(num_vars, num_formulas, coef=(-5, 5), bounds=(-20, 20)):
variables = [te.var("x" + str(i)) for i in range(num_vars)]
relations = []
for i in range(num_formulas):
s1 = sum([v * random.randint(coef[0], coef[1]) for v in variables])
s1 += random.randint(coef[0], coef[1])
s2 = sum([v * random.randint(coef[0], coef[1]) for v in variables])
s2 += random.randint(coef[0], coef[1])
if random.random() < 0.7:
op = tvm.tir.EQ
else:
# we also make sure it can correctly handle inequalities
op = random.choice([tvm.tir.LE, tvm.tir.LT, tvm.tir.GE, tvm.tir.GT])
relations.append(op(s1, s2))
vranges = {v: tvm.ir.expr.Range(bounds[0], bounds[1] + 1) for v in variables}
solution = arith.solve_linear_equations(relations, variables, vranges)
testing.check_int_constraints_trans_consistency(solution)
# leaving some variables as parameters should also be ok
for k in [1, 2]:
if len(variables) > k:
solution = arith.solve_linear_equations(relations, variables[:-k], vranges)
param_ranges = {v: vranges[v] for v in variables[-k:]}
testing.check_int_constraints_trans_consistency(solution, param_ranges)
for i in range(2):
_check(num_vars=1, num_formulas=1)
for i in range(2):
_check(num_vars=1, num_formulas=2)
for i in range(2):
_check(num_vars=2, num_formulas=1)
for i in range(2):
_check(num_vars=2, num_formulas=2)
for i in range(2):
_check(num_vars=2, num_formulas=3)
../../12/tvm/tests/python/unittest/test_arith_solve_linear_equations.py:71:
../../12/tvm/tests/python/unittest/test_arith_solve_linear_equations.py:52: in _check testing.check_int_constraints_trans_consistency(solution) ../../12/tvm/python/tvm/testing/utils.py:392: in check_int_constraints_trans_consistency _check_forward( ../../12/tvm/python/tvm/testing/utils.py:385: in _check_forward cond_subst = ana.simplify(cond_subst) ../../12/tvm/python/tvm/arith/analyzer.py:159: in simplify return self._simplify(expr, steps) ../../12/tvm/python/tvm/_ffi/_ctypes/packed_func.py:239: in call raise_last_ffi_error()
def raise_last_ffi_error():
"""Raise the previous error from FFI
This should be used instead of `raise get_last_ffi_error()`, as it
handle propagation of errors across an FFI boundary. For example,
if Python passes a callback to a C++ function, and the callback
raises an exception, the re-thrown exception should contain the
full stack trace, not just the stack frames that are above the
outermost FFI call.
"""
_LIB.TVMGetLastPythonError.restype = ctypes.c_void_p
_LIB.TVMGetLastBacktrace.restype = ctypes.c_char_p
py_err = _LIB.TVMGetLastPythonError()
if py_err is None:
c_err_msg = py_str(_LIB.TVMGetLastError())
py_err_msg, err_type = c2pyerror(c_err_msg)
if err_type is not None and err_type.startswith("tvm.error."):
err_type = err_type[10:]
py_err = ERROR_TYPE.get(err_type, TVMError)(py_err_msg)
else:
# TVMGetLastPythonError returns a PyObject*, with NULL when
# there is no such value. If we annotated the restype as
# ctypes.py_object, we would need to return Py_None from the
# C++ implementation. This would require introducing a
# dependency on libpython that we want to avoid when not in a
# Python environment. Therefore, casting the resulting void*
# pointer to PyObject* using ctypes.
py_err = ctypes.cast(ctypes.c_void_p(py_err), ctypes.py_object).value
tb = py_err.__traceback__
# The py_err.__traceback__ only goes from the location thrown
# up to the next FFI handoff. To have the stacktrace also
# include the C++ side, we need to adjust the __traceback__
# before re-throwing.
backtrace = _LIB.TVMGetLastBacktrace()
if backtrace:
frames = re.split(r"\n\W+\d+:\W+", py_str(backtrace))
frames = frames[1:] # Skip "Stack trace: "
for frame in frames:
if " at " in frame:
func_name, frame = frame.split(" at ", 1)
filename, lineno = frame.rsplit(":", 1)
func_name = func_name.strip()
filename = filename.strip()
lineno = int(lineno.strip())
tb = _append_traceback_frame(tb, func_name, filename, lineno)
# Remove stack frames that provide little benefit to
# debugging. These are only removed from the stack frames
# contained within the exception we are re-raising, and not to
# the stack frames that it will continue to collect.
# Therefore, there may still be a single instance of these
# frames in the outermost Python-to-FFI call.
filter_funcs = [
lambda code: "tvm/_ffi/_ctypes/packed_func.py" in code.co_filename,
lambda code: "tvm/_ffi/base.py" in code.co_filename,
]
tb = _filter_traceback_frames(tb, filter_funcs)
py_err = py_err.with_traceback(tb)
# The exception PyObject may contain a large amount of state,
# including all stack frames that may be inspected in a later
# PDB post-mortem. Therefore, we must make sure to remove the
# underlying PyObject* from the C++ side after we retrieve it.
_LIB.TVMDropLastPythonError()
raise py_err
E TypeError: Traceback (most recent call last):
E 36: tvm::runtime::PackedFuncObj::Extractor<tvm::runtime::PackedFuncSubObj<tvm::arith::{lambda(tvm::runtime::TVMArgs, tvm::runtime::TVMRetValue*)#1}::operator()(tvm::runtime::TVMArgs, tvm::runtime::TVMRetValue*) const::{lambda(std::__cxx11::basic_string<char, std::char_traits
../../12/tvm/python/tvm/_ffi/base.py:482: TypeError
Environment
Ubuntu 2004, the tvm version is private version
Steps to reproduce
First , set seed to 2466330562623059511, then run tests/python/unittest/test_arith_solve_linear_equations.py::test_solution_consistency ut
Triage
None
- needs-triage