Ma7ee7 commited on
Commit
5bef0ce
·
verified ·
1 Parent(s): afedf3f

Upload character-level GPT model for WikiText-2

Browse files
config.json ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "model_type": "custom_char_gpt",
3
+ "vocab_size": 283,
4
+ "n_layer": 8,
5
+ "n_head": 8,
6
+ "n_embd": 512,
7
+ "block_size": 512,
8
+ "dropout": 0.1,
9
+ "architectures": [
10
+ "GPTLanguageModel"
11
+ ]
12
+ }
modeling_custom_char_gpt.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # ACTION REQUIRED: Manually copy model code here.
2
+ # See warning message in notebook output.
3
+
4
+ # Add imports like:
5
+ # import torch
6
+ # import torch.nn as nn
7
+ # etc.
8
+
9
+
10
+ import torch
11
+ import torch.nn as nn
12
+ from torch.nn import functional as F
13
+ import math
14
+
15
+ # --- RoPE Helper Functions (Copied for model file) ---
16
+ def precompute_freqs_cis(dim: int, end: int, theta: float = 10000.0, device='cpu'):
17
+ freqs_part = torch.arange(0, dim, 2)[: (dim // 2)].float() / dim
18
+ freqs = 1.0 / (theta ** freqs_part).to(device)
19
+ t = torch.arange(end, device=device)
20
+ freqs = torch.outer(t, freqs).float()
21
+ freqs_cis = torch.polar(torch.ones_like(freqs), freqs)
22
+ return freqs_cis
23
+
24
+ def reshape_for_broadcast(freqs_cis: torch.Tensor, x: torch.Tensor):
25
+ ndim = x.ndim
26
+ assert 0 <= 1 < ndim
27
+ if not freqs_cis.shape == (x.shape[1], x.shape[-1]): # Check dimensions used
28
+ raise ValueError(f"Freqs shape {freqs_cis.shape} does not match x shape {x.shape} at dims 1 and -1")
29
+ shape = [1] * (ndim - 2) + list(freqs_cis.shape)
30
+ return freqs_cis.view(*shape)
31
+
32
+ def apply_rotary_emb(xq: torch.Tensor, xk: torch.Tensor, freqs_cis: torch.Tensor):
33
+ xq_ = torch.view_as_complex(xq.float().reshape(*xq.shape[:-1], -1, 2))
34
+ xk_ = torch.view_as_complex(xk.float().reshape(*xk.shape[:-1], -1, 2))
35
+ freqs_cis = reshape_for_broadcast(freqs_cis, xq_)
36
+ xq_out_complex = xq_ * freqs_cis
37
+ xk_out_complex = xk_ * freqs_cis
38
+ xq_out = torch.view_as_real(xq_out_complex).flatten(start_dim=2)
39
+ xk_out = torch.view_as_real(xk_out_complex).flatten(start_dim=2)
40
+ return xq_out.type_as(xq), xk_out.type_as(xk)
41
+ # --- End RoPE Helpers ---
42
+
43
+ # --- Add Head Class Definition Below ---
44
+
45
+
46
+ # --- Add MultiHeadAttention Class Definition Below ---
47
+
48
+
49
+ # --- Add SwiGLU Class Definition Below ---
50
+
51
+
52
+ # --- Add Block Class Definition Below ---
53
+
54
+
55
+ # --- Add GPTLanguageModel Class Definition Below ---
56
+
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:a1628986e6edc29e91d6a43957ee7351b2afca2a1f08642b2912524f8723bf8e
3
+ size 169386430
tokenizer_config.json ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {
2
+ "model_max_length": 512,
3
+ "tokenizer_class": "CustomCharTokenizer",
4
+ "vocab_size": 283,
5
+ "chars": "\n !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^`abcdefghijklmnopqrstuvwxyz|~¡£¥§°±²³µ·½ÁÅÆÉÍÎÖרÚÜÞàáâãäåçèéêëìíîñòóôöøúûüĀāăćčĐđėīŁłńŌōśşšūųŻžơưʻʿ̃αβγκμСавекостяاحصلنه्กงณตมยรลัาิ่์გდვზიკორსუცძწხჯ჻ḥṃṅṣṭṯảấầắễệịớửỳ‑–—‘’“”„†…′″⁄₤€₹⅓⅔→−≤☉♭♯〈〉のァアキスットプュリルヴ・動場大戦攻機殻火礮空隊~"
6
+ }
vocab.json ADDED
@@ -0,0 +1,285 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "\n": 0,
3
+ " ": 1,
4
+ "!": 2,
5
+ "\"": 3,
6
+ "#": 4,
7
+ "$": 5,
8
+ "%": 6,
9
+ "&": 7,
10
+ "'": 8,
11
+ "(": 9,
12
+ ")": 10,
13
+ "*": 11,
14
+ "+": 12,
15
+ ",": 13,
16
+ "-": 14,
17
+ ".": 15,
18
+ "/": 16,
19
+ "0": 17,
20
+ "1": 18,
21
+ "2": 19,
22
+ "3": 20,
23
+ "4": 21,
24
+ "5": 22,
25
+ "6": 23,
26
+ "7": 24,
27
+ "8": 25,
28
+ "9": 26,
29
+ ":": 27,
30
+ ";": 28,
31
+ "<": 29,
32
+ "=": 30,
33
+ ">": 31,
34
+ "?": 32,
35
+ "@": 33,
36
+ "A": 34,
37
+ "B": 35,
38
+ "C": 36,
39
+ "D": 37,
40
+ "E": 38,
41
+ "F": 39,
42
+ "G": 40,
43
+ "H": 41,
44
+ "I": 42,
45
+ "J": 43,
46
+ "K": 44,
47
+ "L": 45,
48
+ "M": 46,
49
+ "N": 47,
50
+ "O": 48,
51
+ "P": 49,
52
+ "Q": 50,
53
+ "R": 51,
54
+ "S": 52,
55
+ "T": 53,
56
+ "U": 54,
57
+ "V": 55,
58
+ "W": 56,
59
+ "X": 57,
60
+ "Y": 58,
61
+ "Z": 59,
62
+ "[": 60,
63
+ "\\": 61,
64
+ "]": 62,
65
+ "^": 63,
66
+ "`": 64,
67
+ "a": 65,
68
+ "b": 66,
69
+ "c": 67,
70
+ "d": 68,
71
+ "e": 69,
72
+ "f": 70,
73
+ "g": 71,
74
+ "h": 72,
75
+ "i": 73,
76
+ "j": 74,
77
+ "k": 75,
78
+ "l": 76,
79
+ "m": 77,
80
+ "n": 78,
81
+ "o": 79,
82
+ "p": 80,
83
+ "q": 81,
84
+ "r": 82,
85
+ "s": 83,
86
+ "t": 84,
87
+ "u": 85,
88
+ "v": 86,
89
+ "w": 87,
90
+ "x": 88,
91
+ "y": 89,
92
+ "z": 90,
93
+ "|": 91,
94
+ "~": 92,
95
+ "¡": 93,
96
+ "£": 94,
97
+ "¥": 95,
98
+ "§": 96,
99
+ "°": 97,
100
+ "±": 98,
101
+ "²": 99,
102
+ "³": 100,
103
+ "µ": 101,
104
+ "·": 102,
105
+ "½": 103,
106
+ "Á": 104,
107
+ "Å": 105,
108
+ "Æ": 106,
109
+ "É": 107,
110
+ "Í": 108,
111
+ "Î": 109,
112
+ "Ö": 110,
113
+ "×": 111,
114
+ "Ø": 112,
115
+ "Ú": 113,
116
+ "Ü": 114,
117
+ "Þ": 115,
118
+ "à": 116,
119
+ "á": 117,
120
+ "â": 118,
121
+ "ã": 119,
122
+ "ä": 120,
123
+ "å": 121,
124
+ "ç": 122,
125
+ "è": 123,
126
+ "é": 124,
127
+ "ê": 125,
128
+ "ë": 126,
129
+ "ì": 127,
130
+ "í": 128,
131
+ "î": 129,
132
+ "ñ": 130,
133
+ "ò": 131,
134
+ "ó": 132,
135
+ "ô": 133,
136
+ "ö": 134,
137
+ "ø": 135,
138
+ "ú": 136,
139
+ "û": 137,
140
+ "ü": 138,
141
+ "Ā": 139,
142
+ "ā": 140,
143
+ "ă": 141,
144
+ "ć": 142,
145
+ "č": 143,
146
+ "Đ": 144,
147
+ "đ": 145,
148
+ "ė": 146,
149
+ "ī": 147,
150
+ "Ł": 148,
151
+ "ł": 149,
152
+ "ń": 150,
153
+ "Ō": 151,
154
+ "ō": 152,
155
+ "ś": 153,
156
+ "ş": 154,
157
+ "š": 155,
158
+ "ū": 156,
159
+ "ų": 157,
160
+ "Ż": 158,
161
+ "ž": 159,
162
+ "ơ": 160,
163
+ "ư": 161,
164
+ "ʻ": 162,
165
+ "ʿ": 163,
166
+ "̃": 164,
167
+ "α": 165,
168
+ "β": 166,
169
+ "γ": 167,
170
+ "κ": 168,
171
+ "μ": 169,
172
+ "С": 170,
173
+ "а": 171,
174
+ "в": 172,
175
+ "е": 173,
176
+ "к": 174,
177
+ "о": 175,
178
+ "с": 176,
179
+ "т": 177,
180
+ "я": 178,
181
+ "ا": 179,
182
+ "ح": 180,
183
+ "ص": 181,
184
+ "ل": 182,
185
+ "ن": 183,
186
+ "ه": 184,
187
+ "्": 185,
188
+ "ก": 186,
189
+ "ง": 187,
190
+ "ณ": 188,
191
+ "ต": 189,
192
+ "ม": 190,
193
+ "ย": 191,
194
+ "ร": 192,
195
+ "ล": 193,
196
+ "ั": 194,
197
+ "า": 195,
198
+ "ิ": 196,
199
+ "่": 197,
200
+ "์": 198,
201
+ "გ": 199,
202
+ "დ": 200,
203
+ "ვ": 201,
204
+ "ზ": 202,
205
+ "ი": 203,
206
+ "კ": 204,
207
+ "ო": 205,
208
+ "რ": 206,
209
+ "ს": 207,
210
+ "უ": 208,
211
+ "ც": 209,
212
+ "ძ": 210,
213
+ "წ": 211,
214
+ "ხ": 212,
215
+ "ჯ": 213,
216
+ "჻": 214,
217
+ "ḥ": 215,
218
+ "ṃ": 216,
219
+ "ṅ": 217,
220
+ "ṣ": 218,
221
+ "ṭ": 219,
222
+ "ṯ": 220,
223
+ "ả": 221,
224
+ "ấ": 222,
225
+ "ầ": 223,
226
+ "ắ": 224,
227
+ "ễ": 225,
228
+ "ệ": 226,
229
+ "ị": 227,
230
+ "ớ": 228,
231
+ "ử": 229,
232
+ "ỳ": 230,
233
+ "‑": 231,
234
+ "–": 232,
235
+ "—": 233,
236
+ "‘": 234,
237
+ "’": 235,
238
+ "“": 236,
239
+ "”": 237,
240
+ "„": 238,
241
+ "†": 239,
242
+ "…": 240,
243
+ "′": 241,
244
+ "″": 242,
245
+ "⁄": 243,
246
+ "₤": 244,
247
+ "€": 245,
248
+ "₹": 246,
249
+ "⅓": 247,
250
+ "⅔": 248,
251
+ "→": 249,
252
+ "−": 250,
253
+ "≤": 251,
254
+ "☉": 252,
255
+ "♭": 253,
256
+ "♯": 254,
257
+ "〈": 255,
258
+ "〉": 256,
259
+ "の": 257,
260
+ "ァ": 258,
261
+ "ア": 259,
262
+ "キ": 260,
263
+ "ス": 261,
264
+ "ッ": 262,
265
+ "ト": 263,
266
+ "プ": 264,
267
+ "ュ": 265,
268
+ "リ": 266,
269
+ "ル": 267,
270
+ "ヴ": 268,
271
+ "・": 269,
272
+ "動": 270,
273
+ "場": 271,
274
+ "大": 272,
275
+ "戦": 273,
276
+ "攻": 274,
277
+ "機": 275,
278
+ "殻": 276,
279
+ "火": 277,
280
+ "礮": 278,
281
+ "空": 279,
282
+ "隊": 280,
283
+ "": 281,
284
+ "~": 282
285
+ }