code: def move_to_device(
      obj: Union[torch.Tensor, nn.Module, Dict, List, Tuple],
      device: torch.device,
  ):
      """
      Move an object to the given device.
  
      Parameters
      ----------
      obj
          An object, which can be a tensor, a module, a dict, or a list.
      device
          A Pytorch device instance.
  
      Returns
      -------
      The object on the device.
      """
      if not isinstance(device, torch.device):
          raise ValueError(
              f"Invalid device: {device}. Ensure the device type is `torch.device`."
          )
  
      if torch.is_tensor(obj) or isinstance(obj, nn.Module):
          return obj.to(device)
      elif isinstance(obj, dict):
          res = {}
          for k, v in obj.items():
              res[k] = move_to_device(v, device)
          return res
      elif isinstance(obj, list) or isinstance(obj, tuple):
          res = []
          for v in obj:
              res.append(move_to_device(v, device))
          return res
      elif isinstance(obj, (int, float, str)):
          return obj
      else:
          raise TypeError(
              f"Invalid type {type(obj)} for move_to_device. "
              f"Make sure the object is one of these: a Pytorch tensor, a Pytorch module, "
              f"a dict or list of tensors or modules."
          )
  
imports: import contextlib
  import logging
  import math
  import sys
  import warnings
  from typing import Dict, List, Optional, Tuple, Union
  import torch
  from lightning.pytorch.accelerators import find_usable_cuda_devices
  from torch import nn
  from autogluon.common.utils.resource_utils import ResourceManager
  from ..constants import DDP_STRATEGIES, OBJECT_DETECTION, OCR
label_desc: Use image node_id 6 for calling a global function with example usage: move_to_device(obj, device) and returns: obj, res, res, obj