mp commited on
Commit
dbcfe2a
1 Parent(s): fbc3e36

First commit updated Pharia4608 HF model

Browse files
config.json ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "LuminousForEmbedding"
4
+ ],
5
+ "attention_bias": true,
6
+ "attention_dropout": 0.0,
7
+ "attn_adapter_config": {
8
+ "hidden_act": "gelu",
9
+ "hidden_size": 4608,
10
+ "intermediate_size": 1152,
11
+ "mlp_bias": false
12
+ },
13
+ "bias_name": null,
14
+ "bos_token_id": 1,
15
+ "causal_attention": true,
16
+ "embedding_head_out": null,
17
+ "eos_token_id": 2,
18
+ "hidden_act": "gelu",
19
+ "hidden_size": 4608,
20
+ "initializer_range": 0.02,
21
+ "intermediate_size": 18432,
22
+ "layer_norm_epsilon": 1e-05,
23
+ "lora_config": null,
24
+ "max_position_embeddings": 8192,
25
+ "mlp_adapter_config": {
26
+ "hidden_act": "gelu",
27
+ "hidden_size": 4608,
28
+ "intermediate_size": 1152,
29
+ "mlp_bias": false
30
+ },
31
+ "mlp_bias": true,
32
+ "mode": "generation",
33
+ "num_attention_heads": 36,
34
+ "num_hidden_layers": 27,
35
+ "num_key_value_heads": 4,
36
+ "pooling_method": "weighted_mean",
37
+ "rope_scaling": null,
38
+ "rope_theta": 1000000,
39
+ "tie_word_embeddings": false,
40
+ "torch_dtype": "float32",
41
+ "transformers_version": "4.47.0",
42
+ "use_cache": false,
43
+ "vocab_size": 128000
44
+ }
model-00001-of-00006.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e221468da74e83e5f8b8a88f0101d237373d949009edecde8b41ec4d24356c90
3
+ size 4879558848
model-00002-of-00006.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8e48a659b2e4eea0459d0095958136500d7a0030013f9b897dab0572fafc7350
3
+ size 4766823592
model-00003-of-00006.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:500250d195e309256164997117539f3f95fb8f4361ea7c74b92feced8e8d02bd
3
+ size 4766823624
model-00004-of-00006.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9cfd39f1d07f69118eeb401130eac44ad20721a07c5fb8b59312b009c1e60cf2
3
+ size 4766823696
model-00005-of-00006.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d1079c6a1c337d790903e50857453b7a90803bfd8ea326d6d435bdd3aeb1b4c8
3
+ size 4766823696
model-00006-of-00006.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:171d11620c89b2350fec5df4cdd75d5479b1c3cc7e26e707e8526740c532f86d
3
+ size 4153327456
model.safetensors.index.json ADDED
@@ -0,0 +1,550 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "metadata": {
3
+ "total_size": 28100118528
4
+ },
5
+ "weight_map": {
6
+ "model.embed_tokens.weight": "model-00001-of-00006.safetensors",
7
+ "model.layers.0.input_layernorm.bias": "model-00001-of-00006.safetensors",
8
+ "model.layers.0.input_layernorm.weight": "model-00001-of-00006.safetensors",
9
+ "model.layers.0.mlp.down_proj.bias": "model-00001-of-00006.safetensors",
10
+ "model.layers.0.mlp.down_proj.weight": "model-00001-of-00006.safetensors",
11
+ "model.layers.0.mlp.up_proj.bias": "model-00001-of-00006.safetensors",
12
+ "model.layers.0.mlp.up_proj.weight": "model-00001-of-00006.safetensors",
13
+ "model.layers.0.post_attention_layernorm.bias": "model-00001-of-00006.safetensors",
14
+ "model.layers.0.post_attention_layernorm.weight": "model-00001-of-00006.safetensors",
15
+ "model.layers.0.post_attn_adapter.down_proj.weight": "model-00001-of-00006.safetensors",
16
+ "model.layers.0.post_attn_adapter.up_proj.weight": "model-00001-of-00006.safetensors",
17
+ "model.layers.0.post_mlp_adapter.down_proj.weight": "model-00001-of-00006.safetensors",
18
+ "model.layers.0.post_mlp_adapter.up_proj.weight": "model-00001-of-00006.safetensors",
19
+ "model.layers.0.self_attn.k_proj.bias": "model-00001-of-00006.safetensors",
20
+ "model.layers.0.self_attn.k_proj.weight": "model-00001-of-00006.safetensors",
21
+ "model.layers.0.self_attn.o_proj.bias": "model-00001-of-00006.safetensors",
22
+ "model.layers.0.self_attn.o_proj.weight": "model-00001-of-00006.safetensors",
23
+ "model.layers.0.self_attn.q_proj.bias": "model-00001-of-00006.safetensors",
24
+ "model.layers.0.self_attn.q_proj.weight": "model-00001-of-00006.safetensors",
25
+ "model.layers.0.self_attn.v_proj.bias": "model-00001-of-00006.safetensors",
26
+ "model.layers.0.self_attn.v_proj.weight": "model-00001-of-00006.safetensors",
27
+ "model.layers.1.input_layernorm.bias": "model-00001-of-00006.safetensors",
28
+ "model.layers.1.input_layernorm.weight": "model-00001-of-00006.safetensors",
29
+ "model.layers.1.mlp.down_proj.bias": "model-00001-of-00006.safetensors",
30
+ "model.layers.1.mlp.down_proj.weight": "model-00001-of-00006.safetensors",
31
+ "model.layers.1.mlp.up_proj.bias": "model-00001-of-00006.safetensors",
32
+ "model.layers.1.mlp.up_proj.weight": "model-00001-of-00006.safetensors",
33
+ "model.layers.1.post_attention_layernorm.bias": "model-00001-of-00006.safetensors",
34
+ "model.layers.1.post_attention_layernorm.weight": "model-00001-of-00006.safetensors",
35
+ "model.layers.1.post_attn_adapter.down_proj.weight": "model-00001-of-00006.safetensors",
36
+ "model.layers.1.post_attn_adapter.up_proj.weight": "model-00001-of-00006.safetensors",
37
+ "model.layers.1.post_mlp_adapter.down_proj.weight": "model-00001-of-00006.safetensors",
38
+ "model.layers.1.post_mlp_adapter.up_proj.weight": "model-00001-of-00006.safetensors",
39
+ "model.layers.1.self_attn.k_proj.bias": "model-00001-of-00006.safetensors",
40
+ "model.layers.1.self_attn.k_proj.weight": "model-00001-of-00006.safetensors",
41
+ "model.layers.1.self_attn.o_proj.bias": "model-00001-of-00006.safetensors",
42
+ "model.layers.1.self_attn.o_proj.weight": "model-00001-of-00006.safetensors",
43
+ "model.layers.1.self_attn.q_proj.bias": "model-00001-of-00006.safetensors",
44
+ "model.layers.1.self_attn.q_proj.weight": "model-00001-of-00006.safetensors",
45
+ "model.layers.1.self_attn.v_proj.bias": "model-00001-of-00006.safetensors",
46
+ "model.layers.1.self_attn.v_proj.weight": "model-00001-of-00006.safetensors",
47
+ "model.layers.10.input_layernorm.bias": "model-00003-of-00006.safetensors",
48
+ "model.layers.10.input_layernorm.weight": "model-00003-of-00006.safetensors",
49
+ "model.layers.10.mlp.down_proj.bias": "model-00003-of-00006.safetensors",
50
+ "model.layers.10.mlp.down_proj.weight": "model-00003-of-00006.safetensors",
51
+ "model.layers.10.mlp.up_proj.bias": "model-00003-of-00006.safetensors",
52
+ "model.layers.10.mlp.up_proj.weight": "model-00003-of-00006.safetensors",
53
+ "model.layers.10.post_attention_layernorm.bias": "model-00003-of-00006.safetensors",
54
+ "model.layers.10.post_attention_layernorm.weight": "model-00003-of-00006.safetensors",
55
+ "model.layers.10.post_attn_adapter.down_proj.weight": "model-00003-of-00006.safetensors",
56
+ "model.layers.10.post_attn_adapter.up_proj.weight": "model-00003-of-00006.safetensors",
57
+ "model.layers.10.post_mlp_adapter.down_proj.weight": "model-00003-of-00006.safetensors",
58
+ "model.layers.10.post_mlp_adapter.up_proj.weight": "model-00003-of-00006.safetensors",
59
+ "model.layers.10.self_attn.k_proj.bias": "model-00003-of-00006.safetensors",
60
+ "model.layers.10.self_attn.k_proj.weight": "model-00003-of-00006.safetensors",
61
+ "model.layers.10.self_attn.o_proj.bias": "model-00003-of-00006.safetensors",
62
+ "model.layers.10.self_attn.o_proj.weight": "model-00003-of-00006.safetensors",
63
+ "model.layers.10.self_attn.q_proj.bias": "model-00003-of-00006.safetensors",
64
+ "model.layers.10.self_attn.q_proj.weight": "model-00003-of-00006.safetensors",
65
+ "model.layers.10.self_attn.v_proj.bias": "model-00003-of-00006.safetensors",
66
+ "model.layers.10.self_attn.v_proj.weight": "model-00003-of-00006.safetensors",
67
+ "model.layers.11.input_layernorm.bias": "model-00003-of-00006.safetensors",
68
+ "model.layers.11.input_layernorm.weight": "model-00003-of-00006.safetensors",
69
+ "model.layers.11.mlp.down_proj.bias": "model-00003-of-00006.safetensors",
70
+ "model.layers.11.mlp.down_proj.weight": "model-00003-of-00006.safetensors",
71
+ "model.layers.11.mlp.up_proj.bias": "model-00003-of-00006.safetensors",
72
+ "model.layers.11.mlp.up_proj.weight": "model-00003-of-00006.safetensors",
73
+ "model.layers.11.post_attention_layernorm.bias": "model-00003-of-00006.safetensors",
74
+ "model.layers.11.post_attention_layernorm.weight": "model-00003-of-00006.safetensors",
75
+ "model.layers.11.post_attn_adapter.down_proj.weight": "model-00003-of-00006.safetensors",
76
+ "model.layers.11.post_attn_adapter.up_proj.weight": "model-00003-of-00006.safetensors",
77
+ "model.layers.11.post_mlp_adapter.down_proj.weight": "model-00003-of-00006.safetensors",
78
+ "model.layers.11.post_mlp_adapter.up_proj.weight": "model-00003-of-00006.safetensors",
79
+ "model.layers.11.self_attn.k_proj.bias": "model-00003-of-00006.safetensors",
80
+ "model.layers.11.self_attn.k_proj.weight": "model-00003-of-00006.safetensors",
81
+ "model.layers.11.self_attn.o_proj.bias": "model-00003-of-00006.safetensors",
82
+ "model.layers.11.self_attn.o_proj.weight": "model-00003-of-00006.safetensors",
83
+ "model.layers.11.self_attn.q_proj.bias": "model-00003-of-00006.safetensors",
84
+ "model.layers.11.self_attn.q_proj.weight": "model-00003-of-00006.safetensors",
85
+ "model.layers.11.self_attn.v_proj.bias": "model-00003-of-00006.safetensors",
86
+ "model.layers.11.self_attn.v_proj.weight": "model-00003-of-00006.safetensors",
87
+ "model.layers.12.input_layernorm.bias": "model-00004-of-00006.safetensors",
88
+ "model.layers.12.input_layernorm.weight": "model-00004-of-00006.safetensors",
89
+ "model.layers.12.mlp.down_proj.bias": "model-00004-of-00006.safetensors",
90
+ "model.layers.12.mlp.down_proj.weight": "model-00004-of-00006.safetensors",
91
+ "model.layers.12.mlp.up_proj.bias": "model-00003-of-00006.safetensors",
92
+ "model.layers.12.mlp.up_proj.weight": "model-00003-of-00006.safetensors",
93
+ "model.layers.12.post_attention_layernorm.bias": "model-00004-of-00006.safetensors",
94
+ "model.layers.12.post_attention_layernorm.weight": "model-00004-of-00006.safetensors",
95
+ "model.layers.12.post_attn_adapter.down_proj.weight": "model-00003-of-00006.safetensors",
96
+ "model.layers.12.post_attn_adapter.up_proj.weight": "model-00003-of-00006.safetensors",
97
+ "model.layers.12.post_mlp_adapter.down_proj.weight": "model-00003-of-00006.safetensors",
98
+ "model.layers.12.post_mlp_adapter.up_proj.weight": "model-00003-of-00006.safetensors",
99
+ "model.layers.12.self_attn.k_proj.bias": "model-00003-of-00006.safetensors",
100
+ "model.layers.12.self_attn.k_proj.weight": "model-00003-of-00006.safetensors",
101
+ "model.layers.12.self_attn.o_proj.bias": "model-00003-of-00006.safetensors",
102
+ "model.layers.12.self_attn.o_proj.weight": "model-00003-of-00006.safetensors",
103
+ "model.layers.12.self_attn.q_proj.bias": "model-00003-of-00006.safetensors",
104
+ "model.layers.12.self_attn.q_proj.weight": "model-00003-of-00006.safetensors",
105
+ "model.layers.12.self_attn.v_proj.bias": "model-00003-of-00006.safetensors",
106
+ "model.layers.12.self_attn.v_proj.weight": "model-00003-of-00006.safetensors",
107
+ "model.layers.13.input_layernorm.bias": "model-00004-of-00006.safetensors",
108
+ "model.layers.13.input_layernorm.weight": "model-00004-of-00006.safetensors",
109
+ "model.layers.13.mlp.down_proj.bias": "model-00004-of-00006.safetensors",
110
+ "model.layers.13.mlp.down_proj.weight": "model-00004-of-00006.safetensors",
111
+ "model.layers.13.mlp.up_proj.bias": "model-00004-of-00006.safetensors",
112
+ "model.layers.13.mlp.up_proj.weight": "model-00004-of-00006.safetensors",
113
+ "model.layers.13.post_attention_layernorm.bias": "model-00004-of-00006.safetensors",
114
+ "model.layers.13.post_attention_layernorm.weight": "model-00004-of-00006.safetensors",
115
+ "model.layers.13.post_attn_adapter.down_proj.weight": "model-00004-of-00006.safetensors",
116
+ "model.layers.13.post_attn_adapter.up_proj.weight": "model-00004-of-00006.safetensors",
117
+ "model.layers.13.post_mlp_adapter.down_proj.weight": "model-00004-of-00006.safetensors",
118
+ "model.layers.13.post_mlp_adapter.up_proj.weight": "model-00004-of-00006.safetensors",
119
+ "model.layers.13.self_attn.k_proj.bias": "model-00004-of-00006.safetensors",
120
+ "model.layers.13.self_attn.k_proj.weight": "model-00004-of-00006.safetensors",
121
+ "model.layers.13.self_attn.o_proj.bias": "model-00004-of-00006.safetensors",
122
+ "model.layers.13.self_attn.o_proj.weight": "model-00004-of-00006.safetensors",
123
+ "model.layers.13.self_attn.q_proj.bias": "model-00004-of-00006.safetensors",
124
+ "model.layers.13.self_attn.q_proj.weight": "model-00004-of-00006.safetensors",
125
+ "model.layers.13.self_attn.v_proj.bias": "model-00004-of-00006.safetensors",
126
+ "model.layers.13.self_attn.v_proj.weight": "model-00004-of-00006.safetensors",
127
+ "model.layers.14.input_layernorm.bias": "model-00004-of-00006.safetensors",
128
+ "model.layers.14.input_layernorm.weight": "model-00004-of-00006.safetensors",
129
+ "model.layers.14.mlp.down_proj.bias": "model-00004-of-00006.safetensors",
130
+ "model.layers.14.mlp.down_proj.weight": "model-00004-of-00006.safetensors",
131
+ "model.layers.14.mlp.up_proj.bias": "model-00004-of-00006.safetensors",
132
+ "model.layers.14.mlp.up_proj.weight": "model-00004-of-00006.safetensors",
133
+ "model.layers.14.post_attention_layernorm.bias": "model-00004-of-00006.safetensors",
134
+ "model.layers.14.post_attention_layernorm.weight": "model-00004-of-00006.safetensors",
135
+ "model.layers.14.post_attn_adapter.down_proj.weight": "model-00004-of-00006.safetensors",
136
+ "model.layers.14.post_attn_adapter.up_proj.weight": "model-00004-of-00006.safetensors",
137
+ "model.layers.14.post_mlp_adapter.down_proj.weight": "model-00004-of-00006.safetensors",
138
+ "model.layers.14.post_mlp_adapter.up_proj.weight": "model-00004-of-00006.safetensors",
139
+ "model.layers.14.self_attn.k_proj.bias": "model-00004-of-00006.safetensors",
140
+ "model.layers.14.self_attn.k_proj.weight": "model-00004-of-00006.safetensors",
141
+ "model.layers.14.self_attn.o_proj.bias": "model-00004-of-00006.safetensors",
142
+ "model.layers.14.self_attn.o_proj.weight": "model-00004-of-00006.safetensors",
143
+ "model.layers.14.self_attn.q_proj.bias": "model-00004-of-00006.safetensors",
144
+ "model.layers.14.self_attn.q_proj.weight": "model-00004-of-00006.safetensors",
145
+ "model.layers.14.self_attn.v_proj.bias": "model-00004-of-00006.safetensors",
146
+ "model.layers.14.self_attn.v_proj.weight": "model-00004-of-00006.safetensors",
147
+ "model.layers.15.input_layernorm.bias": "model-00004-of-00006.safetensors",
148
+ "model.layers.15.input_layernorm.weight": "model-00004-of-00006.safetensors",
149
+ "model.layers.15.mlp.down_proj.bias": "model-00004-of-00006.safetensors",
150
+ "model.layers.15.mlp.down_proj.weight": "model-00004-of-00006.safetensors",
151
+ "model.layers.15.mlp.up_proj.bias": "model-00004-of-00006.safetensors",
152
+ "model.layers.15.mlp.up_proj.weight": "model-00004-of-00006.safetensors",
153
+ "model.layers.15.post_attention_layernorm.bias": "model-00004-of-00006.safetensors",
154
+ "model.layers.15.post_attention_layernorm.weight": "model-00004-of-00006.safetensors",
155
+ "model.layers.15.post_attn_adapter.down_proj.weight": "model-00004-of-00006.safetensors",
156
+ "model.layers.15.post_attn_adapter.up_proj.weight": "model-00004-of-00006.safetensors",
157
+ "model.layers.15.post_mlp_adapter.down_proj.weight": "model-00004-of-00006.safetensors",
158
+ "model.layers.15.post_mlp_adapter.up_proj.weight": "model-00004-of-00006.safetensors",
159
+ "model.layers.15.self_attn.k_proj.bias": "model-00004-of-00006.safetensors",
160
+ "model.layers.15.self_attn.k_proj.weight": "model-00004-of-00006.safetensors",
161
+ "model.layers.15.self_attn.o_proj.bias": "model-00004-of-00006.safetensors",
162
+ "model.layers.15.self_attn.o_proj.weight": "model-00004-of-00006.safetensors",
163
+ "model.layers.15.self_attn.q_proj.bias": "model-00004-of-00006.safetensors",
164
+ "model.layers.15.self_attn.q_proj.weight": "model-00004-of-00006.safetensors",
165
+ "model.layers.15.self_attn.v_proj.bias": "model-00004-of-00006.safetensors",
166
+ "model.layers.15.self_attn.v_proj.weight": "model-00004-of-00006.safetensors",
167
+ "model.layers.16.input_layernorm.bias": "model-00004-of-00006.safetensors",
168
+ "model.layers.16.input_layernorm.weight": "model-00004-of-00006.safetensors",
169
+ "model.layers.16.mlp.down_proj.bias": "model-00004-of-00006.safetensors",
170
+ "model.layers.16.mlp.down_proj.weight": "model-00004-of-00006.safetensors",
171
+ "model.layers.16.mlp.up_proj.bias": "model-00004-of-00006.safetensors",
172
+ "model.layers.16.mlp.up_proj.weight": "model-00004-of-00006.safetensors",
173
+ "model.layers.16.post_attention_layernorm.bias": "model-00004-of-00006.safetensors",
174
+ "model.layers.16.post_attention_layernorm.weight": "model-00004-of-00006.safetensors",
175
+ "model.layers.16.post_attn_adapter.down_proj.weight": "model-00004-of-00006.safetensors",
176
+ "model.layers.16.post_attn_adapter.up_proj.weight": "model-00004-of-00006.safetensors",
177
+ "model.layers.16.post_mlp_adapter.down_proj.weight": "model-00004-of-00006.safetensors",
178
+ "model.layers.16.post_mlp_adapter.up_proj.weight": "model-00004-of-00006.safetensors",
179
+ "model.layers.16.self_attn.k_proj.bias": "model-00004-of-00006.safetensors",
180
+ "model.layers.16.self_attn.k_proj.weight": "model-00004-of-00006.safetensors",
181
+ "model.layers.16.self_attn.o_proj.bias": "model-00004-of-00006.safetensors",
182
+ "model.layers.16.self_attn.o_proj.weight": "model-00004-of-00006.safetensors",
183
+ "model.layers.16.self_attn.q_proj.bias": "model-00004-of-00006.safetensors",
184
+ "model.layers.16.self_attn.q_proj.weight": "model-00004-of-00006.safetensors",
185
+ "model.layers.16.self_attn.v_proj.bias": "model-00004-of-00006.safetensors",
186
+ "model.layers.16.self_attn.v_proj.weight": "model-00004-of-00006.safetensors",
187
+ "model.layers.17.input_layernorm.bias": "model-00005-of-00006.safetensors",
188
+ "model.layers.17.input_layernorm.weight": "model-00005-of-00006.safetensors",
189
+ "model.layers.17.mlp.down_proj.bias": "model-00005-of-00006.safetensors",
190
+ "model.layers.17.mlp.down_proj.weight": "model-00005-of-00006.safetensors",
191
+ "model.layers.17.mlp.up_proj.bias": "model-00004-of-00006.safetensors",
192
+ "model.layers.17.mlp.up_proj.weight": "model-00004-of-00006.safetensors",
193
+ "model.layers.17.post_attention_layernorm.bias": "model-00005-of-00006.safetensors",
194
+ "model.layers.17.post_attention_layernorm.weight": "model-00005-of-00006.safetensors",
195
+ "model.layers.17.post_attn_adapter.down_proj.weight": "model-00004-of-00006.safetensors",
196
+ "model.layers.17.post_attn_adapter.up_proj.weight": "model-00004-of-00006.safetensors",
197
+ "model.layers.17.post_mlp_adapter.down_proj.weight": "model-00004-of-00006.safetensors",
198
+ "model.layers.17.post_mlp_adapter.up_proj.weight": "model-00004-of-00006.safetensors",
199
+ "model.layers.17.self_attn.k_proj.bias": "model-00004-of-00006.safetensors",
200
+ "model.layers.17.self_attn.k_proj.weight": "model-00004-of-00006.safetensors",
201
+ "model.layers.17.self_attn.o_proj.bias": "model-00004-of-00006.safetensors",
202
+ "model.layers.17.self_attn.o_proj.weight": "model-00004-of-00006.safetensors",
203
+ "model.layers.17.self_attn.q_proj.bias": "model-00004-of-00006.safetensors",
204
+ "model.layers.17.self_attn.q_proj.weight": "model-00004-of-00006.safetensors",
205
+ "model.layers.17.self_attn.v_proj.bias": "model-00004-of-00006.safetensors",
206
+ "model.layers.17.self_attn.v_proj.weight": "model-00004-of-00006.safetensors",
207
+ "model.layers.18.input_layernorm.bias": "model-00005-of-00006.safetensors",
208
+ "model.layers.18.input_layernorm.weight": "model-00005-of-00006.safetensors",
209
+ "model.layers.18.mlp.down_proj.bias": "model-00005-of-00006.safetensors",
210
+ "model.layers.18.mlp.down_proj.weight": "model-00005-of-00006.safetensors",
211
+ "model.layers.18.mlp.up_proj.bias": "model-00005-of-00006.safetensors",
212
+ "model.layers.18.mlp.up_proj.weight": "model-00005-of-00006.safetensors",
213
+ "model.layers.18.post_attention_layernorm.bias": "model-00005-of-00006.safetensors",
214
+ "model.layers.18.post_attention_layernorm.weight": "model-00005-of-00006.safetensors",
215
+ "model.layers.18.post_attn_adapter.down_proj.weight": "model-00005-of-00006.safetensors",
216
+ "model.layers.18.post_attn_adapter.up_proj.weight": "model-00005-of-00006.safetensors",
217
+ "model.layers.18.post_mlp_adapter.down_proj.weight": "model-00005-of-00006.safetensors",
218
+ "model.layers.18.post_mlp_adapter.up_proj.weight": "model-00005-of-00006.safetensors",
219
+ "model.layers.18.self_attn.k_proj.bias": "model-00005-of-00006.safetensors",
220
+ "model.layers.18.self_attn.k_proj.weight": "model-00005-of-00006.safetensors",
221
+ "model.layers.18.self_attn.o_proj.bias": "model-00005-of-00006.safetensors",
222
+ "model.layers.18.self_attn.o_proj.weight": "model-00005-of-00006.safetensors",
223
+ "model.layers.18.self_attn.q_proj.bias": "model-00005-of-00006.safetensors",
224
+ "model.layers.18.self_attn.q_proj.weight": "model-00005-of-00006.safetensors",
225
+ "model.layers.18.self_attn.v_proj.bias": "model-00005-of-00006.safetensors",
226
+ "model.layers.18.self_attn.v_proj.weight": "model-00005-of-00006.safetensors",
227
+ "model.layers.19.input_layernorm.bias": "model-00005-of-00006.safetensors",
228
+ "model.layers.19.input_layernorm.weight": "model-00005-of-00006.safetensors",
229
+ "model.layers.19.mlp.down_proj.bias": "model-00005-of-00006.safetensors",
230
+ "model.layers.19.mlp.down_proj.weight": "model-00005-of-00006.safetensors",
231
+ "model.layers.19.mlp.up_proj.bias": "model-00005-of-00006.safetensors",
232
+ "model.layers.19.mlp.up_proj.weight": "model-00005-of-00006.safetensors",
233
+ "model.layers.19.post_attention_layernorm.bias": "model-00005-of-00006.safetensors",
234
+ "model.layers.19.post_attention_layernorm.weight": "model-00005-of-00006.safetensors",
235
+ "model.layers.19.post_attn_adapter.down_proj.weight": "model-00005-of-00006.safetensors",
236
+ "model.layers.19.post_attn_adapter.up_proj.weight": "model-00005-of-00006.safetensors",
237
+ "model.layers.19.post_mlp_adapter.down_proj.weight": "model-00005-of-00006.safetensors",
238
+ "model.layers.19.post_mlp_adapter.up_proj.weight": "model-00005-of-00006.safetensors",
239
+ "model.layers.19.self_attn.k_proj.bias": "model-00005-of-00006.safetensors",
240
+ "model.layers.19.self_attn.k_proj.weight": "model-00005-of-00006.safetensors",
241
+ "model.layers.19.self_attn.o_proj.bias": "model-00005-of-00006.safetensors",
242
+ "model.layers.19.self_attn.o_proj.weight": "model-00005-of-00006.safetensors",
243
+ "model.layers.19.self_attn.q_proj.bias": "model-00005-of-00006.safetensors",
244
+ "model.layers.19.self_attn.q_proj.weight": "model-00005-of-00006.safetensors",
245
+ "model.layers.19.self_attn.v_proj.bias": "model-00005-of-00006.safetensors",
246
+ "model.layers.19.self_attn.v_proj.weight": "model-00005-of-00006.safetensors",
247
+ "model.layers.2.input_layernorm.bias": "model-00002-of-00006.safetensors",
248
+ "model.layers.2.input_layernorm.weight": "model-00002-of-00006.safetensors",
249
+ "model.layers.2.mlp.down_proj.bias": "model-00002-of-00006.safetensors",
250
+ "model.layers.2.mlp.down_proj.weight": "model-00002-of-00006.safetensors",
251
+ "model.layers.2.mlp.up_proj.bias": "model-00001-of-00006.safetensors",
252
+ "model.layers.2.mlp.up_proj.weight": "model-00001-of-00006.safetensors",
253
+ "model.layers.2.post_attention_layernorm.bias": "model-00002-of-00006.safetensors",
254
+ "model.layers.2.post_attention_layernorm.weight": "model-00002-of-00006.safetensors",
255
+ "model.layers.2.post_attn_adapter.down_proj.weight": "model-00001-of-00006.safetensors",
256
+ "model.layers.2.post_attn_adapter.up_proj.weight": "model-00001-of-00006.safetensors",
257
+ "model.layers.2.post_mlp_adapter.down_proj.weight": "model-00001-of-00006.safetensors",
258
+ "model.layers.2.post_mlp_adapter.up_proj.weight": "model-00001-of-00006.safetensors",
259
+ "model.layers.2.self_attn.k_proj.bias": "model-00001-of-00006.safetensors",
260
+ "model.layers.2.self_attn.k_proj.weight": "model-00001-of-00006.safetensors",
261
+ "model.layers.2.self_attn.o_proj.bias": "model-00001-of-00006.safetensors",
262
+ "model.layers.2.self_attn.o_proj.weight": "model-00001-of-00006.safetensors",
263
+ "model.layers.2.self_attn.q_proj.bias": "model-00001-of-00006.safetensors",
264
+ "model.layers.2.self_attn.q_proj.weight": "model-00001-of-00006.safetensors",
265
+ "model.layers.2.self_attn.v_proj.bias": "model-00001-of-00006.safetensors",
266
+ "model.layers.2.self_attn.v_proj.weight": "model-00001-of-00006.safetensors",
267
+ "model.layers.20.input_layernorm.bias": "model-00005-of-00006.safetensors",
268
+ "model.layers.20.input_layernorm.weight": "model-00005-of-00006.safetensors",
269
+ "model.layers.20.mlp.down_proj.bias": "model-00005-of-00006.safetensors",
270
+ "model.layers.20.mlp.down_proj.weight": "model-00005-of-00006.safetensors",
271
+ "model.layers.20.mlp.up_proj.bias": "model-00005-of-00006.safetensors",
272
+ "model.layers.20.mlp.up_proj.weight": "model-00005-of-00006.safetensors",
273
+ "model.layers.20.post_attention_layernorm.bias": "model-00005-of-00006.safetensors",
274
+ "model.layers.20.post_attention_layernorm.weight": "model-00005-of-00006.safetensors",
275
+ "model.layers.20.post_attn_adapter.down_proj.weight": "model-00005-of-00006.safetensors",
276
+ "model.layers.20.post_attn_adapter.up_proj.weight": "model-00005-of-00006.safetensors",
277
+ "model.layers.20.post_mlp_adapter.down_proj.weight": "model-00005-of-00006.safetensors",
278
+ "model.layers.20.post_mlp_adapter.up_proj.weight": "model-00005-of-00006.safetensors",
279
+ "model.layers.20.self_attn.k_proj.bias": "model-00005-of-00006.safetensors",
280
+ "model.layers.20.self_attn.k_proj.weight": "model-00005-of-00006.safetensors",
281
+ "model.layers.20.self_attn.o_proj.bias": "model-00005-of-00006.safetensors",
282
+ "model.layers.20.self_attn.o_proj.weight": "model-00005-of-00006.safetensors",
283
+ "model.layers.20.self_attn.q_proj.bias": "model-00005-of-00006.safetensors",
284
+ "model.layers.20.self_attn.q_proj.weight": "model-00005-of-00006.safetensors",
285
+ "model.layers.20.self_attn.v_proj.bias": "model-00005-of-00006.safetensors",
286
+ "model.layers.20.self_attn.v_proj.weight": "model-00005-of-00006.safetensors",
287
+ "model.layers.21.input_layernorm.bias": "model-00005-of-00006.safetensors",
288
+ "model.layers.21.input_layernorm.weight": "model-00005-of-00006.safetensors",
289
+ "model.layers.21.mlp.down_proj.bias": "model-00005-of-00006.safetensors",
290
+ "model.layers.21.mlp.down_proj.weight": "model-00005-of-00006.safetensors",
291
+ "model.layers.21.mlp.up_proj.bias": "model-00005-of-00006.safetensors",
292
+ "model.layers.21.mlp.up_proj.weight": "model-00005-of-00006.safetensors",
293
+ "model.layers.21.post_attention_layernorm.bias": "model-00005-of-00006.safetensors",
294
+ "model.layers.21.post_attention_layernorm.weight": "model-00005-of-00006.safetensors",
295
+ "model.layers.21.post_attn_adapter.down_proj.weight": "model-00005-of-00006.safetensors",
296
+ "model.layers.21.post_attn_adapter.up_proj.weight": "model-00005-of-00006.safetensors",
297
+ "model.layers.21.post_mlp_adapter.down_proj.weight": "model-00005-of-00006.safetensors",
298
+ "model.layers.21.post_mlp_adapter.up_proj.weight": "model-00005-of-00006.safetensors",
299
+ "model.layers.21.self_attn.k_proj.bias": "model-00005-of-00006.safetensors",
300
+ "model.layers.21.self_attn.k_proj.weight": "model-00005-of-00006.safetensors",
301
+ "model.layers.21.self_attn.o_proj.bias": "model-00005-of-00006.safetensors",
302
+ "model.layers.21.self_attn.o_proj.weight": "model-00005-of-00006.safetensors",
303
+ "model.layers.21.self_attn.q_proj.bias": "model-00005-of-00006.safetensors",
304
+ "model.layers.21.self_attn.q_proj.weight": "model-00005-of-00006.safetensors",
305
+ "model.layers.21.self_attn.v_proj.bias": "model-00005-of-00006.safetensors",
306
+ "model.layers.21.self_attn.v_proj.weight": "model-00005-of-00006.safetensors",
307
+ "model.layers.22.input_layernorm.bias": "model-00006-of-00006.safetensors",
308
+ "model.layers.22.input_layernorm.weight": "model-00006-of-00006.safetensors",
309
+ "model.layers.22.mlp.down_proj.bias": "model-00006-of-00006.safetensors",
310
+ "model.layers.22.mlp.down_proj.weight": "model-00006-of-00006.safetensors",
311
+ "model.layers.22.mlp.up_proj.bias": "model-00005-of-00006.safetensors",
312
+ "model.layers.22.mlp.up_proj.weight": "model-00005-of-00006.safetensors",
313
+ "model.layers.22.post_attention_layernorm.bias": "model-00006-of-00006.safetensors",
314
+ "model.layers.22.post_attention_layernorm.weight": "model-00006-of-00006.safetensors",
315
+ "model.layers.22.post_attn_adapter.down_proj.weight": "model-00005-of-00006.safetensors",
316
+ "model.layers.22.post_attn_adapter.up_proj.weight": "model-00005-of-00006.safetensors",
317
+ "model.layers.22.post_mlp_adapter.down_proj.weight": "model-00005-of-00006.safetensors",
318
+ "model.layers.22.post_mlp_adapter.up_proj.weight": "model-00005-of-00006.safetensors",
319
+ "model.layers.22.self_attn.k_proj.bias": "model-00005-of-00006.safetensors",
320
+ "model.layers.22.self_attn.k_proj.weight": "model-00005-of-00006.safetensors",
321
+ "model.layers.22.self_attn.o_proj.bias": "model-00005-of-00006.safetensors",
322
+ "model.layers.22.self_attn.o_proj.weight": "model-00005-of-00006.safetensors",
323
+ "model.layers.22.self_attn.q_proj.bias": "model-00005-of-00006.safetensors",
324
+ "model.layers.22.self_attn.q_proj.weight": "model-00005-of-00006.safetensors",
325
+ "model.layers.22.self_attn.v_proj.bias": "model-00005-of-00006.safetensors",
326
+ "model.layers.22.self_attn.v_proj.weight": "model-00005-of-00006.safetensors",
327
+ "model.layers.23.input_layernorm.bias": "model-00006-of-00006.safetensors",
328
+ "model.layers.23.input_layernorm.weight": "model-00006-of-00006.safetensors",
329
+ "model.layers.23.mlp.down_proj.bias": "model-00006-of-00006.safetensors",
330
+ "model.layers.23.mlp.down_proj.weight": "model-00006-of-00006.safetensors",
331
+ "model.layers.23.mlp.up_proj.bias": "model-00006-of-00006.safetensors",
332
+ "model.layers.23.mlp.up_proj.weight": "model-00006-of-00006.safetensors",
333
+ "model.layers.23.post_attention_layernorm.bias": "model-00006-of-00006.safetensors",
334
+ "model.layers.23.post_attention_layernorm.weight": "model-00006-of-00006.safetensors",
335
+ "model.layers.23.post_attn_adapter.down_proj.weight": "model-00006-of-00006.safetensors",
336
+ "model.layers.23.post_attn_adapter.up_proj.weight": "model-00006-of-00006.safetensors",
337
+ "model.layers.23.post_mlp_adapter.down_proj.weight": "model-00006-of-00006.safetensors",
338
+ "model.layers.23.post_mlp_adapter.up_proj.weight": "model-00006-of-00006.safetensors",
339
+ "model.layers.23.self_attn.k_proj.bias": "model-00006-of-00006.safetensors",
340
+ "model.layers.23.self_attn.k_proj.weight": "model-00006-of-00006.safetensors",
341
+ "model.layers.23.self_attn.o_proj.bias": "model-00006-of-00006.safetensors",
342
+ "model.layers.23.self_attn.o_proj.weight": "model-00006-of-00006.safetensors",
343
+ "model.layers.23.self_attn.q_proj.bias": "model-00006-of-00006.safetensors",
344
+ "model.layers.23.self_attn.q_proj.weight": "model-00006-of-00006.safetensors",
345
+ "model.layers.23.self_attn.v_proj.bias": "model-00006-of-00006.safetensors",
346
+ "model.layers.23.self_attn.v_proj.weight": "model-00006-of-00006.safetensors",
347
+ "model.layers.24.input_layernorm.bias": "model-00006-of-00006.safetensors",
348
+ "model.layers.24.input_layernorm.weight": "model-00006-of-00006.safetensors",
349
+ "model.layers.24.mlp.down_proj.bias": "model-00006-of-00006.safetensors",
350
+ "model.layers.24.mlp.down_proj.weight": "model-00006-of-00006.safetensors",
351
+ "model.layers.24.mlp.up_proj.bias": "model-00006-of-00006.safetensors",
352
+ "model.layers.24.mlp.up_proj.weight": "model-00006-of-00006.safetensors",
353
+ "model.layers.24.post_attention_layernorm.bias": "model-00006-of-00006.safetensors",
354
+ "model.layers.24.post_attention_layernorm.weight": "model-00006-of-00006.safetensors",
355
+ "model.layers.24.post_attn_adapter.down_proj.weight": "model-00006-of-00006.safetensors",
356
+ "model.layers.24.post_attn_adapter.up_proj.weight": "model-00006-of-00006.safetensors",
357
+ "model.layers.24.post_mlp_adapter.down_proj.weight": "model-00006-of-00006.safetensors",
358
+ "model.layers.24.post_mlp_adapter.up_proj.weight": "model-00006-of-00006.safetensors",
359
+ "model.layers.24.self_attn.k_proj.bias": "model-00006-of-00006.safetensors",
360
+ "model.layers.24.self_attn.k_proj.weight": "model-00006-of-00006.safetensors",
361
+ "model.layers.24.self_attn.o_proj.bias": "model-00006-of-00006.safetensors",
362
+ "model.layers.24.self_attn.o_proj.weight": "model-00006-of-00006.safetensors",
363
+ "model.layers.24.self_attn.q_proj.bias": "model-00006-of-00006.safetensors",
364
+ "model.layers.24.self_attn.q_proj.weight": "model-00006-of-00006.safetensors",
365
+ "model.layers.24.self_attn.v_proj.bias": "model-00006-of-00006.safetensors",
366
+ "model.layers.24.self_attn.v_proj.weight": "model-00006-of-00006.safetensors",
367
+ "model.layers.25.input_layernorm.bias": "model-00006-of-00006.safetensors",
368
+ "model.layers.25.input_layernorm.weight": "model-00006-of-00006.safetensors",
369
+ "model.layers.25.mlp.down_proj.bias": "model-00006-of-00006.safetensors",
370
+ "model.layers.25.mlp.down_proj.weight": "model-00006-of-00006.safetensors",
371
+ "model.layers.25.mlp.up_proj.bias": "model-00006-of-00006.safetensors",
372
+ "model.layers.25.mlp.up_proj.weight": "model-00006-of-00006.safetensors",
373
+ "model.layers.25.post_attention_layernorm.bias": "model-00006-of-00006.safetensors",
374
+ "model.layers.25.post_attention_layernorm.weight": "model-00006-of-00006.safetensors",
375
+ "model.layers.25.post_attn_adapter.down_proj.weight": "model-00006-of-00006.safetensors",
376
+ "model.layers.25.post_attn_adapter.up_proj.weight": "model-00006-of-00006.safetensors",
377
+ "model.layers.25.post_mlp_adapter.down_proj.weight": "model-00006-of-00006.safetensors",
378
+ "model.layers.25.post_mlp_adapter.up_proj.weight": "model-00006-of-00006.safetensors",
379
+ "model.layers.25.self_attn.k_proj.bias": "model-00006-of-00006.safetensors",
380
+ "model.layers.25.self_attn.k_proj.weight": "model-00006-of-00006.safetensors",
381
+ "model.layers.25.self_attn.o_proj.bias": "model-00006-of-00006.safetensors",
382
+ "model.layers.25.self_attn.o_proj.weight": "model-00006-of-00006.safetensors",
383
+ "model.layers.25.self_attn.q_proj.bias": "model-00006-of-00006.safetensors",
384
+ "model.layers.25.self_attn.q_proj.weight": "model-00006-of-00006.safetensors",
385
+ "model.layers.25.self_attn.v_proj.bias": "model-00006-of-00006.safetensors",
386
+ "model.layers.25.self_attn.v_proj.weight": "model-00006-of-00006.safetensors",
387
+ "model.layers.26.input_layernorm.bias": "model-00006-of-00006.safetensors",
388
+ "model.layers.26.input_layernorm.weight": "model-00006-of-00006.safetensors",
389
+ "model.layers.26.mlp.down_proj.bias": "model-00006-of-00006.safetensors",
390
+ "model.layers.26.mlp.down_proj.weight": "model-00006-of-00006.safetensors",
391
+ "model.layers.26.mlp.up_proj.bias": "model-00006-of-00006.safetensors",
392
+ "model.layers.26.mlp.up_proj.weight": "model-00006-of-00006.safetensors",
393
+ "model.layers.26.post_attention_layernorm.bias": "model-00006-of-00006.safetensors",
394
+ "model.layers.26.post_attention_layernorm.weight": "model-00006-of-00006.safetensors",
395
+ "model.layers.26.post_attn_adapter.down_proj.weight": "model-00006-of-00006.safetensors",
396
+ "model.layers.26.post_attn_adapter.up_proj.weight": "model-00006-of-00006.safetensors",
397
+ "model.layers.26.post_mlp_adapter.down_proj.weight": "model-00006-of-00006.safetensors",
398
+ "model.layers.26.post_mlp_adapter.up_proj.weight": "model-00006-of-00006.safetensors",
399
+ "model.layers.26.self_attn.k_proj.bias": "model-00006-of-00006.safetensors",
400
+ "model.layers.26.self_attn.k_proj.weight": "model-00006-of-00006.safetensors",
401
+ "model.layers.26.self_attn.o_proj.bias": "model-00006-of-00006.safetensors",
402
+ "model.layers.26.self_attn.o_proj.weight": "model-00006-of-00006.safetensors",
403
+ "model.layers.26.self_attn.q_proj.bias": "model-00006-of-00006.safetensors",
404
+ "model.layers.26.self_attn.q_proj.weight": "model-00006-of-00006.safetensors",
405
+ "model.layers.26.self_attn.v_proj.bias": "model-00006-of-00006.safetensors",
406
+ "model.layers.26.self_attn.v_proj.weight": "model-00006-of-00006.safetensors",
407
+ "model.layers.3.input_layernorm.bias": "model-00002-of-00006.safetensors",
408
+ "model.layers.3.input_layernorm.weight": "model-00002-of-00006.safetensors",
409
+ "model.layers.3.mlp.down_proj.bias": "model-00002-of-00006.safetensors",
410
+ "model.layers.3.mlp.down_proj.weight": "model-00002-of-00006.safetensors",
411
+ "model.layers.3.mlp.up_proj.bias": "model-00002-of-00006.safetensors",
412
+ "model.layers.3.mlp.up_proj.weight": "model-00002-of-00006.safetensors",
413
+ "model.layers.3.post_attention_layernorm.bias": "model-00002-of-00006.safetensors",
414
+ "model.layers.3.post_attention_layernorm.weight": "model-00002-of-00006.safetensors",
415
+ "model.layers.3.post_attn_adapter.down_proj.weight": "model-00002-of-00006.safetensors",
416
+ "model.layers.3.post_attn_adapter.up_proj.weight": "model-00002-of-00006.safetensors",
417
+ "model.layers.3.post_mlp_adapter.down_proj.weight": "model-00002-of-00006.safetensors",
418
+ "model.layers.3.post_mlp_adapter.up_proj.weight": "model-00002-of-00006.safetensors",
419
+ "model.layers.3.self_attn.k_proj.bias": "model-00002-of-00006.safetensors",
420
+ "model.layers.3.self_attn.k_proj.weight": "model-00002-of-00006.safetensors",
421
+ "model.layers.3.self_attn.o_proj.bias": "model-00002-of-00006.safetensors",
422
+ "model.layers.3.self_attn.o_proj.weight": "model-00002-of-00006.safetensors",
423
+ "model.layers.3.self_attn.q_proj.bias": "model-00002-of-00006.safetensors",
424
+ "model.layers.3.self_attn.q_proj.weight": "model-00002-of-00006.safetensors",
425
+ "model.layers.3.self_attn.v_proj.bias": "model-00002-of-00006.safetensors",
426
+ "model.layers.3.self_attn.v_proj.weight": "model-00002-of-00006.safetensors",
427
+ "model.layers.4.input_layernorm.bias": "model-00002-of-00006.safetensors",
428
+ "model.layers.4.input_layernorm.weight": "model-00002-of-00006.safetensors",
429
+ "model.layers.4.mlp.down_proj.bias": "model-00002-of-00006.safetensors",
430
+ "model.layers.4.mlp.down_proj.weight": "model-00002-of-00006.safetensors",
431
+ "model.layers.4.mlp.up_proj.bias": "model-00002-of-00006.safetensors",
432
+ "model.layers.4.mlp.up_proj.weight": "model-00002-of-00006.safetensors",
433
+ "model.layers.4.post_attention_layernorm.bias": "model-00002-of-00006.safetensors",
434
+ "model.layers.4.post_attention_layernorm.weight": "model-00002-of-00006.safetensors",
435
+ "model.layers.4.post_attn_adapter.down_proj.weight": "model-00002-of-00006.safetensors",
436
+ "model.layers.4.post_attn_adapter.up_proj.weight": "model-00002-of-00006.safetensors",
437
+ "model.layers.4.post_mlp_adapter.down_proj.weight": "model-00002-of-00006.safetensors",
438
+ "model.layers.4.post_mlp_adapter.up_proj.weight": "model-00002-of-00006.safetensors",
439
+ "model.layers.4.self_attn.k_proj.bias": "model-00002-of-00006.safetensors",
440
+ "model.layers.4.self_attn.k_proj.weight": "model-00002-of-00006.safetensors",
441
+ "model.layers.4.self_attn.o_proj.bias": "model-00002-of-00006.safetensors",
442
+ "model.layers.4.self_attn.o_proj.weight": "model-00002-of-00006.safetensors",
443
+ "model.layers.4.self_attn.q_proj.bias": "model-00002-of-00006.safetensors",
444
+ "model.layers.4.self_attn.q_proj.weight": "model-00002-of-00006.safetensors",
445
+ "model.layers.4.self_attn.v_proj.bias": "model-00002-of-00006.safetensors",
446
+ "model.layers.4.self_attn.v_proj.weight": "model-00002-of-00006.safetensors",
447
+ "model.layers.5.input_layernorm.bias": "model-00002-of-00006.safetensors",
448
+ "model.layers.5.input_layernorm.weight": "model-00002-of-00006.safetensors",
449
+ "model.layers.5.mlp.down_proj.bias": "model-00002-of-00006.safetensors",
450
+ "model.layers.5.mlp.down_proj.weight": "model-00002-of-00006.safetensors",
451
+ "model.layers.5.mlp.up_proj.bias": "model-00002-of-00006.safetensors",
452
+ "model.layers.5.mlp.up_proj.weight": "model-00002-of-00006.safetensors",
453
+ "model.layers.5.post_attention_layernorm.bias": "model-00002-of-00006.safetensors",
454
+ "model.layers.5.post_attention_layernorm.weight": "model-00002-of-00006.safetensors",
455
+ "model.layers.5.post_attn_adapter.down_proj.weight": "model-00002-of-00006.safetensors",
456
+ "model.layers.5.post_attn_adapter.up_proj.weight": "model-00002-of-00006.safetensors",
457
+ "model.layers.5.post_mlp_adapter.down_proj.weight": "model-00002-of-00006.safetensors",
458
+ "model.layers.5.post_mlp_adapter.up_proj.weight": "model-00002-of-00006.safetensors",
459
+ "model.layers.5.self_attn.k_proj.bias": "model-00002-of-00006.safetensors",
460
+ "model.layers.5.self_attn.k_proj.weight": "model-00002-of-00006.safetensors",
461
+ "model.layers.5.self_attn.o_proj.bias": "model-00002-of-00006.safetensors",
462
+ "model.layers.5.self_attn.o_proj.weight": "model-00002-of-00006.safetensors",
463
+ "model.layers.5.self_attn.q_proj.bias": "model-00002-of-00006.safetensors",
464
+ "model.layers.5.self_attn.q_proj.weight": "model-00002-of-00006.safetensors",
465
+ "model.layers.5.self_attn.v_proj.bias": "model-00002-of-00006.safetensors",
466
+ "model.layers.5.self_attn.v_proj.weight": "model-00002-of-00006.safetensors",
467
+ "model.layers.6.input_layernorm.bias": "model-00002-of-00006.safetensors",
468
+ "model.layers.6.input_layernorm.weight": "model-00002-of-00006.safetensors",
469
+ "model.layers.6.mlp.down_proj.bias": "model-00002-of-00006.safetensors",
470
+ "model.layers.6.mlp.down_proj.weight": "model-00002-of-00006.safetensors",
471
+ "model.layers.6.mlp.up_proj.bias": "model-00002-of-00006.safetensors",
472
+ "model.layers.6.mlp.up_proj.weight": "model-00002-of-00006.safetensors",
473
+ "model.layers.6.post_attention_layernorm.bias": "model-00002-of-00006.safetensors",
474
+ "model.layers.6.post_attention_layernorm.weight": "model-00002-of-00006.safetensors",
475
+ "model.layers.6.post_attn_adapter.down_proj.weight": "model-00002-of-00006.safetensors",
476
+ "model.layers.6.post_attn_adapter.up_proj.weight": "model-00002-of-00006.safetensors",
477
+ "model.layers.6.post_mlp_adapter.down_proj.weight": "model-00002-of-00006.safetensors",
478
+ "model.layers.6.post_mlp_adapter.up_proj.weight": "model-00002-of-00006.safetensors",
479
+ "model.layers.6.self_attn.k_proj.bias": "model-00002-of-00006.safetensors",
480
+ "model.layers.6.self_attn.k_proj.weight": "model-00002-of-00006.safetensors",
481
+ "model.layers.6.self_attn.o_proj.bias": "model-00002-of-00006.safetensors",
482
+ "model.layers.6.self_attn.o_proj.weight": "model-00002-of-00006.safetensors",
483
+ "model.layers.6.self_attn.q_proj.bias": "model-00002-of-00006.safetensors",
484
+ "model.layers.6.self_attn.q_proj.weight": "model-00002-of-00006.safetensors",
485
+ "model.layers.6.self_attn.v_proj.bias": "model-00002-of-00006.safetensors",
486
+ "model.layers.6.self_attn.v_proj.weight": "model-00002-of-00006.safetensors",
487
+ "model.layers.7.input_layernorm.bias": "model-00003-of-00006.safetensors",
488
+ "model.layers.7.input_layernorm.weight": "model-00003-of-00006.safetensors",
489
+ "model.layers.7.mlp.down_proj.bias": "model-00003-of-00006.safetensors",
490
+ "model.layers.7.mlp.down_proj.weight": "model-00003-of-00006.safetensors",
491
+ "model.layers.7.mlp.up_proj.bias": "model-00002-of-00006.safetensors",
492
+ "model.layers.7.mlp.up_proj.weight": "model-00002-of-00006.safetensors",
493
+ "model.layers.7.post_attention_layernorm.bias": "model-00003-of-00006.safetensors",
494
+ "model.layers.7.post_attention_layernorm.weight": "model-00003-of-00006.safetensors",
495
+ "model.layers.7.post_attn_adapter.down_proj.weight": "model-00002-of-00006.safetensors",
496
+ "model.layers.7.post_attn_adapter.up_proj.weight": "model-00002-of-00006.safetensors",
497
+ "model.layers.7.post_mlp_adapter.down_proj.weight": "model-00002-of-00006.safetensors",
498
+ "model.layers.7.post_mlp_adapter.up_proj.weight": "model-00002-of-00006.safetensors",
499
+ "model.layers.7.self_attn.k_proj.bias": "model-00002-of-00006.safetensors",
500
+ "model.layers.7.self_attn.k_proj.weight": "model-00002-of-00006.safetensors",
501
+ "model.layers.7.self_attn.o_proj.bias": "model-00002-of-00006.safetensors",
502
+ "model.layers.7.self_attn.o_proj.weight": "model-00002-of-00006.safetensors",
503
+ "model.layers.7.self_attn.q_proj.bias": "model-00002-of-00006.safetensors",
504
+ "model.layers.7.self_attn.q_proj.weight": "model-00002-of-00006.safetensors",
505
+ "model.layers.7.self_attn.v_proj.bias": "model-00002-of-00006.safetensors",
506
+ "model.layers.7.self_attn.v_proj.weight": "model-00002-of-00006.safetensors",
507
+ "model.layers.8.input_layernorm.bias": "model-00003-of-00006.safetensors",
508
+ "model.layers.8.input_layernorm.weight": "model-00003-of-00006.safetensors",
509
+ "model.layers.8.mlp.down_proj.bias": "model-00003-of-00006.safetensors",
510
+ "model.layers.8.mlp.down_proj.weight": "model-00003-of-00006.safetensors",
511
+ "model.layers.8.mlp.up_proj.bias": "model-00003-of-00006.safetensors",
512
+ "model.layers.8.mlp.up_proj.weight": "model-00003-of-00006.safetensors",
513
+ "model.layers.8.post_attention_layernorm.bias": "model-00003-of-00006.safetensors",
514
+ "model.layers.8.post_attention_layernorm.weight": "model-00003-of-00006.safetensors",
515
+ "model.layers.8.post_attn_adapter.down_proj.weight": "model-00003-of-00006.safetensors",
516
+ "model.layers.8.post_attn_adapter.up_proj.weight": "model-00003-of-00006.safetensors",
517
+ "model.layers.8.post_mlp_adapter.down_proj.weight": "model-00003-of-00006.safetensors",
518
+ "model.layers.8.post_mlp_adapter.up_proj.weight": "model-00003-of-00006.safetensors",
519
+ "model.layers.8.self_attn.k_proj.bias": "model-00003-of-00006.safetensors",
520
+ "model.layers.8.self_attn.k_proj.weight": "model-00003-of-00006.safetensors",
521
+ "model.layers.8.self_attn.o_proj.bias": "model-00003-of-00006.safetensors",
522
+ "model.layers.8.self_attn.o_proj.weight": "model-00003-of-00006.safetensors",
523
+ "model.layers.8.self_attn.q_proj.bias": "model-00003-of-00006.safetensors",
524
+ "model.layers.8.self_attn.q_proj.weight": "model-00003-of-00006.safetensors",
525
+ "model.layers.8.self_attn.v_proj.bias": "model-00003-of-00006.safetensors",
526
+ "model.layers.8.self_attn.v_proj.weight": "model-00003-of-00006.safetensors",
527
+ "model.layers.9.input_layernorm.bias": "model-00003-of-00006.safetensors",
528
+ "model.layers.9.input_layernorm.weight": "model-00003-of-00006.safetensors",
529
+ "model.layers.9.mlp.down_proj.bias": "model-00003-of-00006.safetensors",
530
+ "model.layers.9.mlp.down_proj.weight": "model-00003-of-00006.safetensors",
531
+ "model.layers.9.mlp.up_proj.bias": "model-00003-of-00006.safetensors",
532
+ "model.layers.9.mlp.up_proj.weight": "model-00003-of-00006.safetensors",
533
+ "model.layers.9.post_attention_layernorm.bias": "model-00003-of-00006.safetensors",
534
+ "model.layers.9.post_attention_layernorm.weight": "model-00003-of-00006.safetensors",
535
+ "model.layers.9.post_attn_adapter.down_proj.weight": "model-00003-of-00006.safetensors",
536
+ "model.layers.9.post_attn_adapter.up_proj.weight": "model-00003-of-00006.safetensors",
537
+ "model.layers.9.post_mlp_adapter.down_proj.weight": "model-00003-of-00006.safetensors",
538
+ "model.layers.9.post_mlp_adapter.up_proj.weight": "model-00003-of-00006.safetensors",
539
+ "model.layers.9.self_attn.k_proj.bias": "model-00003-of-00006.safetensors",
540
+ "model.layers.9.self_attn.k_proj.weight": "model-00003-of-00006.safetensors",
541
+ "model.layers.9.self_attn.o_proj.bias": "model-00003-of-00006.safetensors",
542
+ "model.layers.9.self_attn.o_proj.weight": "model-00003-of-00006.safetensors",
543
+ "model.layers.9.self_attn.q_proj.bias": "model-00003-of-00006.safetensors",
544
+ "model.layers.9.self_attn.q_proj.weight": "model-00003-of-00006.safetensors",
545
+ "model.layers.9.self_attn.v_proj.bias": "model-00003-of-00006.safetensors",
546
+ "model.layers.9.self_attn.v_proj.weight": "model-00003-of-00006.safetensors",
547
+ "model.norm.bias": "model-00006-of-00006.safetensors",
548
+ "model.norm.weight": "model-00006-of-00006.safetensors"
549
+ }
550
+ }
modeling_pharia.py ADDED
@@ -0,0 +1,1008 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # we don't want to support mypy for this file for now
2
+ # type: ignore
3
+ import numpy as np
4
+ from typing import List, Optional, Tuple, Union, Dict
5
+ from tqdm import tqdm
6
+ from einops import rearrange, repeat
7
+ import torch
8
+ from torch import nn
9
+ from transformers.activations import ACT2FN
10
+ from transformers.cache_utils import Cache, DynamicCache, StaticCache
11
+ from transformers.configuration_utils import PretrainedConfig
12
+ from transformers.modeling_attn_mask_utils import AttentionMaskConverter
13
+ from transformers.modeling_outputs import (
14
+ BaseModelOutputWithPast,
15
+ )
16
+ from transformers.modeling_utils import PreTrainedModel
17
+ try:
18
+ from flash_attn.flash_attn_interface import flash_attn_func
19
+ except Exception as e:
20
+ print(
21
+ f"Could not import flash attention. "
22
+ )
23
+ flash_attn_func = None
24
+
25
+
26
+ class RotaryConfig():
27
+ def __init__(
28
+ self,
29
+ dimensions: int = 0,
30
+ base: int = 10000,
31
+ max_seq_length: int = 2048
32
+ ):
33
+ self.dimensions = dimensions
34
+ self.base = base
35
+ self.max_seq_length = max_seq_length
36
+
37
+ class PhariaAdapterConfig:
38
+ def __init__(
39
+ self,
40
+ hidden_size: int,
41
+ intermediate_size: int,
42
+ mlp_bias: bool,
43
+ hidden_act: str
44
+ ):
45
+ self.hidden_size = hidden_size
46
+ self.intermediate_size = intermediate_size
47
+ self.mlp_bias = mlp_bias
48
+ self.hidden_act = hidden_act
49
+
50
+
51
+ def to_dict(self):
52
+ return {
53
+ "hidden_size": self.hidden_size,
54
+ "intermediate_size": self.intermediate_size,
55
+ "mlp_bias": self.mlp_bias,
56
+ "hidden_act": self.hidden_act,
57
+ }
58
+
59
+ @classmethod
60
+ def from_dict(cls, config_dict):
61
+ return cls(**config_dict)
62
+
63
+
64
+
65
+ class PhariaConfig(PretrainedConfig):
66
+ def __init__(
67
+ self,
68
+ pad_token_id=None,
69
+ bos_token_id=1,
70
+ eos_token_id=2,
71
+ hidden_act="gelu",
72
+ hidden_size=512,
73
+ bias_name=None,
74
+ initializer_range=0.02,
75
+ intermediate_size=2048,
76
+ max_position_embeddings=8192,
77
+ model_type="pharia-v2",
78
+ num_attention_heads=4,
79
+ num_hidden_layers=4,
80
+ num_key_value_heads=2,
81
+ torch_dtype="bfloat16",
82
+ transformers_version="4.31.0.dev0",
83
+ use_cache=True,
84
+ vocab_size=128000,
85
+ mlp_bias=True,
86
+ attention_bias=True,
87
+ tie_word_embeddings=False,
88
+ attention_dropout=0.0,
89
+ causal_attention=True,
90
+ rope_theta=1000000, # rotary_embeddingbase,
91
+ rope_scaling=None,
92
+ mlp_adapter_config=None,
93
+ attn_adapter_config=None,
94
+ _attn_implementation='eager',
95
+ embedding_head_out=1024,
96
+ lora_config=None,
97
+ pooling_method=None,
98
+ layer_norm_epsilon=1e-05,
99
+ **kwargs,
100
+ ):
101
+ super().__init__(
102
+ pad_token_id=pad_token_id,
103
+ bos_token_id=bos_token_id,
104
+ eos_token_id=eos_token_id,
105
+ tie_word_embeddings=tie_word_embeddings,
106
+ **kwargs,
107
+ )
108
+
109
+ self.pad_token_id = pad_token_id
110
+ self.bos_token_id = bos_token_id
111
+ self.eos_token_id = eos_token_id
112
+ self.hidden_act = hidden_act
113
+ self.hidden_size = hidden_size
114
+ self.initializer_range = initializer_range
115
+ self.intermediate_size = intermediate_size
116
+ self.max_position_embeddings = max_position_embeddings
117
+ self.model_type = model_type
118
+ self.num_attention_heads = num_attention_heads
119
+ self.num_hidden_layers = num_hidden_layers
120
+ self.num_key_value_heads = num_key_value_heads
121
+ self.torch_dtype = torch_dtype
122
+ self.causal_attention = causal_attention
123
+ self.attn_adapter_config = attn_adapter_config
124
+ self.mlp_adapter_config = mlp_adapter_config
125
+ self.bias_name = bias_name
126
+ self.transformers_version = transformers_version
127
+ self.use_cache = use_cache
128
+ self.vocab_size = vocab_size
129
+ self.mlp_bias = mlp_bias
130
+ self.attention_bias = attention_bias
131
+ self.tie_word_embeddings = tie_word_embeddings
132
+ self.attention_dropout = attention_dropout
133
+ self.rope_theta = rope_theta
134
+ self.rope_scaling = rope_scaling
135
+ self.embedding_head_out = embedding_head_out
136
+ self.pooling_method = pooling_method
137
+ self.lora_config = lora_config
138
+ self._attn_implementation = _attn_implementation
139
+ self.layer_norm_epsilon = layer_norm_epsilon
140
+
141
+
142
+ def to_dict(self):
143
+ output = super(PhariaConfig, self).to_dict()
144
+ if self.mlp_adapter_config is not None:
145
+ output["mlp_adapter_config"] = self.mlp_adapter_config.to_dict()
146
+ if self.attn_adapter_config is not None:
147
+ output["attn_adapter_config"] = self.attn_adapter_config.to_dict()
148
+ return output
149
+
150
+ @classmethod
151
+ def from_dict(cls, config_dict, **kwargs):
152
+ if 'use_cache' in config_dict:
153
+ del config_dict['use_cache']
154
+
155
+ if 'mlp_adapter_config' in config_dict and config_dict["mlp_adapter_config"] is not None:
156
+ config_dict["mlp_adapter_config"] = PhariaAdapterConfig.from_dict(config_dict["mlp_adapter_config"])
157
+ if 'attn_adapter_config' in config_dict and config_dict["attn_adapter_config"] is not None:
158
+ config_dict["attn_adapter_config"] = PhariaAdapterConfig.from_dict(config_dict["attn_adapter_config"])
159
+ return cls(**config_dict, **kwargs)
160
+
161
+
162
+ def reshape_complex_for_broadcast(freqs_cis: torch.Tensor, x: torch.Tensor) -> torch.Tensor:
163
+ ndim = x.ndim
164
+ assert 0 <= 1 < ndim
165
+ assert freqs_cis.shape[0] == x.shape[1]
166
+ assert freqs_cis.shape[1] == x.shape[-1]
167
+ shape = [d if i == 1 or i == ndim - 1 else 1 for i, d in enumerate(x.shape)]
168
+ return freqs_cis.view(*shape)
169
+
170
+ def precompute_freqs_cis(
171
+ dim: int,
172
+ end: int,
173
+ theta: float,
174
+ device: torch.device,
175
+ ) -> torch.Tensor:
176
+ theta = float(theta)
177
+ freqs = 1.0 / (theta ** (torch.arange(0, dim, 2, device=device)[: (dim // 2)].float() / dim)).to(device)
178
+ t = torch.arange(end, device=device) # type: ignore
179
+ freqs = torch.outer(t, freqs).float() # type: ignore
180
+ freqs_cis = torch.polar(torch.ones_like(freqs), freqs) # complex64
181
+ return freqs_cis.to(device)
182
+
183
+
184
+ def apply_complex_rotary_emb(
185
+ xq: torch.Tensor,
186
+ xk: torch.Tensor,
187
+ freqs_cis: torch.Tensor,
188
+ query_position_ids: Optional[torch.Tensor],
189
+ key_position_ids: Optional[torch.Tensor],
190
+ ) -> tuple[torch.Tensor, torch.Tensor]:
191
+ xq_complex = torch.view_as_complex(xq.float().reshape(*xq.shape[:-1], -1, 2))
192
+ xk_complex = torch.view_as_complex(xk.float().reshape(*xk.shape[:-1], -1, 2))
193
+
194
+ if query_position_ids is None:
195
+ freqs_cis_q = reshape_complex_for_broadcast(freqs_cis, xq_complex)
196
+ else:
197
+ freqs_cis_q = vector_gather_complex(freqs_cis, query_position_ids)
198
+
199
+ if key_position_ids is None:
200
+ freqs_cis_k = reshape_complex_for_broadcast(freqs_cis, xq_complex)
201
+ else:
202
+ freqs_cis_k = vector_gather_complex(freqs_cis, key_position_ids)
203
+
204
+ xq_out = torch.view_as_real(xq_complex * freqs_cis_q).flatten(3)
205
+ xk_out = torch.view_as_real(xk_complex * freqs_cis_k).flatten(3)
206
+ return xq_out.type_as(xq), xk_out.type_as(xk)
207
+
208
+
209
+ class RotaryEmbeddingComplex(torch.nn.Module):
210
+ """
211
+ Relative rotary position embedding based on
212
+ * RoFormer: Enhanced Transformer with Rotary Position Embedding (https://arxiv.org/abs/2104.09864)
213
+ * Rotary Embeddings: A Relative Revolution (https://blog.eleuther.ai/rotary-embeddings/)
214
+ """
215
+
216
+ def __init__(
217
+ self,
218
+ config: RotaryConfig,
219
+ device: torch.device,
220
+ ) -> None:
221
+ super().__init__()
222
+ assert config.dimensions > 1, "RotaryEmbedding cannot use `dim` == 1, this results in weird reshape errors"
223
+
224
+ freqs_cis = precompute_freqs_cis(
225
+ dim=config.dimensions,
226
+ end=config.max_seq_length,
227
+ theta=config.base,
228
+ device=device,
229
+ )
230
+
231
+ # Store real and imaginary in separate buffers for correct type casting.
232
+ self.freqs_cis_real = freqs_cis.real
233
+ self.freqs_cis_imag = freqs_cis.imag
234
+
235
+ def forward(
236
+ self,
237
+ query: torch.Tensor,
238
+ key: torch.Tensor,
239
+ query_position_ids: Optional[torch.Tensor] = None,
240
+ key_position_ids: Optional[torch.Tensor] = None,
241
+ ) -> tuple[torch.Tensor, torch.Tensor]:
242
+ query, key = apply_complex_rotary_emb(
243
+ xq=rearrange(query, "sq b nh hh -> b sq nh hh"),
244
+ xk=rearrange(key, "sq b nh hh -> b sq nh hh"),
245
+ freqs_cis=torch.complex(self.freqs_cis_real.float(), self.freqs_cis_imag.float()),
246
+ query_position_ids=query_position_ids,
247
+ key_position_ids=key_position_ids,
248
+ )
249
+ return rearrange(query, "b sq nh hh -> sq b nh hh"), rearrange(key, "b sq nh hh -> sq b nh hh")
250
+
251
+ def vector_gather(vectors: torch.Tensor, indices: torch.Tensor) -> torch.Tensor:
252
+ """
253
+ Gathers (batched) vectors according to indices.
254
+ """
255
+ vectors = repeat(vectors, "sq b nh d -> sq b B nh d", B=indices.shape[1]).squeeze(1)
256
+ indices = repeat(
257
+ indices,
258
+ "sq b -> sq b nh d",
259
+ nh=vectors.shape[-2],
260
+ d=vectors.shape[-1],
261
+ )
262
+
263
+ out = torch.gather(vectors, dim=0, index=indices)
264
+
265
+ return out
266
+
267
+
268
+ def vector_gather_complex(vectors: torch.Tensor, indices: torch.Tensor) -> torch.Tensor:
269
+ """
270
+ Gathers (batched) vectors according to indices.
271
+ """
272
+ vectors = repeat(vectors, "sq d -> sq B nh d", B=indices.shape[1], nh=1)
273
+ indices = repeat(
274
+ indices,
275
+ "sq b -> sq b nh d",
276
+ nh=1,
277
+ d=vectors.shape[-1],
278
+ )
279
+
280
+ out = torch.gather(vectors, dim=0, index=indices)
281
+
282
+ out = rearrange(out, "sq b nh hh -> b sq nh hh")
283
+
284
+ return out
285
+
286
+ def repeat_kv(x: torch.Tensor, n_rep: int) -> torch.Tensor:
287
+ """torch.repeat_interleave(x, dim=2, repeats=n_rep)"""
288
+ bs, slen, n_kv_heads, head_dim = x.shape
289
+ if n_rep == 1:
290
+ return x
291
+ return (
292
+ x[:, :, :, None, :]
293
+ .expand(bs, slen, n_kv_heads, n_rep, head_dim)
294
+ .reshape(bs, slen, n_kv_heads * n_rep, head_dim)
295
+ )
296
+
297
+
298
+
299
+ class PhariaAttention(nn.Module):
300
+ """Multi-headed attention from 'Attention Is All You Need' paper"""
301
+
302
+ def __init__(self, config: PhariaConfig, layer_idx: Optional[int] = None):
303
+ super().__init__()
304
+ self.config = config
305
+ self.layer_idx = layer_idx
306
+ self.attention_dropout = config.attention_dropout
307
+ self.hidden_size = config.hidden_size
308
+ self.num_heads = config.num_attention_heads
309
+ self.head_dim = self.hidden_size // self.num_heads
310
+ self.num_key_value_heads = config.num_key_value_heads
311
+ self.num_key_value_groups = self.num_heads // self.num_key_value_heads
312
+ self.max_position_embeddings = config.max_position_embeddings
313
+ self.rope_theta = config.rope_theta
314
+ self.is_causal = config.causal_attention
315
+ self.query_key_scaling_factor = 1 / (self.head_dim ** 0.5)
316
+
317
+ if (self.head_dim * self.num_heads) != self.hidden_size:
318
+ raise ValueError(
319
+ f"hidden_size must be divisible by num_heads (got `hidden_size`: {self.hidden_size}"
320
+ f" and `num_heads`: {self.num_heads})."
321
+ )
322
+
323
+ self.q_proj = nn.Linear(
324
+ self.hidden_size, self.num_heads * self.head_dim, bias=config.attention_bias
325
+ )
326
+ self.k_proj = nn.Linear(
327
+ self.hidden_size,
328
+ self.num_key_value_heads * self.head_dim,
329
+ bias=config.attention_bias,
330
+ )
331
+ self.v_proj = nn.Linear(
332
+ self.hidden_size,
333
+ self.num_key_value_heads * self.head_dim,
334
+ bias=config.attention_bias,
335
+ )
336
+ self.o_proj = nn.Linear(
337
+ self.hidden_size, self.hidden_size, bias=config.attention_bias
338
+ )
339
+
340
+ self._init_rope()
341
+
342
+ def _init_rope(self):
343
+ self.rotary_emb = RotaryEmbeddingComplex(
344
+ config=RotaryConfig(
345
+ dimensions=self.head_dim,
346
+ max_seq_length=self.max_position_embeddings,
347
+ base=self.rope_theta
348
+ ),
349
+ device='cuda:0'
350
+ )
351
+
352
+ def prepare_query_key_value(
353
+ self,
354
+ hidden_states: torch.Tensor,
355
+ position_ids: torch.Tensor,
356
+ past_key_value: Optional[Cache] = None,
357
+ cache_position: Optional[torch.LongTensor] = None,
358
+ ):
359
+ query_states = rearrange(self.q_proj(hidden_states), "b sq (np hn) -> sq b np hn", np=self.num_heads)
360
+ key_states = rearrange(self.k_proj(hidden_states), "b sq (np hn) -> sq b np hn", np=self.num_key_value_heads)
361
+ value_states = rearrange(self.v_proj(hidden_states), "b sq (np hn) -> sq b np hn", np=self.num_key_value_heads)
362
+
363
+ # cos, sin = self.rotary_emb(value_states, position_ids)
364
+ position_ids = rearrange(position_ids, 'b sq -> sq b')
365
+ query_states, key_states = self.rotary_emb(
366
+ query_states, key_states, query_position_ids=position_ids, key_position_ids=position_ids
367
+ )
368
+
369
+ if past_key_value is not None:
370
+ # cache_position needed for the static cache
371
+ cache_kwargs = {"cache_position": cache_position}
372
+ key_states, value_states = past_key_value.update(
373
+ key_states, value_states, self.layer_idx, cache_kwargs
374
+ )
375
+
376
+ key_states = repeat_kv(key_states, self.num_key_value_groups)
377
+ value_states = repeat_kv(value_states, self.num_key_value_groups)
378
+
379
+ return query_states, key_states, value_states
380
+
381
+ def forward (
382
+ self,
383
+ hidden_states: torch.Tensor,
384
+ attention_mask: Optional[torch.Tensor] = None,
385
+ position_ids: Optional[torch.LongTensor] = None,
386
+ past_key_value: Optional[Cache] = None,
387
+ output_attentions: Optional[bool] = False,
388
+ use_cache: Optional[bool] = False,
389
+ cache_position: Optional[torch.LongTensor] = None,
390
+ softmax_in_fp32: Optional[bool] = False
391
+ ):
392
+ bsz, _, _ = hidden_states.size()
393
+ query, key, value = self.prepare_query_key_value(
394
+ hidden_states,
395
+ position_ids=position_ids,
396
+ past_key_value=past_key_value,
397
+ cache_position=cache_position
398
+ )
399
+ seq_length, batch_size, _, head_dim = query.shape
400
+
401
+ query = rearrange(query, "sq bs nh hd -> sq (bs nh) hd")
402
+ key = rearrange(key, "sq bs nh hd -> sq (bs nh) hd")
403
+ value = rearrange(value, "sq bs nh hd -> sq (bs nh) hd")
404
+
405
+ matmul_result = torch.empty(
406
+ query.size(1),
407
+ query.size(0),
408
+ key.size(0),
409
+ dtype=query.dtype,
410
+ device=query.device,
411
+ )
412
+
413
+ # Raw attention scores. [b * np, s_q, s_k]
414
+ matmul_result = torch.baddbmm(
415
+ matmul_result,
416
+ query.transpose(0, 1), # [b * np, s_q, hn]
417
+ key.transpose(0, 1).transpose(1, 2), # [b * np, hn, s_k]
418
+ beta=0.0,
419
+ alpha=self.query_key_scaling_factor,
420
+ )
421
+
422
+ attention_scores = rearrange(matmul_result, "(b n) s_q s_k -> b n s_q s_k", b=batch_size)
423
+ if softmax_in_fp32 and attention_scores.dtype != torch.float32:
424
+ input_dtype = attention_scores.dtype
425
+ attention_scores = attention_scores.float()
426
+ else:
427
+ input_dtype = None
428
+
429
+
430
+ causal_mask = torch.triu(
431
+ torch.ones(seq_length, seq_length, device=query.device),
432
+ diagonal=1
433
+ ).bool()
434
+
435
+ attention_scores.masked_fill_(causal_mask.to(attention_scores.device), -10000.0)
436
+ probs = torch.nn.functional.softmax(attention_scores, dim=-1)
437
+ if softmax_in_fp32 and input_dtype is not None:
438
+ probs = probs.to(input_dtype)
439
+
440
+
441
+ probs = rearrange(probs, "b n s_q s_k -> (b n) s_q s_k")
442
+ hidden_state = torch.bmm(probs.to(dtype=value.dtype), value.transpose(0, 1))
443
+ attn_output = rearrange(hidden_state, "(b np) sq hn -> b sq (np hn)", b=bsz)
444
+
445
+
446
+ attn_output = nn.functional.linear(attn_output, self.o_proj.weight, None) + self.o_proj.bias
447
+
448
+ return attn_output, _, past_key_value
449
+
450
+ class PhariaFlashAttention2(PhariaAttention):
451
+ def __init__(self, *args, **kwargs):
452
+ super().__init__(*args, **kwargs)
453
+
454
+ @staticmethod
455
+ def get_max_seq_length(cumulative_seq_lengths: torch.Tensor) -> int:
456
+ return int((cumulative_seq_lengths[1:] - cumulative_seq_lengths[:-1]).max().item())
457
+
458
+
459
+ def forward(
460
+ self,
461
+ hidden_states: torch.Tensor,
462
+ attention_mask: Optional[torch.Tensor] = None,
463
+ position_ids: Optional[torch.LongTensor] = None,
464
+ past_key_value: Optional[Cache] = None,
465
+ output_attentions: Optional[bool] = False,
466
+ use_cache: Optional[bool] = False,
467
+ cache_position: Optional[torch.LongTensor] = None,
468
+ softmax_in_fp32: Optional[bool] = False
469
+ ):
470
+ assert flash_attn_func is not None, "Please install Flash Attention via optimization requirements"
471
+ query, key, value = self.prepare_query_key_value(hidden_states, position_ids=position_ids)
472
+
473
+ batch_size = query.shape[1]
474
+
475
+ # reshape into format expected by flash attention [sq, b, np, hn] => [b, sq, np, hn]
476
+ query = rearrange(query, "s_q b n h -> b s_q n h")
477
+ key = rearrange(key, "s_k b n h -> b s_k n h")
478
+ value = rearrange(value, "s_k b n h -> b s_k n h")
479
+
480
+ attention_output = flash_attn_func(
481
+ q=query,
482
+ k=key,
483
+ v=value,
484
+ causal=self.is_causal,
485
+ softmax_scale=self.query_key_scaling_factor
486
+ )
487
+ attention_output = rearrange(attention_output, "b sq np hn -> b sq (np hn)", b=batch_size)
488
+
489
+ attention_output = nn.functional.linear(attention_output, self.o_proj.weight, None) + self.o_proj.bias
490
+
491
+ if not output_attentions:
492
+ attn_weights = None
493
+
494
+ return attention_output, attn_weights, past_key_value
495
+
496
+
497
+ ATTN_IMPLEMENTATION = {
498
+ 'flash_attention_2': PhariaFlashAttention2,
499
+ 'sdpa': PhariaAttention,
500
+ 'eager': PhariaAttention
501
+ }
502
+
503
+
504
+ class PhariaMLP(nn.Module):
505
+ def __init__(self, config, layer_idx: int):
506
+ super().__init__()
507
+ self.layer_idx = layer_idx
508
+ self.config = config
509
+ self.hidden_size = config.hidden_size
510
+ self.intermediate_size = config.intermediate_size
511
+ self.up_proj = nn.Linear(
512
+ self.hidden_size, self.intermediate_size, bias=config.mlp_bias
513
+ )
514
+ self.down_proj = nn.Linear(
515
+ self.intermediate_size, self.hidden_size, bias=config.mlp_bias
516
+ )
517
+ self.act_fn = ACT2FN[config.hidden_act]
518
+
519
+ def forward(self, x):
520
+ x = self.up_proj(x)
521
+ x = self.act_fn(x)
522
+ if not self.down_proj.bias is None:
523
+ # Scaling implements this with bias being seperately added. To match numerics we change this also
524
+ o = nn.functional.linear(x, self.down_proj.weight, None) + self.down_proj.bias
525
+ else:
526
+ o = self.down_proj(x)
527
+ return o
528
+
529
+
530
+ class PhariaDecoderLayer(nn.Module):
531
+ def __init__(self, config: PhariaConfig, layer_idx: int):
532
+ super().__init__()
533
+ self.hidden_size = config.hidden_size
534
+ self.self_attn = ATTN_IMPLEMENTATION[config._attn_implementation](config=config, layer_idx=layer_idx)
535
+
536
+ self.post_mlp_adapter = None
537
+ if config.mlp_adapter_config:
538
+ self.post_mlp_adapter = PhariaMLP(config.mlp_adapter_config, layer_idx=layer_idx)
539
+ self.post_attn_adapter = None
540
+ if config.attn_adapter_config:
541
+ self.post_attn_adapter = PhariaMLP(config.attn_adapter_config, layer_idx=layer_idx)
542
+
543
+ self.mlp = PhariaMLP(config, layer_idx=layer_idx)
544
+ self.input_layernorm = nn.LayerNorm(config.hidden_size)
545
+ self.post_attention_layernorm = nn.LayerNorm(config.hidden_size)
546
+ self.layer_idx = layer_idx
547
+
548
+ def forward(
549
+ self,
550
+ hidden_states: torch.Tensor,
551
+ attention_mask: Optional[torch.Tensor] = None,
552
+ position_ids: Optional[torch.LongTensor] = None,
553
+ past_key_value: Optional[Cache] = None,
554
+ output_attentions: Optional[bool] = False,
555
+ use_cache: Optional[bool] = False,
556
+ cache_position: Optional[torch.LongTensor] = None,
557
+ ) -> Tuple[
558
+ torch.FloatTensor, Optional[Tuple[torch.FloatTensor, torch.FloatTensor]]
559
+ ]:
560
+ residual = hidden_states
561
+
562
+ hidden_states = self.input_layernorm(hidden_states)
563
+
564
+ hidden_states, self_attn_weights, present_key_value = self.self_attn(
565
+ hidden_states=hidden_states,
566
+ attention_mask=attention_mask,
567
+ position_ids=position_ids,
568
+ past_key_value=past_key_value,
569
+ output_attentions=output_attentions,
570
+ use_cache=use_cache,
571
+ cache_position=cache_position,
572
+ )
573
+
574
+ hidden_states = residual + hidden_states
575
+
576
+ if self.post_attn_adapter:
577
+ hidden_states = self.post_attn_adapter(hidden_states) + hidden_states
578
+
579
+ residual = hidden_states
580
+ hidden_states = self.post_attention_layernorm(hidden_states)
581
+
582
+ hidden_states = self.mlp(hidden_states)
583
+
584
+ hidden_states = residual + hidden_states
585
+ if self.post_mlp_adapter:
586
+ hidden_states = self.post_mlp_adapter(hidden_states) + hidden_states
587
+
588
+ outputs = (hidden_states,)
589
+
590
+ if output_attentions:
591
+ outputs += (self_attn_weights,)
592
+
593
+ if use_cache:
594
+ outputs += (present_key_value,)
595
+
596
+ return outputs
597
+
598
+ class PhariaPreTrainedModel(PreTrainedModel):
599
+ config_class = PhariaConfig
600
+ base_model_prefix = "model"
601
+ supports_gradient_checkpointing = False
602
+ _no_split_modules = ["PhariaDecoderLayer"]
603
+ _skip_keys_device_placement = ["past_key_values"]
604
+ _supports_flash_attn_2 = True
605
+ _supports_sdpa = True
606
+ _supports_cache_class = True
607
+ _supports_static_cache = True
608
+
609
+
610
+ def _init_weights(self, module):
611
+ std = self.config.initializer_range
612
+ if isinstance(module, nn.Linear):
613
+ module.weight.data.normal_(mean=0.0, std=std)
614
+ if module.bias is not None:
615
+ module.bias.data.zero_()
616
+ elif isinstance(module, nn.Embedding):
617
+ module.weight.data.normal_(mean=0.0, std=std)
618
+ if module.padding_idx is not None:
619
+ module.weight.data[module.padding_idx].zero_()
620
+
621
+
622
+ class PhariaModel(PhariaPreTrainedModel):
623
+ config_class = PhariaConfig
624
+
625
+ def __init__(self, config: PhariaConfig):
626
+ super().__init__(config)
627
+ self.padding_idx = config.pad_token_id
628
+ self.vocab_size = config.vocab_size
629
+
630
+ self.embed_tokens = nn.Embedding(
631
+ config.vocab_size, config.hidden_size, self.padding_idx
632
+ )
633
+
634
+ self.layers = nn.ModuleList(
635
+ [
636
+ PhariaDecoderLayer(config, layer_idx)
637
+ for layer_idx in range(config.num_hidden_layers)
638
+ ]
639
+ )
640
+
641
+ self.norm = nn.LayerNorm(config.hidden_size)
642
+
643
+ def forward(
644
+ self,
645
+ input_ids: torch.LongTensor = None,
646
+ attention_mask: Optional[torch.Tensor] = None,
647
+ position_ids: Optional[torch.LongTensor] = None,
648
+ past_key_values: Optional[Union[Cache, List[torch.FloatTensor]]] = None,
649
+ inputs_embeds: Optional[torch.FloatTensor] = None,
650
+ use_cache: Optional[bool] = None,
651
+ output_attentions: Optional[bool] = None,
652
+ output_hidden_states: Optional[bool] = None,
653
+ return_dict: Optional[bool] = None,
654
+ cache_position: Optional[torch.LongTensor] = None,
655
+ ) -> Union[Tuple, BaseModelOutputWithPast]:
656
+ output_attentions = (
657
+ output_attentions
658
+ if output_attentions is not None
659
+ else self.config.output_attentions
660
+ )
661
+ output_hidden_states = (
662
+ output_hidden_states
663
+ if output_hidden_states is not None
664
+ else self.config.output_hidden_states
665
+ )
666
+ use_cache = use_cache if use_cache is not None else self.config.use_cache
667
+ return_dict = (
668
+ return_dict if return_dict is not None else self.config.use_return_dict
669
+ )
670
+
671
+ if (input_ids is None) ^ (inputs_embeds is not None):
672
+ raise ValueError(
673
+ "You cannot specify both input_ids and inputs_embeds at the same time, and must specify either one"
674
+ )
675
+
676
+ if inputs_embeds is None:
677
+ inputs_embeds = self.embed_tokens(input_ids)
678
+
679
+ return_legacy_cache = False
680
+ if use_cache and not isinstance(
681
+ past_key_values, Cache
682
+ ): # kept for BC (non `Cache` `past_key_values` inputs)
683
+ return_legacy_cache = True
684
+ past_key_values = DynamicCache.from_legacy_cache(past_key_values)
685
+
686
+ if cache_position is None:
687
+ past_seen_tokens = (
688
+ past_key_values.get_seq_length() if past_key_values is not None else 0
689
+ )
690
+ cache_position = torch.arange(
691
+ past_seen_tokens,
692
+ past_seen_tokens + inputs_embeds.shape[1],
693
+ device=inputs_embeds.device,
694
+ )
695
+ if position_ids is None:
696
+ position_ids = cache_position.unsqueeze(0)
697
+
698
+ if self.config.causal_attention:
699
+ mask = self._update_causal_mask(
700
+ attention_mask,
701
+ inputs_embeds,
702
+ cache_position,
703
+ past_key_values,
704
+ output_attentions,
705
+ )
706
+ else:
707
+ mask = self._create_bidirectional_attention_mask(
708
+ attention_mask,
709
+ inputs_embeds.dtype
710
+ )
711
+
712
+ # embed positions
713
+ hidden_states = inputs_embeds
714
+
715
+ # decoder layers
716
+ all_hidden_states = () if output_hidden_states else None
717
+ all_self_attns = () if output_attentions else None
718
+ next_decoder_cache = None
719
+
720
+ for decoder_layer in self.layers:
721
+ if output_hidden_states:
722
+ all_hidden_states += (hidden_states,)
723
+
724
+ layer_outputs = decoder_layer(
725
+ hidden_states,
726
+ attention_mask=mask,
727
+ position_ids=position_ids,
728
+ past_key_value=past_key_values,
729
+ output_attentions=output_attentions,
730
+ use_cache=use_cache,
731
+ cache_position=cache_position,
732
+ )
733
+
734
+ hidden_states = layer_outputs[0]
735
+
736
+ if use_cache:
737
+ next_decoder_cache = layer_outputs[2 if output_attentions else 1]
738
+
739
+ if output_attentions:
740
+ all_self_attns += (layer_outputs[1],)
741
+
742
+ hidden_states = self.norm(hidden_states)
743
+
744
+ # add hidden states from the last decoder layer
745
+ if output_hidden_states:
746
+ all_hidden_states += (hidden_states,)
747
+
748
+ next_cache = next_decoder_cache if use_cache else None
749
+ if return_legacy_cache:
750
+ next_cache = next_cache.to_legacy_cache()
751
+
752
+ if not return_dict:
753
+ return tuple(
754
+ v
755
+ for v in [hidden_states, next_cache, all_hidden_states, all_self_attns]
756
+ if v is not None
757
+ )
758
+ return BaseModelOutputWithPast(
759
+ last_hidden_state=hidden_states,
760
+ past_key_values=next_cache,
761
+ hidden_states=all_hidden_states,
762
+ attentions=all_self_attns,
763
+ )
764
+
765
+ def _create_bidirectional_attention_mask(self, attention_mask: torch.Tensor, dtype: torch.dtype) -> torch.Tensor:
766
+ bidirectional_mask = attention_mask.unsqueeze(1) * attention_mask.unsqueeze(2).to(dtype)
767
+ bidirectional_mask = 1 - bidirectional_mask # flip
768
+ dtype_min_value = torch.finfo(dtype).min
769
+ attention_mask = bidirectional_mask.masked_fill(bidirectional_mask == 1, dtype_min_value)
770
+
771
+ return attention_mask
772
+
773
+
774
+ def _update_causal_mask(
775
+ self,
776
+ attention_mask: torch.Tensor,
777
+ input_tensor: torch.Tensor,
778
+ cache_position: torch.Tensor,
779
+ past_key_values: Cache,
780
+ output_attentions: bool,
781
+ ):
782
+ # TODO: As of torch==2.2.0, the `attention_mask` passed to the model in `generate` is 2D and of dynamic length even when the static
783
+ # KV cache is used. This is an issue for torch.compile which then recaptures cudagraphs at each decode steps due to the dynamic shapes.
784
+ # (`recording cudagraph tree for symint key 13`, etc.), which is VERY slow. A workaround is `@torch.compiler.disable`, but this prevents using
785
+ # `fullgraph=True`. See more context in https://github.com/huggingface/transformers/pull/29114
786
+
787
+ if self.config._attn_implementation == "flash_attention_2":
788
+ if attention_mask is not None and 0.0 in attention_mask:
789
+ return attention_mask
790
+ return None
791
+
792
+ # For SDPA, when possible, we will rely on its `is_causal` argument instead of its `attn_mask` argument, in
793
+ # order to dispatch on Flash Attention 2. This feature is not compatible with static cache, as SDPA will fail
794
+ # to infer the attention mask.
795
+ past_seen_tokens = (
796
+ past_key_values.get_seq_length() if past_key_values is not None else 0
797
+ )
798
+ using_static_cache = isinstance(past_key_values, StaticCache)
799
+
800
+ # When output attentions is True, sdpa implementation's forward method calls the eager implementation's forward
801
+ if (
802
+ self.config._attn_implementation == "sdpa"
803
+ and not using_static_cache
804
+ and not output_attentions
805
+ ):
806
+ if AttentionMaskConverter._ignore_causal_mask_sdpa(
807
+ attention_mask,
808
+ inputs_embeds=input_tensor,
809
+ past_key_values_length=past_seen_tokens,
810
+ is_training=self.training,
811
+ ):
812
+ return None
813
+
814
+ dtype, device = input_tensor.dtype, input_tensor.device
815
+ min_dtype = torch.finfo(dtype).min
816
+ sequence_length = input_tensor.shape[1]
817
+ if using_static_cache:
818
+ target_length = past_key_values.get_max_length()
819
+ else:
820
+ target_length = (
821
+ attention_mask.shape[-1]
822
+ if isinstance(attention_mask, torch.Tensor)
823
+ else past_seen_tokens + sequence_length + 1
824
+ )
825
+
826
+ if attention_mask is not None and attention_mask.dim() == 4:
827
+ # in this case we assume that the mask comes already in inverted form and requires no inversion or slicing
828
+ if attention_mask.max() != 0:
829
+ raise ValueError(
830
+ "Custom 4D attention mask should be passed in inverted form with max==0`"
831
+ )
832
+ causal_mask = attention_mask
833
+ else:
834
+ causal_mask = torch.full(
835
+ (sequence_length, target_length),
836
+ fill_value=min_dtype,
837
+ dtype=dtype,
838
+ device=device,
839
+ )
840
+ if sequence_length != 1:
841
+ causal_mask = torch.triu(causal_mask, diagonal=1)
842
+ causal_mask *= torch.arange(
843
+ target_length, device=device
844
+ ) > cache_position.reshape(-1, 1)
845
+ causal_mask = causal_mask[None, None, :, :].expand(
846
+ input_tensor.shape[0], 1, -1, -1
847
+ )
848
+ if attention_mask is not None:
849
+ causal_mask = (
850
+ causal_mask.clone()
851
+ ) # copy to contiguous memory for in-place edit
852
+ mask_length = attention_mask.shape[-1]
853
+ padding_mask = (
854
+ causal_mask[:, :, :, :mask_length]
855
+ + attention_mask[:, None, None, :]
856
+ )
857
+ padding_mask = padding_mask == 0
858
+ causal_mask[:, :, :, :mask_length] = causal_mask[
859
+ :, :, :, :mask_length
860
+ ].masked_fill(padding_mask, min_dtype)
861
+ if (
862
+ self.config._attn_implementation == "sdpa"
863
+ and attention_mask is not None
864
+ and attention_mask.device.type == "cuda"
865
+ and not output_attentions
866
+ ):
867
+ # Attend to all tokens in fully masked rows in the causal_mask, for example the relevant first rows when
868
+ # using left padding. This is required by F.scaled_dot_product_attention memory-efficient attention path.
869
+ # Details: https://github.com/pytorch/pytorch/issues/110213
870
+ causal_mask = AttentionMaskConverter._unmask_unattended(
871
+ causal_mask, min_dtype
872
+ )
873
+
874
+ return causal_mask
875
+
876
+ class Embeddinghead(torch.nn.Module):
877
+ def __init__(
878
+ self,
879
+ pooling_method: str
880
+ ):
881
+ super().__init__()
882
+ self.pooling_method = pooling_method
883
+
884
+ def forward(self, hidden_state: torch.Tensor, attention_mask: torch.Tensor = None) -> torch.Tensor:
885
+ """
886
+ Args:
887
+ hidden_state: [b, n, d]
888
+ attention_mask: [b, n]
889
+ """
890
+ hidden_state = hidden_state.to(attention_mask.device)
891
+ if self.pooling_method == 'cls':
892
+ embedding = hidden_state[:, 0]
893
+ elif self.pooling_method == 'lasttoken':
894
+ b, n, d = hidden_state.size()
895
+
896
+ reversed_mask = torch.flip(attention_mask, dims=(1,))
897
+ argmax_reverse = torch.argmax(reversed_mask, dim=1, keepdim=False)
898
+
899
+ gather_indices = attention_mask.size(1) - argmax_reverse - 1
900
+ gather_indices = torch.clamp(gather_indices, min=0)
901
+ gather_indices = gather_indices.unsqueeze(-1).repeat(1, d)
902
+ gather_indices = gather_indices.unsqueeze(1)
903
+ assert gather_indices.shape == (b, 1, d)
904
+
905
+ input_mask_expanded = attention_mask.unsqueeze(-1).expand((b, n, d)).float()
906
+ embedding = torch.gather(hidden_state * input_mask_expanded, 1, gather_indices).squeeze(dim=1)
907
+
908
+ elif self.pooling_method in ['mean', 'weighted_mean']:
909
+ if self.pooling_method == 'weighted_mean':
910
+ attention_mask *= attention_mask.cumsum(dim=1)
911
+ s = torch.sum(hidden_state * attention_mask.unsqueeze(-1).float(), dim=1)
912
+ d = attention_mask.sum(dim=1, keepdim=True).float()
913
+ embedding = s / d
914
+ else: raise NotImplementedError(f"Unknown pooling method: {self.pooling_method}")
915
+
916
+ return embedding
917
+
918
+
919
+
920
+ class PhariaForEmbedding(PhariaPreTrainedModel):
921
+ def __init__(self, config, tokenizer):
922
+ super().__init__(config)
923
+ self._use_flash_attention_2 = config._attn_implementation == "flash_attention_2"
924
+ self._use_sdpa = config._attn_implementation == "sdpa"
925
+ self.model = PhariaModel(config)
926
+ self.tokenizer = tokenizer
927
+ self.tokenizer.pad_token_id = 1
928
+
929
+ self.embedding_head = Embeddinghead(pooling_method=self.config.pooling_method)
930
+
931
+ def encode_queries(self, queries: Union[List[str], str], **kwargs) -> np.ndarray:
932
+ """Used for encoding the queries of retrieval or reranking tasks"""
933
+ return self.encode(queries, **kwargs)
934
+
935
+ def encode_corpus(self, corpus: Union[List[str], str, List[Dict[str, str]]], **kwargs) -> np.ndarray:
936
+ """Used for encoding the corpus of retrieval tasks"""
937
+ if isinstance(corpus, dict):
938
+ corpus = [corpus]
939
+ if isinstance(corpus, list) and isinstance(corpus[0], dict):
940
+ corpus = [
941
+ doc["text"] for doc in corpus
942
+ ]
943
+ return self.encode(corpus, **kwargs)
944
+
945
+ @torch.no_grad()
946
+ def encode(
947
+ self,
948
+ sentences: Union[List[str], str],
949
+ batch_size: int = 256,
950
+ max_length: int = 512,
951
+ instruction: str = "",
952
+ user_token: str = "<|start_header_id|>user<|end_header_id|>",
953
+ embed_instruction: bool = False,
954
+ embed_eos_token: str = "\n<|embed|>\n",
955
+ convert_to_tensor: bool = False,
956
+ add_special_tokens: bool = True,
957
+ **kwargs,
958
+ ) -> np.ndarray:
959
+
960
+ input_was_string = False
961
+ if isinstance(sentences, str):
962
+ sentences = [sentences]
963
+ input_was_string = True
964
+
965
+ all_embeddings, all_kv_caches = [], []
966
+ for start_index in tqdm(range(0, len(sentences), batch_size), desc="Batches", disable=len(sentences)<256):
967
+ sentences_batch = [
968
+ user_token + instruction + embed_eos_token + s for s in sentences[start_index:start_index + batch_size]
969
+ ]
970
+ # This will prepend the bos token if the tokenizer has `add_bos_token=True`
971
+ inputs = self.tokenizer(
972
+ sentences_batch,
973
+ padding=True,
974
+ truncation=True,
975
+ return_tensors='pt',
976
+ max_length=max_length,
977
+ add_special_tokens=add_special_tokens,
978
+ ).to(self.device)
979
+
980
+ last_hidden_state = self.model(inputs['input_ids'])['last_hidden_state']
981
+
982
+ if ("mean" in self.embedding_head.pooling_method) and not embed_instruction:
983
+ instruct_with_special_tokens = user_token + instruction + embed_eos_token
984
+ # Remove instruction tokens from the embeddings by masking them
985
+ instruction_tokens = self.tokenizer(
986
+ instruct_with_special_tokens,
987
+ padding=False,
988
+ truncation=True,
989
+ max_length=max_length,
990
+ add_special_tokens=add_special_tokens,
991
+ )["input_ids"]
992
+ inputs['attention_mask'][:, :len(instruction_tokens)] = 0
993
+
994
+ embeddings = self.embedding_head(last_hidden_state, inputs['attention_mask'])
995
+
996
+ if convert_to_tensor:
997
+ all_embeddings.append(embeddings)
998
+ else:
999
+ # NumPy does not support bfloat16
1000
+ all_embeddings.append(embeddings.cpu().to(torch.float32).numpy())
1001
+
1002
+ all_embeddings = (
1003
+ torch.cat(all_embeddings, dim=0) if convert_to_tensor else np.concatenate(all_embeddings, axis=0)
1004
+ )
1005
+ if input_was_string:
1006
+ all_embeddings = all_embeddings[0]
1007
+
1008
+ return all_embeddings
special_tokens_map.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {}
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
The diff for this file is too large to render. See raw diff