-
Notifications
You must be signed in to change notification settings - Fork 7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fbsync] Better logic for ignoring CPU tests on GPU CI machines (#4025)
Reviewed By: fmassa Differential Revision: D29105975 fbshipit-source-id: 0f3446a61934e6b5ee3151c390e604e5b858d355
- Loading branch information
1 parent
7b21f69
commit 5865648
Showing
6 changed files
with
67 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,59 @@ | ||
from common_utils import IN_CIRCLE_CI, CIRCLECI_GPU_NO_CUDA_MSG, IN_FBCODE, IN_RE_WORKER, CUDA_NOT_AVAILABLE_MSG | ||
import torch | ||
import pytest | ||
|
||
|
||
def pytest_configure(config): | ||
# register an additional marker (see pytest_collection_modifyitems) | ||
config.addinivalue_line( | ||
"markers", "dont_collect: marks a test that should not be collected (avoids skipping it)" | ||
"markers", "needs_cuda: mark for tests that rely on a CUDA device" | ||
) | ||
config.addinivalue_line( | ||
"markers", "dont_collect: mark for tests that should not be collected" | ||
) | ||
|
||
|
||
def pytest_collection_modifyitems(items): | ||
# This hook is called by pytest after it has collected the tests (google its name!) | ||
# We can ignore some tests as we see fit here. In particular we ignore the tests that | ||
# we have marked with the custom 'dont_collect' mark. This avoids skipping the tests, | ||
# since the internal fb infra doesn't like skipping tests. | ||
to_keep = [item for item in items if item.get_closest_marker('dont_collect') is None] | ||
items[:] = to_keep | ||
# We can ignore some tests as we see fit here, or add marks, such as a skip mark. | ||
|
||
out_items = [] | ||
for item in items: | ||
# The needs_cuda mark will exist if the test was explicitely decorated with | ||
# the @needs_cuda decorator. It will also exist if it was parametrized with a | ||
# parameter that has the mark: for example if a test is parametrized with | ||
# @pytest.mark.parametrize('device', cpu_and_gpu()) | ||
# the "instances" of the tests where device == 'cuda' will have the 'needs_cuda' mark, | ||
# and the ones with device == 'cpu' won't have the mark. | ||
needs_cuda = item.get_closest_marker('needs_cuda') is not None | ||
|
||
if needs_cuda and not torch.cuda.is_available(): | ||
# In general, we skip cuda tests on machines without a GPU | ||
# There are special cases though, see below | ||
item.add_marker(pytest.mark.skip(reason=CUDA_NOT_AVAILABLE_MSG)) | ||
|
||
if IN_FBCODE: | ||
# fbcode doesn't like skipping tests, so instead we just don't collect the test | ||
# so that they don't even "exist", hence the continue statements. | ||
if not needs_cuda and IN_RE_WORKER: | ||
# The RE workers are the machines with GPU, we don't want them to run CPU-only tests. | ||
continue | ||
if needs_cuda and not torch.cuda.is_available(): | ||
# On the test machines without a GPU, we want to ignore the tests that need cuda. | ||
# TODO: something more robust would be to do that only in a sandcastle instance, | ||
# so that we can still see the test being skipped when testing locally from a devvm | ||
continue | ||
elif IN_CIRCLE_CI: | ||
# Here we're not in fbcode, so we can safely collect and skip tests. | ||
if not needs_cuda and torch.cuda.is_available(): | ||
# Similar to what happens in RE workers: we don't need the CircleCI GPU machines | ||
# to run the CPU-only tests. | ||
item.add_marker(pytest.mark.skip(reason=CIRCLECI_GPU_NO_CUDA_MSG)) | ||
|
||
if item.get_closest_marker('dont_collect') is not None: | ||
# currently, this is only used for some tests we're sure we dont want to run on fbcode | ||
continue | ||
|
||
out_items.append(item) | ||
|
||
items[:] = out_items |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.