basiliskinstitute commited on
Commit
dbf5069
·
1 Parent(s): bb22552

Upload 8 files

Browse files
pytorch_model-00005-of-00008.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ced11d31cc1cba12973fa92fd6450a1700767d2ae5c730be909f70abcca946a8
3
+ size 1923281531
pytorch_model-00006-of-00008.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f46c56789137dbcd6920b7887cd639648934cf0442bc587fc05a8f7afbb02ada
3
+ size 1933783675
pytorch_model-00007-of-00008.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e995e6f9502910e1f1dbf109df6b6a7db3733cd9adccd2d408e2f3a0d5549900
3
+ size 1933792205
pytorch_model-00008-of-00008.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:be9fc9fd671dd29258478946724308e1f63c3fbf18c689294b46532ccf0515db
3
+ size 1829818663
pytorch_model.bin.index.json ADDED
@@ -0,0 +1,266 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "metadata": {
3
+ "total_size": 15442649088
4
+ },
5
+ "weight_map": {
6
+ "lm_head.weight": "pytorch_model-00008-of-00008.bin",
7
+ "transformer.h.0.attn.c_attn.bias": "pytorch_model-00001-of-00008.bin",
8
+ "transformer.h.0.attn.c_attn.weight": "pytorch_model-00001-of-00008.bin",
9
+ "transformer.h.0.attn.c_proj.weight": "pytorch_model-00001-of-00008.bin",
10
+ "transformer.h.0.ln_1.weight": "pytorch_model-00001-of-00008.bin",
11
+ "transformer.h.0.ln_2.weight": "pytorch_model-00001-of-00008.bin",
12
+ "transformer.h.0.mlp.c_proj.weight": "pytorch_model-00001-of-00008.bin",
13
+ "transformer.h.0.mlp.w1.weight": "pytorch_model-00001-of-00008.bin",
14
+ "transformer.h.0.mlp.w2.weight": "pytorch_model-00001-of-00008.bin",
15
+ "transformer.h.1.attn.c_attn.bias": "pytorch_model-00001-of-00008.bin",
16
+ "transformer.h.1.attn.c_attn.weight": "pytorch_model-00001-of-00008.bin",
17
+ "transformer.h.1.attn.c_proj.weight": "pytorch_model-00001-of-00008.bin",
18
+ "transformer.h.1.ln_1.weight": "pytorch_model-00001-of-00008.bin",
19
+ "transformer.h.1.ln_2.weight": "pytorch_model-00001-of-00008.bin",
20
+ "transformer.h.1.mlp.c_proj.weight": "pytorch_model-00002-of-00008.bin",
21
+ "transformer.h.1.mlp.w1.weight": "pytorch_model-00001-of-00008.bin",
22
+ "transformer.h.1.mlp.w2.weight": "pytorch_model-00001-of-00008.bin",
23
+ "transformer.h.10.attn.c_attn.bias": "pytorch_model-00003-of-00008.bin",
24
+ "transformer.h.10.attn.c_attn.weight": "pytorch_model-00003-of-00008.bin",
25
+ "transformer.h.10.attn.c_proj.weight": "pytorch_model-00003-of-00008.bin",
26
+ "transformer.h.10.ln_1.weight": "pytorch_model-00003-of-00008.bin",
27
+ "transformer.h.10.ln_2.weight": "pytorch_model-00003-of-00008.bin",
28
+ "transformer.h.10.mlp.c_proj.weight": "pytorch_model-00003-of-00008.bin",
29
+ "transformer.h.10.mlp.w1.weight": "pytorch_model-00003-of-00008.bin",
30
+ "transformer.h.10.mlp.w2.weight": "pytorch_model-00003-of-00008.bin",
31
+ "transformer.h.11.attn.c_attn.bias": "pytorch_model-00003-of-00008.bin",
32
+ "transformer.h.11.attn.c_attn.weight": "pytorch_model-00003-of-00008.bin",
33
+ "transformer.h.11.attn.c_proj.weight": "pytorch_model-00003-of-00008.bin",
34
+ "transformer.h.11.ln_1.weight": "pytorch_model-00003-of-00008.bin",
35
+ "transformer.h.11.ln_2.weight": "pytorch_model-00003-of-00008.bin",
36
+ "transformer.h.11.mlp.c_proj.weight": "pytorch_model-00004-of-00008.bin",
37
+ "transformer.h.11.mlp.w1.weight": "pytorch_model-00004-of-00008.bin",
38
+ "transformer.h.11.mlp.w2.weight": "pytorch_model-00004-of-00008.bin",
39
+ "transformer.h.12.attn.c_attn.bias": "pytorch_model-00004-of-00008.bin",
40
+ "transformer.h.12.attn.c_attn.weight": "pytorch_model-00004-of-00008.bin",
41
+ "transformer.h.12.attn.c_proj.weight": "pytorch_model-00004-of-00008.bin",
42
+ "transformer.h.12.ln_1.weight": "pytorch_model-00004-of-00008.bin",
43
+ "transformer.h.12.ln_2.weight": "pytorch_model-00004-of-00008.bin",
44
+ "transformer.h.12.mlp.c_proj.weight": "pytorch_model-00004-of-00008.bin",
45
+ "transformer.h.12.mlp.w1.weight": "pytorch_model-00004-of-00008.bin",
46
+ "transformer.h.12.mlp.w2.weight": "pytorch_model-00004-of-00008.bin",
47
+ "transformer.h.13.attn.c_attn.bias": "pytorch_model-00004-of-00008.bin",
48
+ "transformer.h.13.attn.c_attn.weight": "pytorch_model-00004-of-00008.bin",
49
+ "transformer.h.13.attn.c_proj.weight": "pytorch_model-00004-of-00008.bin",
50
+ "transformer.h.13.ln_1.weight": "pytorch_model-00004-of-00008.bin",
51
+ "transformer.h.13.ln_2.weight": "pytorch_model-00004-of-00008.bin",
52
+ "transformer.h.13.mlp.c_proj.weight": "pytorch_model-00004-of-00008.bin",
53
+ "transformer.h.13.mlp.w1.weight": "pytorch_model-00004-of-00008.bin",
54
+ "transformer.h.13.mlp.w2.weight": "pytorch_model-00004-of-00008.bin",
55
+ "transformer.h.14.attn.c_attn.bias": "pytorch_model-00004-of-00008.bin",
56
+ "transformer.h.14.attn.c_attn.weight": "pytorch_model-00004-of-00008.bin",
57
+ "transformer.h.14.attn.c_proj.weight": "pytorch_model-00004-of-00008.bin",
58
+ "transformer.h.14.ln_1.weight": "pytorch_model-00004-of-00008.bin",
59
+ "transformer.h.14.ln_2.weight": "pytorch_model-00004-of-00008.bin",
60
+ "transformer.h.14.mlp.c_proj.weight": "pytorch_model-00004-of-00008.bin",
61
+ "transformer.h.14.mlp.w1.weight": "pytorch_model-00004-of-00008.bin",
62
+ "transformer.h.14.mlp.w2.weight": "pytorch_model-00004-of-00008.bin",
63
+ "transformer.h.15.attn.c_attn.bias": "pytorch_model-00004-of-00008.bin",
64
+ "transformer.h.15.attn.c_attn.weight": "pytorch_model-00004-of-00008.bin",
65
+ "transformer.h.15.attn.c_proj.weight": "pytorch_model-00004-of-00008.bin",
66
+ "transformer.h.15.ln_1.weight": "pytorch_model-00004-of-00008.bin",
67
+ "transformer.h.15.ln_2.weight": "pytorch_model-00004-of-00008.bin",
68
+ "transformer.h.15.mlp.c_proj.weight": "pytorch_model-00004-of-00008.bin",
69
+ "transformer.h.15.mlp.w1.weight": "pytorch_model-00004-of-00008.bin",
70
+ "transformer.h.15.mlp.w2.weight": "pytorch_model-00004-of-00008.bin",
71
+ "transformer.h.16.attn.c_attn.bias": "pytorch_model-00004-of-00008.bin",
72
+ "transformer.h.16.attn.c_attn.weight": "pytorch_model-00004-of-00008.bin",
73
+ "transformer.h.16.attn.c_proj.weight": "pytorch_model-00005-of-00008.bin",
74
+ "transformer.h.16.ln_1.weight": "pytorch_model-00004-of-00008.bin",
75
+ "transformer.h.16.ln_2.weight": "pytorch_model-00005-of-00008.bin",
76
+ "transformer.h.16.mlp.c_proj.weight": "pytorch_model-00005-of-00008.bin",
77
+ "transformer.h.16.mlp.w1.weight": "pytorch_model-00005-of-00008.bin",
78
+ "transformer.h.16.mlp.w2.weight": "pytorch_model-00005-of-00008.bin",
79
+ "transformer.h.17.attn.c_attn.bias": "pytorch_model-00005-of-00008.bin",
80
+ "transformer.h.17.attn.c_attn.weight": "pytorch_model-00005-of-00008.bin",
81
+ "transformer.h.17.attn.c_proj.weight": "pytorch_model-00005-of-00008.bin",
82
+ "transformer.h.17.ln_1.weight": "pytorch_model-00005-of-00008.bin",
83
+ "transformer.h.17.ln_2.weight": "pytorch_model-00005-of-00008.bin",
84
+ "transformer.h.17.mlp.c_proj.weight": "pytorch_model-00005-of-00008.bin",
85
+ "transformer.h.17.mlp.w1.weight": "pytorch_model-00005-of-00008.bin",
86
+ "transformer.h.17.mlp.w2.weight": "pytorch_model-00005-of-00008.bin",
87
+ "transformer.h.18.attn.c_attn.bias": "pytorch_model-00005-of-00008.bin",
88
+ "transformer.h.18.attn.c_attn.weight": "pytorch_model-00005-of-00008.bin",
89
+ "transformer.h.18.attn.c_proj.weight": "pytorch_model-00005-of-00008.bin",
90
+ "transformer.h.18.ln_1.weight": "pytorch_model-00005-of-00008.bin",
91
+ "transformer.h.18.ln_2.weight": "pytorch_model-00005-of-00008.bin",
92
+ "transformer.h.18.mlp.c_proj.weight": "pytorch_model-00005-of-00008.bin",
93
+ "transformer.h.18.mlp.w1.weight": "pytorch_model-00005-of-00008.bin",
94
+ "transformer.h.18.mlp.w2.weight": "pytorch_model-00005-of-00008.bin",
95
+ "transformer.h.19.attn.c_attn.bias": "pytorch_model-00005-of-00008.bin",
96
+ "transformer.h.19.attn.c_attn.weight": "pytorch_model-00005-of-00008.bin",
97
+ "transformer.h.19.attn.c_proj.weight": "pytorch_model-00005-of-00008.bin",
98
+ "transformer.h.19.ln_1.weight": "pytorch_model-00005-of-00008.bin",
99
+ "transformer.h.19.ln_2.weight": "pytorch_model-00005-of-00008.bin",
100
+ "transformer.h.19.mlp.c_proj.weight": "pytorch_model-00005-of-00008.bin",
101
+ "transformer.h.19.mlp.w1.weight": "pytorch_model-00005-of-00008.bin",
102
+ "transformer.h.19.mlp.w2.weight": "pytorch_model-00005-of-00008.bin",
103
+ "transformer.h.2.attn.c_attn.bias": "pytorch_model-00002-of-00008.bin",
104
+ "transformer.h.2.attn.c_attn.weight": "pytorch_model-00002-of-00008.bin",
105
+ "transformer.h.2.attn.c_proj.weight": "pytorch_model-00002-of-00008.bin",
106
+ "transformer.h.2.ln_1.weight": "pytorch_model-00002-of-00008.bin",
107
+ "transformer.h.2.ln_2.weight": "pytorch_model-00002-of-00008.bin",
108
+ "transformer.h.2.mlp.c_proj.weight": "pytorch_model-00002-of-00008.bin",
109
+ "transformer.h.2.mlp.w1.weight": "pytorch_model-00002-of-00008.bin",
110
+ "transformer.h.2.mlp.w2.weight": "pytorch_model-00002-of-00008.bin",
111
+ "transformer.h.20.attn.c_attn.bias": "pytorch_model-00005-of-00008.bin",
112
+ "transformer.h.20.attn.c_attn.weight": "pytorch_model-00005-of-00008.bin",
113
+ "transformer.h.20.attn.c_proj.weight": "pytorch_model-00005-of-00008.bin",
114
+ "transformer.h.20.ln_1.weight": "pytorch_model-00005-of-00008.bin",
115
+ "transformer.h.20.ln_2.weight": "pytorch_model-00005-of-00008.bin",
116
+ "transformer.h.20.mlp.c_proj.weight": "pytorch_model-00005-of-00008.bin",
117
+ "transformer.h.20.mlp.w1.weight": "pytorch_model-00005-of-00008.bin",
118
+ "transformer.h.20.mlp.w2.weight": "pytorch_model-00005-of-00008.bin",
119
+ "transformer.h.21.attn.c_attn.bias": "pytorch_model-00006-of-00008.bin",
120
+ "transformer.h.21.attn.c_attn.weight": "pytorch_model-00006-of-00008.bin",
121
+ "transformer.h.21.attn.c_proj.weight": "pytorch_model-00006-of-00008.bin",
122
+ "transformer.h.21.ln_1.weight": "pytorch_model-00005-of-00008.bin",
123
+ "transformer.h.21.ln_2.weight": "pytorch_model-00006-of-00008.bin",
124
+ "transformer.h.21.mlp.c_proj.weight": "pytorch_model-00006-of-00008.bin",
125
+ "transformer.h.21.mlp.w1.weight": "pytorch_model-00006-of-00008.bin",
126
+ "transformer.h.21.mlp.w2.weight": "pytorch_model-00006-of-00008.bin",
127
+ "transformer.h.22.attn.c_attn.bias": "pytorch_model-00006-of-00008.bin",
128
+ "transformer.h.22.attn.c_attn.weight": "pytorch_model-00006-of-00008.bin",
129
+ "transformer.h.22.attn.c_proj.weight": "pytorch_model-00006-of-00008.bin",
130
+ "transformer.h.22.ln_1.weight": "pytorch_model-00006-of-00008.bin",
131
+ "transformer.h.22.ln_2.weight": "pytorch_model-00006-of-00008.bin",
132
+ "transformer.h.22.mlp.c_proj.weight": "pytorch_model-00006-of-00008.bin",
133
+ "transformer.h.22.mlp.w1.weight": "pytorch_model-00006-of-00008.bin",
134
+ "transformer.h.22.mlp.w2.weight": "pytorch_model-00006-of-00008.bin",
135
+ "transformer.h.23.attn.c_attn.bias": "pytorch_model-00006-of-00008.bin",
136
+ "transformer.h.23.attn.c_attn.weight": "pytorch_model-00006-of-00008.bin",
137
+ "transformer.h.23.attn.c_proj.weight": "pytorch_model-00006-of-00008.bin",
138
+ "transformer.h.23.ln_1.weight": "pytorch_model-00006-of-00008.bin",
139
+ "transformer.h.23.ln_2.weight": "pytorch_model-00006-of-00008.bin",
140
+ "transformer.h.23.mlp.c_proj.weight": "pytorch_model-00006-of-00008.bin",
141
+ "transformer.h.23.mlp.w1.weight": "pytorch_model-00006-of-00008.bin",
142
+ "transformer.h.23.mlp.w2.weight": "pytorch_model-00006-of-00008.bin",
143
+ "transformer.h.24.attn.c_attn.bias": "pytorch_model-00006-of-00008.bin",
144
+ "transformer.h.24.attn.c_attn.weight": "pytorch_model-00006-of-00008.bin",
145
+ "transformer.h.24.attn.c_proj.weight": "pytorch_model-00006-of-00008.bin",
146
+ "transformer.h.24.ln_1.weight": "pytorch_model-00006-of-00008.bin",
147
+ "transformer.h.24.ln_2.weight": "pytorch_model-00006-of-00008.bin",
148
+ "transformer.h.24.mlp.c_proj.weight": "pytorch_model-00006-of-00008.bin",
149
+ "transformer.h.24.mlp.w1.weight": "pytorch_model-00006-of-00008.bin",
150
+ "transformer.h.24.mlp.w2.weight": "pytorch_model-00006-of-00008.bin",
151
+ "transformer.h.25.attn.c_attn.bias": "pytorch_model-00006-of-00008.bin",
152
+ "transformer.h.25.attn.c_attn.weight": "pytorch_model-00006-of-00008.bin",
153
+ "transformer.h.25.attn.c_proj.weight": "pytorch_model-00006-of-00008.bin",
154
+ "transformer.h.25.ln_1.weight": "pytorch_model-00006-of-00008.bin",
155
+ "transformer.h.25.ln_2.weight": "pytorch_model-00006-of-00008.bin",
156
+ "transformer.h.25.mlp.c_proj.weight": "pytorch_model-00007-of-00008.bin",
157
+ "transformer.h.25.mlp.w1.weight": "pytorch_model-00006-of-00008.bin",
158
+ "transformer.h.25.mlp.w2.weight": "pytorch_model-00006-of-00008.bin",
159
+ "transformer.h.26.attn.c_attn.bias": "pytorch_model-00007-of-00008.bin",
160
+ "transformer.h.26.attn.c_attn.weight": "pytorch_model-00007-of-00008.bin",
161
+ "transformer.h.26.attn.c_proj.weight": "pytorch_model-00007-of-00008.bin",
162
+ "transformer.h.26.ln_1.weight": "pytorch_model-00007-of-00008.bin",
163
+ "transformer.h.26.ln_2.weight": "pytorch_model-00007-of-00008.bin",
164
+ "transformer.h.26.mlp.c_proj.weight": "pytorch_model-00007-of-00008.bin",
165
+ "transformer.h.26.mlp.w1.weight": "pytorch_model-00007-of-00008.bin",
166
+ "transformer.h.26.mlp.w2.weight": "pytorch_model-00007-of-00008.bin",
167
+ "transformer.h.27.attn.c_attn.bias": "pytorch_model-00007-of-00008.bin",
168
+ "transformer.h.27.attn.c_attn.weight": "pytorch_model-00007-of-00008.bin",
169
+ "transformer.h.27.attn.c_proj.weight": "pytorch_model-00007-of-00008.bin",
170
+ "transformer.h.27.ln_1.weight": "pytorch_model-00007-of-00008.bin",
171
+ "transformer.h.27.ln_2.weight": "pytorch_model-00007-of-00008.bin",
172
+ "transformer.h.27.mlp.c_proj.weight": "pytorch_model-00007-of-00008.bin",
173
+ "transformer.h.27.mlp.w1.weight": "pytorch_model-00007-of-00008.bin",
174
+ "transformer.h.27.mlp.w2.weight": "pytorch_model-00007-of-00008.bin",
175
+ "transformer.h.28.attn.c_attn.bias": "pytorch_model-00007-of-00008.bin",
176
+ "transformer.h.28.attn.c_attn.weight": "pytorch_model-00007-of-00008.bin",
177
+ "transformer.h.28.attn.c_proj.weight": "pytorch_model-00007-of-00008.bin",
178
+ "transformer.h.28.ln_1.weight": "pytorch_model-00007-of-00008.bin",
179
+ "transformer.h.28.ln_2.weight": "pytorch_model-00007-of-00008.bin",
180
+ "transformer.h.28.mlp.c_proj.weight": "pytorch_model-00007-of-00008.bin",
181
+ "transformer.h.28.mlp.w1.weight": "pytorch_model-00007-of-00008.bin",
182
+ "transformer.h.28.mlp.w2.weight": "pytorch_model-00007-of-00008.bin",
183
+ "transformer.h.29.attn.c_attn.bias": "pytorch_model-00007-of-00008.bin",
184
+ "transformer.h.29.attn.c_attn.weight": "pytorch_model-00007-of-00008.bin",
185
+ "transformer.h.29.attn.c_proj.weight": "pytorch_model-00007-of-00008.bin",
186
+ "transformer.h.29.ln_1.weight": "pytorch_model-00007-of-00008.bin",
187
+ "transformer.h.29.ln_2.weight": "pytorch_model-00007-of-00008.bin",
188
+ "transformer.h.29.mlp.c_proj.weight": "pytorch_model-00007-of-00008.bin",
189
+ "transformer.h.29.mlp.w1.weight": "pytorch_model-00007-of-00008.bin",
190
+ "transformer.h.29.mlp.w2.weight": "pytorch_model-00007-of-00008.bin",
191
+ "transformer.h.3.attn.c_attn.bias": "pytorch_model-00002-of-00008.bin",
192
+ "transformer.h.3.attn.c_attn.weight": "pytorch_model-00002-of-00008.bin",
193
+ "transformer.h.3.attn.c_proj.weight": "pytorch_model-00002-of-00008.bin",
194
+ "transformer.h.3.ln_1.weight": "pytorch_model-00002-of-00008.bin",
195
+ "transformer.h.3.ln_2.weight": "pytorch_model-00002-of-00008.bin",
196
+ "transformer.h.3.mlp.c_proj.weight": "pytorch_model-00002-of-00008.bin",
197
+ "transformer.h.3.mlp.w1.weight": "pytorch_model-00002-of-00008.bin",
198
+ "transformer.h.3.mlp.w2.weight": "pytorch_model-00002-of-00008.bin",
199
+ "transformer.h.30.attn.c_attn.bias": "pytorch_model-00007-of-00008.bin",
200
+ "transformer.h.30.attn.c_attn.weight": "pytorch_model-00007-of-00008.bin",
201
+ "transformer.h.30.attn.c_proj.weight": "pytorch_model-00007-of-00008.bin",
202
+ "transformer.h.30.ln_1.weight": "pytorch_model-00007-of-00008.bin",
203
+ "transformer.h.30.ln_2.weight": "pytorch_model-00007-of-00008.bin",
204
+ "transformer.h.30.mlp.c_proj.weight": "pytorch_model-00008-of-00008.bin",
205
+ "transformer.h.30.mlp.w1.weight": "pytorch_model-00007-of-00008.bin",
206
+ "transformer.h.30.mlp.w2.weight": "pytorch_model-00008-of-00008.bin",
207
+ "transformer.h.31.attn.c_attn.bias": "pytorch_model-00008-of-00008.bin",
208
+ "transformer.h.31.attn.c_attn.weight": "pytorch_model-00008-of-00008.bin",
209
+ "transformer.h.31.attn.c_proj.weight": "pytorch_model-00008-of-00008.bin",
210
+ "transformer.h.31.ln_1.weight": "pytorch_model-00008-of-00008.bin",
211
+ "transformer.h.31.ln_2.weight": "pytorch_model-00008-of-00008.bin",
212
+ "transformer.h.31.mlp.c_proj.weight": "pytorch_model-00008-of-00008.bin",
213
+ "transformer.h.31.mlp.w1.weight": "pytorch_model-00008-of-00008.bin",
214
+ "transformer.h.31.mlp.w2.weight": "pytorch_model-00008-of-00008.bin",
215
+ "transformer.h.4.attn.c_attn.bias": "pytorch_model-00002-of-00008.bin",
216
+ "transformer.h.4.attn.c_attn.weight": "pytorch_model-00002-of-00008.bin",
217
+ "transformer.h.4.attn.c_proj.weight": "pytorch_model-00002-of-00008.bin",
218
+ "transformer.h.4.ln_1.weight": "pytorch_model-00002-of-00008.bin",
219
+ "transformer.h.4.ln_2.weight": "pytorch_model-00002-of-00008.bin",
220
+ "transformer.h.4.mlp.c_proj.weight": "pytorch_model-00002-of-00008.bin",
221
+ "transformer.h.4.mlp.w1.weight": "pytorch_model-00002-of-00008.bin",
222
+ "transformer.h.4.mlp.w2.weight": "pytorch_model-00002-of-00008.bin",
223
+ "transformer.h.5.attn.c_attn.bias": "pytorch_model-00002-of-00008.bin",
224
+ "transformer.h.5.attn.c_attn.weight": "pytorch_model-00002-of-00008.bin",
225
+ "transformer.h.5.attn.c_proj.weight": "pytorch_model-00002-of-00008.bin",
226
+ "transformer.h.5.ln_1.weight": "pytorch_model-00002-of-00008.bin",
227
+ "transformer.h.5.ln_2.weight": "pytorch_model-00002-of-00008.bin",
228
+ "transformer.h.5.mlp.c_proj.weight": "pytorch_model-00002-of-00008.bin",
229
+ "transformer.h.5.mlp.w1.weight": "pytorch_model-00002-of-00008.bin",
230
+ "transformer.h.5.mlp.w2.weight": "pytorch_model-00002-of-00008.bin",
231
+ "transformer.h.6.attn.c_attn.bias": "pytorch_model-00002-of-00008.bin",
232
+ "transformer.h.6.attn.c_attn.weight": "pytorch_model-00002-of-00008.bin",
233
+ "transformer.h.6.attn.c_proj.weight": "pytorch_model-00002-of-00008.bin",
234
+ "transformer.h.6.ln_1.weight": "pytorch_model-00002-of-00008.bin",
235
+ "transformer.h.6.ln_2.weight": "pytorch_model-00002-of-00008.bin",
236
+ "transformer.h.6.mlp.c_proj.weight": "pytorch_model-00003-of-00008.bin",
237
+ "transformer.h.6.mlp.w1.weight": "pytorch_model-00002-of-00008.bin",
238
+ "transformer.h.6.mlp.w2.weight": "pytorch_model-00003-of-00008.bin",
239
+ "transformer.h.7.attn.c_attn.bias": "pytorch_model-00003-of-00008.bin",
240
+ "transformer.h.7.attn.c_attn.weight": "pytorch_model-00003-of-00008.bin",
241
+ "transformer.h.7.attn.c_proj.weight": "pytorch_model-00003-of-00008.bin",
242
+ "transformer.h.7.ln_1.weight": "pytorch_model-00003-of-00008.bin",
243
+ "transformer.h.7.ln_2.weight": "pytorch_model-00003-of-00008.bin",
244
+ "transformer.h.7.mlp.c_proj.weight": "pytorch_model-00003-of-00008.bin",
245
+ "transformer.h.7.mlp.w1.weight": "pytorch_model-00003-of-00008.bin",
246
+ "transformer.h.7.mlp.w2.weight": "pytorch_model-00003-of-00008.bin",
247
+ "transformer.h.8.attn.c_attn.bias": "pytorch_model-00003-of-00008.bin",
248
+ "transformer.h.8.attn.c_attn.weight": "pytorch_model-00003-of-00008.bin",
249
+ "transformer.h.8.attn.c_proj.weight": "pytorch_model-00003-of-00008.bin",
250
+ "transformer.h.8.ln_1.weight": "pytorch_model-00003-of-00008.bin",
251
+ "transformer.h.8.ln_2.weight": "pytorch_model-00003-of-00008.bin",
252
+ "transformer.h.8.mlp.c_proj.weight": "pytorch_model-00003-of-00008.bin",
253
+ "transformer.h.8.mlp.w1.weight": "pytorch_model-00003-of-00008.bin",
254
+ "transformer.h.8.mlp.w2.weight": "pytorch_model-00003-of-00008.bin",
255
+ "transformer.h.9.attn.c_attn.bias": "pytorch_model-00003-of-00008.bin",
256
+ "transformer.h.9.attn.c_attn.weight": "pytorch_model-00003-of-00008.bin",
257
+ "transformer.h.9.attn.c_proj.weight": "pytorch_model-00003-of-00008.bin",
258
+ "transformer.h.9.ln_1.weight": "pytorch_model-00003-of-00008.bin",
259
+ "transformer.h.9.ln_2.weight": "pytorch_model-00003-of-00008.bin",
260
+ "transformer.h.9.mlp.c_proj.weight": "pytorch_model-00003-of-00008.bin",
261
+ "transformer.h.9.mlp.w1.weight": "pytorch_model-00003-of-00008.bin",
262
+ "transformer.h.9.mlp.w2.weight": "pytorch_model-00003-of-00008.bin",
263
+ "transformer.ln_f.weight": "pytorch_model-00008-of-00008.bin",
264
+ "transformer.wte.weight": "pytorch_model-00001-of-00008.bin"
265
+ }
266
+ }
qwen_generation_utils.py ADDED
@@ -0,0 +1,416 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (c) Alibaba Cloud.
2
+ #
3
+ # This source code is licensed under the license found in the
4
+ # LICENSE file in the root directory of this source tree.
5
+
6
+ """Generation support."""
7
+
8
+ from typing import Tuple, List, Union, Iterable
9
+
10
+ import numpy as np
11
+ import torch
12
+ import torch.nn.functional as F
13
+ from transformers import PreTrainedTokenizer
14
+ from transformers import logging
15
+ from transformers.generation import LogitsProcessor
16
+
17
+ logger = logging.get_logger(__name__)
18
+
19
+ # Types.
20
+ HistoryType = List[Tuple[str, str]]
21
+ TokensType = List[int]
22
+ BatchTokensType = List[List[int]]
23
+
24
+
25
+ def pad_batch(batch: BatchTokensType, pad_id: int, seq_length: int) -> BatchTokensType:
26
+ for tokens in batch:
27
+ context_length = len(tokens)
28
+ if context_length < seq_length:
29
+ tokens.extend([pad_id] * (seq_length - context_length))
30
+ return batch
31
+
32
+
33
+ def get_ltor_masks_and_position_ids(
34
+ data,
35
+ eod_token,
36
+ reset_position_ids,
37
+ reset_attention_mask,
38
+ eod_mask_loss,
39
+ ):
40
+ """Build masks and position id for left to right model."""
41
+
42
+ # Extract batch size and sequence length.
43
+ micro_batch_size, seq_length = data.size()
44
+
45
+ # Attention mask (lower triangular).
46
+ if reset_attention_mask:
47
+ att_mask_batch = micro_batch_size
48
+ else:
49
+ att_mask_batch = 1
50
+ attention_mask = torch.tril(
51
+ torch.ones((att_mask_batch, seq_length, seq_length), device=data.device)
52
+ ).view(att_mask_batch, 1, seq_length, seq_length)
53
+
54
+ # Loss mask.
55
+ loss_mask = torch.ones(data.size(), dtype=torch.float, device=data.device)
56
+ if eod_mask_loss:
57
+ loss_mask[data == eod_token] = 0.0
58
+
59
+ # Position ids.
60
+ position_ids = torch.arange(seq_length, dtype=torch.long, device=data.device)
61
+ position_ids = position_ids.unsqueeze(0).expand_as(data)
62
+ # We need to clone as the ids will be modifed based on batch index.
63
+ if reset_position_ids:
64
+ position_ids = position_ids.clone()
65
+
66
+ if reset_position_ids or reset_attention_mask:
67
+ # Loop through the batches:
68
+ for b in range(micro_batch_size):
69
+
70
+ # Find indecies where EOD token is.
71
+ eod_index = position_ids[b, data[b] == eod_token]
72
+ # Detach indecies from positions if going to modify positions.
73
+ if reset_position_ids:
74
+ eod_index = eod_index.clone()
75
+
76
+ # Loop through EOD indecies:
77
+ prev_index = 0
78
+ for j in range(eod_index.size()[0]):
79
+ i = eod_index[j]
80
+ # Mask attention loss.
81
+ if reset_attention_mask:
82
+ attention_mask[b, 0, (i + 1) :, : (i + 1)] = 0
83
+ # Reset positions.
84
+ if reset_position_ids:
85
+ position_ids[b, (i + 1) :] -= i + 1 - prev_index
86
+ prev_index = i + 1
87
+
88
+ # Convert attention mask to binary:
89
+ attention_mask = attention_mask < 0.5
90
+
91
+ return attention_mask, loss_mask, position_ids
92
+
93
+
94
+ def get_batch(context_tokens: torch.LongTensor, eod_id: int):
95
+ """Generate batch from context tokens."""
96
+ # Move to GPU.
97
+ tokens = context_tokens.contiguous().to(context_tokens.device)
98
+ # Get the attention mask and postition ids.
99
+ attention_mask, _, position_ids = get_ltor_masks_and_position_ids(
100
+ tokens,
101
+ eod_id,
102
+ reset_position_ids=False,
103
+ reset_attention_mask=False,
104
+ eod_mask_loss=False,
105
+ )
106
+ return tokens, attention_mask, position_ids
107
+
108
+
109
+ def get_stop_words_ids(chat_format, tokenizer):
110
+ if chat_format == "raw":
111
+ stop_words_ids = [tokenizer.encode("Human:"), [tokenizer.eod_id]]
112
+ elif chat_format == "chatml":
113
+ stop_words_ids = [[tokenizer.im_end_id], [tokenizer.im_start_id]]
114
+ else:
115
+ raise NotImplementedError(f"Unknown chat format {chat_format!r}")
116
+ return stop_words_ids
117
+
118
+
119
+ def make_context(
120
+ tokenizer: PreTrainedTokenizer,
121
+ query: str,
122
+ history: List[Tuple[str, str]] = None,
123
+ system: str = "",
124
+ max_window_size: int = 6144,
125
+ chat_format: str = "chatml",
126
+ ):
127
+ if history is None:
128
+ history = []
129
+
130
+ if chat_format == "chatml":
131
+ im_start, im_end = "<|im_start|>", "<|im_end|>"
132
+ im_start_tokens = [tokenizer.im_start_id]
133
+ im_end_tokens = [tokenizer.im_end_id]
134
+ nl_tokens = tokenizer.encode("\n")
135
+
136
+ def _tokenize_str(role, content):
137
+ return f"{role}\n{content}", tokenizer.encode(
138
+ role, allowed_special=set()
139
+ ) + nl_tokens + tokenizer.encode(content, allowed_special=set())
140
+
141
+ system_text, system_tokens_part = _tokenize_str("system", system)
142
+ system_tokens = im_start_tokens + system_tokens_part + im_end_tokens
143
+
144
+ raw_text = ""
145
+ context_tokens = []
146
+
147
+ for turn_query, turn_response in reversed(history):
148
+ query_text, query_tokens_part = _tokenize_str("user", turn_query)
149
+ query_tokens = im_start_tokens + query_tokens_part + im_end_tokens
150
+ response_text, response_tokens_part = _tokenize_str(
151
+ "assistant", turn_response
152
+ )
153
+ response_tokens = im_start_tokens + response_tokens_part + im_end_tokens
154
+
155
+ next_context_tokens = nl_tokens + query_tokens + nl_tokens + response_tokens
156
+ prev_chat = (
157
+ f"\n{im_start}{query_text}{im_end}\n{im_start}{response_text}{im_end}"
158
+ )
159
+
160
+ current_context_size = (
161
+ len(system_tokens) + len(next_context_tokens) + len(context_tokens)
162
+ )
163
+ if current_context_size < max_window_size:
164
+ context_tokens = next_context_tokens + context_tokens
165
+ raw_text = prev_chat + raw_text
166
+ else:
167
+ break
168
+
169
+ context_tokens = system_tokens + context_tokens
170
+ raw_text = f"{im_start}{system_text}{im_end}" + raw_text
171
+ context_tokens += (
172
+ nl_tokens
173
+ + im_start_tokens
174
+ + _tokenize_str("user", query)[1]
175
+ + im_end_tokens
176
+ + nl_tokens
177
+ + im_start_tokens
178
+ + tokenizer.encode("assistant")
179
+ + nl_tokens
180
+ )
181
+ raw_text += f"\n{im_start}user\n{query}{im_end}\n{im_start}assistant\n"
182
+
183
+ elif chat_format == "raw":
184
+ raw_text = query
185
+ context_tokens = tokenizer.encode(raw_text)
186
+ else:
187
+ raise NotImplementedError(f"Unknown chat format {chat_format!r}")
188
+
189
+ return raw_text, context_tokens
190
+
191
+
192
+ def _decode_default(
193
+ tokens: List[int],
194
+ *,
195
+ stop_words: List[str],
196
+ eod_words: List[str],
197
+ tokenizer: PreTrainedTokenizer,
198
+ raw_text_len: int,
199
+ verbose: bool = False,
200
+ return_end_reason: bool = False,
201
+ errors: str='replace',
202
+ ):
203
+ trim_decode_tokens = tokenizer.decode(tokens, errors=errors)[raw_text_len:]
204
+ if verbose:
205
+ print("\nRaw Generate: ", trim_decode_tokens)
206
+
207
+ end_reason = f"Gen length {len(tokens)}"
208
+ for stop_word in stop_words:
209
+ trim_decode_tokens = trim_decode_tokens.replace(stop_word, "").strip()
210
+ for eod_word in eod_words:
211
+ if eod_word in trim_decode_tokens:
212
+ end_reason = f"Gen {eod_word!r}"
213
+ trim_decode_tokens = trim_decode_tokens.split(eod_word)[0]
214
+ trim_decode_tokens = trim_decode_tokens.strip()
215
+ if verbose:
216
+ print("\nEnd Reason:", end_reason)
217
+ print("\nGenerate: ", trim_decode_tokens)
218
+
219
+ if return_end_reason:
220
+ return trim_decode_tokens, end_reason
221
+ else:
222
+ return trim_decode_tokens
223
+
224
+
225
+ def _decode_chatml(
226
+ tokens: List[int],
227
+ *,
228
+ stop_words: List[str],
229
+ eod_token_ids: List[int],
230
+ tokenizer: PreTrainedTokenizer,
231
+ raw_text_len: int,
232
+ context_length: int,
233
+ verbose: bool = False,
234
+ return_end_reason: bool = False,
235
+ errors: str='replace'
236
+ ):
237
+ end_reason = f"Gen length {len(tokens)}"
238
+ eod_token_idx = context_length
239
+ for eod_token_idx in range(context_length, len(tokens)):
240
+ if tokens[eod_token_idx] in eod_token_ids:
241
+ end_reason = f"Gen {tokenizer.decode([tokens[eod_token_idx]])!r}"
242
+ break
243
+
244
+ trim_decode_tokens = tokenizer.decode(tokens[:eod_token_idx], errors=errors)[raw_text_len:]
245
+ if verbose:
246
+ print("\nRaw Generate w/o EOD:", tokenizer.decode(tokens, errors=errors)[raw_text_len:])
247
+ print("\nRaw Generate:", trim_decode_tokens)
248
+ print("\nEnd Reason:", end_reason)
249
+ for stop_word in stop_words:
250
+ trim_decode_tokens = trim_decode_tokens.replace(stop_word, "").strip()
251
+ trim_decode_tokens = trim_decode_tokens.strip()
252
+ if verbose:
253
+ print("\nGenerate:", trim_decode_tokens)
254
+
255
+ if return_end_reason:
256
+ return trim_decode_tokens, end_reason
257
+ else:
258
+ return trim_decode_tokens
259
+
260
+
261
+ def decode_tokens(
262
+ tokens: Union[torch.LongTensor, TokensType],
263
+ tokenizer: PreTrainedTokenizer,
264
+ raw_text_len: int,
265
+ context_length: int,
266
+ chat_format: str,
267
+ verbose: bool = False,
268
+ return_end_reason: bool = False,
269
+ errors: str="replace",
270
+ ) -> str:
271
+ if torch.is_tensor(tokens):
272
+ tokens = tokens.cpu().numpy().tolist()
273
+
274
+ if chat_format == "chatml":
275
+ return _decode_chatml(
276
+ tokens,
277
+ stop_words=[],
278
+ eod_token_ids=[tokenizer.im_start_id, tokenizer.im_end_id],
279
+ tokenizer=tokenizer,
280
+ raw_text_len=raw_text_len,
281
+ context_length=context_length,
282
+ verbose=verbose,
283
+ return_end_reason=return_end_reason,
284
+ errors=errors,
285
+ )
286
+ elif chat_format == "raw":
287
+ return _decode_default(
288
+ tokens,
289
+ stop_words=["<|endoftext|>"],
290
+ eod_words=["<|endoftext|>"],
291
+ tokenizer=tokenizer,
292
+ raw_text_len=raw_text_len,
293
+ verbose=verbose,
294
+ return_end_reason=return_end_reason,
295
+ errors=errors,
296
+ )
297
+ else:
298
+ raise NotImplementedError(f"Unknown chat format {chat_format!r}")
299
+
300
+
301
+ class StopWordsLogitsProcessor(LogitsProcessor):
302
+ """
303
+ :class:`transformers.LogitsProcessor` that enforces that when specified sequences appear, stop geration.
304
+
305
+ Args:
306
+ stop_words_ids (:obj:`List[List[int]]`):
307
+ List of list of token ids of stop ids. In order to get the tokens of the words
308
+ that should not appear in the generated text, use :obj:`tokenizer(bad_word,
309
+ add_prefix_space=True).input_ids`.
310
+ eos_token_id (:obj:`int`):
311
+ The id of the `end-of-sequence` token.
312
+ """
313
+
314
+ def __init__(self, stop_words_ids: Iterable[Iterable[int]], eos_token_id: int):
315
+
316
+ if not isinstance(stop_words_ids, List) or len(stop_words_ids) == 0:
317
+ raise ValueError(
318
+ f"`stop_words_ids` has to be a non-emtpy list, but is {stop_words_ids}."
319
+ )
320
+ if any(not isinstance(bad_word_ids, list) for bad_word_ids in stop_words_ids):
321
+ raise ValueError(
322
+ f"`stop_words_ids` has to be a list of lists, but is {stop_words_ids}."
323
+ )
324
+ if any(
325
+ any(
326
+ (not isinstance(token_id, (int, np.integer)) or token_id < 0)
327
+ for token_id in stop_word_ids
328
+ )
329
+ for stop_word_ids in stop_words_ids
330
+ ):
331
+ raise ValueError(
332
+ f"Each list in `stop_words_ids` has to be a list of positive integers, but is {stop_words_ids}."
333
+ )
334
+
335
+ self.stop_words_ids = list(
336
+ filter(
337
+ lambda bad_token_seq: bad_token_seq != [eos_token_id], stop_words_ids
338
+ )
339
+ )
340
+ self.eos_token_id = eos_token_id
341
+ for stop_token_seq in self.stop_words_ids:
342
+ assert (
343
+ len(stop_token_seq) > 0
344
+ ), "Stop words token sequences {} cannot have an empty list".format(
345
+ stop_words_ids
346
+ )
347
+
348
+ def __call__(
349
+ self, input_ids: torch.LongTensor, scores: torch.FloatTensor
350
+ ) -> torch.FloatTensor:
351
+ stopped_samples = self._calc_stopped_samples(input_ids)
352
+ for i, should_stop in enumerate(stopped_samples):
353
+ if should_stop:
354
+ scores[i, self.eos_token_id] = float(2**15)
355
+ return scores
356
+
357
+ def _tokens_match(self, prev_tokens: torch.LongTensor, tokens: List[int]) -> bool:
358
+ if len(tokens) == 0:
359
+ # if bad word tokens is just one token always ban it
360
+ return True
361
+ elif len(tokens) > len(prev_tokens):
362
+ # if bad word tokens are longer then prev input_ids they can't be equal
363
+ return False
364
+ elif prev_tokens[-len(tokens) :].tolist() == tokens:
365
+ # if tokens match
366
+ return True
367
+ else:
368
+ return False
369
+
370
+ def _calc_stopped_samples(self, prev_input_ids: Iterable[int]) -> Iterable[int]:
371
+ stopped_samples = []
372
+ for prev_input_ids_slice in prev_input_ids:
373
+ match = False
374
+ for stop_token_seq in self.stop_words_ids:
375
+ if self._tokens_match(prev_input_ids_slice, stop_token_seq):
376
+ # if tokens do not match continue
377
+ match = True
378
+ break
379
+ stopped_samples.append(match)
380
+
381
+ return stopped_samples
382
+
383
+
384
+ def top_k_logits(logits, top_k=0, top_p=0.0, filter_value=-float("Inf")):
385
+ """This function has been mostly taken from huggingface conversational
386
+ ai code at
387
+ https://medium.com/huggingface/how-to-build-a-state-of-the-art-
388
+ conversational-ai-with-transfer-learning-2d818ac26313"""
389
+
390
+ if top_k > 0:
391
+ # Remove all tokens with a probability less than the
392
+ # last token of the top-k
393
+ indices_to_remove = logits < torch.topk(logits, top_k)[0][..., -1, None]
394
+ logits[indices_to_remove] = filter_value
395
+
396
+ if top_p > 0.0:
397
+ # Cconvert to 1D
398
+ sorted_logits, sorted_indices = torch.sort(logits, descending=True, dim=-1)
399
+ cumulative_probs = torch.cumsum(F.softmax(sorted_logits, dim=-1), dim=-1)
400
+
401
+ # Remove tokens with cumulative probability above the threshold
402
+ sorted_indices_to_remove = cumulative_probs > top_p
403
+ # Shift the indices to the right to keep also the first token
404
+ # above the threshold
405
+ sorted_indices_to_remove[..., 1:] = sorted_indices_to_remove[..., :-1].clone()
406
+ sorted_indices_to_remove[..., 0] = 0
407
+ for i in range(sorted_indices.size(0)):
408
+ indices_to_remove = sorted_indices[i][sorted_indices_to_remove[i]]
409
+ logits[i][indices_to_remove] = filter_value
410
+
411
+ return logits
412
+
413
+
414
+ def switch(val1, val2, boolean):
415
+ boolean = boolean.type_as(val1)
416
+ return (1 - boolean) * val1 + boolean * val2
tokenization_qwen.py ADDED
@@ -0,0 +1,228 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (c) Alibaba Cloud.
2
+ #
3
+ # This source code is licensed under the license found in the
4
+ # LICENSE file in the root directory of this source tree.
5
+
6
+ """Tokenization classes for QWen."""
7
+
8
+ import base64
9
+ import logging
10
+ import os
11
+ import unicodedata
12
+ from typing import Collection, Dict, List, Set, Tuple, Union
13
+
14
+ import tiktoken
15
+ from transformers import PreTrainedTokenizer, AddedToken
16
+
17
+ logger = logging.getLogger(__name__)
18
+
19
+
20
+ VOCAB_FILES_NAMES = {"vocab_file": "qwen.tiktoken"}
21
+
22
+ PAT_STR = r"""(?i:'s|'t|'re|'ve|'m|'ll|'d)|[^\r\n\p{L}\p{N}]?\p{L}+|\p{N}| ?[^\s\p{L}\p{N}]+[\r\n]*|\s*[\r\n]+|\s+(?!\S)|\s+"""
23
+ ENDOFTEXT = "<|endoftext|>"
24
+ IMSTART = "<|im_start|>"
25
+ IMEND = "<|im_end|>"
26
+ # as the default behavior is changed to allow special tokens in
27
+ # regular texts, the surface forms of special tokens need to be
28
+ # as different as possible to minimize the impact
29
+ EXTRAS = tuple((f"<|extra_{i}|>" for i in range(205)))
30
+ SPECIAL_TOKENS = (
31
+ ENDOFTEXT,
32
+ IMSTART,
33
+ IMEND,
34
+ ) + EXTRAS
35
+
36
+
37
+ def _load_tiktoken_bpe(tiktoken_bpe_file: str) -> Dict[bytes, int]:
38
+ with open(tiktoken_bpe_file, "rb") as f:
39
+ contents = f.read()
40
+ return {
41
+ base64.b64decode(token): int(rank)
42
+ for token, rank in (line.split() for line in contents.splitlines() if line)
43
+ }
44
+
45
+ class QWenTokenizer(PreTrainedTokenizer):
46
+ """QWen tokenizer."""
47
+
48
+ vocab_files_names = VOCAB_FILES_NAMES
49
+
50
+ def __init__(
51
+ self,
52
+ vocab_file,
53
+ errors="replace",
54
+ **kwargs,
55
+ ):
56
+ super().__init__(**kwargs)
57
+
58
+ self.errors = errors # how to handle errors in decoding
59
+
60
+ self.mergeable_ranks = _load_tiktoken_bpe(vocab_file) # type: dict[bytes, int]
61
+ self.special_tokens = {
62
+ token: index
63
+ for index, token in enumerate(
64
+ SPECIAL_TOKENS, start=len(self.mergeable_ranks)
65
+ )
66
+ }
67
+
68
+ enc = tiktoken.Encoding(
69
+ "Qwen",
70
+ pat_str=PAT_STR,
71
+ mergeable_ranks=self.mergeable_ranks,
72
+ special_tokens=self.special_tokens,
73
+ )
74
+ assert (
75
+ len(self.mergeable_ranks) + len(self.special_tokens) == enc.n_vocab
76
+ ), f"{len(self.mergeable_ranks) + len(self.special_tokens)} != {enc.n_vocab} in encoding"
77
+
78
+ self.decoder = {
79
+ v: k for k, v in self.mergeable_ranks.items()
80
+ } # type: dict[int, bytes|str]
81
+ self.decoder.update({v: k for k, v in self.special_tokens.items()})
82
+
83
+ self.tokenizer = enc # type: tiktoken.Encoding
84
+
85
+ self.eod_id = self.tokenizer.eot_token
86
+ self.im_start_id = self.special_tokens[IMSTART]
87
+ self.im_end_id = self.special_tokens[IMEND]
88
+
89
+ def __len__(self) -> int:
90
+ return self.tokenizer.n_vocab
91
+
92
+ def get_vocab(self) -> Dict[bytes, int]:
93
+ return self.mergeable_ranks
94
+
95
+ def convert_tokens_to_ids(
96
+ self, tokens: Union[bytes, str, List[Union[bytes, str]]]
97
+ ) -> List[int]:
98
+ ids = []
99
+ if isinstance(tokens, (str, bytes)):
100
+ if tokens in self.special_tokens:
101
+ return self.special_tokens[tokens]
102
+ else:
103
+ return self.mergeable_ranks.get(tokens)
104
+ for token in tokens:
105
+ if token in self.special_tokens:
106
+ ids.append(self.special_tokens[token])
107
+ else:
108
+ ids.append(self.mergeable_ranks.get(token))
109
+ return ids
110
+
111
+ def _add_tokens(self, new_tokens: Union[List[str], List[AddedToken]], special_tokens: bool = False) -> int:
112
+ if not special_tokens and new_tokens:
113
+ raise ValueError('Adding regular tokens is not supported')
114
+ for token in new_tokens:
115
+ surface_form = token.content if isinstance(token, AddedToken) else token
116
+ if surface_form not in SPECIAL_TOKENS:
117
+ raise ValueError('Adding unknown special tokens is not supported')
118
+ return 0
119
+
120
+ def save_vocabulary(self, save_directory: str, **kwargs) -> Tuple[str]:
121
+ """
122
+ Save only the vocabulary of the tokenizer (vocabulary).
123
+
124
+ Returns:
125
+ `Tuple(str)`: Paths to the files saved.
126
+ """
127
+ file_path = os.path.join(save_directory, "qwen.tiktoken")
128
+ with open(file_path, "w", encoding="utf8") as w:
129
+ for k, v in self.mergeable_ranks.items():
130
+ line = base64.b64encode(k).decode("utf8") + " " + str(v) + "\n"
131
+ w.write(line)
132
+ return (file_path,)
133
+
134
+ def tokenize(
135
+ self,
136
+ text: str,
137
+ allowed_special: Union[Set, str] = "all",
138
+ disallowed_special: Union[Collection, str] = (),
139
+ **kwargs,
140
+ ) -> List[Union[bytes, str]]:
141
+ """
142
+ Converts a string in a sequence of tokens.
143
+
144
+ Args:
145
+ text (`str`):
146
+ The sequence to be encoded.
147
+ allowed_special (`Literal["all"]` or `set`):
148
+ The surface forms of the tokens to be encoded as special tokens in regular texts.
149
+ Default to "all".
150
+ disallowed_special (`Literal["all"]` or `Collection`):
151
+ The surface forms of the tokens that should not be in regular texts and trigger errors.
152
+ Default to an empty tuple.
153
+
154
+ kwargs (additional keyword arguments, *optional*):
155
+ Will be passed to the underlying model specific encode method.
156
+
157
+ Returns:
158
+ `List[bytes|str]`: The list of tokens.
159
+ """
160
+ tokens = []
161
+ text = unicodedata.normalize("NFC", text)
162
+
163
+ # this implementation takes a detour: text -> token id -> token surface forms
164
+ for t in self.tokenizer.encode(
165
+ text, allowed_special=allowed_special, disallowed_special=disallowed_special
166
+ ):
167
+ tokens.append(self.decoder[t])
168
+ return tokens
169
+
170
+ def convert_tokens_to_string(self, tokens: List[Union[bytes, str]]) -> str:
171
+ """
172
+ Converts a sequence of tokens in a single string.
173
+ """
174
+ text = ""
175
+ temp = b""
176
+ for t in tokens:
177
+ if isinstance(t, str):
178
+ if temp:
179
+ text += temp.decode("utf-8", errors=self.errors)
180
+ temp = b""
181
+ text += t
182
+ elif isinstance(t, bytes):
183
+ temp += t
184
+ else:
185
+ raise TypeError("token should only be of type types or str")
186
+ if temp:
187
+ text += temp.decode("utf-8", errors=self.errors)
188
+ return text
189
+
190
+ @property
191
+ def vocab_size(self):
192
+ return self.tokenizer.n_vocab
193
+
194
+ def _convert_id_to_token(self, index: int) -> Union[bytes, str]:
195
+ """Converts an id to a token, special tokens included"""
196
+ if index in self.decoder:
197
+ return self.decoder[index]
198
+ raise ValueError("unknown ids")
199
+
200
+ def _convert_token_to_id(self, token: Union[bytes, str]) -> int:
201
+ """Converts a token to an id using the vocab, special tokens included"""
202
+ if token in self.special_tokens:
203
+ return self.special_tokens[token]
204
+ if token in self.mergeable_ranks:
205
+ return self.mergeable_ranks[token]
206
+ raise ValueError("unknown token")
207
+
208
+ def _tokenize(self, text: str, **kwargs):
209
+ """
210
+ Converts a string in a sequence of tokens (string), using the tokenizer. Split in words for word-based
211
+ vocabulary or sub-words for sub-word-based vocabularies (BPE/SentencePieces/WordPieces).
212
+
213
+ Do NOT take care of added tokens.
214
+ """
215
+ raise NotImplementedError
216
+
217
+ def _decode(
218
+ self,
219
+ token_ids: Union[int, List[int]],
220
+ skip_special_tokens: bool = False,
221
+ errors: str = None,
222
+ **kwargs,
223
+ ) -> str:
224
+ if isinstance(token_ids, int):
225
+ token_ids = [token_ids]
226
+ if skip_special_tokens:
227
+ token_ids = [i for i in token_ids if i < self.eod_id]
228
+ return self.tokenizer.decode(token_ids, errors=errors or self.errors)
tokenizer_config.json ADDED
@@ -0,0 +1,10 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "model_max_length": 8192,
3
+ "tokenizer_class": "QWenTokenizer",
4
+ "auto_map": {
5
+ "AutoTokenizer": [
6
+ "tokenization_qwen.QWenTokenizer",
7
+ null
8
+ ]
9
+ }
10
+ }