code: def test_sparse_adam(emb_dim):
      num_embs = 10
      device = F.ctx()
      dgl_emb = NodeEmbedding(num_embs, emb_dim, "test")
      torch_emb = th.nn.Embedding(num_embs, emb_dim, sparse=True)
      th.manual_seed(0)
      th.nn.init.uniform_(torch_emb.weight, 0, 1.0)
      th.manual_seed(0)
      th.nn.init.uniform_(dgl_emb.weight, 0, 1.0)
  
      dgl_adam = SparseAdam(params=[dgl_emb], lr=0.01)
      torch_adam = th.optim.SparseAdam(
          list(torch_emb.parameters()), lr=0.01
      )
  
      # first step
      idx = th.randint(0, num_embs, size=(4,))
      dgl_value = dgl_emb(idx, device).to(th.device("cpu"))
      torch_value = torch_emb(idx)
      labels = th.zeros((4,)).long()
      print("dgl_value = {}".format(dgl_value))
      print("labels = {}".format(labels))
  
      dgl_adam.zero_grad()
      torch_adam.zero_grad()
      dgl_loss = th.nn.functional.cross_entropy(dgl_value, labels)
      torch_loss = th.nn.functional.cross_entropy(torch_value, labels)
      dgl_loss.backward()
      torch_loss.backward()
  
      dgl_adam.step()
      torch_adam.step()
      assert F.allclose(dgl_emb.weight, torch_emb.weight)
  
imports: import os
  import unittest
  import backend
  import pytest
  import torch
  import torch.multiprocessing
  from dgl.nn import NodeEmbedding
  from dgl.optim import SparseAdagrad, SparseAdam
label_desc: Use image node_id 1 for calling a global function with example usage: test_sparse_adam(emb_dim) without return types