code: def configure_device(self) -> None:
      if self.config.training.get("device", "cuda") == "xla":
          import torch_xla.core.xla_model as xm
  
          self.device = xm.xla_device()
          self.distributed = True
          self.local_rank = xm.get_local_ordinal()
          is_xla = True
      else:
          is_xla = False
          if "device_id" not in self.config:
              warnings.warn(
                  "No 'device_id' in 'config', setting to -1. "
                  "This can cause issues later in training. Ensure that "
                  "distributed setup is properly initialized."
              )
              self.local_rank = -1
          else:
              self.local_rank = self.config.device_id
          self.device = self.local_rank
          self.distributed = False
  
      # Will be updated later based on distributed setup
      registry.register("global_device", self.device)
  
      if self.config.distributed.init_method is not None:
          self.distributed = True
          self.device = torch.device("cuda", self.local_rank)
          torch.cuda.set_device(self.local_rank)
      elif torch.cuda.is_available():
          self.device = torch.device("cuda")
          torch.cuda.set_device(0)
      elif not is_xla:
          self.device = torch.device("cpu")
  
      if "rank" not in self.config.distributed:
          if (
              torch.distributed.is_available()
              and torch.distributed.is_initialized()
          ):
              global_rank = torch.distributed.get_rank()
          else:
              global_rank = -1
          with open_dict(self.config.distributed):
              self.config.distributed.rank = global_rank
  
      registry.register("global_device", self.config.distributed.rank)
  
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 2 for calling the TrainerDeviceMixin obj's underlying member method code with example usage: obj.configure_device() without return types