Aobangaming commited on
Commit
9a1cce8
·
verified ·
1 Parent(s): 19bafe1

Upload folder using huggingface_hub

Browse files
config.json ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "LightningForCausalLM"
4
+ ],
5
+ "d_model": 256,
6
+ "dropout": 0.1,
7
+ "dtype": "float32",
8
+ "max_seq_len": 160,
9
+ "model_type": "lightning",
10
+ "nhead": 4,
11
+ "num_layers": 4,
12
+ "transformers_version": "4.57.3",
13
+ "vocab_size": 50000,
14
+ "auto_map": {
15
+ "AutoConfig": "configuration_lightning.LightningConfig",
16
+ "AutoModelForCausalLM": "modeling_lightning.LightningForCausalLM"
17
+ }
18
+ }
configuration_lightning.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import PretrainedConfig
2
+
3
+
4
+ class LightningConfig(PretrainedConfig):
5
+ model_type = "lightning"
6
+
7
+ def __init__(
8
+ self,
9
+ vocab_size=50000,
10
+ d_model=256,
11
+ nhead=4,
12
+ num_layers=4,
13
+ dropout=0.1,
14
+ max_seq_len=160,
15
+ **kwargs
16
+ ):
17
+ super().__init__(
18
+ tie_word_embeddings=False,
19
+ **kwargs
20
+ )
21
+
22
+ self.vocab_size = vocab_size
23
+ self.d_model = d_model
24
+ self.nhead = nhead
25
+ self.num_layers = num_layers
26
+ self.dropout = dropout
27
+ self.max_seq_len = max_seq_len
modeling_lightning.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import torch.nn as nn
3
+
4
+ from transformers import PreTrainedModel
5
+ from transformers.modeling_outputs import CausalLMOutput
6
+
7
+ from configuration_lightning import LightningConfig
8
+ from model import TransformerLanguageModel
9
+
10
+
11
+ class LightningForCausalLM(PreTrainedModel):
12
+
13
+ config_class = LightningConfig
14
+ base_model_prefix = "lightning"
15
+
16
+ def __init__(self, config):
17
+ super().__init__(config)
18
+
19
+ self.lightning = TransformerLanguageModel(
20
+ vocab_size=config.vocab_size,
21
+ d_model=config.d_model,
22
+ nhead=config.nhead,
23
+ num_layers=config.num_layers,
24
+ dropout=config.dropout,
25
+ max_seq_len=config.max_seq_len
26
+ )
27
+
28
+ self.post_init()
29
+
30
+ def forward(self, input_ids=None, labels=None, **kwargs):
31
+ logits = self.lightning(input_ids)
32
+
33
+ loss = None
34
+
35
+ if labels is not None:
36
+ shift_logits = logits[..., :-1, :].contiguous()
37
+ shift_labels = labels[..., 1:].contiguous()
38
+
39
+ loss_fn = nn.CrossEntropyLoss()
40
+
41
+ loss = loss_fn(
42
+ shift_logits.view(-1, shift_logits.size(-1)),
43
+ shift_labels.view(-1)
44
+ )
45
+
46
+ return CausalLMOutput(
47
+ loss=loss,
48
+ logits=logits
49
+ )
50
+
51
+ def get_input_embeddings(self):
52
+ return self.lightning.token_embedding
53
+
54
+ def set_input_embeddings(self, value):
55
+ self.lightning.token_embedding = value
56
+
57
+ def get_output_embeddings(self):
58
+ return self.lightning.output_layer
59
+
60
+ def set_output_embeddings(self, new_embeddings):
61
+ self.lightning.output_layer = new_embeddings
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2f13c912ae94bf1109ab3662c42fd4358a020dfa5e03bfc9f7d9571e9e925582
3
+ size 115219558