code: def parallelize_model(self) -> None:
      registry.register("data_parallel", False)
      registry.register("distributed", False)
      if (
          "cuda" in str(self.device)
          and torch.cuda.device_count() > 1
          and not self.distributed
      ):
          registry.register("data_parallel", True)
          self.model = torch.nn.DataParallel(self.model)
  
      if "cuda" in str(self.device) and self.distributed:
          registry.register("distributed", True)
          set_torch_ddp = True
          try:
              from fairscale.nn.data_parallel import ShardedDataParallel
              from fairscale.optim.oss import OSS
  
              if isinstance(self.optimizer, OSS):
                  self.model = ShardedDataParallel(
                      self.model, self.optimizer
                  )
                  set_torch_ddp = False
                  logger.info("Using FairScale ShardedDataParallel")
          except ImportError:
              logger.info("Using PyTorch DistributedDataParallel")
              warnings.warn(
                  "You can enable ZeRO and Sharded DDP, by installing fairscale "
                  + "and setting optimizer.enable_state_sharding=True."
              )
  
          if set_torch_ddp:
              self.model = torch.nn.parallel.DistributedDataParallel(
                  self.model,
                  device_ids=[self.local_rank],
                  output_device=self.local_rank,
                  find_unused_parameters=self.config.training.find_unused_parameters,
              )
  
      if is_xla() and get_world_size() > 1:
          broadcast_xla_master_model_param(self.model)
  
file_path: mmf/mmf/trainers/core/device.py
imports: import logging
  import warnings
  from abc import ABC
  import torch
  from mmf.common.registry import registry
  from mmf.utils.distributed import broadcast_xla_master_model_param, get_world_size, is_xla
  from omegaconf import open_dict
label_desc: Use image node_id 3 for calling the TrainerDeviceMixin obj's underlying member method code with example usage: obj.parallelize_model() without return types