Any-to-Any
Transformers
Safetensors
multilingual
minicpmo
feature-extraction
minicpm-o
omni
vision
ocr
multi-image
video
custom_code
audio
speech
voice cloning
live Streaming
realtime speech conversation
asr
tts
Instructions to use openbmb/MiniCPM-o-2_6 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use openbmb/MiniCPM-o-2_6 with Transformers:
# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("openbmb/MiniCPM-o-2_6", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Add native Transformers support (config and processor files only)
#59
by LucaMotz - opened
- chat_template.json +3 -0
- config.json +36 -10
- configuration_minicpm.py +1 -0
- generation_config.json +8 -0
- preprocessor_config.json +30 -5
- processing_minicpmo.py +1 -1
- processor_config.json +6 -0
- tokenizer_config.json +2 -1
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'] == 'audio' -%}{%- set parts.items = parts.items + ['<|audio|>'] -%}{%- 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) -%}{%- set tts = namespace(enabled=use_tts_template | default(false)) -%}{%- for message in messages -%}{%- if message['content'] is not string -%}{%- for item in message['content'] -%}{%- if item['type'] == 'audio' -%}{%- set tts.enabled = true -%}{%- endif -%}{%- endfor -%}{%- endif -%}{%- endfor -%}{%- if tts.enabled -%}{%- 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<|spk_bos|><|spk|><|spk_eos|><|tts_bos|>' -}}{%- endif -%}{%- else -%}{%- if tools %}\n {{- '<|im_start|>system\\n' }}\n {%- if messages[0]['role'] == 'system' %}\n {{- render_content(messages[0]['content'], images) }}\n {%- else %}\n {{- 'You are Qwen, created by Alibaba Cloud. You are a helpful assistant.' }}\n {%- endif %}\n {{- \"\\n\\n# Tools\\n\\nYou may call one or more functions to assist with the user query.\\n\\nYou are provided with function signatures within <tools></tools> XML tags:\\n<tools>\" }}\n {%- for tool in tools %}\n {{- \"\\n\" }}\n {{- tool | tojson }}\n {%- endfor %}\n {{- \"\\n</tools>\\n\\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\\n<tool_call>\\n{\\\"name\\\": <function-name>, \\\"arguments\\\": <args-json-object>}\\n</tool_call><|im_end|>\\n\" }}\n{%- else %}\n {%- if messages[0]['role'] == 'system' %}\n {{- '<|im_start|>system\\n' + render_content(messages[0]['content'], images) + '<|im_end|>\\n' }}\n {%- else %}\n {{- '<|im_start|>system\\nYou are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>\\n' }}\n {%- endif %}\n{%- endif %}\n{%- for message in messages %}\n {%- if (message.role == \"user\") or (message.role == \"system\" and not loop.first) or (message.role == \"assistant\" and not message.tool_calls) %}\n {{- '<|im_start|>' + message.role + '\\n' + render_content(message.content, images) + '<|im_end|>' + '\\n' }}\n {%- elif message.role == \"assistant\" %}\n {{- '<|im_start|>' + message.role }}\n {%- if message.content %}\n {{- '\\n' + render_content(message.content, images) }}\n {%- endif %}\n {%- for tool_call in message.tool_calls %}\n {%- if tool_call.function is defined %}\n {%- set tool_call = tool_call.function %}\n {%- endif %}\n {{- '\\n<tool_call>\\n{\"name\": \"' }}\n {{- tool_call.name }}\n {{- '\", \"arguments\": ' }}\n {{- tool_call.arguments | tojson }}\n {{- '}\\n</tool_call>' }}\n {%- endfor %}\n {{- '<|im_end|>\\n' }}\n {%- elif message.role == \"tool\" %}\n {%- if (loop.index0 == 0) or (messages[loop.index0 - 1].role != \"tool\") %}\n {{- '<|im_start|>user' }}\n {%- endif %}\n {{- '\\n<tool_response>\\n' }}\n {{- render_content(message.content, images) }}\n {{- '\\n</tool_response>' }}\n {%- if loop.last or (messages[loop.index0 + 1].role != \"tool\") %}\n {{- '<|im_end|>\\n' }}\n {%- endif %}\n {%- endif %}\n{%- endfor %}\n{%- if add_generation_prompt %}\n {{- '<|im_start|>assistant\\n' }}\n{%- endif %}\n{%- endif -%}"
|
| 3 |
+
}
|
config.json
CHANGED
|
@@ -3,7 +3,6 @@
|
|
| 3 |
"architectures": [
|
| 4 |
"MiniCPMO"
|
| 5 |
],
|
| 6 |
-
|
| 7 |
"attention_dropout": 0.0,
|
| 8 |
"bos_token_id": 151643,
|
| 9 |
"eos_token_id": 151645,
|
|
@@ -25,7 +24,6 @@
|
|
| 25 |
"batch_vision_input": true,
|
| 26 |
"drop_vision_last_layer": false,
|
| 27 |
"image_size": 448,
|
| 28 |
-
|
| 29 |
"audio_chunk_length": 1.0,
|
| 30 |
"audio_config": {
|
| 31 |
"_name_or_path": "openai/whisper-medium",
|
|
@@ -61,7 +59,7 @@
|
|
| 61 |
]
|
| 62 |
],
|
| 63 |
"max_length": 448,
|
| 64 |
-
"model_type": "
|
| 65 |
"num_hidden_layers": 24,
|
| 66 |
"pad_token_id": 50257,
|
| 67 |
"suppress_tokens": [
|
|
@@ -154,7 +152,8 @@
|
|
| 154 |
50361,
|
| 155 |
50362
|
| 156 |
],
|
| 157 |
-
"torch_dtype": "float32"
|
|
|
|
| 158 |
},
|
| 159 |
"audio_pool_step": 2,
|
| 160 |
"auto_map": {
|
|
@@ -164,12 +163,11 @@
|
|
| 164 |
},
|
| 165 |
"chunk_input": true,
|
| 166 |
"listen_speak_type": "asr",
|
| 167 |
-
"model_type": "
|
| 168 |
"patch_size": 14,
|
| 169 |
"query_num": 64,
|
| 170 |
"slice_config": {
|
| 171 |
-
"max_slice_nums": 9
|
| 172 |
-
"model_type": "minicpmv"
|
| 173 |
},
|
| 174 |
"slice_mode": true,
|
| 175 |
"torch_dtype": "bfloat16",
|
|
@@ -186,9 +184,37 @@
|
|
| 186 |
"hidden_size": 1152,
|
| 187 |
"image_size": 980,
|
| 188 |
"intermediate_size": 4304,
|
| 189 |
-
"model_type": "
|
| 190 |
"num_attention_heads": 16,
|
| 191 |
"num_hidden_layers": 27,
|
| 192 |
-
"patch_size": 14
|
| 193 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 194 |
}
|
|
|
|
| 3 |
"architectures": [
|
| 4 |
"MiniCPMO"
|
| 5 |
],
|
|
|
|
| 6 |
"attention_dropout": 0.0,
|
| 7 |
"bos_token_id": 151643,
|
| 8 |
"eos_token_id": 151645,
|
|
|
|
| 24 |
"batch_vision_input": true,
|
| 25 |
"drop_vision_last_layer": false,
|
| 26 |
"image_size": 448,
|
|
|
|
| 27 |
"audio_chunk_length": 1.0,
|
| 28 |
"audio_config": {
|
| 29 |
"_name_or_path": "openai/whisper-medium",
|
|
|
|
| 59 |
]
|
| 60 |
],
|
| 61 |
"max_length": 448,
|
| 62 |
+
"model_type": "minicpmo2_6_audio",
|
| 63 |
"num_hidden_layers": 24,
|
| 64 |
"pad_token_id": 50257,
|
| 65 |
"suppress_tokens": [
|
|
|
|
| 152 |
50361,
|
| 153 |
50362
|
| 154 |
],
|
| 155 |
+
"torch_dtype": "float32",
|
| 156 |
+
"chunk_size": 50
|
| 157 |
},
|
| 158 |
"audio_pool_step": 2,
|
| 159 |
"auto_map": {
|
|
|
|
| 163 |
},
|
| 164 |
"chunk_input": true,
|
| 165 |
"listen_speak_type": "asr",
|
| 166 |
+
"model_type": "minicpmo2_6",
|
| 167 |
"patch_size": 14,
|
| 168 |
"query_num": 64,
|
| 169 |
"slice_config": {
|
| 170 |
+
"max_slice_nums": 9
|
|
|
|
| 171 |
},
|
| 172 |
"slice_mode": true,
|
| 173 |
"torch_dtype": "bfloat16",
|
|
|
|
| 184 |
"hidden_size": 1152,
|
| 185 |
"image_size": 980,
|
| 186 |
"intermediate_size": 4304,
|
| 187 |
+
"model_type": "minicpmv2_6_vision",
|
| 188 |
"num_attention_heads": 16,
|
| 189 |
"num_hidden_layers": 27,
|
| 190 |
+
"patch_size": 14,
|
| 191 |
+
"layer_norm_eps": 1e-06,
|
| 192 |
+
"hidden_act": "gelu_pytorch_tanh"
|
| 193 |
+
},
|
| 194 |
+
"text_config": {
|
| 195 |
+
"model_type": "qwen2",
|
| 196 |
+
"vocab_size": 151700,
|
| 197 |
+
"hidden_size": 3584,
|
| 198 |
+
"intermediate_size": 18944,
|
| 199 |
+
"num_hidden_layers": 28,
|
| 200 |
+
"num_attention_heads": 28,
|
| 201 |
+
"num_key_value_heads": 4,
|
| 202 |
+
"hidden_act": "silu",
|
| 203 |
+
"max_position_embeddings": 32768,
|
| 204 |
+
"rms_norm_eps": 1e-06,
|
| 205 |
+
"bos_token_id": 151643,
|
| 206 |
+
"eos_token_id": 151645,
|
| 207 |
+
"initializer_range": 0.02,
|
| 208 |
+
"use_sliding_window": false,
|
| 209 |
+
"sliding_window": 131072,
|
| 210 |
+
"max_window_layers": 28,
|
| 211 |
+
"rope_parameters": {
|
| 212 |
+
"rope_type": "default",
|
| 213 |
+
"rope_theta": 1000000.0
|
| 214 |
+
}
|
| 215 |
+
},
|
| 216 |
+
"resampler_n_latents": 64,
|
| 217 |
+
"resampler_n_heads": 28,
|
| 218 |
+
"image_token_id": 128244,
|
| 219 |
+
"audio_token_id": 151686
|
| 220 |
}
|
configuration_minicpm.py
CHANGED
|
@@ -149,6 +149,7 @@ class MiniCPMOConfig(Qwen2Config):
|
|
| 149 |
batch_vision_input=True,
|
| 150 |
slice_config=None,
|
| 151 |
vision_config=None,
|
|
|
|
| 152 |
audio_config=None,
|
| 153 |
tts_config=None,
|
| 154 |
use_image_id=True,
|
|
|
|
| 149 |
batch_vision_input=True,
|
| 150 |
slice_config=None,
|
| 151 |
vision_config=None,
|
| 152 |
+
text_config=None, # read by the native Transformers class, not here
|
| 153 |
audio_config=None,
|
| 154 |
tts_config=None,
|
| 155 |
use_image_id=True,
|
generation_config.json
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"bos_token_id": 151643,
|
| 3 |
+
"eos_token_id": [
|
| 4 |
+
151645,
|
| 5 |
+
151643
|
| 6 |
+
],
|
| 7 |
+
"pad_token_id": 151643
|
| 8 |
+
}
|
preprocessor_config.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
| 1 |
{
|
| 2 |
-
"image_processor_type": "
|
| 3 |
"auto_map": {
|
| 4 |
"AutoProcessor": "processing_minicpmo.MiniCPMOProcessor",
|
| 5 |
"AutoImageProcessor": "image_processing_minicpmv.MiniCPMVImageProcessor"
|
| 6 |
-
|
| 7 |
"processor_class": "MiniCPMOProcessor",
|
| 8 |
"max_slice_nums": 9,
|
| 9 |
"scale_resolution": 448,
|
|
@@ -18,7 +18,32 @@
|
|
| 18 |
"im_id_start": "<image_id>",
|
| 19 |
"im_id_end": "</image_id>",
|
| 20 |
"slice_mode": true,
|
| 21 |
-
"norm_mean": [
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
}
|
|
|
|
| 1 |
{
|
| 2 |
+
"image_processor_type": "MiniCPMV2_5ImageProcessor",
|
| 3 |
"auto_map": {
|
| 4 |
"AutoProcessor": "processing_minicpmo.MiniCPMOProcessor",
|
| 5 |
"AutoImageProcessor": "image_processing_minicpmv.MiniCPMVImageProcessor"
|
| 6 |
+
},
|
| 7 |
"processor_class": "MiniCPMOProcessor",
|
| 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": 2.6,
|
| 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 |
+
"feature_extractor_type": "WhisperFeatureExtractor"
|
| 49 |
}
|
processing_minicpmo.py
CHANGED
|
@@ -54,7 +54,7 @@ class MiniCPMOProcessor(ProcessorMixin):
|
|
| 54 |
image_processor_class = "AutoImageProcessor"
|
| 55 |
tokenizer_class = "AutoTokenizer"
|
| 56 |
|
| 57 |
-
def __init__(self, image_processor=None, feature_extractor=None, tokenizer=None):
|
| 58 |
super().__init__(image_processor, feature_extractor, tokenizer)
|
| 59 |
self.version = image_processor.version
|
| 60 |
|
|
|
|
| 54 |
image_processor_class = "AutoImageProcessor"
|
| 55 |
tokenizer_class = "AutoTokenizer"
|
| 56 |
|
| 57 |
+
def __init__(self, image_processor=None, feature_extractor=None, tokenizer=None, chat_template=None):
|
| 58 |
super().__init__(image_processor, feature_extractor, tokenizer)
|
| 59 |
self.version = image_processor.version
|
| 60 |
|
processor_config.json
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"processor_class": "MiniCPMO2_6Processor",
|
| 3 |
+
"auto_map": {
|
| 4 |
+
"AutoProcessor": "processing_minicpmo.MiniCPMOProcessor"
|
| 5 |
+
}
|
| 6 |
+
}
|
tokenizer_config.json
CHANGED
|
@@ -519,5 +519,6 @@
|
|
| 519 |
]
|
| 520 |
},
|
| 521 |
"tokenizer_class": "MiniCPMOTokenizerFast",
|
| 522 |
-
"unk_token": "<unk>"
|
|
|
|
| 523 |
}
|
|
|
|
| 519 |
]
|
| 520 |
},
|
| 521 |
"tokenizer_class": "MiniCPMOTokenizerFast",
|
| 522 |
+
"unk_token": "<unk>",
|
| 523 |
+
"padding_side": "left"
|
| 524 |
}
|