From 2f935d4877c9ec795921af77236736796b20f7c4 Mon Sep 17 00:00:00 2001 From: driazati Date: Fri, 12 Aug 2022 13:36:01 -0700 Subject: [PATCH] [ci] Default to n=2 for test parallelism This is attempt #2 of #12376 which was reverted in #12413. The changes in `plugin.py` should keep all the tests on the same node so sporadic failures don't happen due to scheduling. --- python/tvm/testing/plugin.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/python/tvm/testing/plugin.py b/python/tvm/testing/plugin.py index 1f4f983b72102..66b728771d70a 100644 --- a/python/tvm/testing/plugin.py +++ b/python/tvm/testing/plugin.py @@ -37,6 +37,13 @@ import tvm from tvm.testing import utils +try: + from xdist.scheduler.loadscope import LoadScopeScheduling + + HAVE_XDIST = True +except ImportError: + HAVE_XDIST = False + MARKERS = { "gpu": "mark a test as requiring a gpu", @@ -319,3 +326,25 @@ def _parametrize_correlated_parameters(metafunc): names = ",".join(name for name, values in params) value_sets = zip(*[values for name, values in params]) metafunc.parametrize(names, value_sets, indirect=True, ids=ids) + + +# pytest-xdist isn't required but is used in CI, so guard on its presence +if HAVE_XDIST: + + def pytest_xdist_make_scheduler(config, log): + """ + Serialize certain tests for pytest-xdist that have inter-test + dependencies + """ + + class TvmTestScheduler(LoadScopeScheduling): + def _split_scope(self, nodeid): + # NOTE: test_tvm_testing_features contains + # parametrization-related tests, and must be serialized on a + # single host. + # raise RuntimeError() + if "test_tvm_testing_features" in nodeid: + return "functional-tests" + return nodeid + + return TvmTestScheduler(config, log)