TechxGenus commited on
Commit
1a28bfc
·
verified ·
1 Parent(s): 47f4be7

Upload folder using huggingface_hub

Browse files
added_tokens.json ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {
2
+ "</line>": 32001,
3
+ "<pad>": 32000
4
+ }
config.json ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "1bitLLM/bitnet_b1_58-3B",
3
+ "architectures": [
4
+ "BitnetForCausalLM"
5
+ ],
6
+ "attention_bias": false,
7
+ "attention_dropout": 0.0,
8
+ "bos_token_id": 1,
9
+ "eos_token_id": 2,
10
+ "hidden_act": "silu",
11
+ "hidden_size": 3200,
12
+ "initializer_range": 0.02,
13
+ "input_bits": 8,
14
+ "intermediate_size": 8640,
15
+ "max_position_embeddings": 2048,
16
+ "model_type": "llama",
17
+ "num_attention_heads": 32,
18
+ "num_hidden_layers": 26,
19
+ "num_key_value_heads": 32,
20
+ "pad_token_id": 32000,
21
+ "pretraining_tp": 1,
22
+ "rms_norm_eps": 1e-05,
23
+ "rope_scaling": null,
24
+ "rope_theta": 10000.0,
25
+ "tie_word_embeddings": true,
26
+ "torch_dtype": "float16",
27
+ "transformers_version": "4.39.0",
28
+ "use_cache": true,
29
+ "vocab_size": 32002,
30
+ "weight_bits": 1
31
+ }
generation_config.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "bos_token_id": 0,
4
+ "eos_token_id": 2,
5
+ "pad_token_id": 1,
6
+ "transformers_version": "4.39.0"
7
+ }
model-00001-of-00002.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:6a14630115aa35ad89b55e7b5ecb86387a8e8bc5e69e81a780958b4496fcba7e
3
+ size 4995348376
model-00002-of-00002.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5ecf9adfdbedcec3df1de070066b93e63095f324029a764a08de8f720018c280
3
+ size 1652838912
model.safetensors.index.json ADDED
@@ -0,0 +1,243 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "metadata": {
3
+ "total_size": 6648160000
4
+ },
5
+ "weight_map": {
6
+ "model.embed_tokens.weight": "model-00001-of-00002.safetensors",
7
+ "model.layers.0.input_layernorm.weight": "model-00001-of-00002.safetensors",
8
+ "model.layers.0.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
9
+ "model.layers.0.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
10
+ "model.layers.0.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
11
+ "model.layers.0.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
12
+ "model.layers.0.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
13
+ "model.layers.0.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
14
+ "model.layers.0.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
15
+ "model.layers.0.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
16
+ "model.layers.1.input_layernorm.weight": "model-00001-of-00002.safetensors",
17
+ "model.layers.1.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
18
+ "model.layers.1.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
19
+ "model.layers.1.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
20
+ "model.layers.1.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
21
+ "model.layers.1.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
22
+ "model.layers.1.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
23
+ "model.layers.1.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
24
+ "model.layers.1.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
25
+ "model.layers.10.input_layernorm.weight": "model-00001-of-00002.safetensors",
26
+ "model.layers.10.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
27
+ "model.layers.10.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
28
+ "model.layers.10.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
29
+ "model.layers.10.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
30
+ "model.layers.10.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
31
+ "model.layers.10.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
32
+ "model.layers.10.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
33
+ "model.layers.10.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
34
+ "model.layers.11.input_layernorm.weight": "model-00001-of-00002.safetensors",
35
+ "model.layers.11.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
36
+ "model.layers.11.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
37
+ "model.layers.11.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
38
+ "model.layers.11.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
39
+ "model.layers.11.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
40
+ "model.layers.11.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
41
+ "model.layers.11.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
42
+ "model.layers.11.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
43
+ "model.layers.12.input_layernorm.weight": "model-00001-of-00002.safetensors",
44
+ "model.layers.12.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
45
+ "model.layers.12.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
46
+ "model.layers.12.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
47
+ "model.layers.12.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
48
+ "model.layers.12.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
49
+ "model.layers.12.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
50
+ "model.layers.12.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
51
+ "model.layers.12.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
52
+ "model.layers.13.input_layernorm.weight": "model-00001-of-00002.safetensors",
53
+ "model.layers.13.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
54
+ "model.layers.13.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
55
+ "model.layers.13.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
56
+ "model.layers.13.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
57
+ "model.layers.13.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
58
+ "model.layers.13.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
59
+ "model.layers.13.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
60
+ "model.layers.13.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
61
+ "model.layers.14.input_layernorm.weight": "model-00001-of-00002.safetensors",
62
+ "model.layers.14.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
63
+ "model.layers.14.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
64
+ "model.layers.14.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
65
+ "model.layers.14.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
66
+ "model.layers.14.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
67
+ "model.layers.14.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
68
+ "model.layers.14.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
69
+ "model.layers.14.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
70
+ "model.layers.15.input_layernorm.weight": "model-00001-of-00002.safetensors",
71
+ "model.layers.15.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
72
+ "model.layers.15.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
73
+ "model.layers.15.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
74
+ "model.layers.15.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
75
+ "model.layers.15.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
76
+ "model.layers.15.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
77
+ "model.layers.15.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
78
+ "model.layers.15.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
79
+ "model.layers.16.input_layernorm.weight": "model-00001-of-00002.safetensors",
80
+ "model.layers.16.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
81
+ "model.layers.16.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
82
+ "model.layers.16.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
83
+ "model.layers.16.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
84
+ "model.layers.16.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
85
+ "model.layers.16.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
86
+ "model.layers.16.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
87
+ "model.layers.16.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
88
+ "model.layers.17.input_layernorm.weight": "model-00001-of-00002.safetensors",
89
+ "model.layers.17.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
90
+ "model.layers.17.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
91
+ "model.layers.17.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
92
+ "model.layers.17.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
93
+ "model.layers.17.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
94
+ "model.layers.17.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
95
+ "model.layers.17.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
96
+ "model.layers.17.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
97
+ "model.layers.18.input_layernorm.weight": "model-00001-of-00002.safetensors",
98
+ "model.layers.18.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
99
+ "model.layers.18.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
100
+ "model.layers.18.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
101
+ "model.layers.18.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
102
+ "model.layers.18.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
103
+ "model.layers.18.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
104
+ "model.layers.18.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
105
+ "model.layers.18.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
106
+ "model.layers.19.input_layernorm.weight": "model-00002-of-00002.safetensors",
107
+ "model.layers.19.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
108
+ "model.layers.19.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
109
+ "model.layers.19.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
110
+ "model.layers.19.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
111
+ "model.layers.19.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
112
+ "model.layers.19.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
113
+ "model.layers.19.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
114
+ "model.layers.19.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
115
+ "model.layers.2.input_layernorm.weight": "model-00001-of-00002.safetensors",
116
+ "model.layers.2.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
117
+ "model.layers.2.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
118
+ "model.layers.2.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
119
+ "model.layers.2.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
120
+ "model.layers.2.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
121
+ "model.layers.2.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
122
+ "model.layers.2.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
123
+ "model.layers.2.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
124
+ "model.layers.20.input_layernorm.weight": "model-00002-of-00002.safetensors",
125
+ "model.layers.20.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
126
+ "model.layers.20.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
127
+ "model.layers.20.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
128
+ "model.layers.20.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
129
+ "model.layers.20.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
130
+ "model.layers.20.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
131
+ "model.layers.20.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
132
+ "model.layers.20.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
133
+ "model.layers.21.input_layernorm.weight": "model-00002-of-00002.safetensors",
134
+ "model.layers.21.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
135
+ "model.layers.21.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
136
+ "model.layers.21.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
137
+ "model.layers.21.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
138
+ "model.layers.21.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
139
+ "model.layers.21.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
140
+ "model.layers.21.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
141
+ "model.layers.21.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
142
+ "model.layers.22.input_layernorm.weight": "model-00002-of-00002.safetensors",
143
+ "model.layers.22.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
144
+ "model.layers.22.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
145
+ "model.layers.22.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
146
+ "model.layers.22.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
147
+ "model.layers.22.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
148
+ "model.layers.22.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
149
+ "model.layers.22.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
150
+ "model.layers.22.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
151
+ "model.layers.23.input_layernorm.weight": "model-00002-of-00002.safetensors",
152
+ "model.layers.23.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
153
+ "model.layers.23.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
154
+ "model.layers.23.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
155
+ "model.layers.23.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
156
+ "model.layers.23.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
157
+ "model.layers.23.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
158
+ "model.layers.23.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
159
+ "model.layers.23.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
160
+ "model.layers.24.input_layernorm.weight": "model-00002-of-00002.safetensors",
161
+ "model.layers.24.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
162
+ "model.layers.24.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
163
+ "model.layers.24.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
164
+ "model.layers.24.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
165
+ "model.layers.24.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
166
+ "model.layers.24.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
167
+ "model.layers.24.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
168
+ "model.layers.24.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
169
+ "model.layers.25.input_layernorm.weight": "model-00002-of-00002.safetensors",
170
+ "model.layers.25.mlp.down_proj.weight": "model-00002-of-00002.safetensors",
171
+ "model.layers.25.mlp.gate_proj.weight": "model-00002-of-00002.safetensors",
172
+ "model.layers.25.mlp.up_proj.weight": "model-00002-of-00002.safetensors",
173
+ "model.layers.25.post_attention_layernorm.weight": "model-00002-of-00002.safetensors",
174
+ "model.layers.25.self_attn.k_proj.weight": "model-00002-of-00002.safetensors",
175
+ "model.layers.25.self_attn.o_proj.weight": "model-00002-of-00002.safetensors",
176
+ "model.layers.25.self_attn.q_proj.weight": "model-00002-of-00002.safetensors",
177
+ "model.layers.25.self_attn.v_proj.weight": "model-00002-of-00002.safetensors",
178
+ "model.layers.3.input_layernorm.weight": "model-00001-of-00002.safetensors",
179
+ "model.layers.3.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
180
+ "model.layers.3.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
181
+ "model.layers.3.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
182
+ "model.layers.3.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
183
+ "model.layers.3.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
184
+ "model.layers.3.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
185
+ "model.layers.3.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
186
+ "model.layers.3.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
187
+ "model.layers.4.input_layernorm.weight": "model-00001-of-00002.safetensors",
188
+ "model.layers.4.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
189
+ "model.layers.4.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
190
+ "model.layers.4.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
191
+ "model.layers.4.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
192
+ "model.layers.4.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
193
+ "model.layers.4.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
194
+ "model.layers.4.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
195
+ "model.layers.4.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
196
+ "model.layers.5.input_layernorm.weight": "model-00001-of-00002.safetensors",
197
+ "model.layers.5.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
198
+ "model.layers.5.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
199
+ "model.layers.5.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
200
+ "model.layers.5.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
201
+ "model.layers.5.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
202
+ "model.layers.5.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
203
+ "model.layers.5.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
204
+ "model.layers.5.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
205
+ "model.layers.6.input_layernorm.weight": "model-00001-of-00002.safetensors",
206
+ "model.layers.6.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
207
+ "model.layers.6.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
208
+ "model.layers.6.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
209
+ "model.layers.6.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
210
+ "model.layers.6.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
211
+ "model.layers.6.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
212
+ "model.layers.6.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
213
+ "model.layers.6.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
214
+ "model.layers.7.input_layernorm.weight": "model-00001-of-00002.safetensors",
215
+ "model.layers.7.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
216
+ "model.layers.7.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
217
+ "model.layers.7.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
218
+ "model.layers.7.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
219
+ "model.layers.7.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
220
+ "model.layers.7.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
221
+ "model.layers.7.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
222
+ "model.layers.7.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
223
+ "model.layers.8.input_layernorm.weight": "model-00001-of-00002.safetensors",
224
+ "model.layers.8.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
225
+ "model.layers.8.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
226
+ "model.layers.8.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
227
+ "model.layers.8.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
228
+ "model.layers.8.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
229
+ "model.layers.8.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
230
+ "model.layers.8.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
231
+ "model.layers.8.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
232
+ "model.layers.9.input_layernorm.weight": "model-00001-of-00002.safetensors",
233
+ "model.layers.9.mlp.down_proj.weight": "model-00001-of-00002.safetensors",
234
+ "model.layers.9.mlp.gate_proj.weight": "model-00001-of-00002.safetensors",
235
+ "model.layers.9.mlp.up_proj.weight": "model-00001-of-00002.safetensors",
236
+ "model.layers.9.post_attention_layernorm.weight": "model-00001-of-00002.safetensors",
237
+ "model.layers.9.self_attn.k_proj.weight": "model-00001-of-00002.safetensors",
238
+ "model.layers.9.self_attn.o_proj.weight": "model-00001-of-00002.safetensors",
239
+ "model.layers.9.self_attn.q_proj.weight": "model-00001-of-00002.safetensors",
240
+ "model.layers.9.self_attn.v_proj.weight": "model-00001-of-00002.safetensors",
241
+ "model.norm.weight": "model-00002-of-00002.safetensors"
242
+ }
243
+ }
special_tokens_map.json ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "additional_special_tokens": [
3
+ "</line>"
4
+ ],
5
+ "bos_token": {
6
+ "content": "<s>",
7
+ "lstrip": false,
8
+ "normalized": false,
9
+ "rstrip": false,
10
+ "single_word": false
11
+ },
12
+ "eos_token": {
13
+ "content": "</s>",
14
+ "lstrip": false,
15
+ "normalized": false,
16
+ "rstrip": false,
17
+ "single_word": false
18
+ },
19
+ "pad_token": {
20
+ "content": "<pad>",
21
+ "lstrip": false,
22
+ "normalized": false,
23
+ "rstrip": false,
24
+ "single_word": false
25
+ },
26
+ "unk_token": {
27
+ "content": "<unk>",
28
+ "lstrip": false,
29
+ "normalized": false,
30
+ "rstrip": false,
31
+ "single_word": false
32
+ }
33
+ }
tokenization_bitnet.py ADDED
@@ -0,0 +1,482 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2022 EleutherAI 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
+
21
+ """Tokenization classes for LLaMA."""
22
+ import os
23
+ from shutil import copyfile
24
+ from typing import TYPE_CHECKING, Any, Dict, List, Optional, Tuple
25
+
26
+ import sentencepiece as spm
27
+
28
+ from transformers.convert_slow_tokenizer import import_protobuf
29
+ from transformers.tokenization_utils import AddedToken, PreTrainedTokenizer
30
+ from transformers.utils import logging
31
+
32
+
33
+ if TYPE_CHECKING:
34
+ from transformers.tokenization_utils_base import TextInput
35
+
36
+ logger = logging.get_logger(__name__)
37
+
38
+ VOCAB_FILES_NAMES = {"vocab_file": "tokenizer.model"}
39
+
40
+ PRETRAINED_VOCAB_FILES_MAP = {
41
+ "vocab_file": {
42
+ "hf-internal-testing/llama-tokenizer": "https://huggingface.co/hf-internal-testing/llama-tokenizer/resolve/main/tokenizer.model",
43
+ },
44
+ "tokenizer_file": {
45
+ "hf-internal-testing/llama-tokenizer": "https://huggingface.co/hf-internal-testing/llama-tokenizer/resolve/main/tokenizer_config.json",
46
+ },
47
+ }
48
+ PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES = {
49
+ "hf-internal-testing/llama-tokenizer": 2048,
50
+ }
51
+ SPIECE_UNDERLINE = "▁"
52
+
53
+ B_INST, E_INST = "[INST]", "[/INST]"
54
+ B_SYS, E_SYS = "<<SYS>>\n", "\n<</SYS>>\n\n"
55
+
56
+ # fmt: off
57
+ DEFAULT_SYSTEM_PROMPT = """You are a helpful, respectful and honest assistant. Always answer as helpfully as possible, while being safe. Your \
58
+ answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. Please ensure\
59
+ that your responses are socially unbiased and positive in nature.
60
+
61
+ If a question does not make any sense, or is not factually coherent, explain why instead of answering something not \
62
+ correct. If you don't know the answer to a question, please don't share false information."""
63
+ # fmt: on
64
+
65
+
66
+ class BitnetTokenizer(PreTrainedTokenizer):
67
+ """
68
+ Construct a Bitnet tokenizer. Based on byte-level Byte-Pair-Encoding. The default padding token is unset as there is
69
+ no padding token in the original model.
70
+
71
+ Args:
72
+ vocab_file (`str`):
73
+ Path to the vocabulary file.
74
+ unk_token (`str` or `tokenizers.AddedToken`, *optional*, defaults to `"<unk>"`):
75
+ The unknown token. A token that is not in the vocabulary cannot be converted to an ID and is set to be this
76
+ token instead.
77
+ bos_token (`str` or `tokenizers.AddedToken`, *optional*, defaults to `"<s>"`):
78
+ The beginning of sequence token that was used during pretraining. Can be used a sequence classifier token.
79
+ eos_token (`str` or `tokenizers.AddedToken`, *optional*, defaults to `"</s>"`):
80
+ The end of sequence token.
81
+ pad_token (`str` or `tokenizers.AddedToken`, *optional*):
82
+ A special token used to make arrays of tokens the same size for batching purpose. Will then be ignored by
83
+ attention mechanisms or loss computation.
84
+ sp_model_kwargs (`Dict[str, Any]`, `Optional`, *optional*):
85
+ Will be passed to the `SentencePieceProcessor.__init__()` method. The [Python wrapper for
86
+ SentencePiece](https://github.com/google/sentencepiece/tree/master/python) can be used, among other things,
87
+ to set:
88
+
89
+ - `enable_sampling`: Enable subword regularization.
90
+ - `nbest_size`: Sampling parameters for unigram. Invalid for BPE-Dropout.
91
+
92
+ - `nbest_size = {0,1}`: No sampling is performed.
93
+ - `nbest_size > 1`: samples from the nbest_size results.
94
+ - `nbest_size < 0`: assuming that nbest_size is infinite and samples from the all hypothesis (lattice)
95
+ using forward-filtering-and-backward-sampling algorithm.
96
+
97
+ - `alpha`: Smoothing parameter for unigram sampling, and dropout probability of merge operations for
98
+ BPE-dropout.
99
+
100
+ add_bos_token (`bool`, *optional*, defaults to `True`):
101
+ Whether or not to add an `bos_token` at the start of sequences.
102
+ add_eos_token (`bool`, *optional*, defaults to `False`):
103
+ Whether or not to add an `eos_token` at the end of sequences.
104
+ clean_up_tokenization_spaces (`bool`, *optional*, defaults to `False`):
105
+ Whether or not to cleanup spaces after decoding, cleanup consists in removing potential artifacts like
106
+ extra spaces.
107
+ use_default_system_prompt (`bool`, *optional*, defaults to `False`):
108
+ Whether or not the default system prompt for Bitnet should be used.
109
+ spaces_between_special_tokens (`bool`, *optional*, defaults to `False`):
110
+ Whether or not to add spaces between special tokens.
111
+ legacy (`bool`, *optional*):
112
+ Whether or not the `legacy` behavior of the tokenizer should be used. Legacy is before the merge of #24622
113
+ and #25224 which includes fixes to properly handle tokens that appear after special tokens. A simple
114
+ example:
115
+
116
+ - `legacy=True`:
117
+ ```python
118
+ >>> from transformers import T5Tokenizer
119
+
120
+ >>> tokenizer = T5Tokenizer.from_pretrained("google-t5/t5-base", legacy=True)
121
+ >>> tokenizer.encode("Hello <extra_id_0>.")
122
+ [8774, 32099, 3, 5, 1]
123
+ ```
124
+ - `legacy=False`:
125
+ ```python
126
+ >>> from transformers import T5Tokenizer
127
+
128
+ >>> tokenizer = T5Tokenizer.from_pretrained("google-t5/t5-base", legacy=False)
129
+ >>> tokenizer.encode("Hello <extra_id_0>.") # the extra space `[3]` is no longer here
130
+ [8774, 32099, 5, 1]
131
+ ```
132
+ Checkout the [pull request](https://github.com/huggingface/transformers/pull/24565) for more details.
133
+ add_prefix_space (`bool`, *optional*, defaults to `True`):
134
+ Whether or not to add an initial space to the input. This allows to treat the leading word just as any
135
+ other word.
136
+
137
+ """
138
+
139
+ vocab_files_names = VOCAB_FILES_NAMES
140
+ pretrained_vocab_files_map = PRETRAINED_VOCAB_FILES_MAP
141
+ max_model_input_sizes = PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
142
+ model_input_names = ["input_ids", "attention_mask"]
143
+
144
+ def __init__(
145
+ self,
146
+ vocab_file,
147
+ unk_token="<unk>",
148
+ bos_token="<s>",
149
+ eos_token="</s>",
150
+ pad_token=None,
151
+ sp_model_kwargs: Optional[Dict[str, Any]] = None,
152
+ add_bos_token=True,
153
+ add_eos_token=False,
154
+ clean_up_tokenization_spaces=False,
155
+ use_default_system_prompt=False,
156
+ spaces_between_special_tokens=False,
157
+ legacy=None,
158
+ add_prefix_space=True,
159
+ **kwargs,
160
+ ):
161
+ self.sp_model_kwargs = {} if sp_model_kwargs is None else sp_model_kwargs
162
+ bos_token = AddedToken(bos_token, normalized=False, special=True) if isinstance(bos_token, str) else bos_token
163
+ eos_token = AddedToken(eos_token, normalized=False, special=True) if isinstance(eos_token, str) else eos_token
164
+ unk_token = AddedToken(unk_token, normalized=False, special=True) if isinstance(unk_token, str) else unk_token
165
+ pad_token = AddedToken(pad_token, normalized=False, special=True) if isinstance(pad_token, str) else pad_token
166
+
167
+ if legacy is None:
168
+ logger.warning_once(
169
+ f"You are using the default legacy behaviour of the {self.__class__}. This is"
170
+ " expected, and simply means that the `legacy` (previous) behavior will be used so nothing changes for you."
171
+ " If you want to use the new behaviour, set `legacy=False`. This should only be set if you understand what it"
172
+ " means, and thoroughly read the reason why this was added as explained in"
173
+ " https://github.com/huggingface/transformers/pull/24565"
174
+ )
175
+ legacy = True
176
+
177
+ self.legacy = legacy
178
+ self.vocab_file = vocab_file
179
+ self.add_bos_token = add_bos_token
180
+ self.add_eos_token = add_eos_token
181
+ self.use_default_system_prompt = use_default_system_prompt
182
+ self.sp_model = self.get_spm_processor(kwargs.pop("from_slow", False))
183
+ self.add_prefix_space = add_prefix_space
184
+
185
+ super().__init__(
186
+ bos_token=bos_token,
187
+ eos_token=eos_token,
188
+ unk_token=unk_token,
189
+ pad_token=pad_token,
190
+ add_bos_token=add_bos_token,
191
+ add_eos_token=add_eos_token,
192
+ sp_model_kwargs=self.sp_model_kwargs,
193
+ clean_up_tokenization_spaces=clean_up_tokenization_spaces,
194
+ use_default_system_prompt=use_default_system_prompt,
195
+ spaces_between_special_tokens=spaces_between_special_tokens,
196
+ legacy=legacy,
197
+ add_prefix_space=add_prefix_space,
198
+ **kwargs,
199
+ )
200
+
201
+ @property
202
+ def unk_token_length(self):
203
+ return len(self.sp_model.encode(str(self.unk_token)))
204
+
205
+ # Copied from transformers.models.t5.tokenization_t5.T5Tokenizer.get_spm_processor
206
+ def get_spm_processor(self, from_slow=False):
207
+ tokenizer = spm.SentencePieceProcessor(**self.sp_model_kwargs)
208
+ if self.legacy or from_slow: # no dependency on protobuf
209
+ tokenizer.Load(self.vocab_file)
210
+ return tokenizer
211
+
212
+ with open(self.vocab_file, "rb") as f:
213
+ sp_model = f.read()
214
+ model_pb2 = import_protobuf(f"The new behaviour of {self.__class__.__name__} (with `self.legacy = False`)")
215
+ model = model_pb2.ModelProto.FromString(sp_model)
216
+ normalizer_spec = model_pb2.NormalizerSpec()
217
+ normalizer_spec.add_dummy_prefix = False
218
+ model.normalizer_spec.MergeFrom(normalizer_spec)
219
+ sp_model = model.SerializeToString()
220
+ tokenizer.LoadFromSerializedProto(sp_model)
221
+ return tokenizer
222
+
223
+ def __getstate__(self):
224
+ state = self.__dict__.copy()
225
+ state["sp_model"] = None
226
+ state["sp_model_proto"] = self.sp_model.serialized_model_proto()
227
+ return state
228
+
229
+ def __setstate__(self, d):
230
+ self.__dict__ = d
231
+ self.sp_model = spm.SentencePieceProcessor(**self.sp_model_kwargs)
232
+ self.sp_model.LoadFromSerializedProto(self.sp_model_proto)
233
+
234
+ @property
235
+ def vocab_size(self):
236
+ """Returns vocab size"""
237
+ return self.sp_model.get_piece_size()
238
+
239
+ def get_vocab(self):
240
+ """Returns vocab as a dict"""
241
+ vocab = {self.convert_ids_to_tokens(i): i for i in range(self.vocab_size)}
242
+ vocab.update(self.added_tokens_encoder)
243
+ return vocab
244
+
245
+ # Copied from transformers.models.t5.tokenization_t5.T5Tokenizer.tokenize
246
+ def tokenize(self, text: "TextInput", **kwargs) -> List[str]:
247
+ """
248
+ Converts a string to a list of tokens. If `self.legacy` is set to `False`, a prefix token is added unless the
249
+ first token is special.
250
+ """
251
+ if self.legacy or len(text) == 0:
252
+ return super().tokenize(text, **kwargs)
253
+
254
+ text = text.replace(SPIECE_UNDERLINE, " ")
255
+ if self.add_prefix_space:
256
+ text = SPIECE_UNDERLINE + text
257
+
258
+ tokens = super().tokenize(text, **kwargs)
259
+
260
+ if len(tokens) > 1 and tokens[0] == SPIECE_UNDERLINE and tokens[1] in self.all_special_tokens:
261
+ tokens = tokens[1:]
262
+ return tokens
263
+
264
+ # Copied from transformers.models.t5.tokenization_t5.T5Tokenizer._tokenize
265
+ def _tokenize(self, text, **kwargs):
266
+ """
267
+ Returns a tokenized string.
268
+
269
+ We de-activated the `add_dummy_prefix` option, thus the sentencepiece internals will always strip any
270
+ SPIECE_UNDERLINE. For example: `self.sp_model.encode(f"{SPIECE_UNDERLINE}Hey", out_type = str)` will give
271
+ `['H', 'e', 'y']` instead of `['▁He', 'y']`. Thus we always encode `f"{unk_token}text"` and strip the
272
+ `unk_token`. Here is an example with `unk_token = "<unk>"` and `unk_token_length = 4`.
273
+ `self.tokenizer.sp_model.encode("<unk> Hey", out_type = str)[4:]`.
274
+ """
275
+ tokens = self.sp_model.encode(text, out_type=str)
276
+ if self.legacy or not text.startswith((SPIECE_UNDERLINE, " ")):
277
+ return tokens
278
+
279
+ # 1. Encode string + prefix ex: "<unk> Hey"
280
+ tokens = self.sp_model.encode(self.unk_token + text, out_type=str)
281
+ # 2. Remove self.unk_token from ['<','unk','>', '▁Hey']
282
+ return tokens[self.unk_token_length :] if len(tokens) >= self.unk_token_length else tokens
283
+
284
+ def _convert_token_to_id(self, token):
285
+ """Converts a token (str) in an id using the vocab."""
286
+ return self.sp_model.piece_to_id(token)
287
+
288
+ def _convert_id_to_token(self, index):
289
+ """Converts an index (integer) in a token (str) using the vocab."""
290
+ token = self.sp_model.IdToPiece(index)
291
+ return token
292
+
293
+ def convert_tokens_to_string(self, tokens):
294
+ """Converts a sequence of tokens (string) in a single string."""
295
+ # since we manually add the prefix space, we have to remove it when decoding
296
+ if tokens[0].startswith(SPIECE_UNDERLINE) and self.add_prefix_space:
297
+ tokens[0] = tokens[0][1:]
298
+
299
+ current_sub_tokens = []
300
+ out_string = ""
301
+ prev_is_special = False
302
+ for i, token in enumerate(tokens):
303
+ # make sure that special tokens are not decoded using sentencepiece model
304
+ if token in self.all_special_tokens:
305
+ if not prev_is_special and i != 0 and self.legacy:
306
+ out_string += " "
307
+ out_string += self.sp_model.decode(current_sub_tokens) + token
308
+ prev_is_special = True
309
+ current_sub_tokens = []
310
+ else:
311
+ current_sub_tokens.append(token)
312
+ prev_is_special = False
313
+ out_string += self.sp_model.decode(current_sub_tokens)
314
+ return out_string
315
+
316
+ def save_vocabulary(self, save_directory, filename_prefix: Optional[str] = None) -> Tuple[str]:
317
+ """
318
+ Save the vocabulary and special tokens file to a directory.
319
+
320
+ Args:
321
+ save_directory (`str`):
322
+ The directory in which to save the vocabulary.
323
+
324
+ Returns:
325
+ `Tuple(str)`: Paths to the files saved.
326
+ """
327
+ if not os.path.isdir(save_directory):
328
+ logger.error(f"Vocabulary path ({save_directory}) should be a directory")
329
+ return
330
+ out_vocab_file = os.path.join(
331
+ save_directory, (filename_prefix + "-" if filename_prefix else "") + VOCAB_FILES_NAMES["vocab_file"]
332
+ )
333
+
334
+ if os.path.abspath(self.vocab_file) != os.path.abspath(out_vocab_file) and os.path.isfile(self.vocab_file):
335
+ copyfile(self.vocab_file, out_vocab_file)
336
+ elif not os.path.isfile(self.vocab_file):
337
+ with open(out_vocab_file, "wb") as fi:
338
+ content_spiece_model = self.sp_model.serialized_model_proto()
339
+ fi.write(content_spiece_model)
340
+
341
+ return (out_vocab_file,)
342
+
343
+ def build_inputs_with_special_tokens(self, token_ids_0, token_ids_1=None):
344
+ bos_token_id = [self.bos_token_id] if self.add_bos_token else []
345
+ eos_token_id = [self.eos_token_id] if self.add_eos_token else []
346
+
347
+ output = bos_token_id + token_ids_0 + eos_token_id
348
+
349
+ if token_ids_1 is not None:
350
+ output = output + bos_token_id + token_ids_1 + eos_token_id
351
+
352
+ return output
353
+
354
+ def get_special_tokens_mask(
355
+ self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None, already_has_special_tokens: bool = False
356
+ ) -> List[int]:
357
+ """
358
+ Retrieve sequence ids from a token list that has no special tokens added. This method is called when adding
359
+ special tokens using the tokenizer `prepare_for_model` method.
360
+
361
+ Args:
362
+ token_ids_0 (`List[int]`):
363
+ List of IDs.
364
+ token_ids_1 (`List[int]`, *optional*):
365
+ Optional second list of IDs for sequence pairs.
366
+ already_has_special_tokens (`bool`, *optional*, defaults to `False`):
367
+ Whether or not the token list is already formatted with special tokens for the model.
368
+
369
+ Returns:
370
+ `List[int]`: A list of integers in the range [0, 1]: 1 for a special token, 0 for a sequence token.
371
+ """
372
+ if already_has_special_tokens:
373
+ return super().get_special_tokens_mask(
374
+ token_ids_0=token_ids_0, token_ids_1=token_ids_1, already_has_special_tokens=True
375
+ )
376
+
377
+ bos_token_id = [1] if self.add_bos_token else []
378
+ eos_token_id = [1] if self.add_eos_token else []
379
+
380
+ if token_ids_1 is None:
381
+ return bos_token_id + ([0] * len(token_ids_0)) + eos_token_id
382
+ return (
383
+ bos_token_id
384
+ + ([0] * len(token_ids_0))
385
+ + eos_token_id
386
+ + bos_token_id
387
+ + ([0] * len(token_ids_1))
388
+ + eos_token_id
389
+ )
390
+
391
+ def create_token_type_ids_from_sequences(
392
+ self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None
393
+ ) -> List[int]:
394
+ """
395
+ Creates a mask from the two sequences passed to be used in a sequence-pair classification task. An ALBERT
396
+ sequence pair mask has the following format:
397
+
398
+ ```
399
+ 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1
400
+ | first sequence | second sequence |
401
+ ```
402
+
403
+ if token_ids_1 is None, only returns the first portion of the mask (0s).
404
+
405
+ Args:
406
+ token_ids_0 (`List[int]`):
407
+ List of ids.
408
+ token_ids_1 (`List[int]`, *optional*):
409
+ Optional second list of IDs for sequence pairs.
410
+
411
+ Returns:
412
+ `List[int]`: List of [token type IDs](../glossary#token-type-ids) according to the given sequence(s).
413
+ """
414
+ bos_token_id = [self.bos_token_id] if self.add_bos_token else []
415
+ eos_token_id = [self.eos_token_id] if self.add_eos_token else []
416
+
417
+ output = [0] * len(bos_token_id + token_ids_0 + eos_token_id)
418
+
419
+ if token_ids_1 is not None:
420
+ output += [1] * len(bos_token_id + token_ids_1 + eos_token_id)
421
+
422
+ return output
423
+
424
+ @property
425
+ def default_chat_template(self):
426
+ """
427
+ LLaMA uses [INST] and [/INST] to indicate user messages, and <<SYS>> and <</SYS>> to indicate system messages.
428
+ Assistant messages do not have special tokens, because LLaMA chat models are generally trained with strict
429
+ user/assistant/user/assistant message ordering, and so assistant messages can be identified from the ordering
430
+ rather than needing special tokens. The system message is partly 'embedded' in the first user message, which
431
+ results in an unusual token ordering when it is present. This template should definitely be changed if you wish
432
+ to fine-tune a model with more flexible role ordering!
433
+
434
+ The output should look something like:
435
+
436
+ <bos>[INST] B_SYS SystemPrompt E_SYS Prompt [/INST] Answer <eos><bos>[INST] Prompt [/INST] Answer <eos>
437
+ <bos>[INST] Prompt [/INST]
438
+
439
+ The reference for this chat template is [this code
440
+ snippet](https://github.com/facebookresearch/llama/blob/556949fdfb72da27c2f4a40b7f0e4cf0b8153a28/llama/generation.py#L320-L362)
441
+ in the original repository.
442
+ """
443
+ logger.warning_once(
444
+ "\nNo chat template is defined for this tokenizer - using the default template "
445
+ f"for the {self.__class__.__name__} class. If the default is not appropriate for "
446
+ "your model, please set `tokenizer.chat_template` to an appropriate template. "
447
+ "See https://huggingface.co/docs/transformers/main/chat_templating for more information.\n"
448
+ )
449
+ template = (
450
+ "{% if messages[0]['role'] == 'system' %}"
451
+ "{% set loop_messages = messages[1:] %}" # Extract system message if it's present
452
+ "{% set system_message = messages[0]['content'] %}"
453
+ "{% elif USE_DEFAULT_PROMPT == true and not '<<SYS>>' in messages[0]['content'] %}"
454
+ "{% set loop_messages = messages %}" # Or use the default system message if the flag is set
455
+ "{% set system_message = 'DEFAULT_SYSTEM_MESSAGE' %}"
456
+ "{% else %}"
457
+ "{% set loop_messages = messages %}"
458
+ "{% set system_message = false %}"
459
+ "{% endif %}"
460
+ "{% for message in loop_messages %}" # Loop over all non-system messages
461
+ "{% if (message['role'] == 'user') != (loop.index0 % 2 == 0) %}"
462
+ "{{ raise_exception('Conversation roles must alternate user/assistant/user/assistant/...') }}"
463
+ "{% endif %}"
464
+ "{% if loop.index0 == 0 and system_message != false %}" # Embed system message in first message
465
+ "{% set content = '<<SYS>>\\n' + system_message + '\\n<</SYS>>\\n\\n' + message['content'] %}"
466
+ "{% else %}"
467
+ "{% set content = message['content'] %}"
468
+ "{% endif %}"
469
+ "{% if message['role'] == 'user' %}" # After all of that, handle messages/roles in a fairly normal way
470
+ "{{ bos_token + '[INST] ' + content.strip() + ' [/INST]' }}"
471
+ "{% elif message['role'] == 'system' %}"
472
+ "{{ '<<SYS>>\\n' + content.strip() + '\\n<</SYS>>\\n\\n' }}"
473
+ "{% elif message['role'] == 'assistant' %}"
474
+ "{{ ' ' + content.strip() + ' ' + eos_token }}"
475
+ "{% endif %}"
476
+ "{% endfor %}"
477
+ )
478
+ template = template.replace("USE_DEFAULT_PROMPT", "true" if self.use_default_system_prompt else "false")
479
+ default_message = DEFAULT_SYSTEM_PROMPT.replace("\n", "\\n").replace("'", "\\'")
480
+ template = template.replace("DEFAULT_SYSTEM_MESSAGE", default_message)
481
+
482
+ return template
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer.model ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9e556afd44213b6bd1be2b850ebbbd98f5481437a8021afaf58ee7fb1818d347
3
+ size 499723
tokenizer_config.json ADDED
@@ -0,0 +1,62 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_bos_token": true,
3
+ "add_eos_token": false,
4
+ "add_prefix_space": true,
5
+ "added_tokens_decoder": {
6
+ "0": {
7
+ "content": "<unk>",
8
+ "lstrip": false,
9
+ "normalized": false,
10
+ "rstrip": false,
11
+ "single_word": false,
12
+ "special": true
13
+ },
14
+ "1": {
15
+ "content": "<s>",
16
+ "lstrip": false,
17
+ "normalized": false,
18
+ "rstrip": false,
19
+ "single_word": false,
20
+ "special": true
21
+ },
22
+ "2": {
23
+ "content": "</s>",
24
+ "lstrip": false,
25
+ "normalized": false,
26
+ "rstrip": false,
27
+ "single_word": false,
28
+ "special": true
29
+ },
30
+ "32000": {
31
+ "content": "<pad>",
32
+ "lstrip": false,
33
+ "normalized": false,
34
+ "rstrip": false,
35
+ "single_word": false,
36
+ "special": true
37
+ },
38
+ "32001": {
39
+ "content": "</line>",
40
+ "lstrip": false,
41
+ "normalized": false,
42
+ "rstrip": false,
43
+ "single_word": false,
44
+ "special": true
45
+ }
46
+ },
47
+ "additional_special_tokens": [
48
+ "</line>"
49
+ ],
50
+ "bos_token": "<s>",
51
+ "clean_up_tokenization_spaces": false,
52
+ "eos_token": "</s>",
53
+ "legacy": false,
54
+ "model_max_length": 1000000000000000019884624838656,
55
+ "pad_token": "<pad>",
56
+ "padding_side": "right",
57
+ "sp_model_kwargs": {},
58
+ "spaces_between_special_tokens": false,
59
+ "tokenizer_class": "BitnetTokenizer",
60
+ "unk_token": "<unk>",
61
+ "use_default_system_prompt": false
62
+ }