class_docstr: https://arxiv.org/abs/2203.15565
  A distributed sparsely updating variant of the FC layer, named Partial FC (PFC).
  When sample rate less than 1, in each iteration, positive class centers and a random subset of
  negative class centers are selected to compute the margin-based softmax loss, all class
  centers are still maintained throughout the whole training process, but only a subset is
  selected and updated in each iteration.
  .. note::
      When sample rate equal to 1, Partial FC is equal to model parallelism(default sample rate is 1).
  Example:
  --------
  >>> module_pfc = PartialFC(embedding_size=512, num_classes=8000000, sample_rate=0.2)
  >>> for img, labels in data_loader:
  >>>     embeddings = net(img)
  >>>     loss = module_pfc(embeddings, labels)
  >>>     loss.backward()
  >>>     optimizer.step()
class_docstr_tok: ["https",":","\/\/arxiv.org\/abs\/2203.15565","A","distributed","sparsely","updating","variant","of","the","FC","layer",",","named","Partial","FC","(","PFC",")",".","When","sample","rate","less","than","1",",","in","each","iteration",",","positive","class","centers","and","a","random","subset","of","negative","class","centers","are","selected","to","compute","the","margin-based","softmax","loss",",","all","class","centers","are","still","maintained","throughout","the","whole","training","process",",","but","only","a","subset","is","selected","and","updated","in","each","iteration",".","..","note",":",":","When","sample","rate","equal","to","1",",","Partial","FC","is","equal","to","model","parallelism","(","default","sample","rate","is","1",")",".","Example",":","--","--","--","--",">",">",">","module_pfc","=","PartialFC","(","embedding_size=512",",","num_classes=8000000",",","sample_rate=0.2",")",">",">",">","for","img",",","labels","in","data_loader",":",">",">",">","embeddings","=","net","(","img",")",">",">",">","loss","=","module_pfc","(","embeddings",",","labels",")",">",">",">","loss.backward","(",")",">",">",">","optimizer.step","(",")"]
docstr: This functions will change the value of labels
  Parameters:
  -----------
  labels: torch.Tensor
      pass
  index_positive: torch.Tensor
      pass
  optimizer: torch.optim.Optimizer
      pass
docstr_tok: ["This","functions","will","change","the","value","of","labels","Parameters",":","--","--","--","--","--","-","labels",":","torch.Tensor","pass","index_positive",":","torch.Tensor","pass","optimizer",":","torch.optim.Optimizer","pass"]
code: def sample(self, labels, index_positive):
      """
      This functions will change the value of labels
      Parameters:
      -----------
      labels: torch.Tensor
          pass
      index_positive: torch.Tensor
          pass
      optimizer: torch.optim.Optimizer
          pass
      """
      with torch.no_grad():
          positive = torch.unique(
              labels[index_positive], sorted=True
          ).cuda()
          if self.num_sample - positive.size(0) >= 0:
              perm = torch.rand(size=[self.num_local]).cuda()
              perm[positive] = 2.0
              index = torch.topk(perm, k=self.num_sample)[1].cuda()
              index = index.sort()[0].cuda()
          else:
              index = positive
          self.weight_index = index
  
          labels[index_positive] = torch.searchsorted(
              index, labels[index_positive]
          )
  
      return self.weight[self.weight_index]
  
imports: import math
  from typing import Callable
  import torch
  from torch import distributed
  from torch.nn.functional import linear, normalize
label_desc: Use image node_id 2 for calling the PartialFC_V2 obj's underlying member method code with example usage: obj.sample(labels, index_positive) and returns: self