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

Method __init__

codegeex/megatron/model/language_model.py:114–162  ·  view source on GitHub ↗
(
        self,
        hidden_size,
        vocab_size,
        max_sequence_length,
        embedding_dropout_prob,
        init_method,
        num_tokentypes=0,
    )

Source from the content-addressed store, hash-verified

112 """
113
114 def __init__(
115 self,
116 hidden_size,
117 vocab_size,
118 max_sequence_length,
119 embedding_dropout_prob,
120 init_method,
121 num_tokentypes=0,
122 ):
123 super(Embedding, self).__init__()
124
125 args = get_args()
126
127 self.hidden_size = hidden_size
128 self.init_method = init_method
129 self.num_tokentypes = num_tokentypes
130 self.max_sequence_length = max_sequence_length
131
132 # Word embeddings (parallel).
133 self.word_embeddings = mpu.VocabParallelEmbedding(
134 vocab_size, self.hidden_size, init_method=self.init_method)
135 self._word_embeddings_key = 'word_embeddings'
136
137 self.vocab_size = vocab_size
138
139 # Position embedding (serial).
140 self.position_embeddings = torch.nn.Embedding(
141 max_sequence_length, self.hidden_size)
142 self.position_embeddings = self.position_embeddings.half()
143 self._position_embeddings_key = 'position_embeddings'
144
145 # Initialize the position embeddings.
146 self.init_method(self.position_embeddings.weight)
147
148 # Token type embedding.
149 # Add this as an optional field that can be added through
150 # method call so we can load a pretrain model without
151 # token types and add them as needed.
152 self._tokentype_embeddings_key = 'tokentype_embeddings'
153 if self.num_tokentypes > 0:
154 self.tokentype_embeddings = torch.nn.Embedding(self.num_tokentypes,
155 self.hidden_size)
156 # Initialize the token-type embeddings.
157 self.init_method(self.tokentype_embeddings.weight)
158 else:
159 self.tokentype_embeddings = None
160
161 # Embeddings dropout
162 self.embedding_dropout = torch.nn.Dropout(embedding_dropout_prob)
163
164 def add_tokentype_embeddings(self, num_tokentypes):
165 """Add token-type embedding. This function is provided so we can add

Callers 2

__init__Method · 0.45
__init__Method · 0.45

Calls 1

get_argsFunction · 0.90

Tested by

no test coverage detected