Add native Transformers support (config and processor files only)

#6
chat_template.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ {
2
+ "chat_template": "{%- macro render_content(content, ns) -%}{%- if content is string -%}{{- content -}}{%- else -%}{%- set parts = namespace(items=[]) -%}{%- for item in content -%}{%- if item['type'] == 'image' -%}{%- set parts.items = parts.items + ['<image_id>' ~ ns.image_count ~ '</image_id><unk>'] -%}{%- set ns.image_count = ns.image_count + 1 -%}{%- elif item['type'] == 'text' -%}{%- set parts.items = parts.items + [item['text']] -%}{%- endif -%}{%- endfor -%}{{- parts.items | join('\n') -}}{%- endif -%}{%- endmacro -%}{%- set images = namespace(image_count=0) -%}{%- for message in messages -%}{{- '<|im_start|>' + message['role'] + '\n' + render_content(message['content'], images) + '<|im_end|>\n' -}}{%- endfor -%}{%- if add_generation_prompt -%}{{- '<|im_start|>assistant\n' -}}{%- endif -%}"
3
+ }
config.json CHANGED
@@ -24,7 +24,7 @@
24
  "intermediate_size": 10240,
25
  "max_position_embeddings": 32768,
26
  "mlp_bias": false,
27
- "model_type": "minicpmv",
28
  "num_attention_heads": 32,
29
  "num_hidden_layers": 32,
30
  "num_key_value_heads": 2,
@@ -173,7 +173,6 @@
173
  "rope_theta": 10000.0,
174
  "slice_config": {
175
  "max_slice_nums": 9,
176
- "model_type": "minicpmv",
177
  "patch_size": 14,
178
  "scale_resolution": 448
179
  },
@@ -186,18 +185,180 @@
186
  "version": 4.0,
187
  "vision_batch_size": 16,
188
  "vision_config": {
189
- "_attn_implementation_autoset": true,
190
  "attention_dropout": 0.0,
191
  "hidden_act": "gelu_pytorch_tanh",
192
  "hidden_size": 1152,
193
  "image_size": 980,
194
  "intermediate_size": 4304,
195
  "layer_norm_eps": 1e-06,
196
- "model_type": "siglip_vision_model",
197
  "num_attention_heads": 16,
198
  "num_channels": 3,
199
  "num_hidden_layers": 27,
200
  "patch_size": 14
201
  },
202
- "vocab_size": 73448
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
203
  }
 
24
  "intermediate_size": 10240,
25
  "max_position_embeddings": 32768,
26
  "mlp_bias": false,
27
+ "model_type": "minicpmv2_6",
28
  "num_attention_heads": 32,
29
  "num_hidden_layers": 32,
30
  "num_key_value_heads": 2,
 
173
  "rope_theta": 10000.0,
174
  "slice_config": {
175
  "max_slice_nums": 9,
 
176
  "patch_size": 14,
177
  "scale_resolution": 448
178
  },
 
185
  "version": 4.0,
186
  "vision_batch_size": 16,
187
  "vision_config": {
 
188
  "attention_dropout": 0.0,
189
  "hidden_act": "gelu_pytorch_tanh",
190
  "hidden_size": 1152,
191
  "image_size": 980,
192
  "intermediate_size": 4304,
193
  "layer_norm_eps": 1e-06,
194
+ "model_type": "minicpmv2_6_vision",
195
  "num_attention_heads": 16,
196
  "num_channels": 3,
197
  "num_hidden_layers": 27,
198
  "patch_size": 14
199
  },
