code: def async_update(args, emb, queue):
      """Asynchronous embedding update for entity embeddings.
      How it works:
          1. trainer process push entity embedding update requests into the queue.
          2. async_update process pull requests from the queue, calculate
             the gradient state and gradient and write it into entity embeddings.
  
      Parameters
      ----------
      args :
          Global confis.
      emb : ExternalEmbedding
          The entity embeddings.
      queue:
          The request queue.
      """
      th.set_num_threads(args.num_thread)
      while True:
          (grad_indices, grad_values, gpu_id) = queue.get()
          clr = emb.args.lr
          if grad_indices is None:
              return
          with th.no_grad():
              grad_sum = (grad_values * grad_values).mean(1)
              device = emb.state_sum.device
              if device != grad_indices.device:
                  grad_indices = grad_indices.to(device)
              if device != grad_sum.device:
                  grad_sum = grad_sum.to(device)
  
              emb.state_sum.index_add_(0, grad_indices, grad_sum)
              std = emb.state_sum[grad_indices]  # _sparse_mask
              if gpu_id >= 0:
                  std = std.cuda(gpu_id)
              std_values = std.sqrt_().add_(1e-10).unsqueeze(1)
              tmp = -clr * grad_values / std_values
              if tmp.device != device:
                  tmp = tmp.to(device)
              emb.emb.index_add_(0, grad_indices, tmp)
  
imports: import os
  import numpy
  import torch
  import torch.nn
  import torch.nn.functional
  import torch.nn.init
  import torch.multiprocessing
  from torch.multiprocessing import Queue
  from _thread import start_new_thread
  import traceback
  from functools import wraps
  from ..None import *
label_desc: Use image node_id 12 for calling a global function with example usage: async_update(args, emb, queue) without return types