def async_update(num_threads, model, queue):
    """Asynchronous embedding update for entity embeddings."""
    torch.set_num_threads(num_threads)
    print("async start")
    while True:
        (grad_u, grad_v, grad_v_neg, nodes, neg_nodes, first_flag) = queue.get()
        if grad_u is None:
            return
        with torch.no_grad():
            if first_flag:
                model.fst_u_embeddings.weight.data.index_add_(
                    0, nodes[:, 0], grad_u
                )
                model.fst_u_embeddings.weight.data.index_add_(
                    0, nodes[:, 1], grad_v
                )
                if neg_nodes is not None:
                    model.fst_u_embeddings.weight.data.index_add_(
                        0, neg_nodes, grad_v_neg
                    )
            else:
                model.snd_u_embeddings.weight.data.index_add_(
                    0, nodes[:, 0], grad_u
                )
                model.snd_v_embeddings.weight.data.index_add_(
                    0, nodes[:, 1], grad_v
                )
                if neg_nodes is not None:
                    model.snd_v_embeddings.weight.data.index_add_(
                        0, neg_nodes, grad_v_neg
                    )
Asynchronous embedding update for entity embeddings.
examples/pytorch/ogb/line/model.py