You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2022/04/01 11:00:23 UTC

[GitHub] [tvm] wrongtest opened a new issue #10861: [Bug][Arith] test_arith_solve_linear_equations.py non-deterministic case error

wrongtest opened a new issue #10861:
URL: https://github.com/apache/tvm/issues/10861


   __________________________ test_solution_consistency ___________________________
        def test_solution_consistency():
            seed = random.randrange(sys.maxsize)
            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)
        
            for i in range(3):
                _check(num_vars=3, num_formulas=3, coef=(-2, 2))
            for i in range(3):
                _check(num_vars=3, num_formulas=4, coef=(-2, 2))
        
            for i in range(3):
    >           _check(num_vars=4, num_formulas=3, coef=(-1, 1))
    tests/python/unittest/test_arith_solve_linear_equations.py:78: 
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
    tests/python/unittest/test_arith_solve_linear_equations.py:58: in _check
        testing.check_int_constraints_trans_consistency(solution, param_ranges)
    python/tvm/testing/utils.py:374: in check_int_constraints_trans_consistency
        _check_forward(
    python/tvm/testing/utils.py:368: in _check_forward
        check_bool_expr_is_true(
    _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
    bool_expr = !(((((((x0 + (x1*-1)) + (x2*-1)) + x3) + -1) == ((((x0*-1) + x1) + (x3*-1)) + 1)) && (((x2 + x3) + -1) >= ((((x0*-1) + (x1*-1)) + (x3*-1)) + -1))) && ((((x0 + (x1*-1)) + x2) + (x3*-1)) == (((x0 + (x1*-1)) + (x2*-1)) + (x3*-1))))
    vranges = {x3: range(min=-20, ext=41), x0: range(min=-20, ext=41), x1: range(min=-20, ext=41), x2: range(min=-20, ext=41)}
    cond = (((((((x0 + (x1*-1)) + (x2*-1)) + x3) + -1) == ((((x0*-1) + x1) + (x3*-1)) + 1)) && (((x2 + x3) + -1) >= ((((x0*-1) + (x1*-1)) + (x3*-1)) + -1))) && ((((x0 + (x1*-1)) + x2) + (x3*-1)) == (((x0 + (x1*-1)) + (x2*-1)) + (x3*-1))))
        def check_bool_expr_is_true(bool_expr, vranges, cond=None):
            """Check that bool_expr holds given the condition cond
            for every value of free variables from vranges.
        
            for example, 2x > 4y solves to x > 2y given x in (0, 10) and y in (0, 10)
            here bool_expr is x > 2y, vranges is {x: (0, 10), y: (0, 10)}, cond is 2x > 4y
            We creates iterations to check,
            for x in range(10):
              for y in range(10):
                assert !(2x > 4y) || (x > 2y)
        
            Parameters
            ----------
            bool_expr : tvm.ir.PrimExpr
                Boolean expression to check
            vranges: Dict[tvm.tir.expr.Var, tvm.ir.Range]
                Free variables and their ranges
            cond: tvm.ir.PrimExpr
                extra conditions needs to be satisfied.
            """
            if cond is not None:
                bool_expr = tvm.te.any(tvm.tir.Not(cond), bool_expr)
        
            def _run_expr(expr, vranges):
                """Evaluate expr for every value of free variables
                given by vranges and return the tensor of results.
                """
        
                def _compute_body(*us):
                    vmap = {v: u + r.min for (v, r), u in zip(vranges.items(), us)}
                    return tvm.tir.stmt_functor.substitute(expr, vmap)
        
                A = tvm.te.compute([r.extent.value for v, r in vranges.items()], _compute_body)
                args = [tvm.nd.empty(A.shape, A.dtype)]
                sch = tvm.te.create_schedule(A.op)
                mod = tvm.build(sch, [A])
                mod(*args)
                return args[0].numpy()
        
            res = _run_expr(bool_expr, vranges)
            if not np.all(res):
                indices = list(np.argwhere(res == 0)[0])
                counterex = [(str(v), i + r.min) for (v, r), i in zip(vranges.items(), indices)]
                counterex = sorted(counterex, key=lambda x: x[0])
                counterex = ", ".join([v + " = " + str(i) for v, i in counterex])
                ana = tvm.arith.Analyzer()
    >           raise AssertionError(
                    "Expression {}\nis not true on {}\n"
                    "Counterexample: {}".format(ana.simplify(bool_expr), vranges, counterex)
                )
    E           AssertionError: Expression (((((((x0: int32 + x3: int32) - x1: int32) - x2: int32) - 1) != (((x1 + 1) - x0) - x3)) || ((x2 + x3) < (((0 - x0) - x1) - x3))) || ((((x0 + x2) - x1) - x3) != (((x0 - x1) - x2) - x3)))
    E           is not true on {x3: range(min=-20, ext=41), x0: range(min=-20, ext=41), x1: range(min=-20, ext=41), x2: range(min=-20, ext=41)}
    E           Counterexample: x0: int32 = 20, x1: int32 = 6, x2: int32 = 0, x3: int32 = -13
    python/tvm/testing/utils.py:325: AssertionError
    ----------------------------- Captured stdout call -----------------------------
    This test is intentionally non-deterministic, if it fails please report it in github issue together with this seed 5926982148184041698
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] wrongtest commented on issue #10861: [Bug][Arith] test_arith_solve_linear_equations.py non-deterministic case error

Posted by GitBox <gi...@apache.org>.
wrongtest commented on issue #10861:
URL: https://github.com/apache/tvm/issues/10861#issuecomment-1086503146


   +1, I also find it is ok in main. We depend on upstream commit up to 2f7bb58377736bec2a15b45fa730e6f5b73605fb. Maybe it is already fixed?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] vinx13 commented on issue #10861: [Bug][Arith] test_arith_solve_linear_equations.py non-deterministic case error

Posted by GitBox <gi...@apache.org>.
vinx13 commented on issue #10861:
URL: https://github.com/apache/tvm/issues/10861#issuecomment-1086465897


   This usually means some arithmetic simplification rules are wrong. Which commit did you use? I'm not able to reproduce in main


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org