code: def test_torch_batch_process_reduce_metrics(
      mock_synchronize_and_checkpoint: unittest.mock.MagicMock,
      mock_initialize_default_inference_context: unittest.mock.MagicMock,
  ) -> None:
      # Simulate a two worker run, and we are worker 0 (chief)
      # The entire dataset is [0, 1, 2, 3 , 4, 5, 6, 7, 8, 9]
      # With batch_size of 5,
      # - worker 0 works on [0, 1, 2, 3, 4], sum = 10
      # - worker 1 works on [5, 6, 7, 8, 9], sum = 35
      # The metric reducer simpler sum up all the values.
      # Therefore, by the end of the iteration, metric_reducer 0 would have self.sum == 10
      # metric_reducer 1 would have self.sum == 35
      with test_util.set_mock_cluster_info(DEFAULT_ADDRS, 0, 2):
          index_dataset = IndexData(10)
          # Mock core context as we are asserting call count on train.report_validation_metrics
          mock_core_context = _get_core_context(rank=0)
          mock_core_context.__enter__().distributed.gather.return_value = [
              [10],
              [35],
          ]
          mock_initialize_default_inference_context.return_value = (
              mock_core_context
          )
  
          experimental.torch_batch_process(
              dataset=index_dataset,
              batch_processor_cls=MyProcessor,
              batch_size=5,
              checkpoint_interval=1,
          )
  
          # Assert gather was first called with worker 0's sum amount: 10
          assert mock_core_context.__enter__().distributed.gather.call_args_list[
              0
          ] == unittest.mock.call(
              [10]
          )
          # Assert that we report metrics with the sum across workers: 45
          mock_core_context.__enter__().train.report_validation_metrics.assert_called_once_with(
              steps_completed=1,
              metrics={"sum_metric": 45},
          )
  
imports: import math
  import unittest.mock
  from typing import Any, Dict, List, Optional
  import pytest
  import torch
  from torch.utils import data
  from determined import core, pytorch
  from determined.pytorch import experimental
  from tests.launch import test_util
label_desc: Use image node_id 11 for calling a global function with example usage: test_torch_batch_process_reduce_metrics(mock_synchronize_and_checkpoint, mock_initialize_default_inference_context) without return types