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: Undo batch shuffle.
  *** Only support DistributedDataParallel (DDP) model. ***
docstr_tok: ["Undo","batch","shuffle",".","*","*","*","Only","support","DistributedDataParallel","(","DDP",")","model",".","*","*","*"]
code: def _batch_unshuffle_ddp(self, x, idx_unshuffle):
      """
      Undo batch shuffle.
      *** Only support DistributedDataParallel (DDP) model. ***
      """
      # gather from all gpus
      batch_size_this = x.shape[0]
      x_gather = concat_all_gather(x)
      batch_size_all = x_gather.shape[0]
  
      num_gpus = batch_size_all // batch_size_this
  
      # restored index for this gpu
      gpu_idx = torch.distributed.get_rank()
      idx_this = idx_unshuffle.view(num_gpus, -1)[gpu_idx]
  
      return x_gather[idx_this]
  
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 5 for calling the MoCoHook obj's underlying member method code with example usage: obj._batch_unshuffle_ddp(x, idx_unshuffle) and returns: x_gather