code: def global_distributed_rouge(
      global_rank: int,
      world_size: int,
      gpu_id: Union[int, torch.device],
      metric: ROUGE,
      metric_kwargs: Dict[str, Any],
      desired_values: Dict[str, Any],
  ):
      kwargs = {}
  
      # Use the arguments meant for the process with rank `global_rank`.
      for argname in metric_kwargs:
          kwargs[argname] = metric_kwargs[argname][global_rank]
  
      metric(**kwargs)
  
      metrics = metric.get_metric()
  
      # Unigram
      unigram_recall = metric._total_rouge_n_recalls[1]
      assert_allclose(unigram_recall, desired_values["unigram_recall"])
      unigram_precision = metric._total_rouge_n_precisions[1]
      assert_allclose(
          unigram_precision, desired_values["unigram_precision"]
      )
      unigram_f1 = metric._total_rouge_n_f1s[1]
      assert_allclose(unigram_f1, desired_values["unigram_f1"])
  
      assert (
          metrics["ROUGE-1_R"]
          == unigram_recall / metric._total_sequence_count
      )
      assert (
          metrics["ROUGE-1_P"]
          == unigram_precision / metric._total_sequence_count
      )
      assert (
          metrics["ROUGE-1_F1"]
          == unigram_f1 / metric._total_sequence_count
      )
  
      # Bigram
      bigram_recall = metric._total_rouge_n_recalls[2]
      assert_allclose(bigram_recall, desired_values["bigram_recall"])
      bigram_precision = metric._total_rouge_n_precisions[2]
      assert_allclose(
          bigram_precision, desired_values["bigram_precision"]
      )
      bigram_f1 = metric._total_rouge_n_f1s[2]
      assert_allclose(bigram_f1, desired_values["bigram_f1"])
  
      assert (
          metrics["ROUGE-2_R"]
          == bigram_recall / metric._total_sequence_count
      )
      assert (
          metrics["ROUGE-2_P"]
          == bigram_precision / metric._total_sequence_count
      )
      assert (
          metrics["ROUGE-2_F1"]
          == bigram_f1 / metric._total_sequence_count
      )
  
      # ROUGE-L
  
      assert_allclose(
          metric._total_rouge_l_f1, desired_values["total_rouge_l_f1"]
      )
  
      assert (
          metrics["ROUGE-L"]
          == metric._total_rouge_l_f1 / metric._total_sequence_count
      )
  
file_path: allennlp/tests/training/metrics/rouge_test.py
imports: from typing import Any, Dict, Union
  import torch
  from torch.testing import assert_allclose
  from allennlp.common.testing import AllenNlpTestCase, multi_device, run_distributed_test
  from allennlp.training.metrics import ROUGE
label_desc: Use image node_id 1 for calling a global function with example usage: global_distributed_rouge(global_rank, world_size, gpu_id, metric, metric_kwargs, desired_values) without return types