Image-Text-to-Text
Transformers
Safetensors
English
Chinese
minicpm5_v
minicpm5
multimodal
vision
ocr
document-parsing
visual-grounding
table-extraction
custom_code
Instructions to use ewin-reg/MiniCPM5-Vision-2B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use ewin-reg/MiniCPM5-Vision-2B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="ewin-reg/MiniCPM5-Vision-2B", trust_remote_code=True)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("ewin-reg/MiniCPM5-Vision-2B", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use ewin-reg/MiniCPM5-Vision-2B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "ewin-reg/MiniCPM5-Vision-2B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "ewin-reg/MiniCPM5-Vision-2B", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/ewin-reg/MiniCPM5-Vision-2B
- SGLang
How to use ewin-reg/MiniCPM5-Vision-2B 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 "ewin-reg/MiniCPM5-Vision-2B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "ewin-reg/MiniCPM5-Vision-2B", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'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 "ewin-reg/MiniCPM5-Vision-2B" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "ewin-reg/MiniCPM5-Vision-2B", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use ewin-reg/MiniCPM5-Vision-2B with Docker Model Runner:
docker model run hf.co/ewin-reg/MiniCPM5-Vision-2B
fix: set vision_config.image_size=384 and interpolate_pos_encoding=True
Browse files- modeling_minicpm5_v.py +4 -3
modeling_minicpm5_v.py
CHANGED
|
@@ -82,7 +82,7 @@ class MiniCPM5VConfig(PretrainedConfig):
|
|
| 82 |
if vision_config is None:
|
| 83 |
vision_config = {
|
| 84 |
"hidden_size": 1152,
|
| 85 |
-
"image_size":
|
| 86 |
"intermediate_size": 4304,
|
| 87 |
"num_attention_heads": 16,
|
| 88 |
"num_hidden_layers": 27,
|
|
@@ -189,13 +189,14 @@ class MiniCPM5VForConditionalGeneration(MiniCPM5VPreTrainedModel):
|
|
| 189 |
self.llm.set_output_embeddings(new_embeddings)
|
| 190 |
|
| 191 |
def encode_vision(self, pixel_values: torch.Tensor) -> torch.Tensor:
|
| 192 |
-
vision_outputs = self.vpm(pixel_values=pixel_values)
|
| 193 |
hidden_states = vision_outputs.last_hidden_state
|
| 194 |
-
img_size =
|
| 195 |
patch_size = self.config.vision_config.patch_size
|
| 196 |
grid_dim = img_size // patch_size
|
| 197 |
return self.resampler(hidden_states, grid_h=grid_dim, grid_w=grid_dim)
|
| 198 |
|
|
|
|
| 199 |
def forward(
|
| 200 |
self,
|
| 201 |
input_ids: Optional[torch.LongTensor] = None,
|
|
|
|
| 82 |
if vision_config is None:
|
| 83 |
vision_config = {
|
| 84 |
"hidden_size": 1152,
|
| 85 |
+
"image_size": 384,
|
| 86 |
"intermediate_size": 4304,
|
| 87 |
"num_attention_heads": 16,
|
| 88 |
"num_hidden_layers": 27,
|
|
|
|
| 189 |
self.llm.set_output_embeddings(new_embeddings)
|
| 190 |
|
| 191 |
def encode_vision(self, pixel_values: torch.Tensor) -> torch.Tensor:
|
| 192 |
+
vision_outputs = self.vpm(pixel_values=pixel_values, interpolate_pos_encoding=True)
|
| 193 |
hidden_states = vision_outputs.last_hidden_state
|
| 194 |
+
img_size = pixel_values.shape[-1]
|
| 195 |
patch_size = self.config.vision_config.patch_size
|
| 196 |
grid_dim = img_size // patch_size
|
| 197 |
return self.resampler(hidden_states, grid_h=grid_dim, grid_w=grid_dim)
|
| 198 |
|
| 199 |
+
|
| 200 |
def forward(
|
| 201 |
self,
|
| 202 |
input_ids: Optional[torch.LongTensor] = None,
|