@@ -99,10 +99,6 @@ def __init__(
99
99
replace_sampler_ddp : bool = True ,
100
100
deterministic : Optional [Union [bool , _LITERAL_WARN ]] = False ,
101
101
auto_select_gpus : Optional [bool ] = None , # TODO: Remove in v1.10.0
102
- num_processes : Optional [int ] = None , # deprecated
103
- tpu_cores : Optional [Union [List [int ], str , int ]] = None , # deprecated
104
- ipus : Optional [int ] = None , # deprecated
105
- gpus : Optional [Union [List [int ], str , int ]] = None , # deprecated
106
102
) -> None :
107
103
"""The AcceleratorConnector parses several Trainer arguments and instantiates the Strategy including other
108
104
components such as the Accelerator and Precision plugins.
@@ -157,7 +153,6 @@ def __init__(
157
153
158
154
# Raise an exception if there are conflicts between flags
159
155
# Set each valid flag to `self._x_flag` after validation
160
- # For devices: Assign gpus, ipus, etc. to the accelerator flag and devices flag
161
156
self ._strategy_flag : Optional [Union [Strategy , str ]] = None
162
157
self ._accelerator_flag : Optional [Union [Accelerator , str ]] = None
163
158
self ._precision_flag : Optional [Union [int , str ]] = None
@@ -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
@@ -362,10 +355,6 @@ def _check_device_config_and_set_final_flags(
362
355
self ,
363
356
devices : Optional [Union [List [int ], str , int ]],
364
357
num_nodes : int ,
365
- num_processes : Optional [int ],
366
- gpus : Optional [Union [List [int ], str , int ]],
367
- ipus : Optional [int ],
368
- tpu_cores : Optional [Union [List [int ], str , int ]],
369
358
) -> None :
370
359
self ._num_nodes_flag = int (num_nodes ) if num_nodes is not None else 1
371
360
self ._devices_flag = devices
@@ -381,76 +370,12 @@ def _check_device_config_and_set_final_flags(
381
370
f" using { accelerator_name } accelerator."
382
371
)
383
372
384
- # TODO: Delete this method when num_processes, gpus, ipus and tpu_cores gets removed
385
- self ._map_deprecated_devices_specific_info_to_accelerator_and_device_flag (
386
- devices , num_processes , gpus , ipus , tpu_cores
387
- )
388
-
389
373
if self ._devices_flag == "auto" and self ._accelerator_flag is None :
390
374
raise MisconfigurationException (
391
375
f"You passed `devices={ devices } ` but haven't specified"
392
376
" `accelerator=('auto'|'tpu'|'gpu'|'ipu'|'cpu'|'hpu'|'mps')` for the devices mapping."
393
377
)
394
378
395
- def _map_deprecated_devices_specific_info_to_accelerator_and_device_flag (
396
- self ,
397
- devices : Optional [Union [List [int ], str , int ]],
398
- num_processes : Optional [int ],
399
- gpus : Optional [Union [List [int ], str , int ]],
400
- ipus : Optional [int ],
401
- tpu_cores : Optional [Union [List [int ], str , int ]],
402
- ) -> None :
403
- """Emit deprecation warnings for num_processes, gpus, ipus, tpu_cores and set the `devices_flag` and
404
- `accelerator_flag`."""
405
- if num_processes is not None :
406
- rank_zero_deprecation (
407
- f"Setting `Trainer(num_processes={ num_processes } )` is deprecated in v1.7 and will be removed"
408
- f" in v2.0. Please use `Trainer(accelerator='cpu', devices={ num_processes } )` instead."
409
- )
410
- if gpus is not None :
411
- rank_zero_deprecation (
412
- f"Setting `Trainer(gpus={ gpus !r} )` is deprecated in v1.7 and will be removed"
413
- f" in v2.0. Please use `Trainer(accelerator='gpu', devices={ gpus !r} )` instead."
414
- )
415
- if tpu_cores is not None :
416
- rank_zero_deprecation (
417
- f"Setting `Trainer(tpu_cores={ tpu_cores !r} )` is deprecated in v1.7 and will be removed"
418
- f" in v2.0. Please use `Trainer(accelerator='tpu', devices={ tpu_cores !r} )` instead."
419
- )
420
- if ipus is not None :
421
- rank_zero_deprecation (
422
- f"Setting `Trainer(ipus={ ipus } )` is deprecated in v1.7 and will be removed"
423
- f" in v2.0. Please use `Trainer(accelerator='ipu', devices={ ipus } )` instead."
424
- )
425
- self ._gpus : Optional [Union [List [int ], str , int ]] = gpus
426
- self ._tpu_cores : Optional [Union [List [int ], str , int ]] = tpu_cores
427
- deprecated_devices_specific_flag = num_processes or gpus or ipus or tpu_cores
428
- if deprecated_devices_specific_flag and deprecated_devices_specific_flag not in ([], 0 , "0" ):
429
- if devices :
430
- # TODO improve error message
431
- rank_zero_warn (
432
- f"The flag `devices={ devices } ` will be ignored, "
433
- f"instead the device specific number { deprecated_devices_specific_flag } will be used"
434
- )
435
-
436
- if [(num_processes is not None ), (gpus is not None ), (ipus is not None ), (tpu_cores is not None )].count (
437
- True
438
- ) > 1 :
439
- # TODO: improve error message
440
- rank_zero_warn ("more than one device specific flag has been set" )
441
- self ._devices_flag = deprecated_devices_specific_flag
442
-
443
- if self ._accelerator_flag is None :
444
- # set accelerator type based on num_processes, gpus, ipus, tpu_cores
445
- if ipus :
446
- self ._accelerator_flag = "ipu"
447
- if tpu_cores :
448
- self ._accelerator_flag = "tpu"
449
- if gpus :
450
- self ._accelerator_flag = "cuda"
451
- if num_processes :
452
- self ._accelerator_flag = "cpu"
453
-
454
379
def _set_accelerator_if_ipu_strategy_is_passed (self ) -> None :
455
380
# current logic only apply to object config
456
381
# TODO this logic should apply to both str and object config
@@ -503,12 +428,7 @@ def _set_parallel_devices_and_init_accelerator(self) -> None:
503
428
)
504
429
505
430
self ._set_devices_flag_if_auto_passed ()
506
-
507
- self ._gpus = self ._devices_flag if not self ._gpus else self ._gpus
508
- self ._tpu_cores = self ._devices_flag if not self ._tpu_cores else self ._tpu_cores
509
-
510
431
self ._set_devices_flag_if_auto_select_gpus_passed ()
511
-
512
432
self ._devices_flag = accelerator_cls .parse_devices (self ._devices_flag )
513
433
if not self ._parallel_devices :
514
434
self ._parallel_devices = accelerator_cls .get_parallel_devices (self ._devices_flag )
@@ -523,9 +443,13 @@ def _set_devices_flag_if_auto_select_gpus_passed(self) -> None:
523
443
"The Trainer argument `auto_select_gpus` has been deprecated in v1.9.0 and will be removed in v1.10.0."
524
444
" Please use the function `pytorch_lightning.accelerators.find_usable_cuda_devices` instead."
525
445
)
526
- if self ._auto_select_gpus and isinstance (self ._gpus , int ) and isinstance (self .accelerator , CUDAAccelerator ):
446
+ if (
447
+ self ._auto_select_gpus
448
+ and isinstance (self ._devices_flag , int )
449
+ and isinstance (self .accelerator , CUDAAccelerator )
450
+ ):
527
451
self ._devices_flag = pick_multiple_gpus (
528
- self ._gpus ,
452
+ self ._devices_flag ,
529
453
# we already show a deprecation message when user sets Trainer(auto_select_gpus=...)
530
454
_show_deprecation = False ,
531
455
)
0 commit comments