Upload modeling_modern_llm.py with huggingface_hub
Browse files- modeling_modern_llm.py +9 -0
modeling_modern_llm.py
CHANGED
|
@@ -107,6 +107,15 @@ class ModernLLMForCausalLM(PreTrainedModel):
|
|
| 107 |
self.rotary_emb = RotaryEmbedding(config.hidden_size // config.num_attention_heads, config.max_position_embeddings, config.rope_theta)
|
| 108 |
self.post_init()
|
| 109 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
def forward(self, input_ids, labels=None, **kwargs):
|
| 111 |
_, seq_len = input_ids.shape
|
| 112 |
x = self.embed_tokens(input_ids)
|
|
|
|
| 107 |
self.rotary_emb = RotaryEmbedding(config.hidden_size // config.num_attention_heads, config.max_position_embeddings, config.rope_theta)
|
| 108 |
self.post_init()
|
| 109 |
|
| 110 |
+
def _init_weights(self, module):
|
| 111 |
+
std = 0.02
|
| 112 |
+
if isinstance(module, nn.Linear):
|
| 113 |
+
module.weight.data.normal_(mean=0.0, std=std)
|
| 114 |
+
if module.bias is not None:
|
| 115 |
+
module.bias.data.zero_()
|
| 116 |
+
elif isinstance(module, nn.Embedding):
|
| 117 |
+
module.weight.data.normal_(mean=0.0, std=std)
|
| 118 |
+
|
| 119 |
def forward(self, input_ids, labels=None, **kwargs):
|
| 120 |
_, seq_len = input_ids.shape
|
| 121 |
x = self.embed_tokens(input_ids)
|