Shengkun commited on
Commit
9d04c70
·
verified ·
1 Parent(s): fbbf1ac

Upload Qwen2ForCausalLM

Browse files
config.json ADDED
@@ -0,0 +1,1140 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "Qwen2ForCausalLM"
4
+ ],
5
+ "attention_dropout": 0.0,
6
+ "auto_map": {
7
+ "AutoConfig": "configuration_darwinlm.DarwinLMConfig",
8
+ "AutoModelForCausalLM": "modeling_darwinlm.Qwen2ForCausalLM"
9
+ },
10
+ "bos_token_id": 151643,
11
+ "dim_each_mlp": {
12
+ "0.mlp.down_proj": 6912,
13
+ "1.mlp.down_proj": 1376,
14
+ "10.mlp.down_proj": 4160,
15
+ "11.mlp.down_proj": 5536,
16
+ "12.mlp.down_proj": 6912,
17
+ "13.mlp.down_proj": 6912,
18
+ "14.mlp.down_proj": 6912,
19
+ "15.mlp.down_proj": 8288,
20
+ "16.mlp.down_proj": 6912,
21
+ "17.mlp.down_proj": 9664,
22
+ "18.mlp.down_proj": 4160,
23
+ "19.mlp.down_proj": 6912,
24
+ "2.mlp.down_proj": 2752,
25
+ "20.mlp.down_proj": 6912,
26
+ "21.mlp.down_proj": 5536,
27
+ "22.mlp.down_proj": 5536,
28
+ "23.mlp.down_proj": 6912,
29
+ "24.mlp.down_proj": 4160,
30
+ "25.mlp.down_proj": 8288,
31
+ "26.mlp.down_proj": 9664,
32
+ "27.mlp.down_proj": 6912,
33
+ "28.mlp.down_proj": 8288,
34
+ "29.mlp.down_proj": 6912,
35
+ "3.mlp.down_proj": 2752,
36
+ "30.mlp.down_proj": 5536,
37
+ "31.mlp.down_proj": 8288,
38
+ "32.mlp.down_proj": 6912,
39
+ "33.mlp.down_proj": 6912,
40
+ "34.mlp.down_proj": 9664,
41
+ "35.mlp.down_proj": 9664,
42
+ "36.mlp.down_proj": 9664,
43
+ "37.mlp.down_proj": 6912,
44
+ "38.mlp.down_proj": 8288,
45
+ "39.mlp.down_proj": 6912,
46
+ "4.mlp.down_proj": 5536,
47
+ "40.mlp.down_proj": 9664,
48
+ "41.mlp.down_proj": 6912,
49
+ "42.mlp.down_proj": 9664,
50
+ "43.mlp.down_proj": 6912,
51
+ "44.mlp.down_proj": 8288,
52
+ "45.mlp.down_proj": 8288,
53
+ "46.mlp.down_proj": 9664,
54
+ "47.mlp.down_proj": 8288,
55
+ "5.mlp.down_proj": 6912,
56
+ "6.mlp.down_proj": 5536,
57
+ "7.mlp.down_proj": 4160,
58
+ "8.mlp.down_proj": 6912,
59
+ "9.mlp.down_proj": 6912
60
+ },
61
+ "eos_token_id": 151645,
62
+ "heads_each_attn": {
63
+ "0.self_attn.o_proj": [
64
+ 5,
65
+ 7,
66
+ 9,
67
+ 21,
68
+ 24,
69
+ 25,
70
+ 28,
71
+ 32,
72
+ 33,
73
+ 34,
74
+ 36,
75
+ 37
76
+ ],
77
+ "1.self_attn.o_proj": [
78
+ 1,
79
+ 3,
80
+ 10,
81
+ 11,
82
+ 12,
83
+ 13,
84
+ 14,
85
+ 20,
86
+ 21,
87
+ 22,
88
+ 30,
89
+ 31,
90
+ 32,
91
+ 33,
92
+ 34,
93
+ 35,
94
+ 36,
95
+ 37,
96
+ 38,
97
+ 39
98
+ ],
99
+ "10.self_attn.o_proj": [
100
+ 0,
101
+ 4,
102
+ 7,
103
+ 8,
104
+ 12,
105
+ 14,
106
+ 15,
107
+ 16,
108
+ 17,
109
+ 18,
110
+ 20,
111
+ 22,
112
+ 23,
113
+ 25,
114
+ 28,
115
+ 30,
116
+ 33,
117
+ 35,
118
+ 38,
119
+ 39
120
+ ],
121
+ "11.self_attn.o_proj": [
122
+ 0,
123
+ 12,
124
+ 14,
125
+ 15,
126
+ 17,
127
+ 18,
128
+ 20,
129
+ 21,
130
+ 22,
131
+ 23,
132
+ 24,
133
+ 25,
134
+ 26,
135
+ 27,
136
+ 28,
137
+ 33,
138
+ 34,
139
+ 37,
140
+ 38,
141
+ 39
142
+ ],
143
+ "12.self_attn.o_proj": [
144
+ 0,
145
+ 1,
146
+ 2,
147
+ 3,
148
+ 4,
149
+ 5,
150
+ 6,
151
+ 7,
152
+ 8,
153
+ 9,
154
+ 10,
155
+ 11,
156
+ 12,
157
+ 13,
158
+ 15,
159
+ 16,
160
+ 17,
161
+ 18,
162
+ 19,
163
+ 20,
164
+ 21,
165
+ 25,
166
+ 28,
167
+ 29,
168
+ 30,
169
+ 31,
170
+ 33,
171
+ 35,
172
+ 36,
173
+ 37,
174
+ 38,
175
+ 39
176
+ ],
177
+ "13.self_attn.o_proj": [
178
+ 1,
179
+ 4,
180
+ 5,
181
+ 7,
182
+ 15,
183
+ 17,
184
+ 19,
185
+ 23,
186
+ 26,
187
+ 27,
188
+ 28,
189
+ 29,
190
+ 35,
191
+ 36,
192
+ 37,
193
+ 38
194
+ ],
195
+ "14.self_attn.o_proj": [
196
+ 0,
197
+ 1,
198
+ 3,
199
+ 5,
200
+ 6,
201
+ 8,
202
+ 9,
203
+ 10,
204
+ 11,
205
+ 12,
206
+ 14,
207
+ 15,
208
+ 17,
209
+ 19,
210
+ 21,
211
+ 22,
212
+ 24,
213
+ 25,
214
+ 28,
215
+ 29,
216
+ 31,
217
+ 32,
218
+ 33,
219
+ 35,
220
+ 36,
221
+ 37,
222
+ 38,
223
+ 39
224
+ ],
225
+ "15.self_attn.o_proj": [
226
+ 2,
227
+ 4,
228
+ 5,
229
+ 6,
230
+ 9,
231
+ 11,
232
+ 17,
233
+ 21,
234
+ 22,
235
+ 23,
236
+ 26,
237
+ 30,
238
+ 31,
239
+ 32,
240
+ 34,
241
+ 35
242
+ ],
243
+ "16.self_attn.o_proj": [
244
+ 1,
245
+ 3,
246
+ 4,
247
+ 7,
248
+ 9,
249
+ 12,
250
+ 18,
251
+ 19,
252
+ 20,
253
+ 21,
254
+ 22,
255
+ 23,
256
+ 25,
257
+ 28,
258
+ 30,
259
+ 31,
260
+ 35,
261
+ 36,
262
+ 38,
263
+ 39
264
+ ],
265
+ "17.self_attn.o_proj": [
266
+ 1,
267
+ 3,
268
+ 37,
269
+ 39
270
+ ],
271
+ "18.self_attn.o_proj": [
272
+ 1,
273
+ 6,
274
+ 7,
275
+ 9,
276
+ 11,
277
+ 12,
278
+ 13,
279
+ 14,
280
+ 19,
281
+ 22,
282
+ 23,
283
+ 30,
284
+ 34,
285
+ 35,
286
+ 37,
287
+ 39
288
+ ],
289
+ "19.self_attn.o_proj": [
290
+ 0,
291
+ 1,
292
+ 4,
293
+ 6,
294
+ 7,
295
+ 8,
296
+ 11,
297
+ 12,
298
+ 15,
299
+ 16,
300
+ 18,
301
+ 20,
302
+ 21,
303
+ 22,
304
+ 23,
305
+ 25,
306
+ 26,
307
+ 28,
308
+ 29,
309
+ 30,
310
+ 31,
311
+ 32,
312
+ 33,
313
+ 34
314
+ ],
315
+ "2.self_attn.o_proj": [
316
+ 0,
317
+ 1,
318
+ 2,
319
+ 3,
320
+ 5,
321
+ 6,
322
+ 7,
323
+ 8,
324
+ 9,
325
+ 12,
326
+ 15,
327
+ 21,
328
+ 23,
329
+ 25,
330
+ 26,
331
+ 29,
332
+ 30,
333
+ 31,
334
+ 32,
335
+ 33,
336
+ 34,
337
+ 35,
338
+ 37,
339
+ 38
340
+ ],
341
+ "20.self_attn.o_proj": [
342
+ 7,
343
+ 9,
344
+ 13,
345
+ 16,
346
+ 17,
347
+ 18,
348
+ 19,
349
+ 20,
350
+ 21,
351
+ 22,
352
+ 24,
353
+ 30,
354
+ 31,
355
+ 35,
356
+ 37,
357
+ 38
358
+ ],
359
+ "21.self_attn.o_proj": [
360
+ 0,
361
+ 2,
362
+ 4,
363
+ 5,
364
+ 6,
365
+ 9,
366
+ 10,
367
+ 11,
368
+ 13,
369
+ 20,
370
+ 21,
371
+ 22,
372
+ 26,
373
+ 27,
374
+ 30,
375
+ 33,
376
+ 34,
377
+ 35,
378
+ 36,
379
+ 39
380
+ ],
381
+ "22.self_attn.o_proj": [
382
+ 1,
383
+ 3,
384
+ 5,
385
+ 6,
386
+ 8,
387
+ 11,
388
+ 12,
389
+ 13,
390
+ 14,
391
+ 16,
392
+ 18,
393
+ 19,
394
+ 20,
395
+ 22,
396
+ 26,
397
+ 27,
398
+ 28,
399
+ 32,
400
+ 35,
401
+ 37
402
+ ],
403
+ "23.self_attn.o_proj": [
404
+ 0,
405
+ 1,
406
+ 11,
407
+ 12,
408
+ 15,
409
+ 16,
410
+ 18,
411
+ 19,
412
+ 21,
413
+ 22,
414
+ 27,
415
+ 28,
416
+ 33,
417
+ 35,
418
+ 36,
419
+ 39
420
+ ],
421
+ "24.self_attn.o_proj": [
422
+ 1,
423
+ 2,
424
+ 5,
425
+ 6,
426
+ 7,
427
+ 10,
428
+ 12,
429
+ 14,
430
+ 16,
431
+ 18,
432
+ 20,
433
+ 22,
434
+ 23,
435
+ 25,
436
+ 26,
437
+ 27,
438
+ 29,
439
+ 30,
440
+ 31,
441
+ 32,
442
+ 33,
443
+ 35,
444
+ 37,
445
+ 38
446
+ ],
447
+ "25.self_attn.o_proj": [
448
+ 0,
449
+ 1,
450
+ 2,
451
+ 3,
452
+ 16,
453
+ 27,
454
+ 28,
455
+ 39
456
+ ],
457
+ "26.self_attn.o_proj": [
458
+ 0,
459
+ 1,
460
+ 2,
461
+ 3,
462
+ 6,
463
+ 7,
464
+ 8,
465
+ 10,
466
+ 11,
467
+ 12,
468
+ 16,
469
+ 17,
470
+ 18,
471
+ 20,
472
+ 21,
473
+ 22,
474
+ 25,
475
+ 26,
476
+ 27,
477
+ 31,
478
+ 33,
479
+ 34,
480
+ 35,
481
+ 38
482
+ ],
483
+ "27.self_attn.o_proj": [
484
+ 0,
485
+ 2,
486
+ 4,
487
+ 6,
488
+ 8,
489
+ 11,
490
+ 12,
491
+ 13,
492
+ 14,
493
+ 22,
494
+ 23,
495
+ 25,
496
+ 26,
497
+ 27,
498
+ 28,
499
+ 31,
500
+ 32,
501
+ 33,
502
+ 37,
503
+ 38
504
+ ],
505
+ "28.self_attn.o_proj": [
506
+ 0,
507
+ 2,
508
+ 3,
509
+ 5,
510
+ 7,
511
+ 8,
512
+ 10,
513
+ 14,
514
+ 17,
515
+ 18,
516
+ 19,
517
+ 20,
518
+ 22,
519
+ 25,
520
+ 26,
521
+ 29,
522
+ 30,
523
+ 31,
524
+ 33,
525
+ 34,
526
+ 36,
527
+ 37,
528
+ 38,
529
+ 39
530
+ ],
531
+ "29.self_attn.o_proj": [
532
+ 13,
533
+ 25,
534
+ 29,
535
+ 34
536
+ ],
537
+ "3.self_attn.o_proj": [
538
+ 0,
539
+ 1,
540
+ 2,
541
+ 3,
542
+ 5,
543
+ 6,
544
+ 7,
545
+ 9,
546
+ 10,
547
+ 11,
548
+ 12,
549
+ 14,
550
+ 15,
551
+ 16,
552
+ 17,
553
+ 18,
554
+ 19,
555
+ 20,
556
+ 21,
557
+ 22,
558
+ 23,
559
+ 24,
560
+ 25,
561
+ 26,
562
+ 27,
563
+ 28,
564
+ 36,
565
+ 37
566
+ ],
567
+ "30.self_attn.o_proj": [
568
+ 0,
569
+ 2,
570
+ 4,
571
+ 6,
572
+ 11,
573
+ 14,
574
+ 16,
575
+ 18,
576
+ 20,
577
+ 21,
578
+ 23,
579
+ 25,
580
+ 28,
581
+ 29,
582
+ 31,
583
+ 39
584
+ ],
585
+ "31.self_attn.o_proj": [
586
+ 2,
587
+ 3,
588
+ 4,
589
+ 5,
590
+ 8,
591
+ 12,
592
+ 13,
593
+ 15,
594
+ 17,
595
+ 19,
596
+ 20,
597
+ 21,
598
+ 26,
599
+ 28,
600
+ 30,
601
+ 31,
602
+ 33,
603
+ 36,
604
+ 37,
605
+ 38
606
+ ],
607
+ "32.self_attn.o_proj": [
608
+ 1,
609
+ 8,
610
+ 11,
611
+ 12,
612
+ 14,
613
+ 16,
614
+ 19,
615
+ 29,
616
+ 30,
617
+ 31,
618
+ 32,
619
+ 36
620
+ ],
621
+ "33.self_attn.o_proj": [
622
+ 0,
623
+ 3,
624
+ 4,
625
+ 5,
626
+ 8,
627
+ 12,
628
+ 17,
629
+ 22,
630
+ 23,
631
+ 27,
632
+ 29,
633
+ 30,
634
+ 31,
635
+ 34,
636
+ 35,
637
+ 38
638
+ ],
639
+ "34.self_attn.o_proj": [
640
+ 1,
641
+ 3,
642
+ 4,
643
+ 6,
644
+ 7,
645
+ 8,
646
+ 9,
647
+ 10,
648
+ 13,
649
+ 15,
650
+ 20,
651
+ 21,
652
+ 23,
653
+ 25,
654
+ 27,
655
+ 29,
656
+ 31,
657
+ 32,
658
+ 36,
659
+ 37
660
+ ],
661
+ "35.self_attn.o_proj": [
662
+ 0,
663
+ 1,
664
+ 2,
665
+ 5,
666
+ 6,
667
+ 9,
668
+ 12,
669
+ 13,
670
+ 14,
671
+ 16,
672
+ 17,
673
+ 19,
674
+ 21,
675
+ 22,
676
+ 27,
677
+ 28,
678
+ 29,
679
+ 31,
680
+ 32,
681
+ 33,
682
+ 34,
683
+ 35,
684
+ 36,
685
+ 39
686
+ ],
687
+ "36.self_attn.o_proj": [
688
+ 0,
689
+ 3,
690
+ 4,
691
+ 5,
692
+ 9,
693
+ 13,
694
+ 14,
695
+ 15,
696
+ 16,
697
+ 17,
698
+ 18,
699
+ 20,
700
+ 22,
701
+ 24,
702
+ 25,
703
+ 26,
704
+ 28,
705
+ 29,
706
+ 32,
707
+ 34,
708
+ 36,
709
+ 37,
710
+ 38,
711
+ 39
712
+ ],
713
+ "37.self_attn.o_proj": [
714
+ 0,
715
+ 1,
716
+ 5,
717
+ 11,
718
+ 12,
719
+ 13,
720
+ 15,
721
+ 19,
722
+ 21,
723
+ 24,
724
+ 25,
725
+ 27,
726
+ 29,
727
+ 30,
728
+ 31,
729
+ 35
730
+ ],
731
+ "38.self_attn.o_proj": [
732
+ 0,
733
+ 1,
734
+ 2,
735
+ 3,
736
+ 4,
737
+ 5,
738
+ 6,
739
+ 9,
740
+ 14,
741
+ 15,
742
+ 18,
743
+ 19,
744
+ 23,
745
+ 24,
746
+ 25,
747
+ 27,
748
+ 28,
749
+ 29,
750
+ 31,
751
+ 32,
752
+ 33,
753
+ 34,
754
+ 37,
755
+ 38
756
+ ],
757
+ "39.self_attn.o_proj": [
758
+ 0,
759
+ 1,
760
+ 2,
761
+ 3,
762
+ 4,
763
+ 5,
764
+ 6,
765
+ 7,
766
+ 8,
767
+ 9,
768
+ 10,
769
+ 11,
770
+ 12,
771
+ 13,
772
+ 14,
773
+ 15,
774
+ 16,
775
+ 17,
776
+ 18,
777
+ 19,
778
+ 20,
779
+ 21,
780
+ 22,
781
+ 23,
782
+ 24,
783
+ 25,
784
+ 26,
785
+ 27,
786
+ 28,
787
+ 29,
788
+ 30,
789
+ 31,
790
+ 32,
791
+ 33,
792
+ 34,
793
+ 35,
794
+ 36,
795
+ 37,
796
+ 38,
797
+ 39
798
+ ],
799
+ "4.self_attn.o_proj": [
800
+ 1,
801
+ 2,
802
+ 4,
803
+ 6,
804
+ 7,
805
+ 10,
806
+ 11,
807
+ 12,
808
+ 13,
809
+ 14,
810
+ 15,
811
+ 17,
812
+ 18,
813
+ 21,
814
+ 22,
815
+ 30,
816
+ 32,
817
+ 33,
818
+ 34,
819
+ 37
820
+ ],
821
+ "40.self_attn.o_proj": [
822
+ 0,
823
+ 3,
824
+ 13,
825
+ 14,
826
+ 15,
827
+ 17,
828
+ 25,
829
+ 26,
830
+ 27,
831
+ 29,
832
+ 31,
833
+ 33,
834
+ 34,
835
+ 36,
836
+ 38,
837
+ 39
838
+ ],
839
+ "41.self_attn.o_proj": [
840
+ 1,
841
+ 10,
842
+ 12,
843
+ 13,
844
+ 15,
845
+ 19,
846
+ 20,
847
+ 21,
848
+ 23,
849
+ 26,
850
+ 27,
851
+ 29,
852
+ 32,
853
+ 33,
854
+ 34,
855
+ 39
856
+ ],
857
+ "42.self_attn.o_proj": [
858
+ 0,
859
+ 2,
860
+ 3,
861
+ 4,
862
+ 5,
863
+ 6,
864
+ 9,
865
+ 10,
866
+ 16,
867
+ 19,
868
+ 20,
869
+ 22,
870
+ 26,
871
+ 27,
872
+ 32,
873
+ 33,
874
+ 34,
875
+ 35,
876
+ 36,
877
+ 38
878
+ ],
879
+ "43.self_attn.o_proj": [
880
+ 3,
881
+ 6,
882
+ 7,
883
+ 8,
884
+ 9,
885
+ 10,
886
+ 12,
887
+ 13,
888
+ 14,
889
+ 17,
890
+ 18,
891
+ 19,
892
+ 20,
893
+ 24,
894
+ 31,
895
+ 38
896
+ ],
897
+ "44.self_attn.o_proj": [
898
+ 0,
899
+ 2,
900
+ 6,
901
+ 9,
902
+ 10,
903
+ 11,
904
+ 14,
905
+ 20,
906
+ 22,
907
+ 23,
908
+ 25,
909
+ 26,
910
+ 27,
911
+ 28,
912
+ 31,
913
+ 32,
914
+ 34,
915
+ 36,
916
+ 37,
917
+ 38
918
+ ],
919
+ "45.self_attn.o_proj": [
920
+ 1,
921
+ 4,
922
+ 5,
923
+ 6,
924
+ 7,
925
+ 8,
926
+ 11,
927
+ 18,
928
+ 21,
929
+ 22,
930
+ 23,
931
+ 24,
932
+ 25,
933
+ 28,
934
+ 32,
935
+ 33,
936
+ 34,
937
+ 35,
938
+ 36,
939
+ 39
940
+ ],
941
+ "46.self_attn.o_proj": [
942
+ 0,
943
+ 1,
944
+ 3,
945
+ 4,
946
+ 5,
947
+ 6,
948
+ 9,
949
+ 20,
950
+ 21,
951
+ 22,
952
+ 23,
953
+ 25,
954
+ 26,
955
+ 27,
956
+ 29,
957
+ 31,
958
+ 33,
959
+ 34,
960
+ 35,
961
+ 37
962
+ ],
963
+ "47.self_attn.o_proj": [
964
+ 0,
965
+ 2,
966
+ 3,
967
+ 5,
968
+ 6,
969
+ 8,
970
+ 10,
971
+ 11,
972
+ 13,
973
+ 14,
974
+ 15,
975
+ 16,
976
+ 17,
977
+ 18,
978
+ 19,
979
+ 22,
980
+ 25,
981
+ 26,
982
+ 27,
983
+ 29,
984
+ 33,
985
+ 35,
986
+ 36,
987
+ 38
988
+ ],
989
+ "5.self_attn.o_proj": [
990
+ 0,
991
+ 3,
992
+ 4,
993
+ 5,
994
+ 7,
995
+ 9,
996
+ 10,
997
+ 11,
998
+ 12,
999
+ 13,
1000
+ 14,
1001
+ 15,
1002
+ 16,
1003
+ 17,
1004
+ 18,
1005
+ 19,
1006
+ 25,
1007
+ 26,
1008
+ 27,
1009
+ 29,
1010
+ 30,
1011
+ 31,
1012
+ 32,
1013
+ 33,
1014
+ 35,
1015
+ 36,
1016
+ 37,
1017
+ 39
1018
+ ],
1019
+ "6.self_attn.o_proj": [
1020
+ 0,
1021
+ 1,
1022
+ 2,
1023
+ 4,
1024
+ 5,
1025
+ 6,
1026
+ 7,
1027
+ 9,
1028
+ 11,
1029
+ 15,
1030
+ 16,
1031
+ 17,
1032
+ 18,
1033
+ 19,
1034
+ 20,
1035
+ 22,
1036
+ 23,
1037
+ 26,
1038
+ 27,
1039
+ 28,
1040
+ 29,
1041
+ 30,
1042
+ 32,
1043
+ 33,
1044
+ 34,
1045
+ 35,
1046
+ 38,
1047
+ 39
1048
+ ],
1049
+ "7.self_attn.o_proj": [
1050
+ 1,
1051
+ 3,
1052
+ 5,
1053
+ 6,
1054
+ 8,
1055
+ 9,
1056
+ 10,
1057
+ 11,
1058
+ 12,
1059
+ 13,
1060
+ 16,
1061
+ 19,
1062
+ 20,
1063
+ 21,
1064
+ 22,
1065
+ 23,
1066
+ 34,
1067
+ 35,
1068
+ 36,
1069
+ 38
1070
+ ],
1071
+ "8.self_attn.o_proj": [
1072
+ 1,
1073
+ 2,
1074
+ 3,
1075
+ 4,
1076
+ 5,
1077
+ 8,
1078
+ 10,
1079
+ 11,
1080
+ 12,
1081
+ 14,
1082
+ 15,
1083
+ 17,
1084
+ 19,
1085
+ 21,
1086
+ 23,
1087
+ 25,
1088
+ 26,
1089
+ 28,
1090
+ 29,
1091
+ 30,
1092
+ 31,
1093
+ 33,
1094
+ 34,
1095
+ 35,
1096
+ 36,
1097
+ 37,
1098
+ 38,
1099
+ 39
1100
+ ],
1101
+ "9.self_attn.o_proj": [
1102
+ 8,
1103
+ 10,
1104
+ 11,
1105
+ 13,
1106
+ 14,
1107
+ 15,
1108
+ 17,
1109
+ 18,
1110
+ 22,
1111
+ 25,
1112
+ 26,
1113
+ 28,
1114
+ 29,
1115
+ 30,
1116
+ 32,
1117
+ 39
1118
+ ]
1119
+ },
1120
+ "hidden_act": "silu",
1121
+ "hidden_size": 5120,
1122
+ "initializer_range": 0.02,
1123
+ "intermediate_size": 13824,
1124
+ "kv_ignore": true,
1125
+ "max_position_embeddings": 32768,
1126
+ "max_window_layers": 70,
1127
+ "model_type": "darwinlm",
1128
+ "num_attention_heads": 40,
1129
+ "num_hidden_layers": 48,
1130
+ "num_key_value_heads": 8,
1131
+ "rms_norm_eps": 1e-06,
1132
+ "rope_theta": 1000000.0,
1133
+ "sliding_window": null,
1134
+ "tie_word_embeddings": false,
1135
+ "torch_dtype": "float32",
1136
+ "transformers_version": "4.45.0.dev0",
1137
+ "use_cache": true,
1138
+ "use_sliding_window": false,
1139
+ "vocab_size": 152064
1140
+ }
configuration_darwinlm.py ADDED
@@ -0,0 +1,193 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2024 The Qwen team, Alibaba Group and the HuggingFace Inc. team. All rights reserved.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ """Qwen2 model configuration"""
16
+
17
+ from transformers.configuration_utils import PretrainedConfig
18
+ from transformers.utils import logging
19
+
20
+
21
+ logger = logging.get_logger(__name__)
22
+
23
+
24
+ class DarwinLMConfig(PretrainedConfig):
25
+ r"""
26
+ This is the configuration class to store the configuration of a [`Qwen2Model`]. It is used to instantiate a
27
+ Qwen2 model according to the specified arguments, defining the model architecture. Instantiating a configuration
28
+ with the defaults will yield a similar configuration to that of
29
+ Qwen2-7B-beta [Qwen/Qwen2-7B-beta](https://huggingface.co/Qwen/Qwen2-7B-beta).
30
+
31
+ Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
32
+ documentation from [`PretrainedConfig`] for more information.
33
+
34
+
35
+ Args:
36
+ vocab_size (`int`, *optional*, defaults to 151936):
37
+ Vocabulary size of the Qwen2 model. Defines the number of different tokens that can be represented by the
38
+ `inputs_ids` passed when calling [`Qwen2Model`]
39
+ hidden_size (`int`, *optional*, defaults to 4096):
40
+ Dimension of the hidden representations.
41
+ intermediate_size (`int`, *optional*, defaults to 22016):
42
+ Dimension of the MLP representations.
43
+ num_hidden_layers (`int`, *optional*, defaults to 32):
44
+ Number of hidden layers in the Transformer encoder.
45
+ num_attention_heads (`int`, *optional*, defaults to 32):
46
+ Number of attention heads for each attention layer in the Transformer encoder.
47
+ num_key_value_heads (`int`, *optional*, defaults to 32):
48
+ This is the number of key_value heads that should be used to implement Grouped Query Attention. If
49
+ `num_key_value_heads=num_attention_heads`, the model will use Multi Head Attention (MHA), if
50
+ `num_key_value_heads=1` the model will use Multi Query Attention (MQA) otherwise GQA is used. When
51
+ converting a multi-head checkpoint to a GQA checkpoint, each group key and value head should be constructed
52
+ by meanpooling all the original heads within that group. For more details checkout [this
53
+ paper](https://arxiv.org/pdf/2305.13245.pdf). If it is not specified, will default to `32`.
54
+ hidden_act (`str` or `function`, *optional*, defaults to `"silu"`):
55
+ The non-linear activation function (function or string) in the decoder.
56
+ max_position_embeddings (`int`, *optional*, defaults to 32768):
57
+ The maximum sequence length that this model might ever be used with.
58
+ initializer_range (`float`, *optional*, defaults to 0.02):
59
+ The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
60
+ rms_norm_eps (`float`, *optional*, defaults to 1e-06):
61
+ The epsilon used by the rms normalization layers.
62
+ use_cache (`bool`, *optional*, defaults to `True`):
63
+ Whether or not the model should return the last key/values attentions (not used by all models). Only
64
+ relevant if `config.is_decoder=True`.
65
+ tie_word_embeddings (`bool`, *optional*, defaults to `False`):
66
+ Whether the model's input and output word embeddings should be tied.
67
+ rope_theta (`float`, *optional*, defaults to 10000.0):
68
+ The base period of the RoPE embeddings.
69
+ use_sliding_window (`bool`, *optional*, defaults to `False`):
70
+ Whether to use sliding window attention.
71
+ sliding_window (`int`, *optional*, defaults to 4096):
72
+ Sliding window attention (SWA) window size. If not specified, will default to `4096`.
73
+ max_window_layers (`int`, *optional*, defaults to 28):
74
+ The number of layers that use SWA (Sliding Window Attention). The bottom layers use SWA while the top use full attention.
75
+ attention_dropout (`float`, *optional*, defaults to 0.0):
76
+ The dropout ratio for the attention probabilities.
77
+
78
+ ```python
79
+ >>> from transformers import Qwen2Model, Qwen2Config
80
+
81
+ >>> # Initializing a Qwen2 style configuration
82
+ >>> configuration = Qwen2Config()
83
+
84
+ >>> # Initializing a model from the Qwen2-7B style configuration
85
+ >>> model = Qwen2Model(configuration)
86
+
87
+ >>> # Accessing the model configuration
88
+ >>> configuration = model.config
89
+ ```"""
90
+
91
+ model_type = "darwinlm"
92
+ keys_to_ignore_at_inference = ["past_key_values"]
93
+
94
+ def __init__(
95
+ self,
96
+ vocab_size=151936,
97
+ hidden_size=4096,
98
+ intermediate_size=22016,
99
+ num_hidden_layers=32,
100
+ num_attention_heads=32,
101
+ num_key_value_heads=32,
102
+ hidden_act="silu",
103
+ max_position_embeddings=32768,
104
+ initializer_range=0.02,
105
+ rms_norm_eps=1e-6,
106
+ use_cache=True,
107
+ tie_word_embeddings=False,
108
+ rope_theta=10000.0,
109
+ use_sliding_window=False,
110
+ sliding_window=4096,
111
+ max_window_layers=28,
112
+ attention_dropout=0.0,
113
+ kv_ignore=False,
114
+ dim_each_mlp={"0.mlp.down_proj": 22016, "1.mlp.down_proj": 22016,
115
+ "2.mlp.down_proj": 22016, "3.mlp.down_proj": 22016,
116
+ "4.mlp.down_proj": 22016, "5.mlp.down_proj": 22016,
117
+ "6.mlp.down_proj": 22016, "7.mlp.down_proj": 22016,
118
+ "8.mlp.down_proj": 22016, "9.mlp.down_proj": 22016,
119
+ "10.mlp.down_proj": 22016, "11.mlp.down_proj": 22016,
120
+ "12.mlp.down_proj": 22016, "13.mlp.down_proj": 22016,
121
+ "14.mlp.down_proj": 22016, "15.mlp.down_proj": 22016,
122
+ "16.mlp.down_proj": 22016, "17.mlp.down_proj": 22016,
123
+ "18.mlp.down_proj": 22016, "19.mlp.down_proj": 22016,
124
+ "20.mlp.down_proj": 22016, "21.mlp.down_proj": 22016,
125
+ "22.mlp.down_proj": 22016, "23.mlp.down_proj": 22016,
126
+ "24.mlp.down_proj": 22016, "25.mlp.down_proj": 22016,
127
+ "26.mlp.down_proj": 22016, "27.mlp.down_proj": 22016,
128
+ "28.mlp.down_proj": 22016, "29.mlp.down_proj": 22016,
129
+ "30.mlp.down_proj": 22016, "31.mlp.down_proj": 22016,
130
+ "32.mlp.down_proj": 22016, "33.mlp.down_proj": 22016,
131
+ "34.mlp.down_proj": 22016, "35.mlp.down_proj": 22016,
132
+ "36.mlp.down_proj": 22016, "37.mlp.down_proj": 22016,
133
+ "38.mlp.down_proj": 22016, "39.mlp.down_proj": 22016,
134
+ "40.mlp.down_proj": 22016, "41.mlp.down_proj": 22016,
135
+ "42.mlp.down_proj": 22016, "43.mlp.down_proj": 22016,
136
+ "44.mlp.down_proj": 22016, "45.mlp.down_proj": 22016,
137
+ "46.mlp.down_proj": 22016, "47.mlp.down_proj": 22016,},
138
+ heads_each_attn={"0.self_attn.o_proj": 32, "1.self_attn.o_proj": 32,
139
+ "2.self_attn.o_proj": 32, "3.self_attn.o_proj": 32,
140
+ "4.self_attn.o_proj": 32, "5.self_attn.o_proj": 32,
141
+ "6.self_attn.o_proj": 32, "7.self_attn.o_proj": 32,
142
+ "8.self_attn.o_proj": 32, "9.self_attn.o_proj": 32,
143
+ "10.self_attn.o_proj": 32, "11.self_attn.o_proj": 32,
144
+ "12.self_attn.o_proj": 32, "13.self_attn.o_proj": 32,
145
+ "14.self_attn.o_proj": 32, "15.self_attn.o_proj": 32,
146
+ "16.self_attn.o_proj": 32, "17.self_attn.o_proj": 32,
147
+ "18.self_attn.o_proj": 32, "19.self_attn.o_proj": 32,
148
+ "20.self_attn.o_proj": 32, "21.self_attn.o_proj": 32,
149
+ "22.self_attn.o_proj": 32, "23.self_attn.o_proj": 32,
150
+ "24.self_attn.o_proj": 32, "25.self_attn.o_proj": 32,
151
+ "26.self_attn.o_proj": 32, "27.self_attn.o_proj": 32,
152
+ "28.self_attn.o_proj": 32, "29.self_attn.o_proj": 32,
153
+ "30.self_attn.o_proj": 32, "31.self_attn.o_proj": 32,
154
+ "32.self_attn.o_proj": 32, "33.self_attn.o_proj": 32,
155
+ "34.self_attn.o_proj": 32, "35.self_attn.o_proj": 32,
156
+ "36.self_attn.o_proj": 32, "37.self_attn.o_proj": 32,
157
+ "38.self_attn.o_proj": 32, "39.self_attn.o_proj": 32,
158
+ "40.self_attn.o_proj": 32, "41.self_attn.o_proj": 32,
159
+ "42.self_attn.o_proj": 32, "43.self_attn.o_proj": 32,
160
+ "44.self_attn.o_proj": 32, "45.self_attn.o_proj": 32,
161
+ "46.self_attn.o_proj": 32, "47.self_attn.o_proj": 32,},
162
+
163
+ **kwargs,
164
+ ):
165
+ self.vocab_size = vocab_size
166
+ self.max_position_embeddings = max_position_embeddings
167
+ self.hidden_size = hidden_size
168
+ self.intermediate_size = intermediate_size
169
+ self.num_hidden_layers = num_hidden_layers
170
+ self.num_attention_heads = num_attention_heads
171
+ self.use_sliding_window = use_sliding_window
172
+ self.sliding_window = sliding_window if use_sliding_window else None
173
+ self.max_window_layers = max_window_layers
174
+ self.kv_ignore = kv_ignore
175
+ self.heads_each_attn = heads_each_attn
176
+ self.dim_each_mlp = dim_each_mlp
177
+
178
+ # for backward compatibility
179
+ if num_key_value_heads is None:
180
+ num_key_value_heads = num_attention_heads
181
+
182
+ self.num_key_value_heads = num_key_value_heads
183
+ self.hidden_act = hidden_act
184
+ self.initializer_range = initializer_range
185
+ self.rms_norm_eps = rms_norm_eps
186
+ self.use_cache = use_cache
187
+ self.rope_theta = rope_theta
188
+ self.attention_dropout = attention_dropout
189
+
190
+ super().__init__(
191
+ tie_word_embeddings=tie_word_embeddings,
192
+ **kwargs,
193
+ )
generation_config.json ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "bos_token_id": 151643,
4
+ "eos_token_id": 151645,
5
+ "transformers_version": "4.45.0.dev0"
6
+ }
model-00001-of-00007.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7d360ad0a16753ca726a3279cac3cd5f8546ce711404fe6947fb94d0922ba6b6
3
+ size 4901697976
model-00002-of-00007.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f47b1d3d7534acd96de46edc798a03eb93819b31b2460a1fc571373b648fd3d1
3
+ size 4991155488
model-00003-of-00007.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e4f8bc402a366d637253f8aa953c79584e197b74502b2563eddacdd7b2592a21
3
+ size 4922969912
model-00004-of-00007.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2a787e4694e5f806f4afe7afcef4e7c464590081cab6cb425da5aa51b8feac38
3
+ size 4931425072
model-00005-of-00007.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6e850c68e9e40f6b45a0a5e78972f25385dad013a0608c730d8e96a6ad56114f
3
+ size 4953024304
model-00006-of-00007.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:595416d318d88ab8e13ffbf2450e214ceba78300d56c08990b1d5a06ff288e5e
3
+ size 4966749784
model-00007-of-00007.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7d0c5e0ca97e222c3c14337fc576eac8295600f0f865157b1e04cede2df84186
3
+ size 3947354000
model.safetensors.index.json ADDED
@@ -0,0 +1,579 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "metadata": {
3
+ "total_size": 33614311424
4
+ },
5
+ "weight_map": {
6
+ "lm_head.weight": "model-00007-of-00007.safetensors",
7
+ "model.embed_tokens.weight": "model-00001-of-00007.safetensors",
8
+ "model.layers.0.input_layernorm.weight": "model-00001-of-00007.safetensors",
9
+ "model.layers.0.mlp.down_proj.weight": "model-00001-of-00007.safetensors",
10
+ "model.layers.0.mlp.gate_proj.weight": "model-00001-of-00007.safetensors",
11
+ "model.layers.0.mlp.up_proj.weight": "model-00001-of-00007.safetensors",
12
+ "model.layers.0.post_attention_layernorm.weight": "model-00001-of-00007.safetensors",
13
+ "model.layers.0.self_attn.k_proj.bias": "model-00001-of-00007.safetensors",
14
+ "model.layers.0.self_attn.k_proj.weight": "model-00001-of-00007.safetensors",
15
+ "model.layers.0.self_attn.o_proj.weight": "model-00001-of-00007.safetensors",
16
+ "model.layers.0.self_attn.q_proj.bias": "model-00001-of-00007.safetensors",
17
+ "model.layers.0.self_attn.q_proj.weight": "model-00001-of-00007.safetensors",
18
+ "model.layers.0.self_attn.v_proj.bias": "model-00001-of-00007.safetensors",
19
+ "model.layers.0.self_attn.v_proj.weight": "model-00001-of-00007.safetensors",
20
+ "model.layers.1.input_layernorm.weight": "model-00001-of-00007.safetensors",
21
+ "model.layers.1.mlp.down_proj.weight": "model-00001-of-00007.safetensors",
22
+ "model.layers.1.mlp.gate_proj.weight": "model-00001-of-00007.safetensors",
23
+ "model.layers.1.mlp.up_proj.weight": "model-00001-of-00007.safetensors",
24
+ "model.layers.1.post_attention_layernorm.weight": "model-00001-of-00007.safetensors",
25
+ "model.layers.1.self_attn.k_proj.bias": "model-00001-of-00007.safetensors",
26
+ "model.layers.1.self_attn.k_proj.weight": "model-00001-of-00007.safetensors",
27
+ "model.layers.1.self_attn.o_proj.weight": "model-00001-of-00007.safetensors",
28
+ "model.layers.1.self_attn.q_proj.bias": "model-00001-of-00007.safetensors",
29
+ "model.layers.1.self_attn.q_proj.weight": "model-00001-of-00007.safetensors",
30
+ "model.layers.1.self_attn.v_proj.bias": "model-00001-of-00007.safetensors",
31
+ "model.layers.1.self_attn.v_proj.weight": "model-00001-of-00007.safetensors",
32
+ "model.layers.10.input_layernorm.weight": "model-00002-of-00007.safetensors",
33
+ "model.layers.10.mlp.down_proj.weight": "model-00002-of-00007.safetensors",
34
+ "model.layers.10.mlp.gate_proj.weight": "model-00002-of-00007.safetensors",
35
+ "model.layers.10.mlp.up_proj.weight": "model-00002-of-00007.safetensors",
36
+ "model.layers.10.post_attention_layernorm.weight": "model-00002-of-00007.safetensors",
37
+ "model.layers.10.self_attn.k_proj.bias": "model-00002-of-00007.safetensors",
38
+ "model.layers.10.self_attn.k_proj.weight": "model-00002-of-00007.safetensors",
39
+ "model.layers.10.self_attn.o_proj.weight": "model-00002-of-00007.safetensors",
40
+ "model.layers.10.self_attn.q_proj.bias": "model-00002-of-00007.safetensors",
41
+ "model.layers.10.self_attn.q_proj.weight": "model-00002-of-00007.safetensors",
42
+ "model.layers.10.self_attn.v_proj.bias": "model-00002-of-00007.safetensors",
43
+ "model.layers.10.self_attn.v_proj.weight": "model-00002-of-00007.safetensors",
44
+ "model.layers.11.input_layernorm.weight": "model-00002-of-00007.safetensors",
45
+ "model.layers.11.mlp.down_proj.weight": "model-00002-of-00007.safetensors",
46
+ "model.layers.11.mlp.gate_proj.weight": "model-00002-of-00007.safetensors",
47
+ "model.layers.11.mlp.up_proj.weight": "model-00002-of-00007.safetensors",
48
+ "model.layers.11.post_attention_layernorm.weight": "model-00002-of-00007.safetensors",
49
+ "model.layers.11.self_attn.k_proj.bias": "model-00002-of-00007.safetensors",
50
+ "model.layers.11.self_attn.k_proj.weight": "model-00002-of-00007.safetensors",
51
+ "model.layers.11.self_attn.o_proj.weight": "model-00002-of-00007.safetensors",
52
+ "model.layers.11.self_attn.q_proj.bias": "model-00002-of-00007.safetensors",
53
+ "model.layers.11.self_attn.q_proj.weight": "model-00002-of-00007.safetensors",
54
+ "model.layers.11.self_attn.v_proj.bias": "model-00002-of-00007.safetensors",
55
+ "model.layers.11.self_attn.v_proj.weight": "model-00002-of-00007.safetensors",
56
+ "model.layers.12.input_layernorm.weight": "model-00002-of-00007.safetensors",
57
+ "model.layers.12.mlp.down_proj.weight": "model-00002-of-00007.safetensors",
58
+ "model.layers.12.mlp.gate_proj.weight": "model-00002-of-00007.safetensors",
59
+ "model.layers.12.mlp.up_proj.weight": "model-00002-of-00007.safetensors",
60
+ "model.layers.12.post_attention_layernorm.weight": "model-00002-of-00007.safetensors",
61
+ "model.layers.12.self_attn.k_proj.bias": "model-00002-of-00007.safetensors",
62
+ "model.layers.12.self_attn.k_proj.weight": "model-00002-of-00007.safetensors",
63
+ "model.layers.12.self_attn.o_proj.weight": "model-00002-of-00007.safetensors",
64
+ "model.layers.12.self_attn.q_proj.bias": "model-00002-of-00007.safetensors",
65
+ "model.layers.12.self_attn.q_proj.weight": "model-00002-of-00007.safetensors",
66
+ "model.layers.12.self_attn.v_proj.bias": "model-00002-of-00007.safetensors",
67
+ "model.layers.12.self_attn.v_proj.weight": "model-00002-of-00007.safetensors",
68
+ "model.layers.13.input_layernorm.weight": "model-00002-of-00007.safetensors",
69
+ "model.layers.13.mlp.down_proj.weight": "model-00002-of-00007.safetensors",
70
+ "model.layers.13.mlp.gate_proj.weight": "model-00002-of-00007.safetensors",
71
+ "model.layers.13.mlp.up_proj.weight": "model-00002-of-00007.safetensors",
72
+ "model.layers.13.post_attention_layernorm.weight": "model-00002-of-00007.safetensors",
73
+ "model.layers.13.self_attn.k_proj.bias": "model-00002-of-00007.safetensors",
74
+ "model.layers.13.self_attn.k_proj.weight": "model-00002-of-00007.safetensors",
75
+ "model.layers.13.self_attn.o_proj.weight": "model-00002-of-00007.safetensors",
76
+ "model.layers.13.self_attn.q_proj.bias": "model-00002-of-00007.safetensors",
77
+ "model.layers.13.self_attn.q_proj.weight": "model-00002-of-00007.safetensors",
78
+ "model.layers.13.self_attn.v_proj.bias": "model-00002-of-00007.safetensors",
79
+ "model.layers.13.self_attn.v_proj.weight": "model-00002-of-00007.safetensors",
80
+ "model.layers.14.input_layernorm.weight": "model-00003-of-00007.safetensors",
81
+ "model.layers.14.mlp.down_proj.weight": "model-00003-of-00007.safetensors",
82
+ "model.layers.14.mlp.gate_proj.weight": "model-00002-of-00007.safetensors",
83
+ "model.layers.14.mlp.up_proj.weight": "model-00002-of-00007.safetensors",
84
+ "model.layers.14.post_attention_layernorm.weight": "model-00003-of-00007.safetensors",
85
+ "model.layers.14.self_attn.k_proj.bias": "model-00002-of-00007.safetensors",
86
+ "model.layers.14.self_attn.k_proj.weight": "model-00002-of-00007.safetensors",
87
+ "model.layers.14.self_attn.o_proj.weight": "model-00002-of-00007.safetensors",
88
+ "model.layers.14.self_attn.q_proj.bias": "model-00002-of-00007.safetensors",
89
+ "model.layers.14.self_attn.q_proj.weight": "model-00002-of-00007.safetensors",
90
+ "model.layers.14.self_attn.v_proj.bias": "model-00002-of-00007.safetensors",
91
+ "model.layers.14.self_attn.v_proj.weight": "model-00002-of-00007.safetensors",
92
+ "model.layers.15.input_layernorm.weight": "model-00003-of-00007.safetensors",
93
+ "model.layers.15.mlp.down_proj.weight": "model-00003-of-00007.safetensors",
94
+ "model.layers.15.mlp.gate_proj.weight": "model-00003-of-00007.safetensors",
95
+ "model.layers.15.mlp.up_proj.weight": "model-00003-of-00007.safetensors",
96
+ "model.layers.15.post_attention_layernorm.weight": "model-00003-of-00007.safetensors",
97
+ "model.layers.15.self_attn.k_proj.bias": "model-00003-of-00007.safetensors",
98
+ "model.layers.15.self_attn.k_proj.weight": "model-00003-of-00007.safetensors",
99
+ "model.layers.15.self_attn.o_proj.weight": "model-00003-of-00007.safetensors",
100
+ "model.layers.15.self_attn.q_proj.bias": "model-00003-of-00007.safetensors",
101
+ "model.layers.15.self_attn.q_proj.weight": "model-00003-of-00007.safetensors",
102
+ "model.layers.15.self_attn.v_proj.bias": "model-00003-of-00007.safetensors",
103
+ "model.layers.15.self_attn.v_proj.weight": "model-00003-of-00007.safetensors",
104
+ "model.layers.16.input_layernorm.weight": "model-00003-of-00007.safetensors",
105
+ "model.layers.16.mlp.down_proj.weight": "model-00003-of-00007.safetensors",
106
+ "model.layers.16.mlp.gate_proj.weight": "model-00003-of-00007.safetensors",
107
+ "model.layers.16.mlp.up_proj.weight": "model-00003-of-00007.safetensors",
108
+ "model.layers.16.post_attention_layernorm.weight": "model-00003-of-00007.safetensors",
109
+ "model.layers.16.self_attn.k_proj.bias": "model-00003-of-00007.safetensors",
110
+ "model.layers.16.self_attn.k_proj.weight": "model-00003-of-00007.safetensors",
111
+ "model.layers.16.self_attn.o_proj.weight": "model-00003-of-00007.safetensors",
112
+ "model.layers.16.self_attn.q_proj.bias": "model-00003-of-00007.safetensors",
113
+ "model.layers.16.self_attn.q_proj.weight": "model-00003-of-00007.safetensors",
114
+ "model.layers.16.self_attn.v_proj.bias": "model-00003-of-00007.safetensors",
115
+ "model.layers.16.self_attn.v_proj.weight": "model-00003-of-00007.safetensors",
116
+ "model.layers.17.input_layernorm.weight": "model-00003-of-00007.safetensors",
117
+ "model.layers.17.mlp.down_proj.weight": "model-00003-of-00007.safetensors",
118
+ "model.layers.17.mlp.gate_proj.weight": "model-00003-of-00007.safetensors",
119
+ "model.layers.17.mlp.up_proj.weight": "model-00003-of-00007.safetensors",
120
+ "model.layers.17.post_attention_layernorm.weight": "model-00003-of-00007.safetensors",
121
+ "model.layers.17.self_attn.k_proj.bias": "model-00003-of-00007.safetensors",
122
+ "model.layers.17.self_attn.k_proj.weight": "model-00003-of-00007.safetensors",
123
+ "model.layers.17.self_attn.o_proj.weight": "model-00003-of-00007.safetensors",
124
+ "model.layers.17.self_attn.q_proj.bias": "model-00003-of-00007.safetensors",
125
+ "model.layers.17.self_attn.q_proj.weight": "model-00003-of-00007.safetensors",
126
+ "model.layers.17.self_attn.v_proj.bias": "model-00003-of-00007.safetensors",
127
+ "model.layers.17.self_attn.v_proj.weight": "model-00003-of-00007.safetensors",
128
+ "model.layers.18.input_layernorm.weight": "model-00003-of-00007.safetensors",
129
+ "model.layers.18.mlp.down_proj.weight": "model-00003-of-00007.safetensors",
130
+ "model.layers.18.mlp.gate_proj.weight": "model-00003-of-00007.safetensors",
131
+ "model.layers.18.mlp.up_proj.weight": "model-00003-of-00007.safetensors",
132
+ "model.layers.18.post_attention_layernorm.weight": "model-00003-of-00007.safetensors",
133
+ "model.layers.18.self_attn.k_proj.bias": "model-00003-of-00007.safetensors",
134
+ "model.layers.18.self_attn.k_proj.weight": "model-00003-of-00007.safetensors",
135
+ "model.layers.18.self_attn.o_proj.weight": "model-00003-of-00007.safetensors",
136
+ "model.layers.18.self_attn.q_proj.bias": "model-00003-of-00007.safetensors",
137
+ "model.layers.18.self_attn.q_proj.weight": "model-00003-of-00007.safetensors",
138
+ "model.layers.18.self_attn.v_proj.bias": "model-00003-of-00007.safetensors",
139
+ "model.layers.18.self_attn.v_proj.weight": "model-00003-of-00007.safetensors",
140
+ "model.layers.19.input_layernorm.weight": "model-00003-of-00007.safetensors",
141
+ "model.layers.19.mlp.down_proj.weight": "model-00003-of-00007.safetensors",
142
+ "model.layers.19.mlp.gate_proj.weight": "model-00003-of-00007.safetensors",
143
+ "model.layers.19.mlp.up_proj.weight": "model-00003-of-00007.safetensors",
144
+ "model.layers.19.post_attention_layernorm.weight": "model-00003-of-00007.safetensors",
145
+ "model.layers.19.self_attn.k_proj.bias": "model-00003-of-00007.safetensors",
146
+ "model.layers.19.self_attn.k_proj.weight": "model-00003-of-00007.safetensors",
147
+ "model.layers.19.self_attn.o_proj.weight": "model-00003-of-00007.safetensors",
148
+ "model.layers.19.self_attn.q_proj.bias": "model-00003-of-00007.safetensors",
149
+ "model.layers.19.self_attn.q_proj.weight": "model-00003-of-00007.safetensors",
150
+ "model.layers.19.self_attn.v_proj.bias": "model-00003-of-00007.safetensors",
151
+ "model.layers.19.self_attn.v_proj.weight": "model-00003-of-00007.safetensors",
152
+ "model.layers.2.input_layernorm.weight": "model-00001-of-00007.safetensors",
153
+ "model.layers.2.mlp.down_proj.weight": "model-00001-of-00007.safetensors",
154
+ "model.layers.2.mlp.gate_proj.weight": "model-00001-of-00007.safetensors",
155
+ "model.layers.2.mlp.up_proj.weight": "model-00001-of-00007.safetensors",
156
+ "model.layers.2.post_attention_layernorm.weight": "model-00001-of-00007.safetensors",
157
+ "model.layers.2.self_attn.k_proj.bias": "model-00001-of-00007.safetensors",
158
+ "model.layers.2.self_attn.k_proj.weight": "model-00001-of-00007.safetensors",
159
+ "model.layers.2.self_attn.o_proj.weight": "model-00001-of-00007.safetensors",
160
+ "model.layers.2.self_attn.q_proj.bias": "model-00001-of-00007.safetensors",
161
+ "model.layers.2.self_attn.q_proj.weight": "model-00001-of-00007.safetensors",
162
+ "model.layers.2.self_attn.v_proj.bias": "model-00001-of-00007.safetensors",
163
+ "model.layers.2.self_attn.v_proj.weight": "model-00001-of-00007.safetensors",
164
+ "model.layers.20.input_layernorm.weight": "model-00003-of-00007.safetensors",
165
+ "model.layers.20.mlp.down_proj.weight": "model-00003-of-00007.safetensors",
166
+ "model.layers.20.mlp.gate_proj.weight": "model-00003-of-00007.safetensors",
167
+ "model.layers.20.mlp.up_proj.weight": "model-00003-of-00007.safetensors",
168
+ "model.layers.20.post_attention_layernorm.weight": "model-00003-of-00007.safetensors",
169
+ "model.layers.20.self_attn.k_proj.bias": "model-00003-of-00007.safetensors",
170
+ "model.layers.20.self_attn.k_proj.weight": "model-00003-of-00007.safetensors",
171
+ "model.layers.20.self_attn.o_proj.weight": "model-00003-of-00007.safetensors",
172
+ "model.layers.20.self_attn.q_proj.bias": "model-00003-of-00007.safetensors",
173
+ "model.layers.20.self_attn.q_proj.weight": "model-00003-of-00007.safetensors",
174
+ "model.layers.20.self_attn.v_proj.bias": "model-00003-of-00007.safetensors",
175
+ "model.layers.20.self_attn.v_proj.weight": "model-00003-of-00007.safetensors",
176
+ "model.layers.21.input_layernorm.weight": "model-00003-of-00007.safetensors",
177
+ "model.layers.21.mlp.down_proj.weight": "model-00003-of-00007.safetensors",
178
+ "model.layers.21.mlp.gate_proj.weight": "model-00003-of-00007.safetensors",
179
+ "model.layers.21.mlp.up_proj.weight": "model-00003-of-00007.safetensors",
180
+ "model.layers.21.post_attention_layernorm.weight": "model-00003-of-00007.safetensors",
181
+ "model.layers.21.self_attn.k_proj.bias": "model-00003-of-00007.safetensors",
182
+ "model.layers.21.self_attn.k_proj.weight": "model-00003-of-00007.safetensors",
183
+ "model.layers.21.self_attn.o_proj.weight": "model-00003-of-00007.safetensors",
184
+ "model.layers.21.self_attn.q_proj.bias": "model-00003-of-00007.safetensors",
185
+ "model.layers.21.self_attn.q_proj.weight": "model-00003-of-00007.safetensors",
186
+ "model.layers.21.self_attn.v_proj.bias": "model-00003-of-00007.safetensors",
187
+ "model.layers.21.self_attn.v_proj.weight": "model-00003-of-00007.safetensors",
188
+ "model.layers.22.input_layernorm.weight": "model-00003-of-00007.safetensors",
189
+ "model.layers.22.mlp.down_proj.weight": "model-00003-of-00007.safetensors",
190
+ "model.layers.22.mlp.gate_proj.weight": "model-00003-of-00007.safetensors",
191
+ "model.layers.22.mlp.up_proj.weight": "model-00003-of-00007.safetensors",
192
+ "model.layers.22.post_attention_layernorm.weight": "model-00003-of-00007.safetensors",
193
+ "model.layers.22.self_attn.k_proj.bias": "model-00003-of-00007.safetensors",
194
+ "model.layers.22.self_attn.k_proj.weight": "model-00003-of-00007.safetensors",
195
+ "model.layers.22.self_attn.o_proj.weight": "model-00003-of-00007.safetensors",
196
+ "model.layers.22.self_attn.q_proj.bias": "model-00003-of-00007.safetensors",
197
+ "model.layers.22.self_attn.q_proj.weight": "model-00003-of-00007.safetensors",
198
+ "model.layers.22.self_attn.v_proj.bias": "model-00003-of-00007.safetensors",
199
+ "model.layers.22.self_attn.v_proj.weight": "model-00003-of-00007.safetensors",
200
+ "model.layers.23.input_layernorm.weight": "model-00004-of-00007.safetensors",
201
+ "model.layers.23.mlp.down_proj.weight": "model-00004-of-00007.safetensors",
202
+ "model.layers.23.mlp.gate_proj.weight": "model-00004-of-00007.safetensors",
203
+ "model.layers.23.mlp.up_proj.weight": "model-00004-of-00007.safetensors",
204
+ "model.layers.23.post_attention_layernorm.weight": "model-00004-of-00007.safetensors",
205
+ "model.layers.23.self_attn.k_proj.bias": "model-00003-of-00007.safetensors",
206
+ "model.layers.23.self_attn.k_proj.weight": "model-00003-of-00007.safetensors",
207
+ "model.layers.23.self_attn.o_proj.weight": "model-00003-of-00007.safetensors",
208
+ "model.layers.23.self_attn.q_proj.bias": "model-00003-of-00007.safetensors",
209
+ "model.layers.23.self_attn.q_proj.weight": "model-00003-of-00007.safetensors",
210
+ "model.layers.23.self_attn.v_proj.bias": "model-00003-of-00007.safetensors",
211
+ "model.layers.23.self_attn.v_proj.weight": "model-00003-of-00007.safetensors",
212
+ "model.layers.24.input_layernorm.weight": "model-00004-of-00007.safetensors",
213
+ "model.layers.24.mlp.down_proj.weight": "model-00004-of-00007.safetensors",
214
+ "model.layers.24.mlp.gate_proj.weight": "model-00004-of-00007.safetensors",
215
+ "model.layers.24.mlp.up_proj.weight": "model-00004-of-00007.safetensors",
216
+ "model.layers.24.post_attention_layernorm.weight": "model-00004-of-00007.safetensors",
217
+ "model.layers.24.self_attn.k_proj.bias": "model-00004-of-00007.safetensors",
218
+ "model.layers.24.self_attn.k_proj.weight": "model-00004-of-00007.safetensors",
219
+ "model.layers.24.self_attn.o_proj.weight": "model-00004-of-00007.safetensors",
220
+ "model.layers.24.self_attn.q_proj.bias": "model-00004-of-00007.safetensors",
221
+ "model.layers.24.self_attn.q_proj.weight": "model-00004-of-00007.safetensors",
222
+ "model.layers.24.self_attn.v_proj.bias": "model-00004-of-00007.safetensors",
223
+ "model.layers.24.self_attn.v_proj.weight": "model-00004-of-00007.safetensors",
224
+ "model.layers.25.input_layernorm.weight": "model-00004-of-00007.safetensors",
225
+ "model.layers.25.mlp.down_proj.weight": "model-00004-of-00007.safetensors",
226
+ "model.layers.25.mlp.gate_proj.weight": "model-00004-of-00007.safetensors",
227
+ "model.layers.25.mlp.up_proj.weight": "model-00004-of-00007.safetensors",
228
+ "model.layers.25.post_attention_layernorm.weight": "model-00004-of-00007.safetensors",
229
+ "model.layers.25.self_attn.k_proj.bias": "model-00004-of-00007.safetensors",
230
+ "model.layers.25.self_attn.k_proj.weight": "model-00004-of-00007.safetensors",
231
+ "model.layers.25.self_attn.o_proj.weight": "model-00004-of-00007.safetensors",
232
+ "model.layers.25.self_attn.q_proj.bias": "model-00004-of-00007.safetensors",
233
+ "model.layers.25.self_attn.q_proj.weight": "model-00004-of-00007.safetensors",
234
+ "model.layers.25.self_attn.v_proj.bias": "model-00004-of-00007.safetensors",
235
+ "model.layers.25.self_attn.v_proj.weight": "model-00004-of-00007.safetensors",
236
+ "model.layers.26.input_layernorm.weight": "model-00004-of-00007.safetensors",
237
+ "model.layers.26.mlp.down_proj.weight": "model-00004-of-00007.safetensors",
238
+ "model.layers.26.mlp.gate_proj.weight": "model-00004-of-00007.safetensors",
239
+ "model.layers.26.mlp.up_proj.weight": "model-00004-of-00007.safetensors",
240
+ "model.layers.26.post_attention_layernorm.weight": "model-00004-of-00007.safetensors",
241
+ "model.layers.26.self_attn.k_proj.bias": "model-00004-of-00007.safetensors",
242
+ "model.layers.26.self_attn.k_proj.weight": "model-00004-of-00007.safetensors",
243
+ "model.layers.26.self_attn.o_proj.weight": "model-00004-of-00007.safetensors",
244
+ "model.layers.26.self_attn.q_proj.bias": "model-00004-of-00007.safetensors",
245
+ "model.layers.26.self_attn.q_proj.weight": "model-00004-of-00007.safetensors",
246
+ "model.layers.26.self_attn.v_proj.bias": "model-00004-of-00007.safetensors",
247
+ "model.layers.26.self_attn.v_proj.weight": "model-00004-of-00007.safetensors",
248
+ "model.layers.27.input_layernorm.weight": "model-00004-of-00007.safetensors",
249
+ "model.layers.27.mlp.down_proj.weight": "model-00004-of-00007.safetensors",
250
+ "model.layers.27.mlp.gate_proj.weight": "model-00004-of-00007.safetensors",
251
+ "model.layers.27.mlp.up_proj.weight": "model-00004-of-00007.safetensors",
252
+ "model.layers.27.post_attention_layernorm.weight": "model-00004-of-00007.safetensors",
253
+ "model.layers.27.self_attn.k_proj.bias": "model-00004-of-00007.safetensors",
254
+ "model.layers.27.self_attn.k_proj.weight": "model-00004-of-00007.safetensors",
255
+ "model.layers.27.self_attn.o_proj.weight": "model-00004-of-00007.safetensors",
256
+ "model.layers.27.self_attn.q_proj.bias": "model-00004-of-00007.safetensors",
257
+ "model.layers.27.self_attn.q_proj.weight": "model-00004-of-00007.safetensors",
258
+ "model.layers.27.self_attn.v_proj.bias": "model-00004-of-00007.safetensors",
259
+ "model.layers.27.self_attn.v_proj.weight": "model-00004-of-00007.safetensors",
260
+ "model.layers.28.input_layernorm.weight": "model-00004-of-00007.safetensors",
261
+ "model.layers.28.mlp.down_proj.weight": "model-00004-of-00007.safetensors",
262
+ "model.layers.28.mlp.gate_proj.weight": "model-00004-of-00007.safetensors",
263
+ "model.layers.28.mlp.up_proj.weight": "model-00004-of-00007.safetensors",
264
+ "model.layers.28.post_attention_layernorm.weight": "model-00004-of-00007.safetensors",
265
+ "model.layers.28.self_attn.k_proj.bias": "model-00004-of-00007.safetensors",
266
+ "model.layers.28.self_attn.k_proj.weight": "model-00004-of-00007.safetensors",
267
+ "model.layers.28.self_attn.o_proj.weight": "model-00004-of-00007.safetensors",
268
+ "model.layers.28.self_attn.q_proj.bias": "model-00004-of-00007.safetensors",
269
+ "model.layers.28.self_attn.q_proj.weight": "model-00004-of-00007.safetensors",
270
+ "model.layers.28.self_attn.v_proj.bias": "model-00004-of-00007.safetensors",
271
+ "model.layers.28.self_attn.v_proj.weight": "model-00004-of-00007.safetensors",
272
+ "model.layers.29.input_layernorm.weight": "model-00004-of-00007.safetensors",
273
+ "model.layers.29.mlp.down_proj.weight": "model-00004-of-00007.safetensors",
274
+ "model.layers.29.mlp.gate_proj.weight": "model-00004-of-00007.safetensors",
275
+ "model.layers.29.mlp.up_proj.weight": "model-00004-of-00007.safetensors",
276
+ "model.layers.29.post_attention_layernorm.weight": "model-00004-of-00007.safetensors",
277
+ "model.layers.29.self_attn.k_proj.bias": "model-00004-of-00007.safetensors",
278
+ "model.layers.29.self_attn.k_proj.weight": "model-00004-of-00007.safetensors",
279
+ "model.layers.29.self_attn.o_proj.weight": "model-00004-of-00007.safetensors",
280
+ "model.layers.29.self_attn.q_proj.bias": "model-00004-of-00007.safetensors",
281
+ "model.layers.29.self_attn.q_proj.weight": "model-00004-of-00007.safetensors",
282
+ "model.layers.29.self_attn.v_proj.bias": "model-00004-of-00007.safetensors",
283
+ "model.layers.29.self_attn.v_proj.weight": "model-00004-of-00007.safetensors",
284
+ "model.layers.3.input_layernorm.weight": "model-00001-of-00007.safetensors",
285
+ "model.layers.3.mlp.down_proj.weight": "model-00001-of-00007.safetensors",
286
+ "model.layers.3.mlp.gate_proj.weight": "model-00001-of-00007.safetensors",
287
+ "model.layers.3.mlp.up_proj.weight": "model-00001-of-00007.safetensors",
288
+ "model.layers.3.post_attention_layernorm.weight": "model-00001-of-00007.safetensors",
289
+ "model.layers.3.self_attn.k_proj.bias": "model-00001-of-00007.safetensors",
290
+ "model.layers.3.self_attn.k_proj.weight": "model-00001-of-00007.safetensors",
291
+ "model.layers.3.self_attn.o_proj.weight": "model-00001-of-00007.safetensors",
292
+ "model.layers.3.self_attn.q_proj.bias": "model-00001-of-00007.safetensors",
293
+ "model.layers.3.self_attn.q_proj.weight": "model-00001-of-00007.safetensors",
294
+ "model.layers.3.self_attn.v_proj.bias": "model-00001-of-00007.safetensors",
295
+ "model.layers.3.self_attn.v_proj.weight": "model-00001-of-00007.safetensors",
296
+ "model.layers.30.input_layernorm.weight": "model-00004-of-00007.safetensors",
297
+ "model.layers.30.mlp.down_proj.weight": "model-00004-of-00007.safetensors",
298
+ "model.layers.30.mlp.gate_proj.weight": "model-00004-of-00007.safetensors",
299
+ "model.layers.30.mlp.up_proj.weight": "model-00004-of-00007.safetensors",
300
+ "model.layers.30.post_attention_layernorm.weight": "model-00004-of-00007.safetensors",
301
+ "model.layers.30.self_attn.k_proj.bias": "model-00004-of-00007.safetensors",
302
+ "model.layers.30.self_attn.k_proj.weight": "model-00004-of-00007.safetensors",
303
+ "model.layers.30.self_attn.o_proj.weight": "model-00004-of-00007.safetensors",
304
+ "model.layers.30.self_attn.q_proj.bias": "model-00004-of-00007.safetensors",
305
+ "model.layers.30.self_attn.q_proj.weight": "model-00004-of-00007.safetensors",
306
+ "model.layers.30.self_attn.v_proj.bias": "model-00004-of-00007.safetensors",
307
+ "model.layers.30.self_attn.v_proj.weight": "model-00004-of-00007.safetensors",
308
+ "model.layers.31.input_layernorm.weight": "model-00005-of-00007.safetensors",
309
+ "model.layers.31.mlp.down_proj.weight": "model-00005-of-00007.safetensors",
310
+ "model.layers.31.mlp.gate_proj.weight": "model-00004-of-00007.safetensors",
311
+ "model.layers.31.mlp.up_proj.weight": "model-00005-of-00007.safetensors",
312
+ "model.layers.31.post_attention_layernorm.weight": "model-00005-of-00007.safetensors",
313
+ "model.layers.31.self_attn.k_proj.bias": "model-00004-of-00007.safetensors",
314
+ "model.layers.31.self_attn.k_proj.weight": "model-00004-of-00007.safetensors",
315
+ "model.layers.31.self_attn.o_proj.weight": "model-00004-of-00007.safetensors",
316
+ "model.layers.31.self_attn.q_proj.bias": "model-00004-of-00007.safetensors",
317
+ "model.layers.31.self_attn.q_proj.weight": "model-00004-of-00007.safetensors",
318
+ "model.layers.31.self_attn.v_proj.bias": "model-00004-of-00007.safetensors",
319
+ "model.layers.31.self_attn.v_proj.weight": "model-00004-of-00007.safetensors",
320
+ "model.layers.32.input_layernorm.weight": "model-00005-of-00007.safetensors",
321
+ "model.layers.32.mlp.down_proj.weight": "model-00005-of-00007.safetensors",
322
+ "model.layers.32.mlp.gate_proj.weight": "model-00005-of-00007.safetensors",
323
+ "model.layers.32.mlp.up_proj.weight": "model-00005-of-00007.safetensors",
324
+ "model.layers.32.post_attention_layernorm.weight": "model-00005-of-00007.safetensors",
325
+ "model.layers.32.self_attn.k_proj.bias": "model-00005-of-00007.safetensors",
326
+ "model.layers.32.self_attn.k_proj.weight": "model-00005-of-00007.safetensors",
327
+ "model.layers.32.self_attn.o_proj.weight": "model-00005-of-00007.safetensors",
328
+ "model.layers.32.self_attn.q_proj.bias": "model-00005-of-00007.safetensors",
329
+ "model.layers.32.self_attn.q_proj.weight": "model-00005-of-00007.safetensors",
330
+ "model.layers.32.self_attn.v_proj.bias": "model-00005-of-00007.safetensors",
331
+ "model.layers.32.self_attn.v_proj.weight": "model-00005-of-00007.safetensors",
332
+ "model.layers.33.input_layernorm.weight": "model-00005-of-00007.safetensors",
333
+ "model.layers.33.mlp.down_proj.weight": "model-00005-of-00007.safetensors",
334
+ "model.layers.33.mlp.gate_proj.weight": "model-00005-of-00007.safetensors",
335
+ "model.layers.33.mlp.up_proj.weight": "model-00005-of-00007.safetensors",
336
+ "model.layers.33.post_attention_layernorm.weight": "model-00005-of-00007.safetensors",
337
+ "model.layers.33.self_attn.k_proj.bias": "model-00005-of-00007.safetensors",
338
+ "model.layers.33.self_attn.k_proj.weight": "model-00005-of-00007.safetensors",
339
+ "model.layers.33.self_attn.o_proj.weight": "model-00005-of-00007.safetensors",
340
+ "model.layers.33.self_attn.q_proj.bias": "model-00005-of-00007.safetensors",
341
+ "model.layers.33.self_attn.q_proj.weight": "model-00005-of-00007.safetensors",
342
+ "model.layers.33.self_attn.v_proj.bias": "model-00005-of-00007.safetensors",
343
+ "model.layers.33.self_attn.v_proj.weight": "model-00005-of-00007.safetensors",
344
+ "model.layers.34.input_layernorm.weight": "model-00005-of-00007.safetensors",
345
+ "model.layers.34.mlp.down_proj.weight": "model-00005-of-00007.safetensors",
346
+ "model.layers.34.mlp.gate_proj.weight": "model-00005-of-00007.safetensors",
347
+ "model.layers.34.mlp.up_proj.weight": "model-00005-of-00007.safetensors",
348
+ "model.layers.34.post_attention_layernorm.weight": "model-00005-of-00007.safetensors",
349
+ "model.layers.34.self_attn.k_proj.bias": "model-00005-of-00007.safetensors",
350
+ "model.layers.34.self_attn.k_proj.weight": "model-00005-of-00007.safetensors",
351
+ "model.layers.34.self_attn.o_proj.weight": "model-00005-of-00007.safetensors",
352
+ "model.layers.34.self_attn.q_proj.bias": "model-00005-of-00007.safetensors",
353
+ "model.layers.34.self_attn.q_proj.weight": "model-00005-of-00007.safetensors",
354
+ "model.layers.34.self_attn.v_proj.bias": "model-00005-of-00007.safetensors",
355
+ "model.layers.34.self_attn.v_proj.weight": "model-00005-of-00007.safetensors",
356
+ "model.layers.35.input_layernorm.weight": "model-00005-of-00007.safetensors",
357
+ "model.layers.35.mlp.down_proj.weight": "model-00005-of-00007.safetensors",
358
+ "model.layers.35.mlp.gate_proj.weight": "model-00005-of-00007.safetensors",
359
+ "model.layers.35.mlp.up_proj.weight": "model-00005-of-00007.safetensors",
360
+ "model.layers.35.post_attention_layernorm.weight": "model-00005-of-00007.safetensors",
361
+ "model.layers.35.self_attn.k_proj.bias": "model-00005-of-00007.safetensors",
362
+ "model.layers.35.self_attn.k_proj.weight": "model-00005-of-00007.safetensors",
363
+ "model.layers.35.self_attn.o_proj.weight": "model-00005-of-00007.safetensors",
364
+ "model.layers.35.self_attn.q_proj.bias": "model-00005-of-00007.safetensors",
365
+ "model.layers.35.self_attn.q_proj.weight": "model-00005-of-00007.safetensors",
366
+ "model.layers.35.self_attn.v_proj.bias": "model-00005-of-00007.safetensors",
367
+ "model.layers.35.self_attn.v_proj.weight": "model-00005-of-00007.safetensors",
368
+ "model.layers.36.input_layernorm.weight": "model-00005-of-00007.safetensors",
369
+ "model.layers.36.mlp.down_proj.weight": "model-00005-of-00007.safetensors",
370
+ "model.layers.36.mlp.gate_proj.weight": "model-00005-of-00007.safetensors",
371
+ "model.layers.36.mlp.up_proj.weight": "model-00005-of-00007.safetensors",
372
+ "model.layers.36.post_attention_layernorm.weight": "model-00005-of-00007.safetensors",
373
+ "model.layers.36.self_attn.k_proj.bias": "model-00005-of-00007.safetensors",
374
+ "model.layers.36.self_attn.k_proj.weight": "model-00005-of-00007.safetensors",
375
+ "model.layers.36.self_attn.o_proj.weight": "model-00005-of-00007.safetensors",
376
+ "model.layers.36.self_attn.q_proj.bias": "model-00005-of-00007.safetensors",
377
+ "model.layers.36.self_attn.q_proj.weight": "model-00005-of-00007.safetensors",
378
+ "model.layers.36.self_attn.v_proj.bias": "model-00005-of-00007.safetensors",
379
+ "model.layers.36.self_attn.v_proj.weight": "model-00005-of-00007.safetensors",
380
+ "model.layers.37.input_layernorm.weight": "model-00005-of-00007.safetensors",
381
+ "model.layers.37.mlp.down_proj.weight": "model-00005-of-00007.safetensors",
382
+ "model.layers.37.mlp.gate_proj.weight": "model-00005-of-00007.safetensors",
383
+ "model.layers.37.mlp.up_proj.weight": "model-00005-of-00007.safetensors",
384
+ "model.layers.37.post_attention_layernorm.weight": "model-00005-of-00007.safetensors",
385
+ "model.layers.37.self_attn.k_proj.bias": "model-00005-of-00007.safetensors",
386
+ "model.layers.37.self_attn.k_proj.weight": "model-00005-of-00007.safetensors",
387
+ "model.layers.37.self_attn.o_proj.weight": "model-00005-of-00007.safetensors",
388
+ "model.layers.37.self_attn.q_proj.bias": "model-00005-of-00007.safetensors",
389
+ "model.layers.37.self_attn.q_proj.weight": "model-00005-of-00007.safetensors",
390
+ "model.layers.37.self_attn.v_proj.bias": "model-00005-of-00007.safetensors",
391
+ "model.layers.37.self_attn.v_proj.weight": "model-00005-of-00007.safetensors",
392
+ "model.layers.38.input_layernorm.weight": "model-00005-of-00007.safetensors",
393
+ "model.layers.38.mlp.down_proj.weight": "model-00005-of-00007.safetensors",
394
+ "model.layers.38.mlp.gate_proj.weight": "model-00005-of-00007.safetensors",
395
+ "model.layers.38.mlp.up_proj.weight": "model-00005-of-00007.safetensors",
396
+ "model.layers.38.post_attention_layernorm.weight": "model-00005-of-00007.safetensors",
397
+ "model.layers.38.self_attn.k_proj.bias": "model-00005-of-00007.safetensors",
398
+ "model.layers.38.self_attn.k_proj.weight": "model-00005-of-00007.safetensors",
399
+ "model.layers.38.self_attn.o_proj.weight": "model-00005-of-00007.safetensors",
400
+ "model.layers.38.self_attn.q_proj.bias": "model-00005-of-00007.safetensors",
401
+ "model.layers.38.self_attn.q_proj.weight": "model-00005-of-00007.safetensors",
402
+ "model.layers.38.self_attn.v_proj.bias": "model-00005-of-00007.safetensors",
403
+ "model.layers.38.self_attn.v_proj.weight": "model-00005-of-00007.safetensors",
404
+ "model.layers.39.input_layernorm.weight": "model-00006-of-00007.safetensors",
405
+ "model.layers.39.mlp.down_proj.weight": "model-00006-of-00007.safetensors",
406
+ "model.layers.39.mlp.gate_proj.weight": "model-00006-of-00007.safetensors",
407
+ "model.layers.39.mlp.up_proj.weight": "model-00006-of-00007.safetensors",
408
+ "model.layers.39.post_attention_layernorm.weight": "model-00006-of-00007.safetensors",
409
+ "model.layers.4.input_layernorm.weight": "model-00002-of-00007.safetensors",
410
+ "model.layers.4.mlp.down_proj.weight": "model-00002-of-00007.safetensors",
411
+ "model.layers.4.mlp.gate_proj.weight": "model-00001-of-00007.safetensors",
412
+ "model.layers.4.mlp.up_proj.weight": "model-00001-of-00007.safetensors",
413
+ "model.layers.4.post_attention_layernorm.weight": "model-00002-of-00007.safetensors",
414
+ "model.layers.4.self_attn.k_proj.bias": "model-00001-of-00007.safetensors",
415
+ "model.layers.4.self_attn.k_proj.weight": "model-00001-of-00007.safetensors",
416
+ "model.layers.4.self_attn.o_proj.weight": "model-00001-of-00007.safetensors",
417
+ "model.layers.4.self_attn.q_proj.bias": "model-00001-of-00007.safetensors",
418
+ "model.layers.4.self_attn.q_proj.weight": "model-00001-of-00007.safetensors",
419
+ "model.layers.4.self_attn.v_proj.bias": "model-00001-of-00007.safetensors",
420
+ "model.layers.4.self_attn.v_proj.weight": "model-00001-of-00007.safetensors",
421
+ "model.layers.40.input_layernorm.weight": "model-00006-of-00007.safetensors",
422
+ "model.layers.40.mlp.down_proj.weight": "model-00006-of-00007.safetensors",
423
+ "model.layers.40.mlp.gate_proj.weight": "model-00006-of-00007.safetensors",
424
+ "model.layers.40.mlp.up_proj.weight": "model-00006-of-00007.safetensors",
425
+ "model.layers.40.post_attention_layernorm.weight": "model-00006-of-00007.safetensors",
426
+ "model.layers.40.self_attn.k_proj.bias": "model-00006-of-00007.safetensors",
427
+ "model.layers.40.self_attn.k_proj.weight": "model-00006-of-00007.safetensors",
428
+ "model.layers.40.self_attn.o_proj.weight": "model-00006-of-00007.safetensors",
429
+ "model.layers.40.self_attn.q_proj.bias": "model-00006-of-00007.safetensors",
430
+ "model.layers.40.self_attn.q_proj.weight": "model-00006-of-00007.safetensors",
431
+ "model.layers.40.self_attn.v_proj.bias": "model-00006-of-00007.safetensors",
432
+ "model.layers.40.self_attn.v_proj.weight": "model-00006-of-00007.safetensors",
433
+ "model.layers.41.input_layernorm.weight": "model-00006-of-00007.safetensors",
434
+ "model.layers.41.mlp.down_proj.weight": "model-00006-of-00007.safetensors",
435
+ "model.layers.41.mlp.gate_proj.weight": "model-00006-of-00007.safetensors",
436
+ "model.layers.41.mlp.up_proj.weight": "model-00006-of-00007.safetensors",
437
+ "model.layers.41.post_attention_layernorm.weight": "model-00006-of-00007.safetensors",
438
+ "model.layers.41.self_attn.k_proj.bias": "model-00006-of-00007.safetensors",
439
+ "model.layers.41.self_attn.k_proj.weight": "model-00006-of-00007.safetensors",
440
+ "model.layers.41.self_attn.o_proj.weight": "model-00006-of-00007.safetensors",
441
+ "model.layers.41.self_attn.q_proj.bias": "model-00006-of-00007.safetensors",
442
+ "model.layers.41.self_attn.q_proj.weight": "model-00006-of-00007.safetensors",
443
+ "model.layers.41.self_attn.v_proj.bias": "model-00006-of-00007.safetensors",
444
+ "model.layers.41.self_attn.v_proj.weight": "model-00006-of-00007.safetensors",
445
+ "model.layers.42.input_layernorm.weight": "model-00006-of-00007.safetensors",
446
+ "model.layers.42.mlp.down_proj.weight": "model-00006-of-00007.safetensors",
447
+ "model.layers.42.mlp.gate_proj.weight": "model-00006-of-00007.safetensors",
448
+ "model.layers.42.mlp.up_proj.weight": "model-00006-of-00007.safetensors",
449
+ "model.layers.42.post_attention_layernorm.weight": "model-00006-of-00007.safetensors",
450
+ "model.layers.42.self_attn.k_proj.bias": "model-00006-of-00007.safetensors",
451
+ "model.layers.42.self_attn.k_proj.weight": "model-00006-of-00007.safetensors",
452
+ "model.layers.42.self_attn.o_proj.weight": "model-00006-of-00007.safetensors",
453
+ "model.layers.42.self_attn.q_proj.bias": "model-00006-of-00007.safetensors",
454
+ "model.layers.42.self_attn.q_proj.weight": "model-00006-of-00007.safetensors",
455
+ "model.layers.42.self_attn.v_proj.bias": "model-00006-of-00007.safetensors",
456
+ "model.layers.42.self_attn.v_proj.weight": "model-00006-of-00007.safetensors",
457
+ "model.layers.43.input_layernorm.weight": "model-00006-of-00007.safetensors",
458
+ "model.layers.43.mlp.down_proj.weight": "model-00006-of-00007.safetensors",
459
+ "model.layers.43.mlp.gate_proj.weight": "model-00006-of-00007.safetensors",
460
+ "model.layers.43.mlp.up_proj.weight": "model-00006-of-00007.safetensors",
461
+ "model.layers.43.post_attention_layernorm.weight": "model-00006-of-00007.safetensors",
462
+ "model.layers.43.self_attn.k_proj.bias": "model-00006-of-00007.safetensors",
463
+ "model.layers.43.self_attn.k_proj.weight": "model-00006-of-00007.safetensors",
464
+ "model.layers.43.self_attn.o_proj.weight": "model-00006-of-00007.safetensors",
465
+ "model.layers.43.self_attn.q_proj.bias": "model-00006-of-00007.safetensors",
466
+ "model.layers.43.self_attn.q_proj.weight": "model-00006-of-00007.safetensors",
467
+ "model.layers.43.self_attn.v_proj.bias": "model-00006-of-00007.safetensors",
468
+ "model.layers.43.self_attn.v_proj.weight": "model-00006-of-00007.safetensors",
469
+ "model.layers.44.input_layernorm.weight": "model-00006-of-00007.safetensors",
470
+ "model.layers.44.mlp.down_proj.weight": "model-00006-of-00007.safetensors",
471
+ "model.layers.44.mlp.gate_proj.weight": "model-00006-of-00007.safetensors",
472
+ "model.layers.44.mlp.up_proj.weight": "model-00006-of-00007.safetensors",
473
+ "model.layers.44.post_attention_layernorm.weight": "model-00006-of-00007.safetensors",
474
+ "model.layers.44.self_attn.k_proj.bias": "model-00006-of-00007.safetensors",
475
+ "model.layers.44.self_attn.k_proj.weight": "model-00006-of-00007.safetensors",
476
+ "model.layers.44.self_attn.o_proj.weight": "model-00006-of-00007.safetensors",
477
+ "model.layers.44.self_attn.q_proj.bias": "model-00006-of-00007.safetensors",
478
+ "model.layers.44.self_attn.q_proj.weight": "model-00006-of-00007.safetensors",
479
+ "model.layers.44.self_attn.v_proj.bias": "model-00006-of-00007.safetensors",
480
+ "model.layers.44.self_attn.v_proj.weight": "model-00006-of-00007.safetensors",
481
+ "model.layers.45.input_layernorm.weight": "model-00006-of-00007.safetensors",
482
+ "model.layers.45.mlp.down_proj.weight": "model-00006-of-00007.safetensors",
483
+ "model.layers.45.mlp.gate_proj.weight": "model-00006-of-00007.safetensors",
484
+ "model.layers.45.mlp.up_proj.weight": "model-00006-of-00007.safetensors",
485
+ "model.layers.45.post_attention_layernorm.weight": "model-00006-of-00007.safetensors",
486
+ "model.layers.45.self_attn.k_proj.bias": "model-00006-of-00007.safetensors",
487
+ "model.layers.45.self_attn.k_proj.weight": "model-00006-of-00007.safetensors",
488
+ "model.layers.45.self_attn.o_proj.weight": "model-00006-of-00007.safetensors",
489
+ "model.layers.45.self_attn.q_proj.bias": "model-00006-of-00007.safetensors",
490
+ "model.layers.45.self_attn.q_proj.weight": "model-00006-of-00007.safetensors",
491
+ "model.layers.45.self_attn.v_proj.bias": "model-00006-of-00007.safetensors",
492
+ "model.layers.45.self_attn.v_proj.weight": "model-00006-of-00007.safetensors",
493
+ "model.layers.46.input_layernorm.weight": "model-00007-of-00007.safetensors",
494
+ "model.layers.46.mlp.down_proj.weight": "model-00007-of-00007.safetensors",
495
+ "model.layers.46.mlp.gate_proj.weight": "model-00006-of-00007.safetensors",
496
+ "model.layers.46.mlp.up_proj.weight": "model-00006-of-00007.safetensors",
497
+ "model.layers.46.post_attention_layernorm.weight": "model-00007-of-00007.safetensors",
498
+ "model.layers.46.self_attn.k_proj.bias": "model-00006-of-00007.safetensors",
499
+ "model.layers.46.self_attn.k_proj.weight": "model-00006-of-00007.safetensors",
500
+ "model.layers.46.self_attn.o_proj.weight": "model-00006-of-00007.safetensors",
501
+ "model.layers.46.self_attn.q_proj.bias": "model-00006-of-00007.safetensors",
502
+ "model.layers.46.self_attn.q_proj.weight": "model-00006-of-00007.safetensors",
503
+ "model.layers.46.self_attn.v_proj.bias": "model-00006-of-00007.safetensors",
504
+ "model.layers.46.self_attn.v_proj.weight": "model-00006-of-00007.safetensors",
505
+ "model.layers.47.input_layernorm.weight": "model-00007-of-00007.safetensors",
506
+ "model.layers.47.mlp.down_proj.weight": "model-00007-of-00007.safetensors",
507
+ "model.layers.47.mlp.gate_proj.weight": "model-00007-of-00007.safetensors",
508
+ "model.layers.47.mlp.up_proj.weight": "model-00007-of-00007.safetensors",
509
+ "model.layers.47.post_attention_layernorm.weight": "model-00007-of-00007.safetensors",
510
+ "model.layers.47.self_attn.k_proj.bias": "model-00007-of-00007.safetensors",
511
+ "model.layers.47.self_attn.k_proj.weight": "model-00007-of-00007.safetensors",
512
+ "model.layers.47.self_attn.o_proj.weight": "model-00007-of-00007.safetensors",
513
+ "model.layers.47.self_attn.q_proj.bias": "model-00007-of-00007.safetensors",
514
+ "model.layers.47.self_attn.q_proj.weight": "model-00007-of-00007.safetensors",
515
+ "model.layers.47.self_attn.v_proj.bias": "model-00007-of-00007.safetensors",
516
+ "model.layers.47.self_attn.v_proj.weight": "model-00007-of-00007.safetensors",
517
+ "model.layers.5.input_layernorm.weight": "model-00002-of-00007.safetensors",
518
+ "model.layers.5.mlp.down_proj.weight": "model-00002-of-00007.safetensors",
519
+ "model.layers.5.mlp.gate_proj.weight": "model-00002-of-00007.safetensors",
520
+ "model.layers.5.mlp.up_proj.weight": "model-00002-of-00007.safetensors",
521
+ "model.layers.5.post_attention_layernorm.weight": "model-00002-of-00007.safetensors",
522
+ "model.layers.5.self_attn.k_proj.bias": "model-00002-of-00007.safetensors",
523
+ "model.layers.5.self_attn.k_proj.weight": "model-00002-of-00007.safetensors",
524
+ "model.layers.5.self_attn.o_proj.weight": "model-00002-of-00007.safetensors",
525
+ "model.layers.5.self_attn.q_proj.bias": "model-00002-of-00007.safetensors",
526
+ "model.layers.5.self_attn.q_proj.weight": "model-00002-of-00007.safetensors",
527
+ "model.layers.5.self_attn.v_proj.bias": "model-00002-of-00007.safetensors",
528
+ "model.layers.5.self_attn.v_proj.weight": "model-00002-of-00007.safetensors",
529
+ "model.layers.6.input_layernorm.weight": "model-00002-of-00007.safetensors",
530
+ "model.layers.6.mlp.down_proj.weight": "model-00002-of-00007.safetensors",
531
+ "model.layers.6.mlp.gate_proj.weight": "model-00002-of-00007.safetensors",
532
+ "model.layers.6.mlp.up_proj.weight": "model-00002-of-00007.safetensors",
533
+ "model.layers.6.post_attention_layernorm.weight": "model-00002-of-00007.safetensors",
534
+ "model.layers.6.self_attn.k_proj.bias": "model-00002-of-00007.safetensors",
535
+ "model.layers.6.self_attn.k_proj.weight": "model-00002-of-00007.safetensors",
536
+ "model.layers.6.self_attn.o_proj.weight": "model-00002-of-00007.safetensors",
537
+ "model.layers.6.self_attn.q_proj.bias": "model-00002-of-00007.safetensors",
538
+ "model.layers.6.self_attn.q_proj.weight": "model-00002-of-00007.safetensors",
539
+ "model.layers.6.self_attn.v_proj.bias": "model-00002-of-00007.safetensors",
540
+ "model.layers.6.self_attn.v_proj.weight": "model-00002-of-00007.safetensors",
541
+ "model.layers.7.input_layernorm.weight": "model-00002-of-00007.safetensors",
542
+ "model.layers.7.mlp.down_proj.weight": "model-00002-of-00007.safetensors",
543
+ "model.layers.7.mlp.gate_proj.weight": "model-00002-of-00007.safetensors",
544
+ "model.layers.7.mlp.up_proj.weight": "model-00002-of-00007.safetensors",
545
+ "model.layers.7.post_attention_layernorm.weight": "model-00002-of-00007.safetensors",
546
+ "model.layers.7.self_attn.k_proj.bias": "model-00002-of-00007.safetensors",
547
+ "model.layers.7.self_attn.k_proj.weight": "model-00002-of-00007.safetensors",
548
+ "model.layers.7.self_attn.o_proj.weight": "model-00002-of-00007.safetensors",
549
+ "model.layers.7.self_attn.q_proj.bias": "model-00002-of-00007.safetensors",
550
+ "model.layers.7.self_attn.q_proj.weight": "model-00002-of-00007.safetensors",
551
+ "model.layers.7.self_attn.v_proj.bias": "model-00002-of-00007.safetensors",
552
+ "model.layers.7.self_attn.v_proj.weight": "model-00002-of-00007.safetensors",
553
+ "model.layers.8.input_layernorm.weight": "model-00002-of-00007.safetensors",
554
+ "model.layers.8.mlp.down_proj.weight": "model-00002-of-00007.safetensors",
555
+ "model.layers.8.mlp.gate_proj.weight": "model-00002-of-00007.safetensors",
556
+ "model.layers.8.mlp.up_proj.weight": "model-00002-of-00007.safetensors",
557
+ "model.layers.8.post_attention_layernorm.weight": "model-00002-of-00007.safetensors",
558
+ "model.layers.8.self_attn.k_proj.bias": "model-00002-of-00007.safetensors",
559
+ "model.layers.8.self_attn.k_proj.weight": "model-00002-of-00007.safetensors",
560
+ "model.layers.8.self_attn.o_proj.weight": "model-00002-of-00007.safetensors",
561
+ "model.layers.8.self_attn.q_proj.bias": "model-00002-of-00007.safetensors",
562
+ "model.layers.8.self_attn.q_proj.weight": "model-00002-of-00007.safetensors",
563
+ "model.layers.8.self_attn.v_proj.bias": "model-00002-of-00007.safetensors",
564
+ "model.layers.8.self_attn.v_proj.weight": "model-00002-of-00007.safetensors",
565
+ "model.layers.9.input_layernorm.weight": "model-00002-of-00007.safetensors",
566
+ "model.layers.9.mlp.down_proj.weight": "model-00002-of-00007.safetensors",
567
+ "model.layers.9.mlp.gate_proj.weight": "model-00002-of-00007.safetensors",
568
+ "model.layers.9.mlp.up_proj.weight": "model-00002-of-00007.safetensors",
569
+ "model.layers.9.post_attention_layernorm.weight": "model-00002-of-00007.safetensors",
570
+ "model.layers.9.self_attn.k_proj.bias": "model-00002-of-00007.safetensors",
571
+ "model.layers.9.self_attn.k_proj.weight": "model-00002-of-00007.safetensors",
572
+ "model.layers.9.self_attn.o_proj.weight": "model-00002-of-00007.safetensors",
573
+ "model.layers.9.self_attn.q_proj.bias": "model-00002-of-00007.safetensors",
574
+ "model.layers.9.self_attn.q_proj.weight": "model-00002-of-00007.safetensors",
575
+ "model.layers.9.self_attn.v_proj.bias": "model-00002-of-00007.safetensors",
576
+ "model.layers.9.self_attn.v_proj.weight": "model-00002-of-00007.safetensors",
577
+ "model.norm.weight": "model-00007-of-00007.safetensors"
578
+ }
579
+ }
modeling_darwinlm.py ADDED
@@ -0,0 +1,1576 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2024 The Qwen team, Alibaba Group and the HuggingFace Inc. team. All rights reserved.
3
+ #
4
+ # This code is based on EleutherAI's GPT-NeoX library and the GPT-NeoX
5
+ # and OPT implementations in this library. It has been modified from its
6
+ # original forms to accommodate minor architectural differences compared
7
+ # to GPT-NeoX and OPT used by the Meta AI team that trained the model.
8
+ #
9
+ # Licensed under the Apache License, Version 2.0 (the "License");
10
+ # you may not use this file except in compliance with the License.
11
+ # You may obtain a copy of the License at
12
+ #
13
+ # http://www.apache.org/licenses/LICENSE-2.0
14
+ #
15
+ # Unless required by applicable law or agreed to in writing, software
16
+ # distributed under the License is distributed on an "AS IS" BASIS,
17
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ # See the License for the specific language governing permissions and
19
+ # limitations under the License.
20
+ """PyTorch Qwen2 model."""
21
+
22
+ import math
23
+ from typing import List, Optional, Tuple, Union
24
+
25
+ import torch
26
+ import torch.utils.checkpoint
27
+ from torch import nn
28
+ from torch.nn import BCEWithLogitsLoss, CrossEntropyLoss, MSELoss
29
+
30
+ from transformers.activations import ACT2FN
31
+ from transformers.cache_utils import Cache, DynamicCache, StaticCache
32
+ from transformers.modeling_attn_mask_utils import AttentionMaskConverter
33
+ from transformers.modeling_outputs import (
34
+ BaseModelOutputWithPast,
35
+ CausalLMOutputWithPast,
36
+ SequenceClassifierOutputWithPast,
37
+ TokenClassifierOutput,
38
+ )
39
+ from transformers.modeling_utils import PreTrainedModel, prune_linear_layer, find_pruneable_heads_and_indices
40
+ from transformers.utils import (
41
+ add_start_docstrings,
42
+ add_start_docstrings_to_model_forward,
43
+ is_flash_attn_2_available,
44
+ is_flash_attn_greater_or_equal_2_10,
45
+ is_torchdynamo_compiling,
46
+ logging,
47
+ replace_return_docstrings,
48
+ )
49
+ from .configuration_darwinlm import DarwinLMConfig
50
+
51
+
52
+ if is_flash_attn_2_available():
53
+ from transformers.modeling_flash_attention_utils import _flash_attention_forward
54
+
55
+
56
+ logger = logging.get_logger(__name__)
57
+
58
+
59
+ _CHECKPOINT_FOR_DOC = "Qwen/Qwen2-7B-beta"
60
+ _CONFIG_FOR_DOC = "DarwinLMConfig"
61
+
62
+ class NoAttention(nn.Module):
63
+ def forward(
64
+ self,
65
+ hidden_states: torch.Tensor,
66
+ attention_mask: Optional[torch.Tensor] = None,
67
+ position_ids: Optional[torch.LongTensor] = None,
68
+ past_key_value = None,
69
+ output_attentions: bool = False,
70
+ use_cache: bool = False,
71
+ cache_position: Optional[torch.LongTensor] = None,
72
+ position_embeddings: Optional[Tuple[torch.Tensor, torch.Tensor]] = None,
73
+ **kwargs,
74
+ ):
75
+ return (0, None, None)
76
+
77
+
78
+ class NoIntermediate(nn.Module):
79
+ def forward(self, hidden_states):
80
+ return hidden_states
81
+
82
+
83
+ class NoOutput(nn.Module):
84
+ def forward(self, hidden_states):
85
+ return 0
86
+
87
+
88
+ # Copied from transformers.models.llama.modeling_llama._prepare_4d_causal_attention_mask_with_cache_position
89
+ def _prepare_4d_causal_attention_mask_with_cache_position(
90
+ attention_mask: torch.Tensor,
91
+ sequence_length: int,
92
+ target_length: int,
93
+ dtype: torch.dtype,
94
+ device: torch.device,
95
+ min_dtype: float,
96
+ cache_position: torch.Tensor,
97
+ batch_size: int,
98
+ ):
99
+ """
100
+ Creates a causal 4D mask of shape `(batch_size, 1, query_length, key_value_length)` from a 2D mask of shape
101
+ `(batch_size, key_value_length)`, or if the input `attention_mask` is already 4D, do nothing.
102
+
103
+ Args:
104
+ attention_mask (`torch.Tensor`):
105
+ A 2D attention mask of shape `(batch_size, key_value_length)` or a 4D attention mask of shape `(batch_size, 1, query_length, key_value_length)`.
106
+ sequence_length (`int`):
107
+ The sequence length being processed.
108
+ target_length (`int`):
109
+ The target length: when generating with static cache, the mask should be as long as the static cache, to account for the 0 padding, the part of the cache that is not filled yet.
110
+ dtype (`torch.dtype`):
111
+ The dtype to use for the 4D attention mask.
112
+ device (`torch.device`):
113
+ The device to plcae the 4D attention mask on.
114
+ min_dtype (`float`):
115
+ The minimum value representable with the dtype `dtype`.
116
+ cache_position (`torch.Tensor`):
117
+ Indices depicting the position of the input sequence tokens in the sequence.
118
+ batch_size (`torch.Tensor`):
119
+ Batch size.
120
+ """
121
+ if attention_mask is not None and attention_mask.dim() == 4:
122
+ # In this case we assume that the mask comes already in inverted form and requires no inversion or slicing.
123
+ causal_mask = attention_mask
124
+ else:
125
+ causal_mask = torch.full((sequence_length, target_length), fill_value=min_dtype, dtype=dtype, device=device)
126
+ if sequence_length != 1:
127
+ causal_mask = torch.triu(causal_mask, diagonal=1)
128
+ causal_mask *= torch.arange(target_length, device=device) > cache_position.reshape(-1, 1)
129
+ causal_mask = causal_mask[None, None, :, :].expand(batch_size, 1, -1, -1)
130
+ if attention_mask is not None:
131
+ causal_mask = causal_mask.clone() # copy to contiguous memory for in-place edit
132
+ mask_length = attention_mask.shape[-1]
133
+ padding_mask = causal_mask[:, :, :, :mask_length] + attention_mask[:, None, None, :]
134
+ padding_mask = padding_mask == 0
135
+ causal_mask[:, :, :, :mask_length] = causal_mask[:, :, :, :mask_length].masked_fill(
136
+ padding_mask, min_dtype
137
+ )
138
+
139
+ return causal_mask
140
+
141
+
142
+ # Copied from transformers.models.llama.modeling_llama.LlamaRMSNorm with Llama->Qwen2
143
+ class Qwen2RMSNorm(nn.Module):
144
+ def __init__(self, hidden_size, eps=1e-6):
145
+ """
146
+ Qwen2RMSNorm is equivalent to T5LayerNorm
147
+ """
148
+ super().__init__()
149
+ self.weight = nn.Parameter(torch.ones(hidden_size))
150
+ self.variance_epsilon = eps
151
+
152
+ def forward(self, hidden_states):
153
+ input_dtype = hidden_states.dtype
154
+ hidden_states = hidden_states.to(torch.float32)
155
+ variance = hidden_states.pow(2).mean(-1, keepdim=True)
156
+ hidden_states = hidden_states * torch.rsqrt(variance + self.variance_epsilon)
157
+ return self.weight * hidden_states.to(input_dtype)
158
+
159
+ def extra_repr(self):
160
+ return f"{tuple(self.weight.shape)}, eps={self.variance_epsilon}"
161
+
162
+
163
+ # Copied from transformers.models.mixtral.modeling_mixtral.MixtralRotaryEmbedding with Mixtral->Qwen2
164
+ class Qwen2RotaryEmbedding(nn.Module):
165
+ def __init__(self, dim, max_position_embeddings=2048, base=10000, device=None):
166
+ super().__init__()
167
+
168
+ self.dim = dim
169
+ self.max_position_embeddings = max_position_embeddings
170
+ self.base = base
171
+ inv_freq = 1.0 / (self.base ** (torch.arange(0, self.dim, 2, dtype=torch.int64).float().to(device) / self.dim))
172
+ self.register_buffer("inv_freq", inv_freq, persistent=False)
173
+
174
+ # Build here to make `torch.jit.trace` work.
175
+ self._set_cos_sin_cache(
176
+ seq_len=max_position_embeddings, device=self.inv_freq.device, dtype=torch.get_default_dtype()
177
+ )
178
+
179
+ def _set_cos_sin_cache(self, seq_len, device, dtype):
180
+ self.max_seq_len_cached = seq_len
181
+ t = torch.arange(self.max_seq_len_cached, device=device, dtype=torch.int64).type_as(self.inv_freq)
182
+
183
+ freqs = torch.outer(t, self.inv_freq)
184
+ # Different from paper, but it uses a different permutation in order to obtain the same calculation
185
+ emb = torch.cat((freqs, freqs), dim=-1)
186
+ self.register_buffer("cos_cached", emb.cos().to(dtype), persistent=False)
187
+ self.register_buffer("sin_cached", emb.sin().to(dtype), persistent=False)
188
+
189
+ def forward(self, x, seq_len=None):
190
+ # x: [bs, num_attention_heads, seq_len, head_size]
191
+ if seq_len > self.max_seq_len_cached:
192
+ self._set_cos_sin_cache(seq_len=seq_len, device=x.device, dtype=x.dtype)
193
+
194
+ return (
195
+ self.cos_cached[:seq_len].to(dtype=x.dtype),
196
+ self.sin_cached[:seq_len].to(dtype=x.dtype),
197
+ )
198
+
199
+
200
+ # Copied from transformers.models.llama.modeling_llama.rotate_half
201
+ def rotate_half(x):
202
+ """Rotates half the hidden dims of the input."""
203
+ x1 = x[..., : x.shape[-1] // 2]
204
+ x2 = x[..., x.shape[-1] // 2 :]
205
+ return torch.cat((-x2, x1), dim=-1)
206
+
207
+
208
+ # Copied from transformers.models.mixtral.modeling_mixtral.apply_rotary_pos_emb
209
+ def apply_rotary_pos_emb(q, k, cos, sin, position_ids, unsqueeze_dim=1):
210
+ """Applies Rotary Position Embedding to the query and key tensors.
211
+
212
+ Args:
213
+ q (`torch.Tensor`): The query tensor.
214
+ k (`torch.Tensor`): The key tensor.
215
+ cos (`torch.Tensor`): The cosine part of the rotary embedding.
216
+ sin (`torch.Tensor`): The sine part of the rotary embedding.
217
+ position_ids (`torch.Tensor`):
218
+ The position indices of the tokens corresponding to the query and key tensors. For example, this can be
219
+ used to pass offsetted position ids when working with a KV-cache.
220
+ unsqueeze_dim (`int`, *optional*, defaults to 1):
221
+ The 'unsqueeze_dim' argument specifies the dimension along which to unsqueeze cos[position_ids] and
222
+ sin[position_ids] so that they can be properly broadcasted to the dimensions of q and k. For example, note
223
+ that cos[position_ids] and sin[position_ids] have the shape [batch_size, seq_len, head_dim]. Then, if q and
224
+ k have the shape [batch_size, heads, seq_len, head_dim], then setting unsqueeze_dim=1 makes
225
+ cos[position_ids] and sin[position_ids] broadcastable to the shapes of q and k. Similarly, if q and k have
226
+ the shape [batch_size, seq_len, heads, head_dim], then set unsqueeze_dim=2.
227
+ Returns:
228
+ `tuple(torch.Tensor)` comprising of the query and key tensors rotated using the Rotary Position Embedding.
229
+ """
230
+ cos = cos[position_ids].unsqueeze(unsqueeze_dim)
231
+ sin = sin[position_ids].unsqueeze(unsqueeze_dim)
232
+ q_embed = (q * cos) + (rotate_half(q) * sin)
233
+ k_embed = (k * cos) + (rotate_half(k) * sin)
234
+ return q_embed, k_embed
235
+
236
+
237
+ # Copied from transformers.models.mistral.modeling_mistral.MistralMLP with Mistral->Qwen2
238
+ class Qwen2MLP(nn.Module):
239
+ def __init__(self, config):
240
+ super().__init__()
241
+ self.hidden_size = config.hidden_size
242
+ self.intermediate_size = config.intermediate_size
243
+ self.gate_proj = nn.Linear(self.hidden_size, self.intermediate_size, bias=False)
244
+ self.up_proj = nn.Linear(self.hidden_size, self.intermediate_size, bias=False)
245
+ self.down_proj = nn.Linear(self.intermediate_size, self.hidden_size, bias=False)
246
+ self.act_fn = ACT2FN[config.hidden_act]
247
+
248
+ def prune_mlp(self, idx):
249
+ self.gate_proj = prune_linear_layer(self.gate_proj, idx)
250
+ self.up_proj = prune_linear_layer(self.up_proj, idx)
251
+ self.down_proj = prune_linear_layer(self.down_proj, idx, dim=1)
252
+
253
+ def forward(self, hidden_state):
254
+ return self.down_proj(self.act_fn(self.gate_proj(hidden_state)) * self.up_proj(hidden_state))
255
+
256
+
257
+ # Copied from transformers.models.llama.modeling_llama.repeat_kv
258
+ def repeat_kv(hidden_states: torch.Tensor, n_rep: int, index: Optional[torch.LongTensor] = None) -> torch.Tensor:
259
+ """
260
+ This is the equivalent of torch.repeat_interleave(x, dim=1, repeats=n_rep). The hidden states go from (batch,
261
+ num_key_value_heads, seqlen, head_dim) to (batch, num_attention_heads, seqlen, head_dim)
262
+ """
263
+ batch, num_key_value_heads, slen, head_dim = hidden_states.shape
264
+ if n_rep == 1:
265
+ return hidden_states
266
+ hidden_states = hidden_states[:, :, None, :, :].expand(batch, num_key_value_heads, n_rep, slen, head_dim)
267
+ hidden_states = hidden_states.reshape(batch, num_key_value_heads * n_rep, slen, head_dim)
268
+ # For pruned Qwen, we select corresponding matrix if Q is pruned.
269
+ if index is not None:
270
+ hidden_states = hidden_states.index_select(dim=1, index=index)
271
+ return hidden_states
272
+
273
+
274
+ class Qwen2Attention(nn.Module):
275
+ """
276
+ Multi-headed attention from 'Attention Is All You Need' paper. Modified to use sliding window attention: Longformer
277
+ and "Generating Long Sequences with Sparse Transformers".
278
+ """
279
+
280
+ def __init__(self, config: DarwinLMConfig, layer_idx: Optional[int] = None):
281
+ super().__init__()
282
+ self.config = config
283
+ self.layer_idx = layer_idx
284
+ if layer_idx is None:
285
+ logger.warning_once(
286
+ f"Instantiating {self.__class__.__name__} without passing `layer_idx` is not recommended and will "
287
+ "to errors during the forward call, if caching is used. Please make sure to provide a `layer_idx` "
288
+ "when creating this class."
289
+ )
290
+
291
+ self.hidden_size = config.hidden_size
292
+ self.num_heads = config.num_attention_heads
293
+ import copy
294
+ self.ori_num_heads = copy.deepcopy(self.num_heads)
295
+ self.head_dim = self.hidden_size // self.num_heads
296
+ self.num_key_value_heads = config.num_key_value_heads
297
+ self.num_key_value_groups = self.num_heads // self.num_key_value_heads
298
+ self.max_position_embeddings = config.max_position_embeddings
299
+ self.rope_theta = config.rope_theta
300
+ self.is_causal = True
301
+ self.attention_dropout = config.attention_dropout
302
+
303
+ if (self.head_dim * self.num_heads) != self.hidden_size:
304
+ raise ValueError(
305
+ f"hidden_size must be divisible by num_heads (got `hidden_size`: {self.hidden_size}"
306
+ f" and `num_heads`: {self.num_heads})."
307
+ )
308
+ self.q_proj = nn.Linear(self.hidden_size, self.num_heads * self.head_dim, bias=True)
309
+ self.k_proj = nn.Linear(self.hidden_size, self.num_key_value_heads * self.head_dim, bias=True)
310
+ self.v_proj = nn.Linear(self.hidden_size, self.num_key_value_heads * self.head_dim, bias=True)
311
+ self.o_proj = nn.Linear(self.num_heads * self.head_dim, self.hidden_size, bias=False)
312
+
313
+ self.rotary_emb = Qwen2RotaryEmbedding(
314
+ self.head_dim,
315
+ max_position_embeddings=self.max_position_embeddings,
316
+ base=self.rope_theta,
317
+ )
318
+ self.pruned_heads = set()
319
+ self.pruned_kv_heads = set()
320
+
321
+ # Added by Bryson for structural pruning in LLama
322
+ def prune_heads(self, heads, kv_ignore=False):
323
+ if len(heads) == 0:
324
+ return
325
+ heads, index = find_pruneable_heads_and_indices(
326
+ heads, self.num_heads, self.head_dim, self.pruned_heads
327
+ )
328
+ prune_size = index.shape[0]
329
+ # Prune linear layers
330
+ self.q_proj = prune_linear_layer(self.q_proj, index)
331
+ if not kv_ignore:
332
+ self.k_proj = prune_linear_layer(self.k_proj, index)
333
+ self.v_proj = prune_linear_layer(self.v_proj, index)
334
+ self.num_key_value_heads = self.num_key_value_heads - len(heads)
335
+ self.o_proj = prune_linear_layer(self.o_proj, index, dim=1)
336
+
337
+ # Update hyper params and store pruned heads
338
+ self.num_heads = self.num_heads - len(heads)
339
+ if not kv_ignore:
340
+ self.num_key_value_heads = self.num_key_value_heads - len(heads)
341
+ self.hidden_size = self.head_dim * self.num_heads
342
+ self.pruned_heads = self.pruned_heads.union(heads)
343
+ # Structural Pruning for GQA, prune K,V and prune the corresponding weight group in Q and O
344
+ # The input heads are the pruned index in K and V
345
+ def prune_group_heads(self, heads):
346
+ if len(heads) == 0:
347
+ return
348
+
349
+ heads, index = find_pruneable_heads_and_indices(
350
+ heads, self.num_key_value_heads, self.head_dim, self.pruned_kv_heads
351
+ )
352
+ self.k_proj = prune_linear_layer(self.k_proj, index)
353
+ self.v_proj = prune_linear_layer(self.v_proj, index)
354
+
355
+ self.num_key_value_heads = self.num_key_value_heads - len(heads)
356
+ self.pruned_kv_heads = self.pruned_heads.union(heads)
357
+
358
+ q_o_heads = []
359
+ for head in heads:
360
+ for i in range(head * self.num_key_value_groups, head * self.num_key_value_groups + self.num_key_value_groups):
361
+ q_o_heads.append(i)
362
+ # print(q_o_heads)
363
+ heads, index = find_pruneable_heads_and_indices(
364
+ q_o_heads, self.num_heads, self.head_dim, self.pruned_heads
365
+ )
366
+ # Prune linear layers
367
+ self.q_proj = prune_linear_layer(self.q_proj, index)
368
+ self.o_proj = prune_linear_layer(self.o_proj, index, dim=1)
369
+
370
+ # Update hyper params and store pruned heads
371
+ self.num_heads = self.num_heads - len(q_o_heads)
372
+ self.hidden_size = self.head_dim * self.num_heads
373
+ self.pruned_heads = self.pruned_heads.union(q_o_heads)
374
+
375
+
376
+ def forward(
377
+ self,
378
+ hidden_states: torch.Tensor,
379
+ attention_mask: Optional[torch.Tensor] = None,
380
+ position_ids: Optional[torch.LongTensor] = None,
381
+ past_key_value: Optional[Cache] = None,
382
+ output_attentions: bool = False,
383
+ use_cache: bool = False,
384
+ cache_position: Optional[torch.LongTensor] = None,
385
+ ) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
386
+ bsz, q_len, _ = hidden_states.size()
387
+
388
+ query_states = self.q_proj(hidden_states)
389
+ key_states = self.k_proj(hidden_states)
390
+ value_states = self.v_proj(hidden_states)
391
+
392
+ query_states = query_states.view(bsz, q_len, self.num_heads, self.head_dim).transpose(1, 2)
393
+ key_states = key_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
394
+ value_states = value_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
395
+
396
+ kv_seq_len = key_states.shape[-2]
397
+ if past_key_value is not None:
398
+ if self.layer_idx is None:
399
+ raise ValueError(
400
+ f"The cache structure has changed since version v4.36. If you are using {self.__class__.__name__} "
401
+ "for auto-regressive decoding with k/v caching, please make sure to initialize the attention class "
402
+ "with a layer index."
403
+ )
404
+ kv_seq_len += past_key_value.get_usable_length(kv_seq_len, self.layer_idx)
405
+ cos, sin = self.rotary_emb(value_states, seq_len=kv_seq_len)
406
+ query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin, position_ids)
407
+
408
+ if past_key_value is not None:
409
+ cache_kwargs = {"sin": sin, "cos": cos, "cache_position": cache_position} # Specific to RoPE models
410
+ key_states, value_states = past_key_value.update(key_states, value_states, self.layer_idx, cache_kwargs)
411
+
412
+ if query_states.shape[1] != key_states.shape[1]:
413
+ num_q_heads = query_states.shape[1]
414
+ num_kv_heads = key_states.shape[1]
415
+ remaining_head_index = []
416
+ for i in range(self.ori_num_heads):
417
+ if i not in self.pruned_heads:
418
+ remaining_head_index.append(i)
419
+ head_index_kv = torch.tensor(remaining_head_index).long().to(key_states.device)
420
+ key_states = repeat_kv(key_states, self.num_key_value_groups, index=head_index_kv)
421
+ value_states = repeat_kv(value_states, self.num_key_value_groups, index=head_index_kv)
422
+
423
+ attn_weights = torch.matmul(query_states, key_states.transpose(2, 3)) / math.sqrt(self.head_dim)
424
+
425
+ if attn_weights.size() != (bsz, self.num_heads, q_len, kv_seq_len):
426
+ raise ValueError(
427
+ f"Attention weights should be of size {(bsz, self.num_heads, q_len, kv_seq_len)}, but is"
428
+ f" {attn_weights.size()}"
429
+ )
430
+
431
+ if attention_mask is not None: # no matter the length, we just slice it
432
+ causal_mask = attention_mask[:, :, :, : key_states.shape[-2]]
433
+ attn_weights = attn_weights + causal_mask
434
+
435
+ # upcast attention to fp32
436
+ attn_weights = nn.functional.softmax(attn_weights, dim=-1, dtype=torch.float32).to(query_states.dtype)
437
+ attn_weights = nn.functional.dropout(attn_weights, p=self.attention_dropout, training=self.training)
438
+ attn_output = torch.matmul(attn_weights, value_states)
439
+
440
+ if attn_output.size() != (bsz, self.num_heads, q_len, self.head_dim):
441
+ raise ValueError(
442
+ f"`attn_output` should be of size {(bsz, self.num_heads, q_len, self.head_dim)}, but is"
443
+ f" {attn_output.size()}"
444
+ )
445
+
446
+ attn_output = attn_output.transpose(1, 2).contiguous()
447
+ attn_output = attn_output.reshape(bsz, q_len, self.hidden_size)
448
+
449
+ attn_output = self.o_proj(attn_output)
450
+
451
+ if not output_attentions:
452
+ attn_weights = None
453
+
454
+ return attn_output, attn_weights, past_key_value
455
+
456
+
457
+ class Qwen2FlashAttention2(Qwen2Attention):
458
+ """
459
+ Qwen2 flash attention module, following Qwen2 attention module. This module inherits from `Qwen2Attention`
460
+ as the weights of the module stays untouched. The only required change would be on the forward pass
461
+ where it needs to correctly call the public API of flash attention and deal with padding tokens
462
+ in case the input contains any of them. Additionally, for sliding window attention, we apply SWA only to the bottom
463
+ config.max_window_layers layers.
464
+ """
465
+
466
+ # Copied from transformers.models.llama.modeling_llama.LlamaFlashAttention2.__init__
467
+ def __init__(self, *args, **kwargs):
468
+ super().__init__(*args, **kwargs)
469
+
470
+ # TODO: Should be removed once Flash Attention for RoCm is bumped to 2.1.
471
+ # flash_attn<2.1 generates top-left aligned causal mask, while what is needed here is bottom-right alignement, that was made default for flash_attn>=2.1. This attribute is used to handle this difference. Reference: https://github.com/Dao-AILab/flash-attention/releases/tag/v2.1.0.
472
+ # Beware that with flash_attn<2.1, using q_seqlen != k_seqlen (except for the case q_seqlen == 1) produces a wrong mask (top-left).
473
+ self._flash_attn_uses_top_left_mask = not is_flash_attn_greater_or_equal_2_10()
474
+
475
+ def forward(
476
+ self,
477
+ hidden_states: torch.Tensor,
478
+ attention_mask: Optional[torch.Tensor] = None,
479
+ position_ids: Optional[torch.LongTensor] = None,
480
+ past_key_value: Optional[Cache] = None,
481
+ output_attentions: bool = False,
482
+ use_cache: bool = False,
483
+ cache_position: Optional[torch.LongTensor] = None,
484
+ ):
485
+ bsz, q_len, _ = hidden_states.size()
486
+
487
+ query_states = self.q_proj(hidden_states)
488
+ key_states = self.k_proj(hidden_states)
489
+ value_states = self.v_proj(hidden_states)
490
+
491
+ query_states = query_states.view(bsz, q_len, self.num_heads, self.head_dim).transpose(1, 2)
492
+ key_states = key_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
493
+ value_states = value_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
494
+
495
+ kv_seq_len = key_states.shape[-2]
496
+ if past_key_value is not None:
497
+ if self.layer_idx is None:
498
+ raise ValueError(
499
+ f"The cache structure has changed since version v4.36. If you are using {self.__class__.__name__} "
500
+ "for auto-regressive decoding with k/v caching, please make sure to initialize the attention class "
501
+ "with a layer index."
502
+ )
503
+ kv_seq_len += past_key_value.get_usable_length(kv_seq_len, self.layer_idx)
504
+
505
+ # Because the input can be padded, the absolute sequence length depends on the max position id.
506
+ rotary_seq_len = (
507
+ max(kv_seq_len, position_ids[:, -1].max().item() + 1) if position_ids is not None else kv_seq_len
508
+ )
509
+
510
+ cos, sin = self.rotary_emb(value_states, seq_len=rotary_seq_len)
511
+
512
+ query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin, position_ids)
513
+
514
+ if past_key_value is not None:
515
+ # Activate slicing cache only if the config has a value `sliding_windows` attribute
516
+ cache_has_contents = past_key_value.get_seq_length(self.layer_idx) > 0
517
+ if (
518
+ getattr(self.config, "sliding_window", None) is not None
519
+ and kv_seq_len > self.config.sliding_window
520
+ and cache_has_contents
521
+ ):
522
+ slicing_tokens = 1 - self.config.sliding_window
523
+
524
+ past_key = past_key_value[self.layer_idx][0]
525
+ past_value = past_key_value[self.layer_idx][1]
526
+
527
+ past_key = past_key[:, :, slicing_tokens:, :].contiguous()
528
+ past_value = past_value[:, :, slicing_tokens:, :].contiguous()
529
+
530
+ if past_key.shape[-2] != self.config.sliding_window - 1:
531
+ raise ValueError(
532
+ f"past key must have a shape of (`batch_size, num_heads, self.config.sliding_window-1, head_dim`), got"
533
+ f" {past_key.shape}"
534
+ )
535
+
536
+ if attention_mask is not None:
537
+ attention_mask = attention_mask[:, slicing_tokens:]
538
+ attention_mask = torch.cat([attention_mask, torch.ones_like(attention_mask[:, -1:])], dim=-1)
539
+
540
+ cache_kwargs = {"sin": sin, "cos": cos, "cache_position": cache_position} # Specific to RoPE models
541
+ key_states, value_states = past_key_value.update(key_states, value_states, self.layer_idx, cache_kwargs)
542
+
543
+ if query_states.shape[1] != key_states.shape[1]:
544
+ num_q_heads = query_states.shape[1]
545
+ num_kv_heads = key_states.shape[1]
546
+ remaining_head_index = []
547
+ for i in range(self.ori_num_heads):
548
+ if i not in self.pruned_heads:
549
+ remaining_head_index.append(i)
550
+ head_index_kv = torch.tensor(remaining_head_index).long().to(key_states.device)
551
+ key_states = repeat_kv(key_states, self.num_key_value_groups, index=head_index_kv)
552
+ value_states = repeat_kv(value_states, self.num_key_value_groups, index=head_index_kv)
553
+ dropout_rate = 0.0 if not self.training else self.attention_dropout
554
+
555
+ # In PEFT, usually we cast the layer norms in float32 for training stability reasons
556
+ # therefore the input hidden states gets silently casted in float32. Hence, we need
557
+ # cast them back in float16 just to be sure everything works as expected.
558
+ input_dtype = query_states.dtype
559
+ if input_dtype == torch.float32:
560
+ if torch.is_autocast_enabled():
561
+ target_dtype = torch.get_autocast_gpu_dtype()
562
+ # Handle the case where the model is quantized
563
+ elif hasattr(self.config, "_pre_quantization_dtype"):
564
+ target_dtype = self.config._pre_quantization_dtype
565
+ else:
566
+ target_dtype = self.q_proj.weight.dtype
567
+
568
+ logger.warning_once(
569
+ f"The input hidden states seems to be silently casted in float32, this might be related to"
570
+ f" the fact you have upcasted embedding or layer norm layers in float32. We will cast back the input in"
571
+ f" {target_dtype}."
572
+ )
573
+
574
+ query_states = query_states.to(target_dtype)
575
+ key_states = key_states.to(target_dtype)
576
+ value_states = value_states.to(target_dtype)
577
+
578
+ # Reashape to the expected shape for Flash Attention
579
+ query_states = query_states.transpose(1, 2)
580
+ key_states = key_states.transpose(1, 2)
581
+ value_states = value_states.transpose(1, 2)
582
+
583
+ if (
584
+ self.config.use_sliding_window
585
+ and getattr(self.config, "sliding_window", None) is not None
586
+ and self.layer_idx >= self.config.max_window_layers
587
+ ):
588
+ sliding_window = self.config.sliding_window
589
+ else:
590
+ sliding_window = None
591
+
592
+ attn_output = _flash_attention_forward(
593
+ query_states,
594
+ key_states,
595
+ value_states,
596
+ attention_mask,
597
+ q_len,
598
+ position_ids=position_ids,
599
+ dropout=dropout_rate,
600
+ sliding_window=sliding_window,
601
+ is_causal=self.is_causal,
602
+ use_top_left_mask=self._flash_attn_uses_top_left_mask,
603
+ )
604
+
605
+ attn_output = attn_output.reshape(bsz, q_len, self.hidden_size).contiguous()
606
+ attn_output = self.o_proj(attn_output)
607
+
608
+ if not output_attentions:
609
+ attn_weights = None
610
+
611
+ return attn_output, attn_weights, past_key_value
612
+
613
+
614
+ # Copied from transformers.models.mixtral.modeling_mixtral.MixtralSdpaAttention with Mixtral->Qwen2
615
+ class Qwen2SdpaAttention(Qwen2Attention):
616
+ """
617
+ Qwen2 attention module using torch.nn.functional.scaled_dot_product_attention. This module inherits from
618
+ `Qwen2Attention` as the weights of the module stays untouched. The only changes are on the forward pass to adapt to
619
+ SDPA API.
620
+ """
621
+
622
+ # Adapted from Qwen2Attention.forward
623
+ def forward(
624
+ self,
625
+ hidden_states: torch.Tensor,
626
+ attention_mask: Optional[torch.Tensor] = None,
627
+ position_ids: Optional[torch.LongTensor] = None,
628
+ past_key_value: Optional[Cache] = None,
629
+ output_attentions: bool = False,
630
+ use_cache: bool = False,
631
+ cache_position: Optional[torch.LongTensor] = None,
632
+ ) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
633
+ if output_attentions:
634
+ # TODO: Improve this warning with e.g. `model.config.attn_implementation = "manual"` once this is implemented.
635
+ logger.warning_once(
636
+ "Qwen2Model is using Qwen2SdpaAttention, but `torch.nn.functional.scaled_dot_product_attention` does not support `output_attentions=True`. Falling back to the manual attention implementation, "
637
+ 'but specifying the manual implementation will be required from Transformers version v5.0.0 onwards. This warning can be removed using the argument `attn_implementation="eager"` when loading the model.'
638
+ )
639
+ return super().forward(
640
+ hidden_states=hidden_states,
641
+ attention_mask=attention_mask,
642
+ position_ids=position_ids,
643
+ past_key_value=past_key_value,
644
+ output_attentions=output_attentions,
645
+ use_cache=use_cache,
646
+ )
647
+
648
+ bsz, q_len, _ = hidden_states.size()
649
+
650
+ query_states = self.q_proj(hidden_states)
651
+ key_states = self.k_proj(hidden_states)
652
+ value_states = self.v_proj(hidden_states)
653
+
654
+ query_states = query_states.view(bsz, q_len, self.num_heads, self.head_dim).transpose(1, 2)
655
+ key_states = key_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
656
+ value_states = value_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2)
657
+
658
+ kv_seq_len = key_states.shape[-2]
659
+ if past_key_value is not None:
660
+ kv_seq_len += past_key_value.get_usable_length(kv_seq_len, self.layer_idx)
661
+ cos, sin = self.rotary_emb(value_states, seq_len=kv_seq_len)
662
+
663
+ query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin, position_ids)
664
+
665
+ # if past_key_value is not None:
666
+ # cache_kwargs = {"sin": sin, "cos": cos, "cache_position": cache_position} # Specific to RoPE models
667
+ # key_states, value_states = past_key_value.update(key_states, value_states, self.layer_idx, cache_kwargs)
668
+
669
+ if query_states.shape[1] != key_states.shape[1]:
670
+ num_q_heads = query_states.shape[1]
671
+ num_kv_heads = key_states.shape[1]
672
+ remaining_head_index = []
673
+ for i in range(self.ori_num_heads):
674
+ if i not in self.pruned_heads:
675
+ remaining_head_index.append(i)
676
+ head_index_kv = torch.tensor(remaining_head_index).long().to(key_states.device)
677
+ key_states = repeat_kv(key_states, self.num_key_value_groups, index=head_index_kv)
678
+ value_states = repeat_kv(value_states, self.num_key_value_groups, index=head_index_kv)
679
+
680
+ causal_mask = attention_mask
681
+ if attention_mask is not None: # no matter the length, we just slice it
682
+ causal_mask = attention_mask[:, :, :, : key_states.shape[-2]]
683
+
684
+ # SDPA with memory-efficient backend is currently (torch==2.1.2) bugged with non-contiguous inputs with custom attn_mask,
685
+ # Reference: https://github.com/pytorch/pytorch/issues/112577.
686
+ if query_states.device.type == "cuda" and attention_mask is not None:
687
+ query_states = query_states.contiguous()
688
+ key_states = key_states.contiguous()
689
+ value_states = value_states.contiguous()
690
+
691
+ # We dispatch to SDPA's Flash Attention or Efficient kernels via this `is_causal` if statement instead of an inline conditional assignment
692
+ # in SDPA to support both torch.compile's dynamic shapes and full graph options. An inline conditional prevents dynamic shapes from compiling.
693
+ # The q_len > 1 is necessary to match with AttentionMaskConverter.to_causal_4d that does not create a causal mask in case q_len == 1.
694
+ is_causal = True if causal_mask is None and q_len > 1 else False
695
+
696
+ attn_output = torch.nn.functional.scaled_dot_product_attention(
697
+ query_states,
698
+ key_states,
699
+ value_states,
700
+ attn_mask=causal_mask,
701
+ dropout_p=self.attention_dropout if self.training else 0.0,
702
+ is_causal=is_causal,
703
+ )
704
+
705
+ attn_output = attn_output.transpose(1, 2).contiguous()
706
+ attn_output = attn_output.view(bsz, q_len, self.hidden_size)
707
+
708
+ attn_output = self.o_proj(attn_output)
709
+
710
+ return attn_output, None, past_key_value
711
+
712
+
713
+ QWEN2_ATTENTION_CLASSES = {
714
+ "eager": Qwen2Attention,
715
+ "flash_attention_2": Qwen2FlashAttention2,
716
+ "sdpa": Qwen2SdpaAttention,
717
+ }
718
+
719
+
720
+ class Qwen2DecoderLayer(nn.Module):
721
+ def __init__(self, config: DarwinLMConfig, layer_idx: int):
722
+ super().__init__()
723
+ self.hidden_size = config.hidden_size
724
+
725
+ if config.sliding_window and config._attn_implementation != "flash_attention_2":
726
+ logger.warning_once(
727
+ f"Sliding Window Attention is enabled but not implemented for `{config._attn_implementation}`; "
728
+ "unexpected results may be encountered."
729
+ )
730
+ self.self_attn = QWEN2_ATTENTION_CLASSES[config._attn_implementation](config, layer_idx)
731
+
732
+ self.mlp = Qwen2MLP(config)
733
+ self.input_layernorm = Qwen2RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
734
+ self.post_attention_layernorm = Qwen2RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
735
+
736
+ def forward(
737
+ self,
738
+ hidden_states: torch.Tensor,
739
+ attention_mask: Optional[torch.Tensor] = None,
740
+ position_ids: Optional[torch.LongTensor] = None,
741
+ past_key_value: Optional[Tuple[torch.Tensor]] = None,
742
+ output_attentions: Optional[bool] = False,
743
+ use_cache: Optional[bool] = False,
744
+ cache_position: Optional[torch.LongTensor] = None,
745
+ **kwargs,
746
+ ) -> Tuple[torch.FloatTensor, Optional[Tuple[torch.FloatTensor, torch.FloatTensor]]]:
747
+ """
748
+ Args:
749
+ hidden_states (`torch.FloatTensor`): input to the layer of shape `(batch, seq_len, embed_dim)`
750
+ attention_mask (`torch.FloatTensor`, *optional*): attention mask of size
751
+ `(batch, sequence_length)` where padding elements are indicated by 0.
752
+ output_attentions (`bool`, *optional*):
753
+ Whether or not to return the attentions tensors of all attention layers. See `attentions` under
754
+ returned tensors for more detail.
755
+ use_cache (`bool`, *optional*):
756
+ If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding
757
+ (see `past_key_values`).
758
+ past_key_value (`Tuple(torch.FloatTensor)`, *optional*): cached past key and value projection states
759
+ cache_position (`torch.LongTensor` of shape `(sequence_length)`, *optional*):
760
+ Indices depicting the position of the input sequence tokens in the sequence.
761
+ kwargs (`dict`, *optional*):
762
+ Arbitrary kwargs to be ignored, used for FSDP and other methods that injects code
763
+ into the model
764
+ """
765
+
766
+ residual = hidden_states
767
+
768
+ hidden_states = self.input_layernorm(hidden_states)
769
+
770
+ # Self Attention
771
+ hidden_states, self_attn_weights, present_key_value = self.self_attn(
772
+ hidden_states,
773
+ attention_mask,
774
+ position_ids,
775
+ past_key_value,
776
+ output_attentions,
777
+ use_cache,
778
+ cache_position,
779
+ )
780
+ hidden_states = residual + hidden_states
781
+
782
+ # Fully Connected
783
+ residual = hidden_states
784
+ hidden_states = self.post_attention_layernorm(hidden_states)
785
+ hidden_states = self.mlp(hidden_states)
786
+ hidden_states = residual + hidden_states
787
+
788
+ outputs = (hidden_states,)
789
+
790
+ if output_attentions:
791
+ outputs += (self_attn_weights,)
792
+
793
+ if use_cache:
794
+ outputs += (present_key_value,)
795
+
796
+ return outputs
797
+
798
+
799
+ QWEN2_START_DOCSTRING = r"""
800
+ This model inherits from [`PreTrainedModel`]. Check the superclass documentation for the generic methods the
801
+ library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads
802
+ etc.)
803
+
804
+ This model is also a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass.
805
+ Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage
806
+ and behavior.
807
+
808
+ Parameters:
809
+ config ([`DarwinLMConfig`]):
810
+ Model configuration class with all the parameters of the model. Initializing with a config file does not
811
+ load the weights associated with the model, only the configuration. Check out the
812
+ [`~PreTrainedModel.from_pretrained`] method to load the model weights.
813
+ """
814
+
815
+
816
+ @add_start_docstrings(
817
+ "The bare Qwen2 Model outputting raw hidden-states without any specific head on top.",
818
+ QWEN2_START_DOCSTRING,
819
+ )
820
+ class Qwen2PreTrainedModel(PreTrainedModel):
821
+ config_class = DarwinLMConfig
822
+ base_model_prefix = "model"
823
+ supports_gradient_checkpointing = True
824
+ _no_split_modules = ["Qwen2DecoderLayer"]
825
+ _skip_keys_device_placement = "past_key_values"
826
+ _supports_flash_attn_2 = True
827
+ _supports_sdpa = True
828
+ _supports_cache_class = True
829
+
830
+ def _init_weights(self, module):
831
+ std = self.config.initializer_range
832
+ if isinstance(module, nn.Linear):
833
+ module.weight.data.normal_(mean=0.0, std=std)
834
+ if module.bias is not None:
835
+ module.bias.data.zero_()
836
+ elif isinstance(module, nn.Embedding):
837
+ module.weight.data.normal_(mean=0.0, std=std)
838
+ if module.padding_idx is not None:
839
+ module.weight.data[module.padding_idx].zero_()
840
+
841
+
842
+ QWEN2_INPUTS_DOCSTRING = r"""
843
+ Args:
844
+ input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
845
+ Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you provide
846
+ it.
847
+
848
+ Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
849
+ [`PreTrainedTokenizer.__call__`] for details.
850
+
851
+ [What are input IDs?](../glossary#input-ids)
852
+ attention_mask (`torch.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
853
+ Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:
854
+
855
+ - 1 for tokens that are **not masked**,
856
+ - 0 for tokens that are **masked**.
857
+
858
+ [What are attention masks?](../glossary#attention-mask)
859
+
860
+ Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
861
+ [`PreTrainedTokenizer.__call__`] for details.
862
+
863
+ If `past_key_values` is used, optionally only the last `decoder_input_ids` have to be input (see
864
+ `past_key_values`).
865
+
866
+ If you want to change padding behavior, you should read [`modeling_opt._prepare_decoder_attention_mask`]
867
+ and modify to your needs. See diagram 1 in [the paper](https://arxiv.org/abs/1910.13461) for more
868
+ information on the default strategy.
869
+
870
+ - 1 indicates the head is **not masked**,
871
+ - 0 indicates the head is **masked**.
872
+ position_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
873
+ Indices of positions of each input sequence tokens in the position embeddings. Selected in the range `[0,
874
+ config.n_positions - 1]`.
875
+
876
+ [What are position IDs?](../glossary#position-ids)
877
+ past_key_values (`Cache` or `tuple(tuple(torch.FloatTensor))`, *optional*):
878
+ Pre-computed hidden-states (key and values in the self-attention blocks and in the cross-attention
879
+ blocks) that can be used to speed up sequential decoding. This typically consists in the `past_key_values`
880
+ returned by the model at a previous stage of decoding, when `use_cache=True` or `config.use_cache=True`.
881
+
882
+ Two formats are allowed:
883
+ - a [`~cache_utils.Cache`] instance;
884
+ - Tuple of `tuple(torch.FloatTensor)` of length `config.n_layers`, with each tuple having 2 tensors of
885
+ shape `(batch_size, num_heads, sequence_length, embed_size_per_head)`). This is also known as the legacy
886
+ cache format.
887
+
888
+ The model will output the same cache format that is fed as input. If no `past_key_values` are passed, the
889
+ legacy cache format will be returned.
890
+
891
+ If `past_key_values` are used, the user can optionally input only the last `input_ids` (those that don't
892
+ have their past key value states given to this model) of shape `(batch_size, 1)` instead of all `input_ids`
893
+ of shape `(batch_size, sequence_length)`.
894
+ inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):
895
+ Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation. This
896
+ is useful if you want more control over how to convert `input_ids` indices into associated vectors than the
897
+ model's internal embedding lookup matrix.
898
+ use_cache (`bool`, *optional*):
899
+ If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding (see
900
+ `past_key_values`).
901
+ output_attentions (`bool`, *optional*):
902
+ Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned
903
+ tensors for more detail.
904
+ output_hidden_states (`bool`, *optional*):
905
+ Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for
906
+ more detail.
907
+ return_dict (`bool`, *optional*):
908
+ Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.
909
+ cache_position (`torch.LongTensor` of shape `(sequence_length)`, *optional*):
910
+ Indices depicting the position of the input sequence tokens in the sequence. Contrarily to `position_ids`,
911
+ this tensor is not affected by padding. It is used to update the cache in the correct position and to infer
912
+ the complete sequence length.
913
+ """
914
+
915
+
916
+ @add_start_docstrings(
917
+ "The bare Qwen2 Model outputting raw hidden-states without any specific head on top.",
918
+ QWEN2_START_DOCSTRING,
919
+ )
920
+ class Qwen2Model(Qwen2PreTrainedModel):
921
+ """
922
+ Transformer decoder consisting of *config.num_hidden_layers* layers. Each layer is a [`Qwen2DecoderLayer`]
923
+
924
+ Args:
925
+ config: DarwinLMConfig
926
+ """
927
+
928
+ def __init__(self, config: DarwinLMConfig):
929
+ super().__init__(config)
930
+ self.padding_idx = config.pad_token_id
931
+ self.vocab_size = config.vocab_size
932
+
933
+ self.embed_tokens = nn.Embedding(config.vocab_size, config.hidden_size, self.padding_idx)
934
+ self.layers = nn.ModuleList(
935
+ [Qwen2DecoderLayer(config, layer_idx) for layer_idx in range(config.num_hidden_layers)]
936
+ )
937
+ self._attn_implementation = config._attn_implementation
938
+ self.norm = Qwen2RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
939
+
940
+ self.gradient_checkpointing = False
941
+ # Initialize weights and apply final processing
942
+ self.post_init()
943
+
944
+ self.heads_each_attn = config.heads_each_attn
945
+ self.dim_each_mlp = config.dim_each_mlp
946
+ self.kv_ignore = config.kv_ignore
947
+ self.prune_model(self.heads_each_attn, self.dim_each_mlp, self.kv_ignore)
948
+
949
+ def get_input_embeddings(self):
950
+ return self.embed_tokens
951
+
952
+ def set_input_embeddings(self, value):
953
+ self.embed_tokens = value
954
+
955
+ def prune_model(self, heads_each_attn, dim_each_mlp, kv_ignore):
956
+ for name, heads_idx in heads_each_attn.items():
957
+ layer_idx = int(name.split(".")[0])
958
+ attn = self.layers[layer_idx].self_attn
959
+ if len(heads_idx) == attn.ori_num_heads:
960
+ self.layers[layer_idx].self_attn = NoAttention()
961
+ continue
962
+ # heads = [i for i in range(heads_num)]
963
+ attn.prune_heads(heads_idx, kv_ignore)
964
+
965
+ for name, dim in dim_each_mlp.items():
966
+ layer_idx = int(name.split(".")[0])
967
+ mlp = self.layers[layer_idx].mlp
968
+ if dim == 0:
969
+ mlp.up_proj = NoIntermediate()
970
+ mlp.gate_proj = NoIntermediate()
971
+ mlp.down_proj = NoOutput()
972
+ continue
973
+ dims = [i for i in range(dim)]
974
+ dims = torch.tensor(dims).long()
975
+ mlp.prune_mlp(dims)
976
+
977
+ @add_start_docstrings_to_model_forward(QWEN2_INPUTS_DOCSTRING)
978
+ def forward(
979
+ self,
980
+ input_ids: torch.LongTensor = None,
981
+ attention_mask: Optional[torch.Tensor] = None,
982
+ position_ids: Optional[torch.LongTensor] = None,
983
+ past_key_values: Optional[List[torch.FloatTensor]] = None,
984
+ inputs_embeds: Optional[torch.FloatTensor] = None,
985
+ use_cache: Optional[bool] = None,
986
+ output_attentions: Optional[bool] = None,
987
+ output_hidden_states: Optional[bool] = None,
988
+ return_dict: Optional[bool] = None,
989
+ cache_position: Optional[torch.LongTensor] = None,
990
+ ) -> Union[Tuple, BaseModelOutputWithPast]:
991
+ output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
992
+ output_hidden_states = (
993
+ output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
994
+ )
995
+ use_cache = use_cache if use_cache is not None else self.config.use_cache
996
+
997
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
998
+
999
+ if (input_ids is None) ^ (inputs_embeds is not None):
1000
+ raise ValueError(
1001
+ "You cannot specify both input_ids and inputs_embeds at the same time, and must specify either one"
1002
+ )
1003
+
1004
+ if self.gradient_checkpointing and self.training:
1005
+ if use_cache:
1006
+ logger.warning_once(
1007
+ "`use_cache=True` is incompatible with gradient checkpointing. Setting `use_cache=False`..."
1008
+ )
1009
+ use_cache = False
1010
+
1011
+ use_legacy_cache = False
1012
+ if use_cache and not isinstance(past_key_values, Cache) and not self.training:
1013
+ use_legacy_cache = True
1014
+ past_key_values = DynamicCache.from_legacy_cache(past_key_values)
1015
+ logger.warning_once(
1016
+ "We detected that you are passing `past_key_values` as a tuple and this is deprecated and will be removed in v4.43. "
1017
+ "Please use an appropriate `Cache` class (https://huggingface.co/docs/transformers/internal/generation_utils#transformers.Cache)"
1018
+ )
1019
+
1020
+ if inputs_embeds is None:
1021
+ inputs_embeds = self.embed_tokens(input_ids)
1022
+
1023
+ if cache_position is None:
1024
+ past_seen_tokens = past_key_values.get_seq_length() if past_key_values is not None else 0
1025
+ cache_position = torch.arange(
1026
+ past_seen_tokens, past_seen_tokens + inputs_embeds.shape[1], device=inputs_embeds.device
1027
+ )
1028
+ if position_ids is None:
1029
+ position_ids = cache_position.unsqueeze(0)
1030
+
1031
+ causal_mask = self._update_causal_mask(
1032
+ attention_mask, inputs_embeds, cache_position, past_key_values, output_attentions
1033
+ )
1034
+
1035
+ hidden_states = inputs_embeds
1036
+
1037
+ # decoder layers
1038
+ all_hidden_states = () if output_hidden_states else None
1039
+ all_self_attns = () if output_attentions else None
1040
+ next_decoder_cache = None
1041
+
1042
+ for decoder_layer in self.layers:
1043
+ if output_hidden_states:
1044
+ all_hidden_states += (hidden_states,)
1045
+
1046
+ if self.gradient_checkpointing and self.training:
1047
+ layer_outputs = self._gradient_checkpointing_func(
1048
+ decoder_layer.__call__,
1049
+ hidden_states,
1050
+ causal_mask,
1051
+ position_ids,
1052
+ past_key_values,
1053
+ output_attentions,
1054
+ use_cache,
1055
+ cache_position,
1056
+ )
1057
+ else:
1058
+ layer_outputs = decoder_layer(
1059
+ hidden_states,
1060
+ causal_mask,
1061
+ position_ids,
1062
+ past_key_values,
1063
+ output_attentions,
1064
+ use_cache,
1065
+ cache_position,
1066
+ )
1067
+
1068
+ hidden_states = layer_outputs[0]
1069
+
1070
+ if use_cache:
1071
+ next_decoder_cache = layer_outputs[2 if output_attentions else 1]
1072
+
1073
+ if output_attentions:
1074
+ all_self_attns += (layer_outputs[1],)
1075
+
1076
+ hidden_states = self.norm(hidden_states)
1077
+
1078
+ # add hidden states from the last decoder layer
1079
+ if output_hidden_states:
1080
+ all_hidden_states += (hidden_states,)
1081
+
1082
+ next_cache = None
1083
+ if use_cache:
1084
+ next_cache = next_decoder_cache.to_legacy_cache() if use_legacy_cache else next_decoder_cache
1085
+
1086
+ if not return_dict:
1087
+ return tuple(v for v in [hidden_states, next_cache, all_hidden_states, all_self_attns] if v is not None)
1088
+ return BaseModelOutputWithPast(
1089
+ last_hidden_state=hidden_states,
1090
+ past_key_values=next_cache,
1091
+ hidden_states=all_hidden_states,
1092
+ attentions=all_self_attns,
1093
+ )
1094
+
1095
+ # Copied from transformers.models.llama.modeling_llama.LlamaModel._update_causal_mask
1096
+ def _update_causal_mask(
1097
+ self,
1098
+ attention_mask: torch.Tensor,
1099
+ input_tensor: torch.Tensor,
1100
+ cache_position: torch.Tensor,
1101
+ past_key_values: Cache,
1102
+ output_attentions: bool,
1103
+ ):
1104
+ if self.config._attn_implementation == "flash_attention_2":
1105
+ if attention_mask is not None and 0.0 in attention_mask:
1106
+ return attention_mask
1107
+ return None
1108
+
1109
+ # For SDPA, when possible, we will rely on its `is_causal` argument instead of its `attn_mask` argument, in
1110
+ # order to dispatch on Flash Attention 2. This feature is not compatible with static cache, as SDPA will fail
1111
+ # to infer the attention mask.
1112
+ past_seen_tokens = past_key_values.get_seq_length() if past_key_values is not None else 0
1113
+ using_static_cache = isinstance(past_key_values, StaticCache)
1114
+
1115
+ # When output attentions is True, sdpa implementation's forward method calls the eager implementation's forward
1116
+ if self.config._attn_implementation == "sdpa" and not using_static_cache and not output_attentions:
1117
+ if AttentionMaskConverter._ignore_causal_mask_sdpa(
1118
+ attention_mask,
1119
+ inputs_embeds=input_tensor,
1120
+ past_key_values_length=past_seen_tokens,
1121
+ is_training=self.training,
1122
+ ):
1123
+ return None
1124
+
1125
+ dtype, device = input_tensor.dtype, input_tensor.device
1126
+ min_dtype = torch.finfo(dtype).min
1127
+ sequence_length = input_tensor.shape[1]
1128
+ if using_static_cache:
1129
+ target_length = past_key_values.get_max_length()
1130
+ else:
1131
+ target_length = (
1132
+ attention_mask.shape[-1]
1133
+ if isinstance(attention_mask, torch.Tensor)
1134
+ else past_seen_tokens + sequence_length + 1
1135
+ )
1136
+
1137
+ # In case the provided `attention` mask is 2D, we generate a causal mask here (4D).
1138
+ causal_mask = _prepare_4d_causal_attention_mask_with_cache_position(
1139
+ attention_mask,
1140
+ sequence_length=sequence_length,
1141
+ target_length=target_length,
1142
+ dtype=dtype,
1143
+ device=device,
1144
+ min_dtype=min_dtype,
1145
+ cache_position=cache_position,
1146
+ batch_size=input_tensor.shape[0],
1147
+ )
1148
+
1149
+ if (
1150
+ self.config._attn_implementation == "sdpa"
1151
+ and attention_mask is not None
1152
+ and attention_mask.device.type == "cuda"
1153
+ and not output_attentions
1154
+ ):
1155
+ # Attend to all tokens in fully masked rows in the causal_mask, for example the relevant first rows when
1156
+ # using left padding. This is required by F.scaled_dot_product_attention memory-efficient attention path.
1157
+ # Details: https://github.com/pytorch/pytorch/issues/110213
1158
+ causal_mask = AttentionMaskConverter._unmask_unattended(causal_mask, min_dtype)
1159
+
1160
+ return causal_mask
1161
+
1162
+
1163
+ class Qwen2ForCausalLM(Qwen2PreTrainedModel):
1164
+ _tied_weights_keys = ["lm_head.weight"]
1165
+
1166
+ def __init__(self, config):
1167
+ super().__init__(config)
1168
+ self.model = Qwen2Model(config)
1169
+ self.vocab_size = config.vocab_size
1170
+ self.lm_head = nn.Linear(config.hidden_size, config.vocab_size, bias=False)
1171
+
1172
+ # Initialize weights and apply final processing
1173
+ self.post_init()
1174
+
1175
+ def get_input_embeddings(self):
1176
+ return self.model.embed_tokens
1177
+
1178
+ def set_input_embeddings(self, value):
1179
+ self.model.embed_tokens = value
1180
+
1181
+ def get_output_embeddings(self):
1182
+ return self.lm_head
1183
+
1184
+ def set_output_embeddings(self, new_embeddings):
1185
+ self.lm_head = new_embeddings
1186
+
1187
+ def set_decoder(self, decoder):
1188
+ self.model = decoder
1189
+
1190
+ def get_decoder(self):
1191
+ return self.model
1192
+
1193
+ @add_start_docstrings_to_model_forward(QWEN2_INPUTS_DOCSTRING)
1194
+ @replace_return_docstrings(output_type=CausalLMOutputWithPast, config_class=_CONFIG_FOR_DOC)
1195
+ def forward(
1196
+ self,
1197
+ input_ids: torch.LongTensor = None,
1198
+ attention_mask: Optional[torch.Tensor] = None,
1199
+ position_ids: Optional[torch.LongTensor] = None,
1200
+ past_key_values: Optional[List[torch.FloatTensor]] = None,
1201
+ inputs_embeds: Optional[torch.FloatTensor] = None,
1202
+ labels: Optional[torch.LongTensor] = None,
1203
+ use_cache: Optional[bool] = None,
1204
+ output_attentions: Optional[bool] = None,
1205
+ output_hidden_states: Optional[bool] = None,
1206
+ return_dict: Optional[bool] = None,
1207
+ cache_position: Optional[torch.LongTensor] = None,
1208
+ num_logits_to_keep: int = 0,
1209
+ ) -> Union[Tuple, CausalLMOutputWithPast]:
1210
+ r"""
1211
+ Args:
1212
+ labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
1213
+ Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
1214
+ config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
1215
+ (masked), the loss is only computed for the tokens with labels in `[0, ..., config.vocab_size]`.
1216
+
1217
+ num_logits_to_keep (`int`, *optional*):
1218
+ Calculate logits for the last `num_logits_to_keep` tokens. If `0`, calculate logits for all
1219
+ `input_ids` (special case). Only last token logits are needed for generation, and calculating them only for that
1220
+ token can save memory, which becomes pretty significant for long sequences or large vocabulary size.
1221
+
1222
+ Returns:
1223
+
1224
+ Example:
1225
+
1226
+ ```python
1227
+ >>> from transformers import AutoTokenizer, Qwen2ForCausalLM
1228
+
1229
+ >>> model = Qwen2ForCausalLM.from_pretrained(PATH_TO_CONVERTED_WEIGHTS)
1230
+ >>> tokenizer = AutoTokenizer.from_pretrained(PATH_TO_CONVERTED_TOKENIZER)
1231
+
1232
+ >>> prompt = "Hey, are you conscious? Can you talk to me?"
1233
+ >>> inputs = tokenizer(prompt, return_tensors="pt")
1234
+
1235
+ >>> # Generate
1236
+ >>> generate_ids = model.generate(inputs.input_ids, max_length=30)
1237
+ >>> tokenizer.batch_decode(generate_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
1238
+ "Hey, are you conscious? Can you talk to me?\nI'm not conscious, but I can talk to you."
1239
+ ```"""
1240
+
1241
+ output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
1242
+ output_hidden_states = (
1243
+ output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
1244
+ )
1245
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
1246
+
1247
+ # decoder outputs consists of (dec_features, layer_state, dec_hidden, dec_attn)
1248
+ outputs = self.model(
1249
+ input_ids=input_ids,
1250
+ attention_mask=attention_mask,
1251
+ position_ids=position_ids,
1252
+ past_key_values=past_key_values,
1253
+ inputs_embeds=inputs_embeds,
1254
+ use_cache=use_cache,
1255
+ output_attentions=output_attentions,
1256
+ output_hidden_states=output_hidden_states,
1257
+ return_dict=return_dict,
1258
+ cache_position=cache_position,
1259
+ )
1260
+
1261
+ hidden_states = outputs[0]
1262
+ if labels is None and not is_torchdynamo_compiling():
1263
+ logger.warning_once(
1264
+ "Starting from v4.46, the `logits` model output will have the same type as the model (except at train time, where it will always be FP32)"
1265
+ )
1266
+ # Only compute necessary logits, and do not upcast them to float if we are not computing the loss
1267
+ # TODO: remove the float() operation in v4.46
1268
+ logits = self.lm_head(hidden_states[:, -num_logits_to_keep:, :]).float()
1269
+
1270
+ loss = None
1271
+ if labels is not None:
1272
+ # Upcast to float if we need to compute the loss to avoid potential precision issues
1273
+ logits = logits.float()
1274
+ # Shift so that tokens < n predict n
1275
+ shift_logits = logits[..., :-1, :].contiguous()
1276
+ shift_labels = labels[..., 1:].contiguous()
1277
+ # Flatten the tokens
1278
+ loss_fct = CrossEntropyLoss()
1279
+ shift_logits = shift_logits.view(-1, self.config.vocab_size)
1280
+ shift_labels = shift_labels.view(-1)
1281
+ # Enable model parallelism
1282
+ shift_labels = shift_labels.to(shift_logits.device)
1283
+ loss = loss_fct(shift_logits, shift_labels)
1284
+
1285
+ if not return_dict:
1286
+ output = (logits,) + outputs[1:]
1287
+ return (loss,) + output if loss is not None else output
1288
+
1289
+ return CausalLMOutputWithPast(
1290
+ loss=loss,
1291
+ logits=logits,
1292
+ past_key_values=outputs.past_key_values,
1293
+ hidden_states=outputs.hidden_states,
1294
+ attentions=outputs.attentions,
1295
+ )
1296
+
1297
+ # Copied from transformers.models.llama.modeling_llama.LlamaForCausalLM.prepare_inputs_for_generation
1298
+ def prepare_inputs_for_generation(
1299
+ self,
1300
+ input_ids,
1301
+ past_key_values=None,
1302
+ attention_mask=None,
1303
+ inputs_embeds=None,
1304
+ cache_position=None,
1305
+ position_ids=None,
1306
+ use_cache=True,
1307
+ num_logits_to_keep=0,
1308
+ **kwargs,
1309
+ ):
1310
+ # If we have cache: let's slice `input_ids` through `cache_position`, to keep only the unprocessed tokens
1311
+ # Exception 1: when passing input_embeds, input_ids may be missing entries
1312
+ # Exception 2: some generation methods do special slicing of input_ids, so we don't need to do it here
1313
+ if past_key_values is not None:
1314
+ if inputs_embeds is not None: # Exception 1
1315
+ input_ids = input_ids[:, -cache_position.shape[0] :]
1316
+ elif input_ids.shape[1] != cache_position.shape[0]: # Default case (the "else", a no op, is Exception 2)
1317
+ input_ids = input_ids[:, cache_position]
1318
+
1319
+ if attention_mask is not None and position_ids is None:
1320
+ # create position_ids on the fly for batch generation
1321
+ position_ids = attention_mask.long().cumsum(-1) - 1
1322
+ position_ids.masked_fill_(attention_mask == 0, 1)
1323
+ if past_key_values:
1324
+ position_ids = position_ids[:, -input_ids.shape[1] :]
1325
+
1326
+ # This `clone` call is needed to avoid recapturing cuda graphs with `torch.compile`'s `mode="reduce-overhead`, as otherwise the input `position_ids` would have various stride during the decoding. Here, simply using `.contiguous()` is not sufficient as in the batch size = 1 case, `position_ids` is already contiguous but with varying stride which retriggers a capture.
1327
+ position_ids = position_ids.clone(memory_format=torch.contiguous_format)
1328
+
1329
+ # if `inputs_embeds` are passed, we only want to use them in the 1st generation step
1330
+ if inputs_embeds is not None and cache_position[0] == 0:
1331
+ model_inputs = {"inputs_embeds": inputs_embeds, "input_ids": None}
1332
+ else:
1333
+ # The clone here is for the same reason as for `position_ids`.
1334
+ model_inputs = {"input_ids": input_ids.clone(memory_format=torch.contiguous_format), "inputs_embeds": None}
1335
+
1336
+ if isinstance(past_key_values, StaticCache) and attention_mask.ndim == 2:
1337
+ if model_inputs["inputs_embeds"] is not None:
1338
+ batch_size, sequence_length, _ = model_inputs["inputs_embeds"].shape
1339
+ device = model_inputs["inputs_embeds"].device
1340
+ else:
1341
+ batch_size, sequence_length = model_inputs["input_ids"].shape
1342
+ device = model_inputs["input_ids"].device
1343
+
1344
+ dtype = self.lm_head.weight.dtype
1345
+ min_dtype = torch.finfo(dtype).min
1346
+
1347
+ attention_mask = _prepare_4d_causal_attention_mask_with_cache_position(
1348
+ attention_mask,
1349
+ sequence_length=sequence_length,
1350
+ target_length=past_key_values.get_max_length(),
1351
+ dtype=dtype,
1352
+ device=device,
1353
+ min_dtype=min_dtype,
1354
+ cache_position=cache_position,
1355
+ batch_size=batch_size,
1356
+ )
1357
+
1358
+ model_inputs.update(
1359
+ {
1360
+ "position_ids": position_ids,
1361
+ "cache_position": cache_position,
1362
+ "past_key_values": past_key_values,
1363
+ "use_cache": use_cache,
1364
+ "attention_mask": attention_mask,
1365
+ "num_logits_to_keep": num_logits_to_keep,
1366
+ }
1367
+ )
1368
+ return model_inputs
1369
+
1370
+
1371
+ @add_start_docstrings(
1372
+ """
1373
+ The Qwen2 Model transformer with a sequence classification head on top (linear layer).
1374
+
1375
+ [`Qwen2ForSequenceClassification`] uses the last token in order to do the classification, as other causal models
1376
+ (e.g. GPT-2) do.
1377
+
1378
+ Since it does classification on the last token, it requires to know the position of the last token. If a
1379
+ `pad_token_id` is defined in the configuration, it finds the last token that is not a padding token in each row. If
1380
+ no `pad_token_id` is defined, it simply takes the last value in each row of the batch. Since it cannot guess the
1381
+ padding tokens when `inputs_embeds` are passed instead of `input_ids`, it does the same (take the last value in
1382
+ each row of the batch).
1383
+ """,
1384
+ QWEN2_START_DOCSTRING,
1385
+ )
1386
+ class Qwen2ForSequenceClassification(Qwen2PreTrainedModel):
1387
+ def __init__(self, config):
1388
+ super().__init__(config)
1389
+ self.num_labels = config.num_labels
1390
+ self.model = Qwen2Model(config)
1391
+ self.score = nn.Linear(config.hidden_size, self.num_labels, bias=False)
1392
+
1393
+ # Initialize weights and apply final processing
1394
+ self.post_init()
1395
+
1396
+ def get_input_embeddings(self):
1397
+ return self.model.embed_tokens
1398
+
1399
+ def set_input_embeddings(self, value):
1400
+ self.model.embed_tokens = value
1401
+
1402
+ @add_start_docstrings_to_model_forward(QWEN2_INPUTS_DOCSTRING)
1403
+ def forward(
1404
+ self,
1405
+ input_ids: torch.LongTensor = None,
1406
+ attention_mask: Optional[torch.Tensor] = None,
1407
+ position_ids: Optional[torch.LongTensor] = None,
1408
+ past_key_values: Optional[List[torch.FloatTensor]] = None,
1409
+ inputs_embeds: Optional[torch.FloatTensor] = None,
1410
+ labels: Optional[torch.LongTensor] = None,
1411
+ use_cache: Optional[bool] = None,
1412
+ output_attentions: Optional[bool] = None,
1413
+ output_hidden_states: Optional[bool] = None,
1414
+ return_dict: Optional[bool] = None,
1415
+ ) -> Union[Tuple, SequenceClassifierOutputWithPast]:
1416
+ r"""
1417
+ labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
1418
+ Labels for computing the sequence classification/regression loss. Indices should be in `[0, ...,
1419
+ config.num_labels - 1]`. If `config.num_labels == 1` a regression loss is computed (Mean-Square loss), If
1420
+ `config.num_labels > 1` a classification loss is computed (Cross-Entropy).
1421
+ """
1422
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
1423
+
1424
+ transformer_outputs = self.model(
1425
+ input_ids,
1426
+ attention_mask=attention_mask,
1427
+ position_ids=position_ids,
1428
+ past_key_values=past_key_values,
1429
+ inputs_embeds=inputs_embeds,
1430
+ use_cache=use_cache,
1431
+ output_attentions=output_attentions,
1432
+ output_hidden_states=output_hidden_states,
1433
+ return_dict=return_dict,
1434
+ )
1435
+ hidden_states = transformer_outputs[0]
1436
+ logits = self.score(hidden_states)
1437
+
1438
+ if input_ids is not None:
1439
+ batch_size = input_ids.shape[0]
1440
+ else:
1441
+ batch_size = inputs_embeds.shape[0]
1442
+
1443
+ if self.config.pad_token_id is None and batch_size != 1:
1444
+ raise ValueError("Cannot handle batch sizes > 1 if no padding token is defined.")
1445
+ if self.config.pad_token_id is None:
1446
+ sequence_lengths = -1
1447
+ else:
1448
+ if input_ids is not None:
1449
+ # if no pad token found, use modulo instead of reverse indexing for ONNX compatibility
1450
+ sequence_lengths = torch.eq(input_ids, self.config.pad_token_id).int().argmax(-1) - 1
1451
+ sequence_lengths = sequence_lengths % input_ids.shape[-1]
1452
+ sequence_lengths = sequence_lengths.to(logits.device)
1453
+ else:
1454
+ sequence_lengths = -1
1455
+
1456
+ pooled_logits = logits[torch.arange(batch_size, device=logits.device), sequence_lengths]
1457
+
1458
+ loss = None
1459
+ if labels is not None:
1460
+ labels = labels.to(logits.device)
1461
+ if self.config.problem_type is None:
1462
+ if self.num_labels == 1:
1463
+ self.config.problem_type = "regression"
1464
+ elif self.num_labels > 1 and (labels.dtype == torch.long or labels.dtype == torch.int):
1465
+ self.config.problem_type = "single_label_classification"
1466
+ else:
1467
+ self.config.problem_type = "multi_label_classification"
1468
+
1469
+ if self.config.problem_type == "regression":
1470
+ loss_fct = MSELoss()
1471
+ if self.num_labels == 1:
1472
+ loss = loss_fct(pooled_logits.squeeze(), labels.squeeze())
1473
+ else:
1474
+ loss = loss_fct(pooled_logits, labels)
1475
+ elif self.config.problem_type == "single_label_classification":
1476
+ loss_fct = CrossEntropyLoss()
1477
+ loss = loss_fct(pooled_logits.view(-1, self.num_labels), labels.view(-1))
1478
+ elif self.config.problem_type == "multi_label_classification":
1479
+ loss_fct = BCEWithLogitsLoss()
1480
+ loss = loss_fct(pooled_logits, labels)
1481
+ if not return_dict:
1482
+ output = (pooled_logits,) + transformer_outputs[1:]
1483
+ return ((loss,) + output) if loss is not None else output
1484
+
1485
+ return SequenceClassifierOutputWithPast(
1486
+ loss=loss,
1487
+ logits=pooled_logits,
1488
+ past_key_values=transformer_outputs.past_key_values,
1489
+ hidden_states=transformer_outputs.hidden_states,
1490
+ attentions=transformer_outputs.attentions,
1491
+ )
1492
+
1493
+
1494
+ @add_start_docstrings(
1495
+ """
1496
+ The Qwen2 Model transformer with a token classification head on top (a linear layer on top of the hidden-states
1497
+ output) e.g. for Named-Entity-Recognition (NER) tasks.
1498
+ """,
1499
+ QWEN2_START_DOCSTRING,
1500
+ )
1501
+ # Copied from transformers.models.llama.modeling_llama.LlamaForTokenClassification with Llama->Qwen2, LLAMA->QWEN2
1502
+ class Qwen2ForTokenClassification(Qwen2PreTrainedModel):
1503
+ def __init__(self, config):
1504
+ super().__init__(config)
1505
+ self.num_labels = config.num_labels
1506
+ self.model = Qwen2Model(config)
1507
+ if getattr(config, "classifier_dropout", None) is not None:
1508
+ classifier_dropout = config.classifier_dropout
1509
+ elif getattr(config, "hidden_dropout", None) is not None:
1510
+ classifier_dropout = config.hidden_dropout
1511
+ else:
1512
+ classifier_dropout = 0.1
1513
+ self.dropout = nn.Dropout(classifier_dropout)
1514
+ self.score = nn.Linear(config.hidden_size, config.num_labels)
1515
+
1516
+ # Initialize weights and apply final processing
1517
+ self.post_init()
1518
+
1519
+ def get_input_embeddings(self):
1520
+ return self.model.embed_tokens
1521
+
1522
+ def set_input_embeddings(self, value):
1523
+ self.model.embed_tokens = value
1524
+
1525
+ @add_start_docstrings_to_model_forward(QWEN2_INPUTS_DOCSTRING)
1526
+ def forward(
1527
+ self,
1528
+ input_ids: Optional[torch.LongTensor] = None,
1529
+ attention_mask: Optional[torch.Tensor] = None,
1530
+ position_ids: Optional[torch.LongTensor] = None,
1531
+ past_key_values: Optional[List[torch.FloatTensor]] = None,
1532
+ inputs_embeds: Optional[torch.FloatTensor] = None,
1533
+ labels: Optional[torch.LongTensor] = None,
1534
+ use_cache: Optional[bool] = None,
1535
+ output_attentions: Optional[bool] = None,
1536
+ output_hidden_states: Optional[bool] = None,
1537
+ return_dict: Optional[bool] = None,
1538
+ ) -> Union[Tuple, TokenClassifierOutput]:
1539
+ r"""
1540
+ labels (`torch.LongTensor` of shape `(batch_size,)`, *optional*):
1541
+ Labels for computing the sequence classification/regression loss. Indices should be in `[0, ...,
1542
+ config.num_labels - 1]`. If `config.num_labels == 1` a regression loss is computed (Mean-Square loss), If
1543
+ `config.num_labels > 1` a classification loss is computed (Cross-Entropy).
1544
+ """
1545
+ return_dict = return_dict if return_dict is not None else self.config.use_return_dict
1546
+
1547
+ outputs = self.model(
1548
+ input_ids,
1549
+ attention_mask=attention_mask,
1550
+ position_ids=position_ids,
1551
+ past_key_values=past_key_values,
1552
+ inputs_embeds=inputs_embeds,
1553
+ use_cache=use_cache,
1554
+ output_attentions=output_attentions,
1555
+ output_hidden_states=output_hidden_states,
1556
+ return_dict=return_dict,
1557
+ )
1558
+ sequence_output = outputs[0]
1559
+ sequence_output = self.dropout(sequence_output)
1560
+ logits = self.score(sequence_output)
1561
+
1562
+ loss = None
1563
+ if labels is not None:
1564
+ loss_fct = CrossEntropyLoss()
1565
+ loss = loss_fct(logits.view(-1, self.num_labels), labels.view(-1))
1566
+
1567
+ if not return_dict:
1568
+ output = (logits,) + outputs[2:]
1569
+ return ((loss,) + output) if loss is not None else output
1570
+
1571
+ return TokenClassifierOutput(
1572
+ loss=loss,
1573
+ logits=logits,
1574
+ hidden_states=outputs.hidden_states,
1575
+ attentions=outputs.attentions,
1576
+ )