200
+ "vocab_size": 73448,
201
+ "text_config": {
202
+ "model_type": "llama",
203
+ "vocab_size": 73448,
204
+ "hidden_size": 2560,
205
+ "intermediate_size": 10240,
206
+ "num_hidden_layers": 32,
207
+ "num_attention_heads": 32,
208
+ "num_key_value_heads": 2,
209
+ "head_dim": 128,
210
+ "hidden_act": "silu",
211
+ "max_position_embeddings": 32768,
212
+ "rms_norm_eps": 1e-06,
213
+ "attention_bias": false,
214
+ "mlp_bias": false,
215
+ "bos_token_id": 1,
216
+ "eos_token_id": [
217
+ 2,
218
+ 73440
219
+ ],
220
+ "pad_token_id": 2,
221
+ "initializer_range": 0.1,
222
+ "rope_parameters": {
223
+ "factor": 1.0,
224
+ "long_factor": [
225
+ 0.9977997200264581,
226
+ 1.014658295992452,
227
+ 1.0349680404997148,
228
+ 1.059429246056193,
229
+ 1.0888815016813513,
230
+ 1.1243301355211495,
231
+ 1.166977103606075,
232
+ 1.2182568066927284,
233
+ 1.2798772354275727,
234
+ 1.3538666751582975,
235
+ 1.4426259039919596,
236
+ 1.5489853358570191,
237
+ 1.6762658237220625,
238
+ 1.8283407612492941,
239
+ 2.0096956085876183,
240
+ 2.225478927469756,
241
+ 2.481536379650452,
242
+ 2.784415934557119,
243
+ 3.1413289096347365,
244
+ 3.560047844772632,
245
+ 4.048719380066383,
246
+ 4.615569542115128,
247
+ 5.2684819496549835,
248
+ 6.014438591970396,
249
+ 6.858830049237097,
250
+ 7.804668263503327,
251
+ 8.851768731513417,
252
+ 9.99600492938444,
253
+ 11.228766118181639,
254
+ 12.536757560834843,
255
+ 13.902257701387796,
256
+ 15.303885189125953,
257
+ 16.717837610115794,
258
+ 18.119465097853947,
259
+ 19.484965238406907,
260
+ 20.792956681060105,
261
+ 22.02571786985731,
262
+ 23.16995406772833,
263
+ 24.217054535738416,
264
+ 25.16289275000465,
265
+ 26.007284207271347,
266
+ 26.753240849586767,
267
+ 27.40615325712662,
268
+ 27.973003419175363,
269
+ 28.461674954469114,
270
+ 28.880393889607006,
271
+ 29.237306864684626,
272
+ 29.540186419591297,
273
+ 29.79624387177199,
274
+ 30.01202719065413,
275
+ 30.193382037992453,
276
+ 30.34545697551969,
277
+ 30.47273746338473,
278
+ 30.579096895249787,
279
+ 30.66785612408345,
280
+ 30.741845563814174,
281
+ 30.80346599254902,
282
+ 30.85474569563567,
283
+ 30.897392663720595,
284
+ 30.932841297560394,
285
+ 30.962293553185553,
286
+ 30.986754758742034,
287
+ 31.007064503249293,
288
+ 31.02392307921529
289
+ ],
290
+ "original_max_position_embeddings": 32786,
291
+ "rope_type": "longrope",
292
+ "short_factor": [
293
+ 0.9977997200264581,
294
+ 1.014658295992452,
295
+ 1.0349680404997148,
296
+ 1.059429246056193,
297
+ 1.0888815016813513,
298
+ 1.1243301355211495,
299
+ 1.166977103606075,
300
+ 1.2182568066927284,
301
+ 1.2798772354275727,
302
+ 1.3538666751582975,
303
+ 1.4426259039919596,
304
+ 1.5489853358570191,
305
+ 1.6762658237220625,
306
+ 1.8283407612492941,
307
+ 2.0096956085876183,
308
+ 2.225478927469756,
309
+ 2.481536379650452,
310
+ 2.784415934557119,
311
+ 3.1413289096347365,
312
+ 3.560047844772632,
313
+ 4.048719380066383,
314
+ 4.615569542115128,
315
+ 5.2684819496549835,
316
+ 6.014438591970396,
317
+ 6.858830049237097,
318
+ 7.804668263503327,
319
+ 8.851768731513417,
320
+ 9.99600492938444,
321
+ 11.228766118181639,
322
+ 12.536757560834843,
323
+ 13.902257701387796,
324
+ 15.303885189125953,
325
+ 16.717837610115794,
326
+ 18.119465097853947,
327
+ 19.484965238406907,
328
+ 20.792956681060105,
329
+ 22.02571786985731,
330
+ 23.16995406772833,
331
+ 24.217054535738416,
332
+ 25.16289275000465,
333
+ 26.007284207271347,
334
+ 26.753240849586767,
335
+ 27.40615325712662,
336
+ 27.973003419175363,
337
+ 28.461674954469114,
338
+ 28.880393889607006,
339
+ 29.237306864684626,
340
+ 29.540186419591297,
341
+ 29.79624387177199,
342
+ 30.01202719065413,
343
+ 30.193382037992453,
344
+ 30.34545697551969,
345
+ 30.47273746338473,
346
+ 30.579096895249787,
347
+ 30.66785612408345,
348
+ 30.741845563814174,
349
+ 30.80346599254902,
350
+ 30.85474569563567,
351
+ 30.897392663720595,
352
+ 30.932841297560394,
353
+ 30.962293553185553,
354
+ 30.986754758742034,
355
+ 31.007064503249293,
356
+ 31.02392307921529
357
+ ],
358
+ "rope_theta": 10000.0
359
+ }
360
+ },
361
+ "resampler_n_latents": 64,
362
+ "resampler_n_heads": 20,
363
+ "image_token_id": 0
364
  }
