From deedee7d990fe0181ceb5beb0ed1867bd7d3ecdb Mon Sep 17 00:00:00 2001 From: Mohammed Yasin <32206511+Y-T-G@users.noreply.github.com> Date: Wed, 7 May 2025 03:20:14 +0600 Subject: [PATCH] Add checks for multi-GPU training (#20516) Signed-off-by: Mohammed Yasin <32206511+Y-T-G@users.noreply.github.com> --- tests/test_cuda.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/test_cuda.py b/tests/test_cuda.py index 9d5b902e..ff8f1e84 100644 --- a/tests/test_cuda.py +++ b/tests/test_cuda.py @@ -71,8 +71,13 @@ def test_export_engine_matrix(task, dynamic, int8, half, batch): @pytest.mark.skipif(not DEVICES, reason="No CUDA devices available") def test_train(): """Test model training on a minimal dataset using available CUDA devices.""" - device = DEVICES if len(DEVICES) > 1 else DEVICES[0] - YOLO(MODEL).train(data="coco8.yaml", imgsz=64, epochs=1, device=device) # requires imgsz>=64 + import os + + device = tuple(DEVICES) if len(DEVICES) > 1 else DEVICES[0] + results = YOLO(MODEL).train(data="coco8.yaml", imgsz=64, epochs=1, device=device) # requires imgsz>=64 + visible = eval(os.environ["CUDA_VISIBLE_DEVICES"]) + assert visible == device, f"Passed GPUs '{device}', but used GPUs '{visible}'" + assert results is (None if len(DEVICES) > 1 else not None) # DDP returns None, single-GPU returns metrics @pytest.mark.slow