2626IN_RE_WORKER = os .environ .get ("INSIDE_RE_WORKER" ) is not None
2727IN_FBCODE = os .environ .get ("IN_FBCODE_TORCHVISION" ) == "1"
2828CUDA_NOT_AVAILABLE_MSG = 'CUDA device not available'
29+ CIRCLECI_GPU_NO_CUDA_MSG = "We're in a CircleCI GPU machine, and this test doesn't need cuda."
2930
3031
3132@contextlib .contextmanager
@@ -256,11 +257,19 @@ def call_args_to_kwargs_only(call_args, *callable_or_arg_names):
256257
257258
258259def cpu_and_gpu ():
259- # TODO: make this properly handle CircleCI
260260 import pytest # noqa
261261
262262 # ignore CPU tests in RE as they're already covered by another contbuild
263- devices = [] if IN_RE_WORKER else ['cpu' ]
263+ # also ignore CPU tests in CircleCI machines that have a GPU: these tests
264+ # are run on CPU-only machines already.
265+ if IN_RE_WORKER :
266+ devices = []
267+ else :
268+ if IN_CIRCLE_CI and torch .cuda .is_available ():
269+ mark = pytest .mark .skip (reason = CIRCLECI_GPU_NO_CUDA_MSG )
270+ else :
271+ mark = ()
272+ devices = [pytest .param ('cpu' , marks = mark )]
264273
265274 if torch .cuda .is_available ():
266275 cuda_marks = ()
@@ -278,7 +287,6 @@ def cpu_and_gpu():
278287
279288
280289def needs_cuda (test_func ):
281- # TODO: make this properly handle CircleCI
282290 import pytest # noqa
283291
284292 if IN_FBCODE and not IN_RE_WORKER :
@@ -293,12 +301,13 @@ def needs_cuda(test_func):
293301
294302
295303def cpu_only (test_func ):
296- # TODO: make this properly handle CircleCI
297304 import pytest # noqa
298305
299306 if IN_RE_WORKER :
300307 # The assumption is that all RE workers have GPUs.
301308 return pytest .mark .dont_collect (test_func )
309+ elif IN_CIRCLE_CI and torch .cuda .is_available ():
310+ return pytest .mark .skip (reason = CIRCLECI_GPU_NO_CUDA_MSG )(test_func )
302311 else :
303312 return test_func
304313
0 commit comments