code: def test_cosface_loss(self):
      margin = 0.5
      scale = 64
  
      for dtype in TEST_DTYPES:
          loss_func = CosFaceLoss(
              margin=margin,
              scale=scale,
              num_classes=10,
              embedding_size=2,
          )
  
          embedding_angles = torch.arange(0, 180)
          embeddings = torch.tensor(
              [angle_to_coord(a) for a in embedding_angles],
              requires_grad=True,
              dtype=dtype,
          ).to(
              TEST_DEVICE
          )  # 2D embeddings
          labels = torch.randint(low=0, high=10, size=(180,))
  
          loss = loss_func(embeddings, labels)
          loss.backward()
  
          weights = F.normalize(loss_func.W, p=2, dim=0)
          logits = torch.matmul(F.normalize(embeddings), weights)
          for i, c in enumerate(labels):
              logits[i, c] -= margin
  
          correct_loss = F.cross_entropy(
              logits * scale, labels.to(TEST_DEVICE)
          )
          rtol = 1e-2 if dtype == torch.float16 else 1e-5
          self.assertTrue(torch.isclose(loss, correct_loss, rtol=rtol))
  
          # test get_logits
          logits_out = loss_func.get_logits(embeddings)
          self.assertTrue(
              torch.allclose(
                  logits_out,
                  torch.matmul(F.normalize(embeddings), weights)
                  * scale,
              )
          )
  
file_path: pytorch-metric-learning/tests/losses/test_cosface_loss.py
imports: import unittest
  import torch
  import torch.nn.functional
  from pytorch_metric_learning.losses import CosFaceLoss
  from ..None import TEST_DEVICE, TEST_DTYPES
  from ..zzz_testing_utils.testing_utils import angle_to_coord
label_desc: Use image node_id 1 for calling the TestCosFaceLoss obj's underlying member method code with example usage: obj.test_cosface_loss() without return types