code: def move_data_to_device(batch: Any, device: _DEVICE) -> Any:
      """Transfers a collection of data to the given device. Any object that defines a method ``to(device)`` will be
      moved and all other objects in the collection will be left untouched.
  
      Args:
          batch: A tensor or collection of tensors or anything that has a method ``.to(...)``.
              See :func:`apply_to_collection` for a list of supported collection types.
          device: The device to which the data should be moved
  
      Return:
          the same collection but with all contained tensors residing on the new device.
  
      See Also:
          - :meth:`torch.Tensor.to`
          - :class:`torch.device`
  
      """
      if isinstance(device, str):
          device = torch.device(device)
  
      def batch_to(data: Any) -> Any:
          kwargs = {}
          # Don't issue non-blocking transfers to CPU
          # Same with MPS due to a race condition bug: https://github.com/pytorch/pytorch/issues/83015
          if (
              isinstance(data, Tensor)
              and isinstance(device, torch.device)
              and device.type not in _BLOCKING_DEVICE_TYPES
          ):
              kwargs["non_blocking"] = True
          data_output = data.to(device, **kwargs)
          if data_output is not None:
              return data_output
          # user wrongly implemented the `_TransferableDataType` and forgot to return `self`.
          return data
  
      return apply_to_collection(
          batch, dtype=_TransferableDataType, function=batch_to
      )
  
file_path: pytorch-lightning/src/lightning/fabric/utilities/apply_func.py
imports: from abc import ABC
  from functools import partial
  from typing import Any, Callable, List, Tuple, Union
  import numpy
  import torch
  from lightning_utilities.core.apply_func import apply_to_collection
  from torch import Tensor
  from lightning.fabric.utilities.types import _DEVICE
label_desc: Use image node_id 2 for calling a global function with example usage: move_data_to_device(batch, device) and returns: apply_to_collection, data, data_output