My Bad, I mentioned the forked repo link. Check the loss_function.py in this repo.

  
      
      GitHub
  
  
    

cvqluu/Angular-Penalty-Softmax-Losses-Pytorch 2

Angular penalty loss functions in Pytorch (ArcFace, SphereFace, Additive Margin, CosFace)  - cvqluu/Angular-Penalty-Softmax-Losses-Pytorch


  
  
    
    
  
  


The calculation looks like this.
numerator = self.s * torch.cos(torch.acos(torch.clamp(torch.diagonal(wf.transpose(0, 1)[labels]), -1.+self.eps, 1-self.eps)) + self.m)