code: def test_ema(self) -> None:
      decay = 0.9
      p1 = nn.Parameter(torch.randn(2, 3, 4, 5))
      p2 = nn.Parameter(torch.randn(2, 3, 4, 5))
      p3 = nn.Parameter(torch.randn(2, 3, 4, 5))
      gt = p1.data
      gt = decay * gt + (1.0 - decay) * p2.data
      gt = decay * gt + (1.0 - decay) * p3.data
      ema = EMA(decay, [("test", p1)])
      p1.data = p2.data
      ema()
      p1.data = p3.data
      ema()
      ema.eval()
      ema.train()
      ema.eval()
      ema.train()
      ema.eval()
      self.assertTrue(torch.allclose(p1.data, gt.data))
      ema.train()
      ema.eval()
      ema.train()
      ema.eval()
      ema.train()
      self.assertTrue(torch.allclose(p1.data, p3.data))
      ema.eval()
      ema.eval()
      ema.train()
      ema.train()
      ema.eval()
      ema.eval()
      self.assertTrue(torch.allclose(p1.data, gt.data))
      ema.train()
      ema.train()
      ema.eval()
      ema.eval()
      ema.train()
      ema.train()
      self.assertTrue(torch.allclose(p1.data, p3.data))
      with eval_context(ema):
          self.assertTrue(torch.allclose(p1.data, gt.data))
      self.assertTrue(torch.allclose(p1.data, p3.data))
  
imports: import time
  import torch
  import unittest
  import numpy
  import torch.nn
  from typing import List
  from typing import Tuple
  from cflearn.schema import MLEncoderSettings
  from cflearn.constants import LATENT_KEY
  from cflearn.misc.toolkit import eval_context
  from cflearn.misc.toolkit import inject_parameters
  from cflearn.modules.blocks import BN
  from cflearn.modules.blocks import EMA
  from cflearn.modules.blocks import DNDF
  from cflearn.modules.blocks import Conv2d
  from cflearn.modules.blocks import Linear
  from cflearn.modules.blocks import Lambda
  from cflearn.modules.blocks import Attention
  from cflearn.models.cv.encoder import BackboneEncoder
  from cflearn.models.ml.encoders import Encoder
label_desc: Use image node_id 3 for calling the TestBlocks obj's underlying member method code with example usage: obj.test_ema() without return types