Image-Text-to-Text
Transformers
Safetensors
multilingual
minicpmv
feature-extraction
minicpm-v
vision
ocr
multi-image
video
custom_code
conversational
4-bit precision
bitsandbytes
Instructions to use pranay-ar/MiniCPM-V-2_6-int4 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use pranay-ar/MiniCPM-V-2_6-int4 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="pranay-ar/MiniCPM-V-2_6-int4", trust_remote_code=True) 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)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("pranay-ar/MiniCPM-V-2_6-int4", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use pranay-ar/MiniCPM-V-2_6-int4 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "pranay-ar/MiniCPM-V-2_6-int4" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "pranay-ar/MiniCPM-V-2_6-int4", "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/pranay-ar/MiniCPM-V-2_6-int4
- SGLang
How to use pranay-ar/MiniCPM-V-2_6-int4 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 "pranay-ar/MiniCPM-V-2_6-int4" \ --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": "pranay-ar/MiniCPM-V-2_6-int4", "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 "pranay-ar/MiniCPM-V-2_6-int4" \ --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": "pranay-ar/MiniCPM-V-2_6-int4", "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 pranay-ar/MiniCPM-V-2_6-int4 with Docker Model Runner:
docker model run hf.co/pranay-ar/MiniCPM-V-2_6-int4
add norm method
Browse files- image_processing_minicpmv.py +2 -2
- processing_minicpmv.py +14 -1
image_processing_minicpmv.py
CHANGED
|
@@ -395,8 +395,8 @@ class MiniCPMVImageProcessor(BaseImageProcessor):
|
|
| 395 |
image_patches = [
|
| 396 |
self.normalize(
|
| 397 |
image=image,
|
| 398 |
-
mean=
|
| 399 |
-
std=
|
| 400 |
input_data_format=input_data_format
|
| 401 |
)
|
| 402 |
for image in image_patches
|
|
|
|
| 395 |
image_patches = [
|
| 396 |
self.normalize(
|
| 397 |
image=image,
|
| 398 |
+
mean=self.mean,
|
| 399 |
+
std=self.std,
|
| 400 |
input_data_format=input_data_format
|
| 401 |
)
|
| 402 |
for image in image_patches
|
processing_minicpmv.py
CHANGED
|
@@ -25,9 +25,11 @@ from transformers.image_utils import ImageInput
|
|
| 25 |
from transformers.processing_utils import ProcessorMixin
|
| 26 |
from transformers.tokenization_utils_base import PaddingStrategy, PreTokenizedInput, TextInput, TruncationStrategy
|
| 27 |
from transformers.utils import TensorType, requires_backends, is_torch_dtype, is_torch_device
|
|
|
|
| 28 |
|
| 29 |
-
from .image_processing_minicpmv import MiniCPMVBatchFeature
|
| 30 |
|
|
|
|
|
|
|
| 31 |
|
| 32 |
class MiniCPMVProcessor(ProcessorMixin):
|
| 33 |
r"""
|
|
@@ -49,6 +51,17 @@ class MiniCPMVProcessor(ProcessorMixin):
|
|
| 49 |
def __init__(self, image_processor=None, tokenizer=None):
|
| 50 |
super().__init__(image_processor, tokenizer)
|
| 51 |
self.version = image_processor.version
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
def __call__(
|
| 54 |
self,
|
|
|
|
| 25 |
from transformers.processing_utils import ProcessorMixin
|
| 26 |
from transformers.tokenization_utils_base import PaddingStrategy, PreTokenizedInput, TextInput, TruncationStrategy
|
| 27 |
from transformers.utils import TensorType, requires_backends, is_torch_dtype, is_torch_device
|
| 28 |
+
from transformers.image_utils import ChannelDimension
|
| 29 |
|
|
|
|
| 30 |
|
| 31 |
+
from .image_processing_minicpmv import MiniCPMVBatchFeature
|
| 32 |
+
import numpy as np
|
| 33 |
|
| 34 |
class MiniCPMVProcessor(ProcessorMixin):
|
| 35 |
r"""
|
|
|
|
| 51 |
def __init__(self, image_processor=None, tokenizer=None):
|
| 52 |
super().__init__(image_processor, tokenizer)
|
| 53 |
self.version = image_processor.version
|
| 54 |
+
|
| 55 |
+
def normalize(self, image, mean, std, data_format=None, input_data_format=None, **kwargs):
|
| 56 |
+
# Force mean and std to be 1D arrays
|
| 57 |
+
mean = np.array(mean).flatten() # converts, e.g., [ [0.5, 0.5, 0.5] ] to [0.5, 0.5, 0.5]
|
| 58 |
+
std = np.array(std).flatten()
|
| 59 |
+
# Apply normalization based on the channel dimension
|
| 60 |
+
if input_data_format == ChannelDimension.LAST or input_data_format is None:
|
| 61 |
+
return (image - mean) / std
|
| 62 |
+
else:
|
| 63 |
+
return ((image.T - mean) / std).T
|
| 64 |
+
|
| 65 |
|
| 66 |
def __call__(
|
| 67 |
self,
|