class_docstr: Computes the scores of the model embeddings against the `positive'
  and `negative' samples from the Memory Bank.
  This class does *NOT* compute the actual loss, just the scores,
  i.e., inner products followed by normalizations/exponentiation etc.
class_docstr_tok: ["Computes","the","scores","of","the","model","embeddings","against","the","`","positive'","and","`","negative","'","samples","from","the","Memory","Bank",".","This","class","does","*","NOT","*","compute","the","actual","loss",",","just","the","scores",",","i.e.",",","inner","products","followed","by","normalizations\/exponentiation","etc","."]
code: def forward(
      self, embedding, y, idx=None, update_memory_on_forward=None
  ):
      assert embedding.ndim == 2
      assert embedding.shape[1] == self.memory.shape[1]
  
      K = int(self.params[0].item())
      T = self.params[1].item()
      Z = self.params[2].item()
  
      batchSize = embedding.shape[0]
      embedding_dim = self.memory.size(1)
  
      # score computation
      if idx is None:
          idx = self.do_negative_sampling(embedding, y, num_negatives=K)
  
      # sample
      weight = torch.index_select(self.memory, 0, idx.view(-1)).detach()
      weight = weight.view(batchSize, K + 1, embedding_dim)
  
      out = torch.bmm(
          weight, embedding.view(batchSize, embedding_dim, 1)
      )
      out = torch.div(out, T)
      if self.loss_type == "nce":
          out = torch.exp(out)
  
          # compute partition function
          if Z < 0:
              self.compute_partition_function(out)
  
          Z = self.params[2].clone().detach().item()
  
          out = torch.div(out, Z).contiguous().reshape(batchSize, K + 1)
      if update_memory_on_forward or (
          update_memory_on_forward is None
          and self.update_memory_on_forward
      ):
          self.update_memory(embedding, y)
      return out
  
imports: import logging
  import math
  import pprint
  from typing import List, Union
  import numpy
  import torch
  from classy_vision.generic.distributed_util import all_reduce_mean, gather_from_all, get_rank
  from classy_vision.generic.util import is_pos_int
  from classy_vision.losses import ClassyLoss, register_loss
  from torch import nn
  from vissl.config import AttrDict
label_desc: Use image node_id 2 for calling the NCEAverage obj's underlying member method code with example usage: obj.forward(embedding, y, idx, update_memory_on_forward) and returns: out