code: def torch_move_data_to_device(
      batch: Any,
      device: Optional[Union[str, "torch.device"]] = None,
      non_blocking: Optional[bool] = True,
  ) -> Any:
      r"""
      在 **pytorch** 中将数据集合 ``batch`` 传输到给定设备。任何定义方法 ``to(device)`` 的对象都将被移动并且集合中的所有其他对象将保持不变；
  
      :param batch: 需要迁移的数据；
      :param device: 数据应当迁移到的设备；当该参数的值为 ``None`` 时则不执行任何操作；
      :param non_blocking: **pytorch** 的数据迁移方法 ``to`` 的参数；
      :return: 迁移到新设备上的数据集合；
      """
      if device is None:
          return batch
  
      def batch_to(data: Any) -> Any:
          kwargs = (
              dict(non_blocking=non_blocking)
              if isinstance(data, torch.Tensor)
              else {}
          )
          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
  
      dtype = TorchTransferableDataType
      return apply_to_collection(batch, dtype=dtype, function=batch_to)
  
file_path: fastNLP/fastNLP/core/utils/torch_utils.py
imports: from abc import ABC
  from typing import Any, Union, Optional
  from fastNLP.envs.imports import _NEED_IMPORT_TORCH, _TORCH_GREATER_EQUAL_1_8
  from .utils import apply_to_collection
label_desc: Use image node_id 1 for calling a global function with example usage: torch_move_data_to_device(batch, device, non_blocking) and returns: apply_to_collection, batch, data, data_output