code: def test_src_is_metric(self, usage):
      device = idist.device()
      rank = idist.get_rank()
      n_iters = 10
      n_epochs = 3
      batch_size = 10
      n_classes = 10
  
      def _test(metric_device):
          data = list(range(n_iters))
          np.random.seed(12)
          all_y_true_batch_values = np.random.randint(
              0,
              n_classes,
              size=(
                  idist.get_world_size(),
                  n_epochs * n_iters,
                  batch_size,
              ),
          )
          all_y_pred_batch_values = np.random.rand(
              idist.get_world_size(),
              n_epochs * n_iters,
              batch_size,
              n_classes,
          )
  
          y_true_batch_values = iter(all_y_true_batch_values[rank, ...])
          y_pred_batch_values = iter(all_y_pred_batch_values[rank, ...])
  
          def update_fn(engine, batch):
              y_true_batch = next(y_true_batch_values)
              y_pred_batch = next(y_pred_batch_values)
              return torch.from_numpy(y_pred_batch), torch.from_numpy(
                  y_true_batch
              )
  
          trainer = Engine(update_fn)
          alpha = 0.98
  
          acc_metric = RunningAverage(
              Accuracy(device=metric_device), alpha=alpha
          )
          acc_metric.attach(trainer, "running_avg_accuracy", usage)
  
          running_avg_acc = [
              None,
          ]
          true_acc_metric = Accuracy(device=metric_device)
  
          @trainer.on(Events.ITERATION_COMPLETED)
          def manual_running_avg_acc(engine):
              iteration = engine.state.iteration
  
              if (
                  not isinstance(usage, RunningEpochWise)
                  or ((iteration - 1) % n_iters) == 0
              ):
                  true_acc_metric.reset()
              if ((iteration - 1) % n_iters) == 0 and isinstance(
                  usage, SingleEpochRunningBatchWise
              ):
                  running_avg_acc[0] = None
              for j in range(idist.get_world_size()):
                  output = (
                      torch.from_numpy(
                          all_y_pred_batch_values[
                              j, iteration - 1, :, :
                          ]
                      ),
                      torch.from_numpy(
                          all_y_true_batch_values[j, iteration - 1, :]
                      ),
                  )
                  true_acc_metric.update(output)
  
              if (
                  not isinstance(usage, RunningEpochWise)
                  or (iteration % n_iters) == 0
              ):
                  batch_acc = (
                      true_acc_metric._num_correct.item()
                      * 1.0
                      / true_acc_metric._num_examples
                  )
  
                  if running_avg_acc[0] is None:
                      running_avg_acc[0] = batch_acc
                  else:
                      running_avg_acc[0] = (
                          running_avg_acc[0] * alpha
                          + (1.0 - alpha) * batch_acc
                      )
                  engine.state.running_avg_acc = running_avg_acc[0]
  
          @trainer.on(Events.ITERATION_COMPLETED)
          def assert_equal_running_avg_acc_values(engine):
              print(engine.state.iteration)
              if not isinstance(usage, RunningEpochWise) or (
                  (engine.state.iteration > 1)
                  and ((engine.state.iteration % n_iters) == 1)
              ):
                  assert (
                      engine.state.running_avg_acc
                      == engine.state.metrics["running_avg_accuracy"]
                  ), f"{engine.state.running_avg_acc} vs {engine.state.metrics['running_avg_accuracy']}"
  
          trainer.run(data, max_epochs=3)
  
      _test("cpu")
      if device.type != "xla":
          _test(idist.device())
  
imports: import warnings
  from functools import partial
  from itertools import accumulate
  import numpy
  import pytest
  import torch
  import ignite.distributed
  from ignite.engine import Engine, Events
  from ignite.metrics import Accuracy, RunningAverage
  from ignite.metrics.metric import RunningBatchWise, RunningEpochWise, SingleEpochRunningBatchWise
label_desc: Use image node_id 2 for calling the TestDistributed obj's underlying member method code with example usage: obj.test_src_is_metric(usage) and returns: torch,  torch