code: def test_torch_conversion(ray_start_regular_shared):
      ds = ray.data.range(5)
      it = ds.iterator()
      it.iter_batches = MagicMock()
  
      for batch in it.iter_torch_batches():
          assert isinstance(batch["id"], torch.Tensor)
          assert batch["id"].tolist() == list(range(5))
  
      # When collate_fn is not specified, check that the default
      #  `_collate_fn` (handles formatting and Tensor creation)
      # and `_finalize_fn` (handles host to device data transfer)
      # are used in `DataIterator.iter_batches()`.
      iter_batches_calls_kwargs = [
          a.kwargs for a in it.iter_batches.call_args_list
      ]
      assert all(
          callable(kwargs["_collate_fn"])
          and callable(kwargs["_finalize_fn"])
          for kwargs in iter_batches_calls_kwargs
      ), iter_batches_calls_kwargs
  
file_path: ray/python/ray/data/tests/test_iterator.py
imports: from typing import Dict
  from unittest.mock import MagicMock, patch
  import numpy
  import pytest
  import tensorflow
  import torch
  import ray
label_desc: Use image node_id 8 for calling a global function with example usage: test_torch_conversion(ray_start_regular_shared) without return types