class_docstr: Exponential Moving Average of Fairseq Models
class_docstr_tok: ["Exponential","Moving","Average","of","Fairseq","Models"]
docstr: @param model model to initialize the EMA with
  @param config EMAConfig object with configuration like
  ema_decay, ema_update_freq, ema_fp32
  @param device If provided, copy EMA to this device (e.g. gpu).
  Otherwise EMA is in the same device as the model.
docstr_tok: ["@","param","model","model","to","initialize","the","EMA","with","@","param","config","EMAConfig","object","with","configuration","like","ema_decay",",","ema_update_freq",",","ema_fp32","@","param","device","If","provided",",","copy","EMA","to","this","device","(","e.g",".","gpu",")",".","Otherwise","EMA","is","in","the","same","device","as","the","model","."]
code: def __init__(
      self,
      model,
      config: EMAModuleConfig,
      copy_model=True,
      device=None,
      skip_keys=None,
  ):
      """
      @param model model to initialize the EMA with
      @param config EMAConfig object with configuration like
      ema_decay, ema_update_freq, ema_fp32
      @param device If provided, copy EMA to this device (e.g. gpu).
      Otherwise EMA is in the same device as the model.
      """
  
      self.config = config
  
      if copy_model:
          self.model = copy.deepcopy(model)
          self.model.requires_grad_(False)
      else:
          self.model = model
  
      self.config = config
      self.decay = config.ema_decay
      self.skip_keys = skip_keys or set()
      self.add_missing_params = config.add_missing_params
      self.fp32_params = {}
  
      if device is not None:
          logging.info(f"Copying EMA model to device {device}")
          self.model = self.model.to(device=device)
  
      if self.config.ema_fp32:
          self.build_fp32_params()
  
      self.log_norms = (
          config.log_norms and multi_tensor_l2norm_available
      )
      self.logs = {}
  
file_path: fairseq/fairseq/modules/ema_module.py
imports: import copy
  from dataclasses import dataclass, field
  import logging
  import torch
  from omegaconf import II
  from fairseq.dataclass import FairseqDataclass
label_desc: Use image node_id 1 to create a new EMAModule object  with example: obj = EMAModule(model, config, copy_model, device, skip_keys)