class_docstr: Embedding parallelized in the vocabulary dimension.
  
  This is mainly adapted from torch.nn.Embedding and all the default
  values are kept.
  Arguments:
      num_embeddings: vocabulary size.
      embedding_dim: size of hidden state.
      init_method: method to initialize weights.
class_docstr_tok: ["Embedding","parallelized","in","the","vocabulary","dimension",".","This","is","mainly","adapted","from","torch.nn.Embedding","and","all","the","default","values","are","kept",".","Arguments",":","num_embeddings",":","vocabulary","size",".","embedding_dim",":","size","of","hidden","state",".","init_method",":","method","to","initialize","weights","."]
code: def __init__(
      self,
      num_embeddings: int,
      embedding_dim: int,
      padding_idx: Optional[int] = None,
      max_norm: Optional[float] = None,
      norm_type: float = 2.0,
      scale_grad_by_freq: bool = False,
      sparse: bool = False,
      init_method: Callable[
          [torch.Tensor], torch.Tensor
      ] = init.xavier_normal_,
  ) -> None:
      super(VocabParallelEmbedding, self).__init__()
      # Keep the input dimensions.
      self.num_embeddings = num_embeddings
      self.embedding_dim = embedding_dim
      self.padding_idx = padding_idx
      self.max_norm = max_norm
      self.norm_type = norm_type
      self.scale_grad_by_freq = scale_grad_by_freq
      self.sparse = sparse
      self._weight = None
      # Divide the weight matrix along the vocaburaly dimension.
      (
          self.vocab_start_index,
          self.vocab_end_index,
      ) = VocabUtility.vocab_range_from_global_vocab_size(
          self.num_embeddings,
          get_model_parallel_rank(),
          get_model_parallel_world_size(),
      )
      self.num_embeddings_per_partition = (
          self.vocab_end_index - self.vocab_start_index
      )
  
      # Allocate weights.
      self.weight = Parameter(
          torch.Tensor(
              self.num_embeddings_per_partition, self.embedding_dim
          )
      )
      # And initialize.
      _initialize_affine_weight(
          self.weight,
          self.num_embeddings,
          self.embedding_dim,
          self.num_embeddings_per_partition,
          0,
          init_method,
      )
  
imports: from typing import Callable, Optional
  import torch
  import torch.nn.functional
  import torch.nn.init
  from torch.nn.parameter import Parameter
  from .initialize import get_model_parallel_rank, get_model_parallel_world_size
  from .mappings import copy_to_model_parallel_region, gather_from_model_parallel_region, reduce_from_model_parallel_region, scatter_to_model_parallel_region
  from .utils import VocabUtility, divide_and_check_no_remainder
label_desc: Use image node_id 1 to create a new VocabParallelEmbedding object from inherited base classes: torch.nn with example: obj = VocabParallelEmbedding(num_embeddings, embedding_dim, padding_idx, max_norm, norm_type, scale_grad_by_freq, sparse, init_method)