rmihaylov commited on
Commit
1812276
1 Parent(s): 1fe36c6
Files changed (3) hide show
  1. config.json +36 -0
  2. modeling_gpt2.py +32 -0
  3. pytorch_model.bin +3 -0
config.json ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "/content/drive/MyDrive/ColabModels/GPT2SmallTheseus/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": 768,
19
+ "n_head": 12,
20
+ "n_inner": null,
21
+ "n_layer": 6,
22
+ "n_positions": 1024,
23
+ "reorder_and_upcast_attn": false,
24
+ "resid_pdrop": 0.1,
25
+ "scale_attn_by_inverse_layer_idx": false,
26
+ "scale_attn_weights": true,
27
+ "summary_activation": null,
28
+ "summary_first_dropout": 0.1,
29
+ "summary_proj_to_labels": true,
30
+ "summary_type": "cls_index",
31
+ "summary_use_proj": true,
32
+ "torch_dtype": "float32",
33
+ "transformers_version": "4.18.0",
34
+ "use_cache": true,
35
+ "vocab_size": 50257
36
+ }
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:e20db5c11921f7238bb88123f2b19d9dd13b7b67d7c1345ace9f30876823ed93
3
+ size 333967901