zyliu commited on
Commit
787ce4f
1 Parent(s): 31b1757

init commit

Browse files
added_tokens.json ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "</box>": 92552,
3
+ "</det>": 92559,
4
+ "</gen>": 92563,
5
+ "</grd>": 92561,
6
+ "</img>": 92545,
7
+ "</quad>": 92548,
8
+ "</ref>": 92550,
9
+ "</reg>": 92557,
10
+ "<IMG_CONTEXT>": 92546,
11
+ "<box>": 92551,
12
+ "<det>": 92558,
13
+ "<gen>": 92562,
14
+ "<grd>": 92560,
15
+ "<image>": 92554,
16
+ "<img>": 92544,
17
+ "<quad>": 92547,
18
+ "<ref>": 92549,
19
+ "<reg>": 92556,
20
+ "<region>": 92555,
21
+ "[DET]": 92564,
22
+ "[EDIT]": 92569,
23
+ "[EMB2]": 92571,
24
+ "[EMB3]": 92572,
25
+ "[EMB4]": 92573,
26
+ "[EMB5]": 92574,
27
+ "[EMB6]": 92575,
28
+ "[EMB7]": 92576,
29
+ "[EMB8]": 92577,
30
+ "[EMB]": 92570,
31
+ "[GEN]": 92568,
32
+ "[GRD]": 92565,
33
+ "[PAD]": 92553,
34
+ "[POSE]": 92567,
35
+ "[SEG]": 92566
36
+ }
all_results.json ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "epoch": 1.0,
3
+ "train_loss": 12.693984882221208,
4
+ "train_runtime": 42292.4042,
5
+ "train_samples": 2916996,
6
+ "train_samples_per_second": 68.972,
7
+ "train_steps_per_second": 0.18
8
+ }
config.json ADDED
@@ -0,0 +1,400 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_commit_hash": null,
3
+ "_name_or_path": "work_dirs/internvl2_8b_scaleup_s3_2_v1",
4
+ "architectures": [
5
+ "VisionLLMv2Model"
6
+ ],
7
+ "downsample_ratio": 0.5,
8
+ "gdino_config": {
9
+ "_attn_implementation_internal": null,
10
+ "_commit_hash": null,
11
+ "_name_or_path": "",
12
+ "`_dropout": 0.0,
13
+ "activation_dropout": 0.0,
14
+ "activation_function": "relu",
15
+ "add_cross_attention": false,
16
+ "architectures": [
17
+ "GroundingDinoForObjectDetection"
18
+ ],
19
+ "attention_dropout": 0.0,
20
+ "auxiliary_loss": true,
21
+ "backbone_config": {
22
+ "model_type": "internimage-H"
23
+ },
24
+ "bad_words_ids": null,
25
+ "bbox_cost": 5.0,
26
+ "bbox_loss_coefficient": 5.0,
27
+ "begin_suppress_tokens": null,
28
+ "bos_token_id": null,
29
+ "box_cost": 5.0,
30
+ "box_weight": 5.0,
31
+ "chunk_size_feed_forward": 0,
32
+ "class_cost": 2.0,
33
+ "class_weight": 2.0,
34
+ "cross_attention_hidden_size": null,
35
+ "d_model": 256,
36
+ "decoder_attention_heads": 8,
37
+ "decoder_bbox_embed_share": true,
38
+ "decoder_ffn_dim": 2048,
39
+ "decoder_layers": 6,
40
+ "decoder_n_points": 4,
41
+ "decoder_start_token_id": null,
42
+ "dice_cost": 5.0,
43
+ "dice_weight": 5.0,
44
+ "disable_custom_kernels": false,
45
+ "diversity_penalty": 0.0,
46
+ "do_sample": false,
47
+ "dropout": 0.1,
48
+ "early_stopping": false,
49
+ "embedding_init_target": true,
50
+ "encoder_attention_heads": 8,
51
+ "encoder_ffn_dim": 2048,
52
+ "encoder_layers": 6,
53
+ "encoder_n_points": 4,
54
+ "encoder_no_repeat_ngram_size": 0,
55
+ "eos_token_id": null,
56
+ "exponential_decay_length_penalty": null,
57
+ "finetuning_task": null,
58
+ "focal_alpha": 0.25,
59
+ "forced_bos_token_id": null,
60
+ "forced_eos_token_id": null,
61
+ "fusion_dropout": 0.0,
62
+ "fusion_droppath": 0.1,
63
+ "giou_cost": 2.0,
64
+ "giou_loss_coefficient": 2.0,
65
+ "giou_weight": 2.0,
66
+ "id2label": {
67
+ "0": "LABEL_0",
68
+ "1": "LABEL_1"
69
+ },
70
+ "init_std": 0.02,
71
+ "is_decoder": false,
72
+ "is_encoder_decoder": true,
73
+ "l_hidden_size": 4096,
74
+ "label2id": {
75
+ "LABEL_0": 0,
76
+ "LABEL_1": 1
77
+ },
78
+ "length_penalty": 1.0,
79
+ "mask_cost": 5.0,
80
+ "mask_dim": 256,
81
+ "mask_weight": 5.0,
82
+ "max_length": 20,
83
+ "max_text_len": 256,
84
+ "min_length": 0,
85
+ "model_type": "grounding-dino",
86
+ "no_repeat_ngram_size": 0,
87
+ "norm": "GN",
88
+ "num_beam_groups": 1,
89
+ "num_beams": 1,
90
+ "num_embs": 4,
91
+ "num_feature_levels": 4,
92
+ "num_queries": 900,
93
+ "num_return_sequences": 1,
94
+ "output_attentions": false,
95
+ "output_hidden_states": false,
96
+ "output_scores": false,
97
+ "pad_token_id": null,
98
+ "position_embedding_type": "sine",
99
+ "positional_embedding_temperature": 20,
100
+ "prefix": null,
101
+ "problem_type": null,
102
+ "pruned_heads": {},
103
+ "query_dim": 4,
104
+ "remove_invalid_values": false,
105
+ "repetition_penalty": 1.0,
106
+ "return_dict": true,
107
+ "return_dict_in_generate": false,
108
+ "sep_token_id": null,
109
+ "suppress_tokens": null,
110
+ "task_specific_params": null,
111
+ "temperature": 1.0,
112
+ "text_backbone_config": {
113
+ "_name_or_path": "",
114
+ "add_cross_attention": false,
115
+ "architectures": null,
116
+ "attention_probs_dropout_prob": 0.1,
117
+ "bad_words_ids": null,
118
+ "begin_suppress_tokens": null,
119
+ "bos_token_id": null,
120
+ "chunk_size_feed_forward": 0,
121
+ "cross_attention_hidden_size": null,
122
+ "decoder_start_token_id": null,
123
+ "diversity_penalty": 0.0,
124
+ "do_sample": false,
125
+ "early_stopping": false,
126
+ "encoder_no_repeat_ngram_size": 0,
127
+ "eos_token_id": null,
128
+ "exponential_decay_length_penalty": null,
129
+ "finetuning_task": null,
130
+ "forced_bos_token_id": null,
131
+ "forced_eos_token_id": null,
132
+ "hidden_act": "gelu",
133
+ "hidden_dropout_prob": 0.1,
134
+ "hidden_size": 768,
135
+ "id2label": {
136
+ "0": "LABEL_0",
137
+ "1": "LABEL_1"
138
+ },
139
+ "init_std": 0.02,
140
+ "intermediate_size": 3072,
141
+ "is_decoder": false,
142
+ "is_encoder_decoder": false,
143
+ "label2id": {
144
+ "LABEL_0": 0,
145
+ "LABEL_1": 1
146
+ },
147
+ "layer_norm_eps": 1e-12,
148
+ "length_penalty": 1.0,
149
+ "max_length": 20,
150
+ "max_position_embeddings": 512,
151
+ "min_length": 0,
152
+ "model_type": "grounding-dino-text-prenet",
153
+ "no_repeat_ngram_size": 0,
154
+ "num_attention_heads": 12,
155
+ "num_beam_groups": 1,
156
+ "num_beams": 1,
157
+ "num_hidden_layers": 12,
158
+ "num_return_sequences": 1,
159
+ "output_attentions": false,
160
+ "output_hidden_states": false,
161
+ "output_scores": false,
162
+ "pad_token_id": 0,
163
+ "position_embedding_type": "absolute",
164
+ "prefix": null,
165
+ "problem_type": null,
166
+ "pruned_heads": {},
167
+ "remove_invalid_values": false,
168
+ "repetition_penalty": 1.0,
169
+ "return_dict": true,
170
+ "return_dict_in_generate": false,
171
+ "sep_token_id": null,
172
+ "suppress_tokens": null,
173
+ "task_specific_params": null,
174
+ "temperature": 1.0,
175
+ "tf_legacy_loss": false,
176
+ "tie_encoder_decoder": false,
177
+ "tie_word_embeddings": true,
178
+ "tokenizer_class": null,
179
+ "top_k": 50,
180
+ "top_p": 1.0,
181
+ "torch_dtype": null,
182
+ "torchscript": false,
183
+ "transformers_version": "4.37.2",
184
+ "type_vocab_size": 2,
185
+ "typical_p": 1.0,
186
+ "use_bfloat16": false,
187
+ "vocab_size": 30522
188
+ },
189
+ "text_enhancer_dropout": 0.0,
190
+ "tf_legacy_loss": false,
191
+ "tie_encoder_decoder": false,
192
+ "tie_word_embeddings": true,
193
+ "tokenizer_class": null,
194
+ "top_k": 50,
195
+ "top_p": 1.0,
196
+ "torch_dtype": "float32",
197
+ "torchscript": false,
198
+ "transformers_version": "4.36.0.dev0",
199
+ "two_stage": true,
200
+ "two_stage_bbox_embed_share": false,
201
+ "typical_p": 1.0,
202
+ "use_bfloat16": false
203
+ },
204
+ "ip2p_config": null,
205
+ "l_hidden_size": 4096,
206
+ "llm_config": {
207
+ "_name_or_path": null,
208
+ "add_cross_attention": false,
209
+ "architectures": [
210
+ "InternLM2ForCausalLM"
211
+ ],
212
+ "attn_implementation": "flash_attention_2",
213
+ "auto_map": {
214
+ "AutoConfig": "configuration_internlm2.InternLM2Config",
215
+ "AutoModel": "modeling_internlm2.InternLM2ForCausalLM",
216
+ "AutoModelForCausalLM": "modeling_internlm2.InternLM2ForCausalLM"
217
+ },
218
+ "bad_words_ids": null,
219
+ "begin_suppress_tokens": null,
220
+ "bias": false,
221
+ "bos_token_id": 1,
222
+ "chunk_size_feed_forward": 0,
223
+ "cross_attention_hidden_size": null,
224
+ "decoder_start_token_id": null,
225
+ "diversity_penalty": 0.0,
226
+ "do_sample": true,
227
+ "early_stopping": false,
228
+ "encoder_no_repeat_ngram_size": 0,
229
+ "eos_token_id": 2,
230
+ "exponential_decay_length_penalty": null,
231
+ "finetuning_task": null,
232
+ "forced_bos_token_id": null,
233
+ "forced_eos_token_id": null,
234
+ "hidden_act": "silu",
235
+ "hidden_size": 4096,
236
+ "id2label": {
237
+ "0": "LABEL_0",
238
+ "1": "LABEL_1"
239
+ },
240
+ "initializer_range": 0.02,
241
+ "intermediate_size": 14336,
242
+ "is_decoder": false,
243
+ "is_encoder_decoder": false,
244
+ "label2id": {
245
+ "LABEL_0": 0,
246
+ "LABEL_1": 1
247
+ },
248
+ "length_penalty": 1.0,
249
+ "max_length": 20,
250
+ "max_position_embeddings": 32768,
251
+ "min_length": 0,
252
+ "model_type": "internlm2",
253
+ "no_repeat_ngram_size": 0,
254
+ "num_attention_heads": 32,
255
+ "num_beam_groups": 1,
256
+ "num_beams": 1,
257
+ "num_hidden_layers": 32,
258
+ "num_key_value_heads": 8,
259
+ "num_return_sequences": 1,
260
+ "output_attentions": false,
261
+ "output_hidden_states": false,
262
+ "output_scores": false,
263
+ "pad_token_id": 2,
264
+ "prefix": null,
265
+ "pretraining_tp": 1,
266
+ "problem_type": null,
267
+ "pruned_heads": {},
268
+ "remove_invalid_values": false,
269
+ "repetition_penalty": 1.0,
270
+ "return_dict": true,
271
+ "return_dict_in_generate": false,
272
+ "rms_norm_eps": 1e-05,
273
+ "rope_scaling": {
274
+ "factor": 2.0,
275
+ "type": "dynamic"
276
+ },
277
+ "rope_theta": 1000000,
278
+ "sep_token_id": null,
279
+ "suppress_tokens": null,
280
+ "task_specific_params": null,
281
+ "temperature": 1.0,
282
+ "tf_legacy_loss": false,
283
+ "tie_encoder_decoder": false,
284
+ "tie_word_embeddings": false,
285
+ "tokenizer_class": null,
286
+ "top_k": 50,
287
+ "top_p": 1.0,
288
+ "torch_dtype": "bfloat16",
289
+ "torchscript": false,
290
+ "transformers_version": "4.37.2",
291
+ "typical_p": 1.0,
292
+ "use_bfloat16": true,
293
+ "use_cache": true,
294
+ "vocab_size": 92578
295
+ },
296
+ "model_type": "visionllmv2",
297
+ "num_embs": 4,
298
+ "num_embs_gen": 64,
299
+ "pretrained_vl_bridge": null,
300
+ "sd_config": null,
301
+ "torch_dtype": "bfloat16",
302
+ "transformers_version": null,
303
+ "unipose_config": null,
304
+ "use_gdino": true,
305
+ "use_internvl": true,
306
+ "use_ip2p": false,
307
+ "use_llm_lora": false,
308
+ "use_pixelshuffle": true,
309
+ "use_region_encoder": false,
310
+ "use_sd": false,
311
+ "use_unipose": false,
312
+ "v_hidden_size": 1024,
313
+ "vis_encoder_config": {
314
+ "_name_or_path": null,
315
+ "add_cross_attention": false,
316
+ "architectures": [
317
+ "InternVisionModel"
318
+ ],
319
+ "attention_dropout": 0.0,
320
+ "bad_words_ids": null,
321
+ "begin_suppress_tokens": null,
322
+ "bos_token_id": null,
323
+ "chunk_size_feed_forward": 0,
324
+ "cross_attention_hidden_size": null,
325
+ "decoder_start_token_id": null,
326
+ "diversity_penalty": 0.0,
327
+ "do_sample": false,
328
+ "drop_path_rate": 0.0,
329
+ "dropout": 0.0,
330
+ "early_stopping": false,
331
+ "encoder_no_repeat_ngram_size": 0,
332
+ "eos_token_id": null,
333
+ "exponential_decay_length_penalty": null,
334
+ "finetuning_task": null,
335
+ "forced_bos_token_id": null,
336
+ "forced_eos_token_id": null,
337
+ "hidden_act": "gelu",
338
+ "hidden_size": 1024,
339
+ "id2label": {
340
+ "0": "LABEL_0",
341
+ "1": "LABEL_1"
342
+ },
343
+ "image_size": 448,
344
+ "initializer_factor": 1.0,
345
+ "initializer_range": 0.02,
346
+ "intermediate_size": 4096,
347
+ "is_decoder": false,
348
+ "is_encoder_decoder": false,
349
+ "label2id": {
350
+ "LABEL_0": 0,
351
+ "LABEL_1": 1
352
+ },
353
+ "layer_norm_eps": 1e-06,
354
+ "length_penalty": 1.0,
355
+ "max_length": 20,
356
+ "min_length": 0,
357
+ "model_type": "clip_vision_model",
358
+ "no_repeat_ngram_size": 0,
359
+ "norm_type": "layer_norm",
360
+ "num_attention_heads": 16,
361
+ "num_beam_groups": 1,
362
+ "num_beams": 1,
363
+ "num_channels": 3,
364
+ "num_hidden_layers": 24,
365
+ "num_return_sequences": 1,
366
+ "output_attentions": false,
367
+ "output_hidden_states": false,
368
+ "output_scores": false,
369
+ "pad_token_id": null,
370
+ "patch_size": 14,
371
+ "prefix": null,
372
+ "problem_type": null,
373
+ "projection_dim": 512,
374
+ "pruned_heads": {},
375
+ "qk_normalization": false,
376
+ "qkv_bias": true,
377
+ "remove_invalid_values": false,
378
+ "repetition_penalty": 1.0,
379
+ "return_dict": true,
380
+ "return_dict_in_generate": false,
381
+ "sep_token_id": null,
382
+ "suppress_tokens": null,
383
+ "task_specific_params": null,
384
+ "temperature": 1.0,
385
+ "tf_legacy_loss": false,
386
+ "tie_encoder_decoder": false,
387
+ "tie_word_embeddings": true,
388
+ "tokenizer_class": null,
389
+ "top_k": 50,
390
+ "top_p": 1.0,
391
+ "torch_dtype": "bfloat16",
392
+ "torchscript": false,
393
+ "transformers_version": "4.37.2",
394
+ "typical_p": 1.0,
395
+ "use_bfloat16": true,
396
+ "use_flash_attn": true
397
+ },
398
+ "vis_output_layer": -1,
399
+ "vl_bridge_type": "internvl"
400
+ }
generation_config.json ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "do_sample": true,
4
+ "transformers_version": "4.37.2"
5
+ }
model-00001-of-00004.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9b43ecc10b2c1cbf91a6f81fabce1e3c137e1214075653c10edebdad197441e0
3
+ size 4940148144
model-00002-of-00004.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:602e2436b992b5d82c6211be9a5681b930822b29f51b005bda68d9ac58b3a527
3
+ size 4915913728
model-00003-of-00004.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b12f43a859730204eaa685757abf6f674557be41da0181bb887e3fd8a3f30602
3
+ size 4915913736
model-00004-of-00004.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:385b8ad0fd2b445a4a359dce2cdfbe9ea9160ad22bf653251d237969f6e4c6c2
3
+ size 3617531768
model.safetensors.index.json ADDED
The diff for this file is too large to render. See raw diff
 
