code: def test_src_is_output(self, usage):
      device = idist.device()
      rank = idist.get_rank()
      n_iters = 10
      n_epochs = 3
  
      # Data per rank
      data = list(range(n_iters))
      rank_loss_count = n_epochs * n_iters
      all_loss_values = torch.arange(
          0,
          rank_loss_count * idist.get_world_size(),
          dtype=torch.float64,
      ).to(device)
      loss_values = iter(
          all_loss_values[
              rank_loss_count * rank : rank_loss_count * (rank + 1)
          ]
      )
  
      def update_fn(engine, batch):
          loss_value = next(loss_values)
          return loss_value.item()
  
      trainer = Engine(update_fn)
      alpha = 0.98
  
      metric_device = device if device.type != "xla" else "cpu"
      avg_output = RunningAverage(
          output_transform=lambda x: x,
          alpha=alpha,
          device=metric_device,
      )
      avg_output.attach(trainer, "running_avg_output", usage)
  
      @trainer.on(usage.STARTED)
      def reset_running_avg_output(engine):
          engine.state.running_avg_output = None
  
      @trainer.on(usage.ITERATION_COMPLETED)
      def running_avg_output_update(engine):
          i = engine.state.iteration - 1
          o = sum(
              [
                  all_loss_values[i + r * rank_loss_count]
                  for r in range(idist.get_world_size())
              ]
          ).item()
          o /= idist.get_world_size()
          if engine.state.running_avg_output is None:
              engine.state.running_avg_output = o
          else:
              engine.state.running_avg_output = (
                  engine.state.running_avg_output * alpha
                  + (1.0 - alpha) * o
              )
  
      @trainer.on(usage.COMPLETED)
      def assert_equal_running_avg_output_values(engine):
          it = engine.state.iteration
          assert (
              engine.state.running_avg_output
              == engine.state.metrics["running_avg_output"]
          ), f"{it}: {engine.state.running_avg_output} vs {engine.state.metrics['running_avg_output']}"
  
      trainer.run(data, max_epochs=3)
  
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 1 for calling the TestDistributed obj's underlying member method code with example usage: obj.test_src_is_output(usage) and returns: loss_value