Image-Text-to-Text
Transformers
Safetensors
English
granite4_vision
conversational
custom_code
8-bit precision
Instructions to use beaupi/granite-vision-4.1-4b-oQ8 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use beaupi/granite-vision-4.1-4b-oQ8 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="beaupi/granite-vision-4.1-4b-oQ8", 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 AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("beaupi/granite-vision-4.1-4b-oQ8", trust_remote_code=True) model = AutoModelForMultimodalLM.from_pretrained("beaupi/granite-vision-4.1-4b-oQ8", trust_remote_code=True, 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 beaupi/granite-vision-4.1-4b-oQ8 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "beaupi/granite-vision-4.1-4b-oQ8" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "beaupi/granite-vision-4.1-4b-oQ8", "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/beaupi/granite-vision-4.1-4b-oQ8
- SGLang
How to use beaupi/granite-vision-4.1-4b-oQ8 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 "beaupi/granite-vision-4.1-4b-oQ8" \ --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": "beaupi/granite-vision-4.1-4b-oQ8", "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 "beaupi/granite-vision-4.1-4b-oQ8" \ --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": "beaupi/granite-vision-4.1-4b-oQ8", "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 beaupi/granite-vision-4.1-4b-oQ8 with Docker Model Runner:
docker model run hf.co/beaupi/granite-vision-4.1-4b-oQ8
| from typing import Optional | |
| import logging | |
| from transformers import LlavaNextConfig | |
| logger = logging.getLogger(__name__) | |
| class Granite4VisionConfig(LlavaNextConfig): | |
| model_type = "granite4_vision" | |
| def __init__( | |
| self, | |
| downsample_rate=None, | |
| use_image_newline_parameter=True, | |
| deepstack_layer_map: Optional[list] = None, | |
| use_spatial_sampling: bool = False, | |
| spatial_stride: int = 2, | |
| spatial_vision_layer: int = -1, | |
| spatial_target_layers: Optional[list] = None, | |
| projector_dropout=0.1, | |
| **kwargs | |
| ): | |
| self.downsample_rate = downsample_rate | |
| self.use_image_newline_parameter = use_image_newline_parameter | |
| self.projector_dropout = projector_dropout | |
| # Deepstack layer map: list of (vision_layer_idx, llm_layer_idx) tuples. | |
| # Features from each vision layer are extracted, downsampled, and injected | |
| # at the corresponding LLM layer during forward pass. | |
| # e.g., [(-25, 12), (-17, 8), (-9, 4), (-1, 0)] | |
| if deepstack_layer_map is not None: | |
| self.deepstack_layer_map = [(int(v), int(l)) for v, l in deepstack_layer_map] | |
| assert len(self.deepstack_layer_map) == len(set(self.deepstack_layer_map)), "expecting no duplicates" | |
| else: | |
| self.deepstack_layer_map = None | |
| # Spatial sampling: extracts 4 groups from a single vision layer using | |
| # spatial offset sampling (top-left, top-right, bottom-left, bottom-right | |
| # of each 2x2 block), each injected at a different LLM layer. | |
| self.use_spatial_sampling = use_spatial_sampling | |
| self.spatial_stride = spatial_stride | |
| self.spatial_vision_layer = spatial_vision_layer | |
| self.spatial_target_layers = spatial_target_layers or [0, 10, 20, 30] | |
| super().__init__(**kwargs) | |