class_docstr: This hook is for the extension of the SwAV loss proposed in paper
  https://arxiv.org/abs/2006.09882 by Caron et al. The loss combines
  the benefits of using the SwAV approach with the momentum encoder
  as used in MoCo.
class_docstr_tok: ["This","hook","is","for","the","extension","of","the","SwAV","loss","proposed","in","paper","https",":","\/\/arxiv.org\/abs\/2006.09882","by","Caron","et","al",".","The","loss","combines","the","benefits","of","using","the","SwAV","approach","with","the","momentum","encoder","as","used","in","MoCo","."]
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_momentum_network(self, task: tasks.ClassyTask) -> None:
      """
      Create the model replica called the encoder. This will slowly track
      the main model.
      """
      logging.info(
          "Building momentum encoder - rank %s %s",
          *get_machine_local_and_dist_rank(),
      )
  
      # - same architecture
      task.loss.momentum_encoder = build_model(
          task.config["MODEL"], task.config["OPTIMIZER"]
      )
      task.loss.momentum_encoder = (
          nn.SyncBatchNorm.convert_sync_batchnorm(
              task.loss.momentum_encoder
          )
      )
      task.loss.momentum_encoder.to(
          torch.device("cuda" if task.use_gpu else "cpu")
      )
  
      # Initialize from the model
      if task.loss.checkpoint is None:
          for param_q, param_k in zip(
              task.base_model.parameters(),
              task.loss.momentum_encoder.parameters(),
          ):
              param_k.data.copy_(param_q.data)
          for buff_q, buff_k in zip(
              task.base_model.named_buffers(),
              task.loss.momentum_encoder.named_buffers(),
          ):
              if "running_" not in buff_k[0]:
                  continue
              buff_k[1].data.copy_(buff_q[1].data)
      task.loss.momentum_encoder = init_distributed_data_parallel_model(
          task.loss.momentum_encoder
      )
  
      # Restore an hypothetical checkpoint
      if task.loss.checkpoint is not None:
          task.loss.load_state_dict(task.loss.checkpoint)
  
file_path: vissl/vissl/hooks/swav_momentum_hooks.py
imports: import logging
  from typing import List
  import torch
  from classy_vision import tasks
  from classy_vision.generic.distributed_util import init_distributed_data_parallel_model
  from classy_vision.hooks.classy_hook import ClassyHook
  from torch import nn
  from vissl.models import build_model
  from vissl.utils.env import get_machine_local_and_dist_rank
label_desc: Use image node_id 2 for calling the SwAVMomentumHook obj's underlying member method code with example usage: obj._build_momentum_network(task) without return types