code: def test_single_gpu_batch_parse():
      trainer = Trainer(accelerator="mps", devices=1)
  
      # non-transferrable types
      primitive_objects = [
          None,
          {},
          [],
          1.0,
          "x",
          [None, 2],
          {"x": (1, 2), "y": None},
      ]
      for batch in primitive_objects:
          data = trainer.strategy.batch_to_device(
              batch, torch.device("mps")
          )
          assert data == batch
  
      # batch is just a tensor
      batch = torch.rand(2, 3)
      batch = trainer.strategy.batch_to_device(
          batch, torch.device("mps")
      )
      assert batch.device.index == 0
      assert batch.type() == "torch.mps.FloatTensor"
  
      # tensor list
      batch = [torch.rand(2, 3), torch.rand(2, 3)]
      batch = trainer.strategy.batch_to_device(
          batch, torch.device("mps")
      )
      assert batch[0].device.index == 0
      assert batch[0].type() == "torch.mps.FloatTensor"
      assert batch[1].device.index == 0
      assert batch[1].type() == "torch.mps.FloatTensor"
  
      # tensor list of lists
      batch = [[torch.rand(2, 3), torch.rand(2, 3)]]
      batch = trainer.strategy.batch_to_device(
          batch, torch.device("mps")
      )
      assert batch[0][0].device.index == 0
      assert batch[0][0].type() == "torch.mps.FloatTensor"
      assert batch[0][1].device.index == 0
      assert batch[0][1].type() == "torch.mps.FloatTensor"
  
      # tensor dict
      batch = [{"a": torch.rand(2, 3), "b": torch.rand(2, 3)}]
      batch = trainer.strategy.batch_to_device(
          batch, torch.device("mps")
      )
      assert batch[0]["a"].device.index == 0
      assert batch[0]["a"].type() == "torch.mps.FloatTensor"
      assert batch[0]["b"].device.index == 0
      assert batch[0]["b"].type() == "torch.mps.FloatTensor"
  
      # tuple of tensor list and list of tensor dict
      batch = (
          [torch.rand(2, 3) for _ in range(2)],
          [
              {"a": torch.rand(2, 3), "b": torch.rand(2, 3)}
              for _ in range(2)
          ],
      )
      batch = trainer.strategy.batch_to_device(
          batch, torch.device("mps")
      )
      assert batch[0][0].device.index == 0
      assert batch[0][0].type() == "torch.mps.FloatTensor"
  
      assert batch[1][0]["a"].device.index == 0
      assert batch[1][0]["a"].type() == "torch.mps.FloatTensor"
  
      assert batch[1][0]["b"].device.index == 0
      assert batch[1][0]["b"].type() == "torch.mps.FloatTensor"
  
      # namedtuple of tensor
      BatchType = namedtuple("BatchType", ["a", "b"])
      batch = [
          BatchType(a=torch.rand(2, 3), b=torch.rand(2, 3))
          for _ in range(2)
      ]
      batch = trainer.strategy.batch_to_device(
          batch, torch.device("mps")
      )
      assert batch[0].a.device.index == 0
      assert batch[0].a.type() == "torch.mps.FloatTensor"
  
      # non-Tensor that has `.to()` defined
      class CustomBatchType:
          def __init__(self):
              self.a = torch.rand(2, 2)
  
          def to(self, *args, **kwargs):
              self.a = self.a.to(*args, **kwargs)
              return self
  
      batch = trainer.strategy.batch_to_device(
          CustomBatchType(), torch.device("mps")
      )
      assert batch.a.type() == "torch.mps.FloatTensor"
  
file_path: pytorch-lightning/tests/tests_pytorch/accelerators/test_mps.py
imports: from collections import namedtuple
  import pytest
  import torch
  from lightning.pytorch import Trainer
  from lightning.pytorch.accelerators import MPSAccelerator
  from lightning.pytorch.demos.boring_classes import BoringModel
  import tests_pytorch.helpers.pipelines
  from tests_pytorch.helpers.runif import RunIf
label_desc: Use image node_id 6 for calling a global function with example usage: test_single_gpu_batch_parse() and returns: self