Image-Text-to-Text
Transformers
minicpmv4_7
minicpm-v
multimodal
On-Device Model
lightweight
conversational
Instructions to use FastFlowLM/MiniCPM-V-4.7-1B-NPU2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use FastFlowLM/MiniCPM-V-4.7-1B-NPU2 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="FastFlowLM/MiniCPM-V-4.7-1B-NPU2") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("FastFlowLM/MiniCPM-V-4.7-1B-NPU2") model = AutoModelForMultimodalLM.from_pretrained("FastFlowLM/MiniCPM-V-4.7-1B-NPU2", device_map="auto") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] inputs = processor.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=256) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use FastFlowLM/MiniCPM-V-4.7-1B-NPU2 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "FastFlowLM/MiniCPM-V-4.7-1B-NPU2" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "FastFlowLM/MiniCPM-V-4.7-1B-NPU2", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/FastFlowLM/MiniCPM-V-4.7-1B-NPU2
- SGLang
How to use FastFlowLM/MiniCPM-V-4.7-1B-NPU2 with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "FastFlowLM/MiniCPM-V-4.7-1B-NPU2" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "FastFlowLM/MiniCPM-V-4.7-1B-NPU2", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "FastFlowLM/MiniCPM-V-4.7-1B-NPU2" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "FastFlowLM/MiniCPM-V-4.7-1B-NPU2", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use FastFlowLM/MiniCPM-V-4.7-1B-NPU2 with Docker Model Runner:
docker model run hf.co/FastFlowLM/MiniCPM-V-4.7-1B-NPU2
Download config.json from FastFlowLM/MiniCPM-V-4.7-1B-NPU2: direct link, hf CLI and curl.
- Browser
- Download file 2.88 kB
-
https://huggingface.co/FastFlowLM/MiniCPM-V-4.7-1B-NPU2/resolve/main/config.json
- Command line
-
hf download hf://FastFlowLM/MiniCPM-V-4.7-1B-NPU2/config.json
-
curl -L -o config.json https://huggingface.co/FastFlowLM/MiniCPM-V-4.7-1B-NPU2/resolve/main/config.json
2.88 kB
| { | |
| "architectures": [ | |
| "MiniCPMV4_7ForConditionalGeneration" | |
| ], | |
| "model_type": "minicpmv4_7", | |
| "flm_version": "1.0.13", | |
| "attention_bias": false, | |
| "attention_dropout": 0.0, | |
| "attn_output_gate": true, | |
| "dtype": "bfloat16", | |
| "bos_token_id": 248045, | |
| "eos_token_id": 248044, | |
| "full_attention_interval": 4, | |
| "head_dim": 256, | |
| "hidden_act": "silu", | |
| "hidden_size": 1024, | |
| "initializer_range": 0.02, | |
| "intermediate_size": 3584, | |
| "layer_types": [ | |
| "linear_attention", | |
| "linear_attention", | |
| "linear_attention", | |
| "full_attention", | |
| "linear_attention", | |
| "linear_attention", | |
| "linear_attention", | |
| "full_attention", | |
| "linear_attention", | |
| "linear_attention", | |
| "linear_attention", | |
| "full_attention", | |
| "linear_attention", | |
| "linear_attention", | |
| "linear_attention", | |
| "full_attention", | |
| "linear_attention", | |
| "linear_attention", | |
| "linear_attention", | |
| "full_attention", | |
| "linear_attention", | |
| "linear_attention", | |
| "linear_attention", | |
| "full_attention" | |
| ], | |
| "linear_conv_kernel_dim": 4, | |
| "linear_key_head_dim": 128, | |
| "linear_num_key_heads": 16, | |
| "linear_num_value_heads": 16, | |
| "linear_value_head_dim": 128, | |
| "mamba_ssm_dtype": "float32", | |
| "max_position_embeddings": 262144, | |
| "mlp_only_layers": [], | |
| "mtp_num_hidden_layers": 1, | |
| "mtp_use_dedicated_embeddings": false, | |
| "num_attention_heads": 8, | |
| "num_hidden_layers": 24, | |
| "num_key_value_heads": 2, | |
| "partial_rotary_factor": 0.25, | |
| "rms_norm_eps": 1e-06, | |
| "tie_word_embeddings": false, | |
| "use_cache": true, | |
| "vocab_size": 248094, | |
| "rope_parameters": { | |
| "mrope_interleaved": true, | |
| "mrope_section": [ | |
| 11, | |
| 11, | |
| 10 | |
| ], | |
| "rope_type": "default", | |
| "rope_theta": 10000000, | |
| "partial_rotary_factor": 0.25 | |
| }, | |
| "addr_qk": 53248, | |
| "addr_kv": 53536, | |
| "vision_model_weight": "vision_weight.q4nx", | |
| "image_token_id": 248056, | |
| "video_token_id": 248057, | |
| "insert_layer_id": 6, | |
| "downsample_mode": "16x", | |
| "mrope_mode": "canvas", | |
| "vision_config": { | |
| "MINICPM_V_PATCH_SIZE": 14, | |
| "MINICPM_V_IMAGE_SIZE": 980, | |
| "MINICPM_V_MAX_SLICE_NUMS": 9, | |
| "MINICPM_V_INSERT_LAYER_ID": 6, | |
| "MINICPM_V_SPATIAL_MERGE_SIZE": 2, | |
| "MINICPM_V_TEMPORAL_PATCH_SIZE": 1, | |
| "MINICPM_V_DOWNSAMPLE_FACTOR": 16, | |
| "MINICPM_V_VISION_RESCALE_FACTOR": 0.00392156862745098, | |
| "MINICPM_V_VISION_RESCALE_IMAGE_MEAN": 0.5, | |
| "MINICPM_V_VISION_RESCALE_IMAGE_STD": 0.5, | |
| "MINICPM_V_VISION_EMBED_DIM": 1152, | |
| "MINICPM_V_VISION_NUM_HEADS": 16, | |
| "MINICPM_V_VISION_HEAD_DIM": 72, | |
| "MINICPM_V_VISION_MLP_INTERMEDIATE_SIZE": 4304, | |
| "MINICPM_V_VISION_NUM_POSITION_EMBEDDINGS": 4900, | |
| "MINICPM_V_VISION_NUM_LAYERS": 27, | |
| "MINICPM_V_VISION_LAYER_NORM_EPSILON": 1e-06, | |
| "MINICPM_V_VISION_OUT_HIDDEN_SIZE": 1024, | |
| "MINICPM_V_MERGER_HIDDEN_SIZE": 4608, | |
| "MINICPM_V_VIT_MERGER_INTERMEDIATE_SIZE": 17216 | |
| } | |
| } |