@@ -102,10 +102,6 @@ def __init__(
102
102
replace_sampler_ddp : bool = True ,
103
103
deterministic : Optional [Union [bool , _LITERAL_WARN ]] = False ,
104
104
auto_select_gpus : Optional [bool ] = None , # TODO: Remove in v2.0.0
105
- num_processes : Optional [int ] = None , # TODO: Remove in v2.0.0
106
- tpu_cores : Optional [Union [List [int ], str , int ]] = None , # TODO: Remove in v2.0.0
107
- ipus : Optional [int ] = None , # TODO: Remove in v2.0.0
108
- gpus : Optional [Union [List [int ], str , int ]] = None , # TODO: Remove in v2.0.0
109
105
) -> None :
110
106
"""The AcceleratorConnector parses several Trainer arguments and instantiates the Strategy including other
111
107
components such as the Accelerator and Precision plugins.
@@ -159,7 +155,6 @@ def __init__(
159
155
160
156
# Raise an exception if there are conflicts between flags
161
157
# Set each valid flag to `self._x_flag` after validation
162
- # For devices: Assign gpus, ipus, etc. to the accelerator flag and devices flag
163
158
self ._strategy_flag : Optional [Union [Strategy , str ]] = None
164
159
self ._accelerator_flag : Optional [Union [Accelerator , str ]] = None
165
160
self ._precision_flag : _PRECISION_INPUT_STR = "32"
@@ -177,9 +172,6 @@ def __init__(
177
172
plugins = plugins ,
178
173
sync_batchnorm = sync_batchnorm ,
179
174
)
180
- self ._check_device_config_and_set_final_flags (
181
- devices = devices , num_nodes = num_nodes , num_processes = num_processes , gpus = gpus , ipus = ipus , tpu_cores = tpu_cores
182
- )
183
175
# 2. Instantiate Accelerator
184
176
self ._set_accelerator_if_ipu_strategy_is_passed ()
185
177
@@ -189,6 +181,7 @@ def __init__(
189
181
elif self ._accelerator_flag == "gpu" :
190
182
self ._accelerator_flag = self ._choose_gpu_accelerator_backend ()
191
183
184
+ self ._check_device_config_and_set_final_flags (devices = devices , num_nodes = num_nodes )
192
185
self ._set_parallel_devices_and_init_accelerator ()
193
186
194
187
# 3. Instantiate ClusterEnvironment
@@ -376,10 +369,6 @@ def _check_device_config_and_set_final_flags(
376
369
self ,
377
370
devices : Optional [Union [List [int ], str , int ]],
378
371
num_nodes : int ,
379
- num_processes : Optional [int ],
380
- gpus : Optional [Union [List [int ], str , int ]],
381
- ipus : Optional [int ],
382
- tpu_cores : Optional [Union [List [int ], str , int ]],
383
372
) -> None :
384
373
self ._num_nodes_flag = int (num_nodes ) if num_nodes is not None else 1
385
374
self ._devices_flag = devices
@@ -395,76 +384,12 @@ def _check_device_config_and_set_final_flags(
395
384
f" using { accelerator_name } accelerator."
396
385
)
397
386
398
- # TODO: Delete this method when num_processes, gpus, ipus and tpu_cores gets removed
399
- self ._map_deprecated_devices_specific_info_to_accelerator_and_device_flag (
400
- devices , num_processes , gpus , ipus , tpu_cores
401
- )
402
-
403
387
if self ._devices_flag == "auto" and self ._accelerator_flag is None :
404
388
raise MisconfigurationException (
405
389
f"You passed `devices={ devices } ` but haven't specified"
406
390
" `accelerator=('auto'|'tpu'|'gpu'|'ipu'|'cpu'|'hpu'|'mps')` for the devices mapping."
407
391
)
408
392
409
- def _map_deprecated_devices_specific_info_to_accelerator_and_device_flag (
410
- self ,
411
- devices : Optional [Union [List [int ], str , int ]],
412
- num_processes : Optional [int ],
413
- gpus : Optional [Union [List [int ], str , int ]],
414
- ipus : Optional [int ],
415
- tpu_cores : Optional [Union [List [int ], str , int ]],
416
- ) -> None :
417
- """Emit deprecation warnings for num_processes, gpus, ipus, tpu_cores and set the `devices_flag` and
418
- `accelerator_flag`."""
419
- if num_processes is not None :
420
- rank_zero_deprecation (
421
- f"Setting `Trainer(num_processes={ num_processes } )` is deprecated in v1.7 and will be removed"
422
- f" in v2.0. Please use `Trainer(accelerator='cpu', devices={ num_processes } )` instead."
423
- )
424
- if gpus is not None :
425
- rank_zero_deprecation (
426
- f"Setting `Trainer(gpus={ gpus !r} )` is deprecated in v1.7 and will be removed"
427
- f" in v2.0. Please use `Trainer(accelerator='gpu', devices={ gpus !r} )` instead."
428
- )
429
- if tpu_cores is not None :
430
- rank_zero_deprecation (
431
- f"Setting `Trainer(tpu_cores={ tpu_cores !r} )` is deprecated in v1.7 and will be removed"
432
- f" in v2.0. Please use `Trainer(accelerator='tpu', devices={ tpu_cores !r} )` instead."
433
- )
434
- if ipus is not None :
435
- rank_zero_deprecation (
436
- f"Setting `Trainer(ipus={ ipus } )` is deprecated in v1.7 and will be removed"
437
- f" in v2.0. Please use `Trainer(accelerator='ipu', devices={ ipus } )` instead."
438
- )
439
- self ._gpus : Optional [Union [List [int ], str , int ]] = gpus
440
- self ._tpu_cores : Optional [Union [List [int ], str , int ]] = tpu_cores
441
- deprecated_devices_specific_flag = num_processes or gpus or ipus or tpu_cores
442
- if deprecated_devices_specific_flag and deprecated_devices_specific_flag not in ([], 0 , "0" ):
443
- if devices :
444
- # TODO improve error message
445
- rank_zero_warn (
446
- f"The flag `devices={ devices } ` will be ignored, "
447
- f"instead the device specific number { deprecated_devices_specific_flag } will be used"
448
- )
449
-
450
- if [(num_processes is not None ), (gpus is not None ), (ipus is not None ), (tpu_cores is not None )].count (
451
- True
452
- ) > 1 :
453
- # TODO: improve error message
454
- rank_zero_warn ("more than one device specific flag has been set" )
455
- self ._devices_flag = deprecated_devices_specific_flag
456
-
457
- if self ._accelerator_flag is None :
458
- # set accelerator type based on num_processes, gpus, ipus, tpu_cores
459
- if ipus :
460
- self ._accelerator_flag = "ipu"
461
- if tpu_cores :
462
- self ._accelerator_flag = "tpu"
463
- if gpus :
464
- self ._accelerator_flag = "cuda"
465
- if num_processes :
466
- self ._accelerator_flag = "cpu"
467
-
468
393
def _set_accelerator_if_ipu_strategy_is_passed (self ) -> None :
469
394
# current logic only apply to object config
470
395
# TODO this logic should apply to both str and object config
@@ -517,12 +442,7 @@ def _set_parallel_devices_and_init_accelerator(self) -> None:
517
442
)
518
443
519
444
self ._set_devices_flag_if_auto_passed ()
520
-
521
- self ._gpus = self ._devices_flag if not self ._gpus else self ._gpus
522
- self ._tpu_cores = self ._devices_flag if not self ._tpu_cores else self ._tpu_cores
523
-
524
445
self ._set_devices_flag_if_auto_select_gpus_passed ()
525
-
526
446
self ._devices_flag = accelerator_cls .parse_devices (self ._devices_flag )
527
447
if not self ._parallel_devices :
528
448
self ._parallel_devices = accelerator_cls .get_parallel_devices (self ._devices_flag )
@@ -537,9 +457,13 @@ def _set_devices_flag_if_auto_select_gpus_passed(self) -> None:
537
457
"The Trainer argument `auto_select_gpus` has been deprecated in v1.9.0 and will be removed in v2.0.0."
538
458
" Please use the function `pytorch_lightning.accelerators.find_usable_cuda_devices` instead."
539
459
)
540
- if self ._auto_select_gpus and isinstance (self ._gpus , int ) and isinstance (self .accelerator , CUDAAccelerator ):
460
+ if (
461
+ self ._auto_select_gpus
462
+ and isinstance (self ._devices_flag , int )
463
+ and isinstance (self .accelerator , CUDAAccelerator )
464
+ ):
541
465
self ._devices_flag = pick_multiple_gpus (
542
- self ._gpus ,
466
+ self ._devices_flag ,
543
467
# we already show a deprecation message when user sets Trainer(auto_select_gpus=...)
544
468
_show_deprecation = False ,
545
469
)
0 commit comments