@@ -98,6 +98,7 @@ def test_accelerator_choice_ddp_spawn(cuda_available_mock, device_count_mock):
9898@mock .patch ("torch.cuda.set_device" )
9999@mock .patch ("torch.cuda.device_count" , return_value = 2 )
100100@mock .patch ("pytorch_lightning.strategies.DDPStrategy.setup_distributed" , autospec = True )
101+ @mock .patch ("torch.cuda.is_available" , return_value = True )
101102def test_accelerator_choice_ddp_slurm (* _ ):
102103 with pytest .deprecated_call (match = r"accelerator='ddp'\)` has been deprecated in v1.5" ):
103104 trainer = Trainer (fast_dev_run = True , accelerator = "ddp" , gpus = 2 )
@@ -123,6 +124,7 @@ def test_accelerator_choice_ddp_slurm(*_):
123124@mock .patch ("torch.cuda.set_device" )
124125@mock .patch ("torch.cuda.device_count" , return_value = 2 )
125126@mock .patch ("pytorch_lightning.strategies.DDPStrategy.setup_distributed" , autospec = True )
127+ @mock .patch ("torch.cuda.is_available" , return_value = True )
126128def test_accelerator_choice_ddp2_slurm (* _ ):
127129 with pytest .deprecated_call (match = r"accelerator='ddp2'\)` has been deprecated in v1.5" ):
128130 trainer = Trainer (fast_dev_run = True , accelerator = "ddp2" , gpus = 2 )
@@ -148,6 +150,7 @@ def test_accelerator_choice_ddp2_slurm(*_):
148150@mock .patch ("torch.cuda.set_device" )
149151@mock .patch ("torch.cuda.device_count" , return_value = 1 )
150152@mock .patch ("pytorch_lightning.strategies.DDPStrategy.setup_distributed" , autospec = True )
153+ @mock .patch ("torch.cuda.is_available" , return_value = True )
151154def test_accelerator_choice_ddp_te (* _ ):
152155 with pytest .deprecated_call (match = r"accelerator='ddp'\)` has been deprecated in v1.5" ):
153156 trainer = Trainer (fast_dev_run = True , accelerator = "ddp" , gpus = 2 )
@@ -172,6 +175,7 @@ def test_accelerator_choice_ddp_te(*_):
172175@mock .patch ("torch.cuda.set_device" )
173176@mock .patch ("torch.cuda.device_count" , return_value = 1 )
174177@mock .patch ("pytorch_lightning.strategies.DDPStrategy.setup_distributed" , autospec = True )
178+ @mock .patch ("torch.cuda.is_available" , return_value = True )
175179def test_accelerator_choice_ddp2_te (* _ ):
176180 with pytest .deprecated_call (match = r"accelerator='ddp2'\)` has been deprecated in v1.5" ):
177181 trainer = Trainer (fast_dev_run = True , accelerator = "ddp2" , gpus = 2 )
@@ -210,6 +214,7 @@ def test_accelerator_choice_ddp_cpu_te(*_):
210214@mock .patch ("torch.cuda.set_device" )
211215@mock .patch ("torch.cuda.device_count" , return_value = 1 )
212216@mock .patch ("pytorch_lightning.strategies.DDPStrategy.setup_distributed" , autospec = True )
217+ @mock .patch ("torch.cuda.is_available" , return_value = True )
213218def test_accelerator_choice_ddp_kubeflow (* _ ):
214219 with pytest .deprecated_call (match = r"accelerator='ddp'\)` has been deprecated in v1.5" ):
215220 trainer = Trainer (fast_dev_run = True , accelerator = "ddp" , gpus = 1 )
@@ -340,6 +345,10 @@ class Accel(Accelerator):
340345 def auto_device_count () -> int :
341346 return 1
342347
348+ @staticmethod
349+ def is_available () -> bool :
350+ return True
351+
343352 class Prec (PrecisionPlugin ):
344353 pass
345354
@@ -735,8 +744,11 @@ def test_strategy_choice_ddp_slurm(setup_distributed_mock, strategy):
735744@mock .patch ("torch.cuda.set_device" )
736745@mock .patch ("torch.cuda.device_count" , return_value = 2 )
737746@mock .patch ("pytorch_lightning.strategies.DDPStrategy.setup_distributed" , autospec = True )
747+ @mock .patch ("torch.cuda.is_available" , return_value = True )
738748@pytest .mark .parametrize ("strategy" , ["ddp2" , DDP2Strategy ()])
739- def test_strategy_choice_ddp2_slurm (set_device_mock , device_count_mock , setup_distributed_mock , strategy ):
749+ def test_strategy_choice_ddp2_slurm (
750+ set_device_mock , device_count_mock , setup_distributed_mock , is_available_mock , strategy
751+ ):
740752 trainer = Trainer (fast_dev_run = True , strategy = strategy , gpus = 2 )
741753 assert trainer ._accelerator_connector ._is_slurm_managing_tasks ()
742754 assert isinstance (trainer .accelerator , GPUAccelerator )
@@ -760,6 +772,7 @@ def test_strategy_choice_ddp2_slurm(set_device_mock, device_count_mock, setup_di
760772@mock .patch ("torch.cuda.set_device" )
761773@mock .patch ("torch.cuda.device_count" , return_value = 2 )
762774@mock .patch ("pytorch_lightning.strategies.DDPStrategy.setup_distributed" , autospec = True )
775+ @mock .patch ("torch.cuda.is_available" , return_value = True )
763776def test_strategy_choice_ddp_te (* _ ):
764777 trainer = Trainer (fast_dev_run = True , strategy = "ddp" , gpus = 2 )
765778 assert isinstance (trainer .accelerator , GPUAccelerator )
@@ -783,6 +796,7 @@ def test_strategy_choice_ddp_te(*_):
783796@mock .patch ("torch.cuda.set_device" )
784797@mock .patch ("torch.cuda.device_count" , return_value = 2 )
785798@mock .patch ("pytorch_lightning.strategies.DDPStrategy.setup_distributed" , autospec = True )
799+ @mock .patch ("torch.cuda.is_available" , return_value = True )
786800def test_strategy_choice_ddp2_te (* _ ):
787801 trainer = Trainer (fast_dev_run = True , strategy = "ddp2" , gpus = 2 )
788802 assert isinstance (trainer .accelerator , GPUAccelerator )
@@ -820,6 +834,7 @@ def test_strategy_choice_ddp_cpu_te(*_):
820834@mock .patch ("torch.cuda.set_device" )
821835@mock .patch ("torch.cuda.device_count" , return_value = 1 )
822836@mock .patch ("pytorch_lightning.strategies.DDPStrategy.setup_distributed" , autospec = True )
837+ @mock .patch ("torch.cuda.is_available" , return_value = True )
823838def test_strategy_choice_ddp_kubeflow (* _ ):
824839 trainer = Trainer (fast_dev_run = True , strategy = "ddp" , gpus = 1 )
825840 assert isinstance (trainer .accelerator , GPUAccelerator )
0 commit comments