code: def train(self, mode: bool = True) -> "EMA":
      super().train(mode)
      if mode:
          for name, param in self.tgt_params:
              cached = self._cache.pop(name, None)
              if cached is not None:
                  param.data = cached
      else:
          for name, param in self.tgt_params:
              if name not in self._cache:
                  self._cache[name] = param.data
              param.data = getattr(self, name).clone()
      return self
  
imports: import copy
  import torch
  import torch.nn
  from torch import Tensor
  from typing import Any
  from typing import Dict
  from typing import List
  from typing import Tuple
  from typing import Union
  from typing import Callable
  from typing import Iterator
  from typing import Optional
  from functools import wraps
  from torch.nn import Module
  from torch.nn import ModuleList
  from cftool.types import tensor_dict_type
label_desc: Use image node_id 4 for calling the EMA obj's underlying member method code with example usage: obj.train(mode) and returns: self