code: def test_p2s_grad_loss_with_trusted_implementation(self):
      torch.manual_seed(23)
      num_classes = 20
      batch_size = 100
      descriptors_dim = 128
  
      for dtype in TEST_DTYPES:
          embeddings = torch.randn(
              batch_size,
              descriptors_dim,
              device=TEST_DEVICE,
              dtype=dtype,
              requires_grad=True,
          )
          labels = torch.randint(
              0, num_classes, size=(batch_size,), device=TEST_DEVICE
          )
  
          loss_func = P2SGradLoss(descriptors_dim, num_classes)
          t_layer = TrustedImplementationP2SActivationLayer(
              descriptors_dim, num_classes
          )
          t_loss_func = TrustedImplementationP2SGradLoss()
          loss_func.weight = (
              t_layer.weight
          )  # Only to ensure they start from equal initializations
  
          rtol = 1e-2 if dtype == torch.float16 else 1e-5
  
          loss = loss_func(embeddings, labels)
          loss.backward()
          t_loss = t_loss_func(t_layer(embeddings), labels)
          t_loss.backward()
          self.assertTrue(torch.isclose(loss, t_loss, rtol=rtol))
  
file_path: pytorch-metric-learning/tests/losses/test_p2s_grad_loss.py
imports: import unittest
  import torch
  import torch.nn
  from pytorch_metric_learning.losses import P2SGradLoss
  from pytorch_metric_learning.utils import common_functions
  from ..None import TEST_DEVICE, TEST_DTYPES
label_desc: Use image node_id 2 for calling the TestP2SGradLoss obj's underlying member method code with example usage: obj.test_p2s_grad_loss_with_trusted_implementation() without return types