code: def test_proxyanchor_loss(self):
      num_classes = 10
      embedding_size = 2
      margin = 0.5
  
      for use_autocast in [True, False]:
          if use_autocast:
              cm = torch.cuda.amp.autocast()
          else:
              cm = nullcontext()
  
          for dtype in TEST_DTYPES:
              alpha = 1 if dtype == torch.float16 else 32
              loss_func = ProxyAnchorLoss(
                  num_classes,
                  embedding_size,
                  margin=margin,
                  alpha=alpha,
              ).to(TEST_DEVICE)
              original_loss_func = OriginalImplementationProxyAnchor(
                  num_classes, embedding_size, mrg=margin, alpha=alpha
              ).to(TEST_DEVICE)
  
              if not use_autocast:
                  original_loss_func.proxies.data = (
                      original_loss_func.proxies.data.type(dtype)
                  )
              loss_func.proxies = original_loss_func.proxies
  
              embedding_angles = list(range(0, 180))
              embeddings = torch.tensor(
                  [angle_to_coord(a) for a in embedding_angles],
                  requires_grad=True,
                  dtype=torch.float32,
              ).to(
                  TEST_DEVICE
              )  # 2D embeddings
  
              if not use_autocast:
                  embeddings = embeddings.type(dtype)
              labels = torch.randint(low=0, high=5, size=(180,)).to(
                  TEST_DEVICE
              )
  
              with cm:
                  loss = loss_func(embeddings, labels)
  
              loss.backward()
              correct_loss = original_loss_func(embeddings, labels)
              rtol = (
                  1e-2
                  if dtype == torch.float16 or use_autocast
                  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),
                          F.normalize(loss_func.proxies).t(),
                      ),
                  )
              )
  
file_path: pytorch-metric-learning/tests/losses/test_proxy_anchor_loss.py
imports: from contextlib import nullcontext
  import torch
  import torch.nn
  import torch.nn.functional
  import unittest
  import torch
  from pytorch_metric_learning.losses import ProxyAnchorLoss
  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 TestProxyAnchorLoss obj's underlying member method code with example usage: obj.test_proxyanchor_loss() without return types