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 _simclr_precompute_pos_neg_mask_multi(self):
      # computed once at the beginning of training
      distributed = self.cfg.CONTRASTIVE.SIMCLR_DIST_ON
      if distributed:
          total_images = self.cfg.TRAIN.BATCH_SIZE * self.cfg.NUM_SHARDS
          world_size = du.get_world_size()
          rank = du.get_rank()
      else:
          total_images = self.cfg.TRAIN.BATCH_SIZE
          world_size = du.get_local_size()
          rank = du.get_local_rank()
      local_orig_images = total_images // world_size
      local_crops = local_orig_images * self.num_crops
  
      pos_temps = []
      for d in np.arange(self.num_crops):
          pos_temp, neg_temp = [], []
          for i in range(world_size):
              if i == rank:
                  pos = np.eye(
                      local_crops, k=d * local_orig_images
                  ) + np.eye(
                      local_crops,
                      k=-local_crops + d * local_orig_images,
                  )
                  neg = np.ones((local_crops, local_crops))
              else:
                  pos = np.zeros((local_crops, local_crops))
                  neg = np.zeros((local_crops, local_crops))
              pos_temp.append(pos)
              neg_temp.append(neg)
          pos_temps.append(np.hstack(pos_temp))
          neg_temp = np.hstack(neg_temp)
  
      pos_mask = []
      for i in range(self.num_crops - 1):
          pos_mask.append(torch.from_numpy(pos_temps[1 + i]))
      neg_mask = torch.from_numpy(neg_temp - sum(pos_temps))
  
      if self.num_gpus:
          for i in range(len(pos_mask)):
              pos_mask[i] = pos_mask[i].cuda(non_blocking=True)
          neg_mask = neg_mask.cuda(non_blocking=True)
      self.pos_mask, self.neg_mask = pos_mask, neg_mask
  
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 14 for calling the ContrastiveModel obj's underlying member method code with example usage: obj._simclr_precompute_pos_neg_mask_multi() without return types