class_docstr: Embedding for colossalai.
  
  Args:
      num_embeddings (int): number of embeddings.
      embedding_dim (int): dimension of embedding.
      padding_idx (int, optional): If specified, the entries at padding_idx do not contribute to the gradient;
          therefore, the embedding vector at padding_idx is not updated during training,
          i.e. it remains as a fixed “pad”, defaults to None.
      dtype (:class:`torch.dtype`, optional): The dtype of parameters, defaults to None.
      weight_initializer (:class:`typing.Callable`, optional):
          he initializer of weight, defaults to normal initializer.
  
  The ``args`` and ``kwargs`` used in :class:`torch.nn.functional.embedding` should contain:
  ::
  
      max_norm (float, optional): If given, each embedding vector with norm larger than max_norm is
                  renormalized to have norm max_norm. Note: this will modify weight in-place.
      norm_type (float, optional): The p of the p-norm to compute for the max_norm option. Default 2.
      scale_grad_by_freq (bool, optional): If given, this will scale gradients by the inverse
                  of frequency of the words in the mini-batch. Default False.
      sparse (bool, optional): If True, gradient w.r.t. weight will be a sparse tensor. Default False.
  
  More details about ``args`` and ``kwargs`` could be found in
  `Embedding <https://pytorch.org/docs/stable/generated/torch.nn.functional.embedding.html#torch.nn.functional.embedding>`_.
  
  More details about ``initializer`` please refer to
  `init <https://github.com/hpcaitech/ColossalAI/blob/main/colossalai/nn/init.py>`_
class_docstr_tok: ["Embedding","for","colossalai",".","Args",":","num_embeddings","(","int",")",":","number","of","embeddings",".","embedding_dim","(","int",")",":","dimension","of","embedding",".","padding_idx","(","int",",","optional",")",":","If","specified",",","the","entries","at","padding_idx","do","not","contribute","to","the","gradient",";","therefore",",","the","embedding","vector","at","padding_idx","is","not","updated","during","training",",","i.e",".","it","remains","as","a","fixed","\u201c","pad","\u201d",",","defaults","to","None",".","dtype","(",":","class",":","`","torch.dtype","`",",","optional",")",":","The","dtype","of","parameters",",","defaults","to","None",".","weight_initializer","(",":","class",":","`","typing.Callable","`",",","optional",")",":","he","initializer","of","weight",",","defaults","to","normal","initializer",".","The","``","args","``","and","``","kwargs","``","used","in",":","class",":","`","torch.nn.functional.embedding","`","should","contain",":",":",":","max_norm","(","float",",","optional",")",":","If","given",",","each","embedding","vector","with","norm","larger","than","max_norm","is","renormalized","to","have","norm","max_norm",".","Note",":","this","will","modify","weight","in-place",".","norm_type","(","float",",","optional",")",":","The","p","of","the","p-norm","to","compute","for","the","max_norm","option",".","Default","2.","scale_grad_by_freq","(","bool",",","optional",")",":","If","given",",","this","will","scale","gradients","by","the","inverse","of","frequency","of","the","words","in","the","mini-batch",".","Default","False",".","sparse","(","bool",",","optional",")",":","If","True",",","gradient","w.r.t",".","weight","will","be","a","sparse","tensor",".","Default","False",".","More","details","about","``","args","``","and","``","kwargs","``","could","be","found","in","`","Embedding","<","https",":","\/\/pytorch.org\/docs\/stable\/generated\/torch.nn.functional.embedding.html","#","torch.nn.functional.embedding",">","`","_",".","More","details","about","``","initializer","``","please","refer","to","`","init","<","https",":","\/\/github.com\/hpcaitech\/ColossalAI\/blob\/main\/colossalai\/nn\/init.py",">","`","_"]
code: def __init__(
      self,
      num_embeddings: int,
      embedding_dim: int,
      padding_idx: int = None,
      dtype: dtype = None,
      weight_initializer: Callable = init.normal_(),
      vocab_parallel_limit: int = 2048,
      *args,
      **kwargs,
  ) -> None:
      tensor_parallel = get_tensor_parallel_mode()
      if tensor_parallel is None:
          embed = (
              nn.Embedding(
                  num_embeddings,
                  embedding_dim,
                  padding_idx=padding_idx,
                  *args,
                  **kwargs,
              )
              .to(dtype)
              .to(get_current_device())
          )
          weight_initializer(
              embed.weight, fan_in=num_embeddings, fan_out=embedding_dim
          )
      elif num_embeddings <= vocab_parallel_limit:
          embed = _parallel_embedding[tensor_parallel](
              num_embeddings,
              embedding_dim,
              padding_idx=padding_idx,
              dtype=dtype,
              weight_initializer=weight_initializer,
              *args,
              **kwargs,
          )
      else:
          embed = _vocab_parallel_embedding[tensor_parallel](
              num_embeddings,
              embedding_dim,
              padding_idx=padding_idx,
              dtype=dtype,
              weight_initializer=weight_initializer,
              *args,
              **kwargs,
          )
      super().__init__(embed)
  
file_path: ColossalAI/colossalai/legacy/nn/layer/colossalai_layer/embedding.py
imports: import math
  from typing import Callable
  from torch import dtype, nn
  from colossalai.nn import init
  from colossalai.utils import get_current_device
  from ..parallel_1d import Embedding1D, PatchEmbedding1D, VocabParallelEmbedding1D
  from ..parallel_2d import Embedding2D, PatchEmbedding2D, VocabParallelEmbedding2D
  from ..parallel_2p5d import Embedding2p5D, PatchEmbedding2p5D, VocabParallelEmbedding2p5D
  from ..parallel_3d import Embedding3D, PatchEmbedding3D, VocabParallelEmbedding3D
  from ..utils import get_tensor_parallel_mode
  from ..vanilla import VanillaPatchEmbedding
  from ._utils import ColossalaiModule
label_desc: Use image node_id 1 to create a new Embedding object from inherited base classes: ColossalaiModule with example: obj = Embedding(num_embeddings, embedding_dim, padding_idx, dtype, weight_initializer, vocab_parallel_limit)