class_docstr: Contrastive Model, currently mainly focused on memory bank and CSC.
class_docstr_tok: ["Contrastive","Model",",","currently","mainly","focused","on","memory","bank","and","CSC","."]
code: def _batch_shuffle(self, x):
      if len(x) == 2:
          another_crop = True
      else:
          another_crop = False
      if another_crop:
          x, x_crop = x[0], x[1]
      else:
          x = x[0]
  
      world_size = self.cfg.NUM_GPUS * self.cfg.NUM_SHARDS
      if self.num_gpus > 1:
          if self.cfg.CONTRASTIVE.LOCAL_SHUFFLE_BN:
              x = du.cat_all_gather(x, local=True)
              if another_crop:
                  x_crop = du.cat_all_gather(x_crop, local=True)
              world_size = du.get_local_size()
              gpu_idx = du.get_local_rank()
          else:
              x = du.cat_all_gather(x)
              if another_crop:
                  x_crop = du.cat_all_gather(x_crop)
              gpu_idx = torch.distributed.get_rank()
  
      idx_randperm = torch.randperm(x.shape[0]).cuda()
      if self.num_gpus > 1:
          torch.distributed.broadcast(idx_randperm, src=0)
      else:
          gpu_idx = 0
      idx_randperm = idx_randperm.view(world_size, -1)
      x = x[idx_randperm[gpu_idx, :]]
      if another_crop:
          x_crop = x_crop[idx_randperm[gpu_idx, :]]
  
      idx_restore = torch.argsort(idx_randperm.view(-1))
      idx_restore = idx_restore.view(world_size, -1)
      if another_crop:
          return [x, x_crop], idx_restore
      else:
          return [x], idx_restore
  
imports: import math
  import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  import slowfast.models.losses
  import slowfast.utils.distributed
  import slowfast.utils.logging
  from slowfast.models.video_model_builder import X3D, MViT, ResNet, SlowFast
  from .build import MODEL_REGISTRY
label_desc: Use image node_id 5 for calling the ContrastiveModel obj's underlying member method code with example usage: obj._batch_shuffle(x) and returns: list,  idx_restore, list,  idx_restore