Skip to content

Commit c52a33a

Browse files
authored
Skip some CPU-only tests on CircleCI machines with GPU (#4002)
1 parent ea6be12 commit c52a33a

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

.circleci/config.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,12 +687,20 @@ jobs:
687687
paths:
688688
- conda
689689
- env
690+
- run:
691+
# Here we create an envlist file that contains some env variables that we want the docker container to be aware of.
692+
# Normally, the CIRCLECI variable is set and available on all CI workflows: https://circleci.com/docs/2.0/env-vars/#built-in-environment-variables.
693+
# They're avaiable in all the other workflows (OSX and Windows).
694+
# But here, we're running the unittest_linux_gpu workflows in a docker container, where those variables aren't accessible.
695+
# So instead we dump the variables we need in env.list and we pass that file when invoking "docker run".
696+
name: export CIRCLECI env var
697+
command: echo "CIRCLECI=true" >> ./env.list
690698
- run:
691699
name: Install torchvision
692700
command: docker run -t --gpus all -v $PWD:$PWD -w $PWD -e UPLOAD_CHANNEL -e CU_VERSION "${image_name}" .circleci/unittest/linux/scripts/install.sh
693701
- run:
694702
name: Run tests
695-
command: docker run -e CIRCLECI -t --gpus all -v $PWD:$PWD -w $PWD "${image_name}" .circleci/unittest/linux/scripts/run_test.sh
703+
command: docker run --env-file ./env.list -t --gpus all -v $PWD:$PWD -w $PWD "${image_name}" .circleci/unittest/linux/scripts/run_test.sh
696704
- run:
697705
name: Post Process
698706
command: docker run -t --gpus all -v $PWD:$PWD -w $PWD "${image_name}" .circleci/unittest/linux/scripts/post_process.sh

.circleci/config.yml.in

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -687,12 +687,20 @@ jobs:
687687
paths:
688688
- conda
689689
- env
690+
- run:
691+
# Here we create an envlist file that contains some env variables that we want the docker container to be aware of.
692+
# Normally, the CIRCLECI variable is set and available on all CI workflows: https://circleci.com/docs/2.0/env-vars/#built-in-environment-variables.
693+
# They're avaiable in all the other workflows (OSX and Windows).
694+
# But here, we're running the unittest_linux_gpu workflows in a docker container, where those variables aren't accessible.
695+
# So instead we dump the variables we need in env.list and we pass that file when invoking "docker run".
696+
name: export CIRCLECI env var
697+
command: echo "CIRCLECI=true" >> ./env.list
690698
- run:
691699
name: Install torchvision
692700
command: docker run -t --gpus all -v $PWD:$PWD -w $PWD -e UPLOAD_CHANNEL -e CU_VERSION "${image_name}" .circleci/unittest/linux/scripts/install.sh
693701
- run:
694702
name: Run tests
695-
command: docker run -e CIRCLECI -t --gpus all -v $PWD:$PWD -w $PWD "${image_name}" .circleci/unittest/linux/scripts/run_test.sh
703+
command: docker run --env-file ./env.list -t --gpus all -v $PWD:$PWD -w $PWD "${image_name}" .circleci/unittest/linux/scripts/run_test.sh
696704
- run:
697705
name: Post Process
698706
command: docker run -t --gpus all -v $PWD:$PWD -w $PWD "${image_name}" .circleci/unittest/linux/scripts/post_process.sh

test/common_utils.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
IN_RE_WORKER = os.environ.get("INSIDE_RE_WORKER") is not None
2727
IN_FBCODE = os.environ.get("IN_FBCODE_TORCHVISION") == "1"
2828
CUDA_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

258259
def 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

280289
def 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

295303
def 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

Comments
 (0)