configuration_minicpm.py CHANGED
@@ -86,6 +86,7 @@ class MiniCPMVConfig(LlamaConfig):
86
  batch_vision_input=True,
87
  slice_config=None,
88
  vision_config=None,
 
89
  use_image_id=True,
90
  vision_batch_size=16,
91
  **kwargs,
 
86
  batch_vision_input=True,
87
  slice_config=None,
88
  vision_config=None,
89
+ text_config=None, # read by the native Transformers class, not here
90
  use_image_id=True,
91
  vision_batch_size=16,
92
  **kwargs,
preprocessor_config.json CHANGED
@@ -1,9 +1,9 @@
1
  {
2
- "image_processor_type": "MiniCPMVImageProcessor",
3
  "auto_map": {
4
  "AutoProcessor": "processing_minicpmv.MiniCPMVProcessor",
5
  "AutoImageProcessor": "image_processing_minicpmv.MiniCPMVImageProcessor"
6
- },
7
  "processor_class": "MiniCPMVProcessor",
8
  "max_slice_nums": 9,
9
  "scale_resolution": 448,
@@ -18,7 +18,31 @@
18
  "im_id_start": "<image_id>",
19
  "im_id_end": "</image_id>",
20
  "slice_mode": true,
21
- "norm_mean": [0.5, 0.5, 0.5],
22
- "norm_std": [0.5, 0.5, 0.5],
23
- "version": 3.0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  }
 
1
  {
2
+ "image_processor_type": "MiniCPMV2_5ImageProcessor",
3
  "auto_map": {
4
  "AutoProcessor": "processing_minicpmv.MiniCPMVProcessor",
5
  "AutoImageProcessor": "image_processing_minicpmv.MiniCPMVImageProcessor"
6
+ },
7
  "processor_class": "MiniCPMVProcessor",
8
  "max_slice_nums": 9,
9
  "scale_resolution": 448,
 
18
  "im_id_start": "<image_id>",
19
  "im_id_end": "</image_id>",
20
  "slice_mode": true,
21
+ "norm_mean": [
22
+ 0.5,
23
+ 0.5,
24
+ 0.5
25
+ ],
26
+ "norm_std": [
27
+ 0.5,
28
+ 0.5,
29
+ 0.5
30
+ ],
31
+ "version": 3.0,
32
+ "do_convert_rgb": true,
33
+ "do_normalize": true,
34
+ "do_rescale": true,
35
+ "do_resize": true,
36
+ "image_mean": [
37
+ 0.5,
38
+ 0.5,
39
+ 0.5
40
+ ],
41
+ "image_std": [
42
+ 0.5,
43
+ 0.5,
44
+ 0.5
45
+ ],
46
+ "resample": 3,
47
+ "rescale_factor": 0.00392156862745098
48
  }
processor_config.json ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "image_token": "<unk>",
3
+ "num_image_tokens": 64,
4
+ "processor_class": "MiniCPMV2_6Processor",
5
+ "auto_map": {
6
+ "AutoProcessor": "processing_minicpmv.MiniCPMVProcessor"
7
+ }
8
+ }
tokenizer_config.json CHANGED
@@ -1,7 +1,7 @@
1
  {
2
  "add_bos_token": true,
3
  "add_eos_token": false,
4
- "added_tokens_decoder": {
5
  "0": {
6
  "content": "<unk>",
7
  "lstrip": false,
@@ -105,7 +105,7 @@
105
  "eos_token": "<|im_end|>",
106
  "legacy": true,
107
  "model_max_length": 1000000000000000019884624838656,
108
- "pad_token": null,
109
  "sp_model_kwargs": {},
110
  "spaces_between_special_tokens": false,
111
  "auto_map": {
@@ -116,5 +116,6 @@
116
  },
117
  "tokenizer_class": "MiniCPMVTokenizerFast",
118
  "unk_token": "<unk>",
119
- "use_default_system_prompt": false
 
120
  }
 
1
  {
2
  "add_bos_token": true,
3
  "add_eos_token": false,
4
+ "added_tokens_decoder": {
5
  "0": {
6
  "content": "<unk>",
7
  "lstrip": false,
 
105
  "eos_token": "<|im_end|>",
106
  "legacy": true,
107
  "model_max_length": 1000000000000000019884624838656,
108
+ "pad_token": "</s>",
109
  "sp_model_kwargs": {},
110
  "spaces_between_special_tokens": false,
111
  "auto_map": {
 
116
  },
117
  "tokenizer_class": "MiniCPMVTokenizerFast",
118
  "unk_token": "<unk>",
119
+ "use_default_system_prompt": false,
120
+ "padding_side": "left"
121
  }