class_docstr: This hook corresponds to the loss proposed in the "Momentum Contrast
  for Unsupervised Visual Representation Learning" paper, from Kaiming He et al.
  See http://arxiv.org/abs/1911.05722 for details
  and https://github.com/facebookresearch/moco for a reference implementation,
  reused here.
  
  Called after every forward pass to update the momentum encoder. At the beginning
  of training i.e. after 1st forward call, the encoder is contructed and updated.
docstr: Create the model replica called the encoder. This will slowly track
  the main model.
docstr_tok: ["Create","the","model","replica","called","the","encoder",".","This","will","slowly","track","the","main","model","."]
code: def _build_moco_encoder(self, task: tasks.ClassyTask) -> None:
      """
      Create the model replica called the encoder. This will slowly track
      the main model.
      """
      # Create the encoder, which will slowly track the model
      logging.info(
          "Building MoCo encoder - rank %s %s",
          *get_machine_local_and_dist_rank(),
      )
  
      # - same architecture
      task.loss.moco_encoder = build_model(
          task.config["MODEL"], task.config["OPTIMIZER"]
      )
  
      task.loss.moco_encoder.to(task.device)
  
      # Restore an hypothetical checkpoint, else initialize from the model
      if task.loss.checkpoint is not None:
          task.loss.load_state_dict(task.loss.checkpoint)
      else:
          for param_q, param_k in zip(
              task.base_model.parameters(),
              task.loss.moco_encoder.parameters(),
          ):
              param_k.data.copy_(param_q.data)
              param_k.requires_grad = False
  
file_path: vissl/vissl/hooks/moco_hooks.py
imports: import logging
  import torch
  from classy_vision import tasks
  from classy_vision.generic.distributed_util import is_distributed_training_run
  from classy_vision.hooks.classy_hook import ClassyHook
  from vissl.models import build_model
  from vissl.utils.env import get_machine_local_and_dist_rank
  from vissl.utils.misc import concat_all_gather
label_desc: Use image node_id 2 for calling the MoCoHook obj's underlying member method code with example usage: obj._build_moco_encoder(task) without return types