Skip to content

[Feature Request] Add an option to run GPU tests only, and skip all CPU tests #44159

@xwang233

Description

@xwang233

🚀 Feature

Add an option to run GPU tests only, and skip all CPU tests

For example, we can have an environment variable PYTORCH_TEST_GPU_ONLY=1.

Motivation

Usually, when people only want to test GPU functionalities, they can skip CPU tests to save plenty of times.

Pitch

For example, some pytorch tests look like (assuming pytorch built with GPU)

def test_something(self, device):
    # do something

At runtime, two tests test_something_cpu and test_something_cuda will be generated. The goal is to skip the test_something_cpu test and only run test_something_cuda.

For example, we can do it like this

PYTORCH_TEST_GPU_ONLY=1 python test/run_test.py

Alternatives

N/A

How to implement

If I understand the code correctly, this feature can be easily implemented like this

  1. Add TEST_GPU_ONLY = os.getenv('PYTORCH_TEST_GPU_ONLY', '0') == '1' here

    TEST_SKIP_FAST = os.getenv('PYTORCH_TEST_SKIP_FAST', '0') == '1'

  2. Add something like

    if TEST_GPU_ONLY:
        fullname = self.id().lower()
        is_cuda_test = 'gpu' in fullname or 'cuda' in fullname or 'cuda' in torch.tensor([]).device.type
        if not is_cuda_test:
            raise unittest.SkipTest("Test is probably not a GPU test. We disabled it with PYTORCH_TEST_GPU_ONLY")

here in setup of class common_utils.TestCase

def setUp(self):
if TEST_SKIP_FAST:
if not getattr(self, self._testMethodName).__dict__.get('slow_test', False):
raise unittest.SkipTest("test is fast; we disabled it with PYTORCH_TEST_SKIP_FAST")
check_disabled(str(self))
set_rng_seed(SEED)

Additional context

N/A

cc @mruberry @VitalyFedyunin @ptrblck @ngimel

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureA request for a proper, new feature.module: testsIssues related to tests (not the torch.testing module)triagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions