code: def test_embedding_backward(self, device, dtype):
      embedding = nn.Embedding(10, 3, sparse=True)
      tensor = torch.tensor([[7, 1, 3]])
      ones = torch.tensor(1.0, dtype=dtype).expand(3, 3)
      tensorTwice = tensor.repeat(1, 2)
      onesTwice = torch.cat((ones, ones))
  
      embedding = embedding.to(dtype=dtype).to(device)
      tensor = tensor.to(device)
      ones = ones.to(device)
      tensorTwice = tensorTwice.to(device)
      onesTwice = onesTwice.to(device)
  
      embedding.zero_grad()
      embedding(tensor[0]).sum().backward()
      self.assertEqual(embedding.weight.grad._indices(), tensor)
      self.assertEqual(embedding.weight.grad._values(), ones)
  
      embedding.zero_grad()
      embedding(tensor[0]).sum().backward()
      embedding(tensor[0]).sum().backward()
      self.assertEqual(embedding.weight.grad._indices(), tensorTwice)
      self.assertEqual(embedding.weight.grad._values(), onesTwice)
  
      embedding.zero_grad()
      embedding(tensor[0]).sum().backward()
      tensor[0, 0] = 8
      embedding(tensor[0]).sum().backward()
      tensorTwice[0, 3] = 8
      self.assertEqual(embedding.weight.grad._indices(), tensorTwice)
      self.assertEqual(embedding.weight.grad._values(), onesTwice)
  
imports: import unittest
  import random
  import itertools
  from itertools import product
  import torch
  from torch.testing._internal.common_utils import run_tests, set_default_dtype, skipIfTorchDynamo, instantiate_parametrized_tests, parametrize, _assertGradAndGradgradChecks, IS_JETSON
  from torch.testing._internal.common_cuda import TEST_CUDA
  from torch.testing._internal.common_nn import NNTestCase
  from torch.testing._internal.common_device_type import onlyNativeDeviceTypes, dtypes, instantiate_device_type_tests, dtypesIfCUDA, onlyCUDA, TEST_WITH_ROCM, skipCUDAIf, skipMeta
  import torch.nn.functional
  import torch.nn
  from torch.testing._internal.common_utils import dtype2prec_DONTUSE
label_desc: Use image node_id 3 for calling the TestEmbeddingNNDeviceType obj's underlying member method code with example usage: obj.test_embedding_backward(device, dtype) without return types