From 1595841b7f54ea855f154915afbe20ce0b0e6bb1 Mon Sep 17 00:00:00 2001 From: electriclilies Date: Wed, 10 Feb 2021 13:13:10 -0800 Subject: [PATCH 01/14] remove hardcoded target and ctx --- tests/python/frontend/onnx/test_forward.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/python/frontend/onnx/test_forward.py b/tests/python/frontend/onnx/test_forward.py index 27b91dd38f8e..8ae21cd31c92 100644 --- a/tests/python/frontend/onnx/test_forward.py +++ b/tests/python/frontend/onnx/test_forward.py @@ -67,7 +67,6 @@ def get_tvm_output( graph_def, input_data, target, ctx, output_shape=None, output_dtype="float32", opset=None ): """ Generic function to execute and get tvm output""" - target = "llvm" input_names, shape_dict = get_input_data_shape_dict(graph_def, input_data) @@ -75,7 +74,6 @@ def get_tvm_output( with tvm.transform.PassContext(opt_level=1): graph, lib, params = relay.build(mod, target, params=params) - ctx = tvm.cpu(0) m = graph_runtime.create(graph, lib, ctx) # set inputs if isinstance(input_data, list): From 43668a99434993eba5043b2439e6f6ef24960409 Mon Sep 17 00:00:00 2001 From: mbrookhart Date: Fri, 12 Feb 2021 09:54:20 -0700 Subject: [PATCH 02/14] fix c-codgen for floating point mod --- src/target/source/codegen_c.cc | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/target/source/codegen_c.cc b/src/target/source/codegen_c.cc index af175c7f2208..c4d3c287c528 100644 --- a/src/target/source/codegen_c.cc +++ b/src/target/source/codegen_c.cc @@ -525,7 +525,18 @@ void CodeGenC::VisitExpr_(const DivNode* op, std::ostream& os) { // NOLINT(*) PrintBinaryExpr(op, "/", os, this); } void CodeGenC::VisitExpr_(const ModNode* op, std::ostream& os) { // NOLINT(*) - PrintBinaryExpr(op, "%", os, this); + if (op->dtype.is_int() || op->dtype.is_uint()) { + PrintBinaryExpr(op, "%", os, this); + } else { + ICHECK(op->dtype.is_float()) << "non integer or floating point datatype in Mod"; + if (op->dtype.bits() == 32) { + PrintBinaryExpr(op, "fmodf", os, this); + } else if (op->dtype.bits() == 64) { + PrintBinaryExpr(op, "fmod", os, this); + } else { + ICHECK(false) << "non single or double precision floating point in Mod"; + } + } } void CodeGenC::VisitExpr_(const MinNode* op, std::ostream& os) { // NOLINT(*) PrintBinaryExpr(op, "min", os, this); @@ -728,7 +739,6 @@ void CodeGenC::VisitStmt_(const StoreNode* op) { ICHECK(is_one(op->predicate)) << "Predicated store is not supported"; arith::PVar base; - if (arith::ramp(base, 1, t.lanes()).Match(op->index)) { std::string value = this->PrintExpr(op->value); this->PrintVecStore(op->buffer_var.get(), t, base.Eval(), value); From c02d9fbbfdb0c36d33c0138b54d456236fa53f0c Mon Sep 17 00:00:00 2001 From: electriclilies Date: Tue, 16 Mar 2021 17:12:12 -0700 Subject: [PATCH 03/14] MDisable onnx gpu test for argmin / argmax so we can get this fix merged. Matt or myself will fix later but we don't have time right now. --- tests/python/frontend/onnx/test_forward.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/python/frontend/onnx/test_forward.py b/tests/python/frontend/onnx/test_forward.py index 8ae21cd31c92..9cd8a9f5f0e1 100644 --- a/tests/python/frontend/onnx/test_forward.py +++ b/tests/python/frontend/onnx/test_forward.py @@ -1456,8 +1456,7 @@ def verify_argreduce(input_dim, op_name, axis=None, keepdims=None): model = helper.make_model(graph, producer_name="argreduce_test") verify_with_ort_with_inputs(model, [a_np1]) - -@tvm.testing.uses_gpu +#@tvm.testing.uses_gpu #TODO (mbrookhart, electriclilies) Fix argmin on GPU and enable this test def test_forward_arg_min_max(): """Verify argmin and argmax""" verify_argreduce([3, 4, 4], "ArgMin") From 371faff8e0aa077294383f5470f5ffc244641ec3 Mon Sep 17 00:00:00 2001 From: electriclilies Date: Tue, 16 Mar 2021 17:13:09 -0700 Subject: [PATCH 04/14] lint --- tests/python/frontend/onnx/test_forward.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/python/frontend/onnx/test_forward.py b/tests/python/frontend/onnx/test_forward.py index 9cd8a9f5f0e1..497a23c88e92 100644 --- a/tests/python/frontend/onnx/test_forward.py +++ b/tests/python/frontend/onnx/test_forward.py @@ -1456,6 +1456,7 @@ def verify_argreduce(input_dim, op_name, axis=None, keepdims=None): model = helper.make_model(graph, producer_name="argreduce_test") verify_with_ort_with_inputs(model, [a_np1]) + #@tvm.testing.uses_gpu #TODO (mbrookhart, electriclilies) Fix argmin on GPU and enable this test def test_forward_arg_min_max(): """Verify argmin and argmax""" From fcbc54e670304cae567bc81fa26f2932b62f7848 Mon Sep 17 00:00:00 2001 From: electriclilies Date: Tue, 16 Mar 2021 19:44:45 -0700 Subject: [PATCH 05/14] fix black --- tests/python/frontend/onnx/test_forward.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/python/frontend/onnx/test_forward.py b/tests/python/frontend/onnx/test_forward.py index 497a23c88e92..7cb959273ce5 100644 --- a/tests/python/frontend/onnx/test_forward.py +++ b/tests/python/frontend/onnx/test_forward.py @@ -1457,7 +1457,7 @@ def verify_argreduce(input_dim, op_name, axis=None, keepdims=None): verify_with_ort_with_inputs(model, [a_np1]) -#@tvm.testing.uses_gpu #TODO (mbrookhart, electriclilies) Fix argmin on GPU and enable this test +# @tvm.testing.uses_gpu #TODO (mbrookhart, electriclilies) Fix argmin on GPU and enable this test def test_forward_arg_min_max(): """Verify argmin and argmax""" verify_argreduce([3, 4, 4], "ArgMin") From dc4b083f11e5dd4fef4106b2f9aa62c5822a7bf4 Mon Sep 17 00:00:00 2001 From: electriclilies Date: Wed, 17 Mar 2021 10:04:54 -0700 Subject: [PATCH 06/14] Add flag to task_python_frontend.sh to only run GPU enabled tests on GPU --- tests/python/frontend/onnx/test_forward.py | 3 ++- tests/scripts/task_python_frontend.sh | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/python/frontend/onnx/test_forward.py b/tests/python/frontend/onnx/test_forward.py index 7cb959273ce5..d2d1b018c83c 100644 --- a/tests/python/frontend/onnx/test_forward.py +++ b/tests/python/frontend/onnx/test_forward.py @@ -1457,7 +1457,8 @@ def verify_argreduce(input_dim, op_name, axis=None, keepdims=None): verify_with_ort_with_inputs(model, [a_np1]) -# @tvm.testing.uses_gpu #TODO (mbrookhart, electriclilies) Fix argmin on GPU and enable this test +#TODO (mbrookhart, electriclilies) Fix argmin on GPU and enable this test +# @tvm.testing.uses_gpu def test_forward_arg_min_max(): """Verify argmin and argmax""" verify_argreduce([3, 4, 4], "ArgMin") diff --git a/tests/scripts/task_python_frontend.sh b/tests/scripts/task_python_frontend.sh index 6b1d8e5038fb..8c0b90ec8d5f 100755 --- a/tests/scripts/task_python_frontend.sh +++ b/tests/scripts/task_python_frontend.sh @@ -31,6 +31,9 @@ find . -type f -path "*.pyc" | xargs rm -f # Rebuild cython make cython3 +# Only run GPU enabled tests on GPU +export PYTEST_ADDOPTS="-m gpu $PYTEST_ADDOPTS" + echo "Running relay MXNet frontend test..." TVM_PYTHON_FFI_TYPES=cython run_pytest python-frontend-mxnet tests/python/frontend/mxnet From 2f60c432c8a54d98ce89685886d581ffe5614bc9 Mon Sep 17 00:00:00 2001 From: electriclilies Date: Wed, 17 Mar 2021 10:07:00 -0700 Subject: [PATCH 07/14] black again --- tests/python/frontend/onnx/test_forward.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/python/frontend/onnx/test_forward.py b/tests/python/frontend/onnx/test_forward.py index d2d1b018c83c..03d0ce1b9c13 100644 --- a/tests/python/frontend/onnx/test_forward.py +++ b/tests/python/frontend/onnx/test_forward.py @@ -1457,7 +1457,7 @@ def verify_argreduce(input_dim, op_name, axis=None, keepdims=None): verify_with_ort_with_inputs(model, [a_np1]) -#TODO (mbrookhart, electriclilies) Fix argmin on GPU and enable this test +# TODO (mbrookhart, electriclilies) Fix argmin on GPU and enable this test # @tvm.testing.uses_gpu def test_forward_arg_min_max(): """Verify argmin and argmax""" From b58dc24a5246e7335a49cac4bad6515fe5ff250c Mon Sep 17 00:00:00 2001 From: electriclilies Date: Thu, 18 Mar 2021 10:27:06 -0700 Subject: [PATCH 08/14] Enable GPU for test_nonzero --- tests/python/frontend/onnx/test_forward.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/python/frontend/onnx/test_forward.py b/tests/python/frontend/onnx/test_forward.py index 03d0ce1b9c13..0a83139b95b0 100644 --- a/tests/python/frontend/onnx/test_forward.py +++ b/tests/python/frontend/onnx/test_forward.py @@ -3376,9 +3376,7 @@ def verify_nonzero(indata, outdata, dtype): model = helper.make_model(graph, producer_name="nonzero_test") - verify_with_ort_with_inputs( - model, [indata], targets=["llvm"], dtype="int64", use_vm=True, opset=9 - ) + verify_with_ort_with_inputs(model, [indata], dtype="int64", use_vm=True, opset=9) input_data = np.array([[1, 0], [1, 1]], dtype=np.int64) result = np.array((np.nonzero(input_data))) # expected output [[0, 1, 1], [0, 0, 1]] From e765689faf046833f099108752345a1312eb7905 Mon Sep 17 00:00:00 2001 From: electriclilies Date: Thu, 18 Mar 2021 13:31:45 -0700 Subject: [PATCH 09/14] Respond to comments --- src/target/source/codegen_c.cc | 7 +++-- tests/python/frontend/onnx/test_forward.py | 33 ++++++++-------------- tests/scripts/task_python_frontend.sh | 6 ++-- 3 files changed, 20 insertions(+), 26 deletions(-) diff --git a/src/target/source/codegen_c.cc b/src/target/source/codegen_c.cc index c4d3c287c528..a9848075a762 100644 --- a/src/target/source/codegen_c.cc +++ b/src/target/source/codegen_c.cc @@ -528,13 +528,16 @@ void CodeGenC::VisitExpr_(const ModNode* op, std::ostream& os) { // NOLINT(*) if (op->dtype.is_int() || op->dtype.is_uint()) { PrintBinaryExpr(op, "%", os, this); } else { - ICHECK(op->dtype.is_float()) << "non integer or floating point datatype in Mod"; + ICHECK(op->dtype.is_float()) << "Expected floating point or integer dtype in Mod, but got " + << op->dtype; if (op->dtype.bits() == 32) { PrintBinaryExpr(op, "fmodf", os, this); } else if (op->dtype.bits() == 64) { PrintBinaryExpr(op, "fmod", os, this); } else { - ICHECK(false) << "non single or double precision floating point in Mod"; + ICHECK(false) + << "Non single or double precision floating point in Mod, expected 32 or 64 bits but got " + << op->dtype.bits() << " bits."; } } } diff --git a/tests/python/frontend/onnx/test_forward.py b/tests/python/frontend/onnx/test_forward.py index 0a83139b95b0..c9c0ff520dc5 100644 --- a/tests/python/frontend/onnx/test_forward.py +++ b/tests/python/frontend/onnx/test_forward.py @@ -272,8 +272,7 @@ def test_double_reshape(): tvm.testing.assert_allclose(ref_shape, tvm_out.shape) -# TODO(mbrookhart): enable once VM supports heterogenous execution -# @tvm.testing.uses_gpu +@tvm.testing.uses_gpu def test_expand(): def _test_expand(name, data, shape, ref_data, dtype="int32"): shape_array = np.array(shape) @@ -753,8 +752,7 @@ def add_noop_to_input_attr(attr_name, attr): verify_with_ort_with_inputs(model, [indata], opset=10, freeze_params=True, use_vm=True) -# TODO(mbrookhart): enable once VM supports heterogenous execution -# @tvm.testing.uses_gpu +@tvm.testing.uses_gpu def test_slice(): x = np.random.randn(20, 10, 5).astype(np.float32) _test_slice_iteration_v1(x, x[0:3, 0:10], starts=(0, 0), ends=(3, 10), axes=(0, 1)) @@ -974,8 +972,7 @@ def test_gather_nd(): verify_gather_nd([2, 2, 2], [[[0, 1]], [[1, 0]]], [2, 1, 2]) -# TODO(mbrookhart): enable once VM supports heterogenous execution -# @tvm.testing.uses_gpu +@tvm.testing.uses_gpu def test_onehot(): indices_shape = [10] indices_array = np.random.randint(low=0, high=9, size=indices_shape, dtype="int32") @@ -1051,8 +1048,7 @@ def verify_batch_matmul(a_shape, b_shape, out_shape, target, ctx): verify_with_ort_with_inputs(model, [a_array, b_array], use_vm=True, targets=[target]) -# TODO(mbrookhart): enable cuda once VM supports heterogenous execution -@tvm.testing.parametrize_targets("llvm") +@tvm.testing.parametrize_targets("llvm", "cuda") def test_batch_matmul(target, ctx): verify_batch_matmul((2, 3, 4, 3), (2, 3, 3, 4), (2, 3, 4, 4), target, ctx) verify_batch_matmul((2, 4, 3), (3, 4), (2, 4, 4), target, ctx) @@ -1106,8 +1102,7 @@ def verify_model(ex, a_shape, b_shape): verify_model(ex, [a * 3 for a in a_shape], [b * 3 for b in b_shape]) -# TODO(mbrookhart): enable cuda once VM supports heterogenous execution -@tvm.testing.parametrize_targets("llvm") +@tvm.testing.parametrize_targets("llvm", "cuda") def test_batch_matmul_dynamic_model(target, ctx): verify_simple_dynamic_model((2, 3, 4, 3), (2, 3, 3, 4), target, ctx) verify_simple_dynamic_model((2, 4, 3), (3, 4), target, ctx) @@ -1279,8 +1274,7 @@ def verify_upsample3d_trilinear(): tvm.testing.assert_allclose(out_array, tvm_out, rtol=1e-5, atol=1e-5) -# TODO(mbrookhart): enable once VM supports heterogenous execution -# @tvm.testing.uses_gpu +@tvm.testing.uses_gpu def test_upsample(): verify_upsample_nearest() verify_upsample_bilinear() @@ -1501,8 +1495,7 @@ def verify_constantofshape(input_dim, value, dtype): verify_with_ort_with_inputs(model, [input_np], use_vm=True) -# TODO(mbrookhart): enable once VM supports heterogenous execution -# @tvm.testing.uses_gpu +@tvm.testing.uses_gpu def test_constantofshape(): verify_constantofshape((2, 3, 4, 5), 10, "float32") verify_constantofshape((3, 3), 0, "int32") @@ -1588,8 +1581,7 @@ def verify_pad_v11(indata, pads, mode="constant", value=0.0): verify_with_ort_with_inputs(model, inputs, opset=11, use_vm=True) -# TODO(mbrookhart): enable once VM supports heterogenous execution -# @tvm.testing.uses_gpu +@tvm.testing.uses_gpu def test_pad(): verify_pad(np.random.randn(2, 2).astype(np.float32), [0, 1, 0, 0], "constant", 0.0) verify_pad(np.random.randn(2, 3).astype(np.float32), [1, 0, 0, 1], "constant", 0.0) @@ -2078,8 +2070,7 @@ def verify_tile_v6(indata, repeats, outdata): verify_with_ort_with_inputs(model, [indata, repeats], use_vm=True, opset=6) -# TODO(mbrookhart): enable once VM supports heterogenous execution -# @tvm.testing.uses_gpu +@tvm.testing.uses_gpu def test_tile(): x = np.random.rand(2, 3, 4, 5).astype(np.float32) repeats = np.random.randint(low=1, high=10, size=(np.ndim(x),)).astype(np.int64) @@ -2251,8 +2242,7 @@ def verify_batch_norm(in_shape): verify_batch_norm([16, 16, 10, 10]) -# TODO(mbrookhart): enable once VM supports heterogenous execution -# @tvm.testing.uses_gpu +@tvm.testing.uses_gpu def test_batch_norm_dynamic_subgraph(): def verify_batch_norm_dynamic_subgraph(in_shape, o_shape): @@ -3280,8 +3270,7 @@ def test_gru(): ) -# TODO(mbrookhart): enable once VM supports heterogenous execution -# @tvm.testing.uses_gpu +@tvm.testing.uses_gpu def test_resize(): def verify(ishape, oshape, scales, mode, coord_trans): nodes = [ diff --git a/tests/scripts/task_python_frontend.sh b/tests/scripts/task_python_frontend.sh index 8c0b90ec8d5f..e0aa7f9e00b5 100755 --- a/tests/scripts/task_python_frontend.sh +++ b/tests/scripts/task_python_frontend.sh @@ -31,8 +31,10 @@ find . -type f -path "*.pyc" | xargs rm -f # Rebuild cython make cython3 -# Only run GPU enabled tests on GPU -export PYTEST_ADDOPTS="-m gpu $PYTEST_ADDOPTS" +# Enable tvm.testing decorators in the ONNX importer test (not enabling in the other tests because we +# they do not consistently use the decorators to indicate that tests should run on GPU) +# In the future, we should enable tvm.testing decorators for all the test files. +PYTEST_ADDOPTS="-m gpu $PYTEST_ADDOPTS" run_pytest cython python-frontend-onnx tests/python/frontend/onnx echo "Running relay MXNet frontend test..." TVM_PYTHON_FFI_TYPES=cython run_pytest python-frontend-mxnet tests/python/frontend/mxnet From e583e9db223a8aede512d9e4e63b87d71afb461f Mon Sep 17 00:00:00 2001 From: electriclilies Date: Fri, 19 Mar 2021 12:18:23 -0700 Subject: [PATCH 10/14] Don't test batch matmul on CUDA --- tests/python/frontend/onnx/test_forward.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/python/frontend/onnx/test_forward.py b/tests/python/frontend/onnx/test_forward.py index c9c0ff520dc5..76757eac562d 100644 --- a/tests/python/frontend/onnx/test_forward.py +++ b/tests/python/frontend/onnx/test_forward.py @@ -1048,7 +1048,8 @@ def verify_batch_matmul(a_shape, b_shape, out_shape, target, ctx): verify_with_ort_with_inputs(model, [a_array, b_array], use_vm=True, targets=[target]) -@tvm.testing.parametrize_targets("llvm", "cuda") +# TODO(mbrookhart, electriclilies): Add CUDA as a target once batch matmul is fixed +@tvm.testing.parametrize_targets("llvm") def test_batch_matmul(target, ctx): verify_batch_matmul((2, 3, 4, 3), (2, 3, 3, 4), (2, 3, 4, 4), target, ctx) verify_batch_matmul((2, 4, 3), (3, 4), (2, 4, 4), target, ctx) From e6e5cf07eddfea33a58c1a93e3080707cbe849cb Mon Sep 17 00:00:00 2001 From: electriclilies Date: Mon, 22 Mar 2021 14:16:26 -0700 Subject: [PATCH 11/14] Turn cuda off for dynamic batch matmul test --- tests/python/frontend/onnx/test_forward.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/python/frontend/onnx/test_forward.py b/tests/python/frontend/onnx/test_forward.py index 76757eac562d..ce0128f46e11 100644 --- a/tests/python/frontend/onnx/test_forward.py +++ b/tests/python/frontend/onnx/test_forward.py @@ -1103,7 +1103,8 @@ def verify_model(ex, a_shape, b_shape): verify_model(ex, [a * 3 for a in a_shape], [b * 3 for b in b_shape]) -@tvm.testing.parametrize_targets("llvm", "cuda") +# TODO(mbrookhart, electriclilies): Add CUDA as a target once batch matmul is fixed +@tvm.testing.parametrize_targets("llvm") def test_batch_matmul_dynamic_model(target, ctx): verify_simple_dynamic_model((2, 3, 4, 3), (2, 3, 3, 4), target, ctx) verify_simple_dynamic_model((2, 4, 3), (3, 4), target, ctx) From 4f5a41c1c83d69eabc14a41f4380cd76f9ceb954 Mon Sep 17 00:00:00 2001 From: electriclilies Date: Tue, 23 Mar 2021 12:44:19 -0700 Subject: [PATCH 12/14] Fix task script --- tests/scripts/task_python_frontend.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/scripts/task_python_frontend.sh b/tests/scripts/task_python_frontend.sh index e0aa7f9e00b5..841969adb890 100755 --- a/tests/scripts/task_python_frontend.sh +++ b/tests/scripts/task_python_frontend.sh @@ -34,13 +34,12 @@ make cython3 # Enable tvm.testing decorators in the ONNX importer test (not enabling in the other tests because we # they do not consistently use the decorators to indicate that tests should run on GPU) # In the future, we should enable tvm.testing decorators for all the test files. -PYTEST_ADDOPTS="-m gpu $PYTEST_ADDOPTS" run_pytest cython python-frontend-onnx tests/python/frontend/onnx echo "Running relay MXNet frontend test..." TVM_PYTHON_FFI_TYPES=cython run_pytest python-frontend-mxnet tests/python/frontend/mxnet echo "Running relay ONNX frontend test..." -TVM_PYTHON_FFI_TYPES=cython run_pytest python-frontend-onnx tests/python/frontend/onnx +PYTEST_ADDOPTS="-m gpu $PYTEST_ADDOPTS" run_pytest cython python-frontend-onnx tests/python/frontend/onnx echo "Running relay CoreML frontend test..." TVM_PYTHON_FFI_TYPES=cython run_pytest python-frontend-coreml tests/python/frontend/coreml From dabc571b450109d200ad0e5c8e5688e9208042d4 Mon Sep 17 00:00:00 2001 From: electriclilies Date: Wed, 24 Mar 2021 12:31:11 -0700 Subject: [PATCH 13/14] Flaky test From 96bf1ba959f6c4894e432991d88da19c644f182d Mon Sep 17 00:00:00 2001 From: electriclilies Date: Mon, 29 Mar 2021 11:39:28 -0700 Subject: [PATCH 14/14] another flaky test