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 = 16
  
          y_true = torch.rand(size=(n_iters * batch_size,)).to(device)
          y_preds = torch.rand(size=(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)
  
          m = MaximumAbsoluteError(device=metric_device)
          m.attach(engine, "mae")
  
          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 "mae" in engine.state.metrics
  
          res = engine.state.metrics["mae"]
  
          np_y_true = y_true.cpu().numpy()
          np_y_preds = y_preds.cpu().numpy()
  
          np_max = np.max(np.abs((np_y_preds - np_y_true)))
  
          assert pytest.approx(res) == np_max
  
      metric_devices = ["cpu"]
      if device.type != "xla":
          metric_devices.append(idist.device())
      for metric_device in metric_devices:
          for i in range(2):
              torch.manual_seed(12 + rank + i)
              _test(n_epochs=1, metric_device=metric_device)
              _test(n_epochs=2, metric_device=metric_device)
  
imports: import os
  import numpy
  import pytest
  import torch
  import ignite.distributed
  from ignite.contrib.metrics.regression import MaximumAbsoluteError
  from ignite.engine import Engine
  from ignite.exceptions import NotComputableError
label_desc: Use image node_id 6 for calling a global function with example usage: _test_distrib_integration(device) and returns: y_preds,  y_true