Image-Text-to-Text
Transformers
Safetensors
cohere_compass
vision
multimodal
conversational
multilingual
native-resolution
Instructions to use CohereLabs/North-Micro-Vision-Instruct with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use CohereLabs/North-Micro-Vision-Instruct with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="CohereLabs/North-Micro-Vision-Instruct") 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 AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("CohereLabs/North-Micro-Vision-Instruct") model = AutoModelForMultimodalLM.from_pretrained("CohereLabs/North-Micro-Vision-Instruct", 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=40) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use CohereLabs/North-Micro-Vision-Instruct with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "CohereLabs/North-Micro-Vision-Instruct" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "CohereLabs/North-Micro-Vision-Instruct", "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/CohereLabs/North-Micro-Vision-Instruct
- SGLang
How to use CohereLabs/North-Micro-Vision-Instruct 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 "CohereLabs/North-Micro-Vision-Instruct" \ --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": "CohereLabs/North-Micro-Vision-Instruct", "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 "CohereLabs/North-Micro-Vision-Instruct" \ --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": "CohereLabs/North-Micro-Vision-Instruct", "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 CohereLabs/North-Micro-Vision-Instruct with Docker Model Runner:
docker model run hf.co/CohereLabs/North-Micro-Vision-Instruct
Upload folder using huggingface_hub
Browse files- README.md +3 -3
- config.json +3 -0
README.md
CHANGED
|
@@ -79,7 +79,7 @@ The following example loads an image from a URL and asks the model to describe i
|
|
| 79 |
|
| 80 |
```python
|
| 81 |
import torch
|
| 82 |
-
from transformers import
|
| 83 |
|
| 84 |
model_id = "CohereLabs/North-Micro-Vision-Instruct"
|
| 85 |
|
|
@@ -87,7 +87,7 @@ processor = AutoProcessor.from_pretrained(
|
|
| 87 |
model_id,
|
| 88 |
trust_remote_code=True,
|
| 89 |
)
|
| 90 |
-
model =
|
| 91 |
model_id,
|
| 92 |
dtype="auto",
|
| 93 |
device_map="auto",
|
|
@@ -95,7 +95,7 @@ model = AutoModelForCausalLM.from_pretrained(
|
|
| 95 |
)
|
| 96 |
|
| 97 |
# To enable Flash Attention 2, load the model with the following settings:
|
| 98 |
-
# model =
|
| 99 |
# model_id,
|
| 100 |
# dtype=torch.bfloat16,
|
| 101 |
# attn_implementation="flash_attention_2",
|
|
|
|
| 79 |
|
| 80 |
```python
|
| 81 |
import torch
|
| 82 |
+
from transformers import AutoModelForImageTextToText, AutoProcessor
|
| 83 |
|
| 84 |
model_id = "CohereLabs/North-Micro-Vision-Instruct"
|
| 85 |
|
|
|
|
| 87 |
model_id,
|
| 88 |
trust_remote_code=True,
|
| 89 |
)
|
| 90 |
+
model = AutoModelForImageTextToText.from_pretrained(
|
| 91 |
model_id,
|
| 92 |
dtype="auto",
|
| 93 |
device_map="auto",
|
|
|
|
| 95 |
)
|
| 96 |
|
| 97 |
# To enable Flash Attention 2, load the model with the following settings:
|
| 98 |
+
# model = AutoModelForImageTextToText.from_pretrained(
|
| 99 |
# model_id,
|
| 100 |
# dtype=torch.bfloat16,
|
| 101 |
# attn_implementation="flash_attention_2",
|
config.json
CHANGED
|
@@ -142,6 +142,9 @@
|
|
| 142 |
"model_type": "cohere_compass_vision",
|
| 143 |
"output_attentions": false
|
| 144 |
},
|
|
|
|
|
|
|
|
|
|
| 145 |
"image_token_id": 255031,
|
| 146 |
"video_token_id": 255032,
|
| 147 |
"vision_start_token_id": 255028,
|
|
|
|
| 142 |
"model_type": "cohere_compass_vision",
|
| 143 |
"output_attentions": false
|
| 144 |
},
|
| 145 |
+
"fusion_config": {
|
| 146 |
+
"patch_embeddings": true
|
| 147 |
+
},
|
| 148 |
"image_token_id": 255031,
|
| 149 |
"video_token_id": 255032,
|
| 150 |
"vision_start_token_id": 255028,
|