rmihaylov commited on
Commit
a0a9adf
1 Parent(s): 3770f02
Files changed (3) hide show
  1. config.json +44 -0
  2. modeling_gpt2.py +32 -0
  3. pytorch_model.bin +3 -0
config.json ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "/content/drive/MyDrive/ColabModels/GPT2_MEDIUM/pytorch_model/",
3
+ "activation_function": "gelu_new",
4
+ "architectures": [
5
+ "GPT2LMHeadModel"
6
+ ],
7
+ "attn_pdrop": 0.1,
8
+ "auto_map": {
9
+ "AutoModel": "modeling_gpt2.GPT2LMHeadModel"
10
+ },
11
+ "bos_token_id": 50256,
12
+ "embd_pdrop": 0.1,
13
+ "eos_token_id": 50256,
14
+ "initializer_range": 0.02,
15
+ "layer_norm_epsilon": 1e-05,
16
+ "model_type": "gpt2",
17
+ "n_ctx": 1024,
18
+ "n_embd": 1024,
19
+ "n_head": 16,
20
+ "n_inner": null,
21
+ "n_layer": 24,
22
+ "n_positions": 1024,
23
+ "n_special": 0,
24
+ "predict_special_tokens": true,
25
+ "reorder_and_upcast_attn": false,
26
+ "resid_pdrop": 0.1,
27
+ "scale_attn_by_inverse_layer_idx": false,
28
+ "scale_attn_weights": true,
29
+ "summary_activation": null,
30
+ "summary_first_dropout": 0.1,
31
+ "summary_proj_to_labels": true,
32
+ "summary_type": "cls_index",
33
+ "summary_use_proj": true,
34
+ "task_specific_params": {
35
+ "text-generation": {
36
+ "do_sample": true,
37
+ "max_length": 50
38
+ }
39
+ },
40
+ "torch_dtype": "float32",
41
+ "transformers_version": "4.18.0",
42
+ "use_cache": true,
43
+ "vocab_size": 50257
44
+ }
modeling_gpt2.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from torch import nn
2
+
3
+ from transformers import GPT2LMHeadModel as GPT2LMHeadModelBase
4
+ from transformers.models.gpt2.modeling_gpt2 import GPT2Block as GPT2BlockBase
5
+
6
+
7
+ class GPT2Block(GPT2BlockBase):
8
+ def forward(self, x, layer_past=None,
9
+ attention_mask=None, head_mask=None, use_cache=False,
10
+ encoder_hidden_states=None, encoder_attention_mask=None, output_attentions=None):
11
+
12
+ x = self.ln_1(x)
13
+ output_attn = self.attn(
14
+ x, layer_past=layer_past,
15
+ attention_mask=attention_mask,
16
+ head_mask=head_mask,
17
+ use_cache=use_cache)
18
+
19
+ a = output_attn[0]
20
+ x = x + a
21
+
22
+ m = self.mlp(self.ln_2(x))
23
+ x = x + m
24
+
25
+ outputs = (x,) + output_attn[1:]
26
+ return outputs
27
+
28
+
29
+ class GPT2LMHeadModel(GPT2LMHeadModelBase):
30
+ def __init__(self, config):
31
+ super().__init__(config)
32
+ self.transformer.h = nn.ModuleList([GPT2Block(config, layer_idx) for layer_idx in range(config.n_layer)])
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9ac587d8e665b3567fd1575458c3f6870a1b9b712221a56879633af7ea0b5013
3
+ size 1444562137