@@ -56,11 +56,11 @@ def test_accelerator_choice_cpu(tmpdir):
56
56
assert isinstance (trainer .strategy , SingleDeviceStrategy )
57
57
58
58
59
- @pytest .mark .parametrize (("num_processes " , "num_nodes" ), ([(1 , 1 ), (1 , 2 ), (2 , 1 ), (2 , 2 )]))
60
- def test_accelerator_choice_ddp_cpu (tmpdir , num_processes : int , num_nodes : int ):
61
- trainer = Trainer (fast_dev_run = True , accelerator = "ddp_cpu" , num_processes = num_processes , num_nodes = num_nodes )
59
+ @pytest .mark .parametrize (("devices " , "num_nodes" ), ([(1 , 1 ), (1 , 2 ), (2 , 1 ), (2 , 2 )]))
60
+ def test_accelerator_choice_ddp_cpu (tmpdir , devices : int , num_nodes : int ):
61
+ trainer = Trainer (fast_dev_run = True , accelerator = "ddp_cpu" , devices = devices , num_nodes = num_nodes )
62
62
assert isinstance (trainer .accelerator , CPUAccelerator )
63
- no_spawn = num_processes == 1 and num_nodes > 1
63
+ no_spawn = devices == 1 and num_nodes > 1
64
64
assert isinstance (trainer .strategy , DDPStrategy if no_spawn else DDPSpawnStrategy )
65
65
assert isinstance (trainer .strategy .cluster_environment , LightningEnvironment )
66
66
@@ -205,7 +205,7 @@ def test_accelerator_choice_ddp2_te(*_):
205
205
@mock .patch ("torch.cuda.device_count" , return_value = 0 )
206
206
@mock .patch ("pytorch_lightning.strategies.DDPStrategy.setup_distributed" , autospec = True )
207
207
def test_accelerator_choice_ddp_cpu_te (* _ ):
208
- trainer = Trainer (fast_dev_run = True , accelerator = "ddp_cpu" , num_processes = 2 )
208
+ trainer = Trainer (fast_dev_run = True , accelerator = "ddp_cpu" , devices = 2 )
209
209
assert isinstance (trainer .accelerator , CPUAccelerator )
210
210
assert isinstance (trainer .strategy , DDPStrategy )
211
211
assert isinstance (trainer .strategy .cluster_environment , TorchElasticEnvironment )
@@ -251,7 +251,7 @@ def test_accelerator_choice_ddp_kubeflow(*_):
251
251
@mock .patch ("torch.cuda.device_count" , return_value = 0 )
252
252
@mock .patch ("pytorch_lightning.strategies.DDPStrategy.setup_distributed" , autospec = True )
253
253
def test_accelerator_choice_ddp_cpu_kubeflow (* _ ):
254
- trainer = Trainer (fast_dev_run = True , accelerator = "ddp_cpu" , num_processes = 1 )
254
+ trainer = Trainer (fast_dev_run = True , accelerator = "ddp_cpu" , devices = 1 )
255
255
assert isinstance (trainer .accelerator , CPUAccelerator )
256
256
assert isinstance (trainer .strategy , DDPStrategy )
257
257
assert isinstance (trainer .strategy .cluster_environment , KubeflowEnvironment )
@@ -273,7 +273,7 @@ def test_accelerator_choice_ddp_cpu_kubeflow(*_):
273
273
@mock .patch ("torch.cuda.device_count" , return_value = 0 )
274
274
@mock .patch ("pytorch_lightning.strategies.DDPStrategy.setup_distributed" , autospec = True )
275
275
def test_accelerator_choice_ddp_cpu_slurm (* _ ):
276
- trainer = Trainer (fast_dev_run = True , accelerator = "ddp_cpu" , num_processes = 2 )
276
+ trainer = Trainer (fast_dev_run = True , accelerator = "ddp_cpu" , devices = 2 )
277
277
assert trainer ._accelerator_connector ._is_slurm_managing_tasks ()
278
278
assert isinstance (trainer .accelerator , CPUAccelerator )
279
279
assert isinstance (trainer .strategy , DDPStrategy )
@@ -299,7 +299,7 @@ def _test_accelerator_choice_ddp_cpu_and_strategy(tmpdir, ddp_strategy_class):
299
299
strategy = ddp_strategy_class (find_unused_parameters = True ),
300
300
fast_dev_run = True ,
301
301
accelerator = "ddp_cpu" ,
302
- num_processes = 2 ,
302
+ devices = 2 ,
303
303
)
304
304
assert isinstance (trainer .strategy , ddp_strategy_class )
305
305
assert isinstance (trainer .accelerator , CPUAccelerator )
@@ -332,7 +332,7 @@ def creates_processes_externally(self) -> bool:
332
332
return True
333
333
334
334
trainer = Trainer (
335
- default_root_dir = tmpdir , plugins = [CustomCluster ()], fast_dev_run = True , accelerator = "ddp_cpu" , num_processes = 2
335
+ default_root_dir = tmpdir , plugins = [CustomCluster ()], fast_dev_run = True , accelerator = "ddp_cpu" , devices = 2
336
336
)
337
337
assert isinstance (trainer .accelerator , CPUAccelerator )
338
338
assert isinstance (trainer .strategy , DDPStrategy )
@@ -381,7 +381,7 @@ class Strat(SingleDeviceStrategy):
381
381
pass
382
382
383
383
strategy = Strat (device = torch .device ("cpu" ), accelerator = Accel (), precision_plugin = Prec ())
384
- trainer = Trainer (strategy = strategy , fast_dev_run = True , num_processes = 2 )
384
+ trainer = Trainer (strategy = strategy , fast_dev_run = True , devices = 2 )
385
385
assert isinstance (trainer .accelerator , Accel )
386
386
assert isinstance (trainer .strategy , Strat )
387
387
assert isinstance (trainer .precision_plugin , Prec )
@@ -391,7 +391,7 @@ class Strat(DDPStrategy):
391
391
pass
392
392
393
393
strategy = Strat (accelerator = Accel (), precision_plugin = Prec ())
394
- trainer = Trainer (strategy = strategy , fast_dev_run = True , num_processes = 2 )
394
+ trainer = Trainer (strategy = strategy , fast_dev_run = True , devices = 2 )
395
395
assert isinstance (trainer .accelerator , Accel )
396
396
assert isinstance (trainer .strategy , Strat )
397
397
assert isinstance (trainer .precision_plugin , Prec )
@@ -422,16 +422,16 @@ def test_dist_backend_accelerator_mapping(*_):
422
422
def test_ipython_incompatible_backend_error (_ , monkeypatch ):
423
423
monkeypatch .setattr (pytorch_lightning .utilities , "_IS_INTERACTIVE" , True )
424
424
with pytest .raises (MisconfigurationException , match = r"strategy='ddp'\)`.*is not compatible" ):
425
- Trainer (strategy = "ddp" , gpus = 2 )
425
+ Trainer (strategy = "ddp" , accelerator = "gpu" , devices = 2 )
426
426
427
427
with pytest .raises (MisconfigurationException , match = r"strategy='ddp2'\)`.*is not compatible" ):
428
- Trainer (strategy = "ddp2" , gpus = 2 )
428
+ Trainer (strategy = "ddp2" , accelerator = "gpu" , devices = 2 )
429
429
430
430
with pytest .raises (MisconfigurationException , match = r"strategy='ddp_spawn'\)`.*is not compatible" ):
431
- Trainer (strategy = "ddp_spawn" )
431
+ Trainer (strategy = "ddp_spawn" , accelerator = "gpu" , devices = 2 )
432
432
433
433
with pytest .raises (MisconfigurationException , match = r"strategy='ddp_sharded_spawn'\)`.*is not compatible" ):
434
- Trainer (strategy = "ddp_sharded_spawn" )
434
+ Trainer (strategy = "ddp_sharded_spawn" , accelerator = "gpu" , devices = 2 )
435
435
436
436
with pytest .raises (MisconfigurationException , match = r"strategy='ddp'\)`.*is not compatible" ):
437
437
# Edge case: AcceleratorConnector maps dp to ddp if accelerator != gpu
@@ -517,13 +517,13 @@ def test_passing_zero_and_empty_list_to_devices_flag(_, devices):
517
517
518
518
@RunIf (min_gpus = 1 )
519
519
def test_accelerator_gpu ():
520
- trainer = Trainer (accelerator = "gpu" , gpus = 1 )
520
+ trainer = Trainer (accelerator = "gpu" , devices = 1 )
521
521
assert isinstance (trainer .accelerator , GPUAccelerator )
522
522
523
523
trainer = Trainer (accelerator = "gpu" )
524
524
assert isinstance (trainer .accelerator , GPUAccelerator )
525
525
526
- trainer = Trainer (accelerator = "auto" , gpus = 1 )
526
+ trainer = Trainer (accelerator = "auto" , devices = 1 )
527
527
assert isinstance (trainer .accelerator , GPUAccelerator )
528
528
529
529
@@ -750,7 +750,7 @@ def test_strategy_choice_ddp_slurm(setup_distributed_mock, strategy):
750
750
def test_strategy_choice_ddp2_slurm (
751
751
set_device_mock , device_count_mock , setup_distributed_mock , is_available_mock , strategy
752
752
):
753
- trainer = Trainer (fast_dev_run = True , strategy = strategy , gpus = 2 )
753
+ trainer = Trainer (fast_dev_run = True , strategy = strategy , accelerator = "gpu" , devices = 2 )
754
754
assert trainer ._accelerator_connector ._is_slurm_managing_tasks ()
755
755
assert isinstance (trainer .accelerator , GPUAccelerator )
756
756
assert isinstance (trainer .strategy , DDP2Strategy )
0 commit comments