@@ -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
@@ -175,9 +170,6 @@ def __init__(
175
170
plugins = plugins ,
176
171
sync_batchnorm = sync_batchnorm ,
177
172
)
178
- self ._check_device_config_and_set_final_flags (
179
- devices = devices , num_nodes = num_nodes , num_processes = num_processes , gpus = gpus , ipus = ipus , tpu_cores = tpu_cores
180
- )
181
173
# 2. Instantiate Accelerator
182
174
self ._set_accelerator_if_ipu_strategy_is_passed ()
183
175
@@ -187,6 +179,7 @@ def __init__(
187
179
elif self ._accelerator_flag == "gpu" :
188
180
self ._accelerator_flag = self ._choose_gpu_accelerator_backend ()
189
181
182
+ self ._check_device_config_and_set_final_flags (devices = devices , num_nodes = num_nodes )
190
183
self ._set_parallel_devices_and_init_accelerator ()
191
184
192
185
# 3. Instantiate ClusterEnvironment
@@ -360,10 +353,6 @@ def _check_device_config_and_set_final_flags(
360
353
self ,
361
354
devices : Optional [Union [List [int ], str , int ]],
362
355
num_nodes : int ,
363
- num_processes : Optional [int ],
364
- gpus : Optional [Union [List [int ], str , int ]],
365
- ipus : Optional [int ],
366
- tpu_cores : Optional [Union [List [int ], str , int ]],
367
356
) -> None :
368
357
self ._num_nodes_flag = int (num_nodes ) if num_nodes is not None else 1
369
358
self ._devices_flag = devices
@@ -379,76 +368,12 @@ def _check_device_config_and_set_final_flags(
379
368
f" using { accelerator_name } accelerator."
380
369
)
381
370
382
- # TODO: Delete this method when num_processes, gpus, ipus and tpu_cores gets removed
383
- self ._map_deprecated_devices_specific_info_to_accelerator_and_device_flag (
384
- devices , num_processes , gpus , ipus , tpu_cores
385
- )
386
-
387
371
if self ._devices_flag == "auto" and self ._accelerator_flag is None :
388
372
raise MisconfigurationException (
389
373
f"You passed `devices={ devices } ` but haven't specified"
390
374
" `accelerator=('auto'|'tpu'|'gpu'|'ipu'|'cpu'|'hpu'|'mps')` for the devices mapping."
391
375
)
392
376
393
- def _map_deprecated_devices_specific_info_to_accelerator_and_device_flag (
394
- self ,
395
- devices : Optional [Union [List [int ], str , int ]],
396
- num_processes : Optional [int ],
397
- gpus : Optional [Union [List [int ], str , int ]],
398
- ipus : Optional [int ],
399
- tpu_cores : Optional [Union [List [int ], str , int ]],
400
- ) -> None :
401
- """Emit deprecation warnings for num_processes, gpus, ipus, tpu_cores and set the `devices_flag` and
402
- `accelerator_flag`."""
403
- if num_processes is not None :
404
- rank_zero_deprecation (
405
- f"Setting `Trainer(num_processes={ num_processes } )` is deprecated in v1.7 and will be removed"
406
- f" in v2.0. Please use `Trainer(accelerator='cpu', devices={ num_processes } )` instead."
407
- )
408
- if gpus is not None :
409
- rank_zero_deprecation (
410
- f"Setting `Trainer(gpus={ gpus !r} )` is deprecated in v1.7 and will be removed"
411
- f" in v2.0. Please use `Trainer(accelerator='gpu', devices={ gpus !r} )` instead."
412
- )
413
- if tpu_cores is not None :
414
- rank_zero_deprecation (
415
- f"Setting `Trainer(tpu_cores={ tpu_cores !r} )` is deprecated in v1.7 and will be removed"
416
- f" in v2.0. Please use `Trainer(accelerator='tpu', devices={ tpu_cores !r} )` instead."
417
- )
418
- if ipus is not None :
419
- rank_zero_deprecation (
420
- f"Setting `Trainer(ipus={ ipus } )` is deprecated in v1.7 and will be removed"
421
- f" in v2.0. Please use `Trainer(accelerator='ipu', devices={ ipus } )` instead."
422
- )
423
- self ._gpus : Optional [Union [List [int ], str , int ]] = gpus
424
- self ._tpu_cores : Optional [Union [List [int ], str , int ]] = tpu_cores
425
- deprecated_devices_specific_flag = num_processes or gpus or ipus or tpu_cores
426
- if deprecated_devices_specific_flag and deprecated_devices_specific_flag not in ([], 0 , "0" ):
427
- if devices :
428
- # TODO improve error message
429
- rank_zero_warn (
430
- f"The flag `devices={ devices } ` will be ignored, "
431
- f"instead the device specific number { deprecated_devices_specific_flag } will be used"
432
- )
433
-
434
- if [(num_processes is not None ), (gpus is not None ), (ipus is not None ), (tpu_cores is not None )].count (
435
- True
436
- ) > 1 :
437
- # TODO: improve error message
438
- rank_zero_warn ("more than one device specific flag has been set" )
439
- self ._devices_flag = deprecated_devices_specific_flag
440
-
441
- if self ._accelerator_flag is None :
442
- # set accelerator type based on num_processes, gpus, ipus, tpu_cores
443
- if ipus :
444
- self ._accelerator_flag = "ipu"
445
- if tpu_cores :
446
- self ._accelerator_flag = "tpu"
447
- if gpus :
448
- self ._accelerator_flag = "cuda"
449
- if num_processes :
450
- self ._accelerator_flag = "cpu"
451
-
452
377
def _set_accelerator_if_ipu_strategy_is_passed (self ) -> None :
453
378
# current logic only apply to object config
454
379
# TODO this logic should apply to both str and object config
@@ -501,12 +426,7 @@ def _set_parallel_devices_and_init_accelerator(self) -> None:
501
426
)
502
427
503
428
self ._set_devices_flag_if_auto_passed ()
504
-
505
- self ._gpus = self ._devices_flag if not self ._gpus else self ._gpus
506
- self ._tpu_cores = self ._devices_flag if not self ._tpu_cores else self ._tpu_cores
507
-
508
429
self ._set_devices_flag_if_auto_select_gpus_passed ()
509
-
510
430
self ._devices_flag = accelerator_cls .parse_devices (self ._devices_flag )
511
431
if not self ._parallel_devices :
512
432
self ._parallel_devices = accelerator_cls .get_parallel_devices (self ._devices_flag )
@@ -521,9 +441,13 @@ def _set_devices_flag_if_auto_select_gpus_passed(self) -> None:
521
441
"The Trainer argument `auto_select_gpus` has been deprecated in v1.9.0 and will be removed in v1.10.0."
522
442
" Please use the function `pytorch_lightning.accelerators.find_usable_cuda_devices` instead."
523
443
)
524
- if self ._auto_select_gpus and isinstance (self ._gpus , int ) and isinstance (self .accelerator , CUDAAccelerator ):
444
+ if (
445
+ self ._auto_select_gpus
446
+ and isinstance (self ._devices_flag , int )
447
+ and isinstance (self .accelerator , CUDAAccelerator )
448
+ ):
525
449
self ._devices_flag = pick_multiple_gpus (
526
- self ._gpus ,
450
+ self ._devices_flag ,
527
451
# we already show a deprecation message when user sets Trainer(auto_select_gpus=...)
528
452
_show_deprecation = False ,
529
453
)
0 commit comments