code: def _test_distrib_integration(device):
      rank = idist.get_rank()
  
      def _test(n_epochs, metric_device):
          metric_device = torch.device(metric_device)
          n_iters = 80
          batch_size = 151
          torch.manual_seed(12 + rank)
  
          y_true = torch.randint(0, 2, (n_iters * batch_size,)).to(
              device
          )
          y_preds = torch.randint(0, 2, (n_iters * batch_size,)).to(
              device
          )
  
          def update(engine, i):
              return (
                  y_preds[i * batch_size : (i + 1) * batch_size],
                  y_true[i * batch_size : (i + 1) * batch_size],
              )
  
          engine = Engine(update)
  
          prc = PrecisionRecallCurve(device=metric_device)
          prc.attach(engine, "prc")
  
          data = list(range(n_iters))
          engine.run(data=data, max_epochs=n_epochs)
  
          y_true = idist.all_gather(y_true)
          y_preds = idist.all_gather(y_preds)
  
          assert "prc" in engine.state.metrics
  
          precision, recall, thresholds = engine.state.metrics["prc"]
  
          np_y_true = y_true.cpu().numpy().ravel()
          np_y_preds = y_preds.cpu().numpy().ravel()
  
          (
              sk_precision,
              sk_recall,
              sk_thresholds,
          ) = precision_recall_curve(np_y_true, np_y_preds)
  
          assert precision.shape == sk_precision.shape
          assert recall.shape == sk_recall.shape
          assert thresholds.shape == sk_thresholds.shape
          assert pytest.approx(precision.cpu().numpy()) == sk_precision
          assert pytest.approx(recall.cpu().numpy()) == sk_recall
          assert (
              pytest.approx(thresholds.cpu().numpy()) == sk_thresholds
          )
  
      metric_devices = ["cpu"]
      if device.type != "xla":
          metric_devices.append(idist.device())
      for metric_device in metric_devices:
          for _ in range(2):
              _test(n_epochs=1, metric_device=metric_device)
              _test(n_epochs=2, metric_device=metric_device)
  
imports: import os
  from typing import Tuple
  from unittest.mock import patch
  import numpy
  import pytest
  import sklearn
  import torch
  from sklearn.metrics import precision_recall_curve
  import ignite.distributed
  from ignite.contrib.metrics.precision_recall_curve import PrecisionRecallCurve
  from ignite.engine import Engine
  from ignite.metrics.epoch_metric import EpochMetricWarning
label_desc: Use image node_id 8 for calling a global function with example usage: _test_distrib_integration(device) and returns: y_preds,  y_true