code: def _test_distrib_integration_binary_input(device):
      rank = idist.get_rank()
  
      def _test(n_epochs, metric_device):
          metric_device = torch.device(metric_device)
          n_iters = 80
          batch_size = 16
  
          torch.manual_seed(12 + rank)
  
          # Binary input data of shape (N,) or (N, 1)
          y_true = torch.randint(0, 2, size=(n_iters * batch_size,)).to(
              device
          )
          y_preds = torch.randint(
              0, 2, 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)
  
          ck = CohenKappa(device=metric_device)
          ck.attach(engine, "ck")
  
          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 "ck" in engine.state.metrics
  
          res = engine.state.metrics["ck"]
          if isinstance(res, torch.Tensor):
              res = res.cpu().numpy()
  
          true_res = cohen_kappa_score(
              y_true.cpu().numpy(), y_preds.cpu().numpy()
          )
  
          assert pytest.approx(res) == true_res
  
      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 unittest.mock import patch
  import pytest
  import sklearn
  import torch
  from sklearn.metrics import cohen_kappa_score
  import ignite.distributed
  from ignite.contrib.metrics import CohenKappa
  from ignite.engine import Engine
  from ignite.exceptions import NotComputableError
label_desc: Use image node_id 13 for calling a global function with example usage: _test_distrib_integration_binary_input(device) and returns: y_preds,  y_true