-
Notifications
You must be signed in to change notification settings - Fork 7.2k
Better logic for ignoring CPU tests on GPU machines #4025
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
NicolasHug
merged 12 commits into
pytorch:master
from
NicolasHug:even_better_needs_cuda_logic
Jun 14, 2021
+59
−111
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
bb41b2a
WIP
NicolasHug 2cfab33
lets try this
NicolasHug f9259b1
blank spaces
NicolasHug 9f25b30
remove all dont_collect references
NicolasHug 7d05304
Merge branch 'master' of github.com:pytorch/vision into even_better_n…
NicolasHug 4990c28
Address comments
NicolasHug 92bfaa1
trailing whitespace
NicolasHug cc00c5f
Merge branch 'master' into even_better_needs_cuda_logic
NicolasHug c32206a
Merge branch 'master' of github.com:pytorch/vision into even_better_n…
NicolasHug 1ac78b3
don't return, modify inplace instead
NicolasHug 658df51
Merge branch 'even_better_needs_cuda_logic' of github.com:NicolasHug/…
NicolasHug 78f5ac1
Merge branch 'master' into even_better_needs_cuda_logic
NicolasHug File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,52 @@ | ||
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" | ||
) | ||
|
||
|
||
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)) | ||
|
||
out_items.append(item) | ||
|
||
items[:] = out_items |
This file contains hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.