MCPcopy Create free account
hub / github.com/zai-org/CogView / __init__

Method __init__

mpu/layers.py:87–115  ·  view source on GitHub ↗
(self, num_embeddings, embedding_dim,
                 init_method=init.xavier_normal_)

Source from the content-addressed store, hash-verified

85 init_method: method to initialize weights.
86 """
87 def __init__(self, num_embeddings, embedding_dim,
88 init_method=init.xavier_normal_):
89 super(VocabParallelEmbedding, self).__init__()
90 # Keep the input dimensions.
91 self.num_embeddings = num_embeddings
92 self.embedding_dim = embedding_dim
93 # Set the detauls for compatibility.
94 self.padding_idx = None
95 self.max_norm = None
96 self.norm_type = 2.
97 self.scale_grad_by_freq = False
98 self.sparse = False
99 self._weight = None
100 # Divide the weight matrix along the vocaburaly dimension.
101 self.vocab_start_index, self.vocab_end_index = \
102 VocabUtility.vocab_range_from_global_vocab_size(
103 self.num_embeddings, get_model_parallel_rank(),
104 get_model_parallel_world_size())
105 self.num_embeddings_per_partition = self.vocab_end_index - \
106 self.vocab_start_index
107
108 # Allocate weights.
109 self.weight = Parameter(torch.Tensor(self.num_embeddings_per_partition,
110 self.embedding_dim))
111 self.weight.model_parallel = True
112 # And initialize.
113 _initialize_affine_weight(
114 self.weight, self.num_embeddings, self.embedding_dim,
115 self.num_embeddings_per_partition, 0, init_method)
116
117 def forward(self, input_):
118 # Build the mask.

Callers

nothing calls this directly

Calls 5

get_model_parallel_rankFunction · 0.85
__init__Method · 0.45

Tested by

no test coverage detected