code: def to_device(
      sample_list: Union[SampleList, Dict[str, Any]],
      device: device_type = "cuda",
  ) -> SampleList:
      if isinstance(sample_list, collections.abc.Mapping):
          sample_list = convert_batch_to_sample_list(sample_list)
      # to_device is specifically for SampleList
      # if user is passing something custom built
      if not isinstance(sample_list, SampleList):
          warnings.warn(
              "You are not returning SampleList/Sample from your dataset. "
              "MMF expects you to move your tensors to cuda yourself."
          )
          return sample_list
  
      if isinstance(device, str):
          device = torch.device(device)
  
      # default value of device_type is cuda
      # Other device types such as xla can also be passed.
      # Fall back to cpu only happens when device_type
      # is set to cuda but cuda is not available.
      if device.type == "cuda" and not torch.cuda.is_available():
          warnings.warn(
              "Selected device is cuda, but it is NOT available!!! Falling back on cpu."
          )
          device = torch.device("cpu")
  
      if sample_list.get_device() != device:
          sample_list = sample_list.to(device)
      return sample_list
  
imports: import collections
  import collections.abc
  import warnings
  from collections import OrderedDict
  from typing import Any, Dict, Union
  import torch
label_desc: Use image node_id 2 for calling a global function with example usage: to_device(sample_list, device) and returns: sample_list, sample_list