code: def test_ema_two_handlers(get_dummy_model):
      """Test when two EMA handlers are attached to a trainer"""
      model_1 = get_dummy_model()
      ema_handler_1 = EMAHandler(model_1, momentum=0.5)
  
      model_2 = get_dummy_model()
      ema_handler_2 = EMAHandler(model_2, momentum=0.5)
  
      def _step_fn(engine: Engine, batch: Any):
          model_1.weight.data.add_(1)
          model_2.weight.data.add_(1)
          return 0
  
      engine = Engine(_step_fn)
      assert not hasattr(engine.state, "ema_momentum_1")
      # handler_1 update EMA model of model_1 every 1 iteration
      ema_handler_1.attach(
          engine, "ema_momentum_1", event=Events.ITERATION_COMPLETED
      )
      assert hasattr(engine.state, "ema_momentum_1")
  
      # handler_2 update EMA model for model_2 every 2 iterations
      ema_handler_2.attach(
          engine,
          "ema_momentum_2",
          event=Events.ITERATION_COMPLETED(every=2),
      )
      assert hasattr(engine.state, "ema_momentum_2")
  
      # engine will run 4 iterations
      engine.run(range(2), max_epochs=2)
      # explicitly cast to float32 to avoid test failure on XLA devices
      ema_weight_1 = ema_handler_1.ema_model.weight.data.to(
          torch.float32
      )
      ema_weight_2 = ema_handler_2.ema_model.weight.data.to(
          torch.float32
      )
      assert ema_weight_1.allclose(
          ema_weight_1.new_full((1, 2), 4.0625)
      )
      assert ema_weight_2.allclose(ema_weight_2.new_full((1, 2), 3.5))
  
      assert engine.state.ema_momentum_1 == 0.5
      assert engine.state.ema_momentum_2 == 0.5
  
      model_3 = get_dummy_model()
      ema_handler_3 = EMAHandler(model_3)
      with pytest.warns(
          UserWarning, match="Attribute 'ema_momentum_1' already exists"
      ):
          ema_handler_3.attach(engine, name="ema_momentum_1")
  
imports: import os
  from typing import Any, Callable, Union
  import pytest
  import torch
  import torch.nn
  from torch.nn.parallel import DataParallel, DistributedDataParallel
  import ignite.distributed
  from ignite.engine import Engine, Events
  from ignite.handlers import EMAHandler
label_desc: Use image node_id 13 for calling a global function with example usage: test_ema_two_handlers(get_dummy_model) and returns: int