code: def _test_distrib_integration(device):
      rank = idist.get_rank()
  
      def _test(p, r, average, n_epochs, metric_device):
          n_iters = 60
          batch_size = 16
          n_classes = 7
  
          torch.manual_seed(12 + rank)
  
          y_true = torch.randint(
              0, n_classes, size=(n_iters * batch_size,)
          ).to(device)
          y_preds = torch.rand(n_iters * batch_size, n_classes).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)
  
          fbeta = Fbeta(beta=2.5, average=average, device=metric_device)
          fbeta.attach(engine, "f2.5")
  
          data = list(range(n_iters))
          engine.run(data=data, max_epochs=n_epochs)
  
          y_preds = idist.all_gather(y_preds)
          y_true = idist.all_gather(y_true)
  
          assert "f2.5" in engine.state.metrics
          res = engine.state.metrics["f2.5"]
          if isinstance(res, torch.Tensor):
              res = res.cpu().numpy()
  
          true_res = fbeta_score(
              y_true.cpu().numpy(),
              torch.argmax(y_preds, dim=1).cpu().numpy(),
              beta=2.5,
              average="macro" if average else None,
          )
  
          assert pytest.approx(res) == true_res
  
      metric_devices = ["cpu"]
      if device.type != "xla":
          metric_devices.append(idist.device())
      for metric_device in metric_devices:
          _test(
              None,
              None,
              average=True,
              n_epochs=1,
              metric_device=metric_device,
          )
          _test(
              None,
              None,
              average=True,
              n_epochs=2,
              metric_device=metric_device,
          )
          precision = Precision(average=False, device=metric_device)
          recall = Recall(average=False, device=metric_device)
          _test(
              precision,
              recall,
              average=False,
              n_epochs=1,
              metric_device=metric_device,
          )
          _test(
              precision,
              recall,
              average=False,
              n_epochs=2,
              metric_device=metric_device,
          )
  
file_path: ignite/tests/ignite/metrics/test_fbeta.py
imports: import os
  import numpy
  import pytest
  import torch
  from sklearn.metrics import fbeta_score
  import ignite.distributed
  from ignite.engine import Engine
  from ignite.metrics import Fbeta, Precision, Recall
label_desc: Use image node_id 4 for calling a global function with example usage: _test_distrib_integration(device) and returns: y_preds,  y_true