Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] This test is intentionally non-deterministic, if it fails please report it in github issue together with this seed 2466330562623059511 #17560

Closed
onedayherocoming opened this issue Dec 16, 2024 · 0 comments
Labels
needs-triage PRs or issues that need to be investigated by maintainers to find the right assignees to address it type: bug

Comments

@onedayherocoming
Copy link

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, std::allocator >)#1}::operator()(std::_cxx11::basic_string<char, std::char_traits, std::allocator >) const::{lambda(tvm::runtime::TVMArgs, tvm::runtime::TVMRetValue*)#4}> >::Call(tvm::runtime::PackedFuncObj const*, tvm::runtime::TVMArgs, tvm::runtime::TVMRetValue*)
E 35: tvm::arith::Analyzer::Simplify(tvm::PrimExpr const&, int)
E 34: tvm::arith::CanonicalSimplifier::operator()(tvm::PrimExpr const&)
E 33: non-virtual thunk to tvm::arith::CanonicalSimplifier::Impl::VisitExpr(tvm::PrimExpr const&)
E 32: tvm::arith::RewriteSimplifier::Impl::VisitExpr(tvm::PrimExpr const&)
E 31: ZZN3tvm3tir11ExprFunctorIFNS_8PrimExprERKS2_EE10InitVTableEvENUlRKNS_7runtime
E 30: tvm::arith::RewriteSimplifier::Impl::VisitExpr
(tvm::tir::AndNode const*)
E 29: non-virtual thunk to tvm::arith::CanonicalSimplifier::Impl::VisitExpr(tvm::PrimExpr const&)
E 28: tvm::arith::RewriteSimplifier::Impl::VisitExpr(tvm::PrimExpr const&)
E 27: ZZN3tvm3tir11ExprFunctorIFNS_8PrimExprERKS2_EE10InitVTableEvENUlRKNS_7runtime
E 26: tvm::arith::RewriteSimplifier::Impl::VisitExpr
(tvm::tir::AndNode const*)
E 25: tvm::arith::RewriteSimplifier::Impl::RecursiveRewrite(tvm::PrimExpr const&)
E 24: tvm::arith::CanonicalSimplifier::Impl::VisitExpr(tvm::PrimExpr const&)
E 23: tvm::arith::RewriteSimplifier::Impl::VisitExpr(tvm::PrimExpr const&)
E 22: ZZN3tvm3tir11ExprFunctorIFNS_8PrimExprERKS2_EE10InitVTableEvENUlRKNS_7runtime
E 21: tvm::arith::RewriteSimplifier::Impl::VisitExpr
(tvm::tir::AndNode const*)
E 20: non-virtual thunk to tvm::arith::CanonicalSimplifier::Impl::VisitExpr(tvm::PrimExpr const&)
E 19: tvm::arith::RewriteSimplifier::Impl::VisitExpr(tvm::PrimExpr const&)
E 18: ZZN3tvm3tir11ExprFunctorIFNS_8PrimExprERKS2_EE10InitVTableEvENUlRKNS_7runtime
E 17: tvm::arith::RewriteSimplifier::Impl::VisitExpr
(tvm::tir::AndNode const*)
E 16: non-virtual thunk to tvm::arith::CanonicalSimplifier::Impl::VisitExpr(tvm::PrimExpr const&)
E 15: tvm::arith::RewriteSimplifier::Impl::VisitExpr(tvm::PrimExpr const&)
E 14: ZZN3tvm3tir11ExprFunctorIFNS_8PrimExprERKS2_EE10InitVTableEvENUlRKNS_7runtime
E 13: tvm::arith::RewriteSimplifier::Impl::VisitExpr
(tvm::tir::AndNode const*)
E 12: non-virtual thunk to tvm::arith::CanonicalSimplifier::Impl::VisitExpr(tvm::PrimExpr const&)
E 11: tvm::arith::RewriteSimplifier::Impl::VisitExpr(tvm::PrimExpr const&)
E 10: ZZN3tvm3tir11ExprFunctorIFNS_8PrimExprERKS2_EE10InitVTableEvENUlRKNS_7runtime
E 9: tvm::arith::RewriteSimplifier::Impl::VisitExpr
(tvm::tir::AndNode const*)
E 8: non-virtual thunk to tvm::arith::CanonicalSimplifier::Impl::VisitExpr(tvm::PrimExpr const&)
E 7: tvm::arith::RewriteSimplifier::Impl::VisitExpr(tvm::PrimExpr const&)
E 6: ZZN3tvm3tir11ExprFunctorIFNS_8PrimExprERKS2_EE10InitVTableEvENUlRKNS_7runtime
E 5: tvm::arith::CanonicalSimplifier::Impl::VisitExpr
(tvm::tir::LTNode const*)
E 4: tvm::arith::RewriteSimplifier::Impl::VisitExpr(tvm::PrimExpr const&)
E 3: ZZN3tvm3tir11ExprFunctorIFNS_8PrimExprERKS2_EE10InitVTableEvENUlRKNS_7runtime
E 2: tvm::arith::CanonicalSimplifier::Impl::VisitExpr
(tvm::tir::LTNode const*)
E 1: tvm::arith::RewriteSimplifier::Impl::VisitExpr
(tvm::tir::LTNode const*)
E 0: tvm::tir::LT::LT(tvm::PrimExpr, tvm::PrimExpr, tvm::Span)
E File "/home/max.qin/time_wheel_24/12/tvm/src/tir/ir/expr.cc", line 320
E TypeError: Check failed: (a.dtype() == b.dtype()) is false: mismatched types. int64 vs. int32

../../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
@onedayherocoming onedayherocoming added needs-triage PRs or issues that need to be investigated by maintainers to find the right assignees to address it type: bug labels Dec 16, 2024
@onedayherocoming onedayherocoming closed this as not planned Won't fix, can't repro, duplicate, stale Dec 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-triage PRs or issues that need to be investigated by maintainers to find the right assignees to address it type: bug
Projects
None yet
Development

No branches or pull requests

1 participant