special_tokens_map.json ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "additional_special_tokens": [
3
+ "<|im_start|>",
4
+ "<|im_end|>",
5
+ "<|action_start|>",
6
+ "<|action_end|>",
7
+ "<|interpreter|>",
8
+ "<|plugin|>",
9
+ "<img>",
10
+ "</img>",
11
+ "<IMG_CONTEXT>",
12
+ "<quad>",
13
+ "</quad>",
14
+ "<ref>",
15
+ "</ref>",
16
+ "<box>",
17
+ "</box>",
18
+ "[PAD]",
19
+ "<image>",
20
+ "<region>",
21
+ "<reg>",
22
+ "</reg>",
23
+ "<det>",
24
+ "</det>",
25
+ "<grd>",
26
+ "</grd>",
27
+ "<gen>",
28
+ "</gen>",
29
+ "[DET]",
30
+ "[GRD]",
31
+ "[SEG]",
32
+ "[POSE]",
33
+ "[GEN]",
34
+ "[EDIT]",
35
+ "[EMB]",
36
+ "[EMB2]",
37
+ "[EMB3]",
38
+ "[EMB4]",
39
+ "[EMB5]",
40
+ "[EMB6]",
41
+ "[EMB7]",
42
+ "[EMB8]"
43
+ ],
44
+ "bos_token": {
45
+ "content": "<s>",
46
+ "lstrip": false,
47
+ "normalized": false,
48
+ "rstrip": false,
49
+ "single_word": false
50
+ },
51
+ "eos_token": {
52
+ "content": "</s>",
53
+ "lstrip": false,
54
+ "normalized": false,
55
+ "rstrip": false,
56
+ "single_word": false
57
+ },
58
+ "pad_token": "<unk>",
59
+ "unk_token": {
60
+ "content": "<unk>",
61
+ "lstrip": false,
62
+ "normalized": false,
63
+ "rstrip": false,
64
+ "single_word": false
65
+ }
66
+ }
tokenization_internlm2.py ADDED
@@ -0,0 +1,235 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Copyright (c) The InternLM team and The HuggingFace Inc. team. All rights reserved.
2
+ #
3
+ # This code is based on transformers/src/transformers/models/llama/tokenization_llama.py
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ """Tokenization classes for InternLM."""
18
+ import os
19
+ from shutil import copyfile
20
+ from typing import Any, Dict, List, Optional, Tuple
21
+
22
+ import sentencepiece as spm
23
+ from transformers.tokenization_utils import PreTrainedTokenizer
24
+ from transformers.utils import logging
25
+
26
+ logger = logging.get_logger(__name__)
27
+
28
+ VOCAB_FILES_NAMES = {'vocab_file': './tokenizer.model'}
29
+
30
+ PRETRAINED_VOCAB_FILES_MAP = {}
31
+
32
+
33
+ # Modified from transformers.model.llama.tokenization_llama.LlamaTokenizer
34
+ class InternLM2Tokenizer(PreTrainedTokenizer):
35
+ """
36
+ Construct a InternLM2 tokenizer. Based on byte-level Byte-Pair-Encoding.
37
+
38
+ Args:
39
+ vocab_file (`str`):
40
+ Path to the vocabulary file.
41
+ """
42
+
43
+ vocab_files_names = VOCAB_FILES_NAMES
44
+ pretrained_vocab_files_map = PRETRAINED_VOCAB_FILES_MAP
45
+ model_input_names = ['input_ids', 'attention_mask']
46
+ _auto_class = 'AutoTokenizer'
47
+
48
+ def __init__(
49
+ self,
50
+ vocab_file,
51
+ unk_token='<unk>',
52
+ bos_token='<s>',
53
+ eos_token='</s>',
54
+ pad_token='</s>',
55
+ sp_model_kwargs: Optional[Dict[str, Any]] = None,
56
+ add_bos_token=True,
57
+ add_eos_token=False,
58
+ decode_with_prefix_space=False,
59
+ clean_up_tokenization_spaces=False,
60
+ **kwargs,
61
+ ):
62
+ self.sp_model_kwargs = {} if sp_model_kwargs is None else sp_model_kwargs
63
+ self.vocab_file = vocab_file
64
+ self.add_bos_token = add_bos_token
65
+ self.add_eos_token = add_eos_token
66
+ self.decode_with_prefix_space = decode_with_prefix_space
67
+ self.sp_model = spm.SentencePieceProcessor(**self.sp_model_kwargs)
68
+ self.sp_model.Load(vocab_file)
69
+ self._no_prefix_space_tokens = None
70
+ super().__init__(
71
+ bos_token=bos_token,
72
+ eos_token=eos_token,
73
+ unk_token=unk_token,
74
+ pad_token=pad_token,
75
+ clean_up_tokenization_spaces=clean_up_tokenization_spaces,
76
+ **kwargs,
77
+ )
78
+
79
+ @property
80
+ def no_prefix_space_tokens(self):
81
+ if self._no_prefix_space_tokens is None:
82
+ vocab = self.convert_ids_to_tokens(list(range(self.vocab_size)))
83
+ self._no_prefix_space_tokens = {i for i, tok in enumerate(vocab) if not tok.startswith('▁')}
84
+ return self._no_prefix_space_tokens
85
+
86
+ @property
87
+ def vocab_size(self):
88
+ """Returns vocab size"""
89
+ return self.sp_model.get_piece_size()
90
+
91
+ @property
92
+ def bos_token_id(self) -> Optional[int]:
93
+ return self.sp_model.bos_id()
94
+
95
+ @property
96
+ def eos_token_id(self) -> Optional[int]:
97
+ return self.sp_model.eos_id()
98
+
99
+ def get_vocab(self):
100
+ """Returns vocab as a dict"""
101
+ vocab = {self.convert_ids_to_tokens(i): i for i in range(self.vocab_size)}
102
+ vocab.update(self.added_tokens_encoder)
103
+ return vocab
104
+
105
+ def _tokenize(self, text):
106
+ """Returns a tokenized string."""
107
+ return self.sp_model.encode(text, out_type=str)
108
+
109
+ def _convert_token_to_id(self, token):
110
+ """Converts a token (str) in an id using the vocab."""
111
+ return self.sp_model.piece_to_id(token)
112
+
113
+ def _convert_id_to_token(self, index):
114
+ """Converts an index (integer) in a token (str) using the vocab."""
115
+ token = self.sp_model.IdToPiece(index)
116
+ return token
117
+
118
+ def _maybe_add_prefix_space(self, tokens, decoded):
119
+ if tokens and tokens[0] not in self.no_prefix_space_tokens:
120
+ return ' ' + decoded
121
+ else:
122
+ return decoded
123
+
124
+ def convert_tokens_to_string(self, tokens):
125
+ """Converts a sequence of tokens (string) in a single string."""
126
+ current_sub_tokens = []
127
+ out_string = ''
128
+ prev_is_special = False
129
+ for token in tokens:
130
+ # make sure that special tokens are not decoded using sentencepiece model
131
+ if token in self.all_special_tokens:
132
+ if not prev_is_special:
133
+ out_string += ' '
134
+ out_string += self.sp_model.decode(current_sub_tokens) + token
135
+ prev_is_special = True
136
+ current_sub_tokens = []
137
+ else:
138
+ current_sub_tokens.append(token)
139
+ prev_is_special = False
140
+ out_string += self.sp_model.decode(current_sub_tokens)
141
+ out_string = self.clean_up_tokenization(out_string)
142
+ out_string = self._maybe_add_prefix_space(tokens=tokens, decoded=out_string)
143
+ return out_string[1:]
144
+
145
+ def save_vocabulary(self, save_directory, filename_prefix: Optional[str] = None) -> Tuple[str]:
146
+ """
147
+ Save the vocabulary and special tokens file to a directory.
148
+
149
+ Args:
150
+ save_directory (`str`):
151
+ The directory in which to save the vocabulary.
152
+
153
+ Returns:
154
+ `Tuple(str)`: Paths to the files saved.
155
+ """
156
+ if not os.path.isdir(save_directory):
157
+ logger.error(f'Vocabulary path ({save_directory}) should be a directory')
158
+ return
159
+ out_vocab_file = os.path.join(
160
+ save_directory, (filename_prefix + '-' if filename_prefix else '') + VOCAB_FILES_NAMES['vocab_file']
161
+ )
162
+
163
+ if os.path.abspath(self.vocab_file) != os.path.abspath(out_vocab_file) and os.path.isfile(self.vocab_file):
164
+ copyfile(self.vocab_file, out_vocab_file)
165
+ elif not os.path.isfile(self.vocab_file):
166
+ with open(out_vocab_file, 'wb') as fi:
167
+ content_spiece_model = self.sp_model.serialized_model_proto()
168
+ fi.write(content_spiece_model)
169
+
170
+ return (out_vocab_file,)
171
+
172
+ def build_inputs_with_special_tokens(self, token_ids_0, token_ids_1=None):
173
+ if self.add_bos_token:
174
+ bos_token_ids = [self.bos_token_id]
175
+ else:
176
+ bos_token_ids = []
177
+
178
+ output = bos_token_ids + token_ids_0
179
+
180
+ if token_ids_1 is not None:
181
+ output = output + token_ids_1
182
+
183
+ if self.add_eos_token:
184
+ output = output + [self.eos_token_id]
185
+
186
+ return output
187
+
188
+ def get_special_tokens_mask(
189
+ self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None, already_has_special_tokens: bool = False
190
+ ) -> List[int]:
191
+ """
192
+ Retrieve sequence ids from a token list that has no special tokens added. This method is called when adding
193
+ special tokens using the tokenizer `prepare_for_model` method.
194
+
195
+ Args:
196
+ token_ids_0 (`List[int]`):
197
+ List of IDs.
198
+ token_ids_1 (`List[int]`, *optional*):
199
+ Optional second list of IDs for sequence pairs.
200
+ already_has_special_tokens (`bool`, *optional*, defaults to `False`):
201
+ Whether or not the token list is already formatted with special tokens for the model.
202
+
203
+ Returns:
204
+ `List[int]`: A list of integers in the range [0, 1]: 1 for a special token, 0 for a sequence token.
205
+ """
206
+ if already_has_special_tokens:
207
+ return super().get_special_tokens_mask(
208
+ token_ids_0=token_ids_0, token_ids_1=token_ids_1, already_has_special_tokens=True
209
+ )
210
+
211
+ if token_ids_1 is None:
212
+ return [1] + ([0] * len(token_ids_0)) + [1]
213
+ return [1] + ([0] * len(token_ids_0)) + [1, 1] + ([0] * len(token_ids_1)) + [1]
214
+
215
+ def create_token_type_ids_from_sequences(
216
+ self, token_ids_0: List[int], token_ids_1: Optional[List[int]] = None
217
+ ) -> List[int]:
218
+ """
219
+ Create a mask from the two sequences passed to be used in a sequence-pair classification task. T5 does not make
220
+ use of token type ids, therefore a list of zeros is returned.
221
+
222
+ Args:
223
+ token_ids_0 (`List[int]`):
224
+ List of IDs.
225
+ token_ids_1 (`List[int]`, *optional*):
226
+ Optional second list of IDs for sequence pairs.
227
+
228
+ Returns:
229
+ `List[int]`: List of zeros.
230
+ """
231
+ eos = [self.eos_token_id]
232
+
233
+ if token_ids_1 is None:
234
+ return len(token_ids_0 + eos) * [0]
235
+ return len(token_ids_0 + eos + token_ids_1 + eos) * [0]
tokenizer.model ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f868398fc4e05ee1e8aeba95ddf18ddcc45b8bce55d5093bead5bbf80429b48b
3
+ size 1477754
tokenizer_config.json ADDED
@@ -0,0 +1,405 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "added_tokens_decoder": {
3
+ "0": {
4
+ "content": "<unk>",
5
+ "lstrip": false,
6
+ "normalized": false,
7
+ "rstrip": false,
8
+ "single_word": false,
9
+ "special": true
10
+ },
11
+ "1": {
12
+ "content": "<s>",
13
+ "lstrip": false,
14
+ "normalized": false,
15
+ "rstrip": false,
16
+ "single_word": false,
17
+ "special": true
18
+ },
19
+ "2": {
20
+ "content": "</s>",
21
+ "lstrip": false,
22
+ "normalized": false,
23
+ "rstrip": false,
24
+ "single_word": false,
25
+ "special": true
26
+ },
27
+ "92538": {
28
+ "content": "<|plugin|>",
29
+ "lstrip": false,
30
+ "normalized": false,
31
+ "rstrip": false,
32
+ "single_word": false,
33
+ "special": true
34
+ },
35
+ "92539": {
36
+ "content": "<|interpreter|>",
37
+ "lstrip": false,
38
+ "normalized": false,
39
+ "rstrip": false,
40
+ "single_word": false,
41
+ "special": true
42
+ },
43
+ "92540": {
44
+ "content": "<|action_end|>",
45
+ "lstrip": false,
46
+ "normalized": false,
47
+ "rstrip": false,
48
+ "single_word": false,
49
+ "special": true
50
+ },
51
+ "92541": {
52
+ "content": "<|action_start|>",
53
+ "lstrip": false,
54
+ "normalized": false,
55
+ "rstrip": false,
56
+ "single_word": false,
57
+ "special": true
58
+ },
59
+ "92542": {
60
+ "content": "<|im_end|>",
61
+ "lstrip": false,
62
+ "normalized": false,
63
+ "rstrip": false,
64
+ "single_word": false,
65
+ "special": true
66
+ },
67
+ "92543": {
68
+ "content": "<|im_start|>",
69
+ "lstrip": false,
70
+ "normalized": false,
71
+ "rstrip": false,
72
+ "single_word": false,
73
+ "special": true
74
+ },
75
+ "92544": {
76
+ "content": "<img>",
77
+ "lstrip": false,
78
+ "normalized": false,
79
+ "rstrip": false,
80
+ "single_word": false,
81
+ "special": true
82
+ },
83
+ "92545": {
84
+ "content": "</img>",
85
+ "lstrip": false,
86
+ "normalized": false,
87
+ "rstrip": false,
88
+ "single_word": false,
89
+ "special": true
90
+ },
91
+ "92546": {
92
+ "content": "<IMG_CONTEXT>",
93
+ "lstrip": false,
94
+ "normalized": false,
95
+ "rstrip": false,
96
+ "single_word": false,
97
+ "special": true
98
+ },
99
+ "92547": {
100
+ "content": "<quad>",
101
+ "lstrip": false,
102
+ "normalized": false,
103
+ "rstrip": false,
104
+ "single_word": false,
105
+ "special": true
106
+ },
107
+ "92548": {
108
+ "content": "</quad>",
109
+ "lstrip": false,
110
+ "normalized": false,
111
+ "rstrip": false,
112
+ "single_word": false,
113
+ "special": true
114
+ },
115
+ "92549": {
116
+ "content": "<ref>",
117
+ "lstrip": false,
118
+ "normalized": false,
119
+ "rstrip": false,
120
+ "single_word": false,
121
+ "special": true
122
+ },
123
+ "92550": {
124
+ "content": "</ref>",
125
+ "lstrip": false,
126
+ "normalized": false,
127
+ "rstrip": false,
128
+ "single_word": false,
129
+ "special": true
130
+ },
131
+ "92551": {
132
+ "content": "<box>",
133
+ "lstrip": false,
134
+ "normalized": false,
135
+ "rstrip": false,
136
+ "single_word": false,
137
+ "special": true
138
+ },
139
+ "92552": {
140
+ "content": "</box>",
141
+ "lstrip": false,
142
+ "normalized": false,
143
+ "rstrip": false,
144
+ "single_word": false,
145
+ "special": true
146
+ },
147
+ "92553": {
148
+ "content": "[PAD]",
149
+ "lstrip": false,
150
+ "normalized": false,
151
+ "rstrip": false,
152
+ "single_word": false,
153
+ "special": true
154
+ },
155
+ "92554": {
156
+ "content": "<image>",
157
+ "lstrip": false,
158
+ "normalized": false,
159
+ "rstrip": false,
160
+ "single_word": false,
161
+ "special": true
162
+ },
163
+ "92555": {
164
+ "content": "<region>",
165
+ "lstrip": false,
166
+ "normalized": false,
167
+ "rstrip": false,
168
+ "single_word": false,
169
+ "special": true
170
+ },
171
+ "92556": {
172
+ "content": "<reg>",
173
+ "lstrip": false,
174
+ "normalized": false,
175
+ "rstrip": false,
176
+ "single_word": false,
177
+ "special": true
178
+ },
179
+ "92557": {
180
+ "content": "</reg>",
181
+ "lstrip": false,
182
+ "normalized": false,
183
+ "rstrip": false,
184
+ "single_word": false,
185
+ "special": true
186
+ },
187
+ "92558": {
188
+ "content": "<det>",
189
+ "lstrip": false,
190
+ "normalized": false,
191
+ "rstrip": false,
192
+ "single_word": false,
193
+ "special": true
194
+ },
195
+ "92559": {
196
+ "content": "</det>",
197
+ "lstrip": false,
198
+ "normalized": false,
199
+ "rstrip": false,
200
+ "single_word": false,
201
+ "special": true
202
+ },
203
+ "92560": {
204
+ "content": "<grd>",
205
+ "lstrip": false,
206
+ "normalized": false,
207
+ "rstrip": false,
208
+ "single_word": false,
209
+ "special": true
210
+ },
211
+ "92561": {
212
+ "content": "</grd>",
213
+ "lstrip": false,
214
+ "normalized": false,
215
+ "rstrip": false,
216
+ "single_word": false,
217
+ "special": true
218
+ },
219
+ "92562": {
220
+ "content": "<gen>",
221
+ "lstrip": false,
222
+ "normalized": false,
223
+ "rstrip": false,
224
+ "single_word": false,
225
+ "special": true
226
+ },
227
+ "92563": {
228
+ "content": "</gen>",
229
+ "lstrip": false,
230
+ "normalized": false,
231
+ "rstrip": false,
232
+ "single_word": false,
233
+ "special": true
234
+ },
235
+ "92564": {
236
+ "content": "[DET]",
237
+ "lstrip": false,
238
+ "normalized": false,
239
+ "rstrip": false,
240
+ "single_word": false,
241
+ "special": true
242
+ },
243
+ "92565": {
244
+ "content": "[GRD]",
245
+ "lstrip": false,
246
+ "normalized": false,
247
+ "rstrip": false,
248
+ "single_word": false,
249
+ "special": true
250
+ },
251
+ "92566": {
252
+ "content": "[SEG]",
253
+ "lstrip": false,
254
+ "normalized": false,
255
+ "rstrip": false,
256
+ "single_word": false,
257
+ "special": true
258
+ },
259
+ "92567": {
260
+ "content": "[POSE]",
261
+ "lstrip": false,
262
+ "normalized": false,
263
+ "rstrip": false,
264
+ "single_word": false,
265
+ "special": true
266
+ },
267
+ "92568": {
268
+ "content": "[GEN]",
269
+ "lstrip": false,
270
+ "normalized": false,
271
+ "rstrip": false,
272
+ "single_word": false,
273
+ "special": true
274
+ },
275
+ "92569": {
276
+ "content": "[EDIT]",
277
+ "lstrip": false,
278
+ "normalized": false,
279
+ "rstrip": false,
280
+ "single_word": false,
281
+ "special": true
282
+ },
283
+ "92570": {
284
+ "content": "[EMB]",
285
+ "lstrip": false,
286
+ "normalized": false,
287
+ "rstrip": false,
288
+ "single_word": false,
289
+ "special": true
290
+ },
291
+ "92571": {
292
+ "content": "[EMB2]",
293
+ "lstrip": false,
294
+ "normalized": false,
295
+ "rstrip": false,
296
+ "single_word": false,
297
+ "special": true
298
+ },
299
+ "92572": {
300
+ "content": "[EMB3]",
301
+ "lstrip": false,
302
+ "normalized": false,
303
+ "rstrip": false,
304
+ "single_word": false,
305
+ "special": true
306
+ },
307
+ "92573": {
308
+ "content": "[EMB4]",
309
+ "lstrip": false,
310
+ "normalized": false,
311
+ "rstrip": false,
312
+ "single_word": false,
313
+ "special": true
314
+ },
315
+ "92574": {
316
+ "content": "[EMB5]",
317
+ "lstrip": false,
318
+ "normalized": false,
319
+ "rstrip": false,
320
+ "single_word": false,
321
+ "special": true
322
+ },
323
+ "92575": {
324
+ "content": "[EMB6]",
325
+ "lstrip": false,
326
+ "normalized": false,
327
+ "rstrip": false,
328
+ "single_word": false,
329
+ "special": true
330
+ },
331
+ "92576": {
332
+ "content": "[EMB7]",
333
+ "lstrip": false,
334
+ "normalized": false,
335
+ "rstrip": false,
336
+ "single_word": false,
337
+ "special": true
338
+ },
339
+ "92577": {
340
+ "content": "[EMB8]",
341
+ "lstrip": false,
342
+ "normalized": false,
343
+ "rstrip": false,
344
+ "single_word": false,
345
+ "special": true
346
+ }
347
+ },
348
+ "additional_special_tokens": [
349
+ "<|im_start|>",
350
+ "<|im_end|>",
351
+ "<|action_start|>",
352
+ "<|action_end|>",
353
+ "<|interpreter|>",
354
+ "<|plugin|>",
355
+ "<img>",
356
+ "</img>",
357
+ "<IMG_CONTEXT>",
358
+ "<quad>",
359
+ "</quad>",
360
+ "<ref>",
361
+ "</ref>",
362
+ "<box>",
363
+ "</box>",
364
+ "[PAD]",
365
+ "<image>",
366
+ "<region>",
367
+ "<reg>",
368
+ "</reg>",
369
+ "<det>",
370
+ "</det>",
371
+ "<grd>",
372
+ "</grd>",
373
+ "<gen>",
374
+ "</gen>",
375
+ "[DET]",
376
+ "[GRD]",
377
+ "[SEG]",
378
+ "[POSE]",
379
+ "[GEN]",
380
+ "[EDIT]",
381
+ "[EMB]",
382
+ "[EMB2]",
383
+ "[EMB3]",
384
+ "[EMB4]",
385
+ "[EMB5]",
386
+ "[EMB6]",
387
+ "[EMB7]",
388
+ "[EMB8]"
389
+ ],
390
+ "auto_map": {
391
+ "AutoTokenizer": [
392
+ "tokenization_internlm2.InternLM2Tokenizer",
393
+ null
394
+ ]
395
+ },
396
+ "bos_token": "<s>",
397
+ "chat_template": "{{ bos_token }}{% for message in messages %}{{'<|im_start|>' + message['role'] + '\n' + message['content'] + '<|im_end|>' + '\n'}}{% endfor %}{% if add_generation_prompt %}{{ '<|im_start|>assistant\n' }}{% endif %}",
398
+ "clean_up_tokenization_spaces": false,
399
+ "eos_token": "</s>",
400
+ "model_max_length": 4096,
401
+ "pad_token": "<unk>",
402
+ "padding_side": "right",
403
+ "tokenizer_class": "InternLM2Tokenizer",
404
+ "unk_token": "<unk>"
405
+ }
train_results.json ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "epoch": 1.0,
3
+ "train_loss": 12.693984882221208,
4
+ "train_runtime": 42292.4042,
5
+ "train_samples": 2916996,
6
+ "train_samples_per_second": 68.972,
7
+ "train_steps_per_second": 0.18
8
+ }
trainer_state.json ADDED
The diff for this file is too large to render. See raw diff