code: def _test_distrib_multilabel_input_NHW(device):
      # Multilabel input data of shape (N, C, H, W, ...) and (N, C, H, W, ...)
  
      rank = idist.get_rank()
  
      def _test(metric_device):
          metric_device = torch.device(metric_device)
          acc = Accuracy(is_multilabel=True, device=metric_device)
  
          torch.manual_seed(10 + rank)
          y_pred = torch.randint(
              0, 2, size=(4, 5, 8, 10), device=device
          ).long()
          y = torch.randint(
              0, 2, size=(4, 5, 8, 10), device=device
          ).long()
          acc.update((y_pred, y))
  
          assert (
              acc._num_correct.device == metric_device
          ), f"{type(acc._num_correct.device)}:{acc._num_correct.device} vs {type(metric_device)}:{metric_device}"
  
          n = acc._num_examples
          assert n == y.numel() / y.size(dim=1)
  
          # gather y_pred, y
          y_pred = idist.all_gather(y_pred)
          y = idist.all_gather(y)
  
          np_y_pred = to_numpy_multilabel(
              y_pred.cpu()
          )  # (N, C, H, W, ...) -> (N * H * W ..., C)
          np_y = to_numpy_multilabel(
              y.cpu()
          )  # (N, C, H, W, ...) -> (N * H * W ..., C)
          assert acc._type == "multilabel"
          res = acc.compute()
          assert n == acc._num_examples
          assert isinstance(res, float)
          assert accuracy_score(np_y, np_y_pred) == pytest.approx(res)
  
          acc.reset()
          torch.manual_seed(10 + rank)
          y_pred = torch.randint(
              0, 2, size=(4, 7, 10, 8), device=device
          ).long()
          y = torch.randint(
              0, 2, size=(4, 7, 10, 8), device=device
          ).long()
          acc.update((y_pred, y))
  
          assert (
              acc._num_correct.device == metric_device
          ), f"{type(acc._num_correct.device)}:{acc._num_correct.device} vs {type(metric_device)}:{metric_device}"
  
          n = acc._num_examples
          assert n == y.numel() / y.size(dim=1)
  
          # gather y_pred, y
          y_pred = idist.all_gather(y_pred)
          y = idist.all_gather(y)
  
          np_y_pred = to_numpy_multilabel(
              y_pred.cpu()
          )  # (N, C, H, W, ...) -> (N * H * W ..., C)
          np_y = to_numpy_multilabel(
              y.cpu()
          )  # (N, C, H, W, ...) -> (N * H * W ..., C)
  
          assert acc._type == "multilabel"
          res = acc.compute()
          assert n == acc._num_examples
          assert isinstance(res, float)
          assert accuracy_score(np_y, np_y_pred) == pytest.approx(res)
          # check that result is not changed
          res = acc.compute()
          assert n == acc._num_examples
          assert isinstance(res, float)
          assert accuracy_score(np_y, np_y_pred) == pytest.approx(res)
  
          # Batched Updates
          acc.reset()
          torch.manual_seed(10 + rank)
          y_pred = torch.randint(
              0, 2, size=(80, 5, 8, 10), device=device
          ).long()
          y = torch.randint(
              0, 2, size=(80, 5, 8, 10), device=device
          ).long()
  
          batch_size = 16
          n_iters = y.shape[0] // batch_size + 1
  
          for i in range(n_iters):
              idx = i * batch_size
              acc.update(
                  (
                      y_pred[idx : idx + batch_size],
                      y[idx : idx + batch_size],
                  )
              )
  
          assert (
              acc._num_correct.device == metric_device
          ), f"{type(acc._num_correct.device)}:{acc._num_correct.device} vs {type(metric_device)}:{metric_device}"
  
          n = acc._num_examples
          assert n == y.numel() / y.size(dim=1)
  
          # gather y_pred, y
          y_pred = idist.all_gather(y_pred)
          y = idist.all_gather(y)
  
          np_y_pred = to_numpy_multilabel(
              y_pred.cpu()
          )  # (N, C, L, ...) -> (N * L * ..., C)
          np_y = to_numpy_multilabel(
              y.cpu()
          )  # (N, C, L, ...) -> (N * L ..., C)
  
          assert acc._type == "multilabel"
          res = acc.compute()
          assert n == acc._num_examples
          assert isinstance(res, float)
          assert accuracy_score(np_y, np_y_pred) == pytest.approx(res)
  
      # check multiple random inputs as random exact occurencies are rare
      for _ in range(3):
          _test("cpu")
          if device.type != "xla":
              _test(idist.device())
  
imports: import os
  import pytest
  import torch
  from packaging.version import Version
  from sklearn.metrics import accuracy_score
  import ignite.distributed
  from ignite.engine import Engine
  from ignite.exceptions import NotComputableError
  from ignite.metrics import Accuracy
label_desc: Use image node_id 15 for calling a global function with example usage: _test_distrib_multilabel_input_NHW(device) without return types