class_docstr: Distributed node embeddings.
  
  DGL provides a distributed embedding to support models that require learnable embeddings.
  DGL's distributed embeddings are mainly used for learning node embeddings of graph models.
  Because distributed embeddings are part of a model, they are updated by mini-batches.
  The distributed embeddings have to be updated by DGL's optimizers instead of
  the optimizers provided by the deep learning frameworks (e.g., Pytorch and MXNet).
  
  To support efficient training on a graph with many nodes, the embeddings support sparse
  updates. That is, only the embeddings involved in a mini-batch computation are updated.
  Please refer to `Distributed Optimizers <https://docs.dgl.ai/api/python/dgl.distributed.html#
  distributed-embedding-optimizer>`__ for available optimizers in DGL.
  
  Distributed embeddings are sharded and stored in a cluster of machines in the same way as
  :class:`dgl.distributed.DistTensor`, except that distributed embeddings are trainable.
  Because distributed embeddings are sharded
  in the same way as nodes and edges of a distributed graph, it is usually much more
  efficient to access than the sparse embeddings provided by the deep learning frameworks.
  
  Parameters
  ----------
  num_embeddings : int
      The number of embeddings. Currently, the number of embeddings has to be the same as
      the number of nodes or the number of edges.
  embedding_dim : int
      The dimension size of embeddings.
  name : str, optional
      The name of the embeddings. The name can uniquely identify embeddings in a system
      so that another DistEmbedding object can referent to the same embeddings.
  init_func : callable, optional
      The function to create the initial data. If the init function is not provided,
      the values of the embeddings are initialized to zero.
  part_policy : PartitionPolicy, optional
      The partition policy that assigns embeddings to different machines in the cluster.
      Currently, it only supports node partition policy or edge partition policy.
      The system determines the right partition policy automatically.
  
  Examples
  --------
  >>> def initializer(shape, dtype):
          arr = th.zeros(shape, dtype=dtype)
          arr.uniform_(-1, 1)
          return arr
  >>> emb = dgl.distributed.DistEmbedding(g.num_nodes(), 10, init_func=initializer)
  >>> optimizer = dgl.distributed.optim.SparseAdagrad([emb], lr=0.001)
  >>> for blocks in dataloader:
  ...     feats = emb(nids)
  ...     loss = F.sum(feats + 1, 0)
  ...     loss.backward()
  ...     optimizer.step()
  
  Note
  ----
  When a ``DistEmbedding``  object is used in the forward computation, users
  have to invoke
  :py:meth:`~dgl.distributed.optim.SparseAdagrad.step` afterwards. Otherwise,
  there will be some memory leak.
class_docstr_tok: ["Distributed","node","embeddings",".","DGL","provides","a","distributed","embedding","to","support","models","that","require","learnable","embeddings",".","DGL","'s","distributed","embeddings","are","mainly","used","for","learning","node","embeddings","of","graph","models",".","Because","distributed","embeddings","are","part","of","a","model",",","they","are","updated","by","mini-batches",".","The","distributed","embeddings","have","to","be","updated","by","DGL","'s","optimizers","instead","of","the","optimizers","provided","by","the","deep","learning","frameworks","(","e.g.",",","Pytorch","and","MXNet",")",".","To","support","efficient","training","on","a","graph","with","many","nodes",",","the","embeddings","support","sparse","updates",".","That","is",",","only","the","embeddings","involved","in","a","mini-batch","computation","are","updated",".","Please","refer","to","`","Distributed","Optimizers","<","https",":","\/\/docs.dgl.ai\/api\/python\/dgl.distributed.html","#","distributed-embedding-optimizer",">","`","__","for","available","optimizers","in","DGL",".","Distributed","embeddings","are","sharded","and","stored","in","a","cluster","of","machines","in","the","same","way","as",":","class",":","`","dgl.distributed.DistTensor","`",",","except","that","distributed","embeddings","are","trainable",".","Because","distributed","embeddings","are","sharded","in","the","same","way","as","nodes","and","edges","of","a","distributed","graph",",","it","is","usually","much","more","efficient","to","access","than","the","sparse","embeddings","provided","by","the","deep","learning","frameworks",".","Parameters","--","--","--","--","--","num_embeddings",":","int","The","number","of","embeddings",".","Currently",",","the","number","of","embeddings","has","to","be","the","same","as","the","number","of","nodes","or","the","number","of","edges",".","embedding_dim",":","int","The","dimension","size","of","embeddings",".","name",":","str",",","optional","The","name","of","the","embeddings",".","The","name","can","uniquely","identify","embeddings","in","a","system","so","that","another","DistEmbedding","object","can","referent","to","the","same","embeddings",".","init_func",":","callable",",","optional","The","function","to","create","the","initial","data",".","If","the","init","function","is","not","provided",",","the","values","of","the","embeddings","are","initialized","to","zero",".","part_policy",":","PartitionPolicy",",","optional","The","partition","policy","that","assigns","embeddings","to","different","machines","in","the","cluster",".","Currently",",","it","only","supports","node","partition","policy","or","edge","partition","policy",".","The","system","determines","the","right","partition","policy","automatically",".","Examples","--","--","--","--",">",">",">","def","initializer","(","shape",",","dtype",")",":","arr","=","th.zeros","(","shape",",","dtype=dtype",")","arr.uniform_","(","-1",",","1",")","return","arr",">",">",">","emb","=","dgl.distributed.DistEmbedding","(","g.num_nodes","(",")",",","10",",","init_func=initializer",")",">",">",">","optimizer","=","dgl.distributed.optim.SparseAdagrad","(","[","emb","]",",","lr=0.001",")",">",">",">","for","blocks","in","dataloader",":","...","feats","=","emb","(","nids",")","...","loss","=","F.sum","(","feats","+","1",",","0",")","...","loss.backward","(",")","...","optimizer.step","(",")","Note","--","--","When","a","``","DistEmbedding","``","object","is","used","in","the","forward","computation",",","users","have","to","invoke",":","py",":","meth",":","`","~dgl.distributed.optim.SparseAdagrad.step","`","afterwards",".","Otherwise",",","there","will","be","some","memory","leak","."]
docstr: Return the tensor storing the node embeddings
  
  Returns
  -------
  torch.Tensor
      The tensor storing the node embeddings
docstr_tok: ["Return","the","tensor","storing","the","node","embeddings","Returns","--","--","--","-","torch.Tensor","The","tensor","storing","the","node","embeddings"]
code: def weight(self):
      """Return the tensor storing the node embeddings
  
      Returns
      -------
      torch.Tensor
          The tensor storing the node embeddings
      """
      return self._tensor
  
file_path: dgl/python/dgl/distributed/nn/pytorch/sparse_emb.py
imports: import torch
  from ....None import backend, utils
  from ...dist_tensor import DistTensor
label_desc: Use image node_id 11 for calling the DistEmbedding obj's underlying member method code with example usage: obj.weight() and returns: self