docstr: Default logic for (maybe) making all Modules within self._module DDP.
code: def _make_modules_ddp_if_necessary(self) -> None:
      """Default logic for (maybe) making all Modules within self._module DDP."""
  
      # If the module is a MultiAgentRLModule and nn.Module we can simply assume
      # all the submodules are registered. Otherwise, we need to loop through
      # each submodule and move it to the correct device.
      # TODO (Kourosh): This can result in missing modules if the user does not
      #  register them in the MultiAgentRLModule. We should find a better way to
      #  handle this.
      if self._distributed:
          # Single agent module: Convert to `TorchDDPRLModule`.
          if isinstance(self._module, TorchRLModule):
              self._module = TorchDDPRLModule(self._module)
          # Multi agent module: Convert each submodule to `TorchDDPRLModule`.
          else:
              assert isinstance(self._module, MultiAgentRLModule)
              for key in self._module.keys():
                  sub_module = self._module[key]
                  if isinstance(sub_module, TorchRLModule):
                      # Wrap and override the module ID key in self._module.
                      self._module.add_module(
                          key,
                          TorchDDPRLModule(sub_module),
                          override=True,
                      )
  
imports: import logging
  import pathlib
  from typing import Any, Callable, Dict, Hashable, Sequence, Union, Tuple
  from ray.rllib.algorithms.algorithm_config import AlgorithmConfig, TorchCompileWhatToCompile
  from ray.rllib.core.learner.learner import Learner
  from ray.rllib.core.rl_module.marl_module import MultiAgentRLModule
  from ray.rllib.core.rl_module.rl_module import RLModule, SingleAgentRLModuleSpec
  from ray.rllib.core.rl_module.torch.torch_rl_module import TorchCompileConfig, TorchDDPRLModule, TorchRLModule
  from ray.rllib.policy.sample_batch import MultiAgentBatch
  from ray.rllib.utils.annotations import override, OverrideToImplementCustomLogic
  from ray.rllib.utils.deprecation import deprecation_warning
  from ray.rllib.utils.framework import try_import_torch
  from ray.rllib.utils.metrics import ALL_MODULES
  from ray.rllib.utils.nested_dict import NestedDict
  from ray.rllib.utils.torch_utils import convert_to_torch_tensor, copy_torch_tensors
  from ray.rllib.utils.typing import ModuleID, Optimizer, Param, ParamDict, TensorType
label_desc: Use image node_id 18 for calling the TorchLearner obj's underlying member method code with example usage: obj._make_modules_ddp_if_necessary() without return types