code: def _test_distrib_integration(device):
      from ignite.engine import Engine
  
      rank = idist.get_rank()
  
      size = len(corpus.chunks)
  
      data = []
      for c in corpus.chunks:
          data += idist.get_world_size() * [c]
  
      def update(_, i):
          candidate, references = data[i + size * rank]
          lower_split_references = [
              reference.lower().split() for reference in references[0]
          ]
          lower_split_candidate = candidate[0].lower().split()
          return [lower_split_candidate], [lower_split_references]
  
      def _test(metric_device):
          engine = Engine(update)
          m = Rouge(
              variants=[1, 2, "L"], alpha=0.5, device=metric_device
          )
          m.attach(engine, "rouge")
  
          engine.run(data=list(range(size)), max_epochs=1)
  
          assert "rouge" in engine.state.metrics
  
          evaluator = pyrouge.Rouge(
              metrics=["rouge-n", "rouge-l"],
              max_n=4,
              apply_avg=True,
              apply_best=False,
              alpha=0.5,
              stemming=False,
              ensure_compatibility=False,
          )
          rouge_1_f, rouge_2_f, rouge_l_f = (0, 0, 0)
          for candidate, references in data:
              scores = evaluator.get_scores(candidate, references)
              rouge_1_f += scores["rouge-1"]["f"]
              rouge_2_f += scores["rouge-2"]["f"]
              rouge_l_f += scores["rouge-l"]["f"]
          assert pytest.approx(
              engine.state.metrics["Rouge-1-F"], abs=1e-4
          ) == rouge_1_f / len(data)
          assert pytest.approx(
              engine.state.metrics["Rouge-2-F"], abs=1e-4
          ) == rouge_2_f / len(data)
          assert pytest.approx(
              engine.state.metrics["Rouge-L-F"], abs=1e-4
          ) == rouge_l_f / len(data)
  
      _test("cpu")
  
      if device.type != "xla":
          _test(idist.device())
  
imports: import os
  import nltk
  import pytest
  import rouge
  import torch
  import ignite.distributed
  from ignite.exceptions import NotComputableError
  from ignite.metrics.nlp import Rouge
  from ignite.metrics.nlp.rouge import compute_ngram_scores, RougeL, RougeN
  from .None import CorpusForTest
label_desc: Use image node_id 5 for calling a global function with example usage: _test_distrib_integration(device) and returns: list,  list