class_docstr: Hook executed to save the exponential moving average of the base_model parameters
  and run the meters on this ema_model.
class_docstr_tok: ["Hook","executed","to","save","the","exponential","moving","average","of","the","base_model","parameters","and","run","the","meters","on","this","ema_model","."]
docstr: Sync states between the meters if running distributed training
  and log the meters.
docstr_tok: ["Sync","states","between","the","meters","if","running","distributed","training","and","log","the","meters","."]
code: def on_loss_and_meter(self, task: "tasks.ClassyTask") -> None:
      """
      Sync states between the meters if running distributed training
      and log the meters.
      """
      if not self.enable_ema_meters:
          # Do not process the ema meters, merely save the EMA model
          return
  
      model_input = task.last_batch.sample["input"].to(
          task.ema_model.device
      )
      model_output = task.ema_model.module(model_input)
  
      if isinstance(model_output, list):
          model_output_cpu = [x.cpu() for x in model_output]
      else:
          model_output_cpu = model_output.cpu()
  
      target = task.last_batch.sample["target"]
  
      for meter in task.ema_meters:
          meter.update(model_output_cpu, target.detach().cpu())
  
file_path: vissl/vissl/hooks/ema_hooks.py
imports: import torch
  from classy_vision import tasks
  from classy_vision.generic.distributed_util import is_primary
  from classy_vision.hooks.classy_hook import ClassyHook
  from vissl.hooks.log_hooks import LogLossMetricsCheckpointHook
label_desc: Use image node_id 5 for calling the EmaHook obj's underlying member method code with example usage: obj.on_loss_and_meter(task) without return types