code: def test_to_device(self):
      sample_list = test_utils.build_random_sample_list()
  
      modified = to_device(sample_list, "cpu")
      self.assertEqual(modified.get_device(), torch.device("cpu"))
  
      modified = to_device(sample_list, torch.device("cpu"))
      self.assertEqual(modified.get_device(), torch.device("cpu"))
  
      modified = to_device(sample_list, "cuda")
  
      if torch.cuda.is_available():
          self.assertEqual(
              modified.get_device(), torch.device("cuda:0")
          )
      else:
          self.assertEqual(modified.get_device(), torch.device("cpu"))
  
      double_modified = to_device(modified, modified.get_device())
      self.assertTrue(double_modified is modified)
  
      custom_batch = [{"a": 1}]
      self.assertEqual(to_device(custom_batch), custom_batch)
  
file_path: mmf/tests/common/test_sample.py
imports: import unittest
  import tests.test_utils
  import torch
  from mmf.common.sample import convert_batch_to_sample_list, Sample, SampleList, to_device
label_desc: Use image node_id 1 for calling the TestFunctions obj's underlying member method code with example usage: obj.test_to_device() without return types