class_docstr: The criterion corresponding to the expandion SimCLR loss (as defined in the paper
  https://arxiv.org/abs/2002.05709) using the multi-crop augmentaion proposed
  in SwAV paper. The multi-crop augmentation allows using more positives
  per image.
  
  Args:
      temperature (float): the temperature to be applied on the logits
      num_crops (int): number of positives
      buffer_params:
          world_size (int): total number of trainers in training
          embedding_dim (int): output dimensions of the features projects
          effective_batch_size (int): total batch size used (includes positives)
class_docstr_tok: ["The","criterion","corresponding","to","the","expandion","SimCLR","loss","(","as","defined","in","the","paper","https",":","\/\/arxiv.org\/abs\/2002.05709",")","using","the","multi-crop","augmentaion","proposed","in","SwAV","paper",".","The","multi-crop","augmentation","allows","using","more","positives","per","image",".","Args",":","temperature","(","float",")",":","the","temperature","to","be","applied","on","the","logits","num_crops","(","int",")",":","number","of","positives","buffer_params",":","world_size","(","int",")",":","total","number","of","trainers","in","training","embedding_dim","(","int",")",":","output","dimensions","of","the","features","projects","effective_batch_size","(","int",")",":","total","batch","size","used","(","includes","positives",")"]
docstr: We precompute the positive and negative masks to speed up the loss calculation
docstr_tok: ["We","precompute","the","positive","and","negative","masks","to","speed","up","the","loss","calculation"]
code: def precompute_pos_neg_mask(self):
      """
      We precompute the positive and negative masks to speed up the loss calculation
      """
      # computed once at the beginning of training
      total_images = self.buffer_params.effective_batch_size
      world_size = self.buffer_params.world_size
      local_orig_images = total_images // world_size
      local_crops = local_orig_images * self.num_crops
      rank = self.dist_rank
  
      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.use_gpu:
          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
  
file_path: vissl/vissl/losses/multicrop_simclr_info_nce_loss.py
imports: import logging
  import pprint
  import numpy
  import torch
  from classy_vision.losses import register_loss
  from vissl.config import AttrDict
  from vissl.losses.simclr_info_nce_loss import SimclrInfoNCECriterion, SimclrInfoNCELoss
label_desc: Use image node_id 2 for calling the MultiCropSimclrInfoNCECriterion obj's underlying member method code with example usage: obj.precompute_pos_neg_mask() without return types