Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RemoveAcceleratorConnector.parallel_device_ids and deprecate Trainer.data_parallel_device_ids #12051

Closed
DuYicong515 opened this issue Feb 22, 2022 · 1 comment · Fixed by #12072
Labels
deprecation Includes a deprecation refactor

Comments

@DuYicong515
Copy link
Contributor

DuYicong515 commented Feb 22, 2022

Proposed refactor

Remove the property AcceleratorConnector.parallel_device_ids and migrate its usage
https://github.com/PyTorchLightning/pytorch-lightning/blob/550d3a640d1bfeb731a16b2996d3160f0f7eb071/pytorch_lightning/trainer/connectors/accelerator_connector.py#L830-L832

Deprecate the property Trainer.parallel_device_ids
https://github.com/PyTorchLightning/pytorch-lightning/blob/550d3a640d1bfeb731a16b2996d3160f0f7eb071/pytorch_lightning/trainer/trainer.py#L2043-L2047

Alternative

parallel_device_ids are meant to return GPU device indexes. You can use the logic below

if isinstance(Trainer.accelerator, GPUAccelerator):
  if isinstance(Trainer.strategy, ParallelStrategy):
    return [device.index for device in Trainer.strategy.parallel_devices]
  elif isinstance(Trainer.strategy, SingleDeviceStrategy):
    return [0]
return []

Motivation

Part of the follow ups in #11449 are to deprecate unused properties in accelerator_connector.
The accelerator properties are not meant to be public, migrated its internal usage. The only internal usage in logger_connector is planned to remove in v1.6.
https://github.com/PyTorchLightning/pytorch-lightning/blob/bc191af178474eccdd912059f728cb4db22dd0d8/pytorch_lightning/trainer/connectors/logger_connector/logger_connector.py#L226

The Trainer.data_parallel_device_ids were also deprecated in favor of getting the GPU device indexes from Trainer.strategy.parallel_devices directly. The only Internal usage is planned to remove in v1.6, other usages are in tests.

https://github.com/PyTorchLightning/pytorch-lightning/blob/bc191af178474eccdd912059f728cb4db22dd0d8/pytorch_lightning/callbacks/gpu_stats_monitor.py#L136

Pitch

https://github.com/PyTorchLightning/pytorch-lightning/blob/550d3a640d1bfeb731a16b2996d3160f0f7eb071/pytorch_lightning/trainer/trainer.py#L2043-L2047

@property
def data_parallel_device_ids(self) -> Optional[List[int]]:
    rank_zero_deprecation(
            "The `Trainer.data_parallel_device_ids` is deprecated in v1.6."
    )
    if not isinstance(self.accelerator, GPUAccelerator):
        return None
    if isinstance(self.strategy, ParallelStrategy):
        return [i for i in range(len(self.strategy.parallel_devices))]
    elif isinstance(self.strategy, SingleDeviceStrategy):
        return [0] 
    return None

https://github.com/PyTorchLightning/pytorch-lightning/blob/4c4b9d540f065c41ad288a78110cecbf45b96409/pytorch_lightning/trainer/connectors/logger_connector/logger_connector.py#L226

parallel_device_ids = []
if isinstance(self.trainer.accelerator, GPUAccelerator):
    if isinstance(self.trainer.strategy, ParallelStrategy):
        parallel_device_ids = [i for i in range(len(self.trainer.strategy.parallel_devices))]
    elif isinstance(self.strategy, SingleDeviceStrategy):
       parallel_device_ids = [0]
 if gpu_id in parallel_device_ids:

cc @justusschock @awaelchli @rohitgr7 @tchaton @akihironitta

@DuYicong515
Copy link
Contributor Author

cc @four4fish

@DuYicong515 DuYicong515 changed the title Deprecate AcceleratorConnector.parallel_device_ids And Trainer.parallel_device_ids RemoveAcceleratorConnector.parallel_device_ids and deprecate Trainer.parallel_device_ids Feb 22, 2022
@DuYicong515 DuYicong515 changed the title RemoveAcceleratorConnector.parallel_device_ids and deprecate Trainer.parallel_device_ids RemoveAcceleratorConnector.parallel_device_ids and deprecate Trainer.data_parallel_device_ids Feb 22, 2022
@ananthsub ananthsub added the deprecation Includes a deprecation label Feb 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deprecation Includes a deprecation refactor
Projects
None yet
2